1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright (c) 2017, Dennis Hamester <dennis.hamester@startmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//! See extension [`VK_KHR_display`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VK_KHR_display)

mod display;
mod display_mode;

use core;
use khr_surface;
use utils;
use vks;

pub use self::display::DisplayKhr;
pub use self::display_mode::DisplayModeKhr;

bitflags! {
    /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
    #[derive(Default)]
    pub struct DisplayPlaneAlphaFlagsKhr: vks::VkDisplayPlaneAlphaFlagsKHR {
        /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
        const DISPLAY_PLANE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = vks::VK_DISPLAY_PLANE_ALPHA_FLAG_BITS_MAX_ENUM_KHR;

        /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
        const DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR = vks::VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR;

        /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
        const DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR = vks::VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR;

        /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
        const DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR = vks::VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR;

        /// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
        const DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR = vks::VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR;
    }
}

/// See [`VkDisplayPlaneAlphaFlagBitsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneAlphaFlagBitsKHR)
pub type DisplayPlaneAlphaFlagBitsKhr = DisplayPlaneAlphaFlagsKhr;

bitflags! {
    /// See [`VkDisplayModeCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModeCreateFlagsKHR)
    #[derive(Default)]
    pub struct DisplayModeCreateFlagsKhr: vks::VkDisplayModeCreateFlagsKHR {
        /// See [`VkDisplayModeCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModeCreateFlagsKHR)
        const DISPLAY_MODE_CREATE_FLAG_BITS_MAX_ENUM_KHR = vks::VK_DISPLAY_MODE_CREATE_FLAG_BITS_MAX_ENUM_KHR;
    }
}

/// See [`VkDisplayModeCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModeCreateFlagsKHR)
pub type DisplayModeCreateFlagBitsKhr = DisplayModeCreateFlagsKhr;

bitflags! {
    /// See [`VkDisplaySurfaceCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplaySurfaceCreateFlagsKHR)
    #[derive(Default)]
    pub struct DisplaySurfaceCreateFlagsKhr: vks::VkDisplaySurfaceCreateFlagsKHR {
        /// See [`VkDisplaySurfaceCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplaySurfaceCreateFlagsKHR)
        const DISPLAY_SURFACE_CREATE_FLAG_BITS_MAX_ENUM_KHR = vks::VK_DISPLAY_SURFACE_CREATE_FLAG_BITS_MAX_ENUM_KHR;
    }
}

/// See [`VkDisplaySurfaceCreateFlagsKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplaySurfaceCreateFlagsKHR)
pub type DisplaySurfaceCreateFlagBitsKhr = DisplaySurfaceCreateFlagsKhr;

/// See [`VkDisplayPropertiesKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPropertiesKHR)
#[derive(Debug, Clone, PartialEq)]
pub struct DisplayPropertiesKhr {
    pub display: DisplayKhr,
    pub display_name: Option<String>,
    pub physical_dimensions: core::Extent2D,
    pub physical_resolution: core::Extent2D,
    pub supported_transforms: khr_surface::SurfaceTransformFlagsKhr,
    pub plane_reorder_possible: bool,
    pub persistent_content: bool,
}

impl DisplayPropertiesKhr {
    pub(crate) unsafe fn from_vks(properties: &vks::VkDisplayPropertiesKHR, physical_device: core::PhysicalDevice) -> Self {
        DisplayPropertiesKhr {
            display: DisplayKhr::new(properties.display, physical_device),
            display_name: utils::string_from_cstr(properties.displayName),
            physical_dimensions: (&properties.physicalDimensions).into(),
            physical_resolution: (&properties.physicalResolution).into(),
            supported_transforms: khr_surface::SurfaceTransformFlagsKhr::from_bits_truncate(properties.supportedTransforms),
            plane_reorder_possible: utils::from_vk_bool(properties.planeReorderPossible),
            persistent_content: utils::from_vk_bool(properties.persistentContent),
        }
    }
}

