Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRDisplay.cpp

Issue 2331553002: Update WebVR interface to match the 1.1 spec (Closed)
Patch Set: Addressed further feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/vr/VRDisplay.h" 5 #include "modules/vr/VRDisplay.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/Fullscreen.h" 8 #include "core/dom/Fullscreen.h"
9 #include "core/inspector/ConsoleMessage.h" 9 #include "core/inspector/ConsoleMessage.h"
10 #include "modules/vr/NavigatorVR.h" 10 #include "modules/vr/NavigatorVR.h"
11 #include "modules/vr/VRController.h" 11 #include "modules/vr/VRController.h"
12 #include "modules/vr/VRDisplayCapabilities.h" 12 #include "modules/vr/VRDisplayCapabilities.h"
13 #include "modules/vr/VREyeParameters.h" 13 #include "modules/vr/VREyeParameters.h"
14 #include "modules/vr/VRFrameData.h"
14 #include "modules/vr/VRLayer.h" 15 #include "modules/vr/VRLayer.h"
15 #include "modules/vr/VRPose.h" 16 #include "modules/vr/VRPose.h"
16 #include "modules/vr/VRStageParameters.h" 17 #include "modules/vr/VRStageParameters.h"
17 #include "modules/webgl/WebGLRenderingContextBase.h" 18 #include "modules/webgl/WebGLRenderingContextBase.h"
18 #include "platform/UserGestureIndicator.h" 19 #include "platform/UserGestureIndicator.h"
19 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
20 21
21 namespace blink { 22 namespace blink {
22 23
23 namespace { 24 namespace {
(...skipping 11 matching lines...) Expand all
35 36
36 VRDisplay::VRDisplay(NavigatorVR* navigatorVR) 37 VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
37 : m_navigatorVR(navigatorVR) 38 : m_navigatorVR(navigatorVR)
38 , m_displayId(0) 39 , m_displayId(0)
39 , m_isConnected(false) 40 , m_isConnected(false)
40 , m_isPresenting(false) 41 , m_isPresenting(false)
41 , m_canUpdateFramePose(true) 42 , m_canUpdateFramePose(true)
42 , m_capabilities(new VRDisplayCapabilities()) 43 , m_capabilities(new VRDisplayCapabilities())
43 , m_eyeParametersLeft(new VREyeParameters()) 44 , m_eyeParametersLeft(new VREyeParameters())
44 , m_eyeParametersRight(new VREyeParameters()) 45 , m_eyeParametersRight(new VREyeParameters())
46 , m_depthNear(0.01)
47 , m_depthFar(10000.0)
45 , m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck) 48 , m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck)
46 { 49 {
47 } 50 }
48 51
49 VRDisplay::~VRDisplay() 52 VRDisplay::~VRDisplay()
50 { 53 {
51 } 54 }
52 55
53 VRController* VRDisplay::controller() 56 VRController* VRDisplay::controller()
54 { 57 {
(...skipping 17 matching lines...) Expand all
72 75
73 if (!display->stageParameters.is_null()) { 76 if (!display->stageParameters.is_null()) {
74 if (!m_stageParameters) 77 if (!m_stageParameters)
75 m_stageParameters = new VRStageParameters(); 78 m_stageParameters = new VRStageParameters();
76 m_stageParameters->update(display->stageParameters); 79 m_stageParameters->update(display->stageParameters);
77 } else { 80 } else {
78 m_stageParameters = nullptr; 81 m_stageParameters = nullptr;
79 } 82 }
80 } 83 }
81 84
85 bool VRDisplay::getFrameData(VRFrameData* frameData)
86 {
87 updatePose();
88
89 if (!frameData)
90 return false;
91
92 if (m_depthNear == m_depthFar)
93 return false;
94
95 return frameData->update(m_framePose, m_eyeParametersLeft, m_eyeParametersRi ght, m_depthNear, m_depthFar);
96 }
97
82 VRPose* VRDisplay::getPose() 98 VRPose* VRDisplay::getPose()
83 { 99 {
84 if (m_canUpdateFramePose) { 100 updatePose();
85 m_framePose = getImmediatePose();
86 Platform::current()->currentThread()->addTaskObserver(this);
87 m_canUpdateFramePose = false;
88 }
89 101
90 return m_framePose; 102 if (!m_framePose)
103 return nullptr;
104
105 VRPose* pose = VRPose::create();
106 pose->setPose(m_framePose);
107 return pose;
91 } 108 }
92 109
93 VRPose* VRDisplay::getImmediatePose() 110 void VRDisplay::updatePose()
94 { 111 {
95 VRPose* pose = VRPose::create(); 112 if (m_canUpdateFramePose) {
96 pose->setPose(controller()->getPose(m_displayId)); 113 m_framePose = controller()->getPose(m_displayId);
97 return pose; 114 if (m_isPresenting)
115 m_canUpdateFramePose = false;
116 }
98 } 117 }
99 118
100 void VRDisplay::resetPose() 119 void VRDisplay::resetPose()
101 { 120 {
102 controller()->resetPose(m_displayId); 121 controller()->resetPose(m_displayId);
103 } 122 }
104 123
105 VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) 124 VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye)
106 { 125 {
107 switch (stringToVREye(whichEye)) { 126 switch (stringToVREye(whichEye)) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 { 280 {
262 HeapVector<VRLayer> layers; 281 HeapVector<VRLayer> layers;
263 282
264 if (m_isPresenting) { 283 if (m_isPresenting) {
265 layers.append(m_layer); 284 layers.append(m_layer);
266 } 285 }
267 286
268 return layers; 287 return layers;
269 } 288 }
270 289
271 void VRDisplay::submitFrame(VRPose* pose) 290 void VRDisplay::submitFrame()
272 { 291 {
273 controller()->submitFrame(m_displayId); 292 controller()->submitFrame(m_displayId);
274 } 293 m_canUpdateFramePose = true;
275
276 void VRDisplay::didProcessTask()
277 {
278 // Pose should be stable until control is returned to the user agent.
279 if (!m_canUpdateFramePose) {
280 Platform::current()->currentThread()->removeTaskObserver(this);
281 m_canUpdateFramePose = true;
282 }
283 } 294 }
284 295
285 void VRDisplay::onFullscreenCheck(TimerBase*) 296 void VRDisplay::onFullscreenCheck(TimerBase*)
286 { 297 {
287 // TODO: This is a temporary measure to track if fullscreen mode has been 298 // TODO: This is a temporary measure to track if fullscreen mode has been
288 // exited by the UA. If so we need to end VR presentation. Soon we won't 299 // exited by the UA. If so we need to end VR presentation. Soon we won't
289 // depend on the Fullscreen API to fake VR presentation, so this will 300 // depend on the Fullscreen API to fake VR presentation, so this will
290 // become unnessecary. Until that point, though, this seems preferable to 301 // become unnessecary. Until that point, though, this seems preferable to
291 // adding a bunch of notification plumbing to Fullscreen. 302 // adding a bunch of notification plumbing to Fullscreen.
292 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { 303 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) {
293 m_isPresenting = false; 304 m_isPresenting = false;
294 m_navigatorVR->fireVRDisplayPresentChange(this); 305 m_navigatorVR->fireVRDisplayPresentChange(this);
295 m_fullscreenCheckTimer.stop(); 306 m_fullscreenCheckTimer.stop();
296 controller()->exitPresent(m_displayId); 307 controller()->exitPresent(m_displayId);
297 } 308 }
298 } 309 }
299 310
300 DEFINE_TRACE(VRDisplay) 311 DEFINE_TRACE(VRDisplay)
301 { 312 {
302 visitor->trace(m_navigatorVR); 313 visitor->trace(m_navigatorVR);
303 visitor->trace(m_capabilities); 314 visitor->trace(m_capabilities);
304 visitor->trace(m_stageParameters); 315 visitor->trace(m_stageParameters);
305 visitor->trace(m_eyeParametersLeft); 316 visitor->trace(m_eyeParametersLeft);
306 visitor->trace(m_eyeParametersRight); 317 visitor->trace(m_eyeParametersRight);
307 visitor->trace(m_framePose);
308 visitor->trace(m_layer); 318 visitor->trace(m_layer);
309 } 319 }
310 320
311 } // namespace blink 321 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698