Changeset 165748 in webkit


Ignore:
Timestamp:
Mar 17, 2014 1:04:47 PM (10 years ago)
Author:
timothy_horton@apple.com
Message:

WKThumbnailView should support snapshots
https://bugs.webkit.org/show_bug.cgi?id=130335
<rdar://problem/16255139>

Reviewed by Simon Fraser.

Add a mode where WKThumbnailView takes a software snapshot of the web content,
replacing the live layer tree with said snapshot once it returns from the
web process. This may improve animation performance in cases where the
layer tree would otherwise be very complex.

  • UIProcess/API/Cocoa/WKThumbnailView.h:

Add a property, usesSnapshot, which determines whether the thumbnail view
should use the live layer tree or a snapshot of the content.

  • UIProcess/API/Cocoa/WKThumbnailView.mm:

(-[WKThumbnailView initWithFrame:fromWKView:]):
(-[WKThumbnailView _viewWasUnparented]):
Clear the snapshot when unparented.

(-[WKThumbnailView _viewWasParented]):
Take a snapshot of the web content when parented, if needed.

(-[WKThumbnailView _requestSnapshotIfNeeded]):
If we're using snapshots, and haven't already dispatched an async snapshot request,
and don't already have a snapshot, request a snapshot from the web process.

When it returns, use it as the contents of the WKThumbnailView layer, and
unparent the live layer tree.

(-[WKThumbnailView setScale:]):
(-[WKThumbnailView setUsesSnapshot:]):
(-[WKThumbnailView _setThumbnailLayer:]):
(-[WKThumbnailView _thumbnailLayer]):

  • UIProcess/API/Cocoa/WKThumbnailViewInternal.h:
  • UIProcess/API/mac/WKView.mm:

(-[WKView _setAcceleratedCompositingModeRootLayer:]):
(-[WKView _acceleratedCompositingModeRootLayer]):
WKView should always keep track of the current root layer, instead of totally
handing control over to WKThumbnailView when it is used.

(-[WKView _setThumbnailView:]):
(-[WKView _updateThumbnailViewLayer]):
(-[WKView _reparentLayerTreeInThumbnailView]):
If needed (either we're not using snapshots, or still waiting for the snapshot to be painted),
push the WKView's live layer tree into the thumbnail view.

  • UIProcess/API/mac/WKViewInternal.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::internalShowContextMenu):

  • UIProcess/WebPageProxy.h:
  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::takeThumbnailSnapshot):
Add a message that asynchronously returns a snapshot that respects the
current thumbnail scale and position.

(WebKit::WebPage::scaledSnapshotWithOptions):
Use some nullptr.

  • WebProcess/WebPage/DrawingArea.cpp:

(WebKit::DrawingArea::transform):

  • WebProcess/WebPage/DrawingArea.h:
  • WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:

