Async image decoding for large images should be disabled after the first time a tile is painted
https://bugs.webkit.org/show_bug.cgi?id=174451
<rdar://problem/31246421>
Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-07-25
Reviewed by Simon Fraser.
Source/WebCore:
Flashing because of DOM mutation can be fixed by disabling the asynchronous
image decoding after the first time a tile was painted.
We can detect this by consulting the tile repaintCount. If it is zero, then
it is safe to use asynchronous image decoded. If the tile repaintCount is
greater than zero, we are not sure if the renderer rectangle has an image
drawn in it already or not. In this case we have to use the synchronous
image decoding to avoid causing a flash.
Tests: fast/images/async-image-background-change.html
fast/images/async-image-src-change.html
http/tests/multipart/multipart-async-image.html
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
* page/FrameView.cpp:
(WebCore::FrameView::willPaintContents):
(WebCore::FrameView::paintContentsForSnapshot):
* page/PageOverlayController.cpp:
(WebCore::PageOverlayController::paintContents):
* page/PageOverlayController.h:
* page/linux/ResourceUsageOverlayLinux.cpp:
* page/mac/ServicesOverlayController.h:
* page/mac/ServicesOverlayController.mm:
(WebCore::ServicesOverlayController::Highlight::paintContents):
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::draw):
* platform/graphics/BitmapImage.h:
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::paintGraphicsLayerContents):
* platform/graphics/GraphicsLayer.h:
* platform/graphics/GraphicsLayerClient.h:
(WebCore::GraphicsLayerClient::paintContents):
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::LayerClient::platformCALayerPaintContents):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::platformCALayerPaintContents):
* platform/graphics/ca/GraphicsLayerCA.h:
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/ca/PlatformCALayerClient.h:
(WebCore::PlatformCALayerClient::platformCALayerRepaintCount):
* platform/graphics/ca/TileCoverageMap.cpp:
(WebCore::TileCoverageMap::platformCALayerPaintContents):
* platform/graphics/ca/TileCoverageMap.h:
* platform/graphics/ca/TileGrid.cpp:
(WebCore::TileGrid::platformCALayerPaintContents):
(WebCore::TileGrid::platformCALayerRepaintCount):
* platform/graphics/ca/TileGrid.h:
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
(PlatformCALayer::drawLayerContents):
* platform/graphics/ca/win/PlatformCALayerWin.cpp:
(PlatformCALayer::drawLayerContents):
* platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
(PlatformCALayerWinInternal::displayCallback):
* platform/graphics/ca/win/WebTiledBackingLayerWin.cpp:
(WebTiledBackingLayerWin::displayCallback):
* platform/graphics/mac/WebLayer.mm:
(-[WebLayer drawInContext:]):
(-[WebSimpleLayer drawInContext:]):
* rendering/PaintPhase.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::decodingModeForImageDraw):
* rendering/RenderElement.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::paintLayerContents):
(WebCore::RenderLayer::paintForegroundForFragments):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::paintContents):
* rendering/RenderLayerBacking.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::paintContents):
* rendering/RenderLayerCompositor.h:
* rendering/RenderWidget.cpp:
(WebCore::RenderWidget::paintContents):
* testing/Internals.cpp:
(WebCore::imageFromImageElement):
(WebCore::bitmapImageFromImageElement):
(WebCore::Internals::imageFrameIndex):
(WebCore::Internals::setImageFrameDecodingDuration):
(WebCore::Internals::resetImageAnimation):
(WebCore::Internals::isImageAnimating):
(WebCore::Internals::setClearDecoderAfterAsyncFrameRequestForTesting):
(WebCore::Internals::imageDecodeCount):
(WebCore::Internals::setLargeImageAsyncDecodingEnabledForTesting):
* testing/Internals.h:
* testing/Internals.idl:
Source/WebKit:
* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::drawInContext):
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::imageForRect):
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::renderedImage):
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
(WebKit::CompositingCoordinator::paintContents):
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
Source/WebKitLegacy/mac:
* WebView/WebFrame.mm:
(-[WebFrame _paintBehaviorForDestinationContext:]):
(-[WebFrame _drawRect:contentsOnly:]):
* WebView/WebHTMLView.mm:
(imageFromRect):
Source/WebKitLegacy/win:
* FullscreenVideoController.cpp:
(FullscreenVideoController::LayerClient::platformCALayerPaintContents):
* WebCoreSupport/AcceleratedCompositingContext.cpp:
(AcceleratedCompositingContext::paintContents):
* WebCoreSupport/AcceleratedCompositingContext.h:
LayoutTests:
To test async image decoding for large images, we have to create the <img>
element dynamically so we can listen to the load and webkitImageFrameReady
events and know reliably when to end the test. But with this patch the async
image decoding for large images will be disabled after the first paint.
That means async image decoding for large images will be disabled always
unless we force the async image decoding till the image is painted for the
first time. We use Internals::setLargeImageAsyncDecodingEnabledForTesting()
to force the async image decoding. So painting an image in this case will
require multiple paints; in all of them the async image decoding will be
enabled. But this is okay because it resembles the case where the <img> is
created from a static <img> tag in the HTML file.
For new tests, where we want to make sure that mutating the DOM will not
cause a flash, async image decoding will be forced till the image is drawn
for the first time. After that the async image decoding is enabled but not
forced.
Disable new tests for WK1 because the async image decoding is always enabled
because tiling does not necessarily exist in WK1 . But eventually the async
image decoding for large images will be always disabled for WK1.
* fast/images/async-image-background-change-expected.html: Added.
* fast/images/async-image-background-change.html: Added.
* fast/images/async-image-background-image-repeated.html:
* fast/images/async-image-background-image.html:
* fast/images/async-image-body-background-image.html:
* fast/images/async-image-multiple-clients-repaint.html:
* fast/images/async-image-src-change-expected.html: Added.
* fast/images/async-image-src-change.html: Added.
* fast/images/resources/green-400x400.png: Added.
* fast/images/resources/red-100x100.png: Added.
* fast/images/resources/red-400x400.png: Added.
* fast/images/sprite-sheet-image-draw.html:
* http/tests/multipart/multipart-async-image-expected.txt: Added.
* http/tests/multipart/multipart-async-image.html: Added.
* platform/ios-wk1/TestExpectations:
* platform/mac-wk1/TestExpectations:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@219876 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/platform/mac-wk1/TestExpectations b/LayoutTests/platform/mac-wk1/TestExpectations
index 26c3f4e..2b41564 100644
--- a/LayoutTests/platform/mac-wk1/TestExpectations
+++ b/LayoutTests/platform/mac-wk1/TestExpectations
@@ -156,6 +156,11 @@
http/tests/inspector/network/resource-response-source-disk-cache.html
http/tests/inspector/network/resource-sizes-disk-cache.html
+# Async image decoding is WK2 only
+fast/images/async-image-background-change.html
+fast/images/async-image-src-change.html
+http/tests/multipart/multipart-async-image.html
+
[ Yosemite+ ] fast/ruby/ruby-expansion-cjk-2.html [ ImageOnlyFailure ]
# ShouldOpenExternalURLs not yet supported in WK1