libobs_wrapper\display/
creation_data.rs1use libobs::gs_init_data;
2
3use crate::{display::ObsWindowHandle, enums::OsEnumType};
4
5use super::{GsColorFormat, GsZstencilFormat};
6
7pub type RawDisplayHandle = *mut ::std::os::raw::c_void;
8
9#[derive(Clone)]
10pub struct ObsDisplayCreationData {
11 pub(crate) window_handle: ObsWindowHandle,
12 pub(super) create_child: bool,
13 pub(super) x: i32,
14 pub(super) y: i32,
15 pub(super) width: u32,
16 pub(super) height: u32,
17 pub(super) format: GsColorFormat,
18 pub(super) zsformat: GsZstencilFormat,
19 pub(super) adapter: u32,
20 pub(super) backbuffers: u32,
21 pub(super) background_color: u32,
22}
23
24pub struct CloneableGsInitData(pub gs_init_data);
25
26impl Clone for CloneableGsInitData {
27 fn clone(&self) -> Self {
28 Self(gs_init_data {
29 cx: self.0.cx,
30 cy: self.0.cy,
31 format: self.0.format,
32 zsformat: self.0.zsformat,
33 window: self.0.window,
34 adapter: self.0.adapter,
35 num_backbuffers: self.0.num_backbuffers,
36 })
37 }
38}
39
40impl ObsDisplayCreationData {
41 pub fn new(window_handle: ObsWindowHandle, x: i32, y: i32, width: u32, height: u32) -> Self {
42 Self {
43 window_handle,
44 create_child: true,
46 format: GsColorFormat::BGRA,
47 zsformat: GsZstencilFormat::ZSNone,
48 x,
49 y,
50 width,
51 height,
52 adapter: 0,
53 backbuffers: 0,
54 background_color: 0,
55 }
56 }
57
58 pub fn set_format(mut self, format: GsColorFormat) -> Self {
59 self.format = format;
60 self
61 }
62
63 pub fn set_zsformat(mut self, zsformat: GsZstencilFormat) -> Self {
64 self.zsformat = zsformat;
65 self
66 }
67
68 pub fn set_adapter(mut self, adapter: u32) -> Self {
69 self.adapter = adapter;
70 self
71 }
72
73 pub fn set_backbuffers(mut self, backbuffers: u32) -> Self {
74 self.backbuffers = backbuffers;
75 self
76 }
77
78 pub fn set_background_color(mut self, background_color: u32) -> Self {
79 self.background_color = background_color;
80 self
81 }
82
83 pub fn set_create_child(mut self, should_create: bool) -> Self {
88 self.create_child = should_create;
89 self
90 }
91
92 pub(super) fn build(self, window_override: Option<ObsWindowHandle>) -> CloneableGsInitData {
93 CloneableGsInitData(gs_init_data {
94 cx: self.width,
95 cy: self.height,
96 format: self.format as OsEnumType,
97 zsformat: self.zsformat as OsEnumType,
98
99 window: window_override
100 .map(|s| s.window.0)
101 .unwrap_or_else(|| self.window_handle.window.0),
102 adapter: self.adapter,
103 num_backbuffers: self.backbuffers,
104 })
105 }
106}