aboutsummaryrefslogtreecommitdiff
path: root/src/wl/shm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wl/shm')
-rw-r--r--src/wl/shm/format.zig19
-rw-r--r--src/wl/shm/pool.zig48
2 files changed, 64 insertions, 3 deletions
diff --git a/src/wl/shm/format.zig b/src/wl/shm/format.zig
index e2766ab..6c2a30f 100644
--- a/src/wl/shm/format.zig
+++ b/src/wl/shm/format.zig
@@ -122,4 +122,23 @@ pub const Format = enum(u32) {
xvuy8888 = 0x59555658,
vyuy = 0x59555956,
uyvy = 0x59565955,
+
+ pub fn bytes_per_pixel(self: @This()) usize {
+ return switch (self) {
+ .argb8888 => 4,
+ else => @panic("unimplemented"),
+ };
+ }
+
+ pub fn Pixel(self: @This()) type {
+ return switch (self) {
+ .argb8888 => packed struct {
+ alpha: u8,
+ red: u8,
+ green: u8,
+ blue: u8
+ },
+ else => @panic("unimplemented"),
+ };
+ }
};
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;
+}