diff --git a/third_party/blink/renderer/modules/xr/xr_webgl_swap_chain.cc b/third_party/blink/renderer/modules/xr/xr_webgl_swap_chain.cc index 7bb3991d04f36..9cbeaa7c51327 100644 --- a/third_party/blink/renderer/modules/xr/xr_webgl_swap_chain.cc +++ b/third_party/blink/renderer/modules/xr/xr_webgl_swap_chain.cc @@ -69,6 +69,18 @@ void XRWebGLSwapChain::ClearCurrentTexture() { gl->Disable(GL_SCISSOR_TEST); + // GL_RASTERIZER_DISCARD is page-settable in WebGL2 and causes ANGLE's + // Context::clear() to silently no-op. This is the security clear of an + // XR-runtime-supplied texture (which on Android is an un-zeroed + // AHardwareBuffer falsely marked SetCleared()), so it must not be skipped. + GLboolean rasterizer_discard_was_enabled = GL_FALSE; + if (webgl2()) { + rasterizer_discard_was_enabled = gl->IsEnabled(GL_RASTERIZER_DISCARD); + if (rasterizer_discard_was_enabled) { + gl->Disable(GL_RASTERIZER_DISCARD); + } + } + if (descriptor_.is_texture_array) { DLOG(ERROR) << __func__ << " Performing texture array clear"; for (uint32_t i = 0; i < descriptor_.layers; ++i) { @@ -92,6 +104,10 @@ void XRWebGLSwapChain::ClearCurrentTexture() { } gl->Flush(); + if (rasterizer_discard_was_enabled) { + gl->Enable(GL_RASTERIZER_DISCARD); + } + // WebGLRenderingContextBase inherits from DrawingBuffer::Client, but makes // all the methods private. Downcasting allows us to access them. DrawingBuffer::Client* client =