const drm = @import("../root.zig"); const graphics = @import("estd").graphics; pub const Buffer = struct { const Self = @This(); pub const Raw = @import("raw.zig").Raw; current: Raw, crtc: Raw, pub fn init(card: drm.Card, width: u32, height: u32) !Self { return .{ .current = try Raw.init(card, width, height), .crtc = try Raw.init(card, width, height), }; } pub fn swap(self: *Self) void { const bytes = self.current.bytes; self.current.bytes = self.crtc.bytes; self.crtc.bytes = bytes; const id = self.current.id; self.current.id = self.crtc.id; self.crtc.id = id; } pub fn deinit(self: *Self) void { self.current.deinit(); self.crtc.deinit(); } pub fn canvas(self: *Self) graphics.Canvas { return .{ .width = self.current.width, .height = self.current.height, .buffer = @as( [*]volatile graphics.Color, @ptrCast(@alignCast(self.current.bytes)) )[0..self.current.bytes.len / 4], }; } };