diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-02-02 19:58:26 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-02-02 19:58:26 +0100 |
| commit | 3f4375a14218796cbd7bfff1c8cfff0f7bb1f6df (patch) | |
| tree | 1521b91b8f99af588156058b5f9aa12bb1626ac7 /src/screen/drm/connector | |
| parent | 8d062a90b1ffbe9e00334fa3e9e939406bd32141 (diff) | |
change .editorconfig
Diffstat (limited to 'src/screen/drm/connector')
| -rw-r--r-- | src/screen/drm/connector/connection.zig | 8 | ||||
| -rw-r--r-- | src/screen/drm/connector/mode.zig | 112 | ||||
| -rw-r--r-- | src/screen/drm/connector/root.zig | 161 | ||||
| -rw-r--r-- | src/screen/drm/connector/type.zig | 42 |
4 files changed, 169 insertions, 154 deletions
diff --git a/src/screen/drm/connector/connection.zig b/src/screen/drm/connector/connection.zig index 9c4a8d8..7377800 100644 --- a/src/screen/drm/connector/connection.zig +++ b/src/screen/drm/connector/connection.zig @@ -1,6 +1,6 @@ pub const Connection = enum(u32) { - undefined_state = 0, - connected = 1, - disconnected = 2, - unknown = 3, + undefined_state = 0, + connected = 1, + disconnected = 2, + unknown = 3, }; diff --git a/src/screen/drm/connector/mode.zig b/src/screen/drm/connector/mode.zig index fb61b5b..1e28a23 100644 --- a/src/screen/drm/connector/mode.zig +++ b/src/screen/drm/connector/mode.zig @@ -1,70 +1,70 @@ pub const Mode = extern struct { - const Self = @This(); + const Self = @This(); - const DimensionInfo = extern struct { - const Sync = extern struct { start: u16, end: u16 }; + const DimensionInfo = extern struct { + const Sync = extern struct { start: u16, end: u16 }; - size: u16, - sync: Sync, - total: u16, - }; + size: u16, + sync: Sync, + total: u16, +}; - const Type = packed struct(u32) { - builtin: bool, - clock_c: bool, - crtc_c: bool, - preferred: bool, - default: bool, - userdef: bool, - driver: bool, - _padding: u25, - }; +const Type = packed struct(u32) { + builtin: bool, + clock_c: bool, + crtc_c: bool, + preferred: bool, + default: bool, + userdef: bool, + driver: bool, + _padding: u25, +}; - const Flags = packed struct(u32) { - phsync: bool, - nhsync: bool, - pvsync: bool, - nvsync: bool, - interlace: bool, - dblscan: bool, - csync: bool, - pcsync: bool, - ncsync: bool, - hskew: bool, - bcast: bool, - pixmux: bool, - dblclk: bool, - clkdiv2: bool, - _padding: u18, - }; +const Flags = packed struct(u32) { + phsync: bool, + nhsync: bool, + pvsync: bool, + nvsync: bool, + interlace: bool, + dblscan: bool, + csync: bool, + pcsync: bool, + ncsync: bool, + hskew: bool, + bcast: bool, + pixmux: bool, + dblclk: bool, + clkdiv2: bool, + _padding: u18, + }; - clock: u32, - horizontal: DimensionInfo, - skew: u16, - vertical: DimensionInfo, - line_scans: u16, - vertical_refresh: u32, +clock: u32, + horizontal: DimensionInfo, + skew: u16, + vertical: DimensionInfo, + line_scans: u16, + vertical_refresh: u32, - flags: Flags, - type: Type, - name: [32]u8, + flags: Flags, + type: Type, + name: [32]u8, - pub fn frame_rate(self: *const Self) f32 { - var rate = (@as(u64, @intCast(self.clock)) * 1000000 / self.horizontal.total + self.vertical.total / 2) / self.vertical.total; + pub fn frame_rate(self: *const Self) f32 { + var rate = (@as(u64, @intCast(self.clock)) * 1000000 / self.horizontal.total + self.vertical.total / 2) / self.vertical.total; - if (self.flags.interlace) { - rate *= 2; - } + if (self.flags.interlace) { + rate *= 2; + } - if (self.flags.dblscan) { - rate /= 2; - } + if (self.flags.dblscan) { + rate /= 2; + } - if (self.line_scans > 1) { - rate /= self.line_scans; - } + if (self.line_scans > 1) { + rate /= self.line_scans; + } - return @as(f32, @floatFromInt(rate)) / 1000.0; - } + return @as(f32, @floatFromInt(rate)) / 1000.0; + } }; 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; + } }; diff --git a/src/screen/drm/connector/type.zig b/src/screen/drm/connector/type.zig index 15db753..c813c66 100644 --- a/src/screen/drm/connector/type.zig +++ b/src/screen/drm/connector/type.zig @@ -1,23 +1,23 @@ pub const Type = enum(u32) { - unknown = 0, - vga = 1, - dvi_i = 2, - dvi_d = 3, - dvi_a = 4, - composite = 5, - s_video = 6, - lvds = 7, - component = 8, - nine_pin_din = 9, - display_port = 10, - hdmi_a = 11, - hdmi_b = 12, - tv = 13, - edp = 14, - virtual = 15, - dsi = 16, - dpi = 17, - writeback = 18, - spi = 19, - usb = 20, + unknown = 0, + vga = 1, + dvi_i = 2, + dvi_d = 3, + dvi_a = 4, + composite = 5, + s_video = 6, + lvds = 7, + component = 8, + nine_pin_din = 9, + display_port = 10, + hdmi_a = 11, + hdmi_b = 12, + tv = 13, + edp = 14, + virtual = 15, + dsi = 16, + dpi = 17, + writeback = 18, + spi = 19, + usb = 20, }; |