# HG changeset patch # User Kartikaya Gupta # Date 1520462050 18000 # Node ID 3034411c797eb0ed704743d1878567ca90574983 # Parent b5b539142a931b920b08dd3e9b081b34297094b4 Bug 1443301 - Give the dynamic toolbar class a non-owning ref to the APZCTreeManager. r=botond MozReview-Commit-ID: 8lE53GEhDMI diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -235,17 +235,17 @@ APZCTreeManager::APZCTreeManager(uint64_ RefPtr self(this); NS_DispatchToMainThread( NS_NewRunnableFunction("layers::APZCTreeManager::APZCTreeManager", [self] { self->mFlushObserver = new CheckerboardFlushObserver(self); })); AsyncPanZoomController::InitializeGlobalState(); mApzcTreeLog.ConditionOnPrefFunction(gfxPrefs::APZPrintTree); #if defined(MOZ_WIDGET_ANDROID) - mToolbarAnimator = new AndroidDynamicToolbarAnimator(); + mToolbarAnimator = new AndroidDynamicToolbarAnimator(this); #endif // (MOZ_WIDGET_ANDROID) } APZCTreeManager::~APZCTreeManager() { } void @@ -2020,16 +2020,20 @@ APZCTreeManager::AdjustScrollForSurfaceS } } void APZCTreeManager::ClearTree() { APZThreadUtils::AssertOnSamplerThread(); +#if defined(MOZ_WIDGET_ANDROID) + mToolbarAnimator->ClearTreeManager(); +#endif + // Ensure that no references to APZCs are alive in any lingering input // blocks. This breaks cycles from InputBlockState::mTargetApzc back to // the InputQueue. APZThreadUtils::RunOnControllerThread(NewRunnableMethod( "layers::InputQueue::Clear", mInputQueue, &InputQueue::Clear)); RecursiveMutexAutoLock lock(mTreeLock); diff --git a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp --- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp +++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp @@ -34,18 +34,19 @@ static const int32_t MOVE_TOOLBAR_DOWN static const int32_t MOVE_TOOLBAR_UP = -1; // Multiplier to move the toolbar up static const float SHRINK_FACTOR = 0.95f; // Amount to shrink the either the full content for small pages or the amount left // See: PageTooSmallEnsureToolbarVisible() } // namespace namespace mozilla { namespace layers { -AndroidDynamicToolbarAnimator::AndroidDynamicToolbarAnimator() +AndroidDynamicToolbarAnimator::AndroidDynamicToolbarAnimator(APZCTreeManager* aApz) : mRootLayerTreeId(0) + , mApz(aApz) // Read/Write Compositor Thread, Read only Controller thread , mToolbarState(eToolbarVisible) , mPinnedFlags(0) // Controller thread only , mControllerScrollingRootContent(false) , mControllerDragThresholdReached(false) , mControllerCancelTouchTracking(false) , mControllerDragChangedDirection(false) @@ -90,16 +91,23 @@ AndroidDynamicToolbarAnimator::Initializ // Send queued messages that were posted before Initialize() was called. for (QueuedMessage* message = mCompositorQueuedMessages.getFirst(); message != nullptr; message = message->getNext()) { uiController->ToolbarAnimatorMessageFromCompositor(message->mMessage); } mCompositorQueuedMessages.clear(); } +void +AndroidDynamicToolbarAnimator::ClearTreeManager() +{ + MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); + mApz = nullptr; +} + static bool GetTouchY(MultiTouchInput& multiTouch, ScreenIntCoord* value) { MOZ_ASSERT(value); if (multiTouch.mTouches.Length() == 1) { *value = multiTouch.mTouches[0].mScreenPoint.y; return true; } @@ -338,31 +346,32 @@ AndroidDynamicToolbarAnimator::UpdateAni if ((mToolbarState != eToolbarAnimating) || mCompositorShutdown) { return false; } CompositorBridgeParent* parent = CompositorBridgeParent::GetCompositorBridgeParentFromLayersId(mRootLayerTreeId); if (!parent) { return false; } + MOZ_ASSERT(mApz); // because parent is non-null AsyncCompositionManager* manager = parent->GetCompositionManager(nullptr); if (!manager) { return false; } if (mCompositorSurfaceHeight != mCompositorCompositionSize.height) { // Waiting for the composition to resize if (mCompositorWaitForPageResize && mCompositorAnimationStarted) { mCompositorWaitForPageResize = false; } else { return true; } } else if (!mCompositorAnimationStarted) { - parent->GetAPZCTreeManager()->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)(-mCompositorToolbarHeight))); + mApz->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)(-mCompositorToolbarHeight))); manager->SetFixedLayerMargins(mCompositorToolbarHeight, 0); mCompositorAnimationStarted = true; mCompositorReceivedFirstPaint = false; mCompositorToolbarShowRequested = false; // Reset the start time so the toolbar does not jump on the first animation frame mCompositorAnimationStartTimeStamp = aCurrentFrame; // Since the delta time for this frame will be zero. Just return, the animation will start on the next frame. return true; @@ -407,17 +416,17 @@ AndroidDynamicToolbarAnimator::UpdateAni mCompositorToolbarHeight = 0; } if (continueAnimating) { manager->SetFixedLayerMargins(mCompositorToolbarHeight, 0); } else { if (mCompositorAnimationDirection == MOVE_TOOLBAR_DOWN) { if (!mCompositorReceivedFirstPaint) { - parent->GetAPZCTreeManager()->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)mCompositorMaxToolbarHeight)); + mApz->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)mCompositorMaxToolbarHeight)); } manager->SetFixedLayerMargins(0, GetFixedLayerMarginsBottom()); } else { manager->SetFixedLayerMargins(0, 0); } } if (!continueAnimating) { @@ -628,19 +637,18 @@ AndroidDynamicToolbarAnimator::ProcessTo // If there was no delta left over, the event was completely consumed. if (deltaRemainder == 0) { status = nsEventStatus_eConsumeNoDefault; } uint32_t timeDelta = aTimeStamp - mControllerLastEventTimeStamp; if (mControllerLastEventTimeStamp && timeDelta && aDelta) { float speed = -(float)aDelta / (float)timeDelta; - CompositorBridgeParent* parent = CompositorBridgeParent::GetCompositorBridgeParentFromLayersId(mRootLayerTreeId); - if (parent) { - parent->GetAPZCTreeManager()->ProcessTouchVelocity(aTimeStamp, speed); + if (mApz) { + mApz->ProcessTouchVelocity(aTimeStamp, speed); } } } return status; } void @@ -885,19 +893,18 @@ AndroidDynamicToolbarAnimator::StartComp mToolbarState = eToolbarAnimating; if (initialToolbarState != eToolbarAnimating) { mCompositorAnimationStarted = false; } // Let the controller know we are starting an animation so it may clear the AnimationStartPending flag. NotifyControllerAnimationStarted(); // Only reset the time stamp and start compositor animation if not already animating. if (initialToolbarState != eToolbarAnimating) { - CompositorBridgeParent* parent = CompositorBridgeParent::GetCompositorBridgeParentFromLayersId(mRootLayerTreeId); - if (parent) { - mCompositorAnimationStartTimeStamp = parent->GetAPZCTreeManager()->GetFrameTime(); + if (mApz) { + mCompositorAnimationStartTimeStamp = mApz->GetFrameTime(); } // Kick the compositor to start the animation if we aren't already animating. RequestComposite(); } } } void @@ -928,18 +935,19 @@ AndroidDynamicToolbarAnimator::StopCompo if (mToolbarState == eToolbarAnimating) { if (mCompositorAnimationStarted) { mCompositorAnimationStarted = false; CompositorBridgeParent* parent = CompositorBridgeParent::GetCompositorBridgeParentFromLayersId(mRootLayerTreeId); if (parent) { AsyncCompositionManager* manager = parent->GetCompositionManager(nullptr); if (manager) { - parent->GetAPZCTreeManager()->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)(mCompositorToolbarHeight))); - RequestComposite(); + MOZ_ASSERT(mApz); + mApz->AdjustScrollForSurfaceShift(ScreenPoint(0.0f, (float)(mCompositorToolbarHeight))); + RequestComposite(); } } } mToolbarState = eToolbarUnlocked; } NotifyControllerAnimationStopped(mCompositorToolbarHeight); } diff --git a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h --- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h +++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h @@ -17,16 +17,17 @@ #include "mozilla/Maybe.h" #include "mozilla/TimeStamp.h" #include "nsISupports.h" namespace mozilla { namespace layers { struct FrameMetrics; +class APZCTreeManager; class CompositorOGL; /* * The AndroidDynamicToolbarAnimator is responsible for calculating the position * and drawing the static snapshot of the toolbar. The animator lives in both * compositor thread and controller thread. It intercepts input events in the * controller thread and determines if the intercepted touch events will cause * the toolbar to move or be animated. Once the proper conditions have been met, @@ -46,18 +47,19 @@ class CompositorOGL; * toolbar be hidden in order to unlock the static snapshot and begin translating it. * * See Bug 1335895 for more details. */ class AndroidDynamicToolbarAnimator { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidDynamicToolbarAnimator); - AndroidDynamicToolbarAnimator(); + explicit AndroidDynamicToolbarAnimator(APZCTreeManager* aApz); void Initialize(uint64_t aRootLayerTreeId); + void ClearTreeManager(); // Used to intercept events to determine if the event affects the toolbar. // May apply translation to touch events if the toolbar is visible. // Returns nsEventStatus_eIgnore when the event is not consumed and // nsEventStatus_eConsumeNoDefault when the event was used to translate the // toolbar. nsEventStatus ReceiveInputEvent(InputData& aEvent, const ScreenPoint& aScrollOffset); void SetMaxToolbarHeight(ScreenIntCoord aHeight); // When a pinned reason is set to true, the animator will prevent @@ -162,16 +164,17 @@ protected: // Returns true if the page scroll offset is near the bottom. bool ScrollOffsetNearBottom() const; // Returns true if toolbar is not completely visible nor completely hidden. bool ToolbarInTransition(); void QueueMessage(int32_t aMessage); // Read only Compositor and Controller threads after Initialize() uint64_t mRootLayerTreeId; + MOZ_NON_OWNING_REF APZCTreeManager* mApz; // Read/Write Compositor Thread, Read only Controller thread Atomic mToolbarState; // Current toolbar state. Atomic mPinnedFlags; // The toolbar should not be moved or animated unless no flags are set // Controller thread only bool mControllerScrollingRootContent; // Set to true when the root content is being scrolled bool mControllerDragThresholdReached; // Set to true when the drag threshold has been passed in a single drag