[chromium] Implement deferred image decoding
authorhclam@chromium.org <hclam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Oct 2012 21:40:54 +0000 (21:40 +0000)
committerhclam@chromium.org <hclam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Oct 2012 21:40:54 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94240

Reviewed by Stephen White.

Source/WebCore:

Objectives:

To record image decoding operations during painting and to defer
decoding operations until rasterization.

Rationale:

This is a key feature that enables impl-side painting which requires
fast recording of drawing operations. The existing decode-on-draw
restricts that recording has to block on expensive decoding operations.
This change allows recording of image decoding operations during paint
time.

Design:

Image decoding happens when a BitmapImage is drawn into a
GraphicsContext. When per-tile painting is enabled GraphicsContext
is backed by SkCanvas in recording mode. This SkCanvas records drawing
and image decoding operations to minimize recording time.

An image decoding operation is recorded as a SkPixelRef object
implemented by LazyDecodingPixelRef. This object references raw encoded
data, regions to be decoded and scaling information.

When used in conjunction with per-tile painting this feature defers
image decoding until the SkCanvas referencing the image is rasterized.

Both recording and rasterization happen on the main thread.

Performance Impact:

This feature is enabled by WebKit::setDeferredImageDecodingEnabled()
and does not have an impact when disabled.

This feature is disabled by default.

Upcoming Changes:

1. Implement a full-featured image cache in ImageDecodingStore.
2. Allow rasterization and decoding on impl thread.

Classes Involved:

BitmapImage

BitmapImage is the entry point for deferred image decoding. When
drawing a BitmapImage into a GraphicsContext it makes a request to
create a NativeImageSkia. We substitute the content in NativeImageSkia
such that it is lazily decoded.

DeferredImageDecoder

This is the platform implementation of a image decoder for Chromium.
This is a bridge layer that either delegates calls to the actual
ImageDecoder or create a lazily-decoded SkBitmap and delegates calls
to ImageDecodingStore.

ImageDecodingStore

This object manages all encoded images. It keeps track of encoded
data and the corresponding ImageDecoder for doing actual decoding. It
is also responsible for generating lazily decoded SkBitmaps. This
SkBitmap contains a LazyDecodingPixelRef object which references to an
image entry in ImageDecodingStore.

ScaledImageFragment

A container for a scaled image fragment. In addition to bitmap pixels
it contains information about the ID of the image, scale and clipping.

ImageFrameGenerator

This object is responsible for generating decoded pixels. It is also
a container for encoded image data and corresponding image decoder.

LazyDecodingPixelRef

This object is embedded in a SkBitmap to enable lazy decoding. When
SkBitmap needs to access pixels LazyDecodingPixelRef is locked. It
contains information to locate an image and scaling info, these
information is submitted to ImageDecodingStore to access actual pixels.

Layout tests. There are about 80 tests in this virtual test suite
running this feature in this directory:

platform/chromium/virtual/deferred/fast/images

Unit tests. Added DeferredImageDecoderTest to verify deferred
image decoding behavior.

* WebCore.gypi:
* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::setData):
* platform/graphics/ImageSource.h:
(WebCore):
(ImageSource):
* platform/graphics/chromium/DeferredImageDecoder.cpp: Added.
(WebCore):
(WebCore::DeferredImageDecoder::DeferredImageDecoder):
(WebCore::DeferredImageDecoder::~DeferredImageDecoder):
(WebCore::DeferredImageDecoder::create):
(WebCore::DeferredImageDecoder::createForTesting):
(WebCore::DeferredImageDecoder::filenameExtension):
(WebCore::DeferredImageDecoder::frameBufferAtIndex):
(WebCore::DeferredImageDecoder::setData):
(WebCore::DeferredImageDecoder::isSizeAvailable):
(WebCore::DeferredImageDecoder::size):
(WebCore::DeferredImageDecoder::frameSizeAtIndex):
(WebCore::DeferredImageDecoder::frameCount):
(WebCore::DeferredImageDecoder::repetitionCount):
(WebCore::DeferredImageDecoder::clearFrameBufferCache):
(WebCore::DeferredImageDecoder::frameHasAlphaAtIndex):
(WebCore::DeferredImageDecoder::frameBytesAtIndex):
* platform/graphics/chromium/DeferredImageDecoder.h: Added.
(WebCore):
(DeferredImageDecoder):
* platform/graphics/chromium/ImageDecodingStore.cpp: Added.
(WebCore::ImageDecodingStore::ImageDecodingStore):
(WebCore):
(WebCore::ImageDecodingStore::~ImageDecodingStore):
(WebCore::ImageDecodingStore::instanceOnMainThread):
(WebCore::ImageDecodingStore::initializeOnMainThread):
(WebCore::ImageDecodingStore::shutdown):
(WebCore::ImageDecodingStore::isLazyDecoded):
(WebCore::ImageDecodingStore::createLazyDecodedSkBitmap):
(WebCore::ImageDecodingStore::resizeLazyDecodedSkBitmap):
(WebCore::ImageDecodingStore::setData):
(WebCore::ImageDecodingStore::lockPixels):
(WebCore::ImageDecodingStore::unlockPixels):
(WebCore::ImageDecodingStore::frameGeneratorBeingDestroyed):
(WebCore::ImageDecodingStore::calledOnValidThread):
(WebCore::ImageDecodingStore::lookupFrameCache):
(WebCore::ImageDecodingStore::deleteFrameCache):
* platform/graphics/chromium/ImageDecodingStore.h: Added.
(WebCore):
(ImageDecodingStore):
(WebCore::ImageDecodingStore::create):
* platform/graphics/chromium/ScaledImageFragment.cpp: Added.
(WebCore):
(WebCore::ScaledImageFragment::~ScaledImageFragment):
(WebCore::ScaledImageFragment::ScaledImageFragment):
(WebCore::ScaledImageFragment::isEqual):
* platform/graphics/chromium/ScaledImageFragment.h: Added.
(WebCore):
(ScaledImageFragment):
(WebCore::ScaledImageFragment::create):
(WebCore::ScaledImageFragment::bitmap):
(WebCore::ScaledImageFragment::isComplete):
* platform/graphics/chromium/ImageFrameGenerator.cpp: Added.
(WebCore):
(WebCore::ImageFrameGenerator::ImageFrameGenerator):
(WebCore::ImageFrameGenerator::~ImageFrameGenerator):
(WebCore::ImageFrameGenerator::decoder):
(WebCore::ImageFrameGenerator::setData):
* platform/graphics/chromium/ImageFrameGenerator.h: Added.
(WebCore):
(ImageFrameGenerator):
(WebCore::ImageFrameGenerator::create):
(WebCore::ImageFrameGenerator::size):
(WebCore::ImageFrameGenerator::imageId):
* platform/graphics/chromium/LazyDecodingPixelRef.cpp: Added.
(WebCore):
(WebCore::LazyDecodingPixelRef::LazyDecodingPixelRef):
(WebCore::LazyDecodingPixelRef::~LazyDecodingPixelRef):
(WebCore::LazyDecodingPixelRef::isScaled):
(WebCore::LazyDecodingPixelRef::isClipped):
(WebCore::LazyDecodingPixelRef::onLockPixels):
(WebCore::LazyDecodingPixelRef::onUnlockPixels):
(WebCore::LazyDecodingPixelRef::onLockPixelsAreWritable):
* platform/graphics/chromium/LazyDecodingPixelRef.h: Added.
(WebCore):
(LazyDecodingPixelRef):
(WebCore::LazyDecodingPixelRef::frameGenerator):
* platform/graphics/skia/NativeImageSkia.cpp:
(WebCore::NativeImageSkia::resizedBitmap):
* platform/image-decoders/ImageDecoder.h:
(ImageFrame):
(WebCore::ImageFrame::setSkBitmap):
(WebCore::ImageFrame::getSkBitmap):

Source/WebKit/chromium:

Adding new unit tests for deferred image decoding.
These tests are defined in DeferredImageDecoderTest.cpp. They verify
image decoding happens only when SkPicture is rasterized for both
scaled and non-scaled cases.

Tests: DeferredImageDecoderTest.drawIntoSkPicture
       DeferredImageDecoderTest.drawScaledIntoSkPicture

* WebKit.gypi:
* public/WebSettings.h:
* src/WebKit.cpp:
(WebKit::shutdown):
* src/WebSettingsImpl.cpp:
(WebKit::WebSettingsImpl::setDeferredImageDecodingEnabled):
(WebKit):
* src/WebSettingsImpl.h:
(WebSettingsImpl):
* tests/DeferredImageDecoderTest.cpp: Added.
(WebCore):
(DeferredImageDecoderTest):
(WebCore::DeferredImageDecoderTest::SetUp):
(WebCore::DeferredImageDecoderTest::TearDown):
(WebCore::TEST_F):
* tests/MockImageDecoder.h: Added.
(WebCore):
(MockImageDecoder):
(WebCore::MockImageDecoder::MockImageDecoder):
(WebCore::MockImageDecoder::filenameExtension):
(WebCore::MockImageDecoder::frameBufferAtIndex):
(WebCore::MockImageDecoder::frameBufferRequestCount):

Tools:

Add --enable-deferred-image-decoding to DRT.

* DumpRenderTree/chromium/DumpRenderTree.cpp:
(main):
* DumpRenderTree/chromium/TestShell.cpp:
(TestShell::TestShell):
(TestShell::resetWebSettings):
* DumpRenderTree/chromium/TestShell.h:
(TestShell::setDeferredImageDecodingEnabled):
(TestShell):
* DumpRenderTree/chromium/WebPreferences.cpp:
(WebPreferences::reset):
(WebPreferences::applyTo):
* DumpRenderTree/chromium/WebPreferences.h:
(WebPreferences):
* Scripts/webkitpy/layout_tests/port/chromium.py:
(ChromiumPort.virtual_test_suites):

LayoutTests:

Adding a virtual test suite for Chromium to test deferred image
decoding.

platform/chromium/virtual/deferred/fast/images will be tested with
--force-compositing --enable-per-tile-painting --enable-deferred-image-decoding.

* platform/chromium/virtual/deferred/fast/images/README.txt: Added.

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

34 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium/TestExpectations
LayoutTests/platform/chromium/virtual/deferred/fast/images/README.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/ImageSource.cpp
Source/WebCore/platform/graphics/ImageSource.h
Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ImageDecodingStore.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ImageDecodingStore.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ScaledImageFragment.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ScaledImageFragment.h [new file with mode: 0644]
Source/WebCore/platform/graphics/skia/NativeImageSkia.cpp
Source/WebCore/platform/image-decoders/ImageDecoder.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/public/WebSettings.h
Source/WebKit/chromium/src/WebKit.cpp
Source/WebKit/chromium/src/WebSettingsImpl.cpp
Source/WebKit/chromium/src/WebSettingsImpl.h
Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/MockImageDecoder.h [new file with mode: 0644]
Tools/ChangeLog
Tools/DumpRenderTree/chromium/DumpRenderTree.cpp
Tools/DumpRenderTree/chromium/TestShell.cpp
Tools/DumpRenderTree/chromium/TestShell.h
Tools/DumpRenderTree/chromium/WebPreferences.cpp
Tools/DumpRenderTree/chromium/WebPreferences.h
Tools/Scripts/webkitpy/layout_tests/port/chromium.py

index 4874de7c52cd3aef1c3dfbeb1996ff44b8350caf..e2ca6e39418ab70a343cf1881152a3c2c0570dfe 100644 (file)
@@ -1,3 +1,18 @@
+2012-10-18  Alpha Lam  <hclam@chromium.org>
+
+        [chromium] Implement deferred image decoding
+        https://bugs.webkit.org/show_bug.cgi?id=94240
+
+        Reviewed by Stephen White.
+
+        Adding a virtual test suite for Chromium to test deferred image
+        decoding.
+
+        platform/chromium/virtual/deferred/fast/images will be tested with
+        --force-compositing --enable-per-tile-painting --enable-deferred-image-decoding.
+
+        * platform/chromium/virtual/deferred/fast/images/README.txt: Added.
+
 2012-10-18  Max Vujovic  <mvujovic@adobe.com>
 
         [CSS Shaders] Validate types of built-in vertex attributes
index 0fc2b443dff0ce54f77325b77464737f7bc36c88..63e59fbb271c80c7640bbd658474a42ba6d7f636 100644 (file)
@@ -4233,3 +4233,28 @@ webkit.org/b/84893 http/tests/w3c/webperf/submission/Intel/user-timing [ Skip ]
 # Expected to fail until WebGL extension implementation lands
 webkit.org/b/98257 fast/canvas/webgl/oes-element-index-uint.html [ Failure Pass ]
 webkit.org/b/98257 platform/chromium/virtual/gpu/fast/canvas/webgl/oes-element-index-uint.html [ Failure Pass ]
