servo_webxr_api/
device.rs1use euclid::{Point2D, RigidTransform3D};
8use profile_traits::generic_callback::GenericCallback as ProfileGenericCallback;
9use servo_base::generic_channel::GenericCallback;
10
11use crate::{
12 ContextId, EnvironmentBlendMode, Error, Event, Floor, Frame, HitTestId, HitTestSource,
13 InputSource, LayerId, LayerInit, Native, Quitter, Session, SessionBuilder, SessionInit,
14 SessionMode, Viewports,
15};
16
17pub trait DiscoveryAPI<GL>: 'static {
19 fn request_session(
20 &mut self,
21 mode: SessionMode,
22 init: &SessionInit,
23 xr: SessionBuilder<GL>,
24 ) -> Result<Session, Error>;
25 fn supports_session(&self, mode: SessionMode) -> bool;
26 fn poll_device_changed(&mut self) -> bool {
27 false
28 }
29 fn set_waker(&mut self, _waker: GenericCallback<()>) {}
30}
31
32pub trait DeviceAPI: 'static {
34 fn create_layer(&mut self, context_id: ContextId, init: LayerInit) -> Result<LayerId, Error>;
36
37 fn destroy_layer(&mut self, context_id: ContextId, layer_id: LayerId);
39
40 fn floor_transform(&self) -> Option<RigidTransform3D<f32, Native, Floor>>;
42
43 fn viewports(&self) -> Viewports;
44
45 fn begin_animation_frame(&mut self, layers: &[(ContextId, LayerId)]) -> Option<Frame>;
47
48 fn end_animation_frame(&mut self, layers: &[(ContextId, LayerId)]);
50
51 fn initial_inputs(&self) -> Vec<InputSource>;
54
55 fn set_event_dest(&mut self, dest: ProfileGenericCallback<Event>);
57
58 fn quit(&mut self);
60
61 fn set_quitter(&mut self, quitter: Quitter);
62
63 fn update_clip_planes(&mut self, near: f32, far: f32);
64
65 fn environment_blend_mode(&self) -> EnvironmentBlendMode {
66 EnvironmentBlendMode::Opaque
68 }
69
70 fn granted_features(&self) -> &[String];
71
72 fn request_hit_test(&mut self, _source: HitTestSource) {
73 panic!("This device does not support requesting hit tests");
74 }
75
76 fn cancel_hit_test(&mut self, _id: HitTestId) {
77 panic!("This device does not support hit tests");
78 }
79
80 fn update_frame_rate(&mut self, rate: f32) -> f32 {
81 rate
82 }
83
84 fn supported_frame_rates(&self) -> Vec<f32> {
85 Vec::new()
86 }
87
88 fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
89 None
90 }
91}
92
93impl<GL: 'static> DiscoveryAPI<GL> for Box<dyn DiscoveryAPI<GL>> {
94 fn request_session(
95 &mut self,
96 mode: SessionMode,
97 init: &SessionInit,
98 xr: SessionBuilder<GL>,
99 ) -> Result<Session, Error> {
100 (**self).request_session(mode, init, xr)
101 }
102
103 fn supports_session(&self, mode: SessionMode) -> bool {
104 (**self).supports_session(mode)
105 }
106
107 fn poll_device_changed(&mut self) -> bool {
108 (**self).poll_device_changed()
109 }
110
111 fn set_waker(&mut self, waker: GenericCallback<()>) {
112 (**self).set_waker(waker);
113 }
114}