aboutsummaryrefslogtreecommitdiff
path: root/src/wl/shm/pool.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/wl/shm/pool.zig')
-rw-r--r--src/wl/shm/pool.zig48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/wl/shm/pool.zig b/src/wl/shm/pool.zig
index 1f42a17..40486d6 100644
--- a/src/wl/shm/pool.zig
+++ b/src/wl/shm/pool.zig
@@ -6,10 +6,12 @@ const AnonymousFile = wl.Shm.AnonymousFile;
const Self = @This();
+const log = std.log.scoped(.@"wl.shm.pool");
+
pub const Events = wayland.EventSet(@This(), .{});
-pub const Requests = union(enum) {
- create_buffer: struct { u32, u32, u32, u32, u32, Format },
- destroy: struct {},
+pub const Request = union(enum) {
+ create_buffer: struct { wayland.Object.Ref, u32, u32, u32, u32, Format },
+ destroy: void,
resize: struct { u32 },
};
@@ -40,5 +42,45 @@ pub fn deinit(self: *Self, ctx: *const wayland.Context) void {
self.file.close();
std.posix.munmap(@alignCast(self.buffer));
ctx.display.registry.disable_object(self.handle);
+ ctx.display.request(self, .{ .destroy = {} }) catch |e| {
+ log.err("error on deinit: {}", .{e});
+ };
self.* = undefined;
}
+
+pub fn create_buffer(
+ self: *Self,
+ ctx: *const wayland.Context,
+ offset: usize,
+ width: usize,
+ height: usize,
+ comptime format: Format,
+) !*wl.Buffer(format) {
+ const stride = width * format.bytes_per_pixel();
+ const data = self.buffer[offset..offset + stride * height];
+
+ const buffer = try ctx.allocator.create(wl.Buffer(format));
+ errdefer ctx.allocator.destroy(buffer);
+ try buffer.init(
+ ctx,
+ width,
+ height,
+ data,
+ );
+
+ try ctx.display.request(
+ self,
+ .{
+ .create_buffer = .{
+ buffer.handle,
+ @truncate(offset),
+ @truncate(width),
+ @truncate(height),
+ @truncate(stride),
+ format,
+ }
+ }
+ );
+
+ return buffer;
+}