Title: [205951] branches/safari-602-branch

Diff

Modified: branches/safari-602-branch/Source/WebKit2/ChangeLog (205950 => 205951)


--- branches/safari-602-branch/Source/WebKit2/ChangeLog	2016-09-15 06:57:01 UTC (rev 205950)
+++ branches/safari-602-branch/Source/WebKit2/ChangeLog	2016-09-15 06:57:05 UTC (rev 205951)
@@ -1,5 +1,28 @@
 2016-09-14  Babak Shafiei  <[email protected]>
 
+        Merge r205878. rdar://problem/28229827
+
+    2016-09-13  Tim Horton  <[email protected]>
+
+            Provide a mechanism to specify the maximum size of WKThumbnailView snapshots
+            https://bugs.webkit.org/show_bug.cgi?id=161896
+            <rdar://problem/28229827>
+
+            Reviewed by Simon Fraser.
+
+            Some clients know that their thumbnail views will only be displayed up to
+            a specific size that is significantly smaller than the WKView size. Allow
+            them to avoid wasting lots of memory on unnecessarily large snapshots.
+
+            * UIProcess/API/Cocoa/_WKThumbnailView.h:
+            * UIProcess/API/Cocoa/_WKThumbnailView.mm:
+            (-[_WKThumbnailView requestSnapshot]):
+            (-[_WKThumbnailView _requestSnapshotIfNeeded]):
+            (-[_WKThumbnailView setMaximumSnapshotSize:]):
+            Add a maximumSnapshotSize property which can be changed dynamically.
+
+2016-09-14  Babak Shafiei  <[email protected]>
+
         Merge r205935. rdar://problem/26013388
 
     2016-09-14  Beth Dakin  <[email protected]>

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h (205950 => 205951)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h	2016-09-15 06:57:01 UTC (rev 205950)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h	2016-09-15 06:57:05 UTC (rev 205951)
@@ -40,6 +40,7 @@
 
 @property (nonatomic) CGFloat scale;
 @property (nonatomic, readonly) CGSize snapshotSize;
+@property (nonatomic) CGSize maximumSnapshotSize;
 @property (nonatomic) BOOL exclusivelyUsesSnapshot;
 
 // Defaults to NO.

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm (205950 => 205951)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm	2016-09-15 06:57:01 UTC (rev 205950)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm	2016-09-15 06:57:05 UTC (rev 205951)
@@ -53,7 +53,8 @@
     BOOL _originalSourceViewIsInWindow;
 
     BOOL _snapshotWasDeferred;
-    double _lastSnapshotScale;
+    CGFloat _lastSnapshotScale;
+    CGSize _lastSnapshotMaximumSize;
 }
 
 @synthesize snapshotSize=_snapshotSize;
@@ -94,7 +95,18 @@
     SnapshotOptions options = SnapshotOptionsInViewCoordinates;
     IntSize bitmapSize = snapshotRect.size();
     bitmapSize.scale(_scale * _webPageProxy->deviceScaleFactor());
+
+    if (!CGSizeEqualToSize(_maximumSnapshotSize, CGSizeZero)) {
+        double sizeConstraintScale = 1;
+        if (_maximumSnapshotSize.width)
+            sizeConstraintScale = CGFloatMin(sizeConstraintScale, _maximumSnapshotSize.width / bitmapSize.width());
+        if (_maximumSnapshotSize.height)
+            sizeConstraintScale = CGFloatMin(sizeConstraintScale, _maximumSnapshotSize.height / bitmapSize.height());
+        bitmapSize = IntSize(CGCeiling(bitmapSize.width() * sizeConstraintScale), CGCeiling(bitmapSize.height() * sizeConstraintScale));
+    }
+
     _lastSnapshotScale = _scale;
