From 85bcada8cf78bdf2bfb3be583289686026e0f25e Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 1 Feb 2025 12:47:35 +0100 Subject: screen: start drm implementation --- src/screen/drm/card.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/screen/drm/card.zig (limited to 'src/screen/drm/card.zig') diff --git a/src/screen/drm/card.zig b/src/screen/drm/card.zig new file mode 100644 index 0000000..67f81f3 --- /dev/null +++ b/src/screen/drm/card.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const os = std.os.linux; + +const cerror = @import("../cerror.zig"); + +const Resources = @import("resources.zig").Resources; +const Connector = @import("connector.zig").Connector; + + +pub const Card = struct { + const Self = @This(); + + file: std.fs.File, + allocator: std.mem.Allocator, + + pub fn open(name: []const u8, allocator: std.mem.Allocator) !Self { + var dri_dir = try std.fs.openDirAbsolute("/dev/dri", .{}); + defer dri_dir.close(); + + return .{ + .file = try dri_dir.openFile(name, .{ + .mode = .read_write, + .lock_nonblocking = true, + }), + .allocator = allocator, + }; + } + + pub fn close(self: *Card) void { + self.file.close(); + } + + pub fn is_kms(self: *Card) !bool { + const raw_info = Resources.raw_without_ids(self); + return raw_info.count_crtcs > 0 and raw_info.count_connectors > 0 and raw_info.count_encoders > 0; + } + + pub fn resources(self: *Card) !Resources { + return Resources.init(self); + } + + pub fn connector(self: *Card, id: u32) !Connector { + return Connector.init(self, id); + } +}; -- cgit v1.2.3-70-g09d2