Commit 5e9c485d authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Fix a crash in GLSurfaceEglReadback::SwapBuffers()

The crash is because GLSurfaceEglReadback::SwapBuffers() uses
glReadPixels() to read back pixels from framebuffer to a buffer.
It assumes the current GL_PIXEL_PACK_BUFFER_BINDING is 0, so
glReadPixels() will store pixels in the buffer passed in instead
of buffer binded at GL_PIXEL_PACK_BUFFER. However the
GL_PIXEL_PACK_BUFFER_BINDING is not 0 sometimes. Fix the problem
by binding 0 to GL_PIXEL_PACK_BUFFER before glReadPixels(), and
restore it after glTreadPixels(). This change also sets 0 to
GL_READ_FRAMEBUFFER_BINDING to make sure reading from the right
surface.

Bug: 1073882
Change-Id: Ic4bf35fb02baccb87664b7488af06d77d5197446
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2163080
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762161}
parent dd6eb156
......@@ -44,9 +44,29 @@ bool GLSurfaceEglReadback::IsOffscreen() {
gfx::SwapResult GLSurfaceEglReadback::SwapBuffers(
PresentationCallback callback) {
const gfx::Size size = GetSize();
GLint read_fbo = 0;
GLint pixel_pack_buffer = 0;
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_fbo);
glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &pixel_pack_buffer);
// Make sure pixels are read from fbo 0.
if (read_fbo)
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
// Make sure pixels are stored into |pixels_| instead of buffer binding to
// GL_PIXEL_PACK_BUFFER.
if (pixel_pack_buffer)
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glReadPixels(0, 0, size.width(), size.height(), GL_BGRA, GL_UNSIGNED_BYTE,
pixels_.get());
if (read_fbo)
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_fbo);
if (pixel_pack_buffer)
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixel_pack_buffer);
gfx::SwapResult swap_result = gfx::SwapResult::SWAP_FAILED;
gfx::PresentationFeedback feedback;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment