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..b0c73fdd57defd0ebc403e50b49d1fd832ec6976 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(); |
+ |
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
|
if ((m_layer.leftBounds().size() != 0 && m_layer.leftBounds().size() != 4) || |
(m_layer.rightBounds().size() != 0 && |
m_layer.rightBounds().size() != 4)) { |
@@ -344,6 +349,34 @@ HeapVector<VRLayer> VRDisplay::getLayers() { |
} |
void VRDisplay::submitFrame() { |
+ // 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
|
+ // 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 +402,7 @@ DEFINE_TRACE(VRDisplay) { |
visitor->trace(m_eyeParametersLeft); |
visitor->trace(m_eyeParametersRight); |
visitor->trace(m_layer); |
+ visitor->trace(m_renderingContext); |
} |
} // namespace blink |