Add a getter for the DrawingArea's transform.
Rename it to rootLayerTransform.

  • WebCore.exp.in:
Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r165742 r165748  
     12014-03-17  Tim Horton  <timothy_horton@apple.com>
     2
     3        WKThumbnailView should support snapshots
     4        https://bugs.webkit.org/show_bug.cgi?id=130335
     5        <rdar://problem/16255139>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * WebCore.exp.in:
     10
    1112014-01-29  Sergio Villar Senin  <svillar@igalia.com>
    212
  • trunk/Source/WebCore/WebCore.exp.in

    r165653 r165748  
    17311731__ZNK7WebCore20ResourceResponseBase6isHTTPEv
    17321732__ZNK7WebCore20ResourceResponseBase8mimeTypeEv
     1733__ZNK7WebCore20TransformationMatrix7inverseEv
     1734__ZNK7WebCore20TransformationMatrix7mapRectERKNS_7IntRectE
    17331735__ZNK7WebCore20TransformationMatrixcv13CATransform3DEv
    17341736__ZNK7WebCore21BackForwardController12forwardCountEv
  • trunk/Source/WebKit2/ChangeLog

    r165746 r165748  
     12014-03-17  Tim Horton  <timothy_horton@apple.com>
     2
     3        WKThumbnailView should support snapshots
     4        https://bugs.webkit.org/show_bug.cgi?id=130335
     5        <rdar://problem/16255139>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Add a mode where WKThumbnailView takes a software snapshot of the web content,
     10        replacing the live layer tree with said snapshot once it returns from the
     11        web process. This may improve animation performance in cases where the
     12        layer tree would otherwise be very complex.
     13
     14        * UIProcess/API/Cocoa/WKThumbnailView.h:
     15        Add a property, usesSnapshot, which determines whether the thumbnail view
     16        should use the live layer tree or a snapshot of the content.
     17
     18        * UIProcess/API/Cocoa/WKThumbnailView.mm:
     19        (-[WKThumbnailView initWithFrame:fromWKView:]):
     20        (-[WKThumbnailView _viewWasUnparented]):
     21        Clear the snapshot when unparented.
     22
     23        (-[WKThumbnailView _viewWasParented]):
     24        Take a snapshot of the web content when parented, if needed.
     25
     26        (-[WKThumbnailView _requestSnapshotIfNeeded]):
     27        If we're using snapshots, and haven't already dispatched an async snapshot request,
     28        and don't already have a snapshot, request a snapshot from the web process.
     29
     30        When it returns, use it as the contents of the WKThumbnailView layer, and
     31        unparent the live layer tree.
     32
     33        (-[WKThumbnailView setScale:]):
     34        (-[WKThumbnailView setUsesSnapshot:]):
     35        (-[WKThumbnailView _setThumbnailLayer:]):
     36        (-[WKThumbnailView _thumbnailLayer]):
     37        * UIProcess/API/Cocoa/WKThumbnailViewInternal.h:
     38
     39        * UIProcess/API/mac/WKView.mm:
     40        (-[WKView _setAcceleratedCompositingModeRootLayer:]):
     41        (-[WKView _acceleratedCompositingModeRootLayer]):
     42        WKView should always keep track of the current root layer, instead of totally
     43        handing control over to WKThumbnailView when it is used.
     44
     45        (-[WKView _setThumbnailView:]):
     46        (-[WKView _updateThumbnailViewLayer]):
     47        (-[WKView _reparentLayerTreeInThumbnailView]):
     48        If needed (either we're not using snapshots, or still waiting for the snapshot to be painted),
     49        push the WKView's live layer tree into the thumbnail view.
     50
     51        * UIProcess/API/mac/WKViewInternal.h:
     52        * UIProcess/WebPageProxy.cpp:
     53        (WebKit::WebPageProxy::internalShowContextMenu):
     54        * UIProcess/WebPageProxy.h:
     55        * WebProcess/WebPage/WebPage.h:
     56        * WebProcess/WebPage/WebPage.messages.in:
     57        * WebProcess/WebPage/WebPage.cpp:
     58        (WebKit::WebPage::takeThumbnailSnapshot):
     59        Add a message that asynchronously returns a snapshot that respects the
     60        current thumbnail scale and position.
     61
     62        (WebKit::WebPage::scaledSnapshotWithOptions):
     63        Use some nullptr.
     64
     65        * WebProcess/WebPage/DrawingArea.cpp:
     66        (WebKit::DrawingArea::transform):
     67        * WebProcess/WebPage/DrawingArea.h:
     68        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
     69        Add a getter for the DrawingArea's transform.
     70        Rename it to rootLayerTransform.
     71
    1722014-03-17  Zan Dobersek  <zdobersek@igalia.com>
    273
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKThumbnailView.h

    r164776 r165748  
    4040
    4141@property (nonatomic) CGFloat scale;
     42@property (nonatomic) BOOL usesSnapshot;
    4243
    4344@end
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKThumbnailView.mm

    r164776 r165748  
    5555}
    5656
     57@synthesize _waitingForSnapshot = _waitingForSnapshot;
     58
    5759- (instancetype)initWithFrame:(NSRect)frame fromWKView:(WKView *)wkView
    5860{
     
    7779
    7880    [_wkView _setThumbnailView:nil];
     81
     82    self.layer.contents = nil;
     83
    7984    _webPageProxy->setMayStartMediaWhenInWindow(_originalMayStartMediaWhenInWindow);
    8085}
     
    9196        _webPageProxy->setMayStartMediaWhenInWindow(false);
    9297
     98    [self _requestSnapshotIfNeeded];
    9399    [_wkView _setThumbnailView:self];
     100}
     101
     102- (void)_requestSnapshotIfNeeded
     103{
     104    if (!_usesSnapshot || _waitingForSnapshot || self.layer.contents)
     105        return;
     106
     107    _waitingForSnapshot = YES;
     108
     109    RetainPtr<WKThumbnailView> thumbnailView = self;
     110    _webPageProxy->takeThumbnailSnapshot([thumbnailView](bool, const ShareableBitmap::Handle& imageHandle) {
     111        RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageHandle, SharedMemory::ReadOnly);
     112        RetainPtr<CGImageRef> cgImage = bitmap->makeCGImage();
     113        [thumbnailView _didTakeSnapshot:cgImage.get()];
     114    });
     115}
     116
     117- (void)_didTakeSnapshot:(CGImageRef)image
     118{
     119    _waitingForSnapshot = NO;
     120    self.layer.sublayers = @[];
     121    self.layer.contents = (id)image;
    94122}
    95123
     
    104132- (void)setScale:(CGFloat)scale
    105133{
     134    if (_scale == scale)
     135        return;
     136
    106137    _scale = scale;
    107138
     
    110141}
    111142
    112 - (void)setThumbnailLayer:(CALayer *)layer
     143- (void)setUsesSnapshot:(BOOL)usesSnapshot
     144{
     145    if (_usesSnapshot == usesSnapshot)
     146        return;
     147
     148    _usesSnapshot = usesSnapshot;
     149
     150    if (!self.window)
     151        return;
     152
     153    if (usesSnapshot)
     154        [self _requestSnapshotIfNeeded];
     155    else
     156        [_wkView _reparentLayerTreeInThumbnailView];
     157}
     158
     159- (void)_setThumbnailLayer:(CALayer *)layer
    113160{
    114161    self.layer.sublayers = layer ? @[ layer ] : @[ ];
    115162}
    116163
    117 - (CALayer *)thumbnailLayer
     164- (CALayer *)_thumbnailLayer
    118165{
    119166    if (!self.layer.sublayers.count)
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKThumbnailViewInternal.h

    r164776 r165748  
    3232@interface WKThumbnailView ()
    3333
    34 @property (nonatomic, assign) CALayer *thumbnailLayer;
     34@property (nonatomic, assign, setter = _setThumbnailLayer:) CALayer *_thumbnailLayer;
     35@property (nonatomic, assign, setter = _setWaitingForSnapshot:) BOOL _waitingForSnapshot;
    3536
    3637@end
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r165477 r165748  
    225225    BOOL _allowsMagnification;
    226226    BOOL _allowsBackForwardNavigationGestures;
     227
     228    RetainPtr<CALayer> _rootLayer;
    227229
    228230#if WK_API_ENABLED
     
    24992501    [rootLayer web_disableAllActions];
    25002502
     2503    _data->_rootLayer = rootLayer;
     2504
    25012505#if WK_API_ENABLED
    25022506    if (_data->_thumbnailView) {
    2503         _data->_thumbnailView.thumbnailLayer = rootLayer;
     2507        [self _updateThumbnailViewLayer];
    25042508        return;
    25052509    }
     
    25452549- (CALayer *)_acceleratedCompositingModeRootLayer
    25462550{
    2547     NSView *hostView = _data->_layerHostingView.get();
    2548 
    2549     if (!hostView)
    2550         return nullptr;
    2551 
    2552     if (!hostView.layer.sublayers.count)
    2553         return nullptr;
    2554 
    2555     return [hostView.layer.sublayers objectAtIndex:0];
     2551    return _data->_rootLayer.get();
    25562552}
    25572553
     
    29752971    ASSERT(!_data->_thumbnailView || !thumbnailView);
    29762972
    2977     RetainPtr<CALayer> thumbnailLayer = _data->_thumbnailView.thumbnailLayer;
    2978 
    29792973    _data->_thumbnailView = thumbnailView;
    29802974
    29812975    if (thumbnailView)
    2982         thumbnailView.thumbnailLayer = [self _acceleratedCompositingModeRootLayer];
     2976        [self _updateThumbnailViewLayer];
    29832977    else
    2984         [self _setAcceleratedCompositingModeRootLayer:thumbnailLayer.get()];
     2978        [self _setAcceleratedCompositingModeRootLayer:_data->_rootLayer.get()];
    29852979
    29862980    _data->_page->viewStateDidChange(ViewState::WindowIsActive | ViewState::IsInWindow | ViewState::IsVisible);
     
    29902984{
    29912985    return _data->_thumbnailView;
     2986}
     2987
     2988- (void)_updateThumbnailViewLayer
     2989{
     2990    WKThumbnailView *thumbnailView = _data->_thumbnailView;
     2991    ASSERT(thumbnailView);
     2992
     2993    if (!thumbnailView.usesSnapshot || thumbnailView._waitingForSnapshot)
     2994        [self _reparentLayerTreeInThumbnailView];
     2995}
     2996
     2997- (void)_reparentLayerTreeInThumbnailView
     2998{
     2999    _data->_thumbnailView._thumbnailLayer = _data->_rootLayer.get();
    29923000}
    29933001#endif // WK_API_ENABLED
  • trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h

    r164341 r165748  
    110110#if WK_API_ENABLED
    111111@property (nonatomic, setter=_setThumbnailView:) WKThumbnailView *_thumbnailView;
     112- (void)_reparentLayerTreeInThumbnailView;
    112113#endif
    113114
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r165692 r165748  
    45684568}
    45694569
     4570void WebPageProxy::takeThumbnailSnapshot(ImageCallback::CallbackFunction callbackFunction)
     4571{
     4572    if (!isValid())
     4573        return;
     4574
     4575    RefPtr<ImageCallback> callback = ImageCallback::create(callbackFunction);
     4576
     4577    uint64_t callbackID = callback->callbackID();
     4578    m_imageCallbacks.set(callbackID, callback.get());
     4579
     4580    m_process->send(Messages::WebPage::TakeThumbnailSnapshot(callbackID), m_pageID);
     4581}
     4582
    45704583} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r165577 r165748  
    918918    void setThumbnailScale(double);
    919919
     920    void takeThumbnailSnapshot(ImageCallback::CallbackFunction);
     921
    920922private:
    921923    WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.cpp

    r164192 r165748  
    2626#include "config.h"
    2727#include "DrawingArea.h"
     28#include <WebCore/TransformationMatrix.h>
    2829#include <wtf/Functional.h>
    2930
     
    4142
    4243#include "WebPageCreationParameters.h"
     44
     45using namespace WebCore;
    4346
    4447namespace WebKit {
     
    8487}
    8588
     89TransformationMatrix DrawingArea::rootLayerTransform() const
     90{
     91    return TransformationMatrix();
     92}
     93
    8694} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h

    r165235 r165748  
    108108    virtual void scheduleCompositingLayerFlush() = 0;
    109109
    110     virtual void setTransform(const WebCore::TransformationMatrix&) { }
     110    virtual WebCore::TransformationMatrix rootLayerTransform() const;
     111    virtual void setRootLayerTransform(const WebCore::TransformationMatrix&) { }
    111112
    112113#if USE(COORDINATED_GRAPHICS)
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r165746 r165748  
    15141514#endif // !PLATFORM(IOS)
    15151515
     1516void WebPage::takeThumbnailSnapshot(uint64_t callbackID)
     1517{
     1518    IntRect snapshotRect(IntPoint(), m_viewSize);
     1519    snapshotRect = m_drawingArea->rootLayerTransform().inverse().mapRect(snapshotRect);
     1520
     1521    RefPtr<WebImage> image = scaledSnapshotWithOptions(snapshotRect, 1, SnapshotOptionsShareable | SnapshotOptionsInViewCoordinates);
     1522
     1523    ShareableBitmap::Handle handle;
     1524    if (image)
     1525        image->bitmap()->createHandle(handle, SharedMemory::ReadOnly);
     1526
     1527    send(Messages::WebPageProxy::ImageCallback(handle, callbackID));
     1528}
     1529
    15161530PassRefPtr<WebImage> WebPage::scaledSnapshotWithOptions(const IntRect& rect, double scaleFactor, SnapshotOptions options)
    15171531{
    15181532    Frame* coreFrame = m_mainFrame->coreFrame();
    15191533    if (!coreFrame)
    1520         return 0;
     1534        return nullptr;
    15211535
    15221536    FrameView* frameView = coreFrame->view();
    15231537    if (!frameView)
    1524         return 0;
     1538        return nullptr;
    15251539
    15261540    IntSize bitmapSize = rect.size();
     
    15301544    RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options));
    15311545    if (!snapshot->bitmap())
    1532         return 0;
     1546        return nullptr;
    15331547
    15341548    auto graphicsContext = snapshot->bitmap()->createGraphicsContext();
     
    43084322    transform.scale(inverseScale);
    43094323
    4310     drawingArea()->setTransform(transform);
     4324    drawingArea()->setRootLayerTransform(transform);
    43114325}
    43124326
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r165577 r165748  
    847847    void runJavaScriptInMainFrame(const String&, uint64_t callbackID);
    848848    void forceRepaint(uint64_t callbackID);
     849    void takeThumbnailSnapshot(uint64_t callbackID);
    849850
    850851    void preferencesDidChange(const WebPreferencesStore&);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r165303 r165748  
    337337
    338338    GetBytecodeProfile(uint64_t callbackID)
     339   
     340    TakeThumbnailSnapshot(uint64_t callbackID)
    339341
    340342}
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h

    r165235 r165748  
    113113    void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
    114114
    115     virtual void setTransform(const WebCore::TransformationMatrix&) override;
     115    virtual WebCore::TransformationMatrix rootLayerTransform() const override {  return m_transform; }
     116    virtual void setRootLayerTransform(const WebCore::TransformationMatrix&) override;
    116117
    117118    void updateLayerHostingContext();
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm

    r165404 r165748  
    827827}
    828828
    829 void TiledCoreAnimationDrawingArea::setTransform(const TransformationMatrix& transform)
     829void TiledCoreAnimationDrawingArea::setRootLayerTransform(const TransformationMatrix& transform)
    830830{
    831831    m_transform = transform;
Note: See TracChangeset for help on using the changeset viewer.