summaryrefslogtreecommitdiff
path: root/src/screen/drm/connector/mode.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-02-01 13:06:31 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-02-01 13:06:31 +0100
commit740281072f9e53e5ce62590a352f35d8cc02770a (patch)
tree903dd76feed6e640872a83bfeaeb6239c0870b6f /src/screen/drm/connector/mode.zig
parent85bcada8cf78bdf2bfb3be583289686026e0f25e (diff)
reorganize drm connector
Diffstat (limited to 'src/screen/drm/connector/mode.zig')
-rw-r--r--src/screen/drm/connector/mode.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/screen/drm/connector/mode.zig b/src/screen/drm/connector/mode.zig
new file mode 100644
index 0000000..9f4dfc4
--- /dev/null
+++ b/src/screen/drm/connector/mode.zig
@@ -0,0 +1,59 @@
+pub const Mode = extern struct {
+ const Self = @This();
+
+ const DimensionInfo = extern struct {
+ const Sync = extern struct { start: u16, end: u16 };
+
+ size: u16,
+ sync: Sync,
+ total: u16,
+ };
+
+ 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,
+
+ flags: Flags,
+ type: u32,
+ 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;
+
+ if (self.flags.interlace) {
+ rate *= 2;
+ }
+
+ if (self.flags.dblscan) {
+ rate /= 2;
+ }
+
+ if (self.line_scans > 1) {
+ rate /= self.line_scans;
+ }
+
+ return @as(f32, @floatFromInt(rate)) / 1000.0;
+ }
+};
+