/// See [`VkDisplayModeParametersKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModeParametersKHR)
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DisplayModeParametersKhr {
    pub visible_region: core::Extent2D,
    pub refresh_rate: u32,
}

impl<'a> From<&'a vks::VkDisplayModeParametersKHR> for DisplayModeParametersKhr {
    fn from(parameters: &'a vks::VkDisplayModeParametersKHR) -> Self {
        DisplayModeParametersKhr {
            visible_region: (&parameters.visibleRegion).into(),
            refresh_rate: parameters.refreshRate,
        }
    }
}

impl<'a> From<&'a DisplayModeParametersKhr> for vks::VkDisplayModeParametersKHR {
    fn from(parameters: &'a DisplayModeParametersKhr) -> Self {
        vks::VkDisplayModeParametersKHR {
            visibleRegion: (&parameters.visible_region).into(),
            refreshRate: parameters.refresh_rate,
        }
    }
}

/// See [`VkDisplayModePropertiesKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModePropertiesKHR)
#[derive(Debug, Clone, PartialEq)]
pub struct DisplayModePropertiesKhr {
    pub display_mode: DisplayModeKhr,
    pub parameters: DisplayModeParametersKhr,
}

impl DisplayModePropertiesKhr {
    pub(crate) fn from_vks(properties: &vks::VkDisplayModePropertiesKHR, display: DisplayKhr) -> Self {
        DisplayModePropertiesKhr {
            display_mode: DisplayModeKhr::new(properties.displayMode, display),
            parameters: (&properties.parameters).into(),
        }
    }
}

gen_chain_struct! {
    name: DisplayModeCreateInfoChainKhr [DisplayModeCreateInfoChainKhrWrapper],
    query: DisplayModeCreateInfoChainQueryKhr [DisplayModeCreateInfoChainQueryKhrWrapper],
    vks: VkDisplayModeCreateInfoKHR,
    input: true,
    output: false,
}

/// See [`VkDisplayModeCreateInfoKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayModeCreateInfoKHR)
#[derive(Debug, Clone, PartialEq)]
pub struct DisplayModeCreateInfoKhr {
    pub flags: DisplayModeCreateFlagsKhr,
    pub parameters: DisplayModeParametersKhr,
    pub chain: Option<DisplayModeCreateInfoChainKhr>,
}

#[derive(Debug)]
struct VkDisplayModeCreateInfoKHRWrapper {
    pub vks_struct: vks::VkDisplayModeCreateInfoKHR,
    chain: Option<DisplayModeCreateInfoChainKhrWrapper>,
}

impl VkDisplayModeCreateInfoKHRWrapper {
    fn new(create_info: &DisplayModeCreateInfoKhr, with_chain: bool) -> Self {
        let (pnext, chain) = DisplayModeCreateInfoChainKhrWrapper::new_optional(&create_info.chain, with_chain);

        VkDisplayModeCreateInfoKHRWrapper {
            vks_struct: vks::VkDisplayModeCreateInfoKHR {
                sType: vks::VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR,
                pNext: pnext,
                flags: create_info.flags.bits(),
                parameters: (&create_info.parameters).into(),
            },
            chain: chain,
        }
    }
}

/// See [`VkDisplayPlaneCapabilitiesKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlaneCapabilitiesKHR)
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DisplayPlaneCapabilitiesKhr {
    pub supported_alpha: DisplayPlaneAlphaFlagsKhr,
    pub min_src_position: core::Offset2D,
    pub max_src_position: core::Offset2D,
    pub min_src_extent: core::Extent2D,
    pub max_src_extent: core::Extent2D,
    pub min_dst_position: core::Offset2D,
    pub max_dst_position: core::Offset2D,
    pub min_dst_extent: core::Extent2D,
    pub max_dst_extent: core::Extent2D,
}

