Commit 05bd7baa authored by Brandon Jones's avatar Brandon Jones Committed by Commit Bot

Implemented XRInteractionMode

Recently added to the AR module, described here:
https://immersive-web.github.io/webxr-ar-module/#xrinteractionmode-enum

AR module intent to ship here:
https://groups.google.com/a/chromium.org/g/blink-dev/c/BXxS2U5EaN0

Bug: 1066237
Change-Id: Iefd898c7bd65593812c3063874687fc3eff4efef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2140779Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758959}
parent f3fde739
......@@ -306,6 +306,7 @@ XRSession::XRSession(
client_receiver,
device::mojom::blink::XRSessionMode mode,
EnvironmentBlendMode environment_blend_mode,
InteractionMode interaction_mode,
bool uses_input_eventing,
bool sensorless_session,
XRSessionFeatureSet enabled_features)
......@@ -341,6 +342,15 @@ XRSession::XRSession(
NOTREACHED() << "Unknown environment blend mode: "
<< environment_blend_mode;
}
switch (interaction_mode) {
case kInteractionModeScreen:
interaction_mode_string_ = "screen-space";
break;
case kInteractionModeWorld:
interaction_mode_string_ = "world-space";
break;
}
}
void XRSession::SetDOMOverlayElement(Element* element) {
......
......@@ -80,6 +80,8 @@ class XRSession final
kBlendModeAlphaBlend
};
enum InteractionMode { kInteractionModeScreen = 0, kInteractionModeWorld };
struct MetricsReporter {
explicit MetricsReporter(
mojo::Remote<device::mojom::blink::XRSessionMetricsRecorder> recorder);
......@@ -101,6 +103,7 @@ class XRSession final
client_receiver,
device::mojom::blink::XRSessionMode mode,
EnvironmentBlendMode environment_blend_mode,
InteractionMode interaction_mode,
bool uses_input_eventing,
bool sensorless_session,
XRSessionFeatureSet enabled_features);
......@@ -108,6 +111,7 @@ class XRSession final
XRSystem* xr() const { return xr_; }
const String& environmentBlendMode() const { return blend_mode_string_; }
const String& interactionMode() const { return interaction_mode_string_; }
XRDOMOverlayState* domOverlayState() const { return dom_overlay_state_; }
const String visibilityState() const;
XRRenderState* renderState() const { return render_state_; }
......@@ -371,6 +375,7 @@ class XRSession final
const device::mojom::blink::XRSessionMode mode_;
const bool environment_integration_;
String blend_mode_string_;
String interaction_mode_string_;
XRVisibilityState device_visibility_state_ = XRVisibilityState::VISIBLE;
XRVisibilityState visibility_state_ = XRVisibilityState::VISIBLE;
String visibility_state_string_;
......
......@@ -22,6 +22,11 @@ enum XRVisibilityState {
"hidden",
};
enum XRInteractionMode {
"screen-space",
"world-space"
};
[
ActiveScriptWrappable,
SecureContext,
......@@ -29,6 +34,7 @@ enum XRVisibilityState {
RuntimeEnabled=WebXR
] interface XRSession : EventTarget {
[RuntimeEnabled=WebXRARModule] readonly attribute XREnvironmentBlendMode environmentBlendMode;
[RuntimeEnabled=WebXRARModule] readonly attribute XRInteractionMode interactionMode;
readonly attribute XRVisibilityState visibilityState;
[SameObject] readonly attribute XRRenderState renderState;
[MeasureAs=XRSessionGetInputSources, SameObject] readonly attribute XRInputSourceArray inputSources;
......
......@@ -1250,15 +1250,25 @@ void XRSystem::OnRequestSessionReturned(
if (environment_integration)
blend_mode = XRSession::kBlendModeAlphaBlend;
// TODO(https://crbug.com/1069350): The runtime should be the one to
// communicate the interaction mode, but for the moment we're going to use
// session mode and assume all AR is phone AR.
XRSession::InteractionMode interaction_mode =
XRSession::kInteractionModeWorld;
if (query->mode() == device::mojom::blink::XRSessionMode::kInline ||
query->mode() == device::mojom::blink::XRSessionMode::kImmersiveAr)
interaction_mode = XRSession::kInteractionModeScreen;
XRSessionFeatureSet enabled_features;
for (const auto& feature : session_ptr->enabled_features) {
enabled_features.insert(feature);
}
XRSession* session = CreateSession(
query->mode(), blend_mode, std::move(session_ptr->client_receiver),
std::move(session_ptr->display_info), session_ptr->uses_input_eventing,
enabled_features);
XRSession* session =
CreateSession(query->mode(), blend_mode, interaction_mode,
std::move(session_ptr->client_receiver),
std::move(session_ptr->display_info),
session_ptr->uses_input_eventing, enabled_features);
frameProvider()->OnSessionStarted(session, std::move(session_ptr));
......@@ -1354,6 +1364,7 @@ void XRSystem::ContextDestroyed() {
XRSession* XRSystem::CreateSession(
device::mojom::blink::XRSessionMode mode,
XRSession::EnvironmentBlendMode blend_mode,
XRSession::InteractionMode interaction_mode,
mojo::PendingReceiver<device::mojom::blink::XRSessionClient>
client_receiver,
device::mojom::blink::VRDisplayInfoPtr display_info,
......@@ -1361,8 +1372,8 @@ XRSession* XRSystem::CreateSession(
XRSessionFeatureSet enabled_features,
bool sensorless_session) {
XRSession* session = MakeGarbageCollected<XRSession>(
this, std::move(client_receiver), mode, blend_mode, uses_input_eventing,
sensorless_session, std::move(enabled_features));
this, std::move(client_receiver), mode, blend_mode, interaction_mode,
uses_input_eventing, sensorless_session, std::move(enabled_features));
if (display_info)
session->SetXRDisplayInfo(std::move(display_info));
sessions_.insert(session);
......@@ -1372,10 +1383,12 @@ XRSession* XRSystem::CreateSession(
XRSession* XRSystem::CreateSensorlessInlineSession() {
// TODO(https://crbug.com/944936): The blend mode could be "additive".
XRSession::EnvironmentBlendMode blend_mode = XRSession::kBlendModeOpaque;
return CreateSession(device::mojom::blink::XRSessionMode::kInline, blend_mode,
mojo::NullReceiver() /* client receiver */,
nullptr /* display_info */,
false /* uses_input_eventing */,
XRSession::InteractionMode interaction_mode =
XRSession::kInteractionModeScreen;
return CreateSession(
device::mojom::blink::XRSessionMode::kInline, blend_mode,
interaction_mode, mojo::NullReceiver() /* client receiver */,
nullptr /* display_info */, false /* uses_input_eventing */,
{device::mojom::XRSessionFeature::REF_SPACE_VIEWER},
true /* sensorless_session */);
}
......
......@@ -379,6 +379,7 @@ class XRSystem final : public EventTargetWithInlineData,
XRSession* CreateSession(
device::mojom::blink::XRSessionMode mode,
XRSession::EnvironmentBlendMode blend_mode,
XRSession::InteractionMode interaction_mode,
mojo::PendingReceiver<device::mojom::blink::XRSessionClient>
client_receiver,
device::mojom::blink::VRDisplayInfoPtr display_info,
......
This is a testharness.js-based test.
PASS idl_test setup
PASS idl_test validation
PASS Partial interface XRSession: original interface defined
PASS Partial interface XRSession: member names are unique
PASS Partial interface XRSession[2]: original interface defined
PASS Partial interface XRSession[2]: member names are unique
PASS XRSession interface: attribute environmentBlendMode
FAIL XRSession interface: attribute interactionMode assert_true: The prototype object must have a property "interactionMode" expected true got false
PASS XRSession interface: xrSession must inherit property "environmentBlendMode" with the proper type
FAIL XRSession interface: xrSession must inherit property "interactionMode" with the proper type assert_inherits: property "interactionMode" not found in prototype chain
Harness: the test ran to completion.
......@@ -9117,6 +9117,7 @@ interface XRSession : EventTarget
getter domOverlayState
getter environmentBlendMode
getter inputSources
getter interactionMode
getter onend
getter oninputsourceschange
getter onselect
......
......@@ -11410,6 +11410,7 @@ interface XRSession : EventTarget
getter domOverlayState
getter environmentBlendMode
getter inputSources
getter interactionMode
getter onend
getter oninputsourceschange
getter onselect
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment