OLD | NEW |
---|---|
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/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
10 #include "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 return nullptr; | 114 return nullptr; |
115 | 115 |
116 VRPose* pose = VRPose::create(); | 116 VRPose* pose = VRPose::create(); |
117 pose->setPose(m_framePose); | 117 pose->setPose(m_framePose); |
118 return pose; | 118 return pose; |
119 } | 119 } |
120 | 120 |
121 void VRDisplay::updatePose() | 121 void VRDisplay::updatePose() |
122 { | 122 { |
123 if (m_canUpdateFramePose) { | 123 if (m_canUpdateFramePose) { |
124 // Increment pose counter. This must stay in sync with the | |
125 // frameNumStarted_ counter in device/vr/android/gvr/gvr_device.cc. | |
126 ++m_poseNum; | |
bajones
2016/10/02 20:55:23
This feels very fragile. Let's add a poseId to the
klausw
2016/10/02 21:25:50
I agree, that this would be much cleaner. I'll loo
klausw
2016/10/04 00:40:41
Done. I saw it has a timestamp already internally,
| |
127 // LOG << "klausw:VRDisplay::updatePose " << m_poseNum; | |
124 m_framePose = controller()->getPose(m_displayId); | 128 m_framePose = controller()->getPose(m_displayId); |
125 if (m_isPresenting) | 129 if (m_isPresenting) |
126 m_canUpdateFramePose = false; | 130 m_canUpdateFramePose = false; |
127 } | 131 } |
128 } | 132 } |
129 | 133 |
130 void VRDisplay::resetPose() | 134 void VRDisplay::resetPose() |
131 { | 135 { |
132 controller()->resetPose(m_displayId); | 136 controller()->resetPose(m_displayId); |
133 } | 137 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 343 |
340 if (m_isPresenting) { | 344 if (m_isPresenting) { |
341 layers.append(m_layer); | 345 layers.append(m_layer); |
342 } | 346 } |
343 | 347 |
344 return layers; | 348 return layers; |
345 } | 349 } |
346 | 350 |
347 void VRDisplay::submitFrame() | 351 void VRDisplay::submitFrame() |
348 { | 352 { |
353 // Write the frame number for the pose used into a bottom left pixel block. | |
354 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate | |
355 // the correct corresponding pose for submission. | |
356 auto ctx = toWebGLRenderingContextBase(m_layer.source()->renderingContext()) ; | |
bajones
2016/10/02 20:55:23
Probably just want to cache this on calls to reque
klausw
2016/10/02 21:25:50
Sounds good.
klausw
2016/10/04 00:40:41
Done, saving the underlying GL context since that'
| |
357 int frame = m_poseNum; | |
358 ctx->scissor(0, 0, 4, 4); | |
bajones
2016/10/02 20:55:23
why 4x4? we're only reading one pixel
klausw
2016/10/02 21:25:50
I need to investigate more. I had tried 2x2 at som
klausw
2016/10/04 00:40:41
I tested, smallest that worked was (0, 0, 1, 3). I
| |
359 ctx->colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | |
360 ctx->clearColor( | |
361 (frame & 255) / 255.0f, | |
362 ((frame >> 8) & 255) / 255.0f, | |
363 ((frame >> 16) & 255) / 255.0f, | |
364 1.0f); | |
365 ctx->enable(GL_SCISSOR_TEST); | |
366 ctx->clear(GL_COLOR_BUFFER_BIT); | |
367 | |
368 // TODO(klausw): restore the previous parameters here. | |
369 // WebGLRenderingContextBase's getParameter is based on ScriptState and | |
370 // ScriptValue, I don't know how those work. For now, just restore some | |
371 // presumably-sane values. | |
372 // | |
373 // Alternatively, use a GL context from ctx->drawingBuffer()->contextGL(), | |
374 // but drawingBuffer() is a protected method. | |
375 ctx->disable(GL_SCISSOR_TEST); | |
bajones
2016/10/02 20:55:23
This is definitely not going to fly, as it will br
klausw
2016/10/02 21:25:50
I know it's not acceptable, hence the TODO. I just
klausw
2016/10/03 16:50:17
Good news, WebGLRenderingContextBase has a public
klausw
2016/10/04 00:40:41
This seems to work now, though there's some slight
| |
376 ctx->clearColor(0, 0, 0, 1.0f); | |
377 // LOG << "klausw:VRDisplay::submitFrame " << frameNum; | |
378 | |
349 controller()->submitFrame(m_displayId, m_framePose.Clone()); | 379 controller()->submitFrame(m_displayId, m_framePose.Clone()); |
350 m_canUpdateFramePose = true; | 380 m_canUpdateFramePose = true; |
351 } | 381 } |
352 | 382 |
353 void VRDisplay::onFullscreenCheck(TimerBase*) | 383 void VRDisplay::onFullscreenCheck(TimerBase*) |
354 { | 384 { |
355 // TODO: This is a temporary measure to track if fullscreen mode has been | 385 // TODO: This is a temporary measure to track if fullscreen mode has been |
356 // exited by the UA. If so we need to end VR presentation. Soon we won't | 386 // exited by the UA. If so we need to end VR presentation. Soon we won't |
357 // depend on the Fullscreen API to fake VR presentation, so this will | 387 // depend on the Fullscreen API to fake VR presentation, so this will |
358 // become unnessecary. Until that point, though, this seems preferable to | 388 // become unnessecary. Until that point, though, this seems preferable to |
(...skipping 10 matching lines...) Expand all Loading... | |
369 { | 399 { |
370 visitor->trace(m_navigatorVR); | 400 visitor->trace(m_navigatorVR); |
371 visitor->trace(m_capabilities); | 401 visitor->trace(m_capabilities); |
372 visitor->trace(m_stageParameters); | 402 visitor->trace(m_stageParameters); |
373 visitor->trace(m_eyeParametersLeft); | 403 visitor->trace(m_eyeParametersLeft); |
374 visitor->trace(m_eyeParametersRight); | 404 visitor->trace(m_eyeParametersRight); |
375 visitor->trace(m_layer); | 405 visitor->trace(m_layer); |
376 } | 406 } |
377 | 407 |
378 } // namespace blink | 408 } // namespace blink |
OLD | NEW |