_WKThumbnailView should support a snapshot-only mode
authorconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Oct 2015 01:10:32 +0000 (01:10 +0000)
committerconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Oct 2015 01:10:32 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150106

Reviewed by Tim Horton.

Add a new property to _WKThumbnailView, exclusivelyUsesSnapshot, which causes _WKThumbnailView
to bypass both layer tree reparenting and event suppression on the associated WKView.

Add a new method, -requestSnapshot, which clients can use to force _WKThumbnailView to refresh
on demand.

* UIProcess/API/Cocoa/_WKThumbnailView.h:
* UIProcess/API/Cocoa/_WKThumbnailView.mm:
(-[_WKThumbnailView requestSnapshot]):
Extracted from -_requestSnapshotIfNeeded:.
(-[_WKThumbnailView _viewWasUnparented]):
(-[_WKThumbnailView _viewWasParented]):
(-[_WKThumbnailView _requestSnapshotIfNeeded]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h
Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm

index 8107c62..5789ade 100644 (file)
@@ -1,3 +1,24 @@
+2015-10-13  Conrad Shultz  <conrad_shultz@apple.com>
+
+        _WKThumbnailView should support a snapshot-only mode
+        https://bugs.webkit.org/show_bug.cgi?id=150106
+
+        Reviewed by Tim Horton.
+
+        Add a new property to _WKThumbnailView, exclusivelyUsesSnapshot, which causes _WKThumbnailView
+        to bypass both layer tree reparenting and event suppression on the associated WKView.
+
+        Add a new method, -requestSnapshot, which clients can use to force _WKThumbnailView to refresh
+        on demand.
+
+        * UIProcess/API/Cocoa/_WKThumbnailView.h:
+        * UIProcess/API/Cocoa/_WKThumbnailView.mm:
+        (-[_WKThumbnailView requestSnapshot]):
+        Extracted from -_requestSnapshotIfNeeded:.
+        (-[_WKThumbnailView _viewWasUnparented]):
+        (-[_WKThumbnailView _viewWasParented]):
+        (-[_WKThumbnailView _requestSnapshotIfNeeded]):
+
 2015-10-20  Alexey Proskuryakov  <ap@apple.com>
 
         Build fix.
index 6735aab..7249ac4 100644 (file)
@@ -39,10 +39,13 @@ WK_CLASS_AVAILABLE(10_10, 8_0)
 - (instancetype)initWithFrame:(NSRect)frame fromWKView:(WKView *)wkView;
 
 @property (nonatomic) CGFloat scale;
+@property (nonatomic) BOOL exclusivelyUsesSnapshot;
 
 // This should be removed when all clients go away; it is always YES now.
 @property (nonatomic) BOOL usesSnapshot;
 
+- (void)requestSnapshot;
+
 @end
 
 #endif // TARGET_OS_IPHONE
index 049b5fe..ec5b220 100644 (file)
@@ -56,7 +56,8 @@ using namespace WebKit;
     double _lastSnapshotScale;
 }
 
-@synthesize _waitingForSnapshot = _waitingForSnapshot;
+@synthesize _waitingForSnapshot=_waitingForSnapshot;
+@synthesize exclusivelyUsesSnapshot=_exclusivelyUsesSnapshot;
 
 - (instancetype)initWithFrame:(NSRect)frame fromWKView:(WKView *)wkView
 {
@@ -77,15 +78,38 @@ using namespace WebKit;
     return self;
 }
 
+- (void)requestSnapshot
+{
+    if (_waitingForSnapshot) {
+        _snapshotWasDeferred = YES;
+        return;
+    }
+
+    _waitingForSnapshot = YES;
+
+    RetainPtr<_WKThumbnailView> thumbnailView = self;
+    IntRect snapshotRect(IntPoint(), _webPageProxy->viewSize() - IntSize(0, _webPageProxy->topContentInset()));
+    SnapshotOptions options = SnapshotOptionsInViewCoordinates;
+    IntSize bitmapSize = snapshotRect.size();
+    bitmapSize.scale(_scale * _webPageProxy->deviceScaleFactor());
+    _lastSnapshotScale = _scale;
+    _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;
+        [thumbnailView _didTakeSnapshot:cgImage.get()];
+    });
+}
+
 - (void)_viewWasUnparented
 {
-    [_wkView _setThumbnailView:nil];
-    [_wkView _setIgnoresAllEvents:NO];
+    if (!_exclusivelyUsesSnapshot) {
+        [_wkView _setThumbnailView:nil];
+        [_wkView _setIgnoresAllEvents:NO];
+        _webPageProxy->setMayStartMediaWhenInWindow(_originalMayStartMediaWhenInWindow);
+    }
 
     self.layer.contents = nil;
     _lastSnapshotScale = NAN;
-
-    _webPageProxy->setMayStartMediaWhenInWindow(_originalMayStartMediaWhenInWindow);
 }
 
 - (void)_viewWasParented
@@ -93,12 +117,15 @@ using namespace WebKit;
     if ([_wkView _thumbnailView])
         return;
 
-    if (!_originalSourceViewIsInWindow)
+    if (!_exclusivelyUsesSnapshot && !_originalSourceViewIsInWindow)
         _webPageProxy->setMayStartMediaWhenInWindow(false);
 
     [self _requestSnapshotIfNeeded];
-    [_wkView _setThumbnailView:self];
-    [_wkView _setIgnoresAllEvents:YES];
+
+    if (!_exclusivelyUsesSnapshot) {
+        [_wkView _setThumbnailView:self];
+        [_wkView _setIgnoresAllEvents:YES];
+    }
 }
 
 - (void)_requestSnapshotIfNeeded
@@ -106,24 +133,7 @@ using namespace WebKit;
     if (self.layer.contents && _lastSnapshotScale == _scale)
         return;
 
-    if (_waitingForSnapshot) {
-        _snapshotWasDeferred = YES;
-        return;
-    }
-
-    _waitingForSnapshot = YES;
-
-    RetainPtr<_WKThumbnailView> thumbnailView = self;
-    IntRect snapshotRect(IntPoint(), _webPageProxy->viewSize() - IntSize(0, _webPageProxy->topContentInset()));
-    SnapshotOptions options = SnapshotOptionsInViewCoordinates;
-    IntSize bitmapSize = snapshotRect.size();
-    bitmapSize.scale(_scale * _webPageProxy->deviceScaleFactor());
-    _lastSnapshotScale = _scale;
-    _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;
-        [thumbnailView _didTakeSnapshot:cgImage.get()];
-    });
+    [self requestSnapshot];
 }
 
 - (void)_didTakeSnapshot:(CGImageRef)image