Changeset 167775 in webkit


Ignore:
Timestamp:
Apr 24, 2014 2:45:55 PM (10 years ago)
Author:
timothy_horton@apple.com
Message:

WebKit2 View Gestures: Use a single struct for the snapshot, and pass it around
https://bugs.webkit.org/show_bug.cgi?id=132114

Reviewed by Simon Fraser.

Have only a single map in ViewSnapshotStore, from back-forward item
to ViewSnapshotStore::Snapshot, and return the Snapshot struct when looking
up snapshots (via getSnapshot()), so that future patches can persist additional
information along with the snapshot.

  • UIProcess/ios/ViewGestureControllerIOS.mm:

(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::endSwipeGesture):

  • UIProcess/mac/ViewGestureController.h:
  • UIProcess/mac/ViewGestureControllerMac.mm:

(WebKit::ViewGestureController::retrieveSnapshotForItem):
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::endSwipeGesture):
Adopt getSnapshot() instead of snapshotAndRenderTreeSize().
Move retrieveSnapshotForItem out into a separate function (for future use).

  • UIProcess/mac/ViewSnapshotStore.h:

(WebKit::ViewSnapshotStore::disableSnapshotting):
(WebKit::ViewSnapshotStore::enableSnapshotting):

  • UIProcess/mac/ViewSnapshotStore.mm:

