diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-02-07 20:39:58 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-02-07 20:39:58 +0100 |
| commit | dae5bc02b1c934075e95694953b4330676e21611 (patch) | |
| tree | faa1a80849e5642d0b4bd8b4a91331b1da5b75bf /src/screen/drm/buffer/root.zig | |
| parent | fef523a8d7c87f272de18c8abd57e0cc53e2ef40 (diff) | |
estd: add graphics module
Diffstat (limited to 'src/screen/drm/buffer/root.zig')
| -rw-r--r-- | src/screen/drm/buffer/root.zig | 18 |
1 files changed, 13 insertions, 5 deletions
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], + }; + } }; |