Bug 1364525 - Update APIs to allow APZ to produce scrollbar transforms. r=pchang,botond
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 23 May 2017 10:50:42 -0400
changeset 408330 fa1a20ec07bfb15ddb9101853ad0cedde28ad7a7
parent 408329 22bc11104b412778a84d38c03306afc0ae412f0b
child 408331 9e0b016f2d7a721010ddbffc689222448be32db3
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspchang, botond
bugs1364525
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1364525 - Update APIs to allow APZ to produce scrollbar transforms. r=pchang,botond This allows the APZCTreeManager::PushStateToWR function to also produce a set of transforms to be applied to scrollbar thumbs. The PushStateToWR function will be updated in the next patch to actually produce the transforms. This patch also rearranges code in WebRenderBridgeParent::CompositeToTarget so that either OMTA or APZ can produce animation updates. MozReview-Commit-ID: 1ghvVG32TC5
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/layers/wr/WebRenderBridgeParent.cpp
gfx/layers/wr/WebRenderBridgeParent.h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -362,17 +362,18 @@ APZCTreeManager::UpdateHitTestingTree(ui
 {
   WebRenderScrollDataWrapper wrapper(&aScrollData);
   UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
                            aOriginatingLayersId, aPaintSequenceNumber);
 }
 
 bool
 APZCTreeManager::PushStateToWR(wr::WebRenderAPI* aWrApi,
-                               const TimeStamp& aSampleTime)
+                               const TimeStamp& aSampleTime,
+                               nsTArray<WrTransformProperty>& aTransformArray)
 {
   APZThreadUtils::AssertOnCompositorThread();
   MOZ_ASSERT(aWrApi);
 
   MutexAutoLock lock(mTreeLock);
 
   bool activeAnimations = false;
   uint64_t lastLayersId = -1;
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -18,16 +18,17 @@
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/TimeStamp.h"          // for mozilla::TimeStamp
 #include "nsCOMPtr.h"                   // for already_AddRefed
 
 #if defined(MOZ_WIDGET_ANDROID)
 #include "mozilla/layers/AndroidDynamicToolbarAnimator.h"
 #endif // defined(MOZ_WIDGET_ANDROID)
 
+struct WrTransformProperty;
 
 namespace mozilla {
 class MultiTouchInput;
 
 namespace wr {
 class WebRenderAPI;
 }
 
@@ -148,22 +149,25 @@ public:
                             uint64_t aOriginatingLayersId,
                             uint32_t aPaintSequenceNumber);
 
   /**
    * Called when webrender is enabled, from the compositor thread. This function
    * walks through the tree of APZC instances and tells webrender about the
    * async scroll position. It also advances APZ animations to the specified
    * sample time. In effect it is the webrender equivalent of (part of) the
-   * code in AsyncCompositionManager.
+   * code in AsyncCompositionManager. If scrollbar transforms need updating
+   * to reflect the async scroll position, the updated transforms are appended
+   * to the provided aTransformArray.
    * Returns true if any APZ animations are in progress and we need to keep
    * compositing.
    */
   bool PushStateToWR(wr::WebRenderAPI* aWrApi,
-                     const TimeStamp& aSampleTime);
+                     const TimeStamp& aSampleTime,
+                     nsTArray<WrTransformProperty>& aTransformArray);
 
   /**
    * Walk the tree of APZCs and flushes the repaint requests for all the APZCS
    * corresponding to the given layers id. Finally, sends a flush complete
    * notification to the GeckoContentController for the layers id.
    */
   void FlushApzRepaints(uint64_t aLayersId);
 
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -368,31 +368,31 @@ WebRenderBridgeParent::UpdateAPZ()
   if (RefPtr<APZCTreeManager> apzc = cbp->GetAPZCTreeManager()) {
     apzc->UpdateHitTestingTree(rootLayersId, rootWrbp->GetScrollData(),
         mScrollData.IsFirstPaint(), wr::AsUint64(mPipelineId),
         /* TODO: propagate paint sequence number */ 0);
   }
 }
 
 bool
