Commit 9076d454 authored by Anna Offenwanger's avatar Anna Offenwanger Committed by Commit Bot

Added reset pose event from GVR input sources

Added a value to allow a resetpose event to be propogated from GVR out
to the javascript.

Bug: 843184
Change-Id: I5433be4f26af21fa09a35b7485d8c7911a5e89c2
Reviewed-on: https://chromium-review.googlesource.com/1063027Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Anna Offenwanger <offenwanger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560871}
parent bb680d5a
...@@ -2436,6 +2436,12 @@ void VrShellGl::SendVSync() { ...@@ -2436,6 +2436,12 @@ void VrShellGl::SendVSync() {
prediction_nanos); prediction_nanos);
TRACE_EVENT_END0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel"); TRACE_EVENT_END0("gpu", "VrShellGl::GetVRPosePtrWithNeckModel");
// Process all events. Check for ones we wish to react to.
gvr::Event last_event;
while (gvr_api_->PollEvent(&last_event)) {
pose->pose_reset |= last_event.type == GVR_EVENT_RECENTER;
}
if (report_webxr_input_) { if (report_webxr_input_) {
TRACE_EVENT0("gpu", "VrShellGl::XRInput"); TRACE_EVENT0("gpu", "VrShellGl::XRInput");
if (cardboard_) { if (cardboard_) {
......
...@@ -82,6 +82,11 @@ struct VRPose { ...@@ -82,6 +82,11 @@ struct VRPose {
// For WebXR sessions only, reports the state of all active input devices // For WebXR sessions only, reports the state of all active input devices
// synced with the head pose. // synced with the head pose.
array<XRInputSourceState>? input_state; array<XRInputSourceState>? input_state;
// Indicates that a reset pose event was triggered, either by device specific
// UI or by some other method, and handled on the browser side, and the
// renderer should now bubble up an event to the WebXRDevice API.
bool pose_reset;
}; };
struct VRDisplayCapabilities { struct VRDisplayCapabilities {
...@@ -258,6 +263,8 @@ interface VRDisplayHost { ...@@ -258,6 +263,8 @@ interface VRDisplayHost {
// Provides the necessary functionality for a non-presenting WebXR session to // Provides the necessary functionality for a non-presenting WebXR session to
// draw magic window content. // draw magic window content.
// This interface is hosted in the Browser process, but will move to a sandboxed
// utility process on Windows. The render process communicates with it.
// For AR displays (VRDisplayCapabilities.can_provide_pass_through_images // For AR displays (VRDisplayCapabilities.can_provide_pass_through_images
// is true), clients can use GetFrameData to get images. // is true), clients can use GetFrameData to get images.
// TODO(836478): rename VRMagicWindowProvider to NonExclusiveWindowProvider or // TODO(836478): rename VRMagicWindowProvider to NonExclusiveWindowProvider or
......
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../xr/resources/xr-device-mocking.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<script src="../xr/resources/test-constants.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let fakeDevices = fakeXRDevices();
let watcherDone = new Event("watcherdone");
xr_session_promise_test( (session, t) => {
// Session must have a baseLayer or frame requests will be ignored.
session.baseLayer = new XRWebGLLayer(session, gl);
let eventWatcher = new EventWatcher(t, session, ["resetpose", "watcherdone"]);
let eventPromise = eventWatcher.wait_for(["resetpose", "watcherdone"]);
// Need to have a valid pose or input event's don't process.
var pose = Object.assign({}, VALID_POSE);
pose.poseReset = true;
setPose(pose);
function onPoseReset(event) {
t.step( () => {
assert_equals(event.session, session);
session.dispatchEvent(watcherDone);
});
}
session.addEventListener("resetpose", onPoseReset, false);
// Trigger the reset pose.
session.requestAnimationFrame((time, xrFrame) => {});
return eventPromise;
}, fakeDevices["FakeGooglePixelPhone"], [
{ outputContext: getOutputContext() },
{ exclusive: true },
],
"XRSession resetpose from a device properly fires off the right events");
</script>
...@@ -430,6 +430,7 @@ class MockVRPresentationProvider { ...@@ -430,6 +430,7 @@ class MockVRPresentationProvider {
angularAcceleration: null, angularAcceleration: null,
linearAcceleration: null, linearAcceleration: null,
inputState: null, inputState: null,
poseReset: false,
poseIndex: 0 poseIndex: 0
}; };
} }
......
...@@ -430,6 +430,10 @@ void XRFrameProvider::ProcessScheduledFrame( ...@@ -430,6 +430,10 @@ void XRFrameProvider::ProcessScheduledFrame(
frame_pose_->input_state.value()); frame_pose_->input_state.value());
} }
if (frame_pose_ && frame_pose_->pose_reset) {
exclusive_session_->OnPoseReset();
}
// If there's an exclusive session active only process its frame. // If there's an exclusive session active only process its frame.
std::unique_ptr<TransformationMatrix> pose_matrix = std::unique_ptr<TransformationMatrix> pose_matrix =
getPoseMatrix(frame_pose_); getPoseMatrix(frame_pose_);
...@@ -469,6 +473,10 @@ void XRFrameProvider::ProcessScheduledFrame( ...@@ -469,6 +473,10 @@ void XRFrameProvider::ProcessScheduledFrame(
session->SetNonExclusiveProjectionMatrix(frame_data->projection_matrix); session->SetNonExclusiveProjectionMatrix(frame_data->projection_matrix);
} }
if (frame_pose_ && frame_pose_->pose_reset) {
session->OnPoseReset();
}
std::unique_ptr<TransformationMatrix> pose_matrix = std::unique_ptr<TransformationMatrix> pose_matrix =
getPoseMatrix(frame_pose_); getPoseMatrix(frame_pose_);
session->OnFrame(std::move(pose_matrix), base::nullopt); session->OnFrame(std::move(pose_matrix), base::nullopt);
......
...@@ -531,6 +531,10 @@ void XRSession::OnSelect(XRInputSource* input_source) { ...@@ -531,6 +531,10 @@ void XRSession::OnSelect(XRInputSource* input_source) {
} }
} }
void XRSession::OnPoseReset() {
DispatchEvent(XRSessionEvent::Create(EventTypeNames::resetpose, this));
}
void XRSession::UpdateInputSourceState( void XRSession::UpdateInputSourceState(
XRInputSource* input_source, XRInputSource* input_source,
const device::mojom::blink::XRInputSourceStatePtr& state) { const device::mojom::blink::XRInputSourceStatePtr& state) {
......
...@@ -117,6 +117,8 @@ class XRSession final : public EventTargetWithInlineData { ...@@ -117,6 +117,8 @@ class XRSession final : public EventTargetWithInlineData {
void OnSelectEnd(XRInputSource*); void OnSelectEnd(XRInputSource*);
void OnSelect(XRInputSource*); void OnSelect(XRInputSource*);
void OnPoseReset();
void SetNonExclusiveProjectionMatrix(const WTF::Vector<float>&); void SetNonExclusiveProjectionMatrix(const WTF::Vector<float>&);
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
......
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