diff options
Diffstat (limited to 'src/wl/shm')
| -rw-r--r-- | src/wl/shm/pixel/argb8888.zig | 6 | ||||
| -rw-r--r-- | src/wl/shm/pixel/root.zig | 0 | ||||
| -rw-r--r-- | src/wl/shm/pool.zig | 39 | ||||
| -rw-r--r-- | src/wl/shm/root.zig | 44 |
4 files changed, 32 insertions, 57 deletions
diff --git a/src/wl/shm/pixel/argb8888.zig b/src/wl/shm/pixel/argb8888.zig new file mode 100644 index 0000000..5e5a68e --- /dev/null +++ b/src/wl/shm/pixel/argb8888.zig @@ -0,0 +1,6 @@ +pub const Pixel = packed struct(u32) { + alpha: u8, + red: u8, + green: u8, + blue: u8, +} diff --git a/src/wl/shm/pixel/root.zig b/src/wl/shm/pixel/root.zig new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/wl/shm/pixel/root.zig diff --git a/src/wl/shm/pool.zig b/src/wl/shm/pool.zig index 62b6c18..16ba936 100644 --- a/src/wl/shm/pool.zig +++ b/src/wl/shm/pool.zig @@ -15,29 +15,11 @@ pub const Request = union(enum) { resize: struct { u32 }, }; -handle: wayland.Object.Ref, +handle: wayland.Object.Ref = .null, +init: wayland.Object.interface.Init(Self) = .{}, file: AnonymousFile, buffer: []u8, -pub fn init( - self: *Self, - ctx: wayland.Context, - size: usize, -) !void { - var file = try AnonymousFile.init_random(); - errdefer file.close(); - try file.truncate(size); - - self.* = .{ - .handle = try ctx.display.registry.add_object( - ctx.allocator, - wayland.Object.from_self(self), - ), - .file = file, - .buffer = try file.mmap(), - }; -} - pub fn deinit(self: *Self, ctx: wayland.Context) void { self.file.close(); std.posix.munmap(@alignCast(self.buffer)); @@ -51,9 +33,9 @@ pub fn deinit(self: *Self, ctx: wayland.Context) void { pub fn create_buffer( self: *Self, ctx: wayland.Context, - offset: usize, - width: usize, - height: usize, + offset: u32, + width: u32, + height: u32, comptime format: Format, ) !*wl.Buffer(format) { const stride = width * format.bytes_per_pixel(); @@ -61,12 +43,11 @@ pub fn create_buffer( const buffer = try ctx.allocator.create(wl.Buffer(format)); errdefer ctx.allocator.destroy(buffer); - try buffer.init( - ctx, - width, - height, - data, - ); + try buffer.init.with(ctx, .{ + .width = width, + .height = height, + .data = @alignCast(@ptrCast(data)), + }); try ctx.display.request( self, diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig index 741c7df..46388ad 100644 --- a/src/wl/shm/root.zig +++ b/src/wl/shm/root.zig @@ -13,46 +13,34 @@ pub const Request = union(enum) { create_pool: struct { wayland.Object.Ref, wayland.types.Fd, u32 }, }; -pub var instances: std.ArrayListUnmanaged(*Self) = .empty; - -handle: wayland.Object.Ref, +handle: wayland.Object.Ref = .null, +init: wayland.Object.interface.Init(Self) = .{}, 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 var globals: wayland.Object.interface.Global(Self) = .init; pub const handler: wl.Registry.GlobalHandler = .{ .interface = "wl_shm", .version = 1, - .handler = register, + .handler = globals.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; +fn announce_format(self: * Self, ctx: wayland.Context, fmt: Format) void { + _ = ctx; + self.formats.insert(fmt); } pub fn create_pool(self: *Self, ctx: wayland.Context, size: usize) !*Pool { const pool = try ctx.allocator.create(Pool); errdefer ctx.allocator.destroy(pool); - try pool.init(ctx, size); + + var file = try AnonymousFile.init_random(); + errdefer file.close(); + try file.truncate(size); + + try pool.init.with(ctx, .{ + .file = file, + .buffer = try file.mmap(), + }); try ctx.display.request(self, .{ .create_pool = .{ pool.handle, |