diff --git a/uefi-raw/CHANGELOG.md b/uefi-raw/CHANGELOG.md index f9e5cb6d4..725c0a749 100644 --- a/uefi-raw/CHANGELOG.md +++ b/uefi-raw/CHANGELOG.md @@ -2,6 +2,10 @@ ## Added +- Added `HiiFontProtocol`, `HiiFontExProtocol`. +- Added `HiiImageProtocol`, `HiiImageExProtocol`. +- Added `HiiStringProtocol`. + ## Changed diff --git a/uefi-raw/src/protocol/hii/config.rs b/uefi-raw/src/protocol/hii/config.rs index 1982524c3..24fb40882 100644 --- a/uefi-raw/src/protocol/hii/config.rs +++ b/uefi-raw/src/protocol/hii/config.rs @@ -4,6 +4,7 @@ use core::fmt::Debug; +use super::{FormId, QuestionId, StringId}; use crate::protocol::device_path::DevicePathProtocol; use crate::{Boolean, Char16, Guid, Status, guid, newtype_enum}; @@ -141,10 +142,6 @@ impl core::fmt::Debug for IfrTypeValue { } } -pub type QuestionId = u16; -pub type FormId = u16; -pub type StringId = u16; - /// EFI_HII_CONFIG_ACCESS_PROTOCOL #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/hii/font.rs b/uefi-raw/src/protocol/hii/font.rs new file mode 100644 index 000000000..ddd016715 --- /dev/null +++ b/uefi-raw/src/protocol/hii/font.rs @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Bindings for HII Font protocols and data types + +use super::{HiiHandle, StringId}; +use crate::protocol::console::GraphicsOutputBltPixel; +use crate::protocol::hii::image::ImageOutput; +use crate::{Char8, Char16, Guid, Status, guid}; + +pub type FontHandle = *mut core::ffi::c_void; + +#[derive(Debug)] +#[repr(C)] +pub struct HiiGlyphInfo { + pub width: u16, + pub height: u16, + pub offset_x: i16, + pub offset_y: i16, + pub advance_x: i16, +} + +bitflags::bitflags! { + /// EFI_FONT_INFO_MASK + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] + pub struct FontInfoMask: u32 { + const SYS_FONT = 1 << 0; + const SYS_SIZE = 1 << 1; + const SYS_STYLE = 1 << 2; + const SYS_FORE_COLOR = 1 << 4; + const SYS_BACK_COLOR = 1 << 5; + const RESIZE = 1 << 12; + const RESTYLE = 1 << 13; + const ANY_FONT = 1 << 16; + const ANY_SIZE = 1 << 17; + const ANY_STYLE = 1 << 18; + } +} + +bitflags::bitflags! { + /// EFI_HII_FONT_STYLE + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] + pub struct HiiFontStyle: u32 { + const NORMAL = 0; + const BOLD = 1 << 0; + const ITALIC = 1 << 1; + const EMBOSS = 1 << 16; + const OUTLINE = 1 << 17; + const SHADOW = 1 << 18; + const UNDERLINE = 1 << 19; + const DBL_UNDER = 1 << 20; + } +} + +/// EFI_FONT_INFO +#[derive(Debug)] +#[repr(C)] +pub struct FontInfo { + pub font_style: HiiFontStyle, + pub font_size: u16, + pub font_name: [Char16; 0], +} + +/// EFI_FONT_DISPLAY_INFO +#[derive(Debug)] +#[repr(C)] +pub struct FontDisplayInfo { + pub foreground_color: GraphicsOutputBltPixel, + pub background_color: GraphicsOutputBltPixel, + pub font_mask_info: FontInfoMask, + pub font_info: FontInfo, +} + +bitflags::bitflags! { + /// EFI_HII_OUT_FLAGS + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] + pub struct HiiOutFlags: u32 { + const CLIP = 1 << 0; + const WRAP = 1 << 1; + const CLIP_CLEAN_Y = 1 << 2; + const CLIP_CLEAN_X = 1 << 3; + const TRANSPARENT = 1 << 4; + const IGNORE_IF_NO_GLYPH = 1 << 5; + const IGNORE_LINE_BREAK = 1 << 6; + const DIRECT_TO_SCREEN = 1 << 7; + } +} + +/// EFI_HII_ROW_INFO +#[derive(Debug)] +#[repr(C)] +pub struct HiiRowInfo { + pub start_index: usize, + pub end_index: usize, + pub line_height: usize, + pub line_width: usize, + pub baseline_offset: usize, +} + +/// EFI_HII_FONT_PROTOCOL +#[derive(Debug)] +#[repr(C)] +pub struct HiiFontProtocol { + pub string_to_image: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiOutFlags, + string: *const Char16, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + row_info_array: *mut *mut HiiRowInfo, + row_info_array_size: *mut usize, + column_info_array: *mut usize, + ) -> Status, + pub string_id_to_image: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiOutFlags, + package_list: HiiHandle, + string_id: StringId, + language: *const Char8, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + row_info_array: *mut *mut HiiRowInfo, + row_info_array_size: *mut usize, + column_info_array: *mut usize, + ) -> Status, + pub get_glyph: unsafe extern "efiapi" fn( + this: *const Self, + char: Char16, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + baseline: *mut usize, + ) -> Status, + pub get_font_info: unsafe extern "efiapi" fn( + this: *const Self, + font_handle: *mut FontHandle, + string_info_in: *const FontDisplayInfo, + string_info_out: *mut *mut FontDisplayInfo, + string: *const Char16, + ) -> Status, +} + +impl HiiFontProtocol { + pub const GUID: Guid = guid!("e9ca4775-8657-47fc-97e7-7ed65a084324"); +} + +// NOTE: This protocol is declared in the UEFI spec, but not defined in edk2. +/// EFI_HII_FONT_EX_PROTOCOL +#[derive(Debug)] +#[repr(C)] +pub struct HiiFontExProtocol { + pub string_to_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiOutFlags, + string: *const Char16, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + row_info_array: *mut *mut HiiRowInfo, + row_info_array_size: *mut usize, + column_info_array: *mut usize, + ) -> Status, + pub string_id_to_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiOutFlags, + package_list: HiiHandle, + string_id: StringId, + language: *const Char8, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + row_info_array: *mut *mut HiiRowInfo, + row_info_array_size: *mut usize, + column_info_array: *mut usize, + ) -> Status, + pub get_glyph_ex: unsafe extern "efiapi" fn( + this: *const Self, + char: Char16, + string_info: *const FontDisplayInfo, + blt: *mut *mut ImageOutput, + baseline: *mut usize, + ) -> Status, + pub get_font_info_ex: unsafe extern "efiapi" fn( + this: *const Self, + font_handle: *mut FontHandle, + string_info_in: *const FontDisplayInfo, + string_info_out: *mut *mut FontDisplayInfo, + string: *const Char16, + ) -> Status, + pub get_glyph_info: unsafe extern "efiapi" fn( + this: *const Self, + char: Char16, + font_display_info: *const FontDisplayInfo, + glyph_info: *mut HiiGlyphInfo, + ) -> Status, +} + +impl HiiFontExProtocol { + pub const GUID: Guid = guid!("849e6875-db35-4df8-b41e-c8f33718073f"); +} diff --git a/uefi-raw/src/protocol/hii/image.rs b/uefi-raw/src/protocol/hii/image.rs new file mode 100644 index 000000000..62e943b6a --- /dev/null +++ b/uefi-raw/src/protocol/hii/image.rs @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Bindings for HII Image protocols and data types + +use super::{HiiHandle, ImageId}; +use crate::protocol::console::{GraphicsOutputBltPixel, GraphicsOutputProtocol}; +use crate::{Guid, Status, guid}; +use core::fmt; + +bitflags::bitflags! { + /// EFI_HII_DRAW_FLAGS + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] + pub struct HiiDrawFlags: u32 { + const DEFAULT = 0; + const CLIP = 1 << 0; + const FORCE_TRANS = 1 << 4; + const FORCE_OPAQUE = 1 << 5; + const TRANSPARENT = Self::FORCE_TRANS.bits() | Self::FORCE_OPAQUE.bits(); + const DIRECT_TO_SCREEN = 1 << 7; + } +} + +bitflags::bitflags! { + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] + pub struct ImageInputFlags: u32 { + const TRANSPARENT = 1 << 0; + } +} + +/// EFI_IMAGE_INPUT +#[derive(Debug)] +#[repr(C)] +pub struct ImageInput { + pub flags: ImageInputFlags, + pub width: u16, + pub height: u16, + pub bitmap: *const GraphicsOutputBltPixel, +} + +#[repr(C)] +pub union ImageOutputDest { + pub bitmap: *mut GraphicsOutputBltPixel, + pub screen: *mut GraphicsOutputProtocol, +} + +impl fmt::Debug for ImageOutputDest { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // All union fields are pointers. + f.debug_struct("ImageOutputDest") + .field("bitmap", unsafe { &self.bitmap }) + .field("screen", unsafe { &self.screen }) + .finish() + } +} + +impl Default for ImageOutputDest { + fn default() -> Self { + Self { + bitmap: core::ptr::null_mut(), + } + } +} + +/// EFI_IMAGE_OUTPUT +#[derive(Debug)] +#[repr(C)] +pub struct ImageOutput { + pub width: u16, + pub height: u16, + pub image: ImageOutputDest, +} + +/// EFI_HII_IMAGE_PROTOCOL +#[derive(Debug)] +#[repr(C)] +pub struct HiiImageProtocol { + pub new_image: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: *mut ImageId, + image: *const ImageInput, + ) -> Status, + pub get_image: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: ImageId, + image: *mut ImageInput, + ) -> Status, + pub set_image: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: ImageId, + image: *const ImageInput, + ) -> Status, + pub draw_image: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiDrawFlags, + image: *const ImageInput, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + ) -> Status, + pub draw_image_id: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiDrawFlags, + package_list: HiiHandle, + image_id: ImageId, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + ) -> Status, +} + +impl HiiImageProtocol { + pub const GUID: Guid = guid!("31a6406a-6bdf-4e46-b2a2-ebaa89c40920"); +} + +/// EFI_HII_IMAGE_EX_PROTOCOL +#[derive(Debug)] +#[repr(C)] +pub struct HiiImageExProtocol { + // NOTE: UEFI 2.11 declares `image` as an inout value; edk2 declares it as + // an input-only value, matching the non-extended protocol version. + pub new_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: *mut ImageId, + image: *const ImageInput, + ) -> Status, + pub get_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: ImageId, + image: *mut ImageInput, + ) -> Status, + pub set_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: ImageId, + image: *const ImageInput, + ) -> Status, + pub draw_image_ex: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiDrawFlags, + image: *const ImageInput, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + ) -> Status, + pub draw_image_id_ex: unsafe extern "efiapi" fn( + this: *const Self, + flags: HiiDrawFlags, + package_list: HiiHandle, + image_id: ImageId, + blt: *mut *mut ImageOutput, + blt_x: usize, + blt_y: usize, + ) -> Status, + pub get_image_info: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + image_id: ImageId, + image: *mut ImageOutput, + ) -> Status, +} + +impl HiiImageExProtocol { + pub const GUID: Guid = guid!("1a1241e6-8f19-41a9-bc0e-e8ef39e06546"); +} diff --git a/uefi-raw/src/protocol/hii/mod.rs b/uefi-raw/src/protocol/hii/mod.rs index 2df1f6a55..d90137286 100644 --- a/uefi-raw/src/protocol/hii/mod.rs +++ b/uefi-raw/src/protocol/hii/mod.rs @@ -4,11 +4,21 @@ pub mod config; pub mod database; +pub mod font; +pub mod image; +pub mod string; use crate::{Char16, Guid, newtype_enum}; pub type HiiHandle = *mut core::ffi::c_void; +pub type QuestionId = u16; +pub type ImageId = u16; +pub type StringId = u16; +pub type FormId = u16; +pub type VarstoreId = u16; +pub type AnimationId = u16; + /// EFI_HII_PACKAGE_HEADER #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/hii/string.rs b/uefi-raw/src/protocol/hii/string.rs new file mode 100644 index 000000000..e15bf6ccc --- /dev/null +++ b/uefi-raw/src/protocol/hii/string.rs @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Bindings for HII String protocols and data types + +use super::{HiiHandle, StringId}; +use crate::protocol::hii::font::FontInfo; +use crate::{Char8, Char16, Guid, Status, guid}; + +/// EFI_HII_STRING_PROTOCOL +#[derive(Debug)] +#[repr(C)] +pub struct HiiStringProtocol { + pub new_string: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + string_id: *mut StringId, + language: *const Char8, + language_name: *const Char16, + string: *const Char16, + string_font_info: *const FontInfo, + ) -> Status, + pub get_string: unsafe extern "efiapi" fn( + this: *const Self, + language: *const Char8, + package_list: HiiHandle, + string_id: StringId, + string: *mut *mut Char16, + string_size: *mut usize, + string_font_info: *mut *mut FontInfo, + ) -> Status, + pub set_string: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + string_id: StringId, + language: *const Char8, + string: *const Char16, + string_font_info: *const FontInfo, + ) -> Status, + pub get_languages: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + languages: *mut Char8, + languages_size: *mut usize, + ) -> Status, + pub get_secondary_languages: unsafe extern "efiapi" fn( + this: *const Self, + package_list: HiiHandle, + primary_language: *const Char8, + secondary_languages: *mut Char8, + secondary_languages_size: *mut usize, + ) -> Status, +} + +impl HiiStringProtocol { + pub const GUID: Guid = guid!("0fd96974-23aa-4cdc-b9cb-98d17750322a"); +}