+    _lastSnapshotMaximumSize = _maximumSnapshotSize;
     _webPageProxy->takeSnapshot(snapshotRect, bitmapSize, options, [thumbnailView](const ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
         RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageHandle, SharedMemory::Protection::ReadOnly);
         RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
@@ -135,7 +147,7 @@
 
 - (void)_requestSnapshotIfNeeded
 {
-    if (self.layer.contents && _lastSnapshotScale == _scale)
+    if (self.layer.contents && _lastSnapshotScale == _scale && CGSizeEqualToSize(_lastSnapshotMaximumSize, _maximumSnapshotSize))
         return;
 
     [self requestSnapshot];
@@ -180,6 +192,16 @@
     self.layer.sublayerTransform = CATransform3DMakeScale(_scale, _scale, 1);
 }
 
+- (void)setMaximumSnapshotSize:(CGSize)maximumSnapshotSize
+{
+    if (CGSizeEqualToSize(_maximumSnapshotSize, maximumSnapshotSize))
+        return;
+
+    _maximumSnapshotSize = maximumSnapshotSize;
+
+    [self _requestSnapshotIfNeeded];
+}
+
 // This should be removed when all clients go away; it is always YES now.
 - (void)setUsesSnapshot:(BOOL)usesSnapshot
 {

Modified: branches/safari-602-branch/Tools/ChangeLog (205950 => 205951)


--- branches/safari-602-branch/Tools/ChangeLog	2016-09-15 06:57:01 UTC (rev 205950)
+++ branches/safari-602-branch/Tools/ChangeLog	2016-09-15 06:57:05 UTC (rev 205951)
@@ -1,3 +1,20 @@
+2016-09-14  Babak Shafiei  <[email protected]>
+
+        Merge r205878. rdar://problem/28229827
+
+    2016-09-13  Tim Horton  <[email protected]>
+
+            Provide a mechanism to specify the maximum width of WKThumbnailView snapshots
+            https://bugs.webkit.org/show_bug.cgi?id=161896
+            <rdar://problem/28229827>
+
+            Reviewed by Simon Fraser.
+
+            * TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm:
+            (TestWebKitAPI::TEST):
+            Add a test for the new property.
+            Also fix the old new test to run on arbitrary scale displays without failing.
+
 2016-09-12  Babak Shafiei  <[email protected]>
 
         Merge r205784. rdar://problem/28230123

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm (205950 => 205951)


--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm	2016-09-15 06:57:01 UTC (rev 205950)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm	2016-09-15 06:57:05 UTC (rev 205951)
@@ -76,11 +76,11 @@
 
 TEST(WebKit2, WKThumbnailViewKeepSnapshotWhenRemovedFromSuperview)
 {
-    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest"));
-
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
     PlatformWebView webView(context.get());
     WKView *wkView = webView.platformView();
     setPageLoaderClient(webView.page());
+    WKPageSetCustomBackingScaleFactor(webView.page(), 1);
 
     WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("lots-of-text", "html"));
     WKPageLoadURL(webView.page(), url.get());
@@ -120,6 +120,59 @@
     [thumbnailView removeObserver:observer.get() forKeyPath:@"snapshotSize" context:snapshotSizeChangeKVOContext];
 }
 
+TEST(WebKit2, WKThumbnailViewMaximumSnapshotSize)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+    PlatformWebView webView(context.get());
+    WKView *wkView = webView.platformView();
+    setPageLoaderClient(webView.page());
+    WKPageSetCustomBackingScaleFactor(webView.page(), 1);
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("lots-of-text", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    RetainPtr<_WKThumbnailView> thumbnailView = adoptNS([[_WKThumbnailView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) fromWKView:wkView]);
+
+    RetainPtr<SnapshotSizeObserver> observer = adoptNS([[SnapshotSizeObserver alloc] init]);
+
+    [thumbnailView addObserver:observer.get() forKeyPath:@"snapshotSize" options:NSKeyValueObservingOptionNew context:snapshotSizeChangeKVOContext];
+
+    [wkView.window.contentView addSubview:thumbnailView.get()];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 800);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+
+    [thumbnailView setMaximumSnapshotSize:CGSizeMake(200, 0)];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 200);
+    EXPECT_EQ([thumbnailView snapshotSize].height, 150);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+
+    [thumbnailView setMaximumSnapshotSize:CGSizeMake(0, 300)];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 400);
+    EXPECT_EQ([thumbnailView snapshotSize].height, 300);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+
+    [thumbnailView setMaximumSnapshotSize:CGSizeMake(200, 300)];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 200);
+    EXPECT_EQ([thumbnailView snapshotSize].height, 150);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+
+    [thumbnailView removeObserver:observer.get() forKeyPath:@"snapshotSize" context:snapshotSizeChangeKVOContext];
+}
+
 } // namespace TestWebKitAPI
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to