Changeset 242670 in webkit
- Timestamp:
- Mar 8, 2019, 6:35:57 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
page/scrolling/ScrollingTree.cpp (modified) (11 diffs)
-
page/scrolling/ScrollingTree.h (modified) (5 diffs)
-
page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm (modified) (1 diff)
-
platform/graphics/FloatPoint.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r242669 r242670 1 2019-03-08 Simon Fraser <simon.fraser@apple.com> 2 3 Make it clearer which data is protected by the two locks in ScrollingTree 4 https://bugs.webkit.org/show_bug.cgi?id=195501 5 6 Reviewed by Tim Horton. 7 8 Gather ScrollingTree member variables into two structs, and name the struct 9 members and the locks to make it clear which data is protected by each lock. 10 11 We only need to protect data read by multiple threads; these are the scrolling 12 thread, the event handling thread (which runs ThreadedScrollingTree::tryToHandleWheelEvent()), 13 and the main thread, which pokes various bits of pin/rubber-banding state. 14 Ideally the main thread would always push data to the scrolling thread via a commit, 15 but that's not what happens now. 16 17 Suspiciously, ScrollingTree::shouldHandleWheelEventSynchronously() uses the root node, 18 so should probably hold a lock shared with the scrolling thread (webkit.org/b/195502). 19 20 * page/scrolling/ScrollingTree.cpp: 21 (WebCore::ScrollingTree::shouldHandleWheelEventSynchronously): 22 (WebCore::ScrollingTree::commitTreeState): 23 (WebCore::ScrollingTree::setAsyncFrameOrOverflowScrollingEnabled): 24 (WebCore::ScrollingTree::setMainFrameScrollPosition): 25 (WebCore::ScrollingTree::eventTrackingTypeForPoint): 26 (WebCore::ScrollingTree::isRubberBandInProgress): 27 (WebCore::ScrollingTree::setMainFrameIsRubberBanding): 28 (WebCore::ScrollingTree::isScrollSnapInProgress): 29 (WebCore::ScrollingTree::setMainFrameIsScrollSnapping): 30 (WebCore::ScrollingTree::setMainFramePinState): 31 (WebCore::ScrollingTree::setCanRubberBandState): 32 (WebCore::ScrollingTree::setScrollPinningBehavior): 33 (WebCore::ScrollingTree::scrollPinningBehavior): 34 (WebCore::ScrollingTree::willWheelEventStartSwipeGesture): 35 (WebCore::ScrollingTree::latchedNode): 36 (WebCore::ScrollingTree::setLatchedNode): 37 (WebCore::ScrollingTree::clearLatchedNode): 38 (WebCore::ScrollingTree::scrollingTreeAsText): 39 (WebCore::ScrollingTree::touchActionDataAtPoint const): 40 (WebCore::ScrollingTree::mainFrameScrollPosition): Deleted. 41 (WebCore::ScrollingTree::mainFrameLayoutViewport): Deleted. 42 (WebCore::ScrollingTree::rubberBandsAtLeft): Deleted. 43 (WebCore::ScrollingTree::rubberBandsAtRight): Deleted. 44 (WebCore::ScrollingTree::rubberBandsAtBottom): Deleted. 45 (WebCore::ScrollingTree::rubberBandsAtTop): Deleted. 46 * page/scrolling/ScrollingTree.h: 47 (WebCore::ScrollingTree::hasLatchedNode const): 48 * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm: 49 (WebCore::ScrollingTreeScrollingNodeDelegateMac::stretchAmount): 50 * platform/graphics/FloatPoint.h: 51 (WebCore::FloatPoint::isZero const): 52 1 53 2019-03-08 Simon Fraser <simon.fraser@apple.com> 2 54 -
trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp
r242359 r242670 50 50 { 51 51 // This method is invoked by the event handling thread 52 LockHolder lock(m_ mutex);52 LockHolder lock(m_treeStateMutex); 53 53 54 54 bool shouldSetLatch = wheelEvent.shouldConsiderLatching(); … … 58 58 59 59 if (shouldSetLatch) 60 m_ latchedNodeID = 0;61 62 if (!m_ eventTrackingRegions.isEmpty() && m_rootNode) {60 m_treeState.latchedNodeID = 0; 61 62 if (!m_treeState.eventTrackingRegions.isEmpty() && m_rootNode) { 63 63 auto& frameScrollingNode = downcast<ScrollingTreeFrameScrollingNode>(*m_rootNode); 64 64 FloatPoint position = wheelEvent.position(); 65 position.move(frameScrollingNode.viewToContentsOffset(m_ mainFrameScrollPosition));65 position.move(frameScrollingNode.viewToContentsOffset(m_treeState.mainFrameScrollPosition)); 66 66 67 67 const EventNames& names = eventNames(); … … 69 69 70 70 // Event regions are affected by page scale, so no need to map through scale. 71 bool isSynchronousDispatchRegion = m_ eventTrackingRegions.trackingTypeForPoint(names.wheelEvent, roundedPosition) == TrackingType::Synchronous72 || m_ eventTrackingRegions.trackingTypeForPoint(names.mousewheelEvent, roundedPosition) == TrackingType::Synchronous;71 bool isSynchronousDispatchRegion = m_treeState.eventTrackingRegions.trackingTypeForPoint(names.wheelEvent, roundedPosition) == TrackingType::Synchronous 72 || m_treeState.eventTrackingRegions.trackingTypeForPoint(names.mousewheelEvent, roundedPosition) == TrackingType::Synchronous; 73 73 LOG_WITH_STREAM(Scrolling, stream << "ScrollingTree::shouldHandleWheelEventSynchronously: wheelEvent at " << wheelEvent.position() << " mapped to content point " << position << ", in non-fast region " << isSynchronousDispatchRegion); 74 74 … … 151 151 || rootNode->hasChangedProperty(ScrollingStateScrollingNode::ScrolledContentsLayer) 152 152 || rootNode->hasChangedProperty(ScrollingStateFrameScrollingNode::AsyncFrameOrOverflowScrollingEnabled))) { 153 LockHolder lock(m_ mutex);153 LockHolder lock(m_treeStateMutex); 154 154 155 155 if (rootStateNodeChanged || rootNode->hasChangedProperty(ScrollingStateScrollingNode::ScrolledContentsLayer)) 156 m_ mainFrameScrollPosition = FloatPoint();156 m_treeState.mainFrameScrollPosition = { }; 157 157 158 158 if (rootStateNodeChanged || rootNode->hasChangedProperty(ScrollingStateFrameScrollingNode::EventTrackingRegion)) 159 m_ eventTrackingRegions = scrollingStateTree->rootStateNode()->eventTrackingRegions();159 m_treeState.eventTrackingRegions = scrollingStateTree->rootStateNode()->eventTrackingRegions(); 160 160 161 161 if (rootStateNodeChanged || rootNode->hasChangedProperty(ScrollingStateFrameScrollingNode::AsyncFrameOrOverflowScrollingEnabled)) … … 177 177 178 178 for (auto nodeID : unvisitedNodes) { 179 if (nodeID == m_ latchedNodeID)179 if (nodeID == m_treeState.latchedNodeID) 180 180 clearLatchedNode(); 181 181 … … 288 288 void ScrollingTree::setAsyncFrameOrOverflowScrollingEnabled(bool enabled) 289 289 { 290 LockHolder lock(m_mutex);291 290 m_asyncFrameOrOverflowScrollingEnabled = enabled; 292 291 } 293 292 293 void ScrollingTree::setMainFrameScrollPosition(FloatPoint position) 294 { 295 LockHolder lock(m_treeStateMutex); 296 m_treeState.mainFrameScrollPosition = position; 297 } 298 299 TrackingType ScrollingTree::eventTrackingTypeForPoint(const AtomicString& eventName, IntPoint p) 300 { 301 LockHolder lock(m_treeStateMutex); 302 return m_treeState.eventTrackingRegions.trackingTypeForPoint(eventName, p); 303 } 304 305 // Can be called from the main thread. 306 bool ScrollingTree::isRubberBandInProgress() 307 { 308 LockHolder lock(m_treeStateMutex); 309 return m_treeState.mainFrameIsRubberBanding; 310 } 311 312 void ScrollingTree::setMainFrameIsRubberBanding(bool isRubberBanding) 313 { 314 LockHolder locker(m_treeStateMutex); 315 m_treeState.mainFrameIsRubberBanding = isRubberBanding; 316 } 317 318 // Can be called from the main thread. 319 bool ScrollingTree::isScrollSnapInProgress() 320 { 321 LockHolder lock(m_treeStateMutex); 322 return m_treeState.mainFrameIsScrollSnapping; 323 } 324 325 void ScrollingTree::setMainFrameIsScrollSnapping(bool isScrollSnapping) 326 { 327 LockHolder locker(m_treeStateMutex); 328 m_treeState.mainFrameIsScrollSnapping = isScrollSnapping; 329 } 330 294 331 void ScrollingTree::setMainFramePinState(bool pinnedToTheLeft, bool pinnedToTheRight, bool pinnedToTheTop, bool pinnedToTheBottom) 295 332 { 296 333 LockHolder locker(m_swipeStateMutex); 297 334 298 m_mainFramePinnedToTheLeft = pinnedToTheLeft; 299 m_mainFramePinnedToTheRight = pinnedToTheRight; 300 m_mainFramePinnedToTheTop = pinnedToTheTop; 301 m_mainFramePinnedToTheBottom = pinnedToTheBottom; 302 } 303 304 FloatPoint ScrollingTree::mainFrameScrollPosition() 305 { 306 LockHolder lock(m_mutex); 307 return m_mainFrameScrollPosition; 308 } 309 310 FloatRect ScrollingTree::mainFrameLayoutViewport() 311 { 312 if (!m_rootNode) 313 return { }; 314 315 auto& frameScrollingNode = downcast<ScrollingTreeFrameScrollingNode>(*m_rootNode); 316 return frameScrollingNode.layoutViewport(); 317 } 318 319 void ScrollingTree::setMainFrameScrollPosition(FloatPoint position) 320 { 321 LockHolder lock(m_mutex); 322 m_mainFrameScrollPosition = position; 323 } 324 325 TrackingType ScrollingTree::eventTrackingTypeForPoint(const AtomicString& eventName, IntPoint p) 326 { 327 LockHolder lock(m_mutex); 328 329 return m_eventTrackingRegions.trackingTypeForPoint(eventName, p); 330 } 331 332 bool ScrollingTree::isRubberBandInProgress() 333 { 334 LockHolder lock(m_mutex); 335 336 return m_mainFrameIsRubberBanding; 337 } 338 339 void ScrollingTree::setMainFrameIsRubberBanding(bool isRubberBanding) 340 { 341 LockHolder locker(m_mutex); 342 343 m_mainFrameIsRubberBanding = isRubberBanding; 344 } 345 346 bool ScrollingTree::isScrollSnapInProgress() 347 { 348 LockHolder lock(m_mutex); 349 350 return m_mainFrameIsScrollSnapping; 351 } 352 353 void ScrollingTree::setMainFrameIsScrollSnapping(bool isScrollSnapping) 354 { 355 LockHolder locker(m_mutex); 356 357 m_mainFrameIsScrollSnapping = isScrollSnapping; 335 m_swipeState.mainFramePinnedToTheLeft = pinnedToTheLeft; 336 m_swipeState.mainFramePinnedToTheRight = pinnedToTheRight; 337 m_swipeState.mainFramePinnedToTheTop = pinnedToTheTop; 338 m_swipeState.mainFramePinnedToTheBottom = pinnedToTheBottom; 358 339 } 359 340 … … 362 343 LockHolder locker(m_swipeStateMutex); 363 344 364 m_rubberBandsAtLeft = canRubberBandAtLeft; 365 m_rubberBandsAtRight = canRubberBandAtRight; 366 m_rubberBandsAtTop = canRubberBandAtTop; 367 m_rubberBandsAtBottom = canRubberBandAtBottom; 368 } 369 370 bool ScrollingTree::rubberBandsAtLeft() 345 m_swipeState.rubberBandsAtLeft = canRubberBandAtLeft; 346 m_swipeState.rubberBandsAtRight = canRubberBandAtRight; 347 m_swipeState.rubberBandsAtTop = canRubberBandAtTop; 348 m_swipeState.rubberBandsAtBottom = canRubberBandAtBottom; 349 } 350 351 bool ScrollingTree::isHandlingProgrammaticScroll() 352 { 353 return m_isHandlingProgrammaticScroll; 354 } 355 356 // Can be called from the main thread. 357 void ScrollingTree::setScrollPinningBehavior(ScrollPinningBehavior pinning) 358 { 359 LockHolder locker(m_swipeStateMutex); 360 361 m_swipeState.scrollPinningBehavior = pinning; 362 } 363 364 ScrollPinningBehavior ScrollingTree::scrollPinningBehavior() 371 365 { 372 366 LockHolder lock(m_swipeStateMutex); 373 374 return m_rubberBandsAtLeft; 375 } 376 377 bool ScrollingTree::rubberBandsAtRight() 378 { 379 LockHolder lock(m_swipeStateMutex); 380 381 return m_rubberBandsAtRight; 382 } 383 384 bool ScrollingTree::rubberBandsAtBottom() 385 { 386 LockHolder lock(m_swipeStateMutex); 387 388 return m_rubberBandsAtBottom; 389 } 390 391 bool ScrollingTree::rubberBandsAtTop() 392 { 393 LockHolder lock(m_swipeStateMutex); 394 395 return m_rubberBandsAtTop; 396 } 397 398 bool ScrollingTree::isHandlingProgrammaticScroll() 399 { 400 return m_isHandlingProgrammaticScroll; 401 } 402 403 void ScrollingTree::setScrollPinningBehavior(ScrollPinningBehavior pinning) 404 { 405 LockHolder locker(m_swipeStateMutex); 406 407 m_scrollPinningBehavior = pinning; 408 } 409 410 ScrollPinningBehavior ScrollingTree::scrollPinningBehavior() 411 { 412 LockHolder lock(m_swipeStateMutex); 413 414 return m_scrollPinningBehavior; 367 368 return m_swipeState.scrollPinningBehavior; 415 369 } 416 370 … … 422 376 LockHolder lock(m_swipeStateMutex); 423 377 424 if (wheelEvent.deltaX() > 0 && m_ mainFramePinnedToTheLeft && !m_rubberBandsAtLeft)378 if (wheelEvent.deltaX() > 0 && m_swipeState.mainFramePinnedToTheLeft && !m_swipeState.rubberBandsAtLeft) 425 379 return true; 426 if (wheelEvent.deltaX() < 0 && m_ mainFramePinnedToTheRight && !m_rubberBandsAtRight)380 if (wheelEvent.deltaX() < 0 && m_swipeState.mainFramePinnedToTheRight && !m_swipeState.rubberBandsAtRight) 427 381 return true; 428 if (wheelEvent.deltaY() > 0 && m_ mainFramePinnedToTheTop && !m_rubberBandsAtTop)382 if (wheelEvent.deltaY() > 0 && m_swipeState.mainFramePinnedToTheTop && !m_swipeState.rubberBandsAtTop) 429 383 return true; 430 if (wheelEvent.deltaY() < 0 && m_ mainFramePinnedToTheBottom && !m_rubberBandsAtBottom)384 if (wheelEvent.deltaY() < 0 && m_swipeState.mainFramePinnedToTheBottom && !m_swipeState.rubberBandsAtBottom) 431 385 return true; 432 386 … … 446 400 ScrollingNodeID ScrollingTree::latchedNode() 447 401 { 448 LockHolder locker(m_ mutex);449 return m_ latchedNodeID;402 LockHolder locker(m_treeStateMutex); 403 return m_treeState.latchedNodeID; 450 404 } 451 405 452 406 void ScrollingTree::setLatchedNode(ScrollingNodeID node) 453 407 { 454 LockHolder locker(m_ mutex);455 m_ latchedNodeID = node;408 LockHolder locker(m_treeStateMutex); 409 m_treeState.latchedNodeID = node; 456 410 } 457 411 458 412 void ScrollingTree::clearLatchedNode() 459 413 { 460 LockHolder locker(m_ mutex);461 m_ latchedNodeID = 0;414 LockHolder locker(m_treeStateMutex); 415 m_treeState.latchedNodeID = 0; 462 416 } 463 417 … … 468 422 TextStream::GroupScope scope(ts); 469 423 ts << "scrolling tree"; 470 471 if (m_latchedNodeID) 472 ts.dumpProperty("latched node", m_latchedNodeID); 473 474 if (m_mainFrameScrollPosition != IntPoint()) 475 ts.dumpProperty("main frame scroll position", m_mainFrameScrollPosition); 476 477 { 478 LockHolder lock(m_mutex); 479 if (m_rootNode) { 480 TextStream::GroupScope scope(ts); 481 m_rootNode->dump(ts, ScrollingStateTreeAsTextBehaviorIncludeLayerPositions); 482 } 424 425 LockHolder locker(m_treeStateMutex); 426 427 if (m_treeState.latchedNodeID) 428 ts.dumpProperty("latched node", m_treeState.latchedNodeID); 429 430 if (!m_treeState.mainFrameScrollPosition.isZero()) 431 ts.dumpProperty("main frame scroll position", m_treeState.mainFrameScrollPosition); 432 433 if (m_rootNode) { 434 TextStream::GroupScope scope(ts); 435 m_rootNode->dump(ts, ScrollingStateTreeAsTextBehaviorIncludeLayerPositions); 483 436 } 484 437 … … 490 443 { 491 444 // FIXME: This does not handle the case where there are multiple regions matching this point. 492 for (auto& touchActionData : m_ eventTrackingRegions.touchActionData) {445 for (auto& touchActionData : m_treeState.eventTrackingRegions.touchActionData) { 493 446 if (touchActionData.region.contains(p)) 494 447 return touchActionData; 495 448 } 496 449 497 return WTF::nullopt;450 return { }; 498 451 } 499 452 #endif -
trunk/Source/WebCore/page/scrolling/ScrollingTree.h
r242313 r242670 70 70 WEBCORE_EXPORT virtual void commitTreeState(std::unique_ptr<ScrollingStateTree>); 71 71 72 void setMainFramePinState(bool pinnedToTheLeft, bool pinnedToTheRight, bool pinnedToTheTop, bool pinnedToTheBottom);73 74 72 virtual Ref<ScrollingTreeNode> createScrollingTreeNode(ScrollingNodeType, ScrollingNodeID) = 0; 75 73 … … 89 87 virtual void reportSynchronousScrollingReasonsChanged(MonotonicTime, SynchronousScrollingReasons) { } 90 88 virtual void reportExposedUnfilledArea(MonotonicTime, unsigned /* unfilledArea */) { } 91 92 FloatPoint mainFrameScrollPosition();93 WEBCORE_EXPORT virtual FloatRect mainFrameLayoutViewport();94 89 95 90 #if PLATFORM(IOS_FAMILY) … … 115 110 #endif 116 111 112 void setMainFramePinState(bool pinnedToTheLeft, bool pinnedToTheRight, bool pinnedToTheTop, bool pinnedToTheBottom); 113 117 114 // Can be called from any thread. Will update what edges allow rubber-banding. 118 115 WEBCORE_EXPORT void setCanRubberBandState(bool canRubberBandAtLeft, bool canRubberBandAtRight, bool canRubberBandAtTop, bool canRubberBandAtBottom); 119 116 120 bool rubberBandsAtLeft();121 bool rubberBandsAtRight();122 bool rubberBandsAtTop();123 bool rubberBandsAtBottom();124 117 bool isHandlingProgrammaticScroll(); 125 118 … … 138 131 void clearLatchedNode(); 139 132 140 bool hasLatchedNode() const { return m_ latchedNodeID; }133 bool hasLatchedNode() const { return m_treeState.latchedNodeID; } 141 134 void setOrClearLatchedNode(const PlatformWheelEvent&, ScrollingNodeID); 142 135 … … 169 162 ScrollingTreeNodeMap m_nodeMap; 170 163 171 Lock m_mutex; 172 EventTrackingRegions m_eventTrackingRegions; 173 FloatPoint m_mainFrameScrollPosition; 164 struct TreeState { 165 ScrollingNodeID latchedNodeID { 0 }; 166 EventTrackingRegions eventTrackingRegions; 167 FloatPoint mainFrameScrollPosition; 168 bool mainFrameIsRubberBanding { false }; 169 bool mainFrameIsScrollSnapping { false }; 170 }; 171 172 Lock m_treeStateMutex; 173 TreeState m_treeState; 174 175 struct SwipeState { 176 ScrollPinningBehavior scrollPinningBehavior { DoNotPin }; 177 bool rubberBandsAtLeft { true }; 178 bool rubberBandsAtRight { true }; 179 bool rubberBandsAtTop { true }; 180 bool rubberBandsAtBottom { true }; 181 bool mainFramePinnedToTheLeft { true }; 182 bool mainFramePinnedToTheRight { true }; 183 bool mainFramePinnedToTheTop { true }; 184 bool mainFramePinnedToTheBottom { true }; 185 }; 174 186 175 187 Lock m_swipeStateMutex; 176 ScrollPinningBehavior m_scrollPinningBehavior { DoNotPin }; 177 ScrollingNodeID m_latchedNodeID { 0 }; 188 SwipeState m_swipeState; 178 189 179 190 unsigned m_fixedOrStickyNodeCount { 0 }; 180 181 bool m_rubberBandsAtLeft { true };182 bool m_rubberBandsAtRight { true };183 bool m_rubberBandsAtTop { true };184 bool m_rubberBandsAtBottom { true };185 bool m_mainFramePinnedToTheLeft { true };186 bool m_mainFramePinnedToTheRight { true };187 bool m_mainFramePinnedToTheTop { true };188 bool m_mainFramePinnedToTheBottom { true };189 bool m_mainFrameIsRubberBanding { false };190 bool m_mainFrameIsScrollSnapping { false };191 191 bool m_scrollingPerformanceLoggingEnabled { false }; 192 192 bool m_isHandlingProgrammaticScroll { false }; -
trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm
r242359 r242670 179 179 stretch.setWidth(scrollPosition.x() - maximumScrollPosition().x()); 180 180 181 // FIXME: calling this function should not have these side-effects. 181 182 if (scrollingNode().isRootNode()) { 182 183 if (stretch.isZero()) -
trunk/Source/WebCore/platform/graphics/FloatPoint.h
r225512 r242670 71 71 72 72 static FloatPoint zero() { return FloatPoint(); } 73 bool isZero() const { return !m_x && !m_y; } 73 74 74 75 WEBCORE_EXPORT static FloatPoint narrowPrecision(double x, double y);
Note:
See TracChangeset
for help on using the changeset viewer.