impl<'a> From<&'a vks::VkDisplayPlaneCapabilitiesKHR> for DisplayPlaneCapabilitiesKhr {
    fn from(capabilities: &'a vks::VkDisplayPlaneCapabilitiesKHR) -> Self {
        DisplayPlaneCapabilitiesKhr {
            supported_alpha: DisplayPlaneAlphaFlagsKhr::from_bits_truncate(capabilities.supportedAlpha),
            min_src_position: (&capabilities.minSrcPosition).into(),
            max_src_position: (&capabilities.maxSrcPosition).into(),
            min_src_extent: (&capabilities.minSrcExtent).into(),
            max_src_extent: (&capabilities.maxSrcExtent).into(),
            min_dst_position: (&capabilities.minDstPosition).into(),
            max_dst_position: (&capabilities.maxDstPosition).into(),
            min_dst_extent: (&capabilities.minDstExtent).into(),
            max_dst_extent: (&capabilities.maxDstExtent).into(),
        }
    }
}

/// See [`VkDisplayPlanePropertiesKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplayPlanePropertiesKHR)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DisplayPlanePropertiesKhr {
    pub current_display: Option<DisplayKhr>,
    pub current_stack_index: u32,
}

impl DisplayPlanePropertiesKhr {
    pub(crate) unsafe fn from_vks(properties: &vks::VkDisplayPlanePropertiesKHR, physical_device: &core::PhysicalDevice) -> Self {
        let current_display = if properties.currentDisplay != 0 {
            Some(DisplayKhr::new(properties.currentDisplay, physical_device.clone()))
        }
        else {
            None
        };

        DisplayPlanePropertiesKhr {
            current_display: current_display,
            current_stack_index: properties.currentStackIndex,
        }
    }
}

gen_chain_struct! {
    name: DisplaySurfaceCreateInfoChainKhr [DisplaySurfaceCreateInfoChainKhrWrapper],
    query: DisplaySurfaceCreateInfoChainQueryKhr [DisplaySurfaceCreateInfoChainQueryKhrWrapper],
    vks: VkDisplaySurfaceCreateInfoKHR,
    input: true,
    output: false,
}

/// See [`VkDisplaySurfaceCreateInfoKHR`](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkDisplaySurfaceCreateInfoKHR)
#[derive(Debug, Clone, PartialEq)]
pub struct DisplaySurfaceCreateInfoKhr {
    pub flags: DisplaySurfaceCreateFlagsKhr,
    pub display_mode: DisplayModeKhr,
    pub plane_index: u32,
    pub plane_stack_index: u32,
    pub transform: khr_surface::SurfaceTransformFlagBitsKhr,
    pub global_alpha: f32,
    pub alpha_mode: DisplayPlaneAlphaFlagBitsKhr,
    pub image_extent: core::Extent2D,
    pub chain: Option<DisplaySurfaceCreateInfoChainKhr>,
}

#[derive(Debug)]
pub(crate) struct VkDisplaySurfaceCreateInfoKHRWrapper {
    pub vks_struct: vks::VkDisplaySurfaceCreateInfoKHR,
    chain: Option<DisplaySurfaceCreateInfoChainKhrWrapper>,
}

impl VkDisplaySurfaceCreateInfoKHRWrapper {
    pub fn new(create_info: &DisplaySurfaceCreateInfoKhr, with_chain: bool) -> Self {
        let (pnext, chain) = DisplaySurfaceCreateInfoChainKhrWrapper::new_optional(&create_info.chain, with_chain);

        VkDisplaySurfaceCreateInfoKHRWrapper {
            vks_struct: vks::VkDisplaySurfaceCreateInfoKHR {
                sType: vks::VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR,
                pNext: pnext,
                flags: create_info.flags.bits(),
                displayMode: create_info.display_mode.handle,
                planeIndex: create_info.plane_index,
                planeStackIndex: create_info.plane_stack_index,
                transform: create_info.transform.bits(),
                globalAlpha: create_info.global_alpha,
                alphaMode: create_info.alpha_mode.bits(),
                imageExtent: (&create_info.image_extent).into(),
            },
            chain: chain,
        }
    }
}