Title: [125154] trunk
Revision
125154
Author
[email protected]
Date
2012-08-08 23:23:42 -0700 (Wed, 08 Aug 2012)

Log Message

Source/WebCore: Remove image decoding in some BitmapImage metadata functions
https://bugs.webkit.org/show_bug.cgi?id=93171

Reviewed by Simon Fraser.

These two metadata functions were decoding an entire frame:
- frameOrientationAtIndex
- frameHasAlphaAtIndex

This change removes image decoding from these two methods. This is for
preparation of having asynchronous image decoding, intending to reduce
code location that trigger image decoding.

frameOrientationAtIndex() doesn't require decoding a frame. This method
is only implemented in CG port in ImageSourceCG.cpp which doesn't do
image decoding.

frameHasAlphaAtIndex() is used to optimize certain drawing operations
and accelerated compositing. This change uses a heuristic for non-CG
port to determine if an image has alpha. If an image is not yet
decoded the function answers having alpha. Only if a frame is decoded
and cached that the alpha state of the frame is returned. This is an
admissible heuristic that postpone answering the question until a frame
is decoded.

Tested this change with a fully loaded image and partially loaded image
with background color.

Test: http/tests/images/jpg-img-partial-load.html

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::frameHasAlphaAtIndex):
(WebCore::BitmapImage::frameOrientationAtIndex):
* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::frameHasAlphaAtIndex):
* platform/image-decoders/ImageDecoder.cpp:
(WebCore::ImageDecoder::frameHasAlphaAtIndex):
(WebCore):
* platform/image-decoders/ImageDecoder.h:
(ImageDecoder):

LayoutTests: Test rendering JPEG <img> with CSS background
https://bugs.webkit.org/show_bug.cgi?id=93171

Reviewed by Simon Fraser.

Tests defer answering the alpha state for BitmapImage not yet
decoded doesn't affect rendering results.

Test: http/tests/images/jpg-img-partial-load.html

Tests the rendering results of a partially loaded JPEG image.
The image should be green in the top region and blue in the
lower region. The blue is the background color revealed by
full alpha of the undecoded region.

* fast/images/resources/green-256x256.jpg: Added.
* http/tests/images/jpg-img-partial-load-expected.png: Added.
* http/tests/images/jpg-img-partial-load-expected.txt: Added.
* http/tests/images/jpg-img-partial-load.html: Added.
* http/tests/resources/load-and-stall.php: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (125153 => 125154)


--- trunk/LayoutTests/ChangeLog	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/LayoutTests/ChangeLog	2012-08-09 06:23:42 UTC (rev 125154)
@@ -1,3 +1,26 @@
+2012-08-08  Alpha Lam  <[email protected]>
+
+        Test rendering JPEG <img> with CSS background
+        https://bugs.webkit.org/show_bug.cgi?id=93171
+
+        Reviewed by Simon Fraser.
+
+        Tests defer answering the alpha state for BitmapImage not yet
+        decoded doesn't affect rendering results.
+
+        Test: http/tests/images/jpg-img-partial-load.html
+
+        Tests the rendering results of a partially loaded JPEG image.
+        The image should be green in the top region and blue in the
+        lower region. The blue is the background color revealed by
+        full alpha of the undecoded region.
+
+        * fast/images/resources/green-256x256.jpg: Added.
+        * http/tests/images/jpg-img-partial-load-expected.png: Added.
+        * http/tests/images/jpg-img-partial-load-expected.txt: Added.
+        * http/tests/images/jpg-img-partial-load.html: Added.
+        * http/tests/resources/load-and-stall.php: Added.
+
 2012-08-08  Xingnan Wang  <[email protected]>
 
         Skip CoreAnimation plugin model tests on android

Added: trunk/LayoutTests/fast/images/resources/green-256x256.jpg (0 => 125154)


--- trunk/LayoutTests/fast/images/resources/green-256x256.jpg	                        (rev 0)
+++ trunk/LayoutTests/fast/images/resources/green-256x256.jpg	2012-08-09 06:23:42 UTC (rev 125154)
@@ -0,0 +1,5 @@
+\xFF\xD8\xFF\xE0JFIFHH\xFF\xDBC\xFF\xDBC\xFF\xC0"\xFF\xC4	
+\xFF\xC4\xB5}!1AQa"q2\x81\x91\xA1#B\xB1\xC1R\xD1\xF0$3br\x82	
+%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC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8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A\xFF\xD9
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.png (0 => 125154)


--- trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.png	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.png	2012-08-09 06:23:42 UTC (rev 125154)
@@ -0,0 +1,5 @@
+\x89PNG
+
+
+IHDR X')tEXtchecksumb847f02b02ed1803992577273ea41803\xAF\x88\x8F\xA5
+\xCBIDATx\x9C\xED\xDC1\xC3 A\x88|\xFF#\x87\x9C\xC0\x8D\xB52\x8E5\xD3Ҽr\xF5\xE6Z\x80\xD0g\xF7\x80\xB7X1\x81X1\x81X1\x81;\xCE\xE6\x98w\xEE\x80GY\xC3q\\xE7\x82X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81X1\x81;N_\xE6\xF7\xC6\xF00k\xEE^\xC0s\xC1\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88͵vOx,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\x98\xC0\x88	,\x80\xD8o>\xAE(\xB0\xED\xC7IEND\xAEB`\x82
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.txt (0 => 125154)


--- trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/jpg-img-partial-load-expected.txt	2012-08-09 06:23:42 UTC (rev 125154)
@@ -0,0 +1 @@
+

Added: trunk/LayoutTests/http/tests/images/jpg-img-partial-load.html (0 => 125154)


--- trunk/LayoutTests/http/tests/images/jpg-img-partial-load.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/jpg-img-partial-load.html	2012-08-09 06:23:42 UTC (rev 125154)
@@ -0,0 +1,30 @@
+<html>
+<head>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText(true);
+    testRunner.waitUntilDone();
+}
+
+function checkWidth()
+{
+    var image = document.getElementById("image");
+    if (image.width == 256 && window.testRunner)
+        testRunner.notifyDone();
+
+    setTimeout(checkWidth, 1);
+}
+
+function runTest()
+{
+    var image = document.getElementById("image");
+    image.src = ""
+
+    setTimeout(checkWidth, 1);
+}
+</script>
+</head>
+<body _onload_="setTimeout('runTest()', 1);" style="background-color: yellow;">
+<img id="image" style="background-color: blue;">
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/resources/load-and-stall.php (0 => 125154)


--- trunk/LayoutTests/http/tests/resources/load-and-stall.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resources/load-and-stall.php	2012-08-09 06:23:42 UTC (rev 125154)
@@ -0,0 +1,37 @@
+<?php
+$name = $_GET['name'];
+$stallAt = $_GET['stallAt'];
+$stallFor = $_GET['stallFor'];
+$mimeType = $_GET['mimeType'];
+
+$file = fopen($name, "rb");
+if (!$file)
+    die("Cannot open file.");
+
+header("Content-Type: " . $mimeType);
+header("Content-Length: " . filesize($name));
+
+if (isset($stallAt) && isset($stallFor)) {
+    $stallAt = (int)$stallAt;
+    $stallFor = (int)$stallFor;
+    if ($stallAt > filesize($name))
+        die("Incorrect value for stallAt.");
+
+    while ($written < $stallAt) {
+        $write = 1024;
+        if ($write > $stallAt - $written)
+            $write = $stallAt - $written;
+
+        echo(fread($file, $write));
+        $written += $write;
+        flush();
+        ob_flush();
+    }
+    sleep($stallFor);
+    echo(fread($file, filesize($name) - $stallAt));
+} else {
+    echo(fread($file, filesize($name)));
+}
+
+fclose($file);
+?>

Modified: trunk/Source/WebCore/ChangeLog (125153 => 125154)


