asdf_overlay_event/lib.rs
1/// Describe a event.
2#[derive(Debug, Clone)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum Event {
5 /// Events related to a specific surface.
6 Surface {
7 /// Unique identifier for the surface.
8 id: u64,
9 event: SurfaceEvent,
10 },
11}
12
13/// Describes a surface event.
14#[derive(Debug, Clone)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub enum SurfaceEvent {
17 Added {
18 /// Width of the surface
19 width: u32,
20
21 /// Height of the surface
22 height: u32,
23
24 /// Surface information
25 info: SurfaceInfo,
26 },
27 Resized {
28 // New width of the surface
29 width: u32,
30
31 // New height of the surface
32 height: u32,
33 },
34 Destroyed,
35}
36
37/// Hint for a surface.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40pub struct SurfaceInfo {
41 /// Surface type and type specific informations.
42 pub api: SurfaceType,
43
44 /// The LUID of the GPU adapter which the window used to present to surface.
45 ///
46 /// Client must choose correct GPU adapter using this luid,
47 /// otherwise overlay rendering may fail.
48 pub gpu_id: GpuLuid,
49}
50
51/// Locally unique identifier for a GPU adapter.
52///
53/// This identifier is not persistent across reboots.
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56pub struct GpuLuid {
57 /// The low part of the LUID.
58 pub low: u32,
59 /// The high part of the LUID.
60 pub high: i32,
61}
62
63/// Describes the render api used by a surface.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66pub enum SurfaceType {
67 /// Surface is OpenGL default framebuffer.
68 Opengl {
69 /// Window id of the OpenGL surface
70 window_id: u32,
71 },
72
73 /// Surface is Direct3D9 swapchain.
74 Direct3D9 {
75 /// Window id of the Direct3D9 surface
76 window_id: u32,
77 },
78
79 /// Surface is Direct3D11 swapchain.
80 Direct3D11 {
81 /// Window id of the Direct3D11 surface
82 ///
83 /// If the surface is directcomposition swapchain, the window id will be None.
84 window_id: Option<u32>,
85 },
86
87 /// Surface is Direct3D12 swapchain.
88 Direct3D12 {
89 /// Window id of the Direct3D12 surface
90 ///
91 /// If the surface is directcomposition swapchain, the window id will be None.
92 window_id: Option<u32>,
93 },
94
95 /// Surface is Vulkan win32 surface.
96 Vulkan {
97 /// Window id of the Vulkan surface.
98 window_id: u32,
99 },
100}
101
102impl SurfaceType {
103 /// Return the associated window ID, if any.
104 pub fn window_id(self) -> Option<u32> {
105 match self {
106 SurfaceType::Opengl { window_id } => Some(window_id),
107 SurfaceType::Direct3D9 { window_id } => Some(window_id),
108 SurfaceType::Direct3D11 { window_id } => window_id,
109 SurfaceType::Direct3D12 { window_id } => window_id,
110 SurfaceType::Vulkan { window_id } => Some(window_id),
111 }
112 }
113}