summaryrefslogtreecommitdiff
path: root/src/screen/drm/card.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-02-02 16:00:15 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-02-02 16:00:15 +0100
commit8d062a90b1ffbe9e00334fa3e9e939406bd32141 (patch)
tree20951bba89bbcdc3090e24d99eb9f91c0043f28e /src/screen/drm/card.zig
parent0b6ee849722002a8bc7cc5374e3136bee4be2ccd (diff)
screen: add vsync and double buffering
Diffstat (limited to 'src/screen/drm/card.zig')
-rw-r--r--src/screen/drm/card.zig26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/screen/drm/card.zig b/src/screen/drm/card.zig
index d66a5f1..6147cf2 100644
--- a/src/screen/drm/card.zig
+++ b/src/screen/drm/card.zig
@@ -7,7 +7,8 @@ const Resources = @import("resources.zig").Resources;
const Connector = @import("connector/root.zig").Connector;
const Encoder = @import("encoder/root.zig").Encoder;
const Crtc = @import("crtc/root.zig").Crtc;
-const FrameBuffer = @import("frame-buffer/root.zig").FrameBuffer;
+const DoubleBuffer = @import("frame-buffer/root.zig").DoubleBuffer;
+const Event = @import("event.zig").Event;
pub const Card = struct {
@@ -25,6 +26,7 @@ pub const Card = struct {
.mode = .read_write,
.lock_nonblocking = true,
}),
+
.allocator = allocator,
};
}
@@ -54,7 +56,25 @@ pub const Card = struct {
return Crtc.init(self, id);
}
- pub fn create_frame_buffer(self: *Card, width: u32, height: u32, bpp: u32) !FrameBuffer {
- return FrameBuffer.init(self, width, height, bpp);
+ pub fn create_double_buffer(self: *Card, width: u32, height: u32, bpp: u32) !DoubleBuffer {
+ return DoubleBuffer.init(self, width, height, bpp);
+ }
+
+ pub fn poll_event(self: *Card, timeout: i32) !?Event {
+ var pollfd = os.pollfd {
+ .fd = self.file.handle,
+ .events = os.POLL.IN,
+ .revents = 0
+ };
+
+ try cerror.from_usize(os.poll(@ptrCast(&pollfd), 1, timeout));
+
+ if ((pollfd.revents & os.POLL.IN) != 0) {
+ var event = std.mem.zeroes(Event);
+ try cerror.from_usize(os.read(self.file.handle, @ptrCast(&event), @sizeOf(Event)));
+ return event;
+ }
+
+ return null;
}
};