From 8ab9a9aa21904593dd3adf4c4a5e73afe75ed575 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Thu, 21 Dec 2017 17:42:52 -0800 Subject: [PATCH] Bug 1427668 - Assert that no-alpha backbuffers have 0xff alpha. - r=daoshengmu MozReview-Commit-ID: 5UJdoud0f2C --- dom/canvas/WebGLContext.cpp | 9 +++++++++ dom/canvas/WebGLContext.h | 2 +- gfx/gl/GLContext.h | 1 - gfx/gl/GLReadTexImageHelper.cpp | 5 ----- gfx/layers/CopyableCanvasRenderer.cpp | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index 2e8a132b4b27..a5aa7cc22268 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -1576,6 +1576,15 @@ WebGLContext::PresentScreenBuffer() gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); BlitBackbufferToCurDriverFB(); +#ifdef DEBUG + if (!mOptions.alpha) { + gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); + uint32_t pixel = 3; + gl->fReadPixels(0, 0, 1, 1, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, &pixel); + MOZ_ASSERT((pixel & 0xff000000) == 0xff000000); + } +#endif + if (!screen->PublishFrame(screen->Size())) { GenerateWarning("PublishFrame failed. Losing context."); ForceLoseContext(); diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 208d502c7de9..b2f6865cba28 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -366,7 +366,7 @@ public: GetSurfaceSnapshot(gfxAlphaType* out_alphaType) override; virtual void SetIsOpaque(bool) override {}; - bool GetIsOpaque() override { return false; } + bool GetIsOpaque() override { return !mOptions.alpha; } NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle options, ErrorResult& aRvForDictionaryInit) override; diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index 4f80fe2046be..7dc53835ff43 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -1543,7 +1543,6 @@ public: } void raw_fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) { - ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(pixels); BEFORE_GL_CALL; mSymbols.fReadPixels(x, y, width, height, format, type, pixels); OnSyncCall(); diff --git a/gfx/gl/GLReadTexImageHelper.cpp b/gfx/gl/GLReadTexImageHelper.cpp index bc0d3b4f5ae1..92a8a59dcabf 100644 --- a/gfx/gl/GLReadTexImageHelper.cpp +++ b/gfx/gl/GLReadTexImageHelper.cpp @@ -632,11 +632,6 @@ GLReadTexImageHelper::ReadTexImage(DataSourceSurface* aDest, CLEANUP_IF_GLERROR_OCCURRED("when binding texture"); } - /* Draw quad */ - mGL->fClearColor(1.0f, 0.0f, 1.0f, 1.0f); - mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT); - CLEANUP_IF_GLERROR_OCCURRED("when clearing color buffer"); - mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4); CLEANUP_IF_GLERROR_OCCURRED("when drawing texture"); diff --git a/gfx/layers/CopyableCanvasRenderer.cpp b/gfx/layers/CopyableCanvasRenderer.cpp index 1bfa07a15d1a..3c571c18edeb 100644 --- a/gfx/layers/CopyableCanvasRenderer.cpp +++ b/gfx/layers/CopyableCanvasRenderer.cpp @@ -155,8 +155,8 @@ CopyableCanvasRenderer::ReadbackSurface() } IntSize readSize(frontbuffer->mSize); - SurfaceFormat format = frontbuffer->mHasAlpha ? SurfaceFormat::B8G8R8X8 - : SurfaceFormat::B8G8R8A8; + SurfaceFormat format = frontbuffer->mHasAlpha ? SurfaceFormat::B8G8R8A8 + : SurfaceFormat::B8G8R8X8; bool needsPremult = frontbuffer->mHasAlpha && !mIsAlphaPremultiplied; RefPtr resultSurf = GetTempSurface(readSize, format);