Bug 1379628 - Ensure pixels for Android dynamic toolbar snapshot get processed even if the toolbar is not visible so pending animations may run r=kats draft
authorRandall Barker <rbarker@mozilla.com>
Wed, 12 Jul 2017 12:54:59 -0700
changeset 607756 00e1ea28e70d4b2387049b75aadb563567b33c16
parent 607742 63215af4995f74aae2a6b24ad148e83d47c732f9
child 637140 f5f2ff100d7747b61db54971d34e872d79e90f1b
push id68102
push userbmo:rbarker@mozilla.com
push dateWed, 12 Jul 2017 21:01:01 +0000
reviewerskats
bugs1379628
milestone56.0a1
Bug 1379628 - Ensure pixels for Android dynamic toolbar snapshot get processed even if the toolbar is not visible so pending animations may run r=kats MozReview-Commit-ID: 9iMFN2gdfKl
gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h
gfx/layers/composite/LayerManagerComposite.cpp
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
@@ -494,23 +494,23 @@ AndroidDynamicToolbarAnimator::NotifyLay
 void
 AndroidDynamicToolbarAnimator::AdoptToolbarPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   mCompositorToolbarPixels = Some(Move(aMem));
   mCompositorToolbarPixelsSize = aSize;
 }
 
-Effect*
-AndroidDynamicToolbarAnimator::GetToolbarEffect(CompositorOGL* gl)
+void
+AndroidDynamicToolbarAnimator::UpdateToolbarSnapshotTexture(CompositorOGL* gl)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   // if the compositor has shutdown, do not create any new rendering objects.
   if (mCompositorShutdown) {
-    return nullptr;
+    return;
   }
 
   if (mCompositorToolbarPixels) {
     RefPtr<DataSourceSurface> surface = Factory::CreateWrappingDataSourceSurface(
         mCompositorToolbarPixels.ref().get<uint8_t>(),
         mCompositorToolbarPixelsSize.width * 4,
         IntSize(mCompositorToolbarPixelsSize.width, mCompositorToolbarPixelsSize.height),
         gfx::SurfaceFormat::B8G8R8A8);
@@ -530,16 +530,26 @@ AndroidDynamicToolbarAnimator::GetToolba
     mCompositorToolbarPixels.reset();
     // Send notification that texture is ready after the current composition has completed.
     if (mCompositorToolbarTexture && mCompositorSendResponseForSnapshotUpdate) {
       mCompositorSendResponseForSnapshotUpdate = false;
       CompositorThreadHolder::Loop()->PostTask(NewRunnableMethod("AndroidDynamicToolbarAnimator::PostToolbarReady",
                                                                  this, &AndroidDynamicToolbarAnimator::PostToolbarReady));
     }
   }
+}
+
+Effect*
+AndroidDynamicToolbarAnimator::GetToolbarEffect()
+{
+  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
+  // if the compositor has shutdown, do not create any new rendering objects.
+  if (mCompositorShutdown) {
+    return nullptr;
+  }
 
   if (mCompositorToolbarTexture) {
     if (!mCompositorToolbarEffect) {
       mCompositorToolbarEffect = new EffectRGB(mCompositorToolbarTexture, true, SamplingFilter::LINEAR);
     }
 
     float ratioVisible = (float)mCompositorToolbarHeight / (float)mCompositorMaxToolbarHeight;
     mCompositorToolbarEffect->mTextureCoords.y = 1.0f - ratioVisible;
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.h
@@ -99,18 +99,21 @@ public:
   // 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.
-  Effect* GetToolbarEffect(CompositorOGL* gl);
+  Effect* GetToolbarEffect();
   void Shutdown();
 
 protected:
   enum StaticToolbarState {
     eToolbarVisible,
     eToolbarUpdated,
     eToolbarUnlocked,
     eToolbarAnimating
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -1184,23 +1184,26 @@ LayerManagerComposite::RenderToolbar()
   if (mCompositor->GetTargetContext() != nullptr) {
     return;
   }
 
   if (CompositorBridgeParent* bridge = mCompositor->GetCompositorBridgeParent()) {
     AndroidDynamicToolbarAnimator* animator = bridge->GetAPZCTreeManager()->GetAndroidDynamicToolbarAnimator();
     MOZ_RELEASE_ASSERT(animator);
 
+    animator->UpdateToolbarSnapshotTexture(mCompositor->AsCompositorOGL());
+
     int32_t toolbarHeight = animator->GetCurrentToolbarHeight();
     if (toolbarHeight == 0) {
       return;
     }
 
     EffectChain effects;
-    effects.mPrimaryEffect = animator->GetToolbarEffect(mCompositor->AsCompositorOGL());
+    effects.mPrimaryEffect = animator->GetToolbarEffect();
+
     // If GetToolbarEffect returns null, nothing is rendered for the static snapshot of the toolbar.
     // If the real toolbar chrome is not covering this portion of the surface, the clear color
     // of the surface will be visible. On Android the clear color is the background color of the page.
     if (effects.mPrimaryEffect) {
       ScopedCompositorRenderOffset toolbarOffset(mCompositor->AsCompositorOGL(),
                                                  ScreenPoint(0.0f, -animator->GetCurrentContentOffset()));
       mCompositor->DrawQuad(gfx::Rect(0, 0, mRenderBounds.width, toolbarHeight),
                             IntRect(0, 0, mRenderBounds.width, toolbarHeight), effects, 1.0, gfx::Matrix4x4());