Title: [216135] trunk
Revision
216135
Author
[email protected]
Date
2017-05-03 12:43:42 -0700 (Wed, 03 May 2017)

Log Message

Async image decoding should be disabled for snapshots, printing and preview
https://bugs.webkit.org/show_bug.cgi?id=171467
Source/WebCore:

Patch by Said Abou-Hallawa <[email protected]> on 2017-05-03
Reviewed by Simon Fraser.

Asynchronous image decoding should only be used for window display where
RenderElements can be repainted and painted. For cases where there is only
one chance to draw the image, synchronous decoding should be used.

* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::paintIntoRect):

Tools:

Patch by Said Abou-Hallawa <[email protected]> on 2017-05-03
Reviewed by Simon Fraser.

Add a API test for snapshotting with large images. Ensure the images are
drawn correctly which implies they should have been synchronously decoded.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/large-red-square-image.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm:
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (216134 => 216135)


--- trunk/Source/WebCore/ChangeLog	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Source/WebCore/ChangeLog	2017-05-03 19:43:42 UTC (rev 216135)
@@ -1,3 +1,19 @@
+2017-05-03  Said Abou-Hallawa  <[email protected]>
+
+        Async image decoding should be disabled for snapshots, printing and preview
+        https://bugs.webkit.org/show_bug.cgi?id=171467
+ 
+        Reviewed by Simon Fraser.
+ 
+        Asynchronous image decoding should only be used for window display where
+        RenderElements can be repainted and painted. For cases where there is only
+        one chance to draw the image, synchronous decoding should be used. 
+
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paintIntoRect):
+
 2017-05-03  Nan Wang  <[email protected]>
 
         AX: VO skips cells after cell with aria-colspan

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (216134 => 216135)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2017-05-03 19:43:42 UTC (rev 216135)
@@ -882,7 +882,8 @@
                 downcast<BitmapImage>(*image).updateFromSettings(settings());
 
             auto interpolation = chooseInterpolationQuality(context, *image, &bgLayer, geometry.tileSize());
-            context.drawTiledImage(*image, geometry.destRect(), toLayoutPoint(geometry.relativePhase()), geometry.tileSize(), geometry.spaceSize(), ImagePaintingOptions(compositeOp, bgLayer.blendMode(), DecodingMode::Asynchronous, ImageOrientationDescription(), interpolation));
+            auto decodingMode = (view().frameView().paintBehavior() & PaintBehaviorFlattenCompositingLayers) ? DecodingMode::Synchronous : DecodingMode::Asynchronous;
+            context.drawTiledImage(*image, geometry.destRect(), toLayoutPoint(geometry.relativePhase()), geometry.tileSize(), geometry.spaceSize(), ImagePaintingOptions(compositeOp, bgLayer.blendMode(), decodingMode, ImageOrientationDescription(), interpolation));
         }
     }
 

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (216134 => 216135)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2017-05-03 19:43:42 UTC (rev 216135)
@@ -584,7 +584,8 @@
         downcast<BitmapImage>(*image).updateFromSettings(settings());
 
     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
-    context.drawImage(*img, rect, ImagePaintingOptions(compositeOperator, BlendModeNormal, DecodingMode::Asynchronous, orientationDescription, interpolation));
+    auto decodingMode = (view().frameView().paintBehavior() & PaintBehaviorFlattenCompositingLayers) ? DecodingMode::Synchronous : DecodingMode::Asynchronous;
+    context.drawImage(*img, rect, ImagePaintingOptions(compositeOperator, BlendModeNormal, decodingMode, orientationDescription, interpolation));
 }
 
 bool RenderImage::boxShadowShouldBeAppliedToBackground(const LayoutPoint& paintOffset, BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox*) const

Modified: trunk/Tools/ChangeLog (216134 => 216135)


--- trunk/Tools/ChangeLog	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Tools/ChangeLog	2017-05-03 19:43:42 UTC (rev 216135)
@@ -1,3 +1,18 @@
+2017-05-03  Said Abou-Hallawa  <[email protected]>
+
+        Async image decoding should be disabled for snapshots, printing and preview
+        https://bugs.webkit.org/show_bug.cgi?id=171467
+
+        Reviewed by Simon Fraser.
+
+        Add a API test for snapshotting with large images. Ensure the images are
+        drawn correctly which implies they should have been synchronously decoded.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/large-red-square-image.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm:
+        (TEST):
+
 2017-05-03  Chris Dumez  <[email protected]>
 
         [WK2] Extend processDidCrash delegate to let the client know the reason for the crash

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (216134 => 216135)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-05-03 19:43:42 UTC (rev 216135)
@@ -181,6 +181,7 @@
 		536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */; };
 		536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 536770351CC812F900D425B1 /* WebScriptObjectDescription.html */; };
 		53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */; };
+		55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55226A2E1EB969B600C36AD0 /* large-red-square-image.html */; };
 		5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */; };
 		5714ECB91CA8B5B000051AC8 /* DownloadRequestOriginalURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */; };
 		5714ECBB1CA8BFE400051AC8 /* DownloadRequestOriginalURLFrame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */; };
@@ -682,6 +683,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */,
 				074994421EA5034B000DA44E /* getUserMedia.html in Copy Resources */,
 				C9BF06EF1E9C132500595E3E /* autoplay-muted-with-controls.html in Copy Resources */,
 				F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
