tiny.wayland.shm
Defined in tiny.wayland.
API (12)
Actions
Public operations.
Buffer.copyRegionRgba8Buffer.deinitBuffer.dispatchBuffer.fullRegion: Returns the rectangle covering the whole buffer, so a caller that sends the whole image passes this rectangle towriteRgba8for a present with no damage list.Buffer.openBuffer.writeRgba8: Converts the pixels of the rectangleregionof the full framergba8into the buffer, reordering each pixel's bytes into the buffer's format.Format.fromRaw
Types and contracts
Public types and contracts.
Source
Source: lib/wayland/src/shm/buffer.zig:38
zig
pub const Buffer = struct { object_id: u32, mapping: []align(std.heap.page_size_min) u8, byte_len: usize, width: u32, height: u32, stride: u32, format: Format, busy: bool = false, pub fn open( client: *runtime.Client, shm: u32, width: u32, height: u32, format: Format, ) Error!Buffer { const dimensions = try Dimensions.init(width, height); const descriptor = try createDescriptor(); var descriptor_owned = true; defer if (descriptor_owned) sys.fd.close(descriptor); try truncate(descriptor, dimensions.byte_len); const mapping = try mapDescriptor(descriptor, dimensions.byte_len); errdefer sys.memory.unmap(mapping); const pool = try createPool(client, shm, descriptor, dimensions.byte_len); descriptor_owned = false; var pool_live = true; defer if (pool_live) destroy(client, pool, core.wl_shm_pool.requests.destroy.opcode); const buffer_id = try createBuffer( client, pool, width, height, dimensions.stride, format, ); errdefer destroy( client, buffer_id, core.wl_buffer.requests.destroy.opcode, ); try closePool(client, pool); pool_live = false; return .{ .object_id = buffer_id, .mapping = mapping, .byte_len = dimensions.byte_len, .width = width, .height = height, .stride = dimensions.stride, .format = format, }; } pub fn deinit(self: *Buffer, client: *runtime.Client) void { destroy(client, self.object_id, core.wl_buffer.requests.destroy.opcode); sys.memory.unmap(self.mapping); self.* = undefined; } pub fn dispatch(self: *Buffer, event: *runtime.RoutedView) !void { if (event.object_id != self.object_id or event.metadata.opcode != core.wl_buffer.events.release.opcode) { return error.InvalidBufferEvent; } var decoder = try event.borrowedDecoder(); try decoder.finish(); self.busy = false; } /// Converts the pixels of the rectangle `region` of the full frame `rgba8` /// into the buffer, reordering each pixel's bytes into the buffer's format. /// The slice `rgba8` covers the whole buffer at the buffer's extent and /// stride, so a rectangle sits at the same byte offset in both. A present /// calls this to copy the changed part of a frame into the buffer the /// compositor will read. A present of the whole image passes the whole /// buffer as the rectangle, and a present of one change passes that /// change's rectangle and touches those rows alone. A source shorter than /// the buffer fails with `error.DestinationTooSmall`. A rectangle with zero /// width or height, or one reaching past the buffer's extent, fails with /// `error.InvalidRegion`. pub fn writeRgba8(self: *Buffer, rgba8: []const u8, region: Region) PixelError!void { if (rgba8.len < self.byte_len) return error.DestinationTooSmall; _ = try regionByteLen(self, region); std.debug.assert(self.stride == self.width * 4); const row_byte_len = @as(usize, region.width) * 4; var row: u32 = 0; while (row < region.height) : (row += 1) { const offset = @as(usize, region.y + row) * self.stride + @as(usize, region.x) * 4; convertToShm( self.mapping[offset..][0..row_byte_len], rgba8[offset..][0..row_byte_len], self.format, ); } } /// Returns the rectangle covering the whole buffer, so a caller that sends /// the whole image passes this rectangle to `writeRgba8` for a present with /// no damage list. pub fn fullRegion(self: *const Buffer) Region { return .{ .x = 0, .y = 0, .width = self.width, .height = self.height }; } pub fn copyRegionRgba8( self: *const Buffer, region: Region, destination: []u8, ) PixelError!void { const byte_len = try regionByteLen(self, region); if (destination.len < byte_len) return error.DestinationTooSmall; var row: u32 = 0; while (row < region.height) : (row += 1) { const source_offset = @as(usize, region.y + row) * self.stride + @as(usize, region.x) * 4; const destination_offset = @as(usize, row) * region.width * 4; const row_byte_len = @as(usize, region.width) * 4; convertFromShm( destination[destination_offset..][0..row_byte_len], self.mapping[source_offset..][0..row_byte_len], self.format, ); } }};Source: lib/wayland/src/shm/buffer.zig:27
zig
pub const Error = error{ OutOfMemory, DimensionsTooLarge, CreateFailed,};Source: lib/wayland/src/shm/buffer.zig:9
zig
pub const Format = enum(u32) { argb8888 = 0, xrgb8888 = 1, abgr8888 = 0x3432_4241, xbgr8888 = 0x3432_4258, pub fn fromRaw(raw: u32) ?Format { return std.enums.fromInt(Format, raw); }};Source: lib/wayland/src/shm/buffer.zig:33
zig
pub const PixelError = error{ InvalidRegion, DestinationTooSmall,};Source: lib/wayland/src/shm/buffer.zig:20
zig
pub const Region = struct { x: u32, y: u32, width: u32, height: u32,};Source: lib/wayland/src/root.zig:66
zig
pub const shm = @import("shm/root.zig");Source: lib/wayland/src/shm/root.zig
zig
const buffer = @import("buffer.zig");pub const Buffer = buffer.Buffer;pub const Error = buffer.Error;pub const Format = buffer.Format;pub const PixelError = buffer.PixelError;pub const Region = buffer.Region;Complete call list for shm.Buffer.open
8 direct calls.
lib.wayland.src.shm.buffer.Dimensions.init[function] — private source atlib/wayland/src/shm/buffer.zig:176in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.closePool[function] — private source atlib/wayland/src/shm/buffer.zig:263in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.createBuffer[function] — private source atlib/wayland/src/shm/buffer.zig:238in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.createDescriptor[function] — private source atlib/wayland/src/shm/buffer.zig:195in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.createPool[function] — private source atlib/wayland/src/shm/buffer.zig:218in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.destroy[function] — private source atlib/wayland/src/shm/buffer.zig:357in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.mapDescriptor[function] — private source atlib/wayland/src/shm/buffer.zig:203in nearest public ownerlib.wayland.src.shm.bufferlib.wayland.src.shm.buffer.truncate[function] — private source atlib/wayland/src/shm/buffer.zig:361in nearest public ownerlib.wayland.src.shm.buffer
Audit
| Definitions | 13 |
|---|---|
| Public names | 13 |
| Members | 21 |
| Version | 26.7.0 |
| Revision | daab053ee433 |