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.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125154
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-08-08 Alpha Lam <hclam@chromium.org>
+
+ 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 <xingnan.wang@intel.com>
Skip CoreAnimation plugin model tests on android
--- /dev/null
+<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 = "http://127.0.0.1:8000/resources/load-and-stall.php?name=../../../fast/images/resources/green-256x256.jpg&mimeType=image%2Fjpeg&stallAt=1025&stallFor=60";
+
+ setTimeout(checkWidth, 1);
+}
+</script>
+</head>
+<body onload="setTimeout('runTest()', 1);" style="background-color: yellow;">
+<img id="image" style="background-color: blue;">
+</body>
+</html>
--- /dev/null
+<?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);
+?>
+2012-08-08 Alpha Lam <hclam@chromium.org>
+
+ 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 <webkit.review.bot@gmail.com>
Unreviewed, rolling out r125146.
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()
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
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)
}
+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;
// 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; }