diff options
Diffstat (limited to 'src/screen/drm/resources.zig')
| -rw-r--r-- | src/screen/drm/resources.zig | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/src/screen/drm/resources.zig b/src/screen/drm/resources.zig index 6128f37..fdd5042 100644 --- a/src/screen/drm/resources.zig +++ b/src/screen/drm/resources.zig @@ -5,72 +5,72 @@ const Card = @import("card.zig").Card; const Drm = @import("request.zig").Drm; const RawResources = extern struct { - fb_ids: ?*u32, - crtc_ids: ?*u32, - connector_ids: ?*u32, - encoder_ids: ?*u32, - count_fbs: u32, - count_crtcs: u32, - count_connectors: u32, - count_encoders: u32, - min_width: u32, - max_width: u32, - min_height: u32, - max_height: u32, + fb_ids: ?*u32, + crtc_ids: ?*u32, + connector_ids: ?*u32, + encoder_ids: ?*u32, + count_fbs: u32, + count_crtcs: u32, + count_connectors: u32, + count_encoders: u32, + min_width: u32, + max_width: u32, + min_height: u32, + max_height: u32, }; pub const Resources = struct { - const Self = @This(); - const Range = struct { min: u32, max: u32 }; + const Self = @This(); + const Range = struct { min: u32, max: u32 }; - card: *Card, + card: *Card, - fb_ids: []u32, - crtc_ids: []u32, - connector_ids: []u32, - encoder_ids: []u32, - width: Range, - height: Range, + fb_ids: []u32, + crtc_ids: []u32, + connector_ids: []u32, + encoder_ids: []u32, + width: Range, + height: Range, - pub fn raw_without_ids(card: *Card) !RawResources { - var result = std.mem.zeroes(RawResources); - try Drm.get_resources.request(card.file.handle, RawResources, &result); - return result; - } + pub fn raw_without_ids(card: *Card) !RawResources { + var result = std.mem.zeroes(RawResources); + try Drm.get_resources.request(card.file.handle, RawResources, &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) !Self { - var raw = try Self.raw_without_ids(card); - const resources = .{ - .fb_ids = try card.allocator.alloc(u32, raw.count_fbs), - .crtc_ids = try card.allocator.alloc(u32, raw.count_crtcs), - .connector_ids = try card.allocator.alloc(u32, raw.count_connectors), - .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders), - .width = .{ .min = raw.min_width, .max = raw.max_width }, - .height = .{ .min = raw.min_height, .max = raw.max_height }, - .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) !Self { + var raw = try Self.raw_without_ids(card); + const resources = .{ + .fb_ids = try card.allocator.alloc(u32, raw.count_fbs), + .crtc_ids = try card.allocator.alloc(u32, raw.count_crtcs), + .connector_ids = try card.allocator.alloc(u32, raw.count_connectors), + .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders), + .width = .{ .min = raw.min_width, .max = raw.max_width }, + .height = .{ .min = raw.min_height, .max = raw.max_height }, + .card = card, + }; - @memset(resources.fb_ids, 0); - @memset(resources.crtc_ids, 0); - @memset(resources.connector_ids, 0); - @memset(resources.encoder_ids, 0); + @memset(resources.fb_ids, 0); + @memset(resources.crtc_ids, 0); + @memset(resources.connector_ids, 0); + @memset(resources.encoder_ids, 0); - raw.fb_ids = @ptrCast(resources.fb_ids); - raw.crtc_ids = @ptrCast(resources.crtc_ids); - raw.connector_ids = @ptrCast(resources.connector_ids); - raw.encoder_ids = @ptrCast(resources.encoder_ids); - try Drm.get_resources.request(card.file.handle, RawResources, &raw); + raw.fb_ids = @ptrCast(resources.fb_ids); + raw.crtc_ids = @ptrCast(resources.crtc_ids); + raw.connector_ids = @ptrCast(resources.connector_ids); + raw.encoder_ids = @ptrCast(resources.encoder_ids); + try Drm.get_resources.request(card.file.handle, RawResources, &raw); - return resources; - } + return resources; + } - pub fn deinit(self: *Self) void { - self.card.allocator.free(self.fb_ids); - self.card.allocator.free(self.crtc_ids); - self.card.allocator.free(self.connector_ids); - self.card.allocator.free(self.encoder_ids); - } + pub fn deinit(self: *Self) void { + self.card.allocator.free(self.fb_ids); + self.card.allocator.free(self.crtc_ids); + self.card.allocator.free(self.connector_ids); + self.card.allocator.free(self.encoder_ids); + } }; |