+
+# These tests are failing already and because of virtual test suite for deferred
+# image decoding they need to be suppressed again.
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/animated-gif-restored-from-bfcache.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/exif-orientation-css.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/exif-orientation.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/pdf-as-image-landscape.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/pdf-as-image.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/support-broken-image-delegate.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/color-jpeg-with-color-profile.html [ ImageOnlyFailure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/gif-large-checkerboard.html [ ImageOnlyFailure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/gif-loop-count.html [ ImageOnlyFailure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/paint-subrect-grid.html [ ImageOnlyFailure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/pixel-crack-image-background-webkit-transform-scale.html [ ImageOnlyFailure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/embed-image.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/favicon-as-image.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-circle-focus-ring.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-focus-ring-outline-color-explicitly-inherited-from-map.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-focus-ring-outline-color-not-inherited-from-map.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-focus-ring-outline-color.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-polygon-focus-ring.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/object-image.html [ Failure ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/repaint-subrect-grid.html [ Timeout ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/paletted-png-with-color-profile.html [ Missing ]
+webkit.org/b/94240 platform/chromium/virtual/deferred/fast/images/imagemap-focus-ring-zoom.html [ Failure ]
diff --git a/LayoutTests/platform/chromium/virtual/deferred/fast/images/README.txt b/LayoutTests/platform/chromium/virtual/deferred/fast/images/README.txt
new file mode 100644 (file)
index 0000000..bf882eb
--- /dev/null
@@ -0,0 +1,2 @@
+# Test suites in this directory test the 'deferred image decoding' code path
+# through Chromium DRT.
index 93f6bbe54ab332fd60b7af398ac876cd838ff806..0887f59b2f8689f44a16e3c4cc1ef9cc001912a3 100755 (executable)
@@ -1,3 +1,204 @@
+2012-10-18  Alpha Lam  <hclam@chromium.org>
+
+        [chromium] Implement deferred image decoding
+        https://bugs.webkit.org/show_bug.cgi?id=94240
+
+        Reviewed by Stephen White.
+
+        Objectives:
+
+        To record image decoding operations during painting and to defer
+        decoding operations until rasterization.
+
+        Rationale:
+
+        This is a key feature that enables impl-side painting which requires
+        fast recording of drawing operations. The existing decode-on-draw
+        restricts that recording has to block on expensive decoding operations.
+        This change allows recording of image decoding operations during paint
+        time.
+
+        Design:
+
+        Image decoding happens when a BitmapImage is drawn into a
+        GraphicsContext. When per-tile painting is enabled GraphicsContext
+        is backed by SkCanvas in recording mode. This SkCanvas records drawing
+        and image decoding operations to minimize recording time.
+
+        An image decoding operation is recorded as a SkPixelRef object
+        implemented by LazyDecodingPixelRef. This object references raw encoded
+        data, regions to be decoded and scaling information.
+
+        When used in conjunction with per-tile painting this feature defers
+        image decoding until the SkCanvas referencing the image is rasterized.
+
+        Both recording and rasterization happen on the main thread.
+
+        Performance Impact:
+
+        This feature is enabled by WebKit::setDeferredImageDecodingEnabled()
+        and does not have an impact when disabled.
+
+        This feature is disabled by default.
+
+        Upcoming Changes:
+
+        1. Implement a full-featured image cache in ImageDecodingStore.
+        2. Allow rasterization and decoding on impl thread.
+
+        Classes Involved:
+
+        BitmapImage
+
+        BitmapImage is the entry point for deferred image decoding. When
+        drawing a BitmapImage into a GraphicsContext it makes a request to
+        create a NativeImageSkia. We substitute the content in NativeImageSkia
+        such that it is lazily decoded.
+
+        DeferredImageDecoder
+
+        This is the platform implementation of a image decoder for Chromium.
+        This is a bridge layer that either delegates calls to the actual
+        ImageDecoder or create a lazily-decoded SkBitmap and delegates calls
+        to ImageDecodingStore.
+
+        ImageDecodingStore
+
+        This object manages all encoded images. It keeps track of encoded
+        data and the corresponding ImageDecoder for doing actual decoding. It
+        is also responsible for generating lazily decoded SkBitmaps. This
+        SkBitmap contains a LazyDecodingPixelRef object which references to an
+        image entry in ImageDecodingStore.
+
+        ScaledImageFragment
+
+        A container for a scaled image fragment. In addition to bitmap pixels
+        it contains information about the ID of the image, scale and clipping.
+
+        ImageFrameGenerator
+
+        This object is responsible for generating decoded pixels. It is also
+        a container for encoded image data and corresponding image decoder.
+
+        LazyDecodingPixelRef
+
+        This object is embedded in a SkBitmap to enable lazy decoding. When
+        SkBitmap needs to access pixels LazyDecodingPixelRef is locked. It
+        contains information to locate an image and scaling info, these
+        information is submitted to ImageDecodingStore to access actual pixels.
+
+        Layout tests. There are about 80 tests in this virtual test suite
+        running this feature in this directory:
+
+        platform/chromium/virtual/deferred/fast/images
+
+        Unit tests. Added DeferredImageDecoderTest to verify deferred
+        image decoding behavior.
+
+        * WebCore.gypi:
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::setData):
+        * platform/graphics/ImageSource.h:
+        (WebCore):
+        (ImageSource):
+        * platform/graphics/chromium/DeferredImageDecoder.cpp: Added.
+        (WebCore):
+        (WebCore::DeferredImageDecoder::DeferredImageDecoder):
+        (WebCore::DeferredImageDecoder::~DeferredImageDecoder):
+        (WebCore::DeferredImageDecoder::create):
+        (WebCore::DeferredImageDecoder::createForTesting):
+        (WebCore::DeferredImageDecoder::filenameExtension):
+        (WebCore::DeferredImageDecoder::frameBufferAtIndex):
+        (WebCore::DeferredImageDecoder::setData):
+        (WebCore::DeferredImageDecoder::isSizeAvailable):
+        (WebCore::DeferredImageDecoder::size):
+        (WebCore::DeferredImageDecoder::frameSizeAtIndex):
+        (WebCore::DeferredImageDecoder::frameCount):
+        (WebCore::DeferredImageDecoder::repetitionCount):
+        (WebCore::DeferredImageDecoder::clearFrameBufferCache):
+        (WebCore::DeferredImageDecoder::frameHasAlphaAtIndex):
+        (WebCore::DeferredImageDecoder::frameBytesAtIndex):
+        * platform/graphics/chromium/DeferredImageDecoder.h: Added.
+        (WebCore):
+        (DeferredImageDecoder):
+        * platform/graphics/chromium/ImageDecodingStore.cpp: Added.
+        (WebCore::ImageDecodingStore::ImageDecodingStore):
+        (WebCore):
+        (WebCore::ImageDecodingStore::~ImageDecodingStore):
+        (WebCore::ImageDecodingStore::instanceOnMainThread):
+        (WebCore::ImageDecodingStore::initializeOnMainThread):
+        (WebCore::ImageDecodingStore::shutdown):
+        (WebCore::ImageDecodingStore::isLazyDecoded):
+        (WebCore::ImageDecodingStore::createLazyDecodedSkBitmap):
+        (WebCore::ImageDecodingStore::resizeLazyDecodedSkBitmap):
+        (WebCore::ImageDecodingStore::setData):
+        (WebCore::ImageDecodingStore::lockPixels):
+        (WebCore::ImageDecodingStore::unlockPixels):
+        (WebCore::ImageDecodingStore::frameGeneratorBeingDestroyed):
+        (WebCore::ImageDecodingStore::calledOnValidThread):
+        (WebCore::ImageDecodingStore::lookupFrameCache):
+        (WebCore::ImageDecodingStore::deleteFrameCache):
+        * platform/graphics/chromium/ImageDecodingStore.h: Added.
+        (WebCore):
+        (ImageDecodingStore):
+        (WebCore::ImageDecodingStore::create):
+        * platform/graphics/chromium/ScaledImageFragment.cpp: Added.
+        (WebCore):
+        (WebCore::ScaledImageFragment::~ScaledImageFragment):
+        (WebCore::ScaledImageFragment::ScaledImageFragment):
+        (WebCore::ScaledImageFragment::isEqual):
+        * platform/graphics/chromium/ScaledImageFragment.h: Added.
+        (WebCore):
+        (ScaledImageFragment):
+        (WebCore::ScaledImageFragment::create):
+        (WebCore::ScaledImageFragment::bitmap):
+        (WebCore::ScaledImageFragment::isComplete):
+        * platform/graphics/chromium/ImageFrameGenerator.cpp: Added.
+        (WebCore):
+        (WebCore::ImageFrameGenerator::ImageFrameGenerator):
+        (WebCore::ImageFrameGenerator::~ImageFrameGenerator):
+        (WebCore::ImageFrameGenerator::decoder):
+        (WebCore::ImageFrameGenerator::setData):
+        * platform/graphics/chromium/ImageFrameGenerator.h: Added.
+        (WebCore):
+        (ImageFrameGenerator):
+        (WebCore::ImageFrameGenerator::create):
+        (WebCore::ImageFrameGenerator::size):
+        (WebCore::ImageFrameGenerator::imageId):
+        * platform/graphics/chromium/LazyDecodingPixelRef.cpp: Added.
+        (WebCore):
+        (WebCore::LazyDecodingPixelRef::LazyDecodingPixelRef):
+        (WebCore::LazyDecodingPixelRef::~LazyDecodingPixelRef):
+        (WebCore::LazyDecodingPixelRef::isScaled):
+        (WebCore::LazyDecodingPixelRef::isClipped):
+        (WebCore::LazyDecodingPixelRef::onLockPixels):
+        (WebCore::LazyDecodingPixelRef::onUnlockPixels):
+        (WebCore::LazyDecodingPixelRef::onLockPixelsAreWritable):
+        * platform/graphics/chromium/LazyDecodingPixelRef.h: Added.
+        (WebCore):
+        (LazyDecodingPixelRef):
+        (WebCore::LazyDecodingPixelRef::frameGenerator):
+        * platform/graphics/skia/NativeImageSkia.cpp:
+        (WebCore::NativeImageSkia::resizedBitmap):
+        * platform/image-decoders/ImageDecoder.h:
+        (ImageFrame):
+        (WebCore::ImageFrame::setSkBitmap):
+        (WebCore::ImageFrame::getSkBitmap):
+
+2012-10-18  Yael Aharon  <yael.aharon@intel.com>
+
+        [EFL] GraphicsContext3D::m_renderStyle is not initialized
+        https://bugs.webkit.org/show_bug.cgi?id=99721
+
+        Reviewed by Antonio Gomes.
+
+        Initialize GraphicsContext3D::m_renderStyle.
+
+        No new tests, no new functionality.
+
+        * platform/graphics/efl/GraphicsContext3DEfl.cpp:
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+
 2012-10-18  Max Vujovic  <mvujovic@adobe.com>
 
         [CSS Shaders] Validate types of built-in vertex attributes
index 9019604dce8adcef98cd63bccfae914b4a15d376..48a1dcb3f5ca84241109400fff94ccb21326a704 100644 (file)
             'platform/graphics/chromium/CompositorHUDFontAtlas.h',
             'platform/graphics/chromium/CrossProcessFontLoading.h',
             'platform/graphics/chromium/CrossProcessFontLoading.mm',
+            'platform/graphics/chromium/DeferredImageDecoder.cpp',
+            'platform/graphics/chromium/DeferredImageDecoder.h',
             'platform/graphics/chromium/DrawingBufferChromium.cpp',
             'platform/graphics/chromium/Extensions3DChromium.h',
             'platform/graphics/chromium/FontCacheAndroid.cpp',
             'platform/graphics/chromium/IconChromiumAndroid.cpp',
             'platform/graphics/chromium/ImageBufferDataSkia.h',
             'platform/graphics/chromium/ImageChromium.cpp',
+            'platform/graphics/chromium/ImageDecodingStore.cpp',
+            'platform/graphics/chromium/ImageDecodingStore.h',
+            'platform/graphics/chromium/ImageFrameGenerator.cpp',
+            'platform/graphics/chromium/ImageFrameGenerator.h',
+            'platform/graphics/chromium/LazyDecodingPixelRef.cpp',
+            'platform/graphics/chromium/LazyDecodingPixelRef.h',
             'platform/graphics/chromium/MediaPlayerPrivateChromium.h',
             'platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp',
             'platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h',
             'platform/graphics/chromium/PlatformIcon.h',
+            'platform/graphics/chromium/ScaledImageFragment.cpp',
+            'platform/graphics/chromium/ScaledImageFragment.h',
             'platform/graphics/chromium/SimpleFontDataChromiumWin.cpp',
             'platform/graphics/chromium/TransparencyWin.cpp',
             'platform/graphics/chromium/TransparencyWin.h',
index 82dfde1c9dd82e315bbdd9ee89cd0823c9cc8e4d..abfa5988b42bc690f7eabc953eeb07d053003c4c 100644 (file)
 #include "NotImplemented.h"
 #include "PlatformMemoryInstrumentation.h"
 
+#if PLATFORM(CHROMIUM)
+#include "DeferredImageDecoder.h"
+#endif
+
 namespace WebCore {
 
 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
@@ -79,7 +83,7 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
     // If insufficient bytes are available to determine the image type, no decoder plugin will be
     // made.
     if (!m_decoder) {
-        m_decoder = static_cast<NativeImageSourcePtr>(ImageDecoder::create(*data, m_alphaOption, m_gammaAndColorProfileOption));
+        m_decoder = static_cast<NativeImageDecoderPtr>(NativeImageDecoder::create(*data, m_alphaOption, m_gammaAndColorProfileOption));
 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
         if (m_decoder && s_maxPixelsPerDecodedImage)
             m_decoder->setMaxNumPixels(s_maxPixelsPerDecodedImage);
index 0d8a01e26a72cfff39aa4654374144a0a179ac38..66a8a0a51c39fb9268b221a47b687501593bc4a3 100644 (file)
@@ -47,10 +47,20 @@ class IntSize;
 class SharedBuffer;
 
 #if USE(CG)
-typedef CGImageSourceRef NativeImageSourcePtr;
-#else
+typedef CGImageSourceRef NativeImageDecoderPtr;
+#elif !PLATFORM(CHROMIUM)
 class ImageDecoder;
-typedef ImageDecoder* NativeImageSourcePtr;
+typedef ImageDecoder* NativeImageDecoderPtr;
+#endif
+
+#if PLATFORM(CHROMIUM)
+class DeferredImageDecoder;
+typedef DeferredImageDecoder NativeImageDecoder;
+typedef DeferredImageDecoder* NativeImageDecoderPtr;
+#elif USE(CG)
+#define NativeImageDecoder ImageDecoder
+#else
+typedef ImageDecoder NativeImageDecoder;
 #endif
 
 // Right now GIFs are the only recognized image format that supports animation.
@@ -158,7 +168,7 @@ public:
     void reportMemoryUsage(MemoryObjectInfo*) const;
 
 private:
-    NativeImageSourcePtr m_decoder;
+    NativeImageDecoderPtr m_decoder;
 
 #if !USE(CG)
     AlphaOption m_alphaOption;
diff --git a/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.cpp b/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.cpp
new file mode 100644 (file)
index 0000000..7574196
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DeferredImageDecoder.h"
+
+#include "ImageDecodingStore.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+DeferredImageDecoder::DeferredImageDecoder(ImageDecoder* actualDecoder)
+    : m_allDataReceived(false)
+    , m_actualDecoder(adoptPtr(actualDecoder))
+{
+}
+
+DeferredImageDecoder::~DeferredImageDecoder()
+{
+    // FIXME: Remove the corresponding entry in ImageDecodingStore if image
+    // is defer-decoded.
+}
+
+DeferredImageDecoder* DeferredImageDecoder::create(const SharedBuffer& data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorOption)
+{
+    ImageDecoder* actualDecoder = ImageDecoder::create(data, alphaOption, gammaAndColorOption);
+    return actualDecoder ? new DeferredImageDecoder(actualDecoder) : 0;
+}
+
+PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnPtr<ImageDecoder> decoder)
+{
+    return adoptPtr(new DeferredImageDecoder(decoder.leakPtr()));
+}
+
+String DeferredImageDecoder::filenameExtension() const
+{
+    return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameExtension;
+}
+
+ImageFrame* DeferredImageDecoder::frameBufferAtIndex(size_t index)
+{
+    // Only defer image decoding if this is a single frame image. The reason is
+    // because a multiframe is usually animated GIF. Animation is handled by
+    // BitmapImage which uses some metadata functions that do synchronous image
+    // decoding.
+    if (ImageDecodingStore::instanceOnMainThread()
+        && m_actualDecoder
+        && m_actualDecoder->repetitionCount() == cAnimationNone
+        && m_actualDecoder->isSizeAvailable()) {
+
+        m_size = m_actualDecoder->size();
+        m_filenameExtension = m_actualDecoder->filenameExtension();
+
+        SkBitmap lazyDecodedSkBitmap = ImageDecodingStore::instanceOnMainThread()->createLazyDecodedSkBitmap(m_actualDecoder.release());
+        m_lazyDecodedFrame.setSkBitmap(lazyDecodedSkBitmap);
+        ImageDecodingStore::instanceOnMainThread()->setData(m_lazyDecodedFrame.getSkBitmap(), m_data.release(), m_allDataReceived);
+
+        // Don't mark the frame as completely decoded until the underlying
+        // decoder has really decoded it. Until then, our data and metadata may
+        // be incorrect, so callers can't rely on them.
+        m_lazyDecodedFrame.setStatus(ImageFrame::FramePartial);
+    }
+
+    return m_actualDecoder ? m_actualDecoder->frameBufferAtIndex(index) : &m_lazyDecodedFrame;
+}
+
+void DeferredImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
+{
+    if (m_actualDecoder) {
+        // Keep a reference to data until image decoding is deferred.
+        // When image decoding is deferred then ownership of m_data is
+        // transferred to ImageDecodingStore.
+        m_data = data;
+        m_allDataReceived = allDataReceived;
+        m_actualDecoder->setData(data, allDataReceived);
+    } else {
+        ASSERT(!m_data);
+        ImageDecodingStore::instanceOnMainThread()->setData(m_lazyDecodedFrame.getSkBitmap(), data, allDataReceived);
+    }
+}
+
+bool DeferredImageDecoder::isSizeAvailable()
+{
+    // m_actualDecoder is 0 only if image decoding is deferred and that
+    // means image header decoded successfully and size is available.
+    return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true;
+}
+
+IntSize DeferredImageDecoder::size() const
+{
+    return m_actualDecoder ? m_actualDecoder->size() : m_size;
+}
+
+IntSize DeferredImageDecoder::frameSizeAtIndex(size_t index) const
+{
+    return m_actualDecoder ? m_actualDecoder->frameSizeAtIndex(index) : m_size;
+}
+
+size_t DeferredImageDecoder::frameCount()
+{
+    return m_actualDecoder ? m_actualDecoder->frameCount() : 1;
+}
+
+int DeferredImageDecoder::repetitionCount() const
+{
+    return m_actualDecoder ? m_actualDecoder->repetitionCount() : cAnimationNone;
+}
+
+void DeferredImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
+{
+    // If image decoding is deferred then frame buffer cache is managed by
+    // the compositor and this call is ignored.
+    if (m_actualDecoder)
+        m_actualDecoder->clearFrameBufferCache(clearBeforeFrame);
+}
+
+bool DeferredImageDecoder::frameHasAlphaAtIndex(size_t index) const
+{
+    // FIXME: Synchronize this state with ImageDecodingStore when image is
+    // actually decoded. Return true here is correct in terms of rendering but
+    // may not go through some optimized rendering code path.
+    return m_actualDecoder ? m_actualDecoder->frameHasAlphaAtIndex(index) : true;
+}
+
+unsigned DeferredImageDecoder::frameBytesAtIndex(size_t index) const
+{
+    // If frame decoding is deferred then it is not managed by MemoryCache
+    // so return 0 here.
+    return m_actualDecoder ? m_actualDecoder->frameBytesAtIndex(index) : 0;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.h b/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.h
new file mode 100644 (file)
index 0000000..6b33fe3
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DeferredImageDecoder_h
+#define DeferredImageDecoder_h
+
+#include "ImageDecoder.h"
+#include "ImageSource.h"
+#include "IntSize.h"
+#include "SkBitmap.h"
+
+namespace WebCore {
+
+class SharedBuffer;
+
+class DeferredImageDecoder {
+public:
+    ~DeferredImageDecoder();
+    static DeferredImageDecoder* create(const SharedBuffer& data, ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption);
+
+    static PassOwnPtr<DeferredImageDecoder> createForTesting(PassOwnPtr<ImageDecoder>);
+
+    String filenameExtension() const;
+
+    ImageFrame* frameBufferAtIndex(size_t index);
+
+    void setData(SharedBuffer* data, bool allDataReceived);
+
+    bool isSizeAvailable();
+    IntSize size() const;
+    IntSize frameSizeAtIndex(size_t index) const;
+    size_t frameCount();
+    int repetitionCount() const;
+    void clearFrameBufferCache(size_t);
+    bool frameHasAlphaAtIndex(size_t index) const;
+    unsigned frameBytesAtIndex(size_t index) const;
+
+private:
+    explicit DeferredImageDecoder(ImageDecoder* actualDecoder);
+
+    RefPtr<SharedBuffer> m_data;
+    bool m_allDataReceived;
+    OwnPtr<ImageDecoder> m_actualDecoder;
+
+    String m_filenameExtension;
+    IntSize m_size;
+
+    ImageFrame m_lazyDecodedFrame;
+};
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/ImageDecodingStore.cpp b/Source/WebCore/platform/graphics/chromium/ImageDecodingStore.cpp
new file mode 100644 (file)
index 0000000..02790df
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImageDecodingStore.h"
+
+#include "ImageDecoder.h"
+#include "ImageFrameGenerator.h"
+#include "LazyDecodingPixelRef.h"
+#include "ScaledImageFragment.h"
+#include "SkRect.h"
+#include "SkSize.h"
+
+#include "skia/ext/image_operations.h"
+
+#include <wtf/MainThread.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+namespace {
+
+// URI label for a lazily decoded SkPixelRef.
+const char labelLazyDecoded[] = "lazy";
+
+ImageDecodingStore* s_instanceOnMainThread = 0;
+
+static void setInstanceOnMainThread(ImageDecodingStore* imageDecodingStore)
+{
+    delete s_instanceOnMainThread;
+    s_instanceOnMainThread = imageDecodingStore;
+}
+} // namespace
+
+ImageDecodingStore::ImageDecodingStore()
+{
+}
+
+ImageDecodingStore::~ImageDecodingStore()
+{
+}
+
+ImageDecodingStore* ImageDecodingStore::instanceOnMainThread()
+{
+    ASSERT(isMainThread());
+    return s_instanceOnMainThread;
+}
+
+void ImageDecodingStore::initializeOnMainThread()
+{
+    ASSERT(isMainThread());
+    setInstanceOnMainThread(ImageDecodingStore::create().leakPtr());
+}
+
+void ImageDecodingStore::shutdown()
+{
+    ASSERT(isMainThread());
+    setInstanceOnMainThread(0);
+}
+
+bool ImageDecodingStore::isLazyDecoded(const SkBitmap& bitmap)
+{
+    return bitmap.pixelRef()
+        && bitmap.pixelRef()->getURI()
+        && !memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelLazyDecoded));
+}
+
+SkBitmap ImageDecodingStore::createLazyDecodedSkBitmap(PassOwnPtr<ImageDecoder> decoder)
+{
+    ASSERT(calledOnValidThread());
+
+    SkISize fullSize = SkISize::Make(decoder->size().width(), decoder->size().height());
+    ASSERT(!fullSize.isEmpty());
+
+    SkIRect fullRect = SkIRect::MakeSize(fullSize);
+
+    // Creates a lazily decoded SkPixelRef that references the entire image without scaling.
+    SkBitmap bitmap;
+    bitmap.setConfig(SkBitmap::kARGB_8888_Config, fullSize.width(), fullSize.height());
+    bitmap.setPixelRef(new LazyDecodingPixelRef(ImageFrameGenerator::create(decoder), fullSize, fullRect))->unref();
+
+    // Use URI to identify this is a lazily decoded SkPixelRef of type LazyDecodingPixelRef.
+    // FIXME: Give the actual URI is more useful.
+    bitmap.pixelRef()->setURI(labelLazyDecoded);
+
+    // Inform the bitmap that we will never change the pixels. This is a performance hint
+    // subsystems that may try to cache this bitmap (e.g. pictures, pipes, gpu, pdf, etc.)
+    bitmap.setImmutable();
+
+    // FIXME: Setting bitmap.setIsOpaque() is big performance gain if possible. We can
+    // do so safely if the image is fully loaded and it is a JPEG image, or image was
+    // decoded before.
+
+    return bitmap;
+}
+
+SkBitmap ImageDecodingStore::resizeLazyDecodedSkBitmap(const SkBitmap& bitmap, const SkISize& scaledSize, const SkIRect& scaledSubset)
+{
+    ASSERT(calledOnValidThread());
+
+    LazyDecodingPixelRef* pixelRef = static_cast<LazyDecodingPixelRef*>(bitmap.pixelRef());
+    ASSERT(!pixelRef->isScaled(pixelRef->frameGenerator()->fullSize()) && !pixelRef->isClipped());
+
+    int rowBytes = 0;
+    rowBytes = SkBitmap::ComputeRowBytes(SkBitmap::kARGB_8888_Config, scaledSize.width());
+
+    SkBitmap resizedBitmap;
+    resizedBitmap.setConfig(SkBitmap::kARGB_8888_Config, scaledSubset.width(), scaledSubset.height(), rowBytes);
+    resizedBitmap.setPixelRef(new LazyDecodingPixelRef(pixelRef->frameGenerator(), scaledSize, scaledSubset))->unref();
+
+    // See comments in createLazyDecodedSkBitmap().
+    resizedBitmap.setImmutable();
+    return resizedBitmap;
+}
+
+void ImageDecodingStore::setData(const SkBitmap& bitmap, PassRefPtr<SharedBuffer> data, bool allDataReceived)
+{
+    ASSERT(calledOnValidThread());
+    if (isLazyDecoded(bitmap))
+        static_cast<LazyDecodingPixelRef*>(bitmap.pixelRef())->frameGenerator()->setData(data, allDataReceived);
+}
+
+void* ImageDecodingStore::lockPixels(PassRefPtr<ImageFrameGenerator> frameGenerator, const SkISize& scaledSize, const SkIRect& scaledSubset)
+{
+    ASSERT(calledOnValidThread());
+    ASSERT(m_lockedSkBitmap.isNull());
+
+    SkISize fullSize = frameGenerator->fullSize();
+
+    // The cache only saves the full size image at the moment.
+    ScaledImageFragment* frameCache = lookupFrameCache(frameGenerator->imageId(), fullSize);
+    SkBitmap bitmap;
+
+    if (!frameCache) {
+        // FIXME: Pixels are owned by the ImageDecoder in the generator. Find
+        // a way to transfer ownership to our cache.
+        ImageFrame* frame = frameGenerator->decoder()->frameBufferAtIndex(0);
+
+        // Saves the frame in cache if this is complete.
+        if (frame->status() == ImageFrame::FrameComplete) {
+            m_frameCache.append(ScaledImageFragment::create(frameGenerator->imageId(), fullSize, frame->getSkBitmap(), true));
+        } else if (frame->status() == ImageFrame::FrameEmpty) {
+            // FIXME: If this is a decoding error. Report this to BitmapImage.
+            return 0;
+        }
+
+        bitmap = frame->getSkBitmap();
+    } else {
+        ASSERT(frameCache->isComplete());
+        bitmap = frameCache->bitmap();
+    }
+
+    if (fullSize != scaledSize) {
+        // Image scaling is done on-the-fly and scaled image is destroyed
+        // after use.
+        // FIXME: Resize just the requested fragment.
+        m_lockedSkBitmap = skia::ImageOperations::Resize(bitmap, skia::ImageOperations::RESIZE_LANCZOS3, scaledSize.width(), scaledSize.height());
+    } else
+        m_lockedSkBitmap = bitmap;
+    m_lockedSkBitmap.lockPixels();
+    return m_lockedSkBitmap.getAddr(scaledSubset.x(), scaledSubset.y());
+}
+
+void ImageDecodingStore::unlockPixels()
+{
+    ASSERT(calledOnValidThread());
+
+    m_lockedSkBitmap.unlockPixels();
+    m_lockedSkBitmap.reset();
+}
+
+void ImageDecodingStore::frameGeneratorBeingDestroyed(ImageFrameGenerator* frameGenerator)
+{
+    ASSERT(calledOnValidThread());
+
+    deleteFrameCache(frameGenerator->imageId());
+}
+
+bool ImageDecodingStore::calledOnValidThread() const
+{
+    return this == instanceOnMainThread() && isMainThread();
+}
+
+ScaledImageFragment* ImageDecodingStore::lookupFrameCache(int imageId, const SkISize& scaledSize) const
+{
+    for (size_t i = 0; i < m_frameCache.size(); ++i) {
+        if (m_frameCache[i]->isEqual(imageId, scaledSize))
+            return m_frameCache[i].get();
+    }
+    return 0;
+}
+
+void ImageDecodingStore::deleteFrameCache(int imageId)
+{
+    for (size_t i = 0; i < m_frameCache.size(); ++i) {
+        if (m_frameCache[i]->isEqual(imageId)) {
+            m_frameCache.remove(i);
+            return;
+        }
+    }
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/chromium/ImageDecodingStore.h b/Source/WebCore/platform/graphics/chromium/ImageDecodingStore.h
new file mode 100644 (file)
index 0000000..a6a5d92
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ImageDecodingStore_h
+#define ImageDecodingStore_h
+
+#include "SkBitmap.h"
+#include "SkRect.h"
+#include "SkSize.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class ImageDecoder;
+class ImageFrameGenerator;
+class ScaledImageFragment;
+class SharedBuffer;
+
+// This class can only be instantiated on main thread. There will be an
+// instance on impl thread in the future but that part of implementation
+// is incomplete. See bug: https://bugs.webkit.org/show_bug.cgi?id=94240
+// for details.
+class ImageDecodingStore {
+public:
+    static PassOwnPtr<ImageDecodingStore> create() { return adoptPtr(new ImageDecodingStore); }
+    ~ImageDecodingStore();
+
+    static ImageDecodingStore* instanceOnMainThread();
+    static void initializeOnMainThread();
+    static void shutdown();
+    static bool isLazyDecoded(const SkBitmap&);
+
+    SkBitmap createLazyDecodedSkBitmap(PassOwnPtr<ImageDecoder>);
+    SkBitmap resizeLazyDecodedSkBitmap(const SkBitmap&, const SkISize& scaledSize, const SkIRect& scaledSubset);
+
+    void setData(const SkBitmap&, PassRefPtr<SharedBuffer>, bool allDataReceived);
+
+    // You may only lock one set of pixels at a time; overlapping lock calls are not allowed.
+    void* lockPixels(PassRefPtr<ImageFrameGenerator>, const SkISize& scaledSize, const SkIRect& scaledSubset);
+    void unlockPixels();
+
+    void frameGeneratorBeingDestroyed(ImageFrameGenerator*);
+
+private:
+    ImageDecodingStore();
+    bool calledOnValidThread() const;
+    void createFrameGenerator(PassOwnPtr<ImageDecoder>);
+    ScaledImageFragment* lookupFrameCache(int imageId, const SkISize& scaledSize) const;
+    void deleteFrameCache(int imageId);
+
+    Vector<OwnPtr<ScaledImageFragment> > m_frameCache;
+
+    SkBitmap m_lockedSkBitmap;
+};
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.cpp b/Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.cpp
new file mode 100644 (file)
index 0000000..4c2f299
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "ImageFrameGenerator.h"
+
+#include "ImageDecoder.h"
+#include "ImageDecodingStore.h"
+#include "SharedBuffer.h"
+
+namespace {
+
+// An unique ID for an image file.
+int s_nextImageId = 0;
+
+} // namespace
+
+namespace WebCore {
+
+ImageFrameGenerator::ImageFrameGenerator(PassOwnPtr<ImageDecoder> decoder)
+    : m_decoder(decoder)
+{
+    m_fullSize = SkISize::Make(m_decoder->size().width(), m_decoder->size().height());
+    m_imageId = s_nextImageId++;
+}
+
+ImageFrameGenerator::~ImageFrameGenerator()
+{
+    if (ImageDecodingStore::instanceOnMainThread())
+        ImageDecodingStore::instanceOnMainThread()->frameGeneratorBeingDestroyed(this);
+}
+
+ImageDecoder* ImageFrameGenerator::decoder()
+{
+    return m_decoder.get();
+}
+
+void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataReceived)
+{
+    m_data = data;
+    if (m_decoder)
+        m_decoder->setData(m_data.get(), allDataReceived);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.h b/Source/WebCore/platform/graphics/chromium/ImageFrameGenerator.h
new file mode 100644 (file)
index 0000000..b9cd72b
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ImageFrameGenerator_h
+#define ImageFrameGenerator_h
+
+#include "SkSize.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class ImageDecoder;
+class SharedBuffer;
+
+class ImageFrameGenerator : public RefCounted<ImageFrameGenerator> {
+public:
+    static PassRefPtr<ImageFrameGenerator> create(PassOwnPtr<ImageDecoder> decoder)
+    {
+        return adoptRef(new ImageFrameGenerator(decoder));
+    }
+
+    explicit ImageFrameGenerator(PassOwnPtr<ImageDecoder>);
+    ~ImageFrameGenerator();
+
+    // Creates the image decoder if needed.
+    ImageDecoder* decoder();
+    void setData(PassRefPtr<SharedBuffer>, bool allDataReceived);
+
+    const SkISize& fullSize() const { return m_fullSize; }
+    int imageId() const { return m_imageId; }
+
+private:
+    OwnPtr<ImageDecoder> m_decoder;
+    RefPtr<SharedBuffer> m_data;
+    SkISize m_fullSize;
+    int m_imageId;
+};
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.cpp b/Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.cpp
new file mode 100644 (file)
index 0000000..56dd091
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LazyDecodingPixelRef.h"
+
+#include "ImageDecoder.h"
+#include "ImageDecodingStore.h"
+#include "ImageFrameGenerator.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+LazyDecodingPixelRef::LazyDecodingPixelRef(PassRefPtr<ImageFrameGenerator> frameGenerator, const SkISize& scaledSize, const SkIRect& scaledSubset)
+    : SkPixelRef(0)
+    , m_frameGenerator(frameGenerator)
+    , m_scaledSize(scaledSize)
+    , m_scaledSubset(scaledSubset)
+{
+}
+
+LazyDecodingPixelRef::~LazyDecodingPixelRef()
+{
+}
+
+bool LazyDecodingPixelRef::isScaled(const SkISize& fullSize) const
+{
+    return fullSize != m_scaledSize;
+}
+
+bool LazyDecodingPixelRef::isClipped() const
+{
+    return m_scaledSize.width() != m_scaledSubset.width() || m_scaledSize.height() != m_scaledSubset.height();
+}
+
+void* LazyDecodingPixelRef::onLockPixels(SkColorTable**)
+{
+    ASSERT(isMainThread());
+    return ImageDecodingStore::instanceOnMainThread()->lockPixels(m_frameGenerator, m_scaledSize, m_scaledSubset);
+}
+
+void LazyDecodingPixelRef::onUnlockPixels()
+{
+    ASSERT(isMainThread());
+    ImageDecodingStore::instanceOnMainThread()->unlockPixels();
+}
+
+bool LazyDecodingPixelRef::onLockPixelsAreWritable() const
+{
+    return false;
+}
+
+} // namespace WebKit
diff --git a/Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.h b/Source/WebCore/platform/graphics/chromium/LazyDecodingPixelRef.h
new file mode 100644 (file)
index 0000000..0ab9ccc
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LazyDecodingPixelRef_h
+#define LazyDecodingPixelRef_h
+
+#include "SkFlattenableBuffers.h"
+#include "SkPixelRef.h"
+#include "SkRect.h"
+#include "SkSize.h"
+
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class ImageFrameGenerator;
+
+class LazyDecodingPixelRef : public SkPixelRef {
+public:
+    LazyDecodingPixelRef(PassRefPtr<ImageFrameGenerator>, const SkISize& scaledSize, const SkIRect& scaledSubset);
+    virtual ~LazyDecodingPixelRef();
+
+    SK_DECLARE_UNFLATTENABLE_OBJECT()
+
+    PassRefPtr<ImageFrameGenerator> frameGenerator() const { return m_frameGenerator; }
+    bool isScaled(const SkISize& fullSize) const;
+    bool isClipped() const;
+
+protected:
+    // SkPixelRef implementation.
+    virtual void* onLockPixels(SkColorTable**);
+    virtual void onUnlockPixels();
+    virtual bool onLockPixelsAreWritable() const;
+
+private:
+    RefPtr<ImageFrameGenerator> m_frameGenerator;
+    SkISize m_scaledSize;
+    SkIRect m_scaledSubset;
+};
+
+} // namespace WebCore
+
+#endif // LazyDecodingPixelRef_h_
diff --git a/Source/WebCore/platform/graphics/chromium/ScaledImageFragment.cpp b/Source/WebCore/platform/graphics/chromium/ScaledImageFragment.cpp
new file mode 100644 (file)
index 0000000..974e6ff
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "ScaledImageFragment.h"
+
+namespace WebCore {
+
+ScaledImageFragment::~ScaledImageFragment()
+{
+}
+
+ScaledImageFragment::ScaledImageFragment(int imageId, const SkISize& scaledSize, const SkBitmap& bitmap, const bool isComplete)
+    : m_imageId(imageId)
+    , m_scaledSize(scaledSize)
+    , m_bitmap(bitmap)
+    , m_isComplete(isComplete)
+{
+}
+
+bool ScaledImageFragment::isEqual(int imageId, const SkISize& scaledSize) const
+{
+    return imageId == m_imageId && scaledSize == m_scaledSize;
+}
+
+bool ScaledImageFragment::isEqual(int imageId) const
+{
+    return imageId == m_imageId;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/chromium/ScaledImageFragment.h b/Source/WebCore/platform/graphics/chromium/ScaledImageFragment.h
new file mode 100644 (file)
index 0000000..5b7ffc9
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScaledImageFragment_h
+#define ScaledImageFragment_h
+
+#include "SkBitmap.h"
+#include "SkRect.h"
+#include "SkSize.h"
+
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+// ScaledImageFragment is a scaled version of a image. It is identified
+// by two things:
+// 1. Image ID. The original image that this fragment comes from.
+// 2. Scaled image size.
+class ScaledImageFragment {
+public:
+    static PassOwnPtr<ScaledImageFragment> create(int imageId, const SkISize& scaledSize, const SkBitmap& bitmap, bool isComplete)
+    {
+        return adoptPtr(new ScaledImageFragment(imageId, scaledSize, bitmap, isComplete));
+    }
+
+    ScaledImageFragment(int imageId, const SkISize&, const SkBitmap&, bool isComplete);
+    ~ScaledImageFragment();
+
+    const SkBitmap& bitmap() const { return m_bitmap; }
+    SkBitmap& bitmap() { return m_bitmap; }
+
+    bool isEqual(int imageId, const SkISize& scaledSize) const;
+    bool isEqual(int imageId) const;
+    bool isComplete() const { return m_isComplete; }
+
+private:
+    int m_imageId;
+    SkISize m_scaledSize;
+    SkBitmap m_bitmap;
+    bool m_isComplete;
+};
+
+} // namespace WebCore
+
+#endif
index 1862a2afc6e3504936dcbc903ce6f24d4aaf50ad..d084ec8f41cfaf464c8b64864ffd4056a743a259 100644 (file)
 #include "SkPixelRef.h"
 #include "SkiaUtils.h"
 
+#if PLATFORM(CHROMIUM)
+#include "ImageDecodingStore.h"
+#include "TraceEvent.h"
+#endif
+
 namespace WebCore {
 
 NativeImageSkia::NativeImageSkia()
@@ -73,6 +78,11 @@ bool NativeImageSkia::hasResizedBitmap(const SkISize& scaledImageSize, const SkI
 
 SkBitmap NativeImageSkia::resizedBitmap(const SkISize& scaledImageSize, const SkIRect& scaledImageSubset) const
 {
+#if PLATFORM(CHROMIUM)
+    if (ImageDecodingStore::isLazyDecoded(m_image))
+        return ImageDecodingStore::instanceOnMainThread()->resizeLazyDecodedSkBitmap(m_image, scaledImageSize, scaledImageSubset);
+#endif
+
     if (!hasResizedBitmap(scaledImageSize, scaledImageSubset)) {
         bool shouldCache = isDataComplete()
             && shouldCacheResampling(scaledImageSize, scaledImageSubset);
index fc82a5c25ad78e877dc99188e9fdb1e85b1ad27c..9f697a84ab09afbac3b62ae3fce566c4fb6d742d 100644 (file)
@@ -148,6 +148,18 @@ namespace WebCore {
 
         void reportMemoryUsage(MemoryObjectInfo*) const;
 
+#if PLATFORM(CHROMIUM)
+        void setSkBitmap(const SkBitmap& bitmap)
+        {
+            m_bitmap = NativeImageSkia(bitmap, 1);
+        }
+
+        const SkBitmap& getSkBitmap() const
+        {
+            return m_bitmap.bitmap();
+        }
+#endif
+
     private:
         int width() const;
         int height() const;
index 4aeac7e3bfca4b0cbca23414abad7cf0afa4e35e..b1fe553cce67b7c2f065a4263da51cc492880cb6 100644 (file)
@@ -1,3 +1,41 @@
+2012-10-18  Alpha Lam  <hclam@chromium.org>
+
+        [chromium] Implement deferred image decoding
+        https://bugs.webkit.org/show_bug.cgi?id=94240
+
+        Reviewed by Stephen White.
+
+        Adding new unit tests for deferred image decoding.
+        These tests are defined in DeferredImageDecoderTest.cpp. They verify
+        image decoding happens only when SkPicture is rasterized for both
+        scaled and non-scaled cases.
+
+        Tests: DeferredImageDecoderTest.drawIntoSkPicture
+               DeferredImageDecoderTest.drawScaledIntoSkPicture
+
+        * WebKit.gypi:
+        * public/WebSettings.h:
+        * src/WebKit.cpp:
+        (WebKit::shutdown):
+        * src/WebSettingsImpl.cpp:
+        (WebKit::WebSettingsImpl::setDeferredImageDecodingEnabled):
+        (WebKit):
+        * src/WebSettingsImpl.h:
+        (WebSettingsImpl):
+        * tests/DeferredImageDecoderTest.cpp: Added.
+        (WebCore):
+        (DeferredImageDecoderTest):
+        (WebCore::DeferredImageDecoderTest::SetUp):
+        (WebCore::DeferredImageDecoderTest::TearDown):
+        (WebCore::TEST_F):
+        * tests/MockImageDecoder.h: Added.
+        (WebCore):
+        (MockImageDecoder):
+        (WebCore::MockImageDecoder::MockImageDecoder):
+        (WebCore::MockImageDecoder::filenameExtension):
+        (WebCore::MockImageDecoder::frameBufferAtIndex):
+        (WebCore::MockImageDecoder::frameBufferRequestCount):
+
 2012-10-18  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed.  Rolled DEPS.
index 24cae298ff50491fec13fab43bd9086966786c0f..64063a021c46714d9d59856acec422ef87bde99e 100644 (file)
@@ -61,6 +61,7 @@
             'tests/CompositorFakeWebGraphicsContext3D.h',
             'tests/DateTimeFormatTest.cpp',
             'tests/DecimalTest.cpp',
+            'tests/DeferredImageDecoderTest.cpp',
             'tests/DragImageTest.cpp',
             'tests/EventListenerTest.cpp',
             'tests/FakeWebCompositorOutputSurface.h',
@@ -78,8 +79,9 @@
             'tests/IDBLevelDBCodingTest.cpp',
             'tests/IDBRequestTest.cpp',
             'tests/ImageLayerChromiumTest.cpp',
-            'tests/KURLTest.cpp',
+            'tests/MockImageDecoder.h',
             'tests/KeyboardTest.cpp',
+            'tests/KURLTest.cpp',
             'tests/LevelDBTest.cpp',
             'tests/LinkHighlightTest.cpp',
             'tests/ListenerLeakTest.cpp',
index abd84ed0e57afe9831fffd06391e4291e5dc2be4..08cd19745cc70aae379c8951e64a14827f6a4545 100644 (file)
@@ -86,6 +86,7 @@ public:
     virtual void setDefaultTextEncodingName(const WebString&) = 0;
     virtual void setDefaultTileSize(WebSize) = 0;
     virtual void setDeferred2dCanvasEnabled(bool) = 0;
+    virtual void setDeferredImageDecodingEnabled(bool) = 0;
     virtual void setDeveloperExtrasEnabled(bool) = 0;
     virtual void setDeviceSupportsMouse(bool) = 0;
     virtual void setDeviceSupportsTouch(bool) = 0;
index e357f28e4283a700156d6cfabd50edb3ed2f7897..243d08e62948056979362dfcf858c6ff85e8a768 100644 (file)
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "WebKit.h"
 
+#include "ImageDecodingStore.h"
 #include "LayoutTestSupport.h"
 #include "Logging.h"
 #include "MutationObserver.h"
@@ -165,6 +166,7 @@ void shutdown()
     }
 #endif
     s_webKitPlatformSupport = 0;
+    WebCore::ImageDecodingStore::shutdown();
     Platform::shutdown();
     WebPrerenderingSupport::shutdown();
 }
index 988c5e66b1e13c16e9f67d02a47ca078df386098..dc7736d9a21b09074cfb1d9159cb8f7b19c90980 100644 (file)
@@ -32,6 +32,7 @@
 #include "WebSettingsImpl.h"
 
 #include "FontRenderingMode.h"
+#include "ImageDecodingStore.h"
 #include "Settings.h"
 #include <public/WebString.h>
 #include <public/WebURL.h>
@@ -55,6 +56,7 @@ WebSettingsImpl::WebSettingsImpl(Settings* settings)
     , m_applyDefaultDeviceScaleFactorInCompositor(false)
     , m_gestureTapHighlightEnabled(true)
     , m_autoZoomFocusedNodeToLegibleScale(false)
+    , m_deferredImageDecodingEnabled(false)
     , m_defaultTileSize(WebSize(256, 256))
     , m_maxUntiledLayerSize(WebSize(512, 512))
 {
@@ -480,6 +482,15 @@ void WebSettingsImpl::setDeferred2dCanvasEnabled(bool enabled)
     m_settings->setDeferred2dCanvasEnabled(enabled);
 }
 
+void WebSettingsImpl::setDeferredImageDecodingEnabled(bool enabled)
+{
+    if (!m_deferredImageDecodingEnabled && enabled)
+        ImageDecodingStore::initializeOnMainThread();
+    if (m_deferredImageDecodingEnabled && !enabled)
+        ImageDecodingStore::shutdown();
+    m_deferredImageDecodingEnabled = enabled;
+}
+
 void WebSettingsImpl::setAcceleratedCompositingForFixedPositionEnabled(bool enabled)
 {
     m_settings->setAcceleratedCompositingForFixedPositionEnabled(enabled);
index 1169c31cf3eb2ae80fda1f885cd0869168f46a41..9051bab617f86bfe049b0b77e6e2adf02d72d658 100644 (file)
@@ -78,6 +78,7 @@ public:
     virtual void setDefaultTextEncodingName(const WebString&);
     virtual void setDefaultTileSize(WebSize);
     virtual void setDeferred2dCanvasEnabled(bool);
+    virtual void setDeferredImageDecodingEnabled(bool);
     virtual void setDeveloperExtrasEnabled(bool);
     virtual void setDeviceSupportsMouse(bool);
     virtual void setDeviceSupportsTouch(bool);
@@ -178,6 +179,7 @@ private:
     bool m_applyDefaultDeviceScaleFactorInCompositor;
     bool m_gestureTapHighlightEnabled;
     bool m_autoZoomFocusedNodeToLegibleScale;
+    bool m_deferredImageDecodingEnabled;
     WebSize m_defaultTileSize;
     WebSize m_maxUntiledLayerSize;
 };
diff --git a/Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp b/Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp
new file mode 100644 (file)
index 0000000..4825498
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "DeferredImageDecoder.h"
+
+#include "ImageDecodingStore.h"
+#include "MockImageDecoder.h"
+#include "NativeImageSkia.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+#include "SkPicture.h"
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+
+namespace {
+
+class DeferredImageDecoderTest : public ::testing::Test {
+public:
+    virtual void SetUp()
+    {
+        ImageDecodingStore::initializeOnMainThread();
+        m_actualDecoder = new MockImageDecoder();
+        m_actualDecoder->setSize(600, 613);
+        m_lazyDecoder = DeferredImageDecoder::createForTesting(adoptPtr(m_actualDecoder));
+        m_canvas.setDevice(new SkDevice(SkBitmap::kARGB_8888_Config, 100, 100))->unref();
+    }
+
+    virtual void TearDown()
+    {
+        ImageDecodingStore::shutdown();
+    }
+
+protected:
+    // Don't own this but saves the pointer to query states.
+    MockImageDecoder* m_actualDecoder;
+    OwnPtr<DeferredImageDecoder> m_lazyDecoder;
+    SkPicture m_picture;
+    SkCanvas m_canvas;
+};
+
+TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
+{
+    OwnPtr<NativeImageSkia> image(adoptPtr(m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage()));
+    EXPECT_EQ(m_actualDecoder->size().width(), image->bitmap().width());
+    EXPECT_EQ(m_actualDecoder->size().height(), image->bitmap().height());
+    EXPECT_FALSE(image->bitmap().isNull());
+    EXPECT_TRUE(image->bitmap().isImmutable());
+
+    SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
+    tempCanvas->drawBitmap(image->bitmap(), 0, 0);
+    m_picture.endRecording();
+    EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount());
+
+    m_canvas.drawPicture(m_picture);
+    EXPECT_EQ(1, m_actualDecoder->frameBufferRequestCount());
+}
+
+TEST_F(DeferredImageDecoderTest, drawScaledIntoSkPicture)
+{
+    OwnPtr<NativeImageSkia> image(adoptPtr(m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage()));
+    SkBitmap scaledBitmap = image->resizedBitmap(SkISize::Make(50, 51), SkIRect::MakeWH(50, 51));
+    EXPECT_FALSE(scaledBitmap.isNull());
+    EXPECT_TRUE(scaledBitmap.isImmutable());
+    EXPECT_EQ(50, scaledBitmap.width());
+    EXPECT_EQ(51, scaledBitmap.height());
+    EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount());
+
+    SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
+    tempCanvas->drawBitmap(scaledBitmap, 0, 0);
+    m_picture.endRecording();
+    EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount());
+
+    m_canvas.drawPicture(m_picture);
+    EXPECT_EQ(1, m_actualDecoder->frameBufferRequestCount());
+}
+
+} // namespace
diff --git a/Source/WebKit/chromium/tests/MockImageDecoder.h b/Source/WebKit/chromium/tests/MockImageDecoder.h
new file mode 100644 (file)
index 0000000..5cf2374
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MockImageDecoder_h
+
+#include "ImageDecoder.h"
+
+namespace WebCore {
+
+class MockImageDecoder : public ImageDecoder {
+public:
+    MockImageDecoder()
+        : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndColorProfileApplied)
+        , m_frameBufferRequestCount(0)
+    { }
+
+    virtual String filenameExtension() const
+    {
+        return "mock";
+    }
+
+    virtual ImageFrame* frameBufferAtIndex(size_t)
+    {
+        ++m_frameBufferRequestCount;
+
+        m_frameBufferCache.resize(1);
+        m_frameBufferCache[0].setSize(size().width(), size().height());
+        return &m_frameBufferCache[0];
+    }
+
+    int frameBufferRequestCount() const { return m_frameBufferRequestCount; }
+
+private:
+    int m_frameBufferRequestCount;
+};
+
+} // namespace WebCore
+
+#endif // MockImageDecoder_h
index 067349d9ddd3c88fd69828d2e73923ea90da0178..7823bddcd530159ac92835fdc4e1b7d0998d0fd6 100644 (file)
@@ -1,3 +1,28 @@
+2012-10-18  Alpha Lam  <hclam@chromium.org>
+
+        [chromium] Implement deferred image decoding
+        https://bugs.webkit.org/show_bug.cgi?id=94240
+
+        Reviewed by Stephen White.
+
+        Add --enable-deferred-image-decoding to DRT.
+
+        * DumpRenderTree/chromium/DumpRenderTree.cpp:
+        (main):
+        * DumpRenderTree/chromium/TestShell.cpp:
+        (TestShell::TestShell):
+        (TestShell::resetWebSettings):
+        * DumpRenderTree/chromium/TestShell.h:
+        (TestShell::setDeferredImageDecodingEnabled):
+        (TestShell):
+        * DumpRenderTree/chromium/WebPreferences.cpp:
+        (WebPreferences::reset):
+        (WebPreferences::applyTo):
+        * DumpRenderTree/chromium/WebPreferences.h:
+        (WebPreferences):
+        * Scripts/webkitpy/layout_tests/port/chromium.py:
+        (ChromiumPort.virtual_test_suites):
+
 2012-10-18  Dirk Pranke  <dpranke@chromium.org>
 
         webkitpy: fix chromium bot configs in builders.py
index 30ce28851fc9a9a46b8b63e6dbd00da1c3fea838..5a32104496f79b1f2a4548b3653456b4061fa6b5 100644 (file)
@@ -64,6 +64,7 @@ static const char optionEnableAcceleratedPainting[] = "--enable-accelerated-pain
 static const char optionEnableAcceleratedCompositingForVideo[] = "--enable-accelerated-video";
 static const char optionUseGraphicsContext3DImplementation[] = "--use-graphics-context-3d-implementation=";
 static const char optionEnablePerTilePainting[] = "--enable-per-tile-painting";
+static const char optionEnableDeferredImageDecoding[] = "--enable-deferred-image-decoding";
 
 static const char optionStressOpt[] = "--stress-opt";
 static const char optionStressDeopt[] = "--stress-deopt";
@@ -133,6 +134,7 @@ int main(int argc, char* argv[])
     bool deferred2DCanvasEnabled = false;
     bool acceleratedPaintingEnabled = false;
     bool perTilePaintingEnabled = false;
+    bool deferredImageDecodingEnabled = false;
     bool stressOpt = false;
     bool stressDeopt = false;
     bool hardwareAcceleratedGL = false;
@@ -183,6 +185,8 @@ int main(int argc, char* argv[])
               fprintf(stderr, "Unknown GraphicContext3D implementation %s\n", implementation.c_str());
         } else if (argument == optionEnablePerTilePainting)
             perTilePaintingEnabled = true;
+        else if (argument == optionEnableDeferredImageDecoding)
+            deferredImageDecodingEnabled = true;
         else if (argument == optionStressOpt)
             stressOpt = true;
         else if (argument == optionStressDeopt)
@@ -222,6 +226,7 @@ int main(int argc, char* argv[])
         shell.setDeferred2dCanvasEnabled(deferred2DCanvasEnabled);
         shell.setAcceleratedPaintingEnabled(acceleratedPaintingEnabled);
         shell.setPerTilePaintingEnabled(perTilePaintingEnabled);
+        shell.setDeferredImageDecodingEnabled(deferredImageDecodingEnabled);
         shell.setJavaScriptFlags(javaScriptFlags);
         shell.setStressOpt(stressOpt);
         shell.setStressDeopt(stressDeopt);
index 32585faa1b2d8ad81a83b15e8f712bd8ca72489b..ac7759681a046d03d4718fc458c27e82e1461799 100644 (file)
@@ -114,6 +114,7 @@ TestShell::TestShell()
     , m_accelerated2dCanvasEnabled(false)
     , m_deferred2dCanvasEnabled(false)
     , m_acceleratedPaintingEnabled(false)
+    , m_deferredImageDecodingEnabled(false)
     , m_stressOpt(false)
     , m_stressDeopt(false)
     , m_dumpWhenFinished(true)
@@ -229,6 +230,7 @@ void TestShell::resetWebSettings(WebView& webView)
     m_prefs.accelerated2dCanvasEnabled = m_accelerated2dCanvasEnabled;
     m_prefs.deferred2dCanvasEnabled = m_deferred2dCanvasEnabled;
     m_prefs.acceleratedPaintingEnabled = m_acceleratedPaintingEnabled;
+    m_prefs.deferredImageDecodingEnabled = m_deferredImageDecodingEnabled;
     m_prefs.applyTo(&webView);
 }
 
index 44b5ae388c68d65de890fc800fed5229eec2a324..3926624469b68ccbc874b491ea483a0b6392ce55 100644 (file)
@@ -138,6 +138,7 @@ public:
     void setDeferred2dCanvasEnabled(bool enabled) { m_deferred2dCanvasEnabled = enabled; }
     void setAcceleratedPaintingEnabled(bool enabled) { m_acceleratedPaintingEnabled = enabled; }
     void setPerTilePaintingEnabled(bool);
+    void setDeferredImageDecodingEnabled(bool enabled) { m_deferredImageDecodingEnabled = enabled; }
 #if defined(OS_WIN)
     // Access to the finished event. Used by the static WatchDog thread.
     HANDLE finishedEvent() { return m_finishedEvent; }
@@ -235,6 +236,7 @@ private:
     bool m_deferred2dCanvasEnabled;
     bool m_acceleratedPaintingEnabled;
     bool m_perTilePaintingEnabled;
+    bool m_deferredImageDecodingEnabled;
     WebPreferences m_prefs;
     bool m_stressOpt;
     bool m_stressDeopt;
index 3bc2cdd9f2ae4170c33ad64106d4a7f2d09021f5..5c8c92c99942644dd19a49c98e66c1a4f06d444d 100644 (file)
@@ -116,6 +116,7 @@ void WebPreferences::reset()
     deferred2dCanvasEnabled = false;
     acceleratedPaintingEnabled = false;
     forceCompositingMode = false;
+    deferredImageDecodingEnabled = false;
     mediaPlaybackRequiresUserGesture = false;
     mockScrollbarsEnabled = false;
     cssCustomFilterEnabled = false;
@@ -224,6 +225,7 @@ void WebPreferences::applyTo(WebView* webView)
     settings->setAccelerated2dCanvasEnabled(accelerated2dCanvasEnabled);
     settings->setDeferred2dCanvasEnabled(deferred2dCanvasEnabled);
     settings->setAcceleratedPaintingEnabled(acceleratedPaintingEnabled);
+    settings->setDeferredImageDecodingEnabled(deferredImageDecodingEnabled);
     settings->setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
     settings->setMockScrollbarsEnabled(mockScrollbarsEnabled);
     settings->setApplyDefaultDeviceScaleFactorInCompositor(forceCompositingMode);
index c36553b3546964c76f29916a9ea9b9e2a23e24b2..e0315f2d07c1e5b9855fe7b3aa2e14cf7e1e40bf 100644 (file)
@@ -109,6 +109,7 @@ struct WebPreferences {
     bool accelerated2dCanvasEnabled;
     bool deferred2dCanvasEnabled;
     bool acceleratedPaintingEnabled;
+    bool deferredImageDecodingEnabled;
     bool mediaPlaybackRequiresUserGesture;
     bool mockScrollbarsEnabled;
     bool cssCustomFilterEnabled;
index c310eb15b1954ddeddc333b980f665d5fcdb91ce..a69f5a822aa3fe32846f91701164193cc2238f52 100755 (executable)
@@ -390,6 +390,9 @@ class ChromiumPort(Port):
             VirtualTestSuite('platform/chromium/virtual/softwarecompositing',
                              'compositing',
                              ['--enable-software-compositing']),
+            VirtualTestSuite('platform/chromium/virtual/deferred/fast/images',
+                             'fast/images',
+                             ['--enable-deferred-image-decoding', '--enable-per-tile-painting', '--force-compositing-mode']),
         ]
 
     #