Bug 1449145 - Improve by modernising code in gfx/layers/apz. r?botond draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Wed, 28 Mar 2018 21:41:00 +0300
changeset 773964 e21c48cc41213a87feae7108824a16f1f8bafbd2
parent 773564 56d6db4ad38c869d0bbc2aea449a4a382f109163
push id104362
push userbmo:bpostelnicu@mozilla.com
push dateWed, 28 Mar 2018 18:41:24 +0000
reviewersbotond
bugs1449145
milestone61.0a1
Bug 1449145 - Improve by modernising code in gfx/layers/apz. r?botond MozReview-Commit-ID: FxYKhXPsiTD
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZSampler.cpp
gfx/layers/apz/src/AsyncPanZoomAnimation.h
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
gfx/layers/apz/src/Axis.cpp
gfx/layers/apz/src/CheckerboardEvent.cpp
gfx/layers/apz/src/GenericScrollAnimation.cpp
gfx/layers/apz/src/GenericScrollAnimation.h
gfx/layers/apz/src/GestureEventListener.cpp
gfx/layers/apz/src/HitTestingTreeNode.cpp
gfx/layers/apz/src/InputBlockState.h
gfx/layers/apz/src/InputQueue.cpp
gfx/layers/apz/src/KeyboardMap.cpp
gfx/layers/apz/src/Overscroll.h
gfx/layers/apz/src/OverscrollHandoffState.cpp
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -135,17 +135,17 @@ public:
     nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
     if (obsSvc) {
       obsSvc->RemoveObserver(this, "APZ:FlushActiveCheckerboard");
     }
     mTreeManager = nullptr;
   }
 
 protected:
-  virtual ~CheckerboardFlushObserver() {}
+  virtual ~CheckerboardFlushObserver() = default;
 
 private:
   RefPtr<APZCTreeManager> mTreeManager;
 };
 
 NS_IMPL_ISUPPORTS(APZCTreeManager::CheckerboardFlushObserver, nsIObserver)
 
 NS_IMETHODIMP
@@ -239,19 +239,17 @@ APZCTreeManager::APZCTreeManager(LayersI
     }));
   AsyncPanZoomController::InitializeGlobalState();
   mApzcTreeLog.ConditionOnPrefFunction(gfxPrefs::APZPrintTree);
 #if defined(MOZ_WIDGET_ANDROID)
   mToolbarAnimator = new AndroidDynamicToolbarAnimator(this);
 #endif // (MOZ_WIDGET_ANDROID)
 }
 
