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