• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 The vulkano developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9 
10 use crate::swapchain::Swapchain;
11 
12 /// Represents a region on an image.
13 ///
14 /// A region consists of an arbitrary amount of rectangles.
15 #[derive(Debug, Clone)]
16 pub struct PresentRegion {
17     pub rectangles: Vec<RectangleLayer>,
18 }
19 
20 impl PresentRegion {
21     /// Returns true if this present region is compatible with swapchain.
is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool22     pub fn is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool {
23         self.rectangles
24             .iter()
25             .all(|rect| rect.is_compatible_with(swapchain))
26     }
27 }
28 
29 /// Represents a rectangular region on an image layer.
30 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
31 pub struct RectangleLayer {
32     /// Coordinates in pixels of the top-left hand corner of the rectangle.
33     pub offset: [i32; 2],
34 
35     /// Dimensions in pixels of the rectangle.
36     pub extent: [u32; 2],
37 
38     /// The layer of the image. For images with only one layer, the value of layer must be 0.
39     pub layer: u32,
40 }
41 
42 impl RectangleLayer {
43     /// Returns true if this rectangle layer is compatible with swapchain.
is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool44     pub fn is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool {
45         // FIXME negative offset is not disallowed by spec, but semantically should not be possible
46         debug_assert!(self.offset[0] >= 0);
47         debug_assert!(self.offset[1] >= 0);
48         self.offset[0] as u32 + self.extent[0] <= swapchain.dimensions()[0]
49             && self.offset[1] as u32 + self.extent[1] <= swapchain.dimensions()[1]
50             && self.layer < swapchain.layers()
51     }
52 }
53 
54 impl From<&RectangleLayer> for ash::vk::RectLayerKHR {
55     #[inline]
from(val: &RectangleLayer) -> Self56     fn from(val: &RectangleLayer) -> Self {
57         ash::vk::RectLayerKHR {
58             offset: ash::vk::Offset2D {
59                 x: val.offset[0],
60                 y: val.offset[1],
61             },
62             extent: ash::vk::Extent2D {
63                 width: val.extent[0],
64                 height: val.extent[1],
65             },
66             layer: val.layer,
67         }
68     }
69 }
70