Changeset 167775 in webkit
- Timestamp:
- Apr 24, 2014 2:45:55 PM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r167774 r167775 1 2014-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 1 37 2014-04-24 Enrica Casucci <enrica@apple.com> 2 38 -
trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm
r167552 r167775 152 152 WebKit::WebBackForwardListItem* targetItem = direction == SwipeDirection::Left ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem(); 153 153 154 auto snapshot = WebKit::ViewSnapshotStore::shared().snapshotAndRenderTreeSize(targetItem).first;155 156 154 RetainPtr<UIViewController> snapshotViewController = adoptNS([[UIViewController alloc] init]); 157 155 m_snapshotView = adoptNS([[UIView alloc] initWithFrame:[m_liveSwipeView frame]]); 158 if (snapshot) { 156 157 ViewSnapshotStore::Snapshot snapshot; 158 if (ViewSnapshotStore::shared().getSnapshot(targetItem, snapshot)) { 159 159 #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; 163 163 } 164 164 #else 165 [m_snapshotView layer].contents = (id)snapshot. get();165 [m_snapshotView layer].contents = (id)snapshot.image.get(); 166 166 #endif 167 167 } … … 224 224 return; 225 225 } 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 229 232 // We don't want to replace the current back-forward item's snapshot 230 233 // like we normally would when going back or forward, because we are -
trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h
r167766 r167775 131 131 bool deltaIsSufficientToBeginSwipe(NSEvent *); 132 132 bool scrollEventCanBecomeSwipe(NSEvent *, SwipeDirection&); 133 WebCore::IOSurface* retrieveSnapshotForItem(WebBackForwardListItem*); 133 134 #endif 134 135 -
trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm
r167766 r167775 427 427 } 428 428 429 IOSurface* 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 429 444 void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection direction) 430 445 { … … 438 453 [m_swipeSnapshotLayer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; 439 454 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) { 443 458 m_currentSwipeSnapshotSurface = snapshot; 444 459 [m_swipeSnapshotLayer setContents:(id)snapshot->surface()]; … … 558 573 } 559 574 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 561 580 m_webPageProxy.process().send(Messages::ViewGestureGeometryCollector::SetRenderTreeSizeNotificationThreshold(renderTreeSize * swipeSnapshotRemovalRenderTreeSizeTargetFraction), m_webPageProxy.pageID()); 562 581 -
trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h
r166005 r167775 47 47 static ViewSnapshotStore& shared(); 48 48 49 void recordSnapshot(WebPageProxy&);50 #if USE(IOSURFACE)51 std::pair<RefPtr<WebCore::IOSurface>, uint64_t> snapshotAndRenderTreeSize(WebBackForwardListItem*);52 #else53 std::pair<RetainPtr<CGImageRef>, uint64_t> snapshotAndRenderTreeSize(WebBackForwardListItem*);54 #endif55 56 void disableSnapshotting() { m_enabled = false; }57 void enableSnapshotting() { m_enabled = true; }58 59 private:60 void pruneSnapshots(WebPageProxy&);61 62 49 struct Snapshot { 63 50 #if USE(IOSURFACE) … … 68 55 69 56 std::chrono::steady_clock::time_point creationTime; 57 uint64_t renderTreeSize; 58 59 void clearImage(); 60 bool hasImage() const; 70 61 }; 71 62 63 void recordSnapshot(WebPageProxy&); 64 bool getSnapshot(WebBackForwardListItem*, Snapshot&); 65 66 void disableSnapshotting() { m_enabled = false; } 67 void enableSnapshotting() { m_enabled = true; } 68 69 private: 70 void pruneSnapshots(WebPageProxy&); 71 72 72 HashMap<String, Snapshot> m_snapshotMap; 73 HashMap<String, uint64_t> m_renderTreeSizeMap;74 73 75 74 bool m_enabled; -
trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm
r166886 r167775 73 73 WebBackForwardListItem* item = backForwardEntries[i].get(); 74 74 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; 79 88 } 80 89 81 90 if (mostDistantSnapshottedItem) { 82 m_snapshotMap.remove(mostDistantSnapshottedItem->snapshotUUID()); 91 const auto& snapshot = m_snapshotMap.find(mostDistantSnapshottedItem->snapshotUUID()); 92 snapshot->value.clearImage(); 83 93 return; 84 94 } … … 96 106 } 97 107 98 m_snapshotMap.remove(oldestSnapshotUUID); 108 const auto& snapshot = m_snapshotMap.find(oldestSnapshotUUID); 109 snapshot->value.clearImage(); 99 110 } 100 111 … … 131 142 132 143 String oldSnapshotUUID = item->snapshotUUID(); 133 if (!oldSnapshotUUID.isEmpty()) {144 if (!oldSnapshotUUID.isEmpty()) 134 145 m_snapshotMap.remove(oldSnapshotUUID); 135 m_renderTreeSizeMap.remove(oldSnapshotUUID);136 }137 146 138 147 item->setSnapshotUUID(createCanonicalUUIDString()); … … 140 149 Snapshot snapshot; 141 150 snapshot.creationTime = std::chrono::steady_clock::now(); 151 snapshot.renderTreeSize = webPageProxy.renderTreeSize(); 142 152 143 153 #if USE(IOSURFACE) … … 149 159 150 160 m_snapshotMap.add(item->snapshotUUID(), snapshot); 151 m_renderTreeSizeMap.add(item->snapshotUUID(), webPageProxy.renderTreeSize());152 161 } 153 162 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 163 bool ViewSnapshotStore::getSnapshot(WebBackForwardListItem* item, ViewSnapshotStore::Snapshot& snapshot) 159 164 { 160 165 if (item->snapshotUUID().isEmpty()) 161 return std::make_pair(nullptr, 0);166 return false; 162 167 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 } 166 174 167 const auto& snapshot = m_snapshotMap.find(item->snapshotUUID()); 175 void ViewSnapshotStore::Snapshot::clearImage() 176 { 177 #if USE(IOSURFACE) 178 surface = nullptr; 179 #else 180 image = nullptr; 181 #endif 182 } 168 183 169 if (snapshot == m_snapshotMap.end()) 170 return std::make_pair(nullptr, renderTreeSize->value); 171 184 bool ViewSnapshotStore::Snapshot::hasImage() const 185 { 172 186 #if USE(IOSURFACE) 173 return s td::make_pair(snapshot->value.surface, renderTreeSize->value);187 return surface; 174 188 #else 175 return std::make_pair(snapshot->value.image, renderTreeSize->value);189 return image; 176 190 #endif 177 191 }
Note: See TracChangeset
for help on using the changeset viewer.