@@ -1131,6 +1133,7 @@
 		536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObjectDescription.mm; sourceTree = "<group>"; };
 		536770351CC812F900D425B1 /* WebScriptObjectDescription.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebScriptObjectDescription.html; sourceTree = "<group>"; };
 		53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PriorityQueue.cpp; sourceTree = "<group>"; };
+		55226A2E1EB969B600C36AD0 /* large-red-square-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-red-square-image.html"; sourceTree = "<group>"; };
 		5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronizedFixedQueue.cpp; sourceTree = "<group>"; };
 		5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL.html; sourceTree = "<group>"; };
 		5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURLFrame.html; sourceTree = "<group>"; };
@@ -2211,6 +2214,7 @@
 		BC90977B125571AE00083756 /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				55226A2E1EB969B600C36AD0 /* large-red-square-image.html */,
 				C045F9461385C2F800C0F3CD /* 18-characters.html */,
 				1C2B81851C89252300A5529F /* Ahem.ttf */,
 				93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/large-red-square-image.html (0 => 216135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/large-red-square-image.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/large-red-square-image.html	2017-05-03 19:43:42 UTC (rev 216135)
@@ -0,0 +1,13 @@
+<style>
+    .red-box {
+        background-image: url('large-red-square.png');
+        position:absolute;
+        width:100px;
+        height:100px;
+        top:0px;
+        left:0px;
+    }
+</style>
+<body>
+    <div class="red-box"></div>
+</body>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm (216134 => 216135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm	2017-05-03 19:33:19 UTC (rev 216134)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm	2017-05-03 19:43:42 UTC (rev 216135)
@@ -123,8 +123,8 @@
         NSInteger viewHeightInPixels = viewHeight * backingScaleFactor;
 
         unsigned char rgba[viewWidthInPixels * viewHeightInPixels * 4];
-        CGContextRef context = CGBitmapContextCreate(rgba, viewWidthInPixels, viewHeightInPixels, 8, 4 * viewWidthInPixels, colorSpace.get(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
-        CGContextDrawImage(context, CGRectMake(0, 0, viewWidthInPixels, viewHeightInPixels), cgImage.get());
+        RetainPtr<CGContextRef> context = CGBitmapContextCreate(rgba, viewWidthInPixels, viewHeightInPixels, 8, 4 * viewWidthInPixels, colorSpace.get(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
+        CGContextDrawImage(context.get(), CGRectMake(0, 0, viewWidthInPixels, viewHeightInPixels), cgImage.get());
 
         NSInteger pixelIndex = getPixelIndex(0, 0, viewWidthInPixels);
         EXPECT_EQ(255, rgba[pixelIndex]);
@@ -142,7 +142,6 @@
         EXPECT_EQ(0, rgba[pixelIndex + 1]);
         EXPECT_EQ(0, rgba[pixelIndex + 2]);
 
-        CGContextRelease(context);
         isDone = true;
     }];
 
@@ -244,4 +243,55 @@
     TestWebKitAPI::Util::run(&isDone);
 }
 
+TEST(WKWebView, SnapshotImageLargeAsyncDecoding)
+{
+    NSInteger viewWidth = 800;
+    NSInteger viewHeight = 600;
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"large-red-square-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
+    [webView _test_waitForDidFinishNavigation];
+
+    RetainPtr<WKSnapshotConfiguration> snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:NSMakeRect(0, 0, viewWidth, viewHeight)];
+    [snapshotConfiguration setSnapshotWidth:@(viewWidth)];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+
+        EXPECT_EQ(viewWidth, snapshotImage.size.width);
+
+        RetainPtr<CGImageRef> cgImage = convertToCGImage(snapshotImage);
+        RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
+
+        unsigned char rgba[viewWidth * viewHeight * 4];
+        RetainPtr<CGContextRef> context = CGBitmapContextCreate(rgba, viewWidth, viewHeight, 8, 4 * viewWidth, colorSpace.get(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
+        CGContextDrawImage(context.get(), CGRectMake(0, 0, viewWidth, viewHeight), cgImage.get());
+
+        // Top-left corner of the div (0, 0, 100, 100)
+        NSInteger pixelIndex = getPixelIndex(0, 0, viewWidth);
+        EXPECT_EQ(255, rgba[pixelIndex]);
+        EXPECT_EQ(0, rgba[pixelIndex + 1]);
+        EXPECT_EQ(0, rgba[pixelIndex + 2]);
+
+        // Right-bottom corner of the div (0, 0, 100, 100)
+        pixelIndex = getPixelIndex(99, 99, viewWidth);
+        EXPECT_EQ(255, rgba[pixelIndex]);
+        EXPECT_EQ(0, rgba[pixelIndex + 1]);
+        EXPECT_EQ(0, rgba[pixelIndex + 2]);
+
+        // Outside the div (0, 0, 100, 100)
+        pixelIndex = getPixelIndex(100, 100, viewWidth);
+        EXPECT_EQ(255, rgba[pixelIndex]);
+        EXPECT_EQ(255, rgba[pixelIndex + 1]);
+        EXPECT_EQ(255, rgba[pixelIndex + 2]);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&isDone);
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to