(WebKit::ViewSnapshotStore::pruneSnapshots):
(WebKit::ViewSnapshotStore::recordSnapshot):
(WebKit::ViewSnapshotStore::getSnapshot):
(WebKit::ViewSnapshotStore::snapshotAndRenderTreeSize): Deleted.
Make Snapshot struct public.
Get rid of the separate map of back-forward items to render tree sizes.
When evicting, instead of removing the entry, clear out its snapshot image;
this way, we can keep other snapshot metadata around.

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r167774 r167775  
     12014-04-24  Tim Horton  <timothy_horton@apple.com>
     2
     3        WebKit2 View Gestures: Use a single struct for the snapshot, and pass it around
     4        https://bugs.webkit.org/show_bug.cgi?id=132114
     5
     6        Reviewed by Simon Fraser.
     7
     8        Have only a single map in ViewSnapshotStore, from back-forward item
     9        to ViewSnapshotStore::Snapshot, and return the Snapshot struct when looking
     10        up snapshots (via getSnapshot()), so that future patches can persist additional
     11        information along with the snapshot.
     12
     13        * UIProcess/ios/ViewGestureControllerIOS.mm:
     14        (WebKit::ViewGestureController::beginSwipeGesture):
     15        (WebKit::ViewGestureController::endSwipeGesture):
     16        * UIProcess/mac/ViewGestureController.h:
     17        * UIProcess/mac/ViewGestureControllerMac.mm:
     18        (WebKit::ViewGestureController::retrieveSnapshotForItem):
     19        (WebKit::ViewGestureController::beginSwipeGesture):
     20        (WebKit::ViewGestureController::endSwipeGesture):
     21        Adopt getSnapshot() instead of snapshotAndRenderTreeSize().
     22        Move retrieveSnapshotForItem out into a separate function (for future use).
     23
     24        * UIProcess/mac/ViewSnapshotStore.h:
     25        (WebKit::ViewSnapshotStore::disableSnapshotting):
     26        (WebKit::ViewSnapshotStore::enableSnapshotting):
     27        * UIProcess/mac/ViewSnapshotStore.mm:
     28        (WebKit::ViewSnapshotStore::pruneSnapshots):
     29        (WebKit::ViewSnapshotStore::recordSnapshot):
     30        (WebKit::ViewSnapshotStore::getSnapshot):
     31        (WebKit::ViewSnapshotStore::snapshotAndRenderTreeSize): Deleted.
     32        Make Snapshot struct public.
     33        Get rid of the separate map of back-forward items to render tree sizes.
     34        When evicting, instead of removing the entry, clear out its snapshot image;
     35        this way, we can keep other snapshot metadata around.
     36
    1372014-04-24  Enrica Casucci  <enrica@apple.com>
    238
  • trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm

    r167552 r167775  
    152152    WebKit::WebBackForwardListItem* targetItem = direction == SwipeDirection::Left ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
    153153
    154     auto snapshot = WebKit::ViewSnapshotStore::shared().snapshotAndRenderTreeSize(targetItem).first;
    155 
    156154    RetainPtr<UIViewController> snapshotViewController = adoptNS([[UIViewController alloc] init]);
    157155    m_snapshotView = adoptNS([[UIView alloc] initWithFrame:[m_liveSwipeView frame]]);
    158     if (snapshot) {
     156
     157    ViewSnapshotStore::Snapshot snapshot;
     158    if (ViewSnapshotStore::shared().getSnapshot(targetItem, snapshot)) {
    159159#if USE(IOSURFACE)
    160         if (snapshot->setIsVolatile(false) == IOSurface::SurfaceState::Valid) {
    161             [m_snapshotView layer].contents = (id)snapshot->surface();
    162             m_currentSwipeSnapshotSurface = snapshot;
     160        if (snapshot.surface->setIsVolatile(false) == IOSurface::SurfaceState::Valid) {
     161            [m_snapshotView layer].contents = (id)snapshot.surface->surface();
     162            m_currentSwipeSnapshotSurface = snapshot.surface;
    163163        }
    164164#else
    165         [m_snapshotView layer].contents = (id)snapshot.get();
     165        [m_snapshotView layer].contents = (id)snapshot.image.get();
    166166#endif
    167167    }
     
    224224        return;
    225225    }
    226    
    227     m_targetRenderTreeSize = ViewSnapshotStore::shared().snapshotAndRenderTreeSize(targetItem).second * swipeSnapshotRemovalRenderTreeSizeTargetFraction;
    228    
     226
     227    ViewSnapshotStore::Snapshot snapshot;
     228    m_targetRenderTreeSize = 0;
     229    if (ViewSnapshotStore::shared().getSnapshot(targetItem, snapshot))
     230        m_targetRenderTreeSize = snapshot.renderTreeSize * swipeSnapshotRemovalRenderTreeSizeTargetFraction;
     231
    229232    // We don't want to replace the current back-forward item's snapshot
    230233    // like we normally would when going back or forward, because we are
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h

    r167766 r167775  
    131131    bool deltaIsSufficientToBeginSwipe(NSEvent *);
    132132    bool scrollEventCanBecomeSwipe(NSEvent *, SwipeDirection&);
     133    WebCore::IOSurface* retrieveSnapshotForItem(WebBackForwardListItem*);
    133134#endif
    134135   
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

    r167766 r167775  
    427427}
    428428
     429IOSurface* ViewGestureController::retrieveSnapshotForItem(WebBackForwardListItem* targetItem)
     430{
     431    ViewSnapshotStore::Snapshot snapshot;
     432    if (!ViewSnapshotStore::shared().getSnapshot(targetItem, snapshot))
     433        return nullptr;
     434
     435    if (!snapshot.surface)
     436        return nullptr;
     437
     438    if (snapshot.surface->setIsVolatile(false) != IOSurface::SurfaceState::Valid)
     439        return nullptr;
     440
     441    return snapshot.surface.get();
     442}
     443
    429444void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection direction)
    430445{
     
    438453    [m_swipeSnapshotLayer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
    439454
    440     RefPtr<IOSurface> snapshot = ViewSnapshotStore::shared().snapshotAndRenderTreeSize(targetItem).first;
    441 
    442     if (snapshot && snapshot->setIsVolatile(false) == IOSurface::SurfaceState::Valid) {
     455    IOSurface* snapshot = retrieveSnapshotForItem(targetItem);
     456
     457    if (snapshot) {
    443458        m_currentSwipeSnapshotSurface = snapshot;
    444459        [m_swipeSnapshotLayer setContents:(id)snapshot->surface()];
     
    558573    }
    559574
    560     uint64_t renderTreeSize = ViewSnapshotStore::shared().snapshotAndRenderTreeSize(targetItem).second;
     575    ViewSnapshotStore::Snapshot snapshot;
     576    uint64_t renderTreeSize = 0;
     577    if (ViewSnapshotStore::shared().getSnapshot(targetItem, snapshot))
     578        renderTreeSize = snapshot.renderTreeSize;
     579
    561580    m_webPageProxy.process().send(Messages::ViewGestureGeometryCollector::SetRenderTreeSizeNotificationThreshold(renderTreeSize * swipeSnapshotRemovalRenderTreeSizeTargetFraction), m_webPageProxy.pageID());
    562581
  • trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h

    r166005 r167775  
    4747    static ViewSnapshotStore& shared();
    4848
    49     void recordSnapshot(WebPageProxy&);
    50 #if USE(IOSURFACE)
    51     std::pair<RefPtr<WebCore::IOSurface>, uint64_t> snapshotAndRenderTreeSize(WebBackForwardListItem*);
    52 #else
    53     std::pair<RetainPtr<CGImageRef>, uint64_t> snapshotAndRenderTreeSize(WebBackForwardListItem*);
    54 #endif
    55 
    56     void disableSnapshotting() { m_enabled = false; }
    57     void enableSnapshotting() { m_enabled = true; }
    58 
    59 private:
    60     void pruneSnapshots(WebPageProxy&);
    61 
    6249    struct Snapshot {
    6350#if USE(IOSURFACE)
     
    6855
    6956        std::chrono::steady_clock::time_point creationTime;
     57        uint64_t renderTreeSize;
     58
     59        void clearImage();
     60        bool hasImage() const;
    7061    };
    7162
     63    void recordSnapshot(WebPageProxy&);
     64    bool getSnapshot(WebBackForwardListItem*, Snapshot&);
     65
     66    void disableSnapshotting() { m_enabled = false; }
     67    void enableSnapshotting() { m_enabled = true; }
     68
     69private:
     70    void pruneSnapshots(WebPageProxy&);
     71
    7272    HashMap<String, Snapshot> m_snapshotMap;
    73     HashMap<String, uint64_t> m_renderTreeSizeMap;
    7473
    7574    bool m_enabled;
  • trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm

    r166886 r167775  
    7373        WebBackForwardListItem* item = backForwardEntries[i].get();
    7474        String snapshotUUID = item->snapshotUUID();
    75         if (!snapshotUUID.isEmpty() && m_snapshotMap.contains(snapshotUUID)) {
    76             mostDistantSnapshottedItem = item;
    77             maxDistance = distance;
    78         }
     75        if (snapshotUUID.isEmpty())
     76            continue;
     77
     78        const auto& snapshot = m_snapshotMap.find(mostDistantSnapshottedItem->snapshotUUID());
     79        if (snapshot == m_snapshotMap.end())
     80            continue;
     81
     82        // We're only interested in evicting snapshots that still have images.
     83        if (!snapshot->value.hasImage())
     84            continue;
     85
     86        mostDistantSnapshottedItem = item;
     87        maxDistance = distance;
    7988    }
    8089
    8190    if (mostDistantSnapshottedItem) {
    82         m_snapshotMap.remove(mostDistantSnapshottedItem->snapshotUUID());
     91        const auto& snapshot = m_snapshotMap.find(mostDistantSnapshottedItem->snapshotUUID());
     92        snapshot->value.clearImage();
    8393        return;
    8494    }
     
    96106    }
    97107
    98     m_snapshotMap.remove(oldestSnapshotUUID);
     108    const auto& snapshot = m_snapshotMap.find(oldestSnapshotUUID);
     109    snapshot->value.clearImage();
    99110}
    100111
     
    131142
    132143    String oldSnapshotUUID = item->snapshotUUID();
    133     if (!oldSnapshotUUID.isEmpty()) {
     144    if (!oldSnapshotUUID.isEmpty())
    134145        m_snapshotMap.remove(oldSnapshotUUID);
    135         m_renderTreeSizeMap.remove(oldSnapshotUUID);
    136     }
    137146
    138147    item->setSnapshotUUID(createCanonicalUUIDString());
     
    140149    Snapshot snapshot;
    141150    snapshot.creationTime = std::chrono::steady_clock::now();
     151    snapshot.renderTreeSize = webPageProxy.renderTreeSize();
    142152
    143153#if USE(IOSURFACE)
     
    149159
    150160    m_snapshotMap.add(item->snapshotUUID(), snapshot);
    151     m_renderTreeSizeMap.add(item->snapshotUUID(), webPageProxy.renderTreeSize());
    152161}
    153162
    154 #if USE(IOSURFACE)
    155 std::pair<RefPtr<IOSurface>, uint64_t> ViewSnapshotStore::snapshotAndRenderTreeSize(WebBackForwardListItem* item)
    156 #else
    157 std::pair<RetainPtr<CGImageRef>, uint64_t> ViewSnapshotStore::snapshotAndRenderTreeSize(WebBackForwardListItem* item)
    158 #endif
     163bool ViewSnapshotStore::getSnapshot(WebBackForwardListItem* item, ViewSnapshotStore::Snapshot& snapshot)
    159164{
    160165    if (item->snapshotUUID().isEmpty())
    161         return std::make_pair(nullptr, 0);
     166        return false;
    162167
    163     const auto& renderTreeSize = m_renderTreeSizeMap.find(item->snapshotUUID());
    164     if (renderTreeSize == m_renderTreeSizeMap.end())
    165         return std::make_pair(nullptr, 0);
     168    const auto& snapshotIterator = m_snapshotMap.find(item->snapshotUUID());
     169    if (snapshotIterator == m_snapshotMap.end())
     170        return false;
     171    snapshot = snapshotIterator->value;
     172    return true;
     173}
    166174
    167     const auto& snapshot = m_snapshotMap.find(item->snapshotUUID());
     175void ViewSnapshotStore::Snapshot::clearImage()
     176{
     177#if USE(IOSURFACE)
     178    surface = nullptr;
     179#else
     180    image = nullptr;
     181#endif
     182}
    168183
    169     if (snapshot == m_snapshotMap.end())
    170         return std::make_pair(nullptr, renderTreeSize->value);
    171    
     184bool ViewSnapshotStore::Snapshot::hasImage() const
     185{
    172186#if USE(IOSURFACE)
    173     return std::make_pair(snapshot->value.surface, renderTreeSize->value);
     187    return surface;
    174188#else
    175     return std::make_pair(snapshot->value.image, renderTreeSize->value);
     189    return image;
    176190#endif
    177191}
Note: See TracChangeset for help on using the changeset viewer.