Bug 1304291 - Move driver workaround code into fReadPixels and remove alpha check. r=jgilbert. a=gchang
authorChih-Yi Leu <cleu@mozilla.com>
Thu, 27 Oct 2016 23:23:00 -0400
changeset 356572 2ab68e90f1effbd8517bb785509aa2d0567db9ab
parent 356571 263190e20543fc7f39c6d41c8fd31cedccdbffd8
child 356573 3b68ca65557a1eb724b3f9b3e0d1fe2a1a7574d7
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert, gchang
bugs1304291
milestone51.0a2
Bug 1304291 - Move driver workaround code into fReadPixels and remove alpha check. r=jgilbert. a=gchang
gfx/gl/GLContext.cpp
gfx/gl/GLReadTexImageHelper.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -2868,16 +2868,45 @@ GLContext::fReadPixels(GLint x, GLint y,
         didReadPixels = mScreen->ReadPixels(x, y, width, height, format, type, pixels);
     }
 
     if (!didReadPixels) {
         raw_fReadPixels(x, y, width, height, format, type, pixels);
     }
 
     AfterGLReadCall();
+
+    // Check if GL is giving back 1.0 alpha for
+    // RGBA reads to RGBA images from no-alpha buffers.
+#ifdef XP_MACOSX
+    if (WorkAroundDriverBugs() &&
+        Vendor() == gl::GLVendor::NVIDIA &&
+        format == LOCAL_GL_RGBA &&
+        type == LOCAL_GL_UNSIGNED_BYTE &&
+        !IsCoreProfile() &&
+        width && height)
+    {
+        GLint alphaBits = 0;
+        fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits);
+        if (!alphaBits) {
+            const uint32_t alphaMask = 0xff000000;
+
+            uint32_t* itr = (uint32_t*)pixels;
+            uint32_t testPixel = *itr;
+            if ((testPixel & alphaMask) != alphaMask) {
+                // We need to set the alpha channel to 1.0 manually.
+                uint32_t* itrEnd = itr + width*height;  // Stride is guaranteed to be width*4.
+
+                for (; itr != itrEnd; itr++) {
+                    *itr |= alphaMask;
+                }
+            }
+        }
+    }
+#endif
 }
 
 void
 GLContext::fDeleteFramebuffers(GLsizei n, const GLuint* names)
 {
     if (mScreen) {
         // Notify mScreen which framebuffers we're deleting.
         // Otherwise, we will get framebuffer binding mispredictions.
--- a/gfx/gl/GLReadTexImageHelper.cpp
+++ b/gfx/gl/GLReadTexImageHelper.cpp
@@ -406,46 +406,16 @@ ReadPixelsIntoDataSurface(GLContext* gl,
                         readSurf->GetData());
     }
 
     if (readSurf != dest) {
         MOZ_ASSERT(readFormat == LOCAL_GL_RGBA);
         MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_BYTE);
         gfx::Factory::CopyDataSourceSurface(readSurf, dest);
     }
-
-    // Check if GL is giving back 1.0 alpha for
-    // RGBA reads to RGBA images from no-alpha buffers.
-#ifdef XP_MACOSX
-    if (gl->WorkAroundDriverBugs() &&
-        gl->Vendor() == gl::GLVendor::NVIDIA &&
-        !gl->IsCoreProfile() &&
-        hasAlpha &&
-        width && height)
-    {
-        GLint alphaBits = 0;
-        gl->fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits);
-        if (!alphaBits) {
-            const uint32_t alphaMask = gfxPackedPixelNoPreMultiply(0xff,0,0,0);
-
-            MOZ_ASSERT(dest->GetSize().width * destPixelSize == dest->Stride());
-
-            uint32_t* itr = (uint32_t*)dest->GetData();
-            uint32_t testPixel = *itr;
-            if ((testPixel & alphaMask) != alphaMask) {
-                // We need to set the alpha channel to 1.0 manually.
-                uint32_t* itrEnd = itr + width*height;  // Stride is guaranteed to be width*4.
-
-                for (; itr != itrEnd; itr++) {
-                    *itr |= alphaMask;
-                }
-            }
-        }
-    }
-#endif
 }
 
 already_AddRefed<gfx::DataSourceSurface>
 YInvertImageSurface(gfx::DataSourceSurface* aSurf)
 {
     RefPtr<DataSourceSurface> temp =
       Factory::CreateDataSourceSurfaceWithStride(aSurf->GetSize(),
                                                  aSurf->GetFormat(),