| Index: third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| diff --git a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| index 8cab7bf6b5992028d69c81bdc05eb5494ef2e37f..bf452578ca4625d6d0f3a8b421588ee7c00b974b 100644
|
| --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
|
| @@ -8,6 +8,7 @@
|
| #include "core/dom/Fullscreen.h"
|
| #include "core/frame/UseCounter.h"
|
| #include "core/inspector/ConsoleMessage.h"
|
| +#include "gpu/command_buffer/client/gles2_interface.h"
|
| #include "modules/vr/NavigatorVR.h"
|
| #include "modules/vr/VRController.h"
|
| #include "modules/vr/VRDisplayCapabilities.h"
|
| @@ -204,6 +205,10 @@ ScriptPromise VRDisplay::requestPresent(ScriptState* scriptState,
|
| return promise;
|
| }
|
|
|
| + // Save the WebGL script and underlying GL contexts for use by submitFrame().
|
| + m_renderingContext = toWebGLRenderingContextBase(renderingContext);
|
| + m_contextGL = m_renderingContext->contextGL();
|
| +
|
| if ((m_layer.leftBounds().size() != 0 && m_layer.leftBounds().size() != 4) ||
|
| (m_layer.rightBounds().size() != 0 &&
|
| m_layer.rightBounds().size() != 4)) {
|
| @@ -343,6 +348,35 @@ HeapVector<VRLayer> VRDisplay::getLayers() {
|
| }
|
|
|
| void VRDisplay::submitFrame() {
|
| + // Write the frame number for the pose used into a bottom left pixel block.
|
| + // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate
|
| + // the correct corresponding pose for submission.
|
| + auto gl = m_contextGL;
|
| +
|
| + // We must ensure that the WebGL app's GL state is preserved. We do this by
|
| + // calling low-level GL commands directly so that the rendering context's
|
| + // saved parameters don't get overwritten.
|
| +
|
| + gl->Enable(GL_SCISSOR_TEST);
|
| + // Use a few pixels to ensure we get a clean color. The resolution for the
|
| + // WebGL buffer may not match the final rendered destination size, and
|
| + // texture filtering could interfere for single pixels. This isn't visible
|
| + // since the final rendering hides the edges via a vignette effect.
|
| + gl->Scissor(0, 0, 4, 4);
|
| + gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
| + int frame = m_framePose->poseNum;
|
| + // Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
|
| + gl->ClearColor((frame & 255) / 255.0f, ((frame >> 8) & 255) / 255.0f,
|
| + ((frame >> 16) & 255) / 255.0f, 1.0f);
|
| + gl->Clear(GL_COLOR_BUFFER_BIT);
|
| +
|
| + // Set the GL state back to what was set by the WebVR application.
|
| + m_renderingContext->restoreStateFromContext(
|
| + WebGLRenderingContextBase::StateScissorEnabled |
|
| + WebGLRenderingContextBase::StateScissorBox |
|
| + WebGLRenderingContextBase::StateColorMask |
|
| + WebGLRenderingContextBase::StateClearColor);
|
| +
|
| controller()->submitFrame(m_displayId, m_framePose.Clone());
|
| m_canUpdateFramePose = true;
|
| }
|
| @@ -368,6 +402,7 @@ DEFINE_TRACE(VRDisplay) {
|
| visitor->trace(m_eyeParametersLeft);
|
| visitor->trace(m_eyeParametersRight);
|
| visitor->trace(m_layer);
|
| + visitor->trace(m_renderingContext);
|
| }
|
|
|
| } // namespace blink
|
|
|