Bug 729702 - Use ReadPixelsIntoImageSurface in CopyToTarget instead of duplicating functionality - r=BenWa
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 12 Mar 2012 18:42:02 -0700
changeset 88872 64086bfc8849e135e9260a1ed9f825b317925ba2
parent 88871 85ffbb75239866025a637cc0b1a2d27d2583b74e
child 88873 709bce4da1415dbb619d3fd159fc290c5d100184
push id7058
push userjgilbert@mozilla.com
push dateTue, 13 Mar 2012 01:42:28 +0000
treeherdermozilla-inbound@64086bfc8849 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs729702
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 729702 - Use ReadPixelsIntoImageSurface in CopyToTarget instead of duplicating functionality - r=BenWa
gfx/gl/GLContext.cpp
gfx/layers/opengl/LayerManagerOGL.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1848,17 +1848,19 @@ GLContext::ReadPixelsIntoImageSurface(GL
         aDest->Stride() != aWidth * 4)
     {
         NS_WARNING("ReadPixelsIntoImageSurface called with wrong size or stride surface");
         return;
     }
 
     GLint currentPackAlignment = 0;
     fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, &currentPackAlignment);
-    fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
+
+    if (currentPackAlignment != 4)
+        fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
 
     GLenum format;
     GLenum datatype;
 
     GetOptimalReadFormats(this, format, datatype);
 
     fReadPixels(0, 0, aWidth, aHeight,
                 format, datatype,
@@ -1871,17 +1873,18 @@ GLContext::ReadPixelsIntoImageSurface(GL
             PRUint32 *row = (PRUint32*) (aDest->Data() + aDest->Stride() * j);
             for (int i = 0; i < aWidth; ++i) {
                 *row = (*row & 0xff00ff00) | ((*row & 0xff) << 16) | ((*row & 0xff0000) >> 16);
                 row++;
             }
         }
     }
 
-    fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
+    if (currentPackAlignment != 4)
+        fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
 }
 
 void
 GLContext::BlitTextureImage(TextureImage *aSrc, const nsIntRect& aSrcRect,
                             TextureImage *aDst, const nsIntRect& aDstRect)
 {
     NS_ASSERTION(!aSrc->InUpdate(), "Source texture is in update!");
     NS_ASSERTION(!aDst->InUpdate(), "Destination texture is in update!");
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -1038,49 +1038,20 @@ LayerManagerOGL::CopyToTarget(gfxContext
   if (mGLContext->IsDoubleBuffered()) {
     mGLContext->fReadBuffer(LOCAL_GL_BACK);
   }
   else {
     mGLContext->fReadBuffer(LOCAL_GL_COLOR_ATTACHMENT0);
   }
 #endif
 
-  GLenum format = LOCAL_GL_RGBA;
-  if (mHasBGRA)
-    format = LOCAL_GL_BGRA;
-
   NS_ASSERTION(imageSurface->Stride() == width * 4,
                "Image Surfaces being created with weird stride!");
 
-  PRUint32 currentPackAlignment = 0;
-  mGLContext->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, (GLint*)&currentPackAlignment);
-  if (currentPackAlignment != 4) {
-    mGLContext->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
-  }
-
-  mGLContext->fReadPixels(0, 0,
-                          width, height,
-                          format,
-                          LOCAL_GL_UNSIGNED_BYTE,
-                          imageSurface->Data());
-
-  if (currentPackAlignment != 4) {
-    mGLContext->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
-  }
-
-  if (!mHasBGRA) {
-    // need to swap B and R bytes
-    for (int j = 0; j < height; ++j) {
-      PRUint32 *row = (PRUint32*) (imageSurface->Data() + imageSurface->Stride() * j);
-      for (int i = 0; i < width; ++i) {
-        *row = (*row & 0xff00ff00) | ((*row & 0xff) << 16) | ((*row & 0xff0000) >> 16);
-        row++;
-      }
-    }
-  }
+  mGLContext->ReadPixelsIntoImageSurface(0, 0, width, height, imageSurface);
 
   aTarget->SetOperator(gfxContext::OPERATOR_SOURCE);
   aTarget->Scale(1.0, -1.0);
   aTarget->Translate(-gfxPoint(0.0, height));
   aTarget->SetSource(imageSurface);
   aTarget->Paint();
 }