From 18bc500361aadb84255c5c22dd6737db755b156a Mon Sep 17 00:00:00 2001 From: Riccardo Zaglia Date: Sat, 28 Sep 2024 15:58:03 +0200 Subject: [PATCH] feat(client): :sparkles: Add platform vendor shortcuts --- alvr/client_core/src/platform/mod.rs | 25 +++++++++++++++++++++++++ alvr/client_openxr/src/interaction.rs | 19 +++++-------------- alvr/client_openxr/src/lib.rs | 8 ++------ alvr/client_openxr/src/stream.rs | 3 +-- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/alvr/client_core/src/platform/mod.rs b/alvr/client_core/src/platform/mod.rs index b6193f9322..8203ea8cf8 100644 --- a/alvr/client_core/src/platform/mod.rs +++ b/alvr/client_core/src/platform/mod.rs @@ -30,6 +30,31 @@ pub enum Platform { Unknown, } +impl Platform { + pub const fn is_quest(&self) -> bool { + matches!( + self, + Platform::Quest1 + | Platform::Quest2 + | Platform::Quest3 + | Platform::Quest3S + | Platform::QuestPro + | Platform::QuestUnknown + ) + } + + pub const fn is_pico(&self) -> bool { + matches!(self, Platform::PicoNeo3 | Platform::Pico4) + } + + pub const fn is_vive(&self) -> bool { + matches!( + self, + Platform::Focus3 | Platform::XRElite | Platform::ViveUnknown + ) + } +} + impl Display for Platform { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let name = match self { diff --git a/alvr/client_openxr/src/interaction.rs b/alvr/client_openxr/src/interaction.rs index a3a98ee009..b1effcc6b5 100644 --- a/alvr/client_openxr/src/interaction.rs +++ b/alvr/client_openxr/src/interaction.rs @@ -67,7 +67,7 @@ pub fn initialize_interaction( { alvr_client_core::try_get_permission("com.oculus.permission.EYE_TRACKING") } - if config.combined_eye_gaze && matches!(platform, Platform::Pico4 | Platform::PicoNeo3) { + if config.combined_eye_gaze && platform.is_pico() { alvr_client_core::try_get_permission("com.picovr.permission.EYE_TRACKING") } if config.face_tracking_fb && matches!(platform, Platform::QuestPro) { @@ -79,10 +79,8 @@ pub fn initialize_interaction( #[cfg(target_os = "android")] if let Some(config) = &body_tracking_sources { if (config.body_tracking_fb.enabled()) - && matches!( - platform, - Platform::Quest2 | Platform::Quest3 | Platform::Quest3S | Platform::QuestPro - ) + && platform.is_quest() + && platform != Platform::Quest1 { alvr_client_core::try_get_permission("com.oculus.permission.BODY_TRACKING") } @@ -100,17 +98,10 @@ pub fn initialize_interaction( } let controllers_profile_path = match platform { - Platform::Quest1 - | Platform::Quest2 - | Platform::Quest3 - | Platform::Quest3S - | Platform::QuestPro - | Platform::QuestUnknown => QUEST_CONTROLLER_PROFILE_PATH, // todo: create new controller profile for quest pro and 3 + p if p.is_quest() => QUEST_CONTROLLER_PROFILE_PATH, // todo: create new controller profile for quest pro and 3 Platform::PicoNeo3 => PICO_NEO3_CONTROLLER_PROFILE_PATH, Platform::Pico4 => PICO4_CONTROLLER_PROFILE_PATH, - Platform::Focus3 | Platform::XRElite | Platform::ViveUnknown => { - FOCUS3_CONTROLLER_PROFILE_PATH - } + p if p.is_vive() => FOCUS3_CONTROLLER_PROFILE_PATH, Platform::Yvr => YVR_CONTROLLER_PROFILE_PATH, _ => QUEST_CONTROLLER_PROFILE_PATH, }; diff --git a/alvr/client_openxr/src/lib.rs b/alvr/client_openxr/src/lib.rs index a88fedccea..a4530419bd 100644 --- a/alvr/client_openxr/src/lib.rs +++ b/alvr/client_openxr/src/lib.rs @@ -126,7 +126,7 @@ pub fn entry_point() { let loader_suffix = match platform { Platform::Quest1 => "_quest1", - Platform::PicoNeo3 | Platform::Pico4 => "_pico", + p if p.is_pico() => "_pico", Platform::Yvr => "_yvr", Platform::Lynx => "_lynx", _ => "", @@ -358,11 +358,7 @@ pub fn entry_point() { // combined_eye_gaze is a setting that needs to be enabled at session // creation. Since HTC headsets don't support session reinitialization, skip // all elements that need it, that is face and eye tracking. - if parsed_stream_config.as_ref() != Some(&new_config) - && !matches!( - platform, - Platform::Focus3 | Platform::XRElite | Platform::ViveUnknown - ) + if parsed_stream_config.as_ref() != Some(&new_config) && !platform.is_vive() { parsed_stream_config = Some(new_config); diff --git a/alvr/client_openxr/src/stream.rs b/alvr/client_openxr/src/stream.rs index 2bba10d8da..9f701e47bd 100644 --- a/alvr/client_openxr/src/stream.rs +++ b/alvr/client_openxr/src/stream.rs @@ -183,8 +183,7 @@ impl StreamContext { format, config.foveated_encoding_config.clone(), platform != Platform::Lynx - && !((platform == Platform::Pico4 || platform == Platform::PicoNeo3) - && config.encoder_config.enable_hdr), + && !((platform.is_pico()) && config.encoder_config.enable_hdr), !config.encoder_config.enable_hdr, config.encoder_config.encoding_gamma, );