Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Stage 7c/7d: own output scene and buffer content; drop wlr_scene

oxydizer266c9d5a5965
diff --git a/build.zig b/build.zig
index 967df74..f985614 100644
--- a/build.zig
+++ b/build.zig
@@ -712,6 +712,7 @@ pub fn build(b: *std.Build) void {
});
projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection_test.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
+ projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_outputs.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
inline for (.{ "wlroots-0.20", "wayland-server", "pixman-1" }) |lib| {
projection_tests.root_module.linkSystemLibrary(lib, .{});
@@ -730,6 +731,7 @@ pub fn build(b: *std.Build) void {
}
glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });
glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
+ glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_outputs.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
const run_glass_tests = b.addRunArtifact(glass_tests);
run_glass_tests.setEnvironmentVariable("WLR_RENDERER", "gles2");
@@ -818,6 +820,7 @@ fn addGlass(b: *std.Build, module: *std.Build.Module, damage_audit: bool) void {
module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = if (damage_audit) &.{ "-std=c11", "-Wall", "-Wextra", "-DREDIWM_DAMAGE_AUDIT" } else &.{ "-std=c11", "-Wall", "-Wextra" } });
module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFile(.{ .file = b.path("src/node_surface.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
+ module.addCSourceFile(.{ .file = b.path("src/scene_outputs.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFile(.{ .file = b.path("src/scene_pass.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFile(.{ .file = b.path("src/scene_output.c"), .flags = if (damage_audit) &.{ "-std=c11", "-Wall", "-Wextra", "-Werror", "-DREDIWM_DAMAGE_AUDIT" } else &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
diff --git a/docs/plans/scene-graph-stage7.md b/docs/plans/scene-graph-stage7.md
index 04ccb2b..24f1df0 100644
--- a/docs/plans/scene-graph-stage7.md
+++ b/docs/plans/scene-graph-stage7.md
@@ -130,6 +130,19 @@ suites pass; integration batch: the same failures as HEAD plus flakes that also
the previous commit (`input_persistence`, `xwayland`, `xwayland_fractional`: xrdb sees no
`Xft.dpi` about half the runs).
+**7c and 7d landed 2026-10-16 (one change).** `scene_outputs.c` keeps what each output
+needs (layout position, damage ring, pending commit damage, explicit-sync timelines,
+the `needs_frame` latch, and the registry's direct-scanout flag and colour manager); it
+replaces `wlr_scene_output`, `wlr_scene_output_layout` and the registration half of
+`wlr_scene`. A buffer node holds its own content (locked `wlr_buffer`, texture,
+wait point, single-pixel colour, the `outputs_update`/`output_sample`/`frame_done`
+signals), so the carriers, the hidden host and the leaf-on-carrier trick are gone: the
+projection's `source` is the node itself and its leaf lives in `node->leaf`. No file
+includes `wlr/types/wlr_scene.h` and `wlr.Scene` is not created. The test hook
+`tests/output_destroy_hook.c` now finds the unplug target at `wlr_output_set_name`
+(the wlr scene functions it interposed are no longer called). `rediwm_scene_output_damage_whole`
+moved to `scene_outputs.c`; `Server.sendFrameDone` is the projection's alone.
+
## Design
An own node module, C core with a thin Zig wrapper, living beside `scene_graph.h`:
diff --git a/src/Output.zig b/src/Output.zig
index 8d5462f..03b4af6 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -5,6 +5,7 @@ const wl = @import("wayland").server.wl;
const wlr = @import("wlroots");
const sn = @import("node.zig");
+const SceneOutput = @import("scene_outputs.zig").SceneOutput;
const ControlCenter = @import("control_center/panel.zig").ControlCenter;
const StartMenu = @import("start_menu/panel.zig").StartMenu;
@@ -630,8 +631,7 @@ pub fn create(server: *Server, wlr_output: *wlr.Output) !void {
}
break :blk try server.output_layout.addAuto(wlr_output);
};
- const scene_output = try server.scene.createSceneOutput(wlr_output);
- server.scene_output_layout.addOutput(layout_output, scene_output);
+ _ = try server.scene_outputs.createOutput(wlr_output, layout_output);
server.output_layout.getBox(wlr_output, &output.cached_box);
@@ -1120,8 +1120,7 @@ pub fn commitFrameState(output: *Output, state: *wlr.Output.State) bool {
}
}
if (!success and state.committed.buffer) {
- if (output.server.scene.getSceneOutput(output.wlr_output)) |scene_output|
- @import("scene_output.zig").damageWhole(scene_output);
+ if (output.server.scene_outputs.get(output.wlr_output)) |scene_output| scene_output.damageWhole();
}
return success;
}
@@ -1159,12 +1158,11 @@ const CursorState = struct {
/// desktop with one such client. Anything else that raises `needs_frame`
/// without scene damage is checked here: hardware cursor moves, output
/// capture (which holds an attach-render lock) and gamma changes.
-fn commitIsRedundant(output: *Output, scene_output: *wlr.SceneOutput) bool {
+fn commitIsRedundant(output: *Output, scene_output: *SceneOutput) bool {
if (output.vblank_timer == null or output.color.pending) return false;
const wlr_output = output.wlr_output;
if (!wlr_output.enabled or wlr_output.attach_render_locks > 0) return false;
- if (scene_output.private.gamma_lut_changed) return false;
- if (scene_output.private.pending_commit_damage.notEmpty()) return false;
+ if (scene_output.hasPendingDamage()) return false;
return std.meta.eql(CursorState.of(wlr_output), output.committed_cursor);
}
@@ -1203,7 +1201,7 @@ fn handleVblank(output: *Output) c_int {
}
fn sendFrameDone(output: *Output) void {
- if (output.server.scene.getSceneOutput(output.wlr_output)) |scene_output| {
+ if (output.server.scene_outputs.get(output.wlr_output)) |scene_output| {
var now = timestamp();
output.server.sendFrameDone(scene_output, &now);
}
@@ -1326,7 +1324,7 @@ fn runFrame(output: *Output) void {
const longest: u64 = @intCast(anim.observeLongestMs());
if (longest > stats.global_stats.anim_longest_ms) stats.global_stats.anim_longest_ms = longest;
}
- const scene_output = output.server.scene.getSceneOutput(output.wlr_output) orelse {
+ const scene_output = output.server.scene_outputs.get(output.wlr_output) orelse {
// Safer than `.?`: a missing scene output is a setup failure, not a
// reason to abort the compositor on every refresh.
log.err("handleFrame: no scene output for {s}", .{output.wlr_output.name});
@@ -1516,7 +1514,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
// and attach a bind listener which misses the in-progress destroy signal,
// causing wlr_output_finish() to assert. The scene output removes its
// addons when explicitly destroyed, so wlroots won't destroy it twice.
- if (server.scene.getSceneOutput(output.wlr_output)) |scene_output| {
+ if (server.scene_outputs.get(output.wlr_output)) |scene_output| {
scene_output.destroy();
}
// Remove the layout entry now so remaining automatic positions have
diff --git a/src/Server.zig b/src/Server.zig
index 0aaebde..72c55a4 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -19,6 +19,7 @@ const icon_theme = @import("icon_theme.zig");
const icon_service_mod = @import("icon_service.zig");
const glass = @import("glass.zig");
const scene_output_mod = @import("scene_output.zig");
+const scene_outputs_mod = @import("scene_outputs.zig");
const explicit_sync = @import("explicit_sync.zig");
const ipc_server = @import("ipc/server.zig");
const screenshot = @import("screenshot/capture.zig");
@@ -98,8 +99,8 @@ gpu_timer: ?*@import("gpu_timing.zig").Timer = null,
gpu_timer_tried: bool = false,
gpu_timer_used_ns: u64 = 0,
allocator: *wlr.Allocator,
-/// wlroots' scene, kept for its outputs; the compositor draws from `nodes`.
-scene: *wlr.Scene,
+/// What each output keeps besides the output itself (scene_outputs.h).
+scene_outputs: *scene_outputs_mod.SceneOutputs,
/// The compositor's own scene: its layers are the trees below, bottom to top.
nodes: *sn.Scene,
glass_engine: ?*glass.Engine = null,
@@ -109,7 +110,6 @@ output_renderer: *scene_output_mod.Renderer = undefined,
read_fence: ?*explicit_sync.ReadFence = null,
output_layout: *wlr.OutputLayout,
-scene_output_layout: *wlr.SceneOutputLayout,
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
shell: Shell,
@@ -366,21 +366,12 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
const output_layout = wlr.OutputLayout.create(wl_server) catch return error.OutputLayoutCreateFailed;
errdefer output_layout.destroy();
- const scene = wlr.Scene.create() catch return error.SceneCreateFailed;
- errdefer scene.tree.node.destroy();
- // The world source tree stays disabled: wlroots ignores it, and the projection
- // resolves it into the graph the output pass draws.
- // wlroots would lower each mapped X11 source as if it were hidden,
- // undoing our raise after the map listener runs. Toplevel owns X11
- // stacking alongside its scene ordering instead.
- scene.restack_xwayland_surfaces = false;
-
- // Carriers and the clients' surface trees live under a disabled host, so wlroots
- // computes nothing for them: the projection resolves our scene instead.
- const host = scene.tree.createSceneTree() catch return error.SceneCreateFailed;
- host.node.setEnabled(false);
- const nodes = sn.Scene.create(host) catch return error.SceneCreateFailed;
+ const scene_outputs = scene_outputs_mod.SceneOutputs.create(output_layout) catch return error.SceneCreateFailed;
+ errdefer scene_outputs.destroy();
+ // The projection resolves the scene into the graph the output pass draws.
+ const nodes = sn.Scene.create() catch return error.SceneCreateFailed;
errdefer nodes.destroy();
+ nodes.outputs = scene_outputs;
const background_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
const desktop_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
const world_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
@@ -389,7 +380,6 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
const overlay_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
const ime_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
const lock_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;
- const scene_output_layout = scene.attachOutputLayout(output_layout) catch return error.SceneCreateFailed;
const catalog = applications.Catalog.init(@import("main.zig").gpa, io, environ, !greeter) catch return error.ServerCreateFailed;
errdefer catalog.deinit();
@@ -429,7 +419,7 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
.backend = backend,
.renderer = renderer,
.allocator = wlr_allocator,
- .scene = scene,
+ .scene_outputs = scene_outputs,
.nodes = nodes,
.background_tree = background_tree,
.desktop_tree = desktop_tree,
@@ -439,7 +429,6 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
.ime_tree = ime_tree,
.lock_tree = lock_tree,
.output_layout = output_layout,
- .scene_output_layout = scene_output_layout,
.shell = undefined,
.world = undefined,
.input = undefined,
@@ -817,8 +806,8 @@ pub fn reactivateSession(server: *Server) void {
var it = server.outputs.iterator(.forward);
while (it.next()) |output| {
- if (server.scene.getSceneOutput(output.wlr_output)) |so| {
- so.damage_ring.addWhole();
+ if (server.scene_outputs.get(output.wlr_output)) |so| {
+ so.damageWhole();
}
output.wlr_output.scheduleFrame();
}
@@ -1087,7 +1076,7 @@ pub fn deinit(server: *Server) void {
glass.Engine.destroy(server.glass_engine);
scene_output_mod.Renderer.destroy(server.output_renderer);
explicit_sync.ReadFence.destroy(server.read_fence);
- server.scene.tree.node.destroy();
+ server.scene_outputs.destroy();
server.output_layout.destroy();
server.allocator.destroy();
if (server.gpu_timer) |timer| timer.destroy();
@@ -1100,14 +1089,12 @@ pub fn deinit(server: *Server) void {
/// All output builds, including capture between frames, use the owned pass and
/// the same swapchain/damage history. Commits stay on Output.
-pub fn buildOutputState(server: *Server, output: *wlr.SceneOutput, state: *wlr.Output.State) bool {
+pub fn buildOutputState(server: *Server, output: *scene_outputs_mod.SceneOutput, state: *wlr.Output.State) bool {
return server.output_renderer.buildState(server.world.projection, output, state);
}
-/// Frame callbacks for everything the output shows: the layout trees through
-/// wlroots, the world's surfaces from the graph.
-pub fn sendFrameDone(server: *Server, output: *wlr.SceneOutput, now: *std.posix.timespec) void {
- output.sendFrameDone(now);
+/// Frame callbacks for the surfaces the output shows, from the graph.
+pub fn sendFrameDone(server: *Server, output: *scene_outputs_mod.SceneOutput, now: *std.posix.timespec) void {
server.world.projection.sendFrameDone(output, now);
}
diff --git a/src/World.zig b/src/World.zig
index 10aa066..a46fbc4 100644
--- a/src/World.zig
+++ b/src/World.zig
@@ -58,7 +58,7 @@ pub fn init(world: *World, server: *Server, tree: *sn.Tree) !void {
world.* = .{
.server = server,
.tree = tree,
- .projection = Projection.create(server.nodes, tree, server.scene) orelse return error.SceneCreateFailed,
+ .projection = Projection.create(server.nodes, tree, server.scene_outputs) orelse return error.SceneCreateFailed,
};
world.toplevels.init();
world.closing.init();
diff --git a/src/capture/window_source.zig b/src/capture/window_source.zig
index 2a8fdee..f896f74 100644
--- a/src/capture/window_source.zig
+++ b/src/capture/window_source.zig
@@ -281,10 +281,10 @@ pub const WindowCaptureSource = struct {
/// already relies on `setEnabled(false)` to hide nodes from real output
/// rendering elsewhere (e.g. `screenshot/capture.zig`'s isolation mode).
fn renderOwnBuffer(buffer: *sn.Buffer, sx: c_int, sy: c_int, ctx: *RenderCtx) void {
- renderNodeBuffer(buffer.carrier, if (buffer.surface) |scene_surface| scene_surface.surface else null, sx, sy, ctx);
+ renderNodeBuffer(buffer, if (buffer.surface) |scene_surface| scene_surface.surface else null, sx, sy, ctx);
}
- fn renderNodeBuffer(scene_buffer: *wlr.SceneBuffer, surface: ?*wlr.Surface, sx: c_int, sy: c_int, ctx: *RenderCtx) void {
+ fn renderNodeBuffer(scene_buffer: *sn.Buffer, surface: ?*wlr.Surface, sx: c_int, sy: c_int, ctx: *RenderCtx) void {
const buf = scene_buffer.buffer orelse return;
const texture = wlr.Texture.fromBuffer(ctx.renderer, buf) orelse return;
defer texture.destroy();
@@ -311,8 +311,8 @@ pub const WindowCaptureSource = struct {
.color_encoding = .none,
.color_range = .full,
.luminance_multiplier = &luminance_multiplier,
- .wait_timeline = scene_buffer.private.wait_timeline,
- .wait_point = scene_buffer.private.wait_point,
+ .wait_timeline = scene_buffer.wait_timeline,
+ .wait_point = scene_buffer.wait_point,
};
if (ctx.shape) |*shape| {
rediwm_scene_pass_add_texture_shaped(ctx.pass, &options, shape);
diff --git a/src/extra_protocols.c b/src/extra_protocols.c
index 6f86fb1..e511fc7 100644
--- a/src/extra_protocols.c
+++ b/src/extra_protocols.c
@@ -16,7 +16,7 @@
#include <wlr/types/wlr_drm_lease_v1.h>
#include <wlr/types/wlr_ext_workspace_v1.h>
#include <wlr/types/wlr_output_layout.h>
-#include <wlr/types/wlr_scene.h>
+#include "scene_outputs.h"
#include <wlr/types/wlr_tearing_control_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_xdg_toplevel_tag_v1.h>
@@ -33,7 +33,7 @@ struct rediwm_protocols {
bool workspace_mode;
struct wl_listener tag, description, lease_request, layout_add;
struct wl_list outputs;
- struct wlr_scene *scene; // set once the scene follows the color manager
+ struct rediwm_scene_outputs *scene; // set once the outputs follow the color manager
void *data;
bool (*blocked)(void *);
void (*changed)(void *, struct wlr_surface *);
@@ -227,19 +227,13 @@ void rediwm_protocols_destroy(struct rediwm_protocols *p) {
wl_list_for_each_safe(o, tmp, &p->outputs, link) output_removed(&o->destroy, NULL);
wl_list_remove(&p->tag.link); wl_list_remove(&p->description.link);
wl_list_remove(&p->lease_request.link); wl_list_remove(&p->layout_add.link);
- // wlroots 0.20's scene teardown leaves its color manager listener linked, and
- // the scene goes before the display: the manager's display-destroy signal
- // would then walk freed memory. Unlink it while both are alive.
- if (p->scene && p->scene->color_manager_v1) {
- wl_list_remove(&p->scene->private.color_manager_v1_destroy.link);
- wl_list_init(&p->scene->private.color_manager_v1_destroy.link);
- p->scene->color_manager_v1 = NULL;
- }
+ // The outputs go before the display: detach the colour manager they follow.
+ if (p->scene) rediwm_scene_outputs_set_color_manager(p->scene, NULL);
wl_list_remove(&p->workspace_commit.link);
free(p);
}
struct rediwm_protocols *rediwm_protocols_create(struct wl_display *display,
- struct wlr_backend *backend, struct wlr_renderer *renderer, struct wlr_scene *scene,
+ struct wlr_backend *backend, struct wlr_renderer *renderer, struct rediwm_scene_outputs *scene,
struct wlr_output_layout *layout, void *data, bool (*blocked)(void *),
void (*changed)(void *, struct wlr_surface *)) {
struct rediwm_protocols *p = calloc(1, sizeof(*p));
@@ -266,7 +260,7 @@ struct rediwm_protocols *rediwm_protocols_create(struct wl_display *display,
struct wlr_color_manager_v1 *color = wlr_color_manager_v1_create(display, 2, &options);
free((void *)options.transfer_functions); free((void *)options.primaries);
if (!color) goto fail;
- wlr_scene_set_color_manager_v1(scene, color);
+ rediwm_scene_outputs_set_color_manager(scene, color);
p->scene = scene;
struct wlr_ext_workspace_manager_v1 *workspaces = wlr_ext_workspace_manager_v1_create(display, 1);
if (!workspaces) goto fail;
diff --git a/src/extra_protocols.h b/src/extra_protocols.h
index 79db2ff..0f396ab 100644
--- a/src/extra_protocols.h
+++ b/src/extra_protocols.h
@@ -3,12 +3,12 @@
struct wl_display;
struct wlr_backend;
struct wlr_renderer;
-struct wlr_scene;
+struct rediwm_scene_outputs;
struct wlr_output_layout;
struct wlr_output;
struct wlr_surface;
struct rediwm_protocols;
-struct rediwm_protocols *rediwm_protocols_create(struct wl_display *, struct wlr_backend *, struct wlr_renderer *, struct wlr_scene *, struct wlr_output_layout *, void *, bool (*)(void *), void (*)(void *, struct wlr_surface *));
+struct rediwm_protocols *rediwm_protocols_create(struct wl_display *, struct wlr_backend *, struct wlr_renderer *, struct rediwm_scene_outputs *, struct wlr_output_layout *, void *, bool (*)(void *), void (*)(void *, struct wlr_surface *));
void rediwm_protocols_destroy(struct rediwm_protocols *);
void rediwm_protocols_offer(struct rediwm_protocols *, struct wlr_output *);
void rediwm_protocols_revoke(struct rediwm_protocols *);
diff --git a/src/extra_protocols.zig b/src/extra_protocols.zig
index baf4ba3..28f1bed 100644
--- a/src/extra_protocols.zig
+++ b/src/extra_protocols.zig
@@ -4,7 +4,7 @@ const wlr = @import("wlroots");
const Server = @import("Server.zig");
const Toplevel = @import("Toplevel.zig");
pub const Protocols = opaque {};
-extern fn rediwm_protocols_create(*wl.Server, *wlr.Backend, *wlr.Renderer, *wlr.Scene, *wlr.OutputLayout, *Server, *const fn (*Server) callconv(.c) bool, *const fn (*Server, *wlr.Surface) callconv(.c) void) ?*Protocols;
+extern fn rediwm_protocols_create(*wl.Server, *wlr.Backend, *wlr.Renderer, *@import("scene_outputs.zig").SceneOutputs, *wlr.OutputLayout, *Server, *const fn (*Server) callconv(.c) bool, *const fn (*Server, *wlr.Surface) callconv(.c) void) ?*Protocols;
pub extern fn rediwm_protocols_destroy(?*Protocols) void;
pub extern fn rediwm_protocols_offer(?*Protocols, *wlr.Output) void;
pub extern fn rediwm_protocols_revoke(?*Protocols) void;
@@ -13,7 +13,7 @@ extern fn rediwm_protocols_content(?*Protocols, ?*wlr.Surface) ?[*:0]const u8;
extern fn rediwm_surface_tag(?*wlr.Surface, bool) ?[*:0]const u8;
pub extern fn rediwm_surface_edge_is_srgb(*wlr.Surface) bool;
pub fn create(server: *Server) ?*Protocols {
- return rediwm_protocols_create(server.wl_server, server.backend, server.renderer, server.scene, server.output_layout, server, blocked, changed);
+ return rediwm_protocols_create(server.wl_server, server.backend, server.renderer, server.scene_outputs, server.output_layout, server, blocked, changed);
}
fn blocked(server: *Server) callconv(.c) bool {
return server.greeter_mode or server.locker != null or server.polkit_dialog != null or server.shutting_down;
diff --git a/src/glass.c b/src/glass.c
index 517e073..f5fb415 100644
--- a/src/glass.c
+++ b/src/glass.c
@@ -6,7 +6,6 @@
// reads the framebuffer, and resolve gives it the target's box (projection.c).
#define WLR_USE_UNSTABLE
#include <stdlib.h>
-#include <wlr/types/wlr_scene.h>
#include <wlr/util/addon.h>
#include "glass.h"
#include "node.h"
@@ -26,7 +25,7 @@ struct glass_effect {
struct wl_list link;
struct rediwm_buffer *node, *target;
struct wl_listener destroy, target_destroy;
- struct wlr_addon addon; // on the node's carrier, for rediwm_glass_effect_info
+ struct wlr_addon addon; // on the node, for rediwm_glass_effect_info
enum glass_kind kind;
uint64_t serial;
float radius, opacity;
@@ -61,13 +60,13 @@ static void handle_target_destroy(struct wl_listener *listener, void *data)
static void addon_destroy(struct wlr_addon *addon) { wlr_addon_finish(addon); }
static const struct wlr_addon_interface effect_addon = {.name = "rediwm glass effect",
.destroy = addon_destroy};
-static struct glass_effect *effect_of(struct wlr_scene_node *node)
+static struct glass_effect *effect_of(struct rediwm_node *node)
{
struct wlr_addon *addon = wlr_addon_find(&node->addons, NULL, &effect_addon);
struct glass_effect *effect;
return addon ? (effect = wl_container_of(addon, effect, addon)) : NULL;
}
-bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out)
+bool rediwm_glass_effect_info(struct rediwm_node *node, struct rediwm_glass_info *out)
{
struct glass_effect *effect = effect_of(node);
if (!effect)
@@ -84,9 +83,9 @@ bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_i
};
return true;
}
-bool rediwm_glass_is_effect_node(struct wlr_scene_node *node)
+bool rediwm_glass_is_effect_node(struct rediwm_node *node)
{
- return node->type == WLR_SCENE_NODE_BUFFER && effect_of(node);
+ return node->type == REDIWM_NODE_BUFFER && effect_of(node);
}
static bool accepts_input(struct rediwm_buffer *buffer, double *x, double *y)
{
@@ -115,7 +114,7 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,
effect->opacity = 1;
effect->serial = ++engine->next_serial;
effect->node->point_accepts_input = accepts_input;
- wlr_addon_init(&effect->addon, &effect->node->carrier->node.addons, NULL, &effect_addon);
+ wlr_addon_init(&effect->addon, &effect->node->node.addons, NULL, &effect_addon);
rediwm_node_place_below(&effect->node->node, before);
effect->destroy.notify = handle_destroy;
wl_signal_add(&effect->node->node.events.destroy, &effect->destroy);
diff --git a/src/glass.h b/src/glass.h
index 2595335..1f5ff9e 100644
--- a/src/glass.h
+++ b/src/glass.h
@@ -3,7 +3,7 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
-struct wlr_scene_node;
+struct rediwm_node;
struct rediwm_buffer;
struct rediwm_glass_info {
// The surface the effect backs: drawn over it, same parent, same box.
@@ -17,6 +17,6 @@ struct rediwm_glass_info {
// Keep the last blur while the effect moves (a dragged opaque titlebar, camera motion).
bool held;
};
-// False when `node` (the carrier of an effect's buffer node) is not a glass effect.
-bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out);
-bool rediwm_glass_is_effect_node(struct wlr_scene_node *node);
+// False when `node` is not a glass effect.
+bool rediwm_glass_effect_info(struct rediwm_node *node, struct rediwm_glass_info *out);
+bool rediwm_glass_is_effect_node(struct rediwm_node *node);
diff --git a/src/glass_test.c b/src/glass_test.c
index 6d5dddb..d28d26c 100644
--- a/src/glass_test.c
+++ b/src/glass_test.c
@@ -21,7 +21,9 @@ static void *glass_test_calloc(size_t count, size_t size)
#include <drm_fourcc.h>
#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/util/log.h>
+#include <wlr/types/wlr_output_layout.h>
#include "projection.h"
+#include "scene_outputs.h"
#include "scene_graph.h"
struct test_buffer {
@@ -42,41 +44,37 @@ static struct test_buffer *buffer_create(int width, int height)
}
static void registry_checks(void)
{
- struct wlr_scene *scene = wlr_scene_create();
- assert(scene);
- struct wlr_scene_tree *host = wlr_scene_tree_create(&scene->tree);
- wlr_scene_node_set_enabled(&host->node, false);
- struct rediwm_scene *own = rediwm_scene_create(host, NULL, NULL);
+ struct rediwm_scene *own = rediwm_scene_create(NULL, NULL);
assert(own);
struct glass_engine *engine = rediwm_glass_create();
assert(engine);
struct rediwm_buffer *target = rediwm_buffer_create(&own->tree, NULL);
rediwm_buffer_set_dest_size(target, 200, 60);
struct glass_effect *effect = rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);
- assert(effect && rediwm_glass_is_effect_node(&effect->node->carrier->node));
- assert(!rediwm_glass_is_effect_node(&target->carrier->node));
+ assert(effect && rediwm_glass_is_effect_node(&effect->node->node));
+ assert(!rediwm_glass_is_effect_node(&target->node));
// Below its target, so the blur reads what lies under the surface.
assert(effect->node->node.link.next == &target->node.link);
struct rediwm_glass_info info;
- assert(!rediwm_glass_effect_info(&target->carrier->node, &info));
- assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info));
+ assert(!rediwm_glass_effect_info(&target->node, &info));
+ assert(rediwm_glass_effect_info(&effect->node->node, &info));
assert(info.target == target && info.sigma == 22 && info.saturation == 1.5f && info.opacity == 1);
assert(!info.held && info.serial);
rediwm_glass_configure(effect, 10, .5f);
- assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info) && info.radius == 10 && info.opacity == .5f);
+ assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.radius == 10 && info.opacity == .5f);
// A node address may be reused; the serial is not.
struct rediwm_buffer *panel = rediwm_buffer_create(&own->tree, NULL);
struct glass_effect *other = rediwm_glass_attach(engine, panel, &panel->node, GLASS_PANEL);
struct rediwm_glass_info other_info;
- assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info));
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info));
assert(other_info.serial != info.serial && other_info.sigma == 26 && other_info.saturation == 1.6f);
// Holds: one dragged effect, or every effect during camera motion.
rediwm_glass_hold(engine, effect);
- assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info) && info.held);
- assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info) && !other_info.held);
+ assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.held);
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info) && !other_info.held);
rediwm_glass_hold(engine, NULL);
rediwm_glass_hold_all(engine, true);
- assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info) && other_info.held);
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info) && other_info.held);
rediwm_glass_hold_all(engine, false);
rediwm_glass_hold(engine, effect);
// Removing the target removes its effect, and a held one is released.
@@ -92,12 +90,12 @@ static void registry_checks(void)
assert(engine->held == NULL && wl_list_empty(&engine->effects));
assert(wl_list_length(&own->tree.children) == 1);
other = rediwm_glass_attach(engine, panel, &panel->node, GLASS_SIDEBAR);
- assert(other && rediwm_glass_effect_info(&other->node->carrier->node, &info));
+ assert(other && rediwm_glass_effect_info(&other->node->node, &info));
assert(info.serial != other_info.serial);
assert(info.sigma == 8 && info.saturation == 1.6f);
rediwm_glass_destroy(engine);
assert(wl_list_length(&own->tree.children) == 1); // the panel; its effect went
- wlr_scene_node_destroy(&scene->tree.node);
+ rediwm_scene_destroy(own);
fputs("PASS: glass registry: info, serials, holds, target lifetime, allocation failure\n", stderr);
}
static bool projection_input(struct rediwm_buffer *buffer, double *x, double *y) {
@@ -108,19 +106,17 @@ static bool projection_input(struct rediwm_buffer *buffer, double *x, double *y)
return true;
}
struct items { struct rediwm_item effect, target, client; };
-static struct wlr_scene_node *client_node;
-static bool find_items(const struct rediwm_item *item, struct wlr_scene_node *transport, void *data) {
+static struct rediwm_node *client_node;
+static bool find_items(const struct rediwm_item *item, struct rediwm_node *transport, void *data) {
struct items *found = data;
if (item->kind == REDIWM_ITEM_EFFECT) found->effect = *item;
else if (transport == client_node) found->client = *item;
- else if (transport->type == WLR_SCENE_NODE_BUFFER && !wlr_scene_buffer_from_node(transport)->buffer &&
+ else if (transport->type == REDIWM_NODE_BUFFER && !rediwm_buffer_from_node(transport)->buffer &&
item->width == 200) found->target = *item;
return true;
}
-static void projection_checks(struct wlr_scene *scene, struct glass_engine *engine) {
- struct wlr_scene_tree *host = wlr_scene_tree_create(&scene->tree);
- wlr_scene_node_set_enabled(&host->node, false);
- struct rediwm_scene *own = rediwm_scene_create(host, NULL, NULL);
+static void projection_checks(struct rediwm_scene_outputs *scene, struct glass_engine *engine) {
+ struct rediwm_scene *own = rediwm_scene_create(NULL, NULL);
struct rediwm_tree *source = rediwm_tree_create(&own->tree);
struct rediwm_projection *p = rediwm_projection_create(own, source, scene);
assert(own && source && p);
@@ -128,7 +124,7 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engi
rediwm_node_set_position(&frame->node, 101, 51);
struct test_buffer *image = buffer_create(400, 260);
struct rediwm_buffer *client = rediwm_buffer_create(frame, &image->base);
- client_node = &client->carrier->node;
+ client_node = &client->node;
wlr_buffer_drop(&image->base);
rediwm_buffer_set_source_box(client, &(struct wlr_fbox){10, 10, 380, 240});
rediwm_buffer_set_dest_size(client, 400, 260);
@@ -186,19 +182,24 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engi
assert(gone.client.width == 0 && gone.effect.kind != REDIWM_ITEM_EFFECT);
rediwm_projection_destroy(p);
rediwm_scene_destroy(own);
- wlr_scene_node_destroy(&host->node);
fputs("PASS: projection geometry, input, glass geometry and destruction\n", stderr);
}
int main(void)
{
wlr_log_init(WLR_ERROR, NULL);
registry_checks();
- struct wlr_scene *scene = wlr_scene_create();
+ struct wl_display *display = wl_display_create();
+ assert(display);
+ struct wlr_output_layout *layout = wlr_output_layout_create(display);
+ assert(layout);
+ struct rediwm_scene_outputs *scene = rediwm_scene_outputs_create(layout);
assert(scene);
struct glass_engine *engine = rediwm_glass_create();
assert(engine);
projection_checks(scene, engine);
rediwm_glass_destroy(engine);
- wlr_scene_node_destroy(&scene->tree.node);
+ rediwm_scene_outputs_destroy(scene);
+ wlr_output_layout_destroy(layout);
+ wl_display_destroy(display);
return 0;
}
diff --git a/src/ipc/handlers.zig b/src/ipc/handlers.zig
index 4027f73..549b65d 100644
--- a/src/ipc/handlers.zig
+++ b/src/ipc/handlers.zig
@@ -1227,7 +1227,7 @@ fn handleAction(
else
server.getDefaultOutput() orelse return .{ .err = "NoOutput" };
- const scene_output = server.scene.getSceneOutput(target_out.wlr_output) orelse return .{ .err = "NoSceneOutput" };
+ const scene_output = server.scene_outputs.get(target_out.wlr_output) orelse return .{ .err = "NoSceneOutput" };
var state = wlr.Output.State.init();
defer state.finish();
if (!server.buildOutputState(scene_output, &state)) return .{ .err = "CaptureFailed: scene render failed" };
diff --git a/src/node.c b/src/node.c
index 2894cc0..49aa723 100644
--- a/src/node.c
+++ b/src/node.c
@@ -3,8 +3,17 @@
#include "node.h"
#include <stdlib.h>
#include <string.h>
+#include <wlr/render/drm_syncobj.h>
+#include <wlr/render/wlr_renderer.h>
+#include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_buffer.h>
-#include <wlr/types/wlr_scene.h>
+#include <wlr/types/wlr_compositor.h>
+#include <wlr/types/wlr_single_pixel_buffer_v1.h>
+
+static void buffer_set_buffer(struct rediwm_buffer *b, struct wlr_buffer *buffer);
+static void buffer_set_texture(struct rediwm_buffer *b, struct wlr_texture *texture);
+static void buffer_set_wait_timeline(struct rediwm_buffer *b, struct wlr_drm_syncobj_timeline *timeline,
+ uint64_t point);
// A change to `node`'s own state; `structural` when the tree's shape changed (nodes made,
// moved, stacked or destroyed), which the owner treats as a change of everything.
@@ -31,7 +40,7 @@ static void node_init(struct rediwm_node *node, enum rediwm_node_type type, stru
node->enabled = true;
node->x = node->y = 0;
node->data = NULL;
- node->props = node->group = NULL;
+ node->props = node->group = node->leaf = NULL;
wl_signal_init(&node->events.destroy);
wlr_addon_set_init(&node->addons);
wl_list_init(&node->link);
@@ -43,12 +52,10 @@ static void node_init(struct rediwm_node *node, enum rediwm_node_type type, stru
}
}
-struct rediwm_scene *rediwm_scene_create(struct wlr_scene_tree *host,
- void (*notify)(void *, struct rediwm_node *, bool),
+struct rediwm_scene *rediwm_scene_create(void (*notify)(void *, struct rediwm_node *, bool),
void *data) {
struct rediwm_scene *scene = calloc(1, sizeof(*scene));
if (!scene) return NULL;
- scene->host = host;
node_init(&scene->tree.node, REDIWM_NODE_TREE, NULL);
wl_list_init(&scene->tree.children);
scene->tree.node.scene = scene;
@@ -77,11 +84,6 @@ struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, in
const float color[4]) {
struct rediwm_rect *rect = calloc(1, sizeof(*rect));
if (!rect) return NULL;
- rect->carrier = wlr_scene_rect_create(parent->node.scene->host, width, height, color);
- if (!rect->carrier) {
- free(rect);
- return NULL;
- }
node_init(&rect->node, REDIWM_NODE_RECT, parent);
rect->width = width;
rect->height = height;
@@ -93,25 +95,21 @@ struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, in
struct rediwm_buffer *rediwm_buffer_create(struct rediwm_tree *parent, struct wlr_buffer *buffer) {
struct rediwm_buffer *b = calloc(1, sizeof(*b));
if (!b) return NULL;
- b->carrier = wlr_scene_buffer_create(parent->node.scene->host, NULL);
- if (!b->carrier) {
- free(b);
- return NULL;
- }
node_init(&b->node, REDIWM_NODE_BUFFER, parent);
b->opacity = 1;
b->filter_mode = WLR_SCALE_FILTER_BILINEAR;
b->transform = WL_OUTPUT_TRANSFORM_NORMAL;
pixman_region32_init(&b->opaque_region);
+ wl_list_init(&b->buffer_release.link);
+ wl_list_init(&b->renderer_destroy.link);
+ wl_signal_init(&b->events.outputs_update);
+ wl_signal_init(&b->events.output_sample);
+ wl_signal_init(&b->events.frame_done);
if (buffer) rediwm_buffer_set_buffer(b, buffer);
structure(&b->node);
return b;
}
-struct wlr_scene_tree *rediwm_tree_host(const struct rediwm_tree *tree) {
- return tree->node.scene->host;
-}
-
void rediwm_node_destroy(struct rediwm_node *node) {
if (!node) return;
wl_signal_emit_mutable(&node->events.destroy, NULL);
@@ -119,11 +117,11 @@ void rediwm_node_destroy(struct rediwm_node *node) {
struct rediwm_tree *tree = (struct rediwm_tree *)node;
struct rediwm_node *child, *tmp;
wl_list_for_each_safe(child, tmp, &tree->children, link) rediwm_node_destroy(child);
- } else if (node->type == REDIWM_NODE_RECT) {
- wlr_scene_node_destroy(&((struct rediwm_rect *)node)->carrier->node);
} else if (node->type == REDIWM_NODE_BUFFER) {
struct rediwm_buffer *b = (struct rediwm_buffer *)node;
- wlr_scene_node_destroy(&b->carrier->node);
+ buffer_set_buffer(b, NULL);
+ buffer_set_texture(b, NULL);
+ buffer_set_wait_timeline(b, NULL, 0);
pixman_region32_fini(&b->opaque_region);
}
// Report before the node and its scene are gone; a root has no parent to tell.
@@ -223,54 +221,135 @@ void rediwm_rect_set_size(struct rediwm_rect *rect, int width, int height) {
if (rect->width == width && rect->height == height) return;
rect->width = width;
rect->height = height;
- wlr_scene_rect_set_size(rect->carrier, width, height);
changed(&rect->node);
}
void rediwm_rect_set_color(struct rediwm_rect *rect, const float color[4]) {
if (!memcmp(rect->color, color, sizeof(rect->color))) return;
memcpy(rect->color, color, sizeof(rect->color));
- wlr_scene_rect_set_color(rect->carrier, color);
changed(&rect->node);
}
-void rediwm_buffer_set_buffer(struct rediwm_buffer *b, struct wlr_buffer *buffer) {
+static void buffer_released(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_buffer *b = wl_container_of(listener, b, buffer_release);
+ b->buffer = NULL;
+ wl_list_remove(&b->buffer_release.link);
+ wl_list_init(&b->buffer_release.link);
+}
+
+// As wlr_scene's scene_buffer_set_buffer: the node locks what it shows, and lets it
+// go if the buffer is released first.
+static void buffer_set_buffer(struct rediwm_buffer *b, struct wlr_buffer *buffer) {
+ wl_list_remove(&b->buffer_release.link);
+ wl_list_init(&b->buffer_release.link);
+ if (b->own_buffer) wlr_buffer_unlock(b->buffer);
+ b->buffer = NULL;
+ b->own_buffer = false;
+ b->buffer_width = b->buffer_height = 0;
+ b->buffer_is_opaque = false;
+
+ if (!buffer) return;
+
+ b->own_buffer = true;
+ b->buffer = wlr_buffer_lock(buffer);
+ b->buffer_width = buffer->width;
+ b->buffer_height = buffer->height;
+ b->buffer_is_opaque = wlr_buffer_is_opaque(buffer);
+
+ b->buffer_release.notify = buffer_released;
+ wl_signal_add(&buffer->events.release, &b->buffer_release);
+}
+
+static void texture_renderer_destroyed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_buffer *b = wl_container_of(listener, b, renderer_destroy);
+ buffer_set_texture(b, NULL);
+}
+
+static void buffer_set_texture(struct rediwm_buffer *b, struct wlr_texture *texture) {
+ wl_list_remove(&b->renderer_destroy.link);
+ wlr_texture_destroy(b->texture);
+ b->texture = texture;
+
+ if (texture != NULL) {
+ b->renderer_destroy.notify = texture_renderer_destroyed;
+ wl_signal_add(&texture->renderer->events.destroy, &b->renderer_destroy);
+ } else {
+ wl_list_init(&b->renderer_destroy.link);
+ }
+}
+
+void rediwm_buffer_set_texture(struct rediwm_buffer *b, struct wlr_texture *texture) {
+ buffer_set_texture(b, texture);
+}
+
+static void buffer_set_wait_timeline(struct rediwm_buffer *b, struct wlr_drm_syncobj_timeline *timeline,
+ uint64_t point) {
+ wlr_drm_syncobj_timeline_unref(b->wait_timeline);
+ if (timeline != NULL) {
+ b->wait_timeline = wlr_drm_syncobj_timeline_ref(timeline);
+ b->wait_point = point;
+ } else {
+ b->wait_timeline = NULL;
+ b->wait_point = 0;
+ }
+}
+
+void rediwm_buffer_set_buffer_with_options(struct rediwm_buffer *b, struct wlr_buffer *buffer,
+ const struct rediwm_buffer_options *options) {
+ static const struct rediwm_buffer_options none = {0};
+ if (!options) options = &none;
+
+ // If this is a buffer change, check if it's a single pixel buffer. Cache that so the
+ // pass can still draw it as a colour when the original buffer has been freed after
+ // texture upload.
+ if (buffer != b->buffer) {
+ b->is_single_pixel_buffer = false;
+ struct wlr_client_buffer *client_buffer = buffer ? wlr_client_buffer_get(buffer) : NULL;
+ if (client_buffer != NULL && client_buffer->source != NULL) {
+ struct wlr_single_pixel_buffer_v1 *spb = wlr_single_pixel_buffer_v1_try_from_buffer(client_buffer->source);
+ if (spb != NULL) {
+ b->is_single_pixel_buffer = true;
+ b->single_pixel_buffer_color[0] = spb->r;
+ b->single_pixel_buffer_color[1] = spb->g;
+ b->single_pixel_buffer_color[2] = spb->b;
+ b->single_pixel_buffer_color[3] = spb->a;
+ }
+ }
+ }
+
// A buffer set again is new content even if the pointer matches: a compositor-owned
// buffer is redrawn in place, and the projection is told its damage separately.
- wlr_scene_buffer_set_buffer(b->carrier, buffer);
- b->buffer_width = buffer ? buffer->width : 0;
- b->buffer_height = buffer ? buffer->height : 0;
- buffer_damaged(b, NULL);
+ buffer_set_buffer(b, buffer);
+ buffer_set_texture(b, NULL);
+ buffer_set_wait_timeline(b, options->wait_timeline, options->wait_point);
+ buffer_damaged(b, options->damage);
changed(&b->node);
}
-void rediwm_buffer_set_buffer_with_options(struct rediwm_buffer *b, struct wlr_buffer *buffer,
- const struct wlr_scene_buffer_set_buffer_options *options) {
- wlr_scene_buffer_set_buffer_with_options(b->carrier, buffer, options);
- b->buffer_width = buffer ? buffer->width : 0;
- b->buffer_height = buffer ? buffer->height : 0;
- buffer_damaged(b, options ? options->damage : NULL);
- changed(&b->node);
+void rediwm_buffer_set_buffer(struct rediwm_buffer *b, struct wlr_buffer *buffer) {
+ rediwm_buffer_set_buffer_with_options(b, buffer, NULL);
}
-void rediwm_buffer_set_buffer_with_damage(struct rediwm_buffer *b, struct wlr_buffer *buffer,
- const pixman_region32_t *damage) {
- wlr_scene_buffer_set_buffer_with_damage(b->carrier, buffer, damage);
- b->buffer_width = buffer ? buffer->width : 0;
- b->buffer_height = buffer ? buffer->height : 0;
- buffer_damaged(b, damage);
- changed(&b->node);
+void rediwm_buffer_set_content(struct rediwm_buffer *b, struct wlr_buffer *buffer) {
+ buffer_set_buffer(b, buffer);
+ buffer_set_texture(b, NULL);
+ buffer_set_wait_timeline(b, NULL, 0);
}
-struct wlr_buffer *rediwm_buffer_get_buffer(const struct rediwm_buffer *b) {
- return b->carrier->buffer;
+void rediwm_buffer_set_buffer_with_damage(struct rediwm_buffer *b, struct wlr_buffer *buffer,
+ const pixman_region32_t *damage) {
+ const struct rediwm_buffer_options options = {.damage = damage};
+ rediwm_buffer_set_buffer_with_options(b, buffer, &options);
}
+struct wlr_buffer *rediwm_buffer_get_buffer(const struct rediwm_buffer *b) { return b->buffer; }
+
void rediwm_buffer_set_dest_size(struct rediwm_buffer *b, int width, int height) {
if (b->dst_width == width && b->dst_height == height) return;
b->dst_width = width;
b->dst_height = height;
- wlr_scene_buffer_set_dest_size(b->carrier, width, height);
changed(&b->node);
}
@@ -279,28 +358,24 @@ void rediwm_buffer_set_source_box(struct rediwm_buffer *b, const struct wlr_fbox
const struct wlr_fbox *next = box ? box : &none;
if (!memcmp(&b->src_box, next, sizeof(*next))) return;
b->src_box = *next;
- wlr_scene_buffer_set_source_box(b->carrier, box);
changed(&b->node);
}
void rediwm_buffer_set_opacity(struct rediwm_buffer *b, float opacity) {
if (b->opacity == opacity) return;
b->opacity = opacity;
- wlr_scene_buffer_set_opacity(b->carrier, opacity);
changed(&b->node);
}
void rediwm_buffer_set_filter_mode(struct rediwm_buffer *b, enum wlr_scale_filter_mode mode) {
if (b->filter_mode == mode) return;
b->filter_mode = mode;
- wlr_scene_buffer_set_filter_mode(b->carrier, mode);
changed(&b->node);
}
void rediwm_buffer_set_transform(struct rediwm_buffer *b, enum wl_output_transform transform) {
if (b->transform == transform) return;
b->transform = transform;
- wlr_scene_buffer_set_transform(b->carrier, transform);
changed(&b->node);
}
@@ -312,7 +387,6 @@ void rediwm_buffer_set_opaque_region(struct rediwm_buffer *b, const pixman_regio
if (pixman_region32_equal((pixman_region32_t *)region, &b->opaque_region)) return;
pixman_region32_copy(&b->opaque_region, region);
}
- wlr_scene_buffer_set_opaque_region(b->carrier, &b->opaque_region);
changed(&b->node);
}
diff --git a/src/node.h b/src/node.h
index 55939eb..fa49062 100644
--- a/src/node.h
+++ b/src/node.h
@@ -1,6 +1,7 @@
// The compositor's own scene nodes (stage 7 of docs/plans/scene-graph-stage7.md).
//
-// What wlr_scene gave the compositor as a data model: a tree of nodes with a
+// What wlr_scene gave the compositor as a data model (and the compositor no longer links
+// it): a tree of nodes with a
// position, an enabled flag and an owner pointer, whose leaves are buffers or
// rectangles. It does no drawing, damage or picking here; the projection resolves
// the tree into items and the output pass draws them. Every mutator that can change
@@ -19,15 +20,16 @@
#include <stdint.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol.h>
+#include <wlr/render/color.h>
#include <wlr/render/pass.h>
#include <wlr/util/addon.h>
#include <wlr/util/box.h>
struct wlr_buffer;
-struct wlr_scene_buffer;
-struct wlr_scene_rect;
-struct wlr_scene_tree;
+struct wlr_texture;
+struct wlr_drm_syncobj_timeline;
struct rediwm_scene;
+struct rediwm_scene_outputs;
struct rediwm_tree;
enum rediwm_node_type {
@@ -48,8 +50,9 @@ struct rediwm_node {
} events;
struct wlr_addon_set addons;
// The projection's per-node state, found without a walk of `addons` on every sync:
- // a tree's presentation properties and the group a top-level node is.
- void *props, *group;
+ // a tree's presentation properties, the group a top-level node is, and the leaf a
+ // buffer or rect is.
+ void *props, *group, *leaf;
struct rediwm_scene *scene;
};
@@ -61,22 +64,18 @@ struct rediwm_tree {
struct rediwm_rect {
struct rediwm_node node;
int width, height;
- float color[4]; // premultiplied, as wlr_scene_rect
- // The hidden wlr_scene rect the output pass reads the colour from, kept in step.
- struct wlr_scene_rect *carrier;
+ float color[4]; // premultiplied
};
struct rediwm_buffer;
struct rediwm_surface;
typedef bool (*rediwm_buffer_point_accepts_input)(struct rediwm_buffer *, double *x, double *y);
-// Geometry and content state live here; the pixels themselves (the locked buffer,
-// its texture, wait points, single-pixel colour) are carried by a hidden wlr_scene
-// buffer the output pass already knows how to read. Every setter keeps the two in
-// step. Stage 7c replaces the carrier with the pass's own texture cache.
+// A buffer node shows a wlr_buffer, or a colour, or nothing: the content is held here
+// (the lock, the texture the output pass uploads, wait points, a single-pixel colour),
+// as wlr_scene_buffer keeps it, and the setters keep it in step with the geometry.
struct rediwm_buffer {
struct rediwm_node node;
- struct wlr_scene_buffer *carrier;
rediwm_buffer_point_accepts_input point_accepts_input; // may be NULL
float opacity;
enum wlr_scale_filter_mode filter_mode;
@@ -88,13 +87,33 @@ struct rediwm_buffer {
int buffer_width, buffer_height;
// The client surface this node shows, or NULL (node_surface.h).
struct rediwm_surface *surface;
+
+ // Content. `buffer` is NULL once the renderer has uploaded it and let it go (the
+ // texture then stands for it). `own_buffer`: this node holds a lock on `buffer`.
+ struct wlr_buffer *buffer;
+ bool own_buffer;
+ struct wl_listener buffer_release;
+ struct wlr_texture *texture;
+ struct wl_listener renderer_destroy;
+ struct wlr_drm_syncobj_timeline *wait_timeline;
+ uint64_t wait_point;
+ bool buffer_is_opaque;
+ bool is_single_pixel_buffer;
+ uint32_t single_pixel_buffer_color[4];
+ enum wlr_color_transfer_function transfer_function;
+ enum wlr_color_named_primaries primaries;
+ enum wlr_color_encoding color_encoding;
+ enum wlr_color_range color_range;
+ // What the output pass reports of a surface node (scene_outputs.h).
+ struct {
+ struct wl_signal outputs_update; // struct rediwm_outputs_update_event
+ struct wl_signal output_sample; // struct rediwm_output_sample_event
+ struct wl_signal frame_done; // struct rediwm_frame_done_event
+ } events;
};
struct rediwm_scene {
struct rediwm_tree tree;
- // A hidden, disabled wlr_scene tree that hosts every buffer's carrier, so wlroots
- // computes nothing for them.
- struct wlr_scene_tree *host;
// Something the tree shows may have changed: the owner schedules a frame.
// `node` is the one that changed (NULL when it is gone); `structural` when nodes
// were made, moved, stacked or destroyed, or a layer changed.
@@ -104,6 +123,8 @@ struct rediwm_scene {
// this into screen damage, as wlroots did for the nodes it tracked.
void (*buffer_damaged)(void *data, struct rediwm_buffer *, const pixman_region32_t *damage);
void *changed_data;
+ // The outputs this scene is shown on (what surfaces are told about).
+ struct rediwm_scene_outputs *outputs;
};
static inline struct rediwm_tree *rediwm_tree_from_node(struct rediwm_node *node) {
@@ -116,9 +137,8 @@ static inline struct rediwm_buffer *rediwm_buffer_from_node(struct rediwm_node *
return node->type == REDIWM_NODE_BUFFER ? (struct rediwm_buffer *)node : NULL;
}
-// A scene is its root tree. `host` is where carriers live (the caller disables it); `changed` may be NULL.
-struct rediwm_scene *rediwm_scene_create(struct wlr_scene_tree *host,
- void (*changed)(void *, struct rediwm_node *, bool),
+// A scene is its root tree; `changed` may be NULL.
+struct rediwm_scene *rediwm_scene_create(void (*changed)(void *, struct rediwm_node *, bool),
void *data);
void rediwm_scene_destroy(struct rediwm_scene *);
@@ -128,8 +148,6 @@ struct rediwm_tree *rediwm_tree_create(struct rediwm_tree *parent);
struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, int height,
const float color[4]);
struct rediwm_buffer *rediwm_buffer_create(struct rediwm_tree *parent, struct wlr_buffer *);
-// Where the scene's carriers are made.
-struct wlr_scene_tree *rediwm_tree_host(const struct rediwm_tree *);
// Destroys the node and everything under it; each node emits events.destroy first.
void rediwm_node_destroy(struct rediwm_node *);
@@ -160,11 +178,22 @@ void rediwm_buffer_set_buffer(struct rediwm_buffer *, struct wlr_buffer *);
// As wlr_scene_buffer_set_buffer_with_damage: `damage` is buffer-local.
void rediwm_buffer_set_buffer_with_damage(struct rediwm_buffer *, struct wlr_buffer *,
const pixman_region32_t *damage);
-// As wlr_scene_buffer_set_buffer_with_options: damage plus an acquire point to wait for.
-struct wlr_scene_buffer_set_buffer_options;
+// Damage (buffer-local, NULL for all of it) plus an acquire point to wait for before
+// the buffer is read.
+struct rediwm_buffer_options {
+ const pixman_region32_t *damage;
+ struct wlr_drm_syncobj_timeline *wait_timeline;
+ uint64_t wait_point;
+};
void rediwm_buffer_set_buffer_with_options(struct rediwm_buffer *, struct wlr_buffer *,
- const struct wlr_scene_buffer_set_buffer_options *);
-// The buffer the carrier holds; NULL once the renderer released it after upload.
+ const struct rediwm_buffer_options *);
+// Replaces the content without telling the scene or the projection: for a caller that
+// reports the damage itself (rediwm_projection_present_owned).
+void rediwm_buffer_set_content(struct rediwm_buffer *, struct wlr_buffer *);
+// The renderer's texture of the content, kept until the next buffer is set (the pass
+// uploads it); NULL drops it.
+void rediwm_buffer_set_texture(struct rediwm_buffer *, struct wlr_texture *);
+// The buffer the node holds; NULL once the renderer released it after upload.
struct wlr_buffer *rediwm_buffer_get_buffer(const struct rediwm_buffer *);
void rediwm_buffer_set_dest_size(struct rediwm_buffer *, int width, int height);
void rediwm_buffer_set_source_box(struct rediwm_buffer *, const struct wlr_fbox *);
diff --git a/src/node.zig b/src/node.zig
index 468eda1..f98898f 100644
--- a/src/node.zig
+++ b/src/node.zig
@@ -25,6 +25,7 @@ pub const Node = extern struct {
addons: wlr.AddonSet,
props: ?*anyopaque,
group: ?*anyopaque,
+ leaf: ?*anyopaque,
scene: *Scene,
extern fn rediwm_node_destroy(node: *Node) void;
@@ -125,10 +126,6 @@ pub const Tree = extern struct {
return rediwm_buffer_create(parent, buffer) orelse error.OutOfMemory;
}
- extern fn rediwm_tree_host(tree: *const Tree) *wlr.SceneTree;
- /// The hidden wlr_scene tree that holds the buffers' carriers.
- pub const host = rediwm_tree_host;
-
extern fn rediwm_xdg_surface_create(parent: *Tree, xdg_surface: *wlr.XdgSurface) ?*Tree;
pub fn createSceneXdgSurface(parent: *Tree, xdg_surface: *wlr.XdgSurface) !*Tree {
return rediwm_xdg_surface_create(parent, xdg_surface) orelse error.OutOfMemory;
@@ -154,7 +151,6 @@ pub const Rect = extern struct {
width: c_int,
height: c_int,
color: [4]f32,
- carrier: *wlr.SceneRect,
extern fn rediwm_rect_set_color(rect: *Rect, color: *const [4]f32) void;
pub const setColor = rediwm_rect_set_color;
@@ -168,8 +164,6 @@ pub const Rect = extern struct {
pub const Buffer = extern struct {
node: Node,
- /// The hidden wlr_scene buffer that carries the pixels (see node.h).
- carrier: *wlr.SceneBuffer,
point_accepts_input: ?*const fn (buffer: *Buffer, sx: *f64, sy: *f64) callconv(.c) bool,
opacity: f32,
filter_mode: wlr.RenderPass.ScaleFilterMode,
@@ -182,11 +176,31 @@ pub const Buffer = extern struct {
buffer_height: c_int,
/// The client surface this node shows, if it is one.
surface: ?*Surface,
+ /// The content (see node.h): null `buffer` once the renderer uploaded it and let it go.
+ buffer: ?*wlr.Buffer,
+ own_buffer: bool,
+ buffer_release: wl.Listener(void),
+ texture: ?*wlr.Texture,
+ renderer_destroy: wl.Listener(void),
+ wait_timeline: ?*wlr.DrmSyncobjTimeline,
+ wait_point: u64,
+ buffer_is_opaque: bool,
+ is_single_pixel_buffer: bool,
+ single_pixel_buffer_color: [4]u32,
+ transfer_function: u32,
+ primaries: u32,
+ color_encoding: u32,
+ color_range: u32,
+ events: extern struct {
+ outputs_update: wl.Signal(?*anyopaque),
+ output_sample: wl.Signal(?*anyopaque),
+ frame_done: wl.Signal(?*anyopaque),
+ },
extern fn rediwm_buffer_set_buffer(buffer: *Buffer, wlr_buffer: ?*wlr.Buffer) void;
pub const setBuffer = rediwm_buffer_set_buffer;
extern fn rediwm_buffer_get_buffer(buffer: *const Buffer) ?*wlr.Buffer;
- /// The buffer the carrier holds; null once the renderer released it after upload.
+ /// The buffer the node holds; null once the renderer released it after upload.
pub const getBuffer = rediwm_buffer_get_buffer;
extern fn rediwm_buffer_set_buffer_with_damage(buffer: *Buffer, wlr_buffer: ?*wlr.Buffer, damage: *const pixman.Region32) void;
pub const setBufferWithDamage = rediwm_buffer_set_buffer_with_damage;
@@ -218,35 +232,29 @@ pub const Surface = extern struct {
/// The own scene: its root tree's children are the layers, bottom to top.
pub const Scene = extern struct {
tree: Tree,
- host: *wlr.SceneTree,
changed: ?*const fn (data: ?*anyopaque, node: ?*Node, structural: bool) callconv(.c) void,
buffer_damaged: ?*const fn (data: ?*anyopaque, buffer: *Buffer, damage: ?*const pixman.Region32) callconv(.c) void,
changed_data: ?*anyopaque,
+ /// The outputs this scene is shown on (scene_outputs.h).
+ outputs: ?*anyopaque,
- extern fn rediwm_scene_create(host: *wlr.SceneTree, changed: ?*const fn (?*anyopaque, ?*Node, bool) callconv(.c) void, data: ?*anyopaque) ?*Scene;
- /// `host` is a hidden, disabled wlr_scene tree for the buffers' carriers.
- pub fn create(host: *wlr.SceneTree) !*Scene {
- return rediwm_scene_create(host, null, null) orelse error.OutOfMemory;
+ extern fn rediwm_scene_create(changed: ?*const fn (?*anyopaque, ?*Node, bool) callconv(.c) void, data: ?*anyopaque) ?*Scene;
+ pub fn create() !*Scene {
+ return rediwm_scene_create(null, null) orelse error.OutOfMemory;
}
extern fn rediwm_scene_destroy(scene: ?*Scene) void;
pub const destroy = rediwm_scene_destroy;
};
-/// A scene for unit tests: a wlroots scene with the own scene's hidden host in it.
+/// A scene for unit tests.
pub const TestScene = struct {
- wlr_scene: *wlr.Scene,
nodes: *Scene,
pub fn create() !TestScene {
- const wlr_scene = try wlr.Scene.create();
- errdefer wlr_scene.tree.node.destroy();
- const host = try wlr_scene.tree.createSceneTree();
- host.node.setEnabled(false);
- return .{ .wlr_scene = wlr_scene, .nodes = try Scene.create(host) };
+ return .{ .nodes = try Scene.create() };
}
pub fn destroy(fixture: TestScene) void {
fixture.nodes.destroy();
- fixture.wlr_scene.tree.node.destroy();
}
};
diff --git a/src/node_surface.c b/src/node_surface.c
index c3d7ca3..445a7f2 100644
--- a/src/node_surface.c
+++ b/src/node_surface.c
@@ -17,7 +17,7 @@
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_presentation_time.h>
-#include <wlr/types/wlr_scene.h>
+#include "scene_outputs.h"
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xdg_shell.h>
@@ -94,18 +94,10 @@ static void get_surface_preferred_image_description(struct wlr_surface *surface,
};
}
-// The wlr_scene whose host holds the node's carrier: it knows the outputs and the colour
-// manager (stage 7c replaces both with plain pointers).
-static struct wlr_scene *carrier_scene(struct wlr_scene_buffer *carrier) {
- struct wlr_scene_tree *tree = carrier->node.parent;
- while (tree->node.parent) tree = tree->node.parent;
- return wl_container_of(tree, (struct wlr_scene *)NULL, tree);
-}
-
static void handle_scene_buffer_outputs_update(struct wl_listener *listener, void *data) {
struct rediwm_surface *surface = wl_container_of(listener, surface, outputs_update);
- struct wlr_scene_outputs_update_event *event = data;
- struct wlr_scene *scene = carrier_scene(surface->buffer->carrier);
+ struct rediwm_outputs_update_event *event = data;
+ struct rediwm_scene_outputs *scene = surface->buffer->node.scene->outputs;
// If the surface is no longer visible on any output in the scene, keep the last sent
// preferred configuration to avoid unnecessary redraws.
@@ -130,8 +122,8 @@ static void handle_scene_buffer_outputs_update(struct wl_listener *listener, voi
}
}
- struct wlr_scene_output *scene_output;
- wl_list_for_each(scene_output, &scene->outputs, link) {
+ struct rediwm_scene_output *scene_output;
+ if (scene) wl_list_for_each(scene_output, &scene->outputs, link) {
if (scene_output->output == entered_output->output) {
entered_output->private.suspended = suspend;
if (!suspend && !active) wlr_surface_send_leave(surface->surface, entered_output->output);
@@ -154,7 +146,7 @@ static void handle_scene_buffer_outputs_update(struct wl_listener *listener, voi
wlr_fractional_scale_v1_notify_scale(surface->surface, scale);
wlr_surface_set_preferred_buffer_scale(surface->surface, ceil(scale));
- if (scene->color_manager_v1 != NULL) {
+ if (scene && scene->color_manager_v1 != NULL) {
struct wlr_image_description_v1_data img_desc = {0};
get_surface_preferred_image_description(surface->surface, &img_desc);
wlr_color_manager_v1_set_surface_preferred_image_description(scene->color_manager_v1,
@@ -164,7 +156,7 @@ static void handle_scene_buffer_outputs_update(struct wl_listener *listener, voi
static void handle_scene_buffer_output_sample(struct wl_listener *listener, void *data) {
struct rediwm_surface *surface = wl_container_of(listener, surface, output_sample);
- const struct wlr_scene_output_sample_event *event = data;
+ const struct rediwm_output_sample_event *event = data;
struct wlr_output *output = event->output->output;
if (get_surface_frame_pacing_output(surface->surface) != output) return;
@@ -183,7 +175,7 @@ static void handle_scene_buffer_output_sample(struct wl_listener *listener, void
static void handle_scene_buffer_frame_done(struct wl_listener *listener, void *data) {
struct rediwm_surface *surface = wl_container_of(listener, surface, frame_done);
- struct wlr_scene_frame_done_event *event = data;
+ struct rediwm_frame_done_event *event = data;
if (get_surface_frame_pacing_output(surface->surface) != event->output->output) return;
wlr_surface_send_frame_done(surface->surface, &event->when);
@@ -202,7 +194,7 @@ static void client_buffer_mark_next_can_damage(struct wlr_client_buffer *buffer)
buffer->private.n_ignore_locks++;
}
-static void carrier_unmark_client_buffer(struct wlr_scene_buffer *scene_buffer) {
+static void unmark_client_buffer(struct rediwm_buffer *scene_buffer) {
if (!scene_buffer->buffer) return;
struct wlr_client_buffer *buffer = wlr_client_buffer_get(scene_buffer->buffer);
@@ -217,7 +209,6 @@ static int min(int a, int b) { return a < b ? a : b; }
static void surface_reconfigure(struct rediwm_surface *scene_surface) {
struct rediwm_buffer *scene_buffer = scene_surface->buffer;
- struct wlr_scene_buffer *carrier = scene_buffer->carrier;
struct wlr_surface *surface = scene_surface->surface;
struct wlr_surface_state *state = &surface->current;
@@ -290,13 +281,13 @@ static void surface_reconfigure(struct rediwm_surface *scene_surface) {
rediwm_buffer_set_dest_size(scene_buffer, width, height);
rediwm_buffer_set_transform(scene_buffer, state->transform);
rediwm_buffer_set_opacity(scene_buffer, opacity);
- // The colour description is the carrier's alone: the buffer set below reports it.
- wlr_scene_buffer_set_transfer_function(carrier, tf);
- wlr_scene_buffer_set_primaries(carrier, primaries);
- wlr_scene_buffer_set_color_encoding(carrier, color_encoding);
- wlr_scene_buffer_set_color_range(carrier, color_range);
+ // The colour description has no setters of its own: the buffer set below reports it.
+ scene_buffer->transfer_function = tf;
+ scene_buffer->primaries = primaries;
+ scene_buffer->color_encoding = color_encoding;
+ scene_buffer->color_range = color_range;
- carrier_unmark_client_buffer(carrier);
+ unmark_client_buffer(scene_buffer);
if (surface->buffer) {
// If we've cached the buffer's single-pixel buffer color then any in-place updates
@@ -314,7 +305,7 @@ static void surface_reconfigure(struct rediwm_surface *scene_surface) {
struct wlr_linux_drm_syncobj_surface_v1_state *syncobj_surface_state =
wlr_linux_drm_syncobj_v1_get_surface_state(surface);
- struct wlr_scene_buffer_set_buffer_options options = {
+ struct rediwm_buffer_options options = {
.damage = &surface->buffer_damage,
};
if (syncobj_surface_state != NULL) {
@@ -358,7 +349,7 @@ static void surface_node_destroyed(struct wl_listener *listener, void *data) {
(void)data;
struct rediwm_surface *surface = wl_container_of(listener, surface, node_destroy);
- carrier_unmark_client_buffer(surface->buffer->carrier);
+ unmark_client_buffer(surface->buffer);
surface->buffer->surface = NULL;
surface->buffer->point_accepts_input = NULL;
@@ -386,19 +377,18 @@ struct rediwm_surface *rediwm_surface_create(struct rediwm_tree *parent, struct
surface->surface = wlr_surface;
scene_buffer->surface = surface;
scene_buffer->point_accepts_input = scene_buffer_point_accepts_input;
- struct wlr_scene_buffer *carrier = scene_buffer->carrier;
surface->node_destroy.notify = surface_node_destroyed;
wl_signal_add(&scene_buffer->node.events.destroy, &surface->node_destroy);
surface->outputs_update.notify = handle_scene_buffer_outputs_update;
- wl_signal_add(&carrier->events.outputs_update, &surface->outputs_update);
+ wl_signal_add(&scene_buffer->events.outputs_update, &surface->outputs_update);
surface->output_sample.notify = handle_scene_buffer_output_sample;
- wl_signal_add(&carrier->events.output_sample, &surface->output_sample);
+ wl_signal_add(&scene_buffer->events.output_sample, &surface->output_sample);
surface->frame_done.notify = handle_scene_buffer_frame_done;
- wl_signal_add(&carrier->events.frame_done, &surface->frame_done);
+ wl_signal_add(&scene_buffer->events.frame_done, &surface->frame_done);
surface->surface_destroy.notify = scene_surface_handle_surface_destroy;
wl_signal_add(&wlr_surface->events.destroy, &surface->surface_destroy);
diff --git a/src/node_surface.h b/src/node_surface.h
index 38f4f58..70f2150 100644
--- a/src/node_surface.h
+++ b/src/node_surface.h
@@ -4,9 +4,9 @@
// and wlr_scene_drag_icon onto own nodes (MIT licensed, as
// wlroots; the logic follows types/scene/*.c of wlroots 0.20). A surface is an own buffer
// node whose content follows the wl_surface; a surface with subsurfaces is a tree of
-// them, stacked as the protocol orders them. The pixels still ride on the buffer's
-// carrier (node.h), whose signals the projection raises where wlr_scene_output once did:
-// outputs_update, output_sample and frame_done.
+// them, stacked as the protocol orders them. The binding listens to the buffer node's
+// signals, which the projection and the output pass raise: outputs_update,
+// output_sample and frame_done.
#pragma once
#include "node.h"
#include <wlr/util/box.h>
diff --git a/src/node_test.c b/src/node_test.c
index 7f254c5..b93be5c 100644
--- a/src/node_test.c
+++ b/src/node_test.c
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/types/wlr_buffer.h>
-#include <wlr/types/wlr_scene.h>
static int changes;
static void on_change(void *data, struct rediwm_node *node, bool structural) {
@@ -55,11 +54,7 @@ static void collect(struct rediwm_buffer *b, int sx, int sy, void *data) {
}
int main(void) {
- struct wlr_scene *wlr_scene = wlr_scene_create();
- assert(wlr_scene);
- struct wlr_scene_tree *host = wlr_scene_tree_create(&wlr_scene->tree);
- wlr_scene_node_set_enabled(&host->node, false);
- struct rediwm_scene *scene = rediwm_scene_create(host, on_change, NULL);
+ struct rediwm_scene *scene = rediwm_scene_create(on_change, NULL);
assert(scene && scene->tree.node.enabled && !scene->tree.node.parent);
// Creation reports, a no-op mutation does not.
@@ -180,7 +175,6 @@ int main(void) {
rediwm_node_destroy(&buf->node);
rediwm_scene_destroy(scene);
- wlr_scene_node_destroy(&wlr_scene->tree.node);
puts("node tests passed");
return 0;
}
diff --git a/src/notifications_tests.zig b/src/notifications_tests.zig
index c2b5ae5..c95db7d 100644
--- a/src/notifications_tests.zig
+++ b/src/notifications_tests.zig
@@ -19,14 +19,13 @@ test "notifications unit: replaces_id, urgency, DND, lock suppression" {
defer backend.destroy();
var fixture = try sn.TestScene.create();
defer fixture.destroy();
- const scene = fixture.wlr_scene;
const output_layout = try wlr.OutputLayout.create(display);
defer output_layout.destroy();
var dummy_cursor: wlr.Cursor = std.mem.zeroes(wlr.Cursor);
var server: Server = undefined;
server.wl_server = display;
- server.scene = scene;
+ server.scene_outputs = undefined;
server.overlay_tree = try fixture.nodes.tree.createSceneTree();
server.locker = null;
server.environ = std.process.Environ.empty;
diff --git a/src/osd.zig b/src/osd.zig
index 98e1f21..e088b15 100644
--- a/src/osd.zig
+++ b/src/osd.zig
@@ -218,11 +218,10 @@ test "OSD is noninteractive, stays above lock covers, rescales and releases its
defer layout.destroy();
var fixture = try sn.TestScene.create();
defer fixture.destroy();
- const scene = fixture.wlr_scene;
defer PanelBuffer.drainPool();
var server: Server = undefined;
server.wl_server = display;
- server.scene = scene;
+ server.scene_outputs = undefined;
server.output_layout = layout;
server.overlay_tree = try fixture.nodes.tree.createSceneTree();
server.lock_tree = try fixture.nodes.tree.createSceneTree();
@@ -274,11 +273,10 @@ test "OSD sound and brightness glides smoothly between levels" {
defer layout.destroy();
var fixture = try sn.TestScene.create();
defer fixture.destroy();
- const scene = fixture.wlr_scene;
defer PanelBuffer.drainPool();
var server: Server = undefined;
server.wl_server = display;
- server.scene = scene;
+ server.scene_outputs = undefined;
server.output_layout = layout;
server.overlay_tree = try fixture.nodes.tree.createSceneTree();
server.lock_tree = try fixture.nodes.tree.createSceneTree();
diff --git a/src/projection.c b/src/projection.c
index 7785e40..6cd4563 100644
--- a/src/projection.c
+++ b/src/projection.c
@@ -13,8 +13,8 @@
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_output.h>
-#include <wlr/types/wlr_scene.h>
#include "node_surface.h"
+#include "scene_outputs.h"
#include <wlr/util/addon.h>
#include <wlr/util/log.h>
@@ -37,7 +37,7 @@ struct rediwm_projection {
// scene is kept for its outputs.
struct rediwm_scene *own;
struct rediwm_tree *world;
- struct wlr_scene *scene;
+ struct rediwm_scene_outputs *outputs;
// What changed since the last sync. A change to one top-level subtree (a group) marks
// that group; a change to the shape of the tree, a layer or anything not tied to
// one group marks them all (`all_dirty`). A sync resolves and presents only the
@@ -104,9 +104,8 @@ struct leaf {
// In its group's `items` when the last resolve() reached it, else alone.
struct wl_list paint;
struct rediwm_projection *projection;
- // The wlr_scene node the pass reads the pixels from (`transport`): the carrier of
- // the own node's buffer or rect.
- struct wlr_scene_node *source;
+ // The node the pass reads the pixels from (`transport`): the buffer or rect itself.
+ struct rediwm_node *source;
// The own node it is.
struct rediwm_node *own;
// The group the last resolve() put it in.
@@ -338,8 +337,8 @@ static void mark_group(struct rediwm_projection *p, struct group *g) {
p->any_dirty = true;
}
static void schedule(struct rediwm_projection *p) {
- struct wlr_scene_output *out;
- wl_list_for_each(out, &p->scene->outputs, link)
+ struct rediwm_scene_output *out;
+ wl_list_for_each(out, &p->outputs->outputs, link)
wlr_output_schedule_frame(out->output);
}
static void forget_shown(struct leaf *l);
@@ -405,8 +404,8 @@ static struct group *get_group(struct rediwm_projection *p,
// output. From the sums it applies wlroots' own rule (scene.c,
// update_node_update_outputs): an output is active when it shows more than a tenth
// of what is visible on all of them, and the primary one is the one showing most
-// (the last, on a tie). It then emits the signals wlr_scene would have: the
-// source buffer is where wlr_scene_surface listens.
+// (the last, on a tie). It then emits the signals the surface binding listens to
+// (node_surface.c) on the source buffer.
enum { FEEDBACK_OUTPUTS = 64 };
struct feedback {
struct wl_list link;
@@ -414,7 +413,7 @@ struct feedback {
// Visible pixels as the last build of each output (scene output index) saw them.
uint32_t area[FEEDBACK_OUTPUTS];
uint64_t active;
- struct wlr_scene_output *primary;
+ struct rediwm_scene_output *primary;
};
static void free_feedback(struct leaf *l) {
if (!l->feedback) return;
@@ -481,7 +480,7 @@ static void destroy_leaf(struct leaf *l) {
wl_list_remove(&l->destroy.link);
wl_list_remove(&l->link);
wl_list_remove(&l->paint);
- if (l->source->data == l) l->source->data = NULL;
+ if (l->source->leaf == l) l->source->leaf = NULL;
wlr_addon_finish(&l->source_lookup);
pixman_region32_fini(&l->damage);
pixman_region32_fini(&l->visible);
@@ -529,11 +528,11 @@ static void committed(struct wl_listener *listener, void *data) {
mark_group(l->projection, l->group);
schedule(l->projection);
}
-static struct leaf *get_leaf(struct rediwm_projection *p, struct wlr_scene_node *source,
+static struct leaf *get_leaf(struct rediwm_projection *p, struct rediwm_node *source,
struct rediwm_node *own) {
- // A node's leaf is kept on its carrier.
- if (source->data)
- return source->data;
+ // A node's leaf is kept on the node.
+ if (source->leaf)
+ return source->leaf;
struct leaf *l = calloc(1, sizeof(*l));
if (!l)
return NULL;
@@ -549,11 +548,11 @@ static struct leaf *get_leaf(struct rediwm_projection *p, struct wlr_scene_node
wl_list_init(&l->paint);
wl_list_insert(&p->leaves, &l->link);
wlr_addon_init(&l->source_lookup, &source->addons, p, &source_lookup_impl);
- source->data = l;
- l->effect = source->type == WLR_SCENE_NODE_BUFFER && rediwm_glass_is_effect_node(source);
+ source->leaf = l;
+ l->effect = source->type == REDIWM_NODE_BUFFER && rediwm_glass_is_effect_node(source);
l->destroy.notify = source_destroy;
wl_signal_add(&source->events.destroy, &l->destroy);
- if (source->type == WLR_SCENE_NODE_BUFFER) {
+ if (source->type == REDIWM_NODE_BUFFER) {
l->surface = rediwm_buffer_from_node(own)->surface;
if (l->surface) {
l->damage_width = l->surface->surface->current.buffer_width;
@@ -692,9 +691,9 @@ static void apply_tree(struct rediwm_projection *p, struct tree_props *props, st
w->shadow = cast;
}
}
-// One leaf into the graph. `node` is the wlr_scene node the pass reads pixels from;
+// One leaf into the graph. `node` is the node the pass reads pixels from;
// (x, y) and `enabled` are the leaf's own, from whichever tree placed it.
-static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct wlr_scene_node *node,
+static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct rediwm_node *node,
struct rediwm_node *own, const struct walk *w, double x, double y,
bool enabled) {
struct leaf *l = get_leaf(p, node, own);
@@ -720,14 +719,14 @@ static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct wl
} else if (item->clip) {
item->clip = NULL;
}
- if (node->type == WLR_SCENE_NODE_RECT) {
- struct wlr_scene_rect *r = wlr_scene_rect_from_node(node);
+ if (node->type == REDIWM_NODE_RECT) {
+ struct rediwm_rect *r = rediwm_rect_from_node(node);
item->kind = REDIWM_ITEM_RECT;
item->width = r->width;
item->height = r->height;
memcpy(item->content.color, r->color, sizeof(item->content.color));
} else {
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(node);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(node);
if (l->effect) g->has_effect = true;
item->kind = l->effect ? REDIWM_ITEM_EFFECT
: l->surface ? REDIWM_ITEM_SURFACE
@@ -742,8 +741,8 @@ static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct wl
x += ex;
y += ey;
} else if (!item->width || !item->height) {
- item->width = b->private.buffer_width;
- item->height = b->private.buffer_height;
+ item->width = b->buffer_width;
+ item->height = b->buffer_height;
if (b->transform & 1) {
int tmp = item->width;
item->width = item->height;
@@ -764,7 +763,7 @@ static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct wl
item->content.dim_brightness = w->dim->brightness;
item->content.dim_saturation = w->dim->saturation;
}
- if (w->shadow && node->type == WLR_SCENE_NODE_BUFFER) {
+ if (w->shadow && node->type == REDIWM_NODE_BUFFER) {
item->kind = REDIWM_ITEM_SHADOW;
l->shadow = *w->shadow;
item->shadow = &l->shadow;
@@ -779,10 +778,10 @@ static void resolve_own(struct rediwm_projection *p, struct group *g, struct red
const bool enabled = parent->enabled && node->enabled;
switch (node->type) {
case REDIWM_NODE_RECT:
- resolve_leaf(p, g, &((struct rediwm_rect *)node)->carrier->node, node, parent, x, y, enabled);
+ resolve_leaf(p, g, node, node, parent, x, y, enabled);
return;
case REDIWM_NODE_BUFFER:
- resolve_leaf(p, g, &((struct rediwm_buffer *)node)->carrier->node, node, parent, x, y, enabled);
+ resolve_leaf(p, g, node, node, parent, x, y, enabled);
return;
case REDIWM_NODE_TREE: {
struct walk w = *parent;
@@ -896,9 +895,9 @@ static void present_leaf(struct leaf *l) {
} else {
// What the output pass draws from: the buffer, or the texture left when GLES2
// uploaded it and let the buffer go, or a single-pixel colour.
- const struct wlr_scene_buffer *sb = wlr_scene_buffer_from_node(l->source);
+ const struct rediwm_buffer *sb = rediwm_buffer_from_node(l->source);
paints = paints && item->content.opacity > 0 &&
- (sb->buffer || sb->private.texture || sb->private.is_single_pixel_buffer ||
+ (sb->buffer || sb->texture || sb->is_single_pixel_buffer ||
(l->surface && l->surface->surface->buffer));
}
const bool restyled = !l->has_shown || !paints || snap.x != l->shown.x ||
@@ -916,7 +915,7 @@ static void present_leaf(struct leaf *l) {
}
}
if (item->kind != REDIWM_ITEM_RECT && item->kind != REDIWM_ITEM_EFFECT) {
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(l->source);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(l->source);
struct wlr_buffer *backing = b->buffer;
// wlroots may cache a single-pixel buffer as a color and release the
// source node's buffer reference. The mapped surface still owns it.
@@ -955,7 +954,7 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
// lock is marked ignorable (like wlr_scene's own surface lock): the output pass
// reads the buffer from the node and is told the damage at the next sync.
bool rediwm_projection_present_owned(struct rediwm_projection *p,
- struct wlr_scene_buffer *source,
+ struct rediwm_buffer *source,
struct wlr_renderer *renderer,
struct wlr_buffer *buffer,
const pixman_region32_t *damage) {
@@ -980,13 +979,13 @@ bool rediwm_projection_present_owned(struct rediwm_projection *p,
// Without a texture wrapper, fall back to the plain buffer.
if (current)
current->private.n_ignore_locks--;
- wlr_scene_buffer_set_buffer(source, buffer);
+ rediwm_buffer_set_content(source, buffer);
rediwm_projection_damage_buffer(p, &source->node, NULL);
return false;
}
if (current)
current->private.n_ignore_locks--;
- wlr_scene_buffer_set_buffer(source, &next->base);
+ rediwm_buffer_set_content(source, &next->base);
next->private.n_ignore_locks++;
// The node's lock keeps it alive; drop the one creation handed us.
wlr_buffer_unlock(&next->base);
@@ -997,9 +996,9 @@ bool rediwm_projection_present_owned(struct rediwm_projection *p,
return false;
}
void rediwm_projection_damage_buffer(struct rediwm_projection *p,
- struct wlr_scene_node *source,
+ struct rediwm_node *source,
const pixman_region32_t *damage) {
- struct leaf *l = source->data;
+ struct leaf *l = source->leaf;
// A leaf's first projection applies its whole buffer anyway.
if (!l || l->projection != p)
return;
@@ -1021,16 +1020,16 @@ static uint32_t region_area(const pixman_region32_t *region) {
area += (uint32_t)(box[i].x2 - box[i].x1) * (uint32_t)(box[i].y2 - box[i].y1);
return area;
}
-static struct leaf *transport_leaf(struct rediwm_projection *p, struct wlr_scene_node *node) {
- struct leaf *l = node->data;
+static struct leaf *transport_leaf(struct rediwm_projection *p, struct rediwm_node *node) {
+ struct leaf *l = node->leaf;
return l && l->projection == p ? l : NULL;
}
-static struct leaf *feedback_leaf(struct rediwm_projection *p, struct wlr_scene_node *node) {
+static struct leaf *feedback_leaf(struct rediwm_projection *p, struct rediwm_node *node) {
struct leaf *l = transport_leaf(p, node);
return l && l->feedback ? l : NULL;
}
// What of an item nothing above hides, as the output pass last saw it (layout space).
-void rediwm_projection_note_visible(struct rediwm_projection *p, struct wlr_scene_node *node,
+void rediwm_projection_note_visible(struct rediwm_projection *p, struct rediwm_node *node,
const pixman_region32_t *visible) {
struct leaf *l = transport_leaf(p, node);
if (!l) return;
@@ -1047,9 +1046,9 @@ void rediwm_projection_feedback_begin(struct rediwm_projection *p) {
}
struct feedback *f;
wl_list_for_each(f, &p->feedback, link) memset(f->area, 0, sizeof(f->area));
- struct wlr_scene_output *out;
- wl_list_for_each(out, &p->scene->outputs, link) {
- const unsigned i = out->private.index % FEEDBACK_OUTPUTS;
+ struct rediwm_scene_output *out;
+ wl_list_for_each(out, &p->outputs->outputs, link) {
+ const unsigned i = out->index % FEEDBACK_OUTPUTS;
if (p->shown_output[i].known &&
(p->shown_output[i].scale != out->output->scale ||
p->shown_output[i].transform != out->output->transform ||
@@ -1062,12 +1061,12 @@ void rediwm_projection_feedback_begin(struct rediwm_projection *p) {
}
}
// `visible` is what of the surface nothing above it hides, over the whole layout.
-void rediwm_projection_feedback_note(struct rediwm_projection *p, struct wlr_scene_node *node,
+void rediwm_projection_feedback_note(struct rediwm_projection *p, struct rediwm_node *node,
const pixman_region32_t *visible) {
struct leaf *l = feedback_leaf(p, node);
if (!l || !pixman_region32_not_empty((pixman_region32_t *)visible)) return;
- struct wlr_scene_output *out;
- wl_list_for_each(out, &p->scene->outputs, link) {
+ struct rediwm_scene_output *out;
+ wl_list_for_each(out, &p->outputs->outputs, link) {
if (!out->output->enabled) continue;
struct wlr_box box = {.x = out->x, .y = out->y};
wlr_output_effective_resolution(out->output, &box.width, &box.height);
@@ -1075,7 +1074,7 @@ void rediwm_projection_feedback_note(struct rediwm_projection *p, struct wlr_sce
pixman_region32_init(&shown);
pixman_region32_intersect_rect(&shown, (pixman_region32_t *)visible, box.x, box.y, box.width,
box.height);
- l->feedback->area[out->private.index % FEEDBACK_OUTPUTS] = region_area(&shown);
+ l->feedback->area[out->index % FEEDBACK_OUTPUTS] = region_area(&shown);
pixman_region32_fini(&shown);
}
}
@@ -1083,46 +1082,39 @@ void rediwm_projection_feedback_note(struct rediwm_projection *p, struct wlr_sce
// output, and the signals of what changed.
static void update_feedback(struct leaf *l) {
struct feedback *f = l->feedback;
- struct wlr_scene *scene = l->projection->scene;
- struct wlr_scene_output *out;
+ struct rediwm_scene_outputs *scene = l->projection->outputs;
+ struct rediwm_scene_output *out;
uint64_t total = 0;
wl_list_for_each(out, &scene->outputs, link)
- if (out->output->enabled) total += f->area[out->private.index % FEEDBACK_OUTPUTS];
+ if (out->output->enabled) total += f->area[out->index % FEEDBACK_OUTPUTS];
uint32_t largest = 0;
uint64_t active = 0;
size_t count = 0;
- struct wlr_scene_output *primary = NULL;
+ struct rediwm_scene_output *primary = NULL;
wl_list_for_each(out, &scene->outputs, link) {
if (!out->output->enabled) continue;
- const uint32_t overlap = f->area[out->private.index % FEEDBACK_OUTPUTS];
+ const uint32_t overlap = f->area[out->index % FEEDBACK_OUTPUTS];
// Ten percent of what is visible or less, and the output is ignored.
if (overlap > 0.1 * total) {
if (overlap >= largest) {
largest = overlap;
primary = out;
}
- active |= 1ull << (out->private.index % FEEDBACK_OUTPUTS);
+ active |= 1ull << (out->index % FEEDBACK_OUTPUTS);
count++;
}
}
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(l->source);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(l->source);
const uint64_t before = f->active;
- struct wlr_scene_output *before_primary = f->primary;
+ struct rediwm_scene_output *before_primary = f->primary;
f->active = active;
f->primary = primary;
- wl_list_for_each(out, &scene->outputs, link) {
- const uint64_t mask = 1ull << (out->private.index % FEEDBACK_OUTPUTS);
- if ((active & mask) && !(before & mask))
- wl_signal_emit_mutable(&b->events.output_enter, out);
- else if (!(active & mask) && (before & mask))
- wl_signal_emit_mutable(&b->events.output_leave, out);
- }
if (before == active && before_primary == primary && !(active & l->projection->forced)) return;
- struct wlr_scene_output *outputs[FEEDBACK_OUTPUTS];
- struct wlr_scene_outputs_update_event event = {.active = outputs, .size = count};
+ struct rediwm_scene_output *outputs[FEEDBACK_OUTPUTS];
+ struct rediwm_outputs_update_event event = {.active = outputs, .size = count};
size_t i = 0;
wl_list_for_each(out, &scene->outputs, link)
- if (active & (1ull << (out->private.index % FEEDBACK_OUTPUTS))) outputs[i++] = out;
+ if (active & (1ull << (out->index % FEEDBACK_OUTPUTS))) outputs[i++] = out;
wl_signal_emit_mutable(&b->events.outputs_update, &event);
}
void rediwm_projection_feedback_end(struct rediwm_projection *p) {
@@ -1130,15 +1122,15 @@ void rediwm_projection_feedback_end(struct rediwm_projection *p) {
wl_list_for_each_safe(f, next, &p->feedback, link) update_feedback(f->leaf);
p->forced = 0;
}
-// wlr_scene_output_send_frame_done for the world: the surfaces shown on any
+// Frame callbacks for the world: the surfaces shown on any
// output (the surface itself picks the output that paces it).
-void rediwm_projection_send_frame_done(struct rediwm_projection *p, struct wlr_scene_output *out,
+void rediwm_projection_send_frame_done(struct rediwm_projection *p, struct rediwm_scene_output *out,
struct timespec *now) {
struct feedback *f, *next;
wl_list_for_each_safe(f, next, &p->feedback, link) {
if (!f->active || !f->leaf->seen || !f->leaf->item.enabled) continue;
- struct wlr_scene_frame_done_event event = {.output = out, .when = *now};
- wl_signal_emit_mutable(&wlr_scene_buffer_from_node(f->leaf->source)->events.frame_done, &event);
+ struct rediwm_frame_done_event event = {.output = out, .when = *now};
+ wl_signal_emit_mutable(&rediwm_buffer_from_node(f->leaf->source)->events.frame_done, &event);
}
}
// The group a node belongs to: the child of a layer it hangs under (root 0, layer 1,
@@ -1157,16 +1149,16 @@ static void scene_changed(void *data, struct rediwm_node *node, bool structural)
schedule(p);
}
static void buffer_given(void *data, struct rediwm_buffer *b, const pixman_region32_t *damage) {
- rediwm_projection_damage_buffer(data, &b->carrier->node, damage);
+ rediwm_projection_damage_buffer(data, &b->node, damage);
}
struct rediwm_projection *rediwm_projection_create(struct rediwm_scene *own, struct rediwm_tree *world,
- struct wlr_scene *scene) {
+ struct rediwm_scene_outputs *outputs) {
struct rediwm_projection *p = calloc(1, sizeof(*p));
if (!p)
return NULL;
p->own = own;
p->world = world;
- p->scene = scene;
+ p->outputs = outputs;
wl_list_init(&p->leaves);
wl_list_init(&p->groups);
wl_list_init(&p->paint);
@@ -1322,7 +1314,7 @@ static void damage_restacked(struct rediwm_projection *p) {
}
}
static void apply_damage(struct rediwm_projection *p) {
- if (pixman_region32_not_empty(&p->pending)) rediwm_scene_damage_layout(p->scene, &p->pending);
+ if (pixman_region32_not_empty(&p->pending)) rediwm_scene_damage_layout(p->outputs, &p->pending);
pixman_region32_clear(&p->pending);
}
#ifdef REDIWM_DAMAGE_AUDIT
@@ -1447,7 +1439,7 @@ static bool pick_leaf(struct rediwm_projection *p, const struct group *only, dou
py >= s.y + s.height)
continue;
double x = lx - s.x, y = ly - s.y;
- if (l->source->type == WLR_SCENE_NODE_BUFFER) {
+ if (l->source->type == REDIWM_NODE_BUFFER) {
x *= (double)item->width / s.width;
y *= (double)item->height / s.height;
// A window's rounded corners are transparent: a point the shape cuts away
diff --git a/src/projection.h b/src/projection.h
index bc6eb7e..ebcc437 100644
--- a/src/projection.h
+++ b/src/projection.h
@@ -1,13 +1,12 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
-struct wlr_scene_node;
-struct wlr_scene_tree;
-struct wlr_scene;
+struct rediwm_node;
+struct rediwm_buffer;
+struct rediwm_scene_outputs;
struct rediwm_node;
struct rediwm_tree;
struct rediwm_scene;
-struct wlr_scene_buffer;
struct wlr_surface_state;
struct rediwm_projection;
struct rediwm_item;
@@ -18,7 +17,7 @@ struct rediwm_clip_spec;
// node for the world, the node itself for the layout trees. Callbacks must not
// mutate the scene; pointers are borrowed for this call.
typedef bool (*rediwm_item_iterator)(const struct rediwm_item *,
- struct wlr_scene_node *transport, void *);
+ struct rediwm_node *transport, void *);
bool rediwm_projection_for_each_item(struct rediwm_projection *, bool reverse, rediwm_item_iterator, void *);
// Whether a commit changed how buffer pixels map onto the surface, so damage
// from before it cannot be combined with damage after it.
@@ -30,7 +29,7 @@ bool rediwm_surface_state_remapped(const struct wlr_surface_state *);
// for its outputs.
struct rediwm_projection *rediwm_projection_create(struct rediwm_scene *own,
struct rediwm_tree *world,
- struct wlr_scene *);
+ struct rediwm_scene_outputs *);
void rediwm_projection_destroy(struct rediwm_projection *);
void rediwm_projection_sync(struct rediwm_projection *, double, double, double,
double, double);
@@ -93,17 +92,16 @@ struct rediwm_shadow_spec;
// buffer node; NULL damages all of it. Surface leaves track their own.
struct pixman_region32;
void rediwm_projection_damage_buffer(struct rediwm_projection *,
- struct wlr_scene_node *,
+ struct rediwm_node *,
const struct pixman_region32 *);
// Presents `buffer` on a compositor-owned source buffer node, updating its
// texture in place with `damage` (buffer-local) when the renderer can. The
// caller may release `buffer` afterwards. NULL damage replaces everything.
// Returns whether the texture was updated in place.
-struct wlr_scene_buffer;
struct wlr_renderer;
struct wlr_buffer;
bool rediwm_projection_present_owned(struct rediwm_projection *,
- struct wlr_scene_buffer *,
+ struct rediwm_buffer *,
struct wlr_renderer *,
struct wlr_buffer *,
const struct pixman_region32 *);
@@ -119,14 +117,14 @@ void rediwm_mirror_opaque(struct pixman_region32 *out, const struct pixman_regio
// `end` works out and sends what changed: outputs entered and left, the primary
// output.
// What of an item nothing above hides, in layout space, as the pass saw it.
-struct wlr_scene_output;
-void rediwm_projection_note_visible(struct rediwm_projection *, struct wlr_scene_node *,
+struct rediwm_scene_output;
+void rediwm_projection_note_visible(struct rediwm_projection *, struct rediwm_node *,
const struct pixman_region32 *visible);
void rediwm_projection_feedback_begin(struct rediwm_projection *);
-void rediwm_projection_feedback_note(struct rediwm_projection *, struct wlr_scene_node *,
+void rediwm_projection_feedback_note(struct rediwm_projection *, struct rediwm_node *,
const struct pixman_region32 *visible);
void rediwm_projection_feedback_end(struct rediwm_projection *);
-// Frame callbacks of the world's surfaces, beside wlr_scene_output_send_frame_done.
+// Frame callbacks of the world's surfaces.
struct timespec;
-void rediwm_projection_send_frame_done(struct rediwm_projection *, struct wlr_scene_output *,
+void rediwm_projection_send_frame_done(struct rediwm_projection *, struct rediwm_scene_output *,
struct timespec *now);
diff --git a/src/projection.zig b/src/projection.zig
index 6db87eb..f9d41bd 100644
--- a/src/projection.zig
+++ b/src/projection.zig
@@ -2,7 +2,7 @@ const std = @import("std");
const wlr = @import("wlroots");
const node = @import("node.zig");
pub const Projection = opaque {
- extern fn rediwm_projection_create(own: *node.Scene, world: *node.Tree, scene: *wlr.Scene) ?*Projection;
+ extern fn rediwm_projection_create(own: *node.Scene, world: *node.Tree, outputs: *@import("scene_outputs.zig").SceneOutputs) ?*Projection;
/// `own` is the compositor's scene (its root's children are layers, bottom to
/// top) and `world` the layer that follows the camera. The projection asks for a
/// frame whenever the scene changes.
@@ -15,18 +15,18 @@ pub const Projection = opaque {
pub const sync = rediwm_projection_sync;
extern fn rediwm_projection_sync_fixed(projection: ?*Projection, zoom: f64, cx: f64, cy: f64, ox: f64, oy: f64, fixed: ?*node.Tree) void;
pub const syncFixed = rediwm_projection_sync_fixed;
- extern fn rediwm_projection_damage_buffer(projection: *Projection, source: *wlr.SceneNode, damage: ?*const @import("pixman").Region32) void;
+ extern fn rediwm_projection_damage_buffer(projection: *Projection, source: *node.Node, damage: ?*const @import("pixman").Region32) void;
/// Buffer-local damage for the buffer just set on a compositor-owned
/// buffer node; null damages all of it.
pub fn damageBuffer(projection: *Projection, buffer: *node.Buffer, damage: ?*const @import("pixman").Region32) void {
- rediwm_projection_damage_buffer(projection, &buffer.carrier.node, damage);
+ rediwm_projection_damage_buffer(projection, &buffer.node, damage);
}
- extern fn rediwm_projection_present_owned(projection: *Projection, source: *wlr.SceneBuffer, renderer: *wlr.Renderer, buffer: *wlr.Buffer, damage: ?*const @import("pixman").Region32) bool;
+ extern fn rediwm_projection_present_owned(projection: *Projection, source: *node.Buffer, renderer: *wlr.Renderer, buffer: *wlr.Buffer, damage: ?*const @import("pixman").Region32) bool;
/// Sets `buffer` on a compositor-owned buffer node, updating the texture
/// in place with `damage` when the renderer allows; null replaces all.
/// The caller may drop `buffer` afterwards. True when updated in place.
pub fn presentOwned(projection: *Projection, target: *node.Buffer, renderer: *wlr.Renderer, buffer: *wlr.Buffer, damage: ?*const @import("pixman").Region32) bool {
- return rediwm_projection_present_owned(projection, target.carrier, renderer, buffer, damage);
+ return rediwm_projection_present_owned(projection, target, renderer, buffer, damage);
}
pub const Hit = extern struct {
/// The leaf that was hit: a client surface's node, or a shell node.
@@ -47,9 +47,8 @@ pub const Projection = opaque {
var hit: Hit = undefined;
return if (rediwm_projection_node_at(projection, lx, ly, &hit)) hit else null;
}
- extern fn rediwm_projection_send_frame_done(projection: *Projection, output: *wlr.SceneOutput, now: *std.posix.timespec) void;
- /// Frame callbacks of the world's client surfaces for one output, beside
- /// `wlr.SceneOutput.sendFrameDone`, which reaches the layout trees only.
+ extern fn rediwm_projection_send_frame_done(projection: *Projection, output: *@import("scene_outputs.zig").SceneOutput, now: *std.posix.timespec) void;
+ /// Frame callbacks of the world's client surfaces for one output.
pub const sendFrameDone = rediwm_projection_send_frame_done;
};
extern fn rediwm_projection_set_tree_zoom(target: *node.Node, scale: f64) bool;
diff --git a/src/projection_test.c b/src/projection_test.c
index 29fcb25..e747bcb 100644
--- a/src/projection_test.c
+++ b/src/projection_test.c
@@ -7,21 +7,19 @@
#include <wlr/backend.h>
#include <wlr/backend/headless.h>
#include <wlr/interfaces/wlr_buffer.h>
+#include <wlr/types/wlr_output_layout.h>
-// One own scene with its hidden wlr_scene host and a world layer, per test.
+// One own scene and a world layer, per test.
struct rig {
struct rediwm_scene *own, *parking; // `parking` holds what the pass no longer reaches
struct rediwm_tree *world;
- struct wlr_scene_tree *host;
};
-static struct rig rig_create(struct wlr_scene *scene) {
+static struct rig rig_create(struct rediwm_scene_outputs *scene) {
+ (void)scene;
struct rig rig = {0};
- rig.host = wlr_scene_tree_create(&scene->tree);
- assert(rig.host);
- wlr_scene_node_set_enabled(&rig.host->node, false);
- rig.own = rediwm_scene_create(rig.host, NULL, NULL);
- rig.parking = rediwm_scene_create(rig.host, NULL, NULL);
+ rig.own = rediwm_scene_create(NULL, NULL);
+ rig.parking = rediwm_scene_create(NULL, NULL);
assert(rig.own && rig.parking);
rig.world = rediwm_tree_create(&rig.own->tree);
assert(rig.world);
@@ -30,20 +28,10 @@ static struct rig rig_create(struct wlr_scene *scene) {
static void rig_destroy(struct rig *rig) {
rediwm_scene_destroy(rig->own);
rediwm_scene_destroy(rig->parking);
- wlr_scene_node_destroy(&rig->host->node);
-}
-// The leaf of an own node: leaves hang on the node the pass reads, its carrier.
-static struct wlr_scene_node *carrier_of(struct rediwm_node *node) {
- if (node->type == REDIWM_NODE_BUFFER) return &((struct rediwm_buffer *)node)->carrier->node;
- if (node->type == REDIWM_NODE_RECT) return &((struct rediwm_rect *)node)->carrier->node;
- return NULL;
}
static struct leaf *leaf_of(struct rediwm_projection *p, struct rediwm_node *node) {
- struct wlr_scene_node *carrier = carrier_of(node);
- assert(carrier);
- struct wlr_addon *addon = wlr_addon_find(&carrier->addons, p, &source_lookup_impl);
- struct leaf *l;
- return addon ? (l = wl_container_of(addon, l, source_lookup)) : NULL;
+ struct leaf *l = node->leaf;
+ return l && l->projection == p ? l : NULL;
}
static struct rediwm_node *pick(struct rediwm_projection *p, double x, double y, double *nx, double *ny) {
@@ -54,12 +42,12 @@ static struct rediwm_node *pick(struct rediwm_projection *p, double x, double y,
return hit.own;
}
-static struct wlr_scene_node *effect_node;
-bool rediwm_glass_is_effect_node(struct wlr_scene_node *node) {
+static struct rediwm_node *effect_node;
+bool rediwm_glass_is_effect_node(struct rediwm_node *node) {
return node == effect_node;
}
// glass.c is not linked here: the stub effect keeps its own box.
-bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out) {
+bool rediwm_glass_effect_info(struct rediwm_node *node, struct rediwm_glass_info *out) {
(void)node;
(void)out;
return false;
@@ -79,12 +67,12 @@ static void commit_damage(struct leaf *l, int x, int y, int width, int height) {
&surface->buffer_damage, x, y, width, height));
committed(&l->commit, NULL);
}
-static bool damaged(struct wlr_scene_output *out, int x, int y) {
+static bool damaged(struct rediwm_scene_output *out, int x, int y) {
return pixman_region32_contains_point(&out->damage_ring.current, x, y, NULL);
}
-static void clear_damage(struct wlr_scene_output *out) {
+static void clear_damage(struct rediwm_scene_output *out) {
pixman_region32_clear(&out->damage_ring.current);
- pixman_region32_clear(&out->private.pending_commit_damage);
+ pixman_region32_clear(&out->pending_commit_damage);
}
// Where the graph puts a leaf once rounded in layout space.
static void assert_position(struct rediwm_projection *p,
@@ -151,11 +139,11 @@ static void assert_presented(struct rediwm_projection *p) {
// The typed graph: complete and in paint order before anything is presented,
// unrounded, and the only source of geometry.
struct graph_probe {
- struct wlr_scene_node *transport;
+ struct rediwm_node *transport;
struct rediwm_item expected;
int count;
};
-static bool probe_item(const struct rediwm_item *item, struct wlr_scene_node *transport, void *data) {
+static bool probe_item(const struct rediwm_item *item, struct rediwm_node *transport, void *data) {
struct graph_probe *probe = data;
if (transport != probe->transport) return true;
probe->count++;
@@ -165,7 +153,7 @@ static bool probe_item(const struct rediwm_item *item, struct wlr_scene_node *tr
return true;
}
// A sync with nothing changed resolves nothing; every kind of change brings it back.
-static void test_clean_sync(struct wlr_scene *scene) {
+static void test_clean_sync(struct rediwm_scene_outputs *scene) {
struct rig rig = rig_create(scene);
struct rediwm_projection *p = rediwm_projection_create(rig.own, rig.world, scene);
struct wlr_buffer *buffer = buffer_create();
@@ -196,7 +184,7 @@ static void test_clean_sync(struct wlr_scene *scene) {
assert(l->item.edges.x2 == 50);
// A surface commit, or an owned buffer's damage.
l->item.edges.x2 = 12345;
- rediwm_projection_damage_buffer(p, &node->carrier->node, NULL);
+ rediwm_projection_damage_buffer(p, &node->node, NULL);
rediwm_projection_sync(p, 2, 0, 0, 0, 0);
assert(l->item.edges.x2 == 50);
// Only the group that changed is walked again; a change to the tree's shape walks all.
@@ -222,7 +210,7 @@ static void test_clean_sync(struct wlr_scene *scene) {
rig_destroy(&rig);
wlr_buffer_drop(buffer);
}
-static void test_graph(struct wlr_scene *scene) {
+static void test_graph(struct rediwm_scene_outputs *scene) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -242,7 +230,7 @@ static void test_graph(struct wlr_scene *scene) {
rediwm_node_set_position(&client->node, 4, 3);
rediwm_node_set_position(&border->node, -2, -3);
rediwm_node_set_position(&other->node, 90, 60);
- effect_node = carrier_of(&glass->node);
+ effect_node = &glass->node;
rediwm_buffer_set_dest_size(client, 100, 60);
rediwm_buffer_set_dest_size(glass, 50, 20);
assert(rediwm_projection_set_tree_zoom(&frame->node, .85));
@@ -497,7 +485,7 @@ static void test_clip_opaque(void) {
assert(rediwm_clip_opaque(&(struct rediwm_clip){rediwm_xform_rect(identity, 5, 7, 120, 80), {40, 40, 40, 40}, 0, {0}, 0, 0, 0, 0, {0}}, one) == 1);
assert(one[0].x == 5 + 42 && one[0].y == 7 && one[0].width == 120 - 84 && one[0].height == 80);
}
-static void test_clip_projection(struct wlr_scene *scene) {
+static void test_clip_projection(struct rediwm_scene_outputs *scene) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -518,7 +506,7 @@ static void test_clip_projection(struct wlr_scene *scene) {
rediwm_buffer_set_dest_size(client, 100, 60);
rediwm_buffer_set_dest_size(title, 100, 12);
rediwm_buffer_set_dest_size(glass, 100, 12);
- effect_node = carrier_of(&glass->node);
+ effect_node = &glass->node;
assert(rediwm_projection_set_tree_zoom(&frame->node, .85));
assert(rediwm_projection_set_tree_scale(&nested->node, .5));
@@ -631,10 +619,10 @@ static void test_clip_projection(struct wlr_scene *scene) {
// projection itself; and a point the shape cuts away goes to what is below.
// Damage is in output pixels and the points below are in layout coordinates, at
// whatever scale an earlier test left the output.
-static bool layout_damaged(struct wlr_scene_output *out, double x, double y) {
+static bool layout_damaged(struct rediwm_scene_output *out, double x, double y) {
return damaged(out, (int)(x * out->output->scale), (int)(y * out->output->scale));
}
-static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *out) {
+static void test_clip_output(struct rediwm_scene_outputs *scene, struct rediwm_scene_output *out) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -693,7 +681,7 @@ static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *o
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
assert(layout_damaged(out, 301, 201) && layout_damaged(out, 419, 279) && layout_damaged(out, 300, 240));
assert(!layout_damaged(out, 360, 240) && !layout_damaged(out, 100, 100));
- assert(pixman_region32_not_empty(&out->private.pending_commit_damage));
+ assert(pixman_region32_not_empty(&out->pending_commit_damage));
clear_damage(out);
// Setting the same shape again damages nothing.
assert(rediwm_projection_set_tree_clip(&frame->node, &spec));
@@ -735,7 +723,7 @@ static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *o
// Stage 4d: a shadow's view has no buffer, so wlroots damages nothing for it and the
// projection damages the footprint itself: when it appears, moves, changes, is
// hidden with its window, or goes away, and never when nothing changed.
-static void test_shadow_output(struct wlr_scene *scene, struct wlr_scene_output *out) {
+static void test_shadow_output(struct rediwm_scene_outputs *scene, struct rediwm_scene_output *out) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -809,7 +797,7 @@ static struct events_seen events_since(struct rediwm_projection *p, uint64_t *cu
static bool event_is(const struct rediwm_damage_event *e, uint64_t leaf, int x, int y, int w, int h) {
return e->leaf == leaf && e->box.x == x && e->box.y == y && e->box.width == w && e->box.height == h;
}
-static void test_damage_events(struct wlr_scene *scene) {
+static void test_damage_events(struct rediwm_scene_outputs *scene) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -838,12 +826,12 @@ static void test_damage_events(struct wlr_scene *scene) {
// Reported buffer damage maps through the scale, a pixel wider for filtering.
pixman_region32_t damage;
pixman_region32_init_rect(&damage, 20, 40, 10, 10);
- rediwm_projection_damage_buffer(p, carrier_of(&a->node), &damage);
+ rediwm_projection_damage_buffer(p, &a->node, &damage);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
seen = events_since(p, &cursor, NULL);
assert(seen.count == 1 && event_is(&seen.last[0], la->item.id, 49, 49, 7, 7));
// Unreported damage is the whole box.
- rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);
+ rediwm_projection_damage_buffer(p, &a->node, NULL);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
seen = events_since(p, &cursor, NULL);
assert(seen.count == 1 && event_is(&seen.last[0], la->item.id, 40, 30, 100, 60));
@@ -906,7 +894,7 @@ static void test_damage_events(struct wlr_scene *scene) {
// A window's dim is a field of what its leaves show: inherited down the tree like
// its shape, ended where a popup hangs under it, and a change of it restyles (so
// damages) every leaf under the tree and no other.
-static void test_dim(struct wlr_scene *scene) {
+static void test_dim(struct rediwm_scene_outputs *scene) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -1042,7 +1030,7 @@ static bool in_group(struct group *g, struct leaf *l) {
return false;
}
static int snap_width(struct leaf *l) { return rediwm_edges_snap(l->item.edges).width; }
-static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {
+static void test_groups(struct rediwm_scene_outputs *scene, struct rediwm_scene_output *out) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -1204,7 +1192,7 @@ static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {
// Stage 6b: the screen's damage comes from the graph. A restack damages what
// changed order, a change of what a leaf itself shows is cut to what was visible
// of it at the last build, and a window going away is damaged at once.
-static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *out) {
+static void test_graph_damage(struct rediwm_scene_outputs *scene, struct rediwm_scene_output *out) {
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);
@@ -1234,26 +1222,26 @@ static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *
struct leaf *la = leaf_of(p, &a->node), *lb = leaf_of(p, &b->node);
pixman_region32_t visible;
pixman_region32_init_rect(&visible, 20, 20, 50, 120);
- rediwm_projection_note_visible(p, carrier_of(&a->node), &visible);
- rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);
+ rediwm_projection_note_visible(p, &a->node, &visible);
+ rediwm_projection_damage_buffer(p, &a->node, NULL);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
assert(layout_damaged(out, 30, 60) && !layout_damaged(out, 150, 60));
clear_damage(out);
// Nothing visible, nothing to damage; a leaf the pass never saw is damaged whole.
pixman_region32_clear(&visible);
- rediwm_projection_note_visible(p, carrier_of(&a->node), &visible);
- rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);
+ rediwm_projection_note_visible(p, &a->node, &visible);
+ rediwm_projection_damage_buffer(p, &a->node, NULL);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
assert(!pixman_region32_not_empty(&out->damage_ring.current));
assert(!lb->has_visible);
- rediwm_projection_damage_buffer(p, carrier_of(&b->node), NULL);
+ rediwm_projection_damage_buffer(p, &b->node, NULL);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
assert(layout_damaged(out, 70, 50) && layout_damaged(out, 250, 150));
clear_damage(out);
// A leaf that is moved damages where it was only where it was visible, and
// where it is whatever the last build saw.
pixman_region32_init_rect(&visible, 60, 40, 40, 120);
- rediwm_projection_note_visible(p, carrier_of(&b->node), &visible);
+ rediwm_projection_note_visible(p, &b->node, &visible);
rediwm_node_set_position(&frame_b->node, 200, 150);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
assert(layout_damaged(out, 70, 60) && !layout_damaged(out, 150, 60)); // old box, cut
@@ -1263,7 +1251,7 @@ static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *
// A window going away damages what it showed without waiting for a sync: a
// capture can build a frame before the next one.
- rediwm_projection_note_visible(p, carrier_of(&a->node), &(pixman_region32_t){.extents = {20, 20, 220, 140}, .data = NULL});
+ rediwm_projection_note_visible(p, &a->node, &(pixman_region32_t){.extents = {20, 20, 220, 140}, .data = NULL});
rediwm_node_destroy(&frame_a->node);
assert(layout_damaged(out, 30, 30) && layout_damaged(out, 210, 130));
pixman_region32_fini(&visible);
@@ -1274,10 +1262,10 @@ static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *
// Stage 6a: what the output pass reports of a surface becomes the signals wlroots
// would have sent. Two outputs side by side, a node over the seam.
static int outputs_updates, frame_dones, update_size;
-static struct wlr_scene_output *update_active[4];
+static struct rediwm_scene_output *update_active[4];
static void on_outputs_update(struct wl_listener *listener, void *data) {
(void)listener;
- const struct wlr_scene_outputs_update_event *event = data;
+ const struct rediwm_outputs_update_event *event = data;
outputs_updates++;
update_size = (int)event->size;
for (size_t i = 0; i < event->size && i < 4; i++) update_active[i] = event->active[i];
@@ -1287,7 +1275,7 @@ static void on_frame_done(struct wl_listener *listener, void *data) {
(void)data;
frame_dones++;
}
-static void report(struct rediwm_projection *p, struct wlr_scene_node *node, int x, int y, int w, int h) {
+static void report(struct rediwm_projection *p, struct rediwm_node *node, int x, int y, int w, int h) {
pixman_region32_t visible;
pixman_region32_init(&visible);
if (w > 0) pixman_region32_union_rect(&visible, &visible, x, y, w, h);
@@ -1296,7 +1284,7 @@ static void report(struct rediwm_projection *p, struct wlr_scene_node *node, int
rediwm_projection_feedback_end(p);
pixman_region32_fini(&visible);
}
-static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend, struct wlr_scene_output *left,
+static void test_feedback(struct rediwm_scene_outputs *scene, struct wlr_backend *backend, struct rediwm_scene_output *left,
struct wlr_output *left_output) {
struct wlr_output *right_output = wlr_headless_add_output(backend, 320, 240);
assert(right_output);
@@ -1305,11 +1293,11 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,
wlr_output_state_set_enabled(&state, true);
assert(wlr_output_commit_state(right_output, &state));
wlr_output_state_finish(&state);
- struct wlr_scene_output *right = wlr_scene_output_create(scene, right_output);
+ struct rediwm_scene_output *right = rediwm_scene_output_create(scene, right_output, NULL);
assert(right);
int seam = 0, unused = 0;
wlr_output_effective_resolution(left_output, &seam, &unused);
- wlr_scene_output_set_position(right, seam, 0);
+ right->x = seam;
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
@@ -1325,18 +1313,18 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,
l->feedback->leaf = l;
wl_list_insert(&p->feedback, &l->feedback->link);
struct wl_listener updated = {.notify = on_outputs_update}, done = {.notify = on_frame_done};
- wl_signal_add(&node->carrier->events.outputs_update, &updated);
- wl_signal_add(&node->carrier->events.frame_done, &done);
+ wl_signal_add(&node->events.outputs_update, &updated);
+ wl_signal_add(&node->events.frame_done, &done);
struct timespec now = {0};
// Over the seam: both outputs show more than a tenth, the one with most is primary.
- report(p, carrier_of(&node->node), seam - 26, 50, 200, 100); // 26 columns left, 174 right
+ report(p, &node->node, seam - 26, 50, 200, 100); // 26 columns left, 174 right
assert(outputs_updates == 1 && update_size == 2 && l->feedback->primary == right);
- assert(l->feedback->active == (1ull << left->private.index | 1ull << right->private.index));
- report(p, carrier_of(&node->node), seam - 26, 50, 200, 100);
+ assert(l->feedback->active == (1ull << left->index | 1ull << right->index));
+ report(p, &node->node, seam - 26, 50, 200, 100);
assert(outputs_updates == 1); // Unchanged: no signal.
// A sliver on the other side is ignored (10 % rule): 2 of 28 columns.
- report(p, carrier_of(&node->node), seam - 26, 50, 28, 100);
+ report(p, &node->node, seam - 26, 50, 28, 100);
assert(outputs_updates == 2 && update_size == 1 && update_active[0] == left && l->feedback->primary == left);
// Frames are sent for what is shown, and for no output it is not.
rediwm_projection_send_frame_done(p, left, &now);
@@ -1348,22 +1336,22 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,
assert(frame_dones == 1);
rediwm_node_set_enabled(&node->node, true);
rediwm_projection_sync(p, 1, 0, 0, 0, 0);
- report(p, carrier_of(&node->node), 0, 0, 0, 0); // hidden
+ report(p, &node->node, 0, 0, 0, 0); // hidden
assert(outputs_updates == 3 && update_size == 0 && !l->feedback->active && !l->feedback->primary);
rediwm_projection_send_frame_done(p, left, &now);
assert(frame_dones == 1); // nothing shown, nothing sent
// An active output whose scale changed hears again, whatever else is the same.
- report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);
+ report(p, &node->node, seam - 26, 50, 26, 100);
assert(outputs_updates == 4 && update_size == 1);
- report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);
+ report(p, &node->node, seam - 26, 50, 26, 100);
assert(outputs_updates == 4);
wlr_output_state_init(&state);
wlr_output_state_set_scale(&state, 1.25f);
assert(wlr_output_commit_state(left_output, &state));
wlr_output_state_finish(&state);
- report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);
+ report(p, &node->node, seam - 26, 50, 26, 100);
assert(outputs_updates == 5);
- report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);
+ report(p, &node->node, seam - 26, 50, 26, 100);
assert(outputs_updates == 5);
wlr_output_state_init(&state);
wlr_output_state_set_scale(&state, 1.f);
@@ -1375,7 +1363,7 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,
rediwm_projection_destroy(p);
rig_destroy(&rig);
wlr_buffer_drop(buffer);
- wlr_scene_output_destroy(right);
+ rediwm_scene_output_destroy(right);
wlr_output_destroy(right_output);
}
int main(void) {
@@ -1390,9 +1378,11 @@ int main(void) {
wlr_output_state_set_enabled(&state, true);
assert(wlr_output_commit_state(output, &state));
wlr_output_state_finish(&state);
- struct wlr_scene *scene = wlr_scene_create();
+ struct wlr_output_layout *layout = wlr_output_layout_create(display);
+ assert(layout);
+ struct rediwm_scene_outputs *scene = rediwm_scene_outputs_create(layout);
assert(scene);
- struct wlr_scene_output *out = wlr_scene_output_create(scene, output);
+ struct rediwm_scene_output *out = rediwm_scene_output_create(scene, output, NULL);
assert(out);
struct rig rig = rig_create(scene);
struct rediwm_tree *source = rig.world;
@@ -1527,7 +1517,8 @@ int main(void) {
test_graph_damage(scene, out);
test_feedback(scene, backend, out, output);
test_opaque();
- wlr_scene_node_destroy(&scene->tree.node);
+ rediwm_scene_outputs_destroy(scene);
+ wlr_output_layout_destroy(layout);
wlr_buffer_drop(a);
wlr_buffer_drop(b);
wlr_backend_destroy(backend);
diff --git a/src/reveal.zig b/src/reveal.zig
index 7538d3f..daeedb4 100644
--- a/src/reveal.zig
+++ b/src/reveal.zig
@@ -148,7 +148,7 @@ pub fn tick(self: *Reveal, output: *Output, now_ms: i64) bool {
fn setVeil(self: *Reveal, output: *Output, alpha: f32) void {
const server = self.server orelse return;
- const scene_output = server.scene.getSceneOutput(output.wlr_output) orelse return;
+ const scene_output = server.scene_outputs.get(output.wlr_output) orelse return;
if (!server.output_renderer.setVeil(scene_output, alpha)) {
std.log.scoped(.reveal).warn("could not veil {s}", .{output.wlr_output.name});
}
diff --git a/src/scene_damage.c b/src/scene_damage.c
index 04a9ec5..0006f6c 100644
--- a/src/scene_damage.c
+++ b/src/scene_damage.c
@@ -6,15 +6,15 @@
#include "scene_view.h"
#include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_output.h>
-#include <wlr/types/wlr_scene.h>
+#include "scene_outputs.h"
// Damage a layout-space region on every output it touches, as a node update
// would: the ring and the commit damage, in device pixels, and a frame request.
// For changes the graph shows only as a different clip (a border colour), which
// move no view node.
-void rediwm_scene_damage_layout(struct wlr_scene *scene, const pixman_region32_t *region) {
- struct wlr_scene_output *out;
- wl_list_for_each(out, &scene->outputs, link) {
+void rediwm_scene_damage_layout(struct rediwm_scene_outputs *outputs, const pixman_region32_t *region) {
+ struct rediwm_scene_output *out;
+ wl_list_for_each(out, &outputs->outputs, link) {
struct wlr_output *output = out->output;
struct output_view v = {.width = output->width, .height = output->height,
.scale = output->scale, .transform = output->transform,
@@ -32,8 +32,8 @@ void rediwm_scene_damage_layout(struct wlr_scene *scene, const pixman_region32_t
output_view_region(&device, &v, true);
pixman_region32_intersect_rect(&device, &device, 0, 0, v.width, v.height);
wlr_damage_ring_add(&out->damage_ring, &device);
- pixman_region32_union(&out->private.pending_commit_damage,
- &out->private.pending_commit_damage, &device);
+ pixman_region32_union(&out->pending_commit_damage,
+ &out->pending_commit_damage, &device);
wlr_output_schedule_frame(output);
}
pixman_region32_fini(&device);
diff --git a/src/scene_damage.h b/src/scene_damage.h
index de1e146..dcb480c 100644
--- a/src/scene_damage.h
+++ b/src/scene_damage.h
@@ -1,6 +1,6 @@
#pragma once
-struct wlr_scene;
+struct rediwm_scene_outputs;
struct pixman_region32;
// Damages a layout-space region on every output it touches, for changes that
// move no view node (a clip's border colour).
-void rediwm_scene_damage_layout(struct wlr_scene *, const struct pixman_region32 *);
+void rediwm_scene_damage_layout(struct rediwm_scene_outputs *, const struct pixman_region32 *);
diff --git a/src/scene_output.c b/src/scene_output.c
index fe1425e..0393ca8 100644
--- a/src/scene_output.c
+++ b/src/scene_output.c
@@ -3,6 +3,7 @@
#define WLR_USE_UNSTABLE
#define WLR_PRIVATE private
#include "scene_output.h"
+#include "scene_outputs.h"
#include "scene_view.h"
#include "scene_pass.h"
#include "scene_graph.h"
@@ -24,7 +25,7 @@
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_output.h>
-#include <wlr/types/wlr_scene.h>
+#include "node.h"
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <wlr/util/transform.h>
@@ -60,7 +61,7 @@ struct output_state {
};
struct entry {
struct rediwm_item item;
- struct wlr_scene_node *transport;
+ struct rediwm_node *transport;
struct wlr_box box; // snap of item edges in layout space
pixman_region32_t visible, opaque;
bool sampled;
@@ -70,11 +71,11 @@ struct entry {
struct rediwm_glass_info glass;
struct wlr_box padded;
float sigma; // layout pixels
- struct wlr_scene_node *front;
+ struct rediwm_node *front;
struct effect_cache *cache;
bool reblur;
};
-static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, struct wlr_scene_output *out,
+static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, struct rediwm_scene_output *out,
struct wlr_render_pass *pass, const struct output_view *v, pixman_region32_t *damage, bool backdrop);
struct rediwm_output_renderer {
struct rediwm_scene_renderer *pass;
@@ -146,13 +147,7 @@ struct wlr_render_pass *rediwm_output_begin_pass(struct rediwm_output_renderer *
struct wlr_buffer *buffer, const struct wlr_buffer_pass_options *options) {
return rediwm_scene_pass_begin(r->pass, buffer, options);
}
-void rediwm_scene_output_damage_whole(struct wlr_scene_output *out) {
- wlr_damage_ring_add_whole(&out->damage_ring);
- pixman_region32_union_rect(&out->private.pending_commit_damage,
- &out->private.pending_commit_damage, 0, 0, out->output->width, out->output->height);
- wlr_output_schedule_frame(out->output);
-}
-bool rediwm_scene_output_set_veil(struct rediwm_output_renderer *r, struct wlr_scene_output *out, float alpha) {
+bool rediwm_scene_output_set_veil(struct rediwm_output_renderer *r, struct rediwm_scene_output *out, float alpha) {
alpha = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
struct output_state *os = alpha > 0 ? output_state_get(r, out->output) : output_state_find(r, out->output);
if (!os) return alpha == 0;
@@ -260,7 +255,7 @@ static bool same_clip(const struct rediwm_clip *a, const struct rediwm_clip *b)
for (int i = 0; i < 4; i++) if (a->radii[i] != b->radii[i]) return false;
return true;
}
-static bool collect(const struct rediwm_item *item, struct wlr_scene_node *transport, void *data) {
+static bool collect(const struct rediwm_item *item, struct rediwm_node *transport, void *data) {
struct collector *collector = data;
struct rediwm_output_renderer *r = collector->renderer;
if (!item->enabled) { return true; }
@@ -305,9 +300,9 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
// No buffer: the pixels are the shadow's, and never opaque.
skip = item->content.opacity == 0 || item->shadow->color[3] == 0;
} else {
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(transport);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(transport);
skip = item->content.opacity == 0 ||
- (!b->buffer && !b->private.texture && !b->private.is_single_pixel_buffer);
+ (!b->buffer && !b->texture && !b->is_single_pixel_buffer);
}
if (skip) { pixman_region32_fini(&visible); return true; }
if (here && !pixman_region32_not_empty(&visible) &&
@@ -331,16 +326,16 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
e->padded = (struct wlr_box){box.x - pad, box.y - pad, box.width + 2 * pad, box.height + 2 * pad};
pixman_region32_union_rect(&collector->reads, &collector->reads,
e->padded.x, e->padded.y, e->padded.width, e->padded.height);
- e->front = &glass.target->carrier->node;
+ e->front = &glass.target->node;
return true;
}
bool full = item->kind == REDIWM_ITEM_RECT && item->content.color[3] == 1;
if (item->kind != REDIWM_ITEM_RECT && item->kind != REDIWM_ITEM_SHADOW) {
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(transport);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(transport);
// Match the surface adapter's opacity policy. A cached raster whose
// buffer was released must not suddenly hide previously visible peers.
if (b->buffer && item->content.opacity == 1) {
- full = b->private.buffer_is_opaque;
+ full = b->buffer_is_opaque;
if (!full) {
rediwm_mirror_opaque(&e->opaque, &b->opaque_region, item->width, item->height, s.width, s.height);
pixman_region32_translate(&e->opaque, s.x, s.y);
@@ -376,49 +371,37 @@ static void clear_entries(struct rediwm_output_renderer *r) {
}
r->entries.size = 0;
}
-// The node's own texture cache, as wlr_scene keeps it. Buffer replacement and
-// scene destruction already clear it in wlroots. Do not keep an extra buffer
-// lock: shm clients must still update in place.
-static void texture_renderer_destroy(struct wl_listener *listener, void *data) {
- (void)data;
- struct wlr_scene_buffer *b = wl_container_of(listener, b, private.renderer_destroy);
- wl_list_remove(&b->private.renderer_destroy.link);
- wl_list_init(&b->private.renderer_destroy.link);
- wlr_texture_destroy(b->private.texture);
- b->private.texture = NULL;
-}
-static struct wlr_texture *buffer_texture(struct wlr_scene_buffer *b, struct wlr_renderer *renderer) {
- if (!b->buffer || b->private.texture) return b->private.texture;
+// The node's own texture cache. Do not keep an extra buffer lock: shm clients must
+// still update in place.
+static struct wlr_texture *buffer_texture(struct rediwm_buffer *b, struct wlr_renderer *renderer) {
+ if (!b->buffer || b->texture) return b->texture;
struct wlr_client_buffer *client = wlr_client_buffer_get(b->buffer);
if (client) return client->texture;
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, b->buffer);
if (!texture) return NULL;
- if (b->private.own_buffer) {
- b->private.own_buffer = false;
+ if (b->own_buffer) {
+ b->own_buffer = false;
wlr_buffer_unlock(b->buffer);
}
- b->private.texture = texture;
- wl_list_remove(&b->private.renderer_destroy.link);
- b->private.renderer_destroy.notify = texture_renderer_destroy;
- wl_signal_add(&renderer->events.destroy, &b->private.renderer_destroy);
+ rediwm_buffer_set_texture(b, texture);
return texture;
}
-static void sample(struct entry *e, struct wlr_scene_output *out, bool scanout) {
+static void sample(struct entry *e, struct rediwm_scene_output *out, bool scanout) {
if (e->item.kind == REDIWM_ITEM_RECT) return;
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(e->transport);
- struct wlr_scene_output_sample_event event = {
+ struct rediwm_buffer *b = rediwm_buffer_from_node(e->transport);
+ struct rediwm_output_sample_event event = {
.output = out, .direct_scanout = scanout,
- .release_timeline = scanout ? out->private.out_timeline : out->private.in_timeline,
- .release_point = scanout ? out->private.out_point : out->private.in_point,
+ .release_timeline = scanout ? out->out_timeline : out->in_timeline,
+ .release_point = scanout ? out->out_point : out->in_point,
};
wl_signal_emit_mutable(&b->events.output_sample, &event);
}
-static bool try_scanout(struct entry *e, struct wlr_scene_output *out,
+static bool try_scanout(struct entry *e, struct rediwm_scene_output *out,
struct wlr_output_state *state, const struct output_view *v) {
- if (e->item.clip || e->item.kind != REDIWM_ITEM_SURFACE || !out->scene->private.direct_scanout ||
+ if (e->item.clip || e->item.kind != REDIWM_ITEM_SURFACE || !out->outputs->direct_scanout ||
(state->committed & (WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_RENDER_FORMAT)) ||
!wlr_output_is_direct_scanout_allowed(out->output)) return false;
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(e->transport);
+ struct rediwm_buffer *b = rediwm_buffer_from_node(e->transport);
const struct rediwm_content *c = &e->item.content;
// Scanout shows the client's buffer as it is: a dimmed window needs the pass.
if (!b->buffer || c->transform != v->transform || c->opacity != 1 ||
@@ -448,10 +431,10 @@ static bool try_scanout(struct entry *e, struct wlr_scene_output *out,
wlr_output_state_set_buffer(&pending, buffer);
pending.buffer_src_box = c->src_box;
pending.buffer_dst_box = dst;
- if (b->private.wait_timeline)
- wlr_output_state_set_wait_timeline(&pending, b->private.wait_timeline, b->private.wait_point);
- if (out->private.out_timeline)
- wlr_output_state_set_signal_timeline(&pending, out->private.out_timeline, ++out->private.out_point);
+ if (b->wait_timeline)
+ wlr_output_state_set_wait_timeline(&pending, b->wait_timeline, b->wait_point);
+ if (out->out_timeline)
+ wlr_output_state_set_signal_timeline(&pending, out->out_timeline, ++out->out_point);
bool ok = wlr_output_test_state(out->output, &pending) && wlr_output_state_copy(state, &pending);
wlr_output_state_finish(&pending);
if (ok) sample(e, out, true);
@@ -511,7 +494,7 @@ static struct effect_cache *cache_for(struct output_state *os, uint64_t serial)
// A re-blur changes the effect's own pixels (`changed`). Returns false on
// allocation failure.
static bool decide_effects(struct rediwm_output_renderer *r, struct output_state *os,
- struct wlr_scene_output *out, const struct output_view *v, pixman_region32_t *changed) {
+ struct rediwm_scene_output *out, const struct output_view *v, pixman_region32_t *changed) {
struct entry *entries = r->entries.data;
const size_t len = r->entries.size / sizeof(*entries);
struct attribution a = {.view = v, .entries = entries, .len = len};
@@ -548,7 +531,7 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
pixman_region32_union_rect(&a.explained, &a.explained, 0, 0, v->width, v->height);
pixman_region32_t unexplained;
pixman_region32_init(&unexplained);
- pixman_region32_subtract(&unexplained, &out->private.pending_commit_damage, &a.explained);
+ pixman_region32_subtract(&unexplained, &out->pending_commit_damage, &a.explained);
struct effect_cache *c;
wl_list_for_each(c, &os->caches, link) c->seen = false;
bool ok = true;
@@ -605,7 +588,7 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
return ok;
}
static void render_effect(struct entry *e, struct wlr_render_pass *pass, const struct output_view *v,
- struct rediwm_output_renderer *r, struct wlr_scene_output *out, const pixman_region32_t *clip,
+ struct rediwm_output_renderer *r, struct rediwm_scene_output *out, const pixman_region32_t *clip,
bool backdrop) {
struct effect_cache *c = e->cache;
if (!c) return;
@@ -676,8 +659,8 @@ static void render_effect(struct entry *e, struct wlr_render_pass *pass, const s
for (size_t i = 0; i < len; i++) {
struct entry *f = &entries[i];
if (f->transport != e->front || f->item.kind == REDIWM_ITEM_RECT) continue;
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(f->transport);
- if (b->private.is_single_pixel_buffer || b->transform != WL_OUTPUT_TRANSFORM_NORMAL) break;
+ struct rediwm_buffer *b = rediwm_buffer_from_node(f->transport);
+ if (b->is_single_pixel_buffer || b->transform != WL_OUTPUT_TRANSFORM_NORMAL) break;
o.front = buffer_texture(b, renderer);
o.front_box = device_box(f->box, v);
o.front_opacity = f->item.content.opacity;
@@ -693,7 +676,7 @@ static void render_effect(struct entry *e, struct wlr_render_pass *pass, const s
// `backdrop`: drawing into an effect's quarter-size image (stage 5f), where an
// item counts with its whole box, not what is visible of it on screen, and
// `damage` is the region the blur reads.
-static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, struct wlr_scene_output *out,
+static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, struct rediwm_scene_output *out,
struct wlr_render_pass *pass, const struct output_view *v, pixman_region32_t *damage, bool backdrop) {
struct wlr_box dst = device_box(e->box, v);
if (misses_damage(&dst, damage)) return true;
@@ -771,9 +754,9 @@ static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, stru
if (!shaped) wlr_render_pass_add_rect(pass, &rect);
else if (pixman_region32_not_empty(&clip)) rediwm_scene_pass_add_rect_shaped(pass, &rect, &shape);
} else {
- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(e->transport);
- if (b->private.is_single_pixel_buffer) {
- const uint32_t *color = b->private.single_pixel_buffer_color;
+ struct rediwm_buffer *b = rediwm_buffer_from_node(e->transport);
+ if (b->is_single_pixel_buffer) {
+ const uint32_t *color = b->single_pixel_buffer_color;
// Match wlroots' single-pixel path during parity, including its
// treatment of opacity (only alpha is multiplied there).
struct wlr_render_rect_options rect = {.box = dst,
@@ -793,7 +776,7 @@ static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, stru
.texture = texture, .dst_box = dst, .src_box = c->src_box,
.transform = wlr_output_transform_compose(wlr_output_transform_invert(c->transform), v->transform),
.alpha = &c->opacity, .filter_mode = c->filter_mode,
- .wait_timeline = b->private.wait_timeline, .wait_point = b->private.wait_point,
+ .wait_timeline = b->wait_timeline, .wait_point = b->wait_point,
};
if (pixman_region32_not_empty(&core)) {
t.clip = &core;
@@ -837,7 +820,7 @@ static bool audit_read(struct wlr_renderer *renderer, struct wlr_buffer *buffer,
wlr_texture_destroy(texture);
return ok;
}
-static void audit_damage(struct rediwm_output_renderer *r, struct wlr_scene_output *out,
+static void audit_damage(struct rediwm_output_renderer *r, struct rediwm_scene_output *out,
struct wlr_buffer *real, struct entry *entries, size_t len, const struct output_view *v,
const pixman_region32_t *damage, float veil) {
struct wlr_output *output = out->output;
@@ -916,12 +899,10 @@ static void audit_damage(struct rediwm_output_renderer *r, struct wlr_scene_outp
}
#endif
bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
- struct rediwm_projection *projection, struct wlr_scene_output *out, struct wlr_output_state *state) {
+ struct rediwm_projection *projection, struct rediwm_scene_output *out, struct wlr_output_state *state) {
if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && !state->enabled) return true;
struct wlr_output *output = out->output;
- // These scene services are not installed by RediWM. KMS colour state is
- // applied later by Output.commitFrameState, for either presenter.
- if (out->scene->gamma_control_manager_v1 || out->private.combined_color_transform) return false;
+ // KMS colour state is applied later by Output.commitFrameState, for either presenter.
struct output_view v = {.width = output->width, .height = output->height,
.scale = state->committed & WLR_OUTPUT_STATE_SCALE ? state->scale : output->scale,
.transform = state->committed & WLR_OUTPUT_STATE_TRANSFORM ? state->transform : output->transform,
@@ -941,8 +922,8 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
r->projection = projection;
rediwm_projection_feedback_begin(projection);
struct collector collector = {.renderer = r, .view = &v};
- struct wlr_scene_output *other;
- wl_list_for_each(other, &out->scene->outputs, link) {
+ struct rediwm_scene_output *other;
+ wl_list_for_each(other, &out->outputs->outputs, link) {
if (other == out || !other->output->enabled || collector.others == 15) continue;
struct wlr_box *box = &collector.other[collector.others++];
*box = (struct wlr_box){.x = other->x, .y = other->y};
@@ -978,14 +959,14 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
if (pixman_region32_not_empty(&changed)) {
pixman_region32_intersect_rect(&changed, &changed, 0, 0, v.width, v.height);
wlr_damage_ring_add(&out->damage_ring, &changed);
- pixman_region32_union(&out->private.pending_commit_damage,
- &out->private.pending_commit_damage, &changed);
+ pixman_region32_union(&out->pending_commit_damage,
+ &out->pending_commit_damage, &changed);
}
pixman_region32_fini(&changed);
- wlr_output_state_set_damage(state, &out->private.pending_commit_damage);
+ wlr_output_state_set_damage(state, &out->pending_commit_damage);
bool scanout = len == 1 && veil == 0 && try_scanout(&entries[0], out, state, &v);
- if (out->private.prev_scanout != scanout) {
- out->private.prev_scanout = scanout;
+ if (out->prev_scanout != scanout) {
+ out->prev_scanout = scanout;
wlr_log(WLR_DEBUG, "Direct scan-out %s", scanout ? "enabled" : "disabled");
}
bool ok = scanout;
@@ -995,8 +976,8 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
buffer = wlr_swapchain_acquire(output->swapchain);
if (!buffer) goto done;
struct wlr_render_pass *pass = rediwm_scene_pass_begin(r->pass, buffer,
- &(struct wlr_buffer_pass_options){.signal_timeline = out->private.in_timeline,
- .signal_point = ++out->private.in_point});
+ &(struct wlr_buffer_pass_options){.signal_timeline = out->in_timeline,
+ .signal_point = ++out->in_point});
if (!pass) goto done;
pixman_region32_t damage, background;
pixman_region32_init(&damage);
@@ -1029,9 +1010,9 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
pixman_region32_fini(&damage);
if (ok) {
wlr_output_state_set_buffer(state, buffer);
- if (out->private.in_timeline) {
- wlr_output_state_set_wait_timeline(state, out->private.in_timeline, out->private.in_point);
- wlr_output_state_set_signal_timeline(state, out->private.out_timeline, ++out->private.out_point);
+ if (out->in_timeline) {
+ wlr_output_state_set_wait_timeline(state, out->in_timeline, out->in_point);
+ wlr_output_state_set_signal_timeline(state, out->out_timeline, ++out->out_point);
}
}
done:
diff --git a/src/scene_output.h b/src/scene_output.h
index 0ec85fb..dd923af 100644
--- a/src/scene_output.h
+++ b/src/scene_output.h
@@ -1,7 +1,7 @@
#pragma once
#include <stdbool.h>
struct wlr_renderer;
-struct wlr_scene_output;
+struct rediwm_scene_output;
struct wlr_output_state;
struct rediwm_projection;
struct rediwm_output_renderer;
@@ -22,11 +22,10 @@ struct wlr_render_pass *rediwm_output_begin_pass(struct rediwm_output_renderer *
// Builds but never commits. The scene adapter continues to own surface
// enter/leave, pacing and the damage notifications during stages 3–5.
bool rediwm_scene_output_build_state(struct rediwm_output_renderer *,
- struct rediwm_projection *, struct wlr_scene_output *, struct wlr_output_state *);
-void rediwm_scene_output_damage_whole(struct wlr_scene_output *);
+ struct rediwm_projection *, struct rediwm_scene_output *, struct wlr_output_state *);
// Black over everything the output pass draws except the software cursor, at this
// alpha (0 = none, 1 = black), for the session's fade in and the greeter's fade
// out. A change repaints the whole output but re-blurs no glass: the veil lies
// above every effect. Direct scan-out waits until it is 0. False only when the
// state for a nonzero veil could not be allocated.
-bool rediwm_scene_output_set_veil(struct rediwm_output_renderer *, struct wlr_scene_output *, float alpha);
+bool rediwm_scene_output_set_veil(struct rediwm_output_renderer *, struct rediwm_scene_output *, float alpha);
diff --git a/src/scene_output.zig b/src/scene_output.zig
index 50c64a5..14b8cc8 100644
--- a/src/scene_output.zig
+++ b/src/scene_output.zig
@@ -1,4 +1,5 @@
const wlr = @import("wlroots");
+const SceneOutput = @import("scene_outputs.zig").SceneOutput;
const Projection = @import("projection.zig").Projection;
extern var rediwm_scene_output_reblurs: u64;
@@ -14,12 +15,10 @@ pub const Renderer = opaque {
pub const enableBackdrops = rediwm_output_renderer_enable_backdrops;
extern fn rediwm_output_renderer_destroy(renderer: ?*Renderer) void;
pub const destroy = rediwm_output_renderer_destroy;
- extern fn rediwm_scene_output_build_state(renderer: *Renderer, projection: *Projection, output: *wlr.SceneOutput, state: *wlr.Output.State) bool;
+ extern fn rediwm_scene_output_build_state(renderer: *Renderer, projection: *Projection, output: *SceneOutput, state: *wlr.Output.State) bool;
pub const buildState = rediwm_scene_output_build_state;
extern fn rediwm_output_begin_pass(renderer: *Renderer, buffer: *wlr.Buffer, options: ?*const wlr.Renderer.BufferPassOptions) ?*wlr.RenderPass;
pub const beginPass = rediwm_output_begin_pass;
- extern fn rediwm_scene_output_set_veil(renderer: *Renderer, output: *wlr.SceneOutput, alpha: f32) bool;
+ extern fn rediwm_scene_output_set_veil(renderer: *Renderer, output: *SceneOutput, alpha: f32) bool;
pub const setVeil = rediwm_scene_output_set_veil;
};
-extern fn rediwm_scene_output_damage_whole(output: *wlr.SceneOutput) void;
-pub const damageWhole = rediwm_scene_output_damage_whole;
diff --git a/src/scene_outputs.c b/src/scene_outputs.c
new file mode 100644
index 0000000..d8f4517
--- /dev/null
+++ b/src/scene_outputs.c
@@ -0,0 +1,277 @@
+// Per-output state: see scene_outputs.h.
+#define WLR_USE_UNSTABLE
+#define WLR_PRIVATE private
+#include "scene_outputs.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <wlr/backend.h>
+#include <wlr/backend/drm.h>
+#include <wlr/render/drm_syncobj.h>
+#include <wlr/render/wlr_renderer.h>
+#include <wlr/types/wlr_color_management_v1.h>
+#include <wlr/types/wlr_output.h>
+#include <wlr/types/wlr_output_layout.h>
+#include <wlr/util/region.h>
+#include <wlr/util/transform.h>
+
+void rediwm_scene_output_damage(struct rediwm_scene_output *out, const pixman_region32_t *damage) {
+ struct wlr_output *output = out->output;
+
+ pixman_region32_t clipped;
+ pixman_region32_init(&clipped);
+ pixman_region32_intersect_rect(&clipped, damage, 0, 0, output->width, output->height);
+
+ if (!pixman_region32_empty(&clipped)) {
+ wlr_output_schedule_frame(output);
+ wlr_damage_ring_add(&out->damage_ring, &clipped);
+ pixman_region32_union(&out->pending_commit_damage, &out->pending_commit_damage, &clipped);
+ }
+
+ pixman_region32_fini(&clipped);
+}
+
+void rediwm_scene_output_damage_whole(struct rediwm_scene_output *out) {
+ wlr_damage_ring_add_whole(&out->damage_ring);
+ pixman_region32_union_rect(&out->pending_commit_damage, &out->pending_commit_damage, 0, 0,
+ out->output->width, out->output->height);
+ wlr_output_schedule_frame(out->output);
+}
+
+bool rediwm_scene_output_needs_frame(const struct rediwm_scene_output *out) {
+ return out->output->needs_frame || !pixman_region32_empty((pixman_region32_t *)&out->pending_commit_damage);
+}
+
+bool rediwm_scene_output_has_pending_damage(const struct rediwm_scene_output *out) {
+ return !pixman_region32_empty((pixman_region32_t *)&out->pending_commit_damage);
+}
+
+static void output_commit(struct wl_listener *listener, void *data) {
+ struct rediwm_scene_output *out = wl_container_of(listener, out, output_commit);
+ struct wlr_output_event_commit *event = data;
+ const struct wlr_output_state *state = event->state;
+
+ // If the output has been committed with a certain damage, we know that region will be
+ // acknowledged by the backend so we don't need to keep track of it anymore.
+ if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
+ if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
+ pixman_region32_subtract(&out->pending_commit_damage, &out->pending_commit_damage, &state->damage);
+ } else {
+ pixman_region32_fini(&out->pending_commit_damage);
+ pixman_region32_init(&out->pending_commit_damage);
+ }
+ }
+
+ // A new mode, or the output coming on, changes what every pixel shows. (Which surfaces
+ // are on it is the projection's to work out each frame.)
+ if (state->committed & (WLR_OUTPUT_STATE_TRANSFORM | WLR_OUTPUT_STATE_SCALE |
+ WLR_OUTPUT_STATE_SUBPIXEL | WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_ENABLED))
+ rediwm_scene_output_damage_whole(out);
+}
+
+static void output_damage(struct wl_listener *listener, void *data) {
+ struct rediwm_scene_output *out = wl_container_of(listener, out, output_damage);
+ struct wlr_output *output = out->output;
+ struct wlr_output_event_damage *event = data;
+
+ int width, height;
+ wlr_output_transformed_resolution(output, &width, &height);
+
+ pixman_region32_t damage;
+ pixman_region32_init(&damage);
+ pixman_region32_copy(&damage, event->damage);
+ wlr_region_transform(&damage, &damage, wlr_output_transform_invert(output->transform), width, height);
+ rediwm_scene_output_damage(out, &damage);
+ pixman_region32_fini(&damage);
+}
+
+static void output_needs_frame(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_scene_output *out = wl_container_of(listener, out, output_needs_frame);
+ wlr_output_schedule_frame(out->output);
+}
+
+static void layout_output_destroyed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_scene_output *out = wl_container_of(listener, out, layout_output_destroy);
+ wl_list_remove(&out->layout_output_destroy.link);
+ wl_list_init(&out->layout_output_destroy.link);
+ out->layout_output = NULL;
+}
+
+static void set_position(struct rediwm_scene_output *out, int x, int y) {
+ if (out->x == x && out->y == y) return;
+ out->x = x;
+ out->y = y;
+ rediwm_scene_output_damage_whole(out);
+}
+
+static void layout_changed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_scene_outputs *outputs = wl_container_of(listener, outputs, layout_change);
+ struct rediwm_scene_output *out;
+ wl_list_for_each(out, &outputs->outputs, link) {
+ if (out->layout_output) set_position(out, out->layout_output->x, out->layout_output->y);
+ }
+}
+
+static void layout_destroyed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_scene_outputs *outputs = wl_container_of(listener, outputs, layout_destroy);
+ wl_list_remove(&outputs->layout_change.link);
+ wl_list_init(&outputs->layout_change.link);
+ wl_list_remove(&outputs->layout_destroy.link);
+ wl_list_init(&outputs->layout_destroy.link);
+ outputs->layout = NULL;
+}
+
+static void color_manager_destroyed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct rediwm_scene_outputs *outputs = wl_container_of(listener, outputs, color_manager_destroy);
+ wl_list_remove(&outputs->color_manager_destroy.link);
+ wl_list_init(&outputs->color_manager_destroy.link);
+ outputs->color_manager_v1 = NULL;
+}
+
+static bool env_enabled(const char *name) {
+ const char *value = getenv(name);
+ return value && value[0] && value[0] != '0';
+}
+
+struct rediwm_scene_outputs *rediwm_scene_outputs_create(struct wlr_output_layout *layout) {
+ struct rediwm_scene_outputs *outputs = calloc(1, sizeof(*outputs));
+ if (!outputs) return NULL;
+ wl_list_init(&outputs->outputs);
+ outputs->direct_scanout = !env_enabled("WLR_SCENE_DISABLE_DIRECT_SCANOUT");
+ wl_list_init(&outputs->color_manager_destroy.link);
+ outputs->layout = layout;
+ outputs->layout_change.notify = layout_changed;
+ wl_signal_add(&layout->events.change, &outputs->layout_change);
+ outputs->layout_destroy.notify = layout_destroyed;
+ wl_signal_add(&layout->events.destroy, &outputs->layout_destroy);
+ return outputs;
+}
+
+void rediwm_scene_outputs_destroy(struct rediwm_scene_outputs *outputs) {
+ if (!outputs) return;
+ struct rediwm_scene_output *out, *tmp;
+ wl_list_for_each_safe(out, tmp, &outputs->outputs, link) rediwm_scene_output_destroy(out);
+ if (outputs->layout) {
+ wl_list_remove(&outputs->layout_change.link);
+ wl_list_remove(&outputs->layout_destroy.link);
+ }
+ // The manager outlives this and would walk a freed listener when the display goes.
+ wl_list_remove(&outputs->color_manager_destroy.link);
+ free(outputs);
+}
+
+void rediwm_scene_outputs_set_color_manager(struct rediwm_scene_outputs *outputs,
+ struct wlr_color_manager_v1 *manager) {
+ wl_list_remove(&outputs->color_manager_destroy.link);
+ wl_list_init(&outputs->color_manager_destroy.link);
+ outputs->color_manager_v1 = manager;
+ if (!manager) return;
+ outputs->color_manager_destroy.notify = color_manager_destroyed;
+ wl_signal_add(&manager->events.destroy, &outputs->color_manager_destroy);
+}
+
+static void addon_destroyed(struct wlr_addon *addon) {
+ struct rediwm_scene_output *out = wl_container_of(addon, out, addon);
+ rediwm_scene_output_destroy(out);
+}
+
+static const struct wlr_addon_interface output_addon_impl = {
+ .name = "rediwm_scene_output",
+ .destroy = addon_destroyed,
+};
+
+struct rediwm_scene_output *rediwm_scene_output_create(struct rediwm_scene_outputs *outputs,
+ struct wlr_output *output,
+ struct wlr_output_layout_output *layout_output) {
+ struct rediwm_scene_output *out = calloc(1, sizeof(*out));
+ if (!out) return NULL;
+
+ out->output = output;
+ out->outputs = outputs;
+ wlr_damage_ring_init(&out->damage_ring);
+ pixman_region32_init(&out->pending_commit_damage);
+
+ // The lowest free index, with the list kept in index order.
+ int prev_index = -1;
+ struct wl_list *prev_link = &outputs->outputs;
+ struct rediwm_scene_output *current;
+ wl_list_for_each(current, &outputs->outputs, link) {
+ if (prev_index + 1 != current->index) break;
+ prev_index = current->index;
+ prev_link = &current->link;
+ }
+
+ int drm_fd = wlr_backend_get_drm_fd(output->backend);
+ if (drm_fd >= 0 && output->backend->features.timeline && output->renderer != NULL &&
+ output->renderer->features.timeline) {
+ out->in_timeline = wlr_drm_syncobj_timeline_create(drm_fd);
+ out->out_timeline = wlr_drm_syncobj_timeline_create(drm_fd);
+ if (out->in_timeline == NULL || out->out_timeline == NULL) {
+ wlr_drm_syncobj_timeline_unref(out->in_timeline);
+ wlr_drm_syncobj_timeline_unref(out->out_timeline);
+ wlr_damage_ring_finish(&out->damage_ring);
+ pixman_region32_fini(&out->pending_commit_damage);
+ free(out);
+ return NULL;
+ }
+ }
+
+ out->index = prev_index + 1;
+ assert(out->index < 64);
+ wl_list_insert(prev_link, &out->link);
+ wlr_addon_init(&out->addon, &output->addons, outputs, &output_addon_impl);
+ wl_signal_init(&out->events.destroy);
+
+ out->output_commit.notify = output_commit;
+ wl_signal_add(&output->events.commit, &out->output_commit);
+ out->output_damage.notify = output_damage;
+ wl_signal_add(&output->events.damage, &out->output_damage);
+ out->output_needs_frame.notify = output_needs_frame;
+ wl_signal_add(&output->events.needs_frame, &out->output_needs_frame);
+
+ wl_list_init(&out->layout_output_destroy.link);
+ if (layout_output) {
+ out->layout_output = layout_output;
+ out->layout_output_destroy.notify = layout_output_destroyed;
+ wl_signal_add(&layout_output->events.destroy, &out->layout_output_destroy);
+ out->x = layout_output->x;
+ out->y = layout_output->y;
+ }
+ rediwm_scene_output_damage_whole(out);
+ return out;
+}
+
+void rediwm_scene_output_destroy(struct rediwm_scene_output *out) {
+ if (!out) return;
+ wl_signal_emit_mutable(&out->events.destroy, NULL);
+
+ wlr_addon_finish(&out->addon);
+ wlr_damage_ring_finish(&out->damage_ring);
+ pixman_region32_fini(&out->pending_commit_damage);
+ wl_list_remove(&out->link);
+ wl_list_remove(&out->output_commit.link);
+ wl_list_remove(&out->output_damage.link);
+ wl_list_remove(&out->output_needs_frame.link);
+ wl_list_remove(&out->layout_output_destroy.link);
+ if (out->in_timeline != NULL) {
+ wlr_drm_syncobj_timeline_signal(out->in_timeline, UINT64_MAX);
+ wlr_drm_syncobj_timeline_unref(out->in_timeline);
+ }
+ if (out->out_timeline != NULL) {
+ wlr_drm_syncobj_timeline_signal(out->out_timeline, UINT64_MAX);
+ wlr_drm_syncobj_timeline_unref(out->out_timeline);
+ }
+ free(out);
+}
+
+struct rediwm_scene_output *rediwm_scene_outputs_get(struct rediwm_scene_outputs *outputs,
+ struct wlr_output *output) {
+ struct wlr_addon *addon = wlr_addon_find(&output->addons, outputs, &output_addon_impl);
+ if (!addon) return NULL;
+ struct rediwm_scene_output *out = wl_container_of(addon, out, addon);
+ return out;
+}
diff --git a/src/scene_outputs.h b/src/scene_outputs.h
new file mode 100644
index 0000000..19398df
--- /dev/null
+++ b/src/scene_outputs.h
@@ -0,0 +1,90 @@
+// What the compositor keeps per output besides the output itself (stage 7c of
+// docs/plans/scene-graph-stage7.md): where it sits in the layout, the damage the
+// backend has not yet taken, the damage ring for its buffer swapchain, and the
+// explicit-sync timelines. It replaces wlr_scene_output, wlr_scene_output_layout and
+// the parts of wlr_scene that registered outputs (wlroots 0.20, MIT licensed; the
+// handlers follow types/wlr_scene.c and types/scene/output_layout.c).
+//
+// The output pass (scene_output.c) draws from the projection and asks this for
+// the damage to repaint; the frame loop asks `needs_frame`.
+#pragma once
+#include <pixman.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <time.h>
+#include <wayland-server-core.h>
+#include <wlr/types/wlr_damage_ring.h>
+#include <wlr/util/addon.h>
+
+struct wlr_output;
+struct wlr_output_layout;
+struct wlr_output_layout_output;
+struct wlr_color_manager_v1;
+struct wlr_drm_syncobj_timeline;
+struct rediwm_scene_outputs;
+
+struct rediwm_scene_output {
+ struct wlr_output *output;
+ struct wl_list link; // rediwm_scene_outputs.outputs, by index
+ struct rediwm_scene_outputs *outputs;
+ struct wlr_addon addon;
+ struct wlr_damage_ring damage_ring;
+ int x, y; // in the layout
+ int index; // below 64: a bit in the projection's masks
+ struct {
+ struct wl_signal destroy;
+ } events;
+ // What was damaged and not yet committed with a buffer.
+ pixman_region32_t pending_commit_damage;
+ bool prev_scanout;
+ // Explicit sync: the pass signals `in` when it has drawn, the scanout signals `out`.
+ struct wlr_drm_syncobj_timeline *in_timeline, *out_timeline;
+ uint64_t in_point, out_point;
+ struct wlr_output_layout_output *layout_output; // NULL once the layout dropped it
+ struct wl_listener layout_output_destroy, output_commit, output_damage, output_needs_frame;
+};
+
+struct rediwm_scene_outputs {
+ struct wl_list outputs; // rediwm_scene_output.link
+ // Scanning a client buffer out directly; WLR_SCENE_DISABLE_DIRECT_SCANOUT turns it off.
+ bool direct_scanout;
+ // For the preferred image description of surfaces; NULL until set.
+ struct wlr_color_manager_v1 *color_manager_v1;
+ struct wlr_output_layout *layout;
+ struct wl_listener color_manager_destroy, layout_change, layout_destroy;
+};
+
+// What a buffer node reports (the structs wlr_scene emitted, with our outputs).
+struct rediwm_outputs_update_event {
+ struct rediwm_scene_output **active;
+ size_t size;
+};
+struct rediwm_output_sample_event {
+ struct rediwm_scene_output *output;
+ bool direct_scanout;
+ struct wlr_drm_syncobj_timeline *release_timeline;
+ uint64_t release_point;
+};
+struct rediwm_frame_done_event {
+ struct rediwm_scene_output *output;
+ struct timespec when;
+};
+
+// Outputs follow `layout`: they take its positions as it changes.
+struct rediwm_scene_outputs *rediwm_scene_outputs_create(struct wlr_output_layout *layout);
+void rediwm_scene_outputs_destroy(struct rediwm_scene_outputs *);
+void rediwm_scene_outputs_set_color_manager(struct rediwm_scene_outputs *, struct wlr_color_manager_v1 *);
+
+// NULL on allocation failure. `layout_output` gives the position and keeps it current.
+struct rediwm_scene_output *rediwm_scene_output_create(struct rediwm_scene_outputs *,
+ struct wlr_output *,
+ struct wlr_output_layout_output *layout_output);
+void rediwm_scene_output_destroy(struct rediwm_scene_output *);
+struct rediwm_scene_output *rediwm_scene_outputs_get(struct rediwm_scene_outputs *, struct wlr_output *);
+
+// Damage in the output's device pixels (a frame is requested if any is on the buffer).
+void rediwm_scene_output_damage(struct rediwm_scene_output *, const pixman_region32_t *);
+void rediwm_scene_output_damage_whole(struct rediwm_scene_output *);
+// Whether anything asks for a frame: the output itself, or damage not yet committed.
+bool rediwm_scene_output_needs_frame(const struct rediwm_scene_output *);
+bool rediwm_scene_output_has_pending_damage(const struct rediwm_scene_output *);
diff --git a/src/scene_outputs.zig b/src/scene_outputs.zig
new file mode 100644
index 0000000..efc5bd7
--- /dev/null
+++ b/src/scene_outputs.zig
@@ -0,0 +1,31 @@
+//! Per-output state besides the output itself (scene_outputs.h).
+const wlr = @import("wlroots");
+
+pub const SceneOutput = opaque {
+ extern fn rediwm_scene_output_destroy(output: *SceneOutput) void;
+ pub const destroy = rediwm_scene_output_destroy;
+ extern fn rediwm_scene_output_needs_frame(output: *const SceneOutput) bool;
+ /// Whether anything asks for a frame: the output itself, or damage not yet committed.
+ pub const needsFrame = rediwm_scene_output_needs_frame;
+ extern fn rediwm_scene_output_has_pending_damage(output: *const SceneOutput) bool;
+ pub const hasPendingDamage = rediwm_scene_output_has_pending_damage;
+ extern fn rediwm_scene_output_damage_whole(output: *SceneOutput) void;
+ /// Repaints all of the output and asks for a frame.
+ pub const damageWhole = rediwm_scene_output_damage_whole;
+};
+
+pub const SceneOutputs = opaque {
+ extern fn rediwm_scene_outputs_create(layout: *wlr.OutputLayout) ?*SceneOutputs;
+ /// Outputs follow `layout`: they take its positions as it changes.
+ pub fn create(layout: *wlr.OutputLayout) !*SceneOutputs {
+ return rediwm_scene_outputs_create(layout) orelse error.OutOfMemory;
+ }
+ extern fn rediwm_scene_outputs_destroy(outputs: ?*SceneOutputs) void;
+ pub const destroy = rediwm_scene_outputs_destroy;
+ extern fn rediwm_scene_output_create(outputs: *SceneOutputs, output: *wlr.Output, layout_output: ?*wlr.OutputLayout.Output) ?*SceneOutput;
+ pub fn createOutput(outputs: *SceneOutputs, output: *wlr.Output, layout_output: ?*wlr.OutputLayout.Output) !*SceneOutput {
+ return rediwm_scene_output_create(outputs, output, layout_output) orelse error.OutOfMemory;
+ }
+ extern fn rediwm_scene_outputs_get(outputs: *SceneOutputs, output: *wlr.Output) ?*SceneOutput;
+ pub const get = rediwm_scene_outputs_get;
+};
diff --git a/src/screenshot/capture.zig b/src/screenshot/capture.zig
index 4a48157..369bedb 100644
--- a/src/screenshot/capture.zig
+++ b/src/screenshot/capture.zig
@@ -288,7 +288,7 @@ pub const Manager = struct {
failJob(job, "SessionLocked");
return;
}
- const scene_output = mgr.server.scene.getSceneOutput(job.output.wlr_output) orelse {
+ const scene_output = mgr.server.scene_outputs.get(job.output.wlr_output) orelse {
log.err("processPendingJob: no scene output for {s}", .{job.output_name});
failJob(job, "CaptureFailed: missing scene output");
return;
diff --git a/tests/output_destroy_hook.c b/tests/output_destroy_hook.c
index 4ba9a81..cfaaffe 100644
--- a/tests/output_destroy_hook.c
+++ b/tests/output_destroy_hook.c
@@ -1,4 +1,4 @@
-// Test-only hot-unplug injection and scene lifetime check in the real compositor.
+// Test-only hot-unplug injection and lifetime checks in the real compositor.
#define _GNU_SOURCE
#define WLR_USE_UNSTABLE
#include <assert.h>
@@ -7,15 +7,12 @@
#include <string.h>
#include <unistd.h>
#include <wlr/types/wlr_output.h>
-#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/backend.h>
#include <wlr/backend/headless.h>
-static struct wlr_scene *scene;
-static struct wlr_output *target, *dying;
+static struct wlr_output *target;
static struct wl_event_source *timer;
-static unsigned mutations;
static bool cursor_destroyed;
static bool unplugged, initialized;
static struct wlr_backend *headless;
@@ -23,10 +20,28 @@ static unsigned width, height;
static char *connector_name;
static bool reconnecting;
+static int unplug(void *data);
+
+// The first output the backend creates is the unplug target. This runs when the
+// backend names it, before the compositor has seen it.
void wlr_output_set_name(struct wlr_output *output, const char *name) {
void (*set_name)(struct wlr_output *, const char *) =
dlsym(RTLD_NEXT, "wlr_output_set_name");
assert(set_name);
+ if (!initialized) {
+ initialized = true;
+ target = output;
+ headless = output->backend;
+ width = output->width;
+ height = output->height;
+ if (getenv("REDIWM_TEST_REPLUG")) {
+ connector_name = strdup(name);
+ assert(connector_name);
+ }
+ timer = wl_event_loop_add_timer(output->event_loop, unplug, NULL);
+ assert(timer);
+ wl_event_source_timer_update(timer, 20);
+ }
// Present the same connector identity before the backend emits new_output.
set_name(output, reconnecting ? connector_name : name);
}
@@ -66,48 +81,8 @@ static int unplug(void *data) {
return 0;
}
if (!getenv("REDIWM_TEST_REPLUG")) wl_event_source_remove(timer);
- dying = target;
wlr_output_destroy(target);
- dying = NULL;
- assert(mutations > 0);
unplugged = true;
if (getenv("REDIWM_TEST_REPLUG")) wl_event_source_timer_update(timer, 20);
return 0;
}
-
-struct wlr_scene_output *wlr_scene_output_create(struct wlr_scene *s,
- struct wlr_output *output) {
- struct wlr_scene_output *(*create)(struct wlr_scene *, struct wlr_output *) =
- dlsym(RTLD_NEXT, "wlr_scene_output_create");
- assert(create);
- struct wlr_scene_output *result = create(s, output);
- if (!initialized && result) {
- initialized = true;
- scene = s;
- target = output;
- headless = output->backend;
- width = output->width;
- height = output->height;
- if (getenv("REDIWM_TEST_REPLUG")) {
- connector_name = strdup(output->name);
- assert(connector_name);
- }
- timer = wl_event_loop_add_timer(output->event_loop, unplug, NULL);
- assert(timer);
- wl_event_source_timer_update(timer, 20);
- }
- return result;
-}
-
-void wlr_scene_node_destroy(struct wlr_scene_node *node) {
- void (*destroy)(struct wlr_scene_node *) =
- dlsym(RTLD_NEXT, "wlr_scene_node_destroy");
- assert(destroy);
- if (dying) {
- // Removing per-output chrome must never uncover surfaces on an output
- // whose destroy signal is already in progress (wlroots issue #4096).
- assert(wlr_scene_get_scene_output(scene, dying) == NULL);
- ++mutations;
- }
- destroy(node);
-}