[SKIA/CHROMIUM] Perform getImageData format conversions using Skia
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 19:21:32 +0000 (19:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 19:21:32 +0000 (19:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77553

Patch by Brian Salomon <bsalomon@google.com> on 2012-02-01
Reviewed by Stephen White.

Source/WebCore:

Many existing canvas tests exercise this functionality.

* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::getImageData):

LayoutTests:

* platform/chromium/test_expectations.txt:

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

LayoutTests/ChangeLog
LayoutTests/platform/chromium/test_expectations.txt
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

index 8af76b4..dab31eb 100644 (file)
@@ -1,3 +1,12 @@
+2012-02-01  Brian Salomon  <bsalomon@google.com>
+
+        [SKIA/CHROMIUM] Perform getImageData format conversions using Skia
+        https://bugs.webkit.org/show_bug.cgi?id=77553
+
+        Reviewed by Stephen White.
+
+        * platform/chromium/test_expectations.txt:
+
 2012-02-01  Nate Chapin  <japhet@chromium.org>
 
         Test for https://bugs.webkit.org/show_bug.cgi?id=73097.
index c34ffb9..6bd36fa 100644 (file)
@@ -2379,7 +2379,7 @@ BUGCR61739 WIN RELEASE : animations/suspend-resume-animation-events.html = TEXT
 // See https://bugs.webkit.org/show_bug.cgi?id=51982 for more info.
 BUGWK52509 LINUX WIN : svg/css/rect-gradient-stroke-shadow.svg = IMAGE
 BUGWK52509 LEOPARD : svg/css/rect-gradient-stroke-shadow.svg = IMAGE
-BUGCR63921 LINUX WIN CPU : fast/canvas/canvas-fillPath-shadow.html = TEXT
+BUGCR63921 LINUX WIN : fast/canvas/canvas-fillPath-shadow.html = TEXT
 
 // Mainly flaky with mac debug, but also intermittent crashes seen on linux and windows
 BUGCR64129 : fast/files/revoke-blob-url.html = PASS CRASH
@@ -2591,11 +2591,9 @@ BUGCR71783 : scrollbars/custom-scrollbar-with-incomplete-style.html = IMAGE
 // GPU
 //
 
-// This test expects that putImageData followed by getImageData at the same location
-// will return the exact same pixel values. However, the spec allows some fuzziness
-// due to conversion to/from premultiplied-alpha. When we do the conversions on the
-// GPU we may be off by one in r, g, and/or b.
-BUGWK73952 GPU : canvas/philip/tests/2d.imageData.put.unchanged.html = TEXT
+// Combination of unpremul plus gradient computation at half-integer coords causes
+// this to fail.
+BUGWK77550 GPU : canvas/philip/tests/2d.gradient.interpolate.colouralpha.html = TEXT
 
 // These will have slight differences on the edges of antialiased paths and need rebaseling
 BUGBSALOMON GPU : fast/canvas/arc360.html = IMAGE
index 0d00a4c..73d789c 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-01  Brian Salomon  <bsalomon@google.com>
+
+        [SKIA/CHROMIUM] Perform getImageData format conversions using Skia
+        https://bugs.webkit.org/show_bug.cgi?id=77553
+
+        Reviewed by Stephen White.
+
+        Many existing canvas tests exercise this functionality.
+
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::getImageData):
+
 2012-02-01  Nate Chapin  <japhet@chromium.org>
 
         preventDefault() in a mousedown in a subframe should not
index f96c569..ef0a933 100644 (file)
@@ -226,65 +226,18 @@ PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkCanvas* canvas,
         || rect.maxY() > size.height())
         memset(data, 0, result->length());
 
-    int originX = rect.x();
-    int destX = 0;
-    if (originX < 0) {
-        destX = -originX;
-        originX = 0;
-    }
-    int endX = rect.maxX();
-    if (endX > size.width())
-        endX = size.width();
-    int numColumns = endX - originX;
-
-    if (numColumns <= 0)
-        return result.release();
-
-    int originY = rect.y();
-    int destY = 0;
-    if (originY < 0) {
-        destY = -originY;
-        originY = 0;
-    }
-    int endY = rect.maxY();
-    if (endY > size.height())
-        endY = size.height();
-    int numRows = endY - originY;
-
-    if (numRows <= 0)
-        return result.release();
-
-    SkBitmap srcBitmap;
-    if (!canvas->readPixels(SkIRect::MakeXYWH(originX, originY, numColumns, numRows), &srcBitmap))
-        return result.release();
-
     unsigned destBytesPerRow = 4 * rect.width();
-    unsigned char* destRow = data + destY * destBytesPerRow + destX * 4;
-
-    // Do conversion of byte order and alpha divide (if necessary)
-    for (int y = 0; y < numRows; ++y) {
-        SkPMColor* srcBitmapRow = srcBitmap.getAddr32(0, y);
-        for (int x = 0; x < numColumns; ++x) {
-            SkPMColor srcPMColor = srcBitmapRow[x];
-            unsigned char* destPixel = &destRow[x * 4];
-            if (multiplied == Unmultiplied) {
-                unsigned char a = SkGetPackedA32(srcPMColor);
-                destPixel[0] = a ? SkGetPackedR32(srcPMColor) * 255 / a : 0;
-                destPixel[1] = a ? SkGetPackedG32(srcPMColor) * 255 / a : 0;
-                destPixel[2] = a ? SkGetPackedB32(srcPMColor) * 255 / a : 0;
-                destPixel[3] = a;
-            } else {
-                // Input and output are both pre-multiplied, we just need to re-arrange the
-                // bytes from the bitmap format to RGBA.
-                destPixel[0] = SkGetPackedR32(srcPMColor);
-                destPixel[1] = SkGetPackedG32(srcPMColor);
-                destPixel[2] = SkGetPackedB32(srcPMColor);
-                destPixel[3] = SkGetPackedA32(srcPMColor);
-            }
-        }
-        destRow += destBytesPerRow;
-    }
+    SkBitmap destBitmap;
+    destBitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height(), destBytesPerRow);
+    destBitmap.setPixels(data);
+
+    SkCanvas::Config8888 config8888;
+    if (multiplied == Premultiplied)
+        config8888 = SkCanvas::kRGBA_Premul_Config8888;
+    else
+        config8888 = SkCanvas::kRGBA_Unpremul_Config8888;
 
+    canvas->readPixels(&destBitmap, rect.x(), rect.y(), config8888);
     return result.release();
 }