-WebRenderBridgeParent::PushAPZStateToWR()
+WebRenderBridgeParent::PushAPZStateToWR(nsTArray<WrTransformProperty>& aTransformArray)
 {
   CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
   if (!cbp) {
     return false;
   }
   if (RefPtr<APZCTreeManager> apzc = cbp->GetAPZCTreeManager()) {
     TimeStamp animationTime = mCompositorScheduler->GetLastComposeTime();
     TimeDuration frameInterval = cbp->GetVsyncInterval();
     // As with the non-webrender codepath in AsyncCompositionManager, we want to
     // use the timestamp for the next vsync when advancing animations.
     if (frameInterval != TimeDuration::Forever()) {
       animationTime += frameInterval;
     }
-    return apzc->PushStateToWR(mApi, animationTime);
+    return apzc->PushStateToWR(mApi, animationTime, aTransformArray);
   }
   return false;
 }
 
 const WebRenderScrollData&
 WebRenderBridgeParent::GetScrollData() const
 {
   MOZ_ASSERT(mozilla::layers::CompositorThreadHolder::IsInCompositorThread());
@@ -771,38 +771,46 @@ WebRenderBridgeParent::CompositeToTarget
 
   if (!mIsSnapshotting &&
       wr::RenderThread::Get()->GetPendingFrameCount(mApi->GetId()) > maxPendingFrameCount) {
     // Render thread is busy, try next time.
     ScheduleComposition();
     return;
   }
 
-  if (PushAPZStateToWR()) {
-    ScheduleComposition();
-  }
+  bool scheduleComposite = false;
+  nsTArray<WrOpacityProperty> opacityArray;
+  nsTArray<WrTransformProperty> transformArray;
 
   if (gfxPrefs::WebRenderOMTAEnabled()) {
-    nsTArray<WrOpacityProperty> opacityArray;
-    nsTArray<WrTransformProperty> transformArray;
     SampleAnimations(opacityArray, transformArray);
 
     if (!transformArray.IsEmpty() || !opacityArray.IsEmpty()) {
-      mApi->GenerateFrame(opacityArray, transformArray);
-      ScheduleComposition();
-      return;
+      scheduleComposite = true;
     }
   }
 
-  mApi->GenerateFrame();
+  if (PushAPZStateToWR(transformArray)) {
+    scheduleComposite = true;
+  }
+
+  if (!transformArray.IsEmpty() || !opacityArray.IsEmpty()) {
+    mApi->GenerateFrame(opacityArray, transformArray);
+  } else {
+    mApi->GenerateFrame();
+  }
 
   // XXX Enable it when async video is supported.
   // if (!mCompositableHolder->GetCompositeUntilTime().IsNull()) {
-  //   ScheduleComposition();
+  //   scheduleComposite = true;
   // }
+
+  if (scheduleComposite) {
+    ScheduleComposition();
+  }
 }
 
 void
 WebRenderBridgeParent::HoldPendingTransactionId(uint32_t aWrEpoch, uint64_t aTransactionId)
 {
   // The transaction ID might get reset to 1 if the page gets reloaded, see
   // https://bugzilla.mozilla.org/show_bug.cgi?id=1145295#c41
   // Otherwise, it should be continually increasing.
--- a/gfx/layers/wr/WebRenderBridgeParent.h
+++ b/gfx/layers/wr/WebRenderBridgeParent.h
@@ -194,17 +194,19 @@ private:
 
   void SampleAnimations(nsTArray<WrOpacityProperty>& aOpacityArray,
                         nsTArray<WrTransformProperty>& aTransformArray);
 
   CompositorBridgeParent* GetRootCompositorBridgeParent() const;
 
   // Have APZ push the async scroll state to WR. Returns true if an APZ
   // animation is in effect and we need to schedule another composition.
-  bool PushAPZStateToWR();
+  // If scrollbars need their transforms updated, the provided aTransformArray
+  // is populated with the property update details.
+  bool PushAPZStateToWR(nsTArray<WrTransformProperty>& aTransformArray);
 
 private:
   struct PendingTransactionId {
     PendingTransactionId(wr::Epoch aEpoch, uint64_t aId)
       : mEpoch(aEpoch)
       , mId(aId)
     {}
     wr::Epoch mEpoch;