gfx_hal/display/
mod.rs

1//! Displays.
2//!
3//! A display represent a physical display collected from an Adapter
4
5use crate::{
6    window::{Extent2D, Offset2D},
7    Backend,
8};
9use std::ops::Range;
10
11pub mod control;
12
13bitflags! {
14    /**
15    List of the hardware display transformations
16    */
17    pub struct SurfaceTransformFlags : u32 {
18        /// Specify that image content is presented without being transformed.
19        const IDENTITY = 0x00000001;
20        /// Specify that image content is rotated 90 degrees clockwise.
21        const ROTATE_90 = 0x00000002;
22        /// Specify that image content is rotated 180 degrees clockwise.
23        const ROTATE_180 = 0x00000004;
24        /// Specify that image content is rotated 270 degrees clockwise.
25        const ROTATE_270 = 0x00000008;
26        /// Specify that image content is mirrored horizontally.
27        const HORIZONTAL_MIRROR = 0x00000010;
28        /// Specify that image content is mirrored horizontally, then rotated 90 degrees clockwise.
29        const HORIZONTAL_MIRROR_ROTATE_90 = 0x00000020;
30        /// Specify that image content is mirrored horizontally, then rotated 180 degrees clockwise.
31        const HORIZONTAL_MIRROR_ROTATE_180 = 0x00000040;
32        /// Specify that image content is mirrored horizontally, then rotated 270 degrees clockwise.
33        const HORIZONTAL_MIRROR_ROTATE_270 = 0x00000080;
34        /// Specify that the presentation transform is not specified, and is instead determined by platform-specific considerations and mechanisms outside Vulkan.
35        const INHERIT = 0x00000100;
36    }
37}
38impl From<SurfaceTransform> for SurfaceTransformFlags {
39    fn from(surface_transformation: SurfaceTransform) -> Self {
40        match surface_transformation {
41            SurfaceTransform::Identity => Self::IDENTITY,
42            SurfaceTransform::Rotate90 => Self::ROTATE_90,
43            SurfaceTransform::Rotate180 => Self::ROTATE_180,
44            SurfaceTransform::Rotate270 => Self::ROTATE_270,
45            SurfaceTransform::HorizontalMirror => Self::HORIZONTAL_MIRROR,
46            SurfaceTransform::HorizontalMirrorRotate90 => Self::HORIZONTAL_MIRROR_ROTATE_90,
47            SurfaceTransform::HorizontalMirrorRotate180 => Self::HORIZONTAL_MIRROR_ROTATE_180,
48            SurfaceTransform::HorizontalMirrorRotate270 => Self::HORIZONTAL_MIRROR_ROTATE_270,
49            SurfaceTransform::Inherit => Self::INHERIT,
50        }
51    }
52}
53
54#[derive(Debug, PartialEq)]
55#[allow(non_camel_case_types)]
56/**
57List of the hardware display transformations
58*/
59pub enum SurfaceTransform {
60    /// Specify that image content is presented without being transformed.
61    Identity,
62    /// Specify that image content is rotated 90 degrees clockwise.
63    Rotate90,
64    /// Specify that image content is rotated 180 degrees clockwise.
65    Rotate180,
66    /// Specify that image content is rotated 270 degrees clockwise.
67    Rotate270,
68    /// Specify that image content is mirrored horizontally.
69    HorizontalMirror,
70    /// Specify that image content is mirrored horizontally, then rotated 90 degrees clockwise.
71    HorizontalMirrorRotate90,
72    /// Specify that image content is mirrored horizontally, then rotated 180 degrees clockwise.
73    HorizontalMirrorRotate180,
74    /// Specify that image content is mirrored horizontally, then rotated 270 degrees clockwise.
75    HorizontalMirrorRotate270,
76    /// Specify that the presentation transform is not specified, and is instead determined by platform-specific considerations and mechanisms outside Vulkan.
77    Inherit,
78}
79impl Default for SurfaceTransform {
80    fn default() -> Self {
81        Self::Identity
82    }
83}
84
85/**
86General information about the a [display][Display].
87*/
88#[derive(Debug)]
89pub struct DisplayInfo {
90    /// Name of the display. Generally, this will be the name provided by the display’s EDID.
91    pub name: Option<String>,
92    /// Physical width and height of the visible portion of the display, in millimeters.
93    pub physical_dimensions: Extent2D,
94    /// Physical, native, or preferred resolution of the display.
95    pub physical_resolution: Extent2D,
96    /// Description of the supported transforms by the display.
97    pub supported_transforms: SurfaceTransformFlags,
98    /// Tells whether the planes on the display can have their z order changed. If true, the application can re-arrange the planes on this display in any order relative to each other.
99    pub plane_reorder_possible: bool,
100    /// Tells whether the display supports self-refresh/internal buffering. If true, the application can submit persistent present operations on swapchains created against this display.
101    pub persistent_content: bool,
102}
103
104bitflags! {
105    /**
106    Alpha mode used in display surface creation
107    */
108    pub struct DisplayPlaneAlphaFlags : u32 {
109        /// Specifies that the source image will be treated as opaque
110        const OPAQUE = 1;
111        /// Specifies that the provided global alpha value will be applied to all pixels in the source image.
112        const GLOBAL = 2;
113        /// Specifies that the alpha value will be determined by the alpha channel of the source image’s pixels.
114        /// If the source format contains no alpha values, no blending will be applied. The source alpha values are not premultiplied into the source image’s other color channels.
115        const PER_PIXEL = 4;
116        /// Equivalent to PerPixel, except the source alpha values are assumed to be premultiplied into the source image’s other color channels.
117        const PER_PIXEL_PREMULTIPLIED = 8;
118    }
119}
120impl From<DisplayPlaneAlpha> for DisplayPlaneAlphaFlags {
121    fn from(display_plane_alpha: DisplayPlaneAlpha) -> Self {
122        match display_plane_alpha {
123            DisplayPlaneAlpha::Opaque => Self::OPAQUE,
124            DisplayPlaneAlpha::Global(_) => Self::GLOBAL,
125            DisplayPlaneAlpha::PerPixel => Self::PER_PIXEL,
126            DisplayPlaneAlpha::PerPixelPremultiplied => Self::PER_PIXEL_PREMULTIPLIED,
127        }
128    }
129}
130
131/**
132Alpha mode used in display surface creation
133*/
134#[derive(Debug)]
135#[allow(non_camel_case_types)]
136pub enum DisplayPlaneAlpha {
137    /// Specifies that the source image will be treated as opaque
138    Opaque,
139    /// Specifies that the provided global alpha value will be applied to all pixels in the source image.
140    Global(f32),
141    /// Specifies that the alpha value will be determined by the alpha channel of the source image’s pixels. If the source format contains no alpha values, no blending will be applied. The source alpha values are not premultiplied into the source image’s other color channels.
142    PerPixel,
143    /// Equivalent to PerPixel, except the source alpha values are assumed to be premultiplied into the source image’s other color channels.
144    PerPixelPremultiplied,
145}
146
147impl Default for DisplayPlaneAlpha {
148    fn default() -> Self {
149        Self::Opaque
150    }
151}
152
153/// Error occurring on displays operations.
154#[derive(Clone, Debug, PartialEq, thiserror::Error)]
155pub enum DisplayError {
156    /// Out of either host or device memory.
157    #[error(transparent)]
158    OutOfMemory(#[from] crate::device::OutOfMemory),
159
160    /// Unsupported feature
161    #[error("Unsupported feature")]
162    UnsupportedFeature,
163}
164
165/// Error occurring on display modes operations.
166#[derive(Clone, Debug, PartialEq, thiserror::Error)]
167pub enum DisplayModeError {
168    /// Out of either host or device memory.
169    #[error(transparent)]
170    OutOfMemory(#[from] crate::device::OutOfMemory),
171
172    /// Unsupported resolution and refresh rate combination
173    #[error("Unsupported resolution and refresh rate combination")]
174    UnsupportedDisplayMode,
175}
176
177/// Error occurring while creating a display plane surface.
178#[derive(Clone, Debug, PartialEq, thiserror::Error)]
179pub enum DisplayPlaneSurfaceError {
180    /// Out of either host or device memory.
181    #[error(transparent)]
182    OutOfMemory(#[from] crate::device::OutOfMemory),
183
184    /// Unsupported feature
185    #[error("Unsupported feature")]
186    UnsupportedFeature,
187}
188
189/**
190Representation of a display
191*/
192#[derive(Debug)]
193pub struct Display<B: Backend> {
194    /// The display handle.
195    pub handle: B::Display,
196    /// General informations about this display.
197    pub info: DisplayInfo,
198    /// Builtin display modes
199    pub modes: Vec<DisplayMode<B>>,
200}
201
202/**
203General information about the a [DisplayMode][DisplayMode].
204*/
205#[derive(Debug)]
206pub struct DisplayMode<B: Backend> {
207    /// The display mode handle
208    pub handle: B::DisplayMode,
209    /// Resolution
210    pub resolution: (u32, u32),
211    /// Refresh rate
212    pub refresh_rate: u32,
213}
214
215/**
216Representation of a plane
217*/
218#[derive(Debug)]
219pub struct Plane {
220    /// The plane handle.
221    pub handle: u32,
222    /// The current index on the z stack.
223    pub z_index: u32,
224}
225
226/**
227Represent a combination of [display mode][DisplayMode] (so [display][Display] and resolution) and a plane
228*/
229#[derive(Debug)]
230pub struct DisplayPlane<'a, B: Backend> {
231    /// Display mode
232    pub display_mode: &'a DisplayMode<B>,
233    /// Plane index
234    pub plane: &'a Plane,
235    /// Supported alpha capabilities
236    pub supported_alpha: Vec<DisplayPlaneAlpha>,
237    /// The minimum and the maximum source rectangle offset supported by this plane using the specified mode.
238    pub src_position: Range<Offset2D>,
239    /// The minimum and maximum source rectangle size supported by this plane using the specified mode.
240    pub src_extent: Range<Extent2D>,
241    /// Same as src_position. but applied to destination.
242    pub dst_position: Range<Offset2D>,
243    /// Same as src_extent. but applied to destination.
244    pub dst_extent: Range<Extent2D>,
245}