summaryrefslogtreecommitdiff
path: root/src/screen/drm/connector/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen/drm/connector/root.zig')
-rw-r--r--src/screen/drm/connector/root.zig161
1 files changed, 88 insertions, 73 deletions
diff --git a/src/screen/drm/connector/root.zig b/src/screen/drm/connector/root.zig
index c104e84..6141899 100644
--- a/src/screen/drm/connector/root.zig
+++ b/src/screen/drm/connector/root.zig
@@ -9,89 +9,104 @@ pub const Mode = @import("mode.zig").Mode;
pub const ConnectorType = @import("type.zig").Type;
const RawConnector = extern struct {
- encoder_ids: ?*u32,
- modes: ?*Mode,
- prop_ids: ?*u32,
- prop_value_ids: ?*u64,
- count_modes: u32,
- count_props: u32,
- count_encoders: u32,
- encoder_id: u32,
- id: u32,
- type: ConnectorType,
- type_id: u32,
- connection: Connection,
- mm_width: u32,
- mm_height: u32,
- subpixel: u32,
- pad: u32,
+ encoder_ids: ?*u32,
+ modes: ?*Mode,
+ prop_ids: ?*u32,
+ prop_value_ids: ?*u64,
+ count_modes: u32,
+ count_props: u32,
+ count_encoders: u32,
+ encoder_id: u32,
+ id: u32,
+ type: ConnectorType,
+ type_id: u32,
+ connection: Connection,
+ mm_width: u32,
+ mm_height: u32,
+ subpixel: u32,
+ pad: u32,
};
pub const Connector = struct {
- const Self = @This();
+ const Self = @This();
- card: *Card,
+ card: *Card,
- encoder_ids: []u32,
- modes: []Mode,
- prop_ids: []u32,
- prop_value_ids: []u64,
- encoder_id: u32,
- id: u32,
- type: ConnectorType,
- type_id: u32,
- connection: Connection,
- mm_width: u32,
- mm_height: u32,
- subpixel: u32,
- pad: u32,
+ encoder_ids: []u32,
+ modes: []Mode,
+ prop_ids: []u32,
+ prop_value_ids: []u64,
+ encoder_id: u32,
+ id: u32,
+ type: ConnectorType,
+ type_id: u32,
+ connection: Connection,
+ mm_width: u32,
+ mm_height: u32,
+ subpixel: u32,
+ pad: u32,
- pub fn raw_without_ids(card: *Card, id: u32) !RawConnector {
- var result = std.mem.zeroInit(RawConnector, .{ .id = id });
- try Drm.get_connector.request(card.file.handle, RawConnector, &result);
- return result;
- }
+ pub fn raw_without_ids(card: *Card, id: u32) !RawConnector {
+ var result = std.mem.zeroInit(RawConnector, .{ .id = id });
+ try Drm.get_connector.request(card.file.handle, RawConnector, &result);
+ return result;
+ }
- // NOTE: This function does not take in account
- // that there might be some hot-plugging going
- // on. This might have to change in the future.
- pub fn init(card: *Card, id: u32) !Self {
- var raw = try Self.raw_without_ids(card, id);
- const resources = .{
- .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
- .modes = try card.allocator.alloc(Mode, raw.count_modes),
- .prop_ids = try card.allocator.alloc(u32, raw.count_props),
- .prop_value_ids = try card.allocator.alloc(u64, raw.count_props),
- .encoder_id = raw.encoder_id,
- .id = raw.id,
- .type = raw.type,
- .type_id = raw.type_id,
- .connection = raw.connection,
- .mm_width = raw.mm_width,
- .mm_height = raw.mm_height,
- .subpixel = raw.subpixel,
- .pad = raw.pad,
- .card = card,
- };
+ // NOTE: This function does not take in account
+ // that there might be some hot-plugging going
+ // on. This might have to change in the future.
+ pub fn init(card: *Card, id: u32) !Self {
+ var raw = try Self.raw_without_ids(card, id);
+ const resources = .{
+ .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
+ .modes = try card.allocator.alloc(Mode, raw.count_modes),
+ .prop_ids = try card.allocator.alloc(u32, raw.count_props),
+ .prop_value_ids = try card.allocator.alloc(u64, raw.count_props),
+ .encoder_id = raw.encoder_id,
+ .id = raw.id,
+ .type = raw.type,
+ .type_id = raw.type_id,
+ .connection = raw.connection,
+ .mm_width = raw.mm_width,
+ .mm_height = raw.mm_height,
+ .subpixel = raw.subpixel,
+ .pad = raw.pad,
+ .card = card,
+ };
- @memset(resources.encoder_ids, 0);
- @memset(resources.modes, std.mem.zeroes(Mode));
- @memset(resources.prop_ids, 0);
- @memset(resources.prop_value_ids, 0);
+ @memset(resources.encoder_ids, 0);
+ @memset(resources.modes, std.mem.zeroes(Mode));
+ @memset(resources.prop_ids, 0);
+ @memset(resources.prop_value_ids, 0);
- raw.encoder_ids = @ptrCast(resources.encoder_ids);
- raw.modes = @ptrCast(resources.modes);
- raw.prop_ids = @ptrCast(resources.prop_ids);
- raw.prop_value_ids = @ptrCast(resources.prop_value_ids);
+ raw.encoder_ids = @ptrCast(resources.encoder_ids);
+ raw.modes = @ptrCast(resources.modes);
+ raw.prop_ids = @ptrCast(resources.prop_ids);
+ raw.prop_value_ids = @ptrCast(resources.prop_value_ids);
- try Drm.get_connector.request(card.file.handle, RawConnector, &raw);
+ try Drm.get_connector.request(card.file.handle, RawConnector, &raw);
- return resources;
- }
+ return resources;
+ }
- pub fn deinit(self: *Self) void {
- self.card.allocator.free(self.encoder_ids);
- self.card.allocator.free(self.modes);
- self.card.allocator.free(self.prop_ids);
- }
+ pub fn deinit(self: *Self) void {
+ self.card.allocator.free(self.encoder_ids);
+ self.card.allocator.free(self.modes);
+ self.card.allocator.free(self.prop_ids);
+ }
+
+ pub fn compatible_crtc(self: *Self) ?usize {
+ for (self.encoder_ids) |encoder_id| {
+ var encoder = self.card.encoder(encoder_id) catch continue;
+ defer encoder.deinit();
+
+ for (0..32) |index| {
+ if ((encoder.possible_crtcs & (@as(u32, 1) << @intCast(index))) != 0) {
+ return index;
+ }
+ }
+ }
+
+ return null;
+ }
};