diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-30 15:49:18 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-30 15:49:18 +0200 |
| commit | a46436e58beaaa322c082af5e886f96fd31d7a08 (patch) | |
| tree | 05a05b149c2f18cb0562aef94fe41bd5aaad9fbc /src/wl/shm/pool.zig | |
| parent | 4feb8c7dab2b0a3492b8248ee12c3f0a475106f1 (diff) | |
Diffstat (limited to 'src/wl/shm/pool.zig')
| -rw-r--r-- | src/wl/shm/pool.zig | 39 |
1 files changed, 10 insertions, 29 deletions
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, |