@@ -2,6 +2,100 @@ const std = @import("std");
22const Allocator = std .mem .Allocator ;
33const os = @import ("os.zig" );
44
5+ pub const ModeSetPlane = extern struct {
6+ planeId : u32 = 0 ,
7+ crtcId : u32 = 0 ,
8+ fbId : u32 = 0 ,
9+ flags : u32 = 0 ,
10+ crtcX : i32 = 0 ,
11+ crtcY : i32 = 0 ,
12+ crtcWidth : u32 = 0 ,
13+ crtcHeight : u32 = 0 ,
14+ srcX : i32 = 0 ,
15+ srcY : i32 = 0 ,
16+ srcWidth : u32 = 0 ,
17+ srcHeight : u32 = 0 ,
18+
19+ pub const req = os .IOCTL .IOWR (0xB7 , ModeSetPlane );
20+
21+ pub fn set (self : * ModeSetPlane , fd : std.os.fd_t ) ! void {
22+ return switch (std .os .errno (os .ioctl (fd , req , @intFromPtr (self )))) {
23+ .SUCCESS = > {},
24+ .BADF = > error .NotOpenForWriting ,
25+ .NOENT = > error .NotFound ,
26+ .FAULT = > unreachable ,
27+ .INVAL = > unreachable ,
28+ .NOTTY = > error .NotATerminal ,
29+ .OPNOTSUPP = > error .NotSupported ,
30+ else = > | e | std .os .unexpectedErrno (e ),
31+ };
32+ }
33+ };
34+
35+ pub const ModeGetPlane = extern struct {
36+ planeId : u32 = 0 ,
37+ crtcId : u32 = 0 ,
38+ fbId : u32 = 0 ,
39+ possibleCrtcs : u32 = 0 ,
40+ gammaSize : u32 = 0 ,
41+ countFormatTypes : u32 = 0 ,
42+ formatTypesPtr : u64 = 0 ,
43+
44+ pub const req = os .IOCTL .IOWR (0xB6 , ModeGetPlane );
45+
46+ pub fn get (self : * ModeGetPlane , fd : std.os.fd_t ) ! void {
47+ return switch (std .os .errno (os .ioctl (fd , req , @intFromPtr (self )))) {
48+ .SUCCESS = > {},
49+ .BADF = > error .NotOpenForWriting ,
50+ .NOENT = > error .NotFound ,
51+ .FAULT = > unreachable ,
52+ .INVAL = > unreachable ,
53+ .NOTTY = > error .NotATerminal ,
54+ .OPNOTSUPP = > error .NotSupported ,
55+ else = > | e | std .os .unexpectedErrno (e ),
56+ };
57+ }
58+
59+ pub fn getAllocated (self : * ModeGetPlane , fd : std.os.fd_t , alloc : Allocator ) ! void {
60+ try self .get (fd );
61+
62+ errdefer self .deinit (alloc );
63+ if (self .countFormatTypes > 0 ) self .formatTypesPtr = @intFromPtr ((try alloc .alloc (u32 , self .countFormatTypes )).ptr );
64+
65+ try self .get (fd );
66+ }
67+
68+ pub fn deinit (self : * const ModeGetPlane , alloc : Allocator ) void {
69+ if (self .formatTypes ()) | v | alloc .free (v );
70+ }
71+
72+ pub fn format (self : * const ModeGetPlane , comptime _ : []const u8 , options : std.fmt.FormatOptions , writer : anytype ) ! void {
73+ _ = options ;
74+
75+ try writer .writeAll (@typeName (ModeGetConnector ));
76+ try writer .print ("{{ .planeId = {}, .crtcId = {}, .fbId = {}, .possibleCrtcs = {}, .gammaSize = {}" , .{
77+ self .planeId ,
78+ self .crtcId ,
79+ self .fbId ,
80+ self .possibleCrtcs ,
81+ self .gammaSize ,
82+ });
83+
84+ if (self .formatTypes ()) | v | try writer .print (", .formatTypes = {any}" , .{v });
85+
86+ try writer .writeAll (" }" );
87+ }
88+
89+ fn fieldPointer (self : * const ModeGetPlane , comptime field : std .meta .FieldEnum (ModeGetPlane ), comptime T : type , count : u32 ) ? []const T {
90+ if (@field (self , @tagName (field )) == 0 ) return null ;
91+ return @as ([* ]T , @ptrFromInt (@field (self , @tagName (field ))))[0.. count ];
92+ }
93+
94+ pub inline fn formatTypes (self : * const ModeGetPlane ) ? []const u32 {
95+ return self .fieldPointer (.formatTypesPtr , u32 , self .countFormatTypes );
96+ }
97+ };
98+
599pub const Event = union (Type ) {
6100 vblank : VBlank ,
7101 flipComplete : VBlank ,
0 commit comments