summaryrefslogtreecommitdiff
path: root/src/screen/drm/buffer
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen/drm/buffer')
-rw-r--r--src/screen/drm/buffer/raw.zig8
-rw-r--r--src/screen/drm/buffer/root.zig18
2 files changed, 16 insertions, 10 deletions
diff --git a/src/screen/drm/buffer/raw.zig b/src/screen/drm/buffer/raw.zig
index a79c6a7..c5a04f3 100644
--- a/src/screen/drm/buffer/raw.zig
+++ b/src/screen/drm/buffer/raw.zig
@@ -6,16 +6,16 @@ const cerror = @import("../../cerror.zig");
pub const Raw = struct {
const Self = @This();
- card: *drm.Card,
+ card: drm.Card,
+
id: u32,
width: u32,
height: u32,
stride: u32,
handle: u32,
- pixels: []volatile drm.Pixel,
bytes: []volatile u8,
- pub fn init(card: *drm.Card, width: u32, height: u32) !Self {
+ pub fn init(card: drm.Card, width: u32, height: u32) !Self {
var create_dumb = std.mem.zeroInit(drm.request.CreateDumb, .{
.width = width,
.height = height,
@@ -32,7 +32,6 @@ pub const Raw = struct {
.height = create_dumb.height,
.stride = create_dumb.pitch,
.handle = create_dumb.handle,
- .pixels = undefined,
.bytes = undefined,
.card = card,
};
@@ -74,7 +73,6 @@ pub const Raw = struct {
try cerror.from_usize(address);
- fb.pixels = @as([*]volatile drm.Pixel, @ptrFromInt(address))[0..create_dumb.size / 4];
fb.bytes = @as([*]volatile u8, @ptrFromInt(address))[0..create_dumb.size];
return fb;
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],
+ };
+ }
};