Bug 1498699 - Move the LAYERS_UPDATED notification from AndroidDynamicToolbarAnimator to UiCompositorControllerParent. r=jnicol
This extracts code that is conceptually unrelated to the dynamic toolbar
from the dynamic toolbar codebase. It is a stepping stone to being able
to not instantiate the AndroidDynamicToolbarAnimator at all for
non-Fennec android products.
Differential Revision:
https://phabricator.services.mozilla.com/D8657
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
@@ -61,17 +61,16 @@ AndroidDynamicToolbarAnimator::AndroidDy
, mControllerRootScrollY(0.0f)
, mControllerLastDragDirection(0)
, mControllerTouchCount(0)
, mControllerLastEventTimeStamp(0)
, mControllerState(eNothingPending)
// Compositor thread only
, mCompositorShutdown(false)
, mCompositorAnimationDeferred(false)
- , mCompositorLayersUpdateEnabled(false)
, mCompositorAnimationStarted(false)
, mCompositorReceivedFirstPaint(false)
, mCompositorWaitForPageResize(false)
, mCompositorToolbarShowRequested(false)
, mCompositorSendResponseForSnapshotUpdate(false)
, mCompositorAnimationStyle(eAnimate)
, mCompositorMaxToolbarHeight(0)
, mCompositorToolbarHeight(0)
@@ -481,33 +480,16 @@ AndroidDynamicToolbarAnimator::MaybeUpda
if (prevSize.height != size.height) {
UpdateControllerCompositionHeight(size.height);
UpdateFixedLayerMargins();
}
UpdateRootFrameMetrics(aMetrics);
}
-// Layers updates are need by Robocop test which enables them
-void
-AndroidDynamicToolbarAnimator::EnableLayersUpdateNotifications(bool aEnable)
-{
- MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
- mCompositorLayersUpdateEnabled = aEnable;
-}
-
-void
-AndroidDynamicToolbarAnimator::NotifyLayersUpdated()
-{
- MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
- if (mCompositorLayersUpdateEnabled) {
- PostMessage(LAYERS_UPDATED);
- }
-}
-
void
AndroidDynamicToolbarAnimator::AdoptToolbarPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
mCompositorToolbarPixels = Some(std::move(aMem));
mCompositorToolbarPixelsSize = aSize;
}
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h
@@ -92,21 +92,16 @@ public:
// Returns true if the animation will continue and false if it has completed.
bool UpdateAnimation(const TimeStamp& aCurrentFrame);
// Called to signify the first paint has occurred.
void FirstPaint();
// Called whenever the root document's FrameMetrics have reached a steady state.
void UpdateRootFrameMetrics(const FrameMetrics& aMetrics);
// Only update the frame metrics if the root composition size has changed
void MaybeUpdateCompositionSizeAndRootFrameMetrics(const FrameMetrics& aMetrics);
- // When aEnable is set to true, it informs the animator that the UI thread expects to
- // be notified when the layer tree has been updated. Enabled currently by robocop tests.
- void EnableLayersUpdateNotifications(bool aEnable);
- // Called when a layer has been updated so the UI thread may be notified if necessary.
- void NotifyLayersUpdated();
// Adopts the Shmem containing the toolbar snapshot sent from the UI thread.
// The AndroidDynamicToolbarAnimator is responsible for deallocating the Shmem when
// it is done being used.
void AdoptToolbarPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize);
// Updates the toolbar snapshot texture and notifies the UI thread that the static toolbar is
// now ready to be displayed.
void UpdateToolbarSnapshotTexture(CompositorOGL* gl);
// Returns the Effect object used by the compositor to render the toolbar snapshot.
@@ -221,17 +216,16 @@ protected:
QueuedMessage() = delete;
QueuedMessage(const QueuedMessage&) = delete;
QueuedMessage& operator=(const QueuedMessage&) = delete;
};
// Compositor thread only
bool mCompositorShutdown; // Set to true when the compositor has been shutdown
bool mCompositorAnimationDeferred; // An animation has been deferred until the toolbar is unlocked
- bool mCompositorLayersUpdateEnabled; // Flag set to true when the UI thread is expecting to be notified when a layer has been updated
bool mCompositorAnimationStarted; // Set to true when the compositor has actually started animating the static snapshot.
bool mCompositorReceivedFirstPaint; // Set to true when a first paint occurs. Used by toolbar animator to detect a new page load.
bool mCompositorWaitForPageResize; // Set to true if the bottom of the page has been reached and the toolbar animator should wait for the page to resize before ending animation.
bool mCompositorToolbarShowRequested; // Set to true if the animator has already requested the real toolbar chrome be shown
bool mCompositorSendResponseForSnapshotUpdate; // Set to true when a message should be sent after a static toolbar snapshot update
AnimationStyle mCompositorAnimationStyle; // Set to true when the snapshot should be immediately hidden or shown in the animation update
ScreenIntCoord mCompositorMaxToolbarHeight; // Should contain the same value as mControllerMaxToolbarHeight
ScreenIntCoord mCompositorToolbarHeight; // This value is only updated by the compositor thread when the mToolbarState == ToolbarAnimating
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -1018,17 +1018,20 @@ AsyncCompositionManager::ApplyAsyncConte
AndroidDynamicToolbarAnimator* animator = bridge->GetAndroidDynamicToolbarAnimator();
MOZ_ASSERT(animator);
if (mIsFirstPaint) {
animator->UpdateRootFrameMetrics(metrics);
animator->FirstPaint();
mIsFirstPaint = false;
}
if (mLayersUpdated) {
- animator->NotifyLayersUpdated();
+ LayersId rootLayerTreeId = bridge->RootLayerTreeId();
+ if (RefPtr<UiCompositorControllerParent> uiController = UiCompositorControllerParent::GetFromRootLayerTreeId(rootLayerTreeId)) {
+ uiController->NotifyLayersUpdated();
+ }
mLayersUpdated = false;
}
// If this is not actually the root content then the animator is not getting updated in AsyncPanZoomController::NotifyLayersUpdated
// because the root content document is not scrollable. So update it here so it knows if the root composition size has changed.
if (!metrics.IsRootContent()) {
animator->MaybeUpdateCompositionSizeAndRootFrameMetrics(metrics);
}
}
--- a/gfx/layers/ipc/UiCompositorControllerParent.cpp
+++ b/gfx/layers/ipc/UiCompositorControllerParent.cpp
@@ -160,19 +160,18 @@ UiCompositorControllerParent::RecvReques
return IPC_OK();
}
mozilla::ipc::IPCResult
UiCompositorControllerParent::RecvEnableLayerUpdateNotifications(const bool& aEnable)
{
#if defined(MOZ_WIDGET_ANDROID)
- if (mAnimator) {
- mAnimator->EnableLayersUpdateNotifications(aEnable);
- }
+ // Layers updates are need by Robocop test which enables them
+ mCompositorLayersUpdateEnabled = aEnable;
#endif // defined(MOZ_WIDGET_ANDROID)
return IPC_OK();
}
mozilla::ipc::IPCResult
UiCompositorControllerParent::RecvToolbarPixelsToCompositor(Shmem&& aMem, const ScreenIntSize& aSize)
{
@@ -232,18 +231,31 @@ UiCompositorControllerParent::ToolbarAni
bool
UiCompositorControllerParent::AllocPixelBuffer(const int32_t aSize, ipc::Shmem* aMem)
{
MOZ_ASSERT(aSize > 0);
return AllocShmem(aSize, ipc::SharedMemory::TYPE_BASIC, aMem);
}
+void
+UiCompositorControllerParent::NotifyLayersUpdated()
+{
+#ifdef MOZ_WIDGET_ANDROID
+ if (mCompositorLayersUpdateEnabled) {
+ ToolbarAnimatorMessageFromCompositor(LAYERS_UPDATED);
+ }
+#endif
+}
+
UiCompositorControllerParent::UiCompositorControllerParent(const LayersId& aRootLayerTreeId)
: mRootLayerTreeId(aRootLayerTreeId)
+#ifdef MOZ_WIDGET_ANDROID
+ , mCompositorLayersUpdateEnabled(false)
+#endif
, mMaxToolbarHeight(0)
{
MOZ_COUNT_CTOR(UiCompositorControllerParent);
}
UiCompositorControllerParent::~UiCompositorControllerParent()
{
MOZ_COUNT_DTOR(UiCompositorControllerParent);
--- a/gfx/layers/ipc/UiCompositorControllerParent.h
+++ b/gfx/layers/ipc/UiCompositorControllerParent.h
@@ -44,29 +44,33 @@ public:
// Class specific functions
#if defined(MOZ_WIDGET_ANDROID)
void RegisterAndroidDynamicToolbarAnimator(AndroidDynamicToolbarAnimator* aAnimator);
#endif // MOZ_WIDGET_ANDROID
void ToolbarAnimatorMessageFromCompositor(int32_t aMessage);
bool AllocPixelBuffer(const int32_t aSize, Shmem* aMem);
+ // Called when a layer has been updated so the UI thread may be notified if necessary.
+ void NotifyLayersUpdated();
+
private:
explicit UiCompositorControllerParent(const LayersId& aRootLayerTreeId);
~UiCompositorControllerParent();
void InitializeForSameProcess();
void InitializeForOutOfProcess();
void Initialize();
void Open(Endpoint<PUiCompositorControllerParent>&& aEndpoint);
void Shutdown();
LayersId mRootLayerTreeId;
#if defined(MOZ_WIDGET_ANDROID)
RefPtr<AndroidDynamicToolbarAnimator> mAnimator;
+ bool mCompositorLayersUpdateEnabled; // Flag set to true when the UI thread is expecting to be notified when a layer has been updated
#endif // defined(MOZ_WIDGET_ANDROID)
int32_t mMaxToolbarHeight;
};
} // namespace layers
} // namespace mozilla