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

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

Issue 2384593002: Encode frame number in pixel data for pose sync (Closed)
Patch Set: dcheng #22, mthiesse #31: rebase, simpler ring buffer initialization, fix type Created 4 years, 2 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/frame/UseCounter.h" 9 #include "core/frame/UseCounter.h"
10 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
11 #include "gpu/command_buffer/client/gles2_interface.h"
11 #include "modules/vr/NavigatorVR.h" 12 #include "modules/vr/NavigatorVR.h"
12 #include "modules/vr/VRController.h" 13 #include "modules/vr/VRController.h"
13 #include "modules/vr/VRDisplayCapabilities.h" 14 #include "modules/vr/VRDisplayCapabilities.h"
14 #include "modules/vr/VREyeParameters.h" 15 #include "modules/vr/VREyeParameters.h"
15 #include "modules/vr/VRFrameData.h" 16 #include "modules/vr/VRFrameData.h"
16 #include "modules/vr/VRLayer.h" 17 #include "modules/vr/VRLayer.h"
17 #include "modules/vr/VRPose.h" 18 #include "modules/vr/VRPose.h"
18 #include "modules/vr/VRStageParameters.h" 19 #include "modules/vr/VRStageParameters.h"
19 #include "modules/webgl/WebGLRenderingContextBase.h" 20 #include "modules/webgl/WebGLRenderingContextBase.h"
20 #include "platform/UserGestureIndicator.h" 21 #include "platform/UserGestureIndicator.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 m_layer.source()->renderingContext(); 199 m_layer.source()->renderingContext();
199 200
200 if (!renderingContext || !renderingContext->is3d()) { 201 if (!renderingContext || !renderingContext->is3d()) {
201 forceExitPresent(); 202 forceExitPresent();
202 DOMException* exception = DOMException::create( 203 DOMException* exception = DOMException::create(
203 InvalidStateError, "Layer source must have a WebGLRenderingContext"); 204 InvalidStateError, "Layer source must have a WebGLRenderingContext");
204 resolver->reject(exception); 205 resolver->reject(exception);
205 return promise; 206 return promise;
206 } 207 }
207 208
209 // Save the WebGL script and underlying GL contexts for use by submitFrame().
210 m_renderingContext = toWebGLRenderingContextBase(renderingContext);
211 m_contextGL = m_renderingContext->contextGL();
212
bajones 2016/10/05 20:49:05 Let's null these out on ExitPresent.
klausw 2016/10/05 21:00:24 Done, specifically in forceExitPresent (which gets
208 if ((m_layer.leftBounds().size() != 0 && m_layer.leftBounds().size() != 4) || 213 if ((m_layer.leftBounds().size() != 0 && m_layer.leftBounds().size() != 4) ||
209 (m_layer.rightBounds().size() != 0 && 214 (m_layer.rightBounds().size() != 0 &&
210 m_layer.rightBounds().size() != 4)) { 215 m_layer.rightBounds().size() != 4)) {
211 forceExitPresent(); 216 forceExitPresent();
212 DOMException* exception = DOMException::create( 217 DOMException* exception = DOMException::create(
213 InvalidStateError, 218 InvalidStateError,
214 "Layer bounds must either be an empty array or have 4 values"); 219 "Layer bounds must either be an empty array or have 4 values");
215 resolver->reject(exception); 220 resolver->reject(exception);
216 return promise; 221 return promise;
217 } 222 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 HeapVector<VRLayer> layers; 342 HeapVector<VRLayer> layers;
338 343
339 if (m_isPresenting) { 344 if (m_isPresenting) {
340 layers.append(m_layer); 345 layers.append(m_layer);
341 } 346 }
342 347
343 return layers; 348 return layers;
344 } 349 }
345 350
346 void VRDisplay::submitFrame() { 351 void VRDisplay::submitFrame() {
352 // Write the frame number for the pose used into a bottom left pixel block.
bajones 2016/10/05 20:49:05 Check that we're presenting and early terminate if
klausw 2016/10/05 21:00:24 Done. The original code unconditionally called con
353 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate
354 // the correct corresponding pose for submission.
355 auto gl = m_contextGL;
356
357 // We must ensure that the WebGL app's GL state is preserved. We do this by
358 // calling low-level GL commands directly so that the rendering context's
359 // saved parameters don't get overwritten.
360
361 gl->Enable(GL_SCISSOR_TEST);
362 // Use a few pixels to ensure we get a clean color. The resolution for the
363 // WebGL buffer may not match the final rendered destination size, and
364 // texture filtering could interfere for single pixels. This isn't visible
365 // since the final rendering hides the edges via a vignette effect.
366 gl->Scissor(0, 0, 4, 4);
367 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
368 int idx = m_framePose->poseIndex;
369 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
370 gl->ClearColor((idx & 255) / 255.0f, ((idx >> 8) & 255) / 255.0f,
371 ((idx >> 16) & 255) / 255.0f, 1.0f);
372 gl->Clear(GL_COLOR_BUFFER_BIT);
373
374 // Set the GL state back to what was set by the WebVR application.
375 m_renderingContext->restoreScissorEnabled();
376 m_renderingContext->restoreScissorBox();
377 m_renderingContext->restoreColorMask();
378 m_renderingContext->restoreClearColor();
379
347 controller()->submitFrame(m_displayId, m_framePose.Clone()); 380 controller()->submitFrame(m_displayId, m_framePose.Clone());
348 m_canUpdateFramePose = true; 381 m_canUpdateFramePose = true;
349 } 382 }
350 383
351 void VRDisplay::onFullscreenCheck(TimerBase*) { 384 void VRDisplay::onFullscreenCheck(TimerBase*) {
352 // 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
353 // 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
354 // 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
355 // become unnessecary. Until that point, though, this seems preferable to 388 // become unnessecary. Until that point, though, this seems preferable to
356 // adding a bunch of notification plumbing to Fullscreen. 389 // adding a bunch of notification plumbing to Fullscreen.
357 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { 390 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) {
358 m_isPresenting = false; 391 m_isPresenting = false;
359 m_navigatorVR->fireVRDisplayPresentChange(this); 392 m_navigatorVR->fireVRDisplayPresentChange(this);
360 m_fullscreenCheckTimer.stop(); 393 m_fullscreenCheckTimer.stop();
361 controller()->exitPresent(m_displayId); 394 controller()->exitPresent(m_displayId);
362 } 395 }
363 } 396 }
364 397
365 DEFINE_TRACE(VRDisplay) { 398 DEFINE_TRACE(VRDisplay) {
366 visitor->trace(m_navigatorVR); 399 visitor->trace(m_navigatorVR);
367 visitor->trace(m_capabilities); 400 visitor->trace(m_capabilities);
368 visitor->trace(m_stageParameters); 401 visitor->trace(m_stageParameters);
369 visitor->trace(m_eyeParametersLeft); 402 visitor->trace(m_eyeParametersLeft);
370 visitor->trace(m_eyeParametersRight); 403 visitor->trace(m_eyeParametersRight);
371 visitor->trace(m_layer); 404 visitor->trace(m_layer);
405 visitor->trace(m_renderingContext);
372 } 406 }
373 407
374 } // namespace blink 408 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698