| 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 42356ff9d830023964f01dc76d8139b76bc1c3cf..6183d47c5da642556600912a24a967dc3049998a 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"
|
| @@ -205,6 +206,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)) {
|
| @@ -294,6 +299,8 @@ void VRDisplay::forceExitPresent() {
|
| }
|
|
|
| m_isPresenting = false;
|
| + m_renderingContext = nullptr;
|
| + m_contextGL = nullptr;
|
| }
|
|
|
| void VRDisplay::updateLayerBounds() {
|
| @@ -344,6 +351,39 @@ HeapVector<VRLayer> VRDisplay::getLayers() {
|
| }
|
|
|
| void VRDisplay::submitFrame() {
|
| + if (!m_isPresenting || !m_contextGL) {
|
| + // Something got confused, we can't submit frames if we're not presenting.
|
| + return;
|
| + }
|
| +
|
| + // 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 idx = m_framePose->poseIndex;
|
| + // Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
|
| + gl->ClearColor((idx & 255) / 255.0f, ((idx >> 8) & 255) / 255.0f,
|
| + ((idx >> 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->restoreScissorEnabled();
|
| + m_renderingContext->restoreScissorBox();
|
| + m_renderingContext->restoreColorMask();
|
| + m_renderingContext->restoreClearColor();
|
| +
|
| controller()->submitFrame(m_displayId, m_framePose.Clone());
|
| m_canUpdateFramePose = true;
|
| }
|
| @@ -369,6 +409,7 @@ DEFINE_TRACE(VRDisplay) {
|
| visitor->trace(m_eyeParametersLeft);
|
| visitor->trace(m_eyeParametersRight);
|
| visitor->trace(m_layer);
|
| + visitor->trace(m_renderingContext);
|
| }
|
|
|
| } // namespace blink
|
|
|