[CG] ImageBufferData::getData has an invariant comparison in the inner part of a...
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 02:04:29 +0000 (02:04 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 02:04:29 +0000 (02:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68588
<rdar://problem/10164955>

Reviewed by Simon Fraser.

Factor the unmultiplied check out of the inner loop, resulting in a
speed bump in ImageBufferData::getData.

No new tests, performance improvement.

* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::getData):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95695 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp

index b74f74e..53665ce 100644 (file)
@@ -1,3 +1,19 @@
+2011-09-21  Tim Horton  <timothy_horton@apple.com>
+
+        [CG] ImageBufferData::getData has an invariant comparison in the inner part of a loop which doesn't get optimized out
+        https://bugs.webkit.org/show_bug.cgi?id=68588
+        <rdar://problem/10164955>
+
+        Reviewed by Simon Fraser.
+
+        Factor the unmultiplied check out of the inner loop, resulting in a
+        speed bump in ImageBufferData::getData.
+
+        No new tests, performance improvement.
+
+        * platform/graphics/cg/ImageBufferDataCG.cpp:
+        (WebCore::ImageBufferData::getData):
+
 2011-09-21  Sameer Patil  <mkrp87@motorola.com>
 
         :hover selector fails when hovering over a child select element with size attribute
index 08652c9..0d2e14b 100644 (file)
@@ -173,20 +173,29 @@ PassRefPtr<ByteArray> ImageBufferData::getData(const IntRect& rect, const IntSiz
             return result.release();
         }
 #endif
-        for (int y = 0; y < height; ++y) {
-            for (int x = 0; x < width; x++) {
-                int basex = x * 4;
-                unsigned char alpha = srcRows[basex + 3];
-                if (unmultiplied && alpha) {
-                    destRows[basex] = (srcRows[basex] * 255) / alpha;
-                    destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha;
-                    destRows[basex + 2] = (srcRows[basex + 2] * 255) / alpha;
-                    destRows[basex + 3] = alpha;
-                } else
-                    reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0];
+        if (unmultiplied) {
+            for (int y = 0; y < height; ++y) {
+                for (int x = 0; x < width; x++) {
+                    int basex = x * 4;
+                    unsigned char alpha = srcRows[basex + 3];
+                    if (alpha) {
+                        destRows[basex] = (srcRows[basex] * 255) / alpha;
+                        destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha;
+                        destRows[basex + 2] = (srcRows[basex + 2] * 255) / alpha;
+                        destRows[basex + 3] = alpha;
+                    } else
+                        reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0];
+                }
+                srcRows += srcBytesPerRow;
+                destRows += destBytesPerRow;
+            }
+        } else {
+            for (int y = 0; y < height; ++y) {
+                for (int x = 0; x < width * 4; x += 4)
+                    reinterpret_cast<uint32_t*>(destRows + x)[0] = reinterpret_cast<uint32_t*>(srcRows + x)[0];
+                srcRows += srcBytesPerRow;
+                destRows += destBytesPerRow;
             }
-            srcRows += srcBytesPerRow;
-            destRows += destBytesPerRow;
         }
     } else {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
@@ -223,24 +232,38 @@ PassRefPtr<ByteArray> ImageBufferData::getData(const IntRect& rect, const IntSiz
             vImagePermuteChannels_ARGB8888(&src, &dest, map, kvImageNoFlags);
         }
 #else
-        for (int y = 0; y < height; ++y) {
-            for (int x = 0; x < width; x++) {
-                int basex = x * 4;
-                unsigned char alpha = srcRows[basex + 3];
-                if (unmultiplied && alpha) {
-                    destRows[basex] = (srcRows[basex + 2] * 255) / alpha;
-                    destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha;
-                    destRows[basex + 2] = (srcRows[basex] * 255) / alpha;
-                    destRows[basex + 3] = alpha;
-                } else {
+        if (unmultiplied) {
+            for (int y = 0; y < height; ++y) {
+                for (int x = 0; x < width; x++) {
+                    int basex = x * 4;
+                    unsigned char alpha = srcRows[basex + 3];
+                    if (alpha) {
+                        destRows[basex] = (srcRows[basex + 2] * 255) / alpha;
+                        destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha;
+                        destRows[basex + 2] = (srcRows[basex] * 255) / alpha;
+                        destRows[basex + 3] = alpha;
+                    } else {
+                        destRows[basex] = srcRows[basex + 2];
+                        destRows[basex + 1] = srcRows[basex + 1];
+                        destRows[basex + 2] = srcRows[basex];
+                        destRows[basex + 3] = srcRows[basex + 3];
+                    }
+                }
+                srcRows += srcBytesPerRow;
+                destRows += destBytesPerRow;
+            }
+        } else {
+            for (int y = 0; y < height; ++y) {
+                for (int x = 0; x < width; x++) {
+                    int basex = x * 4;
                     destRows[basex] = srcRows[basex + 2];
                     destRows[basex + 1] = srcRows[basex + 1];
                     destRows[basex + 2] = srcRows[basex];
-                    destRows[basex + 3] = alpha;
+                    destRows[basex + 3] = srcRows[basex + 3];
                 }
+                srcRows += srcBytesPerRow;
+                destRows += destBytesPerRow;
             }
-            srcRows += srcBytesPerRow;
-            destRows += destBytesPerRow;
         }
 #endif // USE(ACCELERATE)
         IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly, 0);