-APZCTreeManager::~APZCTreeManager()
-{
-}
+APZCTreeManager::~APZCTreeManager() = default;
 
 void
 APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
                                         const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
 {
   APZThreadUtils::AssertOnSamplerThread();
 
   if (aOldApzcTreeManager) {
@@ -3161,17 +3159,17 @@ APZCTreeManager::ComputeTransformForScro
   // Note that since the async transform is applied on top of the content's
   // regular transform, we need to make sure to unapply the async transform in
   // the same coordinate space. This requires applying the content transform
   // and then unapplying it after unapplying the async transform.
   if (aScrollbarIsDescendant) {
     AsyncTransformComponentMatrix overscroll =
         aApzc->GetOverscrollTransform(AsyncPanZoomController::eForCompositing);
     Matrix4x4 asyncUntransform = (asyncTransform * overscroll).Inverse().ToUnknownMatrix();
-    Matrix4x4 contentTransform = aScrollableContentTransform;
+    const Matrix4x4& contentTransform = aScrollableContentTransform;
     Matrix4x4 contentUntransform = contentTransform.Inverse();
 
     AsyncTransformComponentMatrix asyncCompensation =
         ViewAs<AsyncTransformComponentMatrix>(
             contentTransform
           * asyncUntransform
           * contentUntransform);
 
--- a/gfx/layers/apz/src/APZSampler.cpp
+++ b/gfx/layers/apz/src/APZSampler.cpp
@@ -15,19 +15,17 @@
 namespace mozilla {
 namespace layers {
 
 APZSampler::APZSampler(const RefPtr<APZCTreeManager>& aApz)
   : mApz(aApz)
 {
 }
 
-APZSampler::~APZSampler()
-{
-}
+APZSampler::~APZSampler() = default;
 
 void
 APZSampler::ClearTree()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   mApz->ClearTree();
 }
 
--- a/gfx/layers/apz/src/AsyncPanZoomAnimation.h
+++ b/gfx/layers/apz/src/AsyncPanZoomAnimation.h
@@ -21,18 +21,17 @@ namespace layers {
 class WheelScrollAnimation;
 class KeyboardScrollAnimation;
 class SmoothScrollAnimation;
 
 class AsyncPanZoomAnimation {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AsyncPanZoomAnimation)
 
 public:
-  explicit AsyncPanZoomAnimation()
-  { }
+  explicit AsyncPanZoomAnimation() = default;
 
   virtual bool DoSample(FrameMetrics& aFrameMetrics,
                         const TimeDuration& aDelta) = 0;
 
   bool Sample(FrameMetrics& aFrameMetrics,
               const TimeDuration& aDelta) {
     // In some situations, particularly when handoff is involved, it's possible
     // for |aDelta| to be negative on the first call to sample. Ignore such a
@@ -65,18 +64,17 @@ public:
   virtual bool WantsRepaints() {
     return true;
   }
 
   virtual void Cancel(CancelAnimationFlags aFlags) {}
 
 protected:
   // Protected destructor, to discourage deletion outside of Release():
-  virtual ~AsyncPanZoomAnimation()
-  { }
+  virtual ~AsyncPanZoomAnimation() = default;
 
   /**
    * Tasks scheduled for execution after the APZC's mMonitor is released.
    * Derived classes can add tasks here in Sample(), and the APZC can call
    * ExecuteDeferredTasks() to execute them.
    */
   nsTArray<RefPtr<Runnable>> mDeferredTasks;
 };
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -545,24 +545,28 @@ public:
 
 private:
   AsyncPanZoomController* mApzc;
   AsyncPanZoomController::PanZoomState mInitialState;
 };
 
 class ZoomAnimation: public AsyncPanZoomAnimation {
 public:
-  ZoomAnimation(CSSPoint aStartOffset, CSSToParentLayerScale2D aStartZoom,
-                CSSPoint aEndOffset, CSSToParentLayerScale2D aEndZoom)
-    : mTotalDuration(TimeDuration::FromMilliseconds(gfxPrefs::APZZoomAnimationDuration()))
+  ZoomAnimation(const CSSPoint& aStartOffset,
+                const CSSToParentLayerScale2D& aStartZoom,
+                const CSSPoint& aEndOffset,
+                const CSSToParentLayerScale2D& aEndZoom)
+    : mTotalDuration(
+        TimeDuration::FromMilliseconds(gfxPrefs::APZZoomAnimationDuration()))
     , mStartOffset(aStartOffset)
     , mStartZoom(aStartZoom)
     , mEndOffset(aEndOffset)
     , mEndZoom(aEndZoom)
-  {}
+  {
+  }
 
   virtual bool DoSample(FrameMetrics& aFrameMetrics,
                         const TimeDuration& aDelta) override
   {
     mDuration += aDelta;
     double animPosition = mDuration / mTotalDuration;
 
     if (animPosition >= 1.0) {
@@ -1113,17 +1117,17 @@ nsEventStatus AsyncPanZoomController::Ha
     if (!tapInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
 
     rv = HandleGestureEvent(tapInput);
     break;
   }
   case KEYBOARD_INPUT: {
-    KeyboardInput keyInput = aEvent.AsKeyboardInput();
+    const KeyboardInput& keyInput = aEvent.AsKeyboardInput();
     rv = OnKeyboard(keyInput);
     break;
   }
   }
 
   return rv;
 }
 
@@ -1407,17 +1411,17 @@ nsEventStatus AsyncPanZoomController::On
   mY.SetVelocity(0);
   mLastZoomFocus = aEvent.mLocalFocusPoint - mFrameMetrics.GetCompositionBounds().TopLeft();
 
   return nsEventStatus_eConsumeNoDefault;
 }
 
 nsEventStatus AsyncPanZoomController::OnScale(const PinchGestureInput& aEvent) {
   APZC_LOG("%p got a scale in state %d\n", this, mState);
- 
+
   if (HasReadyTouchBlock() && !GetCurrentTouchBlock()->TouchActionAllowsPinchZoom()) {
     return nsEventStatus_eIgnore;
   }
 
   if (mState != PINCHING) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -62,25 +62,25 @@ class OverscrollEffectBase;
 class WidgetOverscrollEffect;
 class GenericOverscrollEffect;
 class AndroidSpecificState;
 struct KeyboardScrollAction;
 
 // Base class for grouping platform-specific APZC state variables.
 class PlatformSpecificStateBase {
 public:
-  virtual ~PlatformSpecificStateBase() {}
+  virtual ~PlatformSpecificStateBase() = default;
   virtual AndroidSpecificState* AsAndroidSpecificState() { return nullptr; }
 };
 
 /*
  * Represents a transform from the ParentLayer coordinate space of an APZC
  * to the ParentLayer coordinate space of its parent APZC.
- * Each layer along the way contributes to the transform. We track 
- * contributions that are perspective transforms separately, as sometimes 
+ * Each layer along the way contributes to the transform. We track
+ * contributions that are perspective transforms separately, as sometimes
  * these require special handling.
  */
 struct AncestorTransform {
   gfx::Matrix4x4 mTransform;
   gfx::Matrix4x4 mPerspectiveTransform;
 
   AncestorTransform() = default;
 
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -376,19 +376,19 @@ bool Axis::FlingApplyFrictionOrCancel(co
                                       float aFriction,
                                       float aThreshold) {
   if (fabsf(mVelocity) <= aThreshold) {
     // If the velocity is very low, just set it to 0 and stop the fling,
     // otherwise we'll just asymptotically approach 0 and the user won't
     // actually see any changes.
     mVelocity = 0.0f;
     return false;
-  } else {
-    mVelocity *= pow(1.0f - aFriction, float(aDelta.ToMilliseconds()));
   }
+
+  mVelocity *= pow(1.0f - aFriction, float(aDelta.ToMilliseconds()));
   AXIS_LOG("%p|%s reduced velocity to %f due to friction\n",
     mAsyncPanZoomController, Name(), mVelocity);
   return true;
 }
 
 ParentLayerCoord Axis::DisplacementWillOverscrollAmount(ParentLayerCoord aDisplacement) const {
   ParentLayerCoord newOrigin = GetOrigin() + aDisplacement;
   ParentLayerCoord newCompositionEnd = GetCompositionEnd() + aDisplacement;
--- a/gfx/layers/apz/src/CheckerboardEvent.cpp
+++ b/gfx/layers/apz/src/CheckerboardEvent.cpp
@@ -154,18 +154,18 @@ CheckerboardEvent::StartEvent()
   mCheckerboardingActive = true;
   mStartTime = TimeStamp::Now();
 
   if (!mRecordTrace) {
     return;
   }
   MonitorAutoLock lock(mRendertraceLock);
   std::vector<PropertyValue> history;
-  for (size_t i = 0; i < sRendertracePropertyCount; i++) {
-    mBufferedProperties[i].Flush(history, lock);
+  for (PropertyBuffer& bufferedProperty : mBufferedProperties) {
+    bufferedProperty.Flush(history, lock);
   }
   std::sort(history.begin(), history.end());
   for (const PropertyValue& p : history) {
     LogInfo(p.mProperty, p.mTimeStamp, p.mRect, p.mExtraInfo, lock);
   }
   mRendertraceInfo << " -- checkerboarding starts below --" << std::endl;
 }
 
--- a/gfx/layers/apz/src/GenericScrollAnimation.cpp
+++ b/gfx/layers/apz/src/GenericScrollAnimation.cpp
@@ -25,25 +25,29 @@ GenericScrollAnimation::GenericScrollAni
   if (gfxPrefs::SmoothScrollMSDPhysicsEnabled()) {
     mAnimationPhysics = MakeUnique<ScrollAnimationMSDPhysics>(aInitialPosition);
   } else {
     mAnimationPhysics = MakeUnique<ScrollAnimationBezierPhysics>(aInitialPosition, aSettings);
   }
 }
 
 void
-GenericScrollAnimation::UpdateDelta(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity)
+GenericScrollAnimation::UpdateDelta(TimeStamp aTime,
+                                    const nsPoint& aDelta,
+                                    const nsSize& aCurrentVelocity)
 {
   mFinalDestination += aDelta;
 
   Update(aTime, aCurrentVelocity);
 }
 
 void
-GenericScrollAnimation::UpdateDestination(TimeStamp aTime, nsPoint aDestination, const nsSize& aCurrentVelocity)
+GenericScrollAnimation::UpdateDestination(TimeStamp aTime,
+                                          const nsPoint& aDestination,
+                                          const nsSize& aCurrentVelocity)
 {
   mFinalDestination = aDestination;
 
   Update(aTime, aCurrentVelocity);
 }
 
 void
 GenericScrollAnimation::Update(TimeStamp aTime, const nsSize& aCurrentVelocity)
--- a/gfx/layers/apz/src/GenericScrollAnimation.h
+++ b/gfx/layers/apz/src/GenericScrollAnimation.h
@@ -23,18 +23,22 @@ class GenericScrollAnimation
 {
 public:
   GenericScrollAnimation(AsyncPanZoomController& aApzc,
                          const nsPoint& aInitialPosition,
                          const ScrollAnimationBezierPhysicsSettings& aSettings);
 
   bool DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta) override;
 
-  void UpdateDelta(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity);
-  void UpdateDestination(TimeStamp aTime, nsPoint aDestination, const nsSize& aCurrentVelocity);
+  void UpdateDelta(TimeStamp aTime,
+                   const nsPoint& aDelta,
+                   const nsSize& aCurrentVelocity);
+  void UpdateDestination(TimeStamp aTime,
+                         const nsPoint& aDestination,
+                         const nsSize& aCurrentVelocity);
 
   CSSPoint GetDestination() const {
     return CSSPoint::FromAppUnits(mFinalDestination);
   }
 
 private:
   void Update(TimeStamp aTime, const nsSize& aCurrentVelocity);
 
--- a/gfx/layers/apz/src/GestureEventListener.cpp
+++ b/gfx/layers/apz/src/GestureEventListener.cpp
@@ -76,19 +76,17 @@ GestureEventListener::GestureEventListen
     mFocusChange(0.0f),
     mLastTouchInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0),
     mLastTapInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0),
     mLongTapTimeoutTask(nullptr),
     mMaxTapTimeoutTask(nullptr)
 {
 }
 
-GestureEventListener::~GestureEventListener()
-{
-}
+GestureEventListener::~GestureEventListener() = default;
 
 nsEventStatus GestureEventListener::HandleInputEvent(const MultiTouchInput& aEvent)
 {
   GEL_LOG("Receiving event type %d with %zu touches in state %d\n", aEvent.mType, aEvent.mTouches.Length(), mState);
 
   nsEventStatus rv = nsEventStatus_eIgnore;
 
   // Cache the current event since it may become the single or long tap that we
--- a/gfx/layers/apz/src/HitTestingTreeNode.cpp
+++ b/gfx/layers/apz/src/HitTestingTreeNode.cpp
@@ -47,19 +47,17 @@ HitTestingTreeNode::RecycleWith(AsyncPan
   Destroy(); // clear out tree pointers
   mApzc = aApzc;
   mLayersId = aLayersId;
   MOZ_ASSERT(!mApzc || mApzc->GetLayersId() == mLayersId);
   // The caller is expected to call SetHitTestData to repopulate the hit-test
   // fields.
 }
 
-HitTestingTreeNode::~HitTestingTreeNode()
-{
-}
+HitTestingTreeNode::~HitTestingTreeNode() = default;
 
 void
 HitTestingTreeNode::Destroy()
 {
   APZThreadUtils::AssertOnSamplerThread();
 
   mPrevSibling = nullptr;
   mLastChild = nullptr;
--- a/gfx/layers/apz/src/InputBlockState.h
+++ b/gfx/layers/apz/src/InputBlockState.h
@@ -6,17 +6,17 @@
 
 #ifndef mozilla_layers_InputBlockState_h
 #define mozilla_layers_InputBlockState_h
 
 #include "InputData.h"                      // for MultiTouchInput
 #include "mozilla/RefCounted.h"             // for RefCounted
 #include "mozilla/RefPtr.h"                 // for RefPtr
 #include "mozilla/gfx/Matrix.h"             // for Matrix4x4
-#include "mozilla/layers/APZUtils.h"     
+#include "mozilla/layers/APZUtils.h"
 #include "mozilla/layers/LayersTypes.h"     // for TouchBehaviorFlags
 #include "mozilla/layers/AsyncDragMetrics.h"
 #include "mozilla/TimeStamp.h"              // for TimeStamp
 #include "nsTArray.h"                       // for nsTArray
 #include "TouchCounter.h"
 
 namespace mozilla {
 namespace layers {
@@ -47,18 +47,17 @@ public:
     eUnconfirmed,
     eTimedOut,
     eTimedOutAndMainThreadResponded,
     eConfirmed
   };
 
   explicit InputBlockState(const RefPtr<AsyncPanZoomController>& aTargetApzc,
                            TargetConfirmationFlags aFlags);
-  virtual ~InputBlockState()
-  {}
+  virtual ~InputBlockState() = default;
 
   virtual CancelableBlockState* AsCancelableBlock() {
     return nullptr;
   }
   virtual TouchBlockState* AsTouchBlock() {
     return nullptr;
   }
   virtual WheelBlockState* AsWheelBlock() {
--- a/gfx/layers/apz/src/InputQueue.cpp
+++ b/gfx/layers/apz/src/InputQueue.cpp
@@ -15,19 +15,17 @@
 #include "QueuedInput.h"
 
 #define INPQ_LOG(...)
 // #define INPQ_LOG(...) printf_stderr("INPQ: " __VA_ARGS__)
 
 namespace mozilla {
 namespace layers {
 
-InputQueue::InputQueue()
-{
-}
+InputQueue::InputQueue() = default;
 
 InputQueue::~InputQueue() {
   mQueuedInputs.Clear();
 }
 
 nsEventStatus
 InputQueue::ReceiveInputEvent(const RefPtr<AsyncPanZoomController>& aTarget,
                               TargetConfirmationFlags aFlags,
--- a/gfx/layers/apz/src/KeyboardMap.cpp
+++ b/gfx/layers/apz/src/KeyboardMap.cpp
@@ -6,19 +6,17 @@
 
 #include "mozilla/layers/KeyboardMap.h"
 
 #include "mozilla/TextEvents.h" // for IgnoreModifierState, ShortcutKeyCandidate
 
 namespace mozilla {
 namespace layers {
 
-KeyboardShortcut::KeyboardShortcut()
-{
-}
+KeyboardShortcut::KeyboardShortcut() = default;
 
 KeyboardShortcut::KeyboardShortcut(KeyboardInput::KeyboardEventType aEventType,
                                    uint32_t aKeyCode,
                                    uint32_t aCharCode,
                                    Modifiers aModifiers,
                                    Modifiers aModifiersMask,
                                    const KeyboardScrollAction& aAction)
   : mAction(aAction)
@@ -125,19 +123,17 @@ KeyboardShortcut::MatchesModifiers(const
   return (aInput.modifiers & modifiersMask) == mModifiers;
 }
 
 KeyboardMap::KeyboardMap(nsTArray<KeyboardShortcut>&& aShortcuts)
   : mShortcuts(aShortcuts)
 {
 }
 
-KeyboardMap::KeyboardMap()
-{
-}
+KeyboardMap::KeyboardMap() = default;
 
 Maybe<KeyboardShortcut>
 KeyboardMap::FindMatch(const KeyboardInput& aEvent) const
 {
   // If there are no shortcut candidates, then just search with with the
   // keyboard input
   if (aEvent.mShortcutCandidates.IsEmpty()) {
     return FindMatchInternal(aEvent, IgnoreModifierState());
--- a/gfx/layers/apz/src/Overscroll.h
+++ b/gfx/layers/apz/src/Overscroll.h
@@ -64,17 +64,17 @@ public:
 
 private:
   AsyncPanZoomController& mApzc;
 };
 
 // Base class for different overscroll effects;
 class OverscrollEffectBase {
 public:
-  virtual ~OverscrollEffectBase() {}
+  virtual ~OverscrollEffectBase() = default;
   virtual void ConsumeOverscroll(ParentLayerPoint& aOverscroll,
                                  bool aShouldOverscrollX,
                                  bool aShouldOverscrollY) = 0;
   virtual void HandleFlingOverscroll(const ParentLayerPoint& aVelocity) = 0;
 };
 
 // A generic overscroll effect, implemented by AsyncPanZoomController itself.
 class GenericOverscrollEffect : public OverscrollEffectBase {
--- a/gfx/layers/apz/src/OverscrollHandoffState.cpp
+++ b/gfx/layers/apz/src/OverscrollHandoffState.cpp
@@ -8,17 +8,17 @@
 
 #include <algorithm>              // for std::stable_sort
 #include "mozilla/Assertions.h"
 #include "AsyncPanZoomController.h"
 
 namespace mozilla {
 namespace layers {
 
-OverscrollHandoffChain::~OverscrollHandoffChain() {}
+OverscrollHandoffChain::~OverscrollHandoffChain() = default;
 
 void
 OverscrollHandoffChain::Add(AsyncPanZoomController* aApzc)
 {
   mChain.push_back(aApzc);
 }
 
 struct CompareByScrollPriority