aboutsummaryrefslogtreecommitdiff
path: root/src/wl
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-08-24 07:08:31 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-08-24 07:08:31 +0200
commite66af367ddc2a17e8218efd37ddabd3a6b7557a4 (patch)
treef363c1661902760be57da31f937ff842e560b44e /src/wl
parentc2e723ca28321e09fbf58f396cb9e98591344a7e (diff)
Add wl.shm
Diffstat (limited to 'src/wl')
-rw-r--r--src/wl/registry.zig2
-rw-r--r--src/wl/root.zig1
-rw-r--r--src/wl/shm/format.zig125
-rw-r--r--src/wl/shm/pool.zig9
-rw-r--r--src/wl/shm/root.zig69
5 files changed, 205 insertions, 1 deletions
diff --git a/src/wl/registry.zig b/src/wl/registry.zig
index 9d91952..6c8ebdc 100644
--- a/src/wl/registry.zig
+++ b/src/wl/registry.zig
@@ -88,7 +88,7 @@ fn global(
interface: []const u8,
version: u32,
) !void {
- log.debug("global {s}", .{interface});
+ log.debug("global {s} {}", .{interface, version});
for (self.handlers) |handler| {
if (version == handler.version and std.mem.eql(u8, interface, handler.interface)) {
if (handler.handler(ctx)) |object_ref| {
diff --git a/src/wl/root.zig b/src/wl/root.zig
index d08c19b..43eb531 100644
--- a/src/wl/root.zig
+++ b/src/wl/root.zig
@@ -3,3 +3,4 @@ pub const Registry = @import("registry.zig");
pub const Callback = @import("callback.zig");
pub const Output = @import("output/root.zig");
pub const Compositor = @import("compositor.zig");
+pub const Shm = @import("shm/root.zig");
diff --git a/src/wl/shm/format.zig b/src/wl/shm/format.zig
new file mode 100644
index 0000000..e2766ab
--- /dev/null
+++ b/src/wl/shm/format.zig
@@ -0,0 +1,125 @@
+pub const Format = enum(u32) {
+ argb8888 = 0,
+ xrgb8888 = 1,
+ c1 = 0x20203143,
+ d1 = 0x20203144,
+ r1 = 0x20203152,
+ c2 = 0x20203243,
+ d2 = 0x20203244,
+ r2 = 0x20203252,
+ c4 = 0x20203443,
+ d4 = 0x20203444,
+ r4 = 0x20203452,
+ c8 = 0x20203843,
+ d8 = 0x20203844,
+ r8 = 0x20203852,
+ r10 = 0x20303152,
+ r12 = 0x20323152,
+ r16 = 0x20363152,
+ p010 = 0x30313050,
+ p210 = 0x30313250,
+ y210 = 0x30313259,
+ q410 = 0x30313451,
+ y410 = 0x30313459,
+ axbxgxrx106106106106 = 0x30314241,
+ yuv420_10bit = 0x30315559,
+ p030 = 0x30333050,
+ bgra1010102 = 0x30334142,
+ rgba1010102 = 0x30334152,
+ abgr2101010 = 0x30334241,
+ xbgr2101010 = 0x30334258,
+ argb2101010 = 0x30335241,
+ xrgb2101010 = 0x30335258,
+ vuy101010 = 0x30335556,
+ xvyu2101010 = 0x30335658,
+ bgrx1010102 = 0x30335842,
+ rgbx1010102 = 0x30335852,
+ x0l0 = 0x304c3058,
+ y0l0 = 0x304c3059,
+ q401 = 0x31303451,
+ yuv411 = 0x31315559,
+ yvu411 = 0x31315659,
+ nv21 = 0x3132564e,
+ nv61 = 0x3136564e,
+ p012 = 0x32313050,
+ y212 = 0x32313259,
+ y412 = 0x32313459,
+ bgra4444 = 0x32314142,
+ rgba4444 = 0x32314152,
+ abgr4444 = 0x32314241,
+ xbgr4444 = 0x32314258,
+ argb4444 = 0x32315241,
+ xrgb4444 = 0x32315258,
+ yuv420 = 0x32315559,
+ nv12 = 0x3231564e,
+ yvu420 = 0x32315659,
+ bgrx4444 = 0x32315842,
+ rgbx4444 = 0x32315852,
+ rg1616 = 0x32334752,
+ gr1616 = 0x32335247,
+ nv42 = 0x3234564e,
+ x0l2 = 0x324c3058,
+ y0l2 = 0x324c3059,
+ bgra8888 = 0x34324142,
+ rgba8888 = 0x34324152,
+ abgr8888 = 0x34324241,
+ xbgr8888 = 0x34324258,
+ bgr888 = 0x34324742,
+ rgb888 = 0x34324752,
+ vuy888 = 0x34325556,
+ yuv444 = 0x34325559,
+ nv24 = 0x3432564e,
+ yvu444 = 0x34325659,
+ bgrx8888 = 0x34325842,
+ rgbx8888 = 0x34325852,
+ bgra5551 = 0x35314142,
+ rgba5551 = 0x35314152,
+ abgr1555 = 0x35314241,
+ xbgr1555 = 0x35314258,
+ argb1555 = 0x35315241,
+ xrgb1555 = 0x35315258,
+ nv15 = 0x3531564e,
+ bgrx5551 = 0x35315842,
+ rgbx5551 = 0x35315852,
+ p016 = 0x36313050,
+ y216 = 0x36313259,
+ y416 = 0x36313459,
+ bgr565 = 0x36314742,
+ rgb565 = 0x36314752,
+ yuv422 = 0x36315559,
+ nv16 = 0x3631564e,
+ yvu422 = 0x36315659,
+ xvyu12_16161616 = 0x36335658,
+ yuv420_8bit = 0x38305559,
+ abgr16161616 = 0x38344241,
+ xbgr16161616 = 0x38344258,
+ argb16161616 = 0x38345241,
+ xrgb16161616 = 0x38345258,
+ xvyu16161616 = 0x38345658,
+ rg88 = 0x38384752,
+ gr88 = 0x38385247,
+ bgr565_a8 = 0x38413542,
+ rgb565_a8 = 0x38413552,
+ bgr888_a8 = 0x38413842,
+ rgb888_a8 = 0x38413852,
+ xbgr8888_a8 = 0x38414258,
+ xrgb8888_a8 = 0x38415258,
+ bgrx8888_a8 = 0x38415842,
+ rgbx8888_a8 = 0x38415852,
+ rgb332 = 0x38424752,
+ bgr233 = 0x38524742,
+ yvu410 = 0x39555659,
+ yuv410 = 0x39565559,
+ abgr16161616f = 0x48344241,
+ xbgr16161616f = 0x48344258,
+ argb16161616f = 0x48345241,
+ xrgb16161616f = 0x48345258,
+ yvyu = 0x55595659,
+ ayuv = 0x56555941,
+ xyuv8888 = 0x56555958,
+ yuyv = 0x56595559,
+ avuy8888 = 0x59555641,
+ xvuy8888 = 0x59555658,
+ vyuy = 0x59555956,
+ uyvy = 0x59565955,
+};
diff --git a/src/wl/shm/pool.zig b/src/wl/shm/pool.zig
new file mode 100644
index 0000000..dc30d1b
--- /dev/null
+++ b/src/wl/shm/pool.zig
@@ -0,0 +1,9 @@
+const wayland = @import("../../root.zig");
+const Format = @import("root.zig").Format;
+
+pub const Events = wayland.EventSet(@This(), .{});
+pub const Requests = union(enum) {
+ create_buffer: struct { u32, u32, u32, u32, u32, Format },
+ destroy: struct {},
+ resize: struct { u32 },
+};
diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig
new file mode 100644
index 0000000..2d24aca
--- /dev/null
+++ b/src/wl/shm/root.zig
@@ -0,0 +1,69 @@
+const std = @import("std");
+const wayland = @import("../../root.zig");
+const wl = wayland.wl;
+
+pub const Pool = @import("pool.zig");
+pub const Format = @import("format.zig").Format;
+
+const Self = @This();
+
+pub const Events = wayland.EventSet(Self, .{ announce_format });
+pub const Requests = union(enum) {
+ create_pool: struct { u32, wayland.types.Fd, u32 },
+};
+
+pub var instances: std.ArrayListUnmanaged(*Self) = .empty;
+
+handle: wayland.Object.Ref,
+formats: std.EnumSet(Format) = .initEmpty(),
+
+pub fn init(
+ self: *Self,
+ ctx: *wayland.Context,
+) !void {
+ self.* = .{
+ .handle = try ctx.display.registry.add_object(
+ ctx.allocator,
+ wayland.Object.from_self(self),
+ ),
+ };
+}
+
+fn announce_format(self: * Self, ctx: *wayland.Context, fmt: Format) void {
+ _ = ctx;
+ self.formats.insert(fmt);
+}
+
+pub const handler: wl.Registry.GlobalHandler = .{
+ .interface = "wl_shm",
+ .version = 1,
+ .handler = register,
+};
+
+fn register(ctx: *wayland.Context) ?wayland.Object.Ref {
+ const shm = ctx.allocator.create(Self) catch return null;
+ shm.init(ctx) catch return null;
+
+ instances.append(ctx.allocator, shm) catch return null;
+ return shm.handle;
+}
+
+pub fn format(
+ self: *const Self,
+ comptime fmt: []const u8,
+ options: std.fmt.FormatOptions,
+ writer: anytype,
+) !void {
+ _ = fmt;
+ _ = options;
+ try writer.print("wl.shm {{ ", .{});
+
+ {
+ var iterator = self.formats.iterator();
+ while (iterator.next()) |f| {
+ try writer.print("{s} ", .{@tagName(f)});
+ }
+ }
+
+ try writer.print("}}", .{});
+}