--- trunk/Source/WebCore/ChangeLog	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/Source/WebCore/ChangeLog	2012-08-09 06:23:42 UTC (rev 125154)
@@ -1,3 +1,46 @@
+2012-08-08  Alpha Lam  <[email protected]>
+
+        Remove image decoding in some BitmapImage metadata functions
+        https://bugs.webkit.org/show_bug.cgi?id=93171
+
+        Reviewed by Simon Fraser.
+
+        These two metadata functions were decoding an entire frame:
+        - frameOrientationAtIndex
+        - frameHasAlphaAtIndex
+
+        This change removes image decoding from these two methods. This is for
+        preparation of having asynchronous image decoding, intending to reduce
+        code location that trigger image decoding.
+
+        frameOrientationAtIndex() doesn't require decoding a frame. This method
+        is only implemented in CG port in ImageSourceCG.cpp which doesn't do
+        image decoding.
+
+        frameHasAlphaAtIndex() is used to optimize certain drawing operations
+        and accelerated compositing. This change uses a heuristic for non-CG
+        port to determine if an image has alpha. If an image is not yet
+        decoded the function answers having alpha. Only if a frame is decoded
+        and cached that the alpha state of the frame is returned. This is an
+        admissible heuristic that postpone answering the question until a frame
+        is decoded.
+
+        Tested this change with a fully loaded image and partially loaded image
+        with background color.
+
+        Test: http/tests/images/jpg-img-partial-load.html
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::frameHasAlphaAtIndex):
+        (WebCore::BitmapImage::frameOrientationAtIndex):
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::frameHasAlphaAtIndex):
+        * platform/image-decoders/ImageDecoder.cpp:
+        (WebCore::ImageDecoder::frameHasAlphaAtIndex):
+        (WebCore):
+        * platform/image-decoders/ImageDecoder.h:
+        (ImageDecoder):
+
 2012-08-08  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r125146.

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (125153 => 125154)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2012-08-09 06:23:42 UTC (rev 125154)
@@ -322,11 +322,13 @@
 
 bool BitmapImage::frameHasAlphaAtIndex(size_t index)
 {
-    // When a frame has not finished decoding, always mark it as having alpha.
-    // See ImageSource::framehasAlphaAtIndex for explanation of why incomplete images claim to have alpha.
-    if (!ensureFrameIsCached(index))
+    if (m_frames.size() <= index)
         return true;
-    return m_frames[index].m_hasAlpha;
+
+    if (m_frames[index].m_haveMetadata)
+        return m_frames[index].m_hasAlpha;
+
+    return m_source.frameHasAlphaAtIndex(index);
 }
 
 bool BitmapImage::currentFrameHasAlpha()
@@ -341,9 +343,13 @@
 
 ImageOrientation BitmapImage::frameOrientationAtIndex(size_t index)
 {
-    if (!ensureFrameIsCached(index))
+    if (m_frames.size() <= index)
         return DefaultImageOrientation;
-    return m_frames[index].m_orientation;
+
+    if (m_frames[index].m_haveMetadata)
+        return m_frames[index].m_orientation;
+
+    return m_source.orientationAtIndex(index);
 }
 
 #if !ASSERT_DISABLED

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (125153 => 125154)


--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2012-08-09 06:23:42 UTC (rev 125154)
@@ -184,14 +184,9 @@
 
 bool ImageSource::frameHasAlphaAtIndex(size_t index)
 {
-    // When a frame has not finished decoding, always mark it as having alpha.
-    // Ports that check the result of this function to determine their
-    // compositing op need this in order to not draw the undecoded portion as
-    // black.
-    // TODO: Perhaps we should ensure that each individual decoder returns true
-    // in this case.
-    return !frameIsCompleteAtIndex(index)
-        || m_decoder->frameBufferAtIndex(index)->hasAlpha();
+    if (!m_decoder)
+        return true;
+    return m_decoder->frameHasAlphaAtIndex(index);
 }
 
 bool ImageSource::frameIsCompleteAtIndex(size_t index)

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp (125153 => 125154)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2012-08-09 06:23:42 UTC (rev 125154)
@@ -277,6 +277,15 @@
 
 }
 
+bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
+{
+    if (m_frameBufferCache.size() <= index)
+        return true;
+    if (m_frameBufferCache[index].status() == ImageFrame::FrameComplete)
+        return m_frameBufferCache[index].hasAlpha();
+    return true;
+}
+
 void ImageDecoder::prepareScaleDataIfNecessary()
 {
     m_scaled = false;

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h (125153 => 125154)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2012-08-09 05:50:24 UTC (rev 125153)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2012-08-09 06:23:42 UTC (rev 125154)
@@ -276,6 +276,9 @@
         // ImageDecoder-owned pointer.
         virtual ImageFrame* frameBufferAtIndex(size_t) = 0;
 
+        // Make the best effort guess to check if the requested frame has alpha channel.
+        virtual bool frameHasAlphaAtIndex(size_t) const;
+
         void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; }
         bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfile; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to