From dae5bc02b1c934075e95694953b4330676e21611 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 7 Feb 2025 20:39:58 +0100 Subject: estd: add graphics module --- src/screen/drm/buffer/root.zig | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/screen/drm/buffer/root.zig') diff --git a/src/screen/drm/buffer/root.zig b/src/screen/drm/buffer/root.zig index d40fd8d..f14ed66 100644 --- a/src/screen/drm/buffer/root.zig +++ b/src/screen/drm/buffer/root.zig @@ -1,4 +1,5 @@ const drm = @import("../root.zig"); +const graphics = @import("estd").graphics; pub const Buffer = struct { const Self = @This(); @@ -7,7 +8,7 @@ pub const Buffer = struct { current: Raw, crtc: Raw, - pub fn init(card: *drm.Card, width: u32, height: u32) !Self { + 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), @@ -15,10 +16,6 @@ pub const Buffer = struct { } pub fn swap(self: *Self) void { - const pixels = self.current.pixels; - self.current.pixels = self.crtc.pixels; - self.crtc.pixels = pixels; - const bytes = self.current.bytes; self.current.bytes = self.crtc.bytes; self.crtc.bytes = bytes; @@ -32,5 +29,16 @@ pub const Buffer = struct { 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.Pixel, + @ptrCast(@alignCast(self.current.bytes)) + )[0..self.current.bytes.len / 4], + }; + } }; -- cgit v1.2.3-70-g09d2