use euclid::{Point2D, RigidTransform3D};
use profile_traits::generic_callback::GenericCallback as ProfileGenericCallback;
use crate::{
ContextId, EnvironmentBlendMode, Error, Event, Floor, Frame, HitTestId, HitTestSource,
InputSource, LayerId, LayerInit, Native, Quitter, Session, SessionBuilder, SessionInit,
SessionMode, Viewports,
};
pub trait DiscoveryAPI<GL>: 'static {
fn request_session(
&mut self,
mode: SessionMode,
init: &SessionInit,
xr: SessionBuilder<GL>,
) -> Result<Session, Error>;
fn supports_session(&self, mode: SessionMode) -> bool;
}
pub trait DeviceAPI: 'static {
fn create_layer(&mut self, context_id: ContextId, init: LayerInit) -> Result<LayerId, Error>;
fn destroy_layer(&mut self, context_id: ContextId, layer_id: LayerId);
fn floor_transform(&self) -> Option<RigidTransform3D<f32, Native, Floor>>;
fn viewports(&self) -> Viewports;
fn begin_animation_frame(&mut self, layers: &[(ContextId, LayerId)]) -> Option<Frame>;
fn end_animation_frame(&mut self, layers: &[(ContextId, LayerId)]);
fn initial_inputs(&self) -> Vec<InputSource>;
fn set_event_dest(&mut self, dest: ProfileGenericCallback<Event>);
fn quit(&mut self);
fn set_quitter(&mut self, quitter: Quitter);
fn update_clip_planes(&mut self, near: f32, far: f32);
fn environment_blend_mode(&self) -> EnvironmentBlendMode {
EnvironmentBlendMode::Opaque
}
fn granted_features(&self) -> &[String];
fn request_hit_test(&mut self, _source: HitTestSource) {
panic!("This device does not support requesting hit tests");
}
fn cancel_hit_test(&mut self, _id: HitTestId) {
panic!("This device does not support hit tests");
}
fn update_frame_rate(&mut self, rate: f32) -> f32 {
rate
}
fn supported_frame_rates(&self) -> Vec<f32> {
Vec::new()
}
fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
None
}
}
impl<GL: 'static> DiscoveryAPI<GL> for Box<dyn DiscoveryAPI<GL>> {
fn request_session(
&mut self,
mode: SessionMode,
init: &SessionInit,
xr: SessionBuilder<GL>,
) -> Result<Session, Error> {
(**self).request_session(mode, init, xr)
}
fn supports_session(&self, mode: SessionMode) -> bool {
(**self).supports_session(mode)
}
}