| 1 | const std = @import("std"); |
| 2 | const uefi = std.os.uefi; |
| 3 | const Guid = uefi.Guid; |
| 4 | const Status = uefi.Status; |
| 5 | const cc = uefi.cc; |
| 6 | |
| 7 | pub const GraphicsOutput = extern struct { |
| 8 | _query_mode: *const fn (*const GraphicsOutput, u32, *usize, **Mode.Info) callconv(cc) Status, |
| 9 | _set_mode: *const fn (*GraphicsOutput, u32) callconv(cc) Status, |
| 10 | _blt: *const fn (*GraphicsOutput, ?[*]BltPixel, BltOperation, usize, usize, usize, usize, usize, usize, usize) callconv(cc) Status, |
| 11 | mode: *Mode, |
| 12 | |
| 13 | pub const QueryModeError = uefi.UnexpectedError || error{ |
| 14 | DeviceError, |
| 15 | InvalidParameter, |
| 16 | }; |
| 17 | pub const SetModeError = uefi.UnexpectedError || error{ |
| 18 | DeviceError, |
| 19 | Unsupported, |
| 20 | }; |
| 21 | pub const BltError = uefi.UnexpectedError || error{ |
| 22 | InvalidParameter, |
| 23 | DeviceError, |
| 24 | }; |
| 25 | |
| 26 | /// Returns information for an available graphics mode that the graphics device and the set of active video output devices supports. |
| 27 | pub fn queryMode(self: *const GraphicsOutput, mode_id: u32) QueryModeError!*Mode.Info { |
| 28 | var size_of_info: usize = undefined; |
| 29 | var info: *Mode.Info = undefined; |
| 30 | switch (self._query_mode(self, mode_id, &size_of_info, &info)) { |
| 31 | .success => return info, |
| 32 | .device_error => return error.DeviceError, |
| 33 | .invalid_parameter => return error.InvalidParameter, |
| 34 | else => |status| return uefi.unexpectedStatus(status), |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /// Set the video device into the specified mode and clears the visible portions of the output display to black. |
| 39 | pub fn setMode(self: *GraphicsOutput, mode_id: u32) SetModeError!void { |
| 40 | switch (self._set_mode(self, mode_id)) { |
| 41 | .success => {}, |
| 42 | .device_error => return error.DeviceError, |
| 43 | .unsupported => return error.Unsupported, |
| 44 | else => |status| return uefi.unexpectedStatus(status), |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer. |
| 49 | pub fn blt( |
| 50 | self: *GraphicsOutput, |
| 51 | blt_buffer: ?[*]BltPixel, |
| 52 | blt_operation: BltOperation, |
| 53 | source_x: usize, |
| 54 | source_y: usize, |
| 55 | destination_x: usize, |
| 56 | destination_y: usize, |
| 57 | width: usize, |
| 58 | height: usize, |
| 59 | delta: usize, |
| 60 | ) BltError!void { |
| 61 | switch (self._blt( |
| 62 | self, |
| 63 | blt_buffer, |
| 64 | blt_operation, |
| 65 | source_x, |
| 66 | source_y, |
| 67 | destination_x, |
| 68 | destination_y, |
| 69 | width, |
| 70 | height, |
| 71 | delta, |
| 72 | )) { |
| 73 | .success => {}, |
| 74 | .device_error => return error.DeviceError, |
| 75 | .invalid_parameter => return error.InvalidParameter, |
| 76 | else => |status| return uefi.unexpectedStatus(status), |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | pub const guid align(8) = Guid{ |
| 81 | .time_low = 0x9042a9de, |
| 82 | .time_mid = 0x23dc, |
| 83 | .time_high_and_version = 0x4a38, |
| 84 | .clock_seq_high_and_reserved = 0x96, |
| 85 | .clock_seq_low = 0xfb, |
| 86 | .node = [_]u8{ 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a }, |
| 87 | }; |
| 88 | |
| 89 | pub const Mode = extern struct { |
| 90 | max_mode: u32, |
| 91 | mode: u32, |
| 92 | info: *Info, |
| 93 | size_of_info: usize, |
| 94 | frame_buffer_base: u64, |
| 95 | frame_buffer_size: usize, |
| 96 | |
| 97 | pub const Info = extern struct { |
| 98 | version: u32, |
| 99 | horizontal_resolution: u32, |
| 100 | vertical_resolution: u32, |
| 101 | pixel_format: PixelFormat, |
| 102 | pixel_information: PixelBitmask, |
| 103 | pixels_per_scan_line: u32, |
| 104 | }; |
| 105 | }; |
| 106 | |
| 107 | pub const PixelFormat = enum(u32) { |
| 108 | red_green_blue_reserved_8_bit_per_color, |
| 109 | blue_green_red_reserved_8_bit_per_color, |
| 110 | bit_mask, |
| 111 | blt_only, |
| 112 | }; |
| 113 | |
| 114 | pub const PixelBitmask = extern struct { |
| 115 | red_mask: u32, |
| 116 | green_mask: u32, |
| 117 | blue_mask: u32, |
| 118 | reserved_mask: u32, |
| 119 | }; |
| 120 | |
| 121 | pub const BltPixel = extern struct { |
| 122 | blue: u8, |
| 123 | green: u8, |
| 124 | red: u8, |
| 125 | reserved: u8 = undefined, |
| 126 | }; |
| 127 | |
| 128 | pub const BltOperation = enum(u32) { |
| 129 | blt_video_fill, |
| 130 | blt_video_to_blt_buffer, |
| 131 | blt_buffer_to_video, |
| 132 | blt_video_to_video, |
| 133 | graphics_output_blt_operation_max, |
| 134 | }; |
| 135 | }; |