Commit 50c695f4 authored by Kris Taeleman's avatar Kris Taeleman
Browse files

Bug 1610731 - Add plumbing for sticky data. r=botond

This patch is pretty uninteresting, just building the pipe to move data
from the main-thread to APZ.

Differential Revision: https://phabricator.services.mozilla.com/D69555

--HG--
extra : moz-landing-system : lando
parent 4c319c0c
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -569,6 +569,31 @@ struct ParamTraits<mozilla::gfx::RectTyped<T>> {
  }
};

template <class T>
struct ParamTraits<mozilla::gfx::RectAbsoluteTyped<T>> {
  typedef mozilla::gfx::RectAbsoluteTyped<T> paramType;

  static void Write(Message* msg, const paramType& param) {
    WriteParam(msg, param.Left());
    WriteParam(msg, param.Right());
    WriteParam(msg, param.Top());
    WriteParam(msg, param.Bottom());
  }

  static bool Read(const Message* msg, PickleIterator* iter,
                   paramType* result) {
    auto l = result->Left();
    auto r = result->Right();
    auto t = result->Top();
    auto b = result->Bottom();

    bool retVal = (ReadParam(msg, iter, &l) && ReadParam(msg, iter, &r) &&
                   ReadParam(msg, iter, &t) && ReadParam(msg, iter, &b));
    result->SetBox(l, r, t, b);
    return retVal;
  }
};

template <class T>
struct ParamTraits<mozilla::gfx::IntRectTyped<T>> {
  typedef mozilla::gfx::IntRectTyped<T> paramType;
+8 −0
Original line number Diff line number Diff line
@@ -455,6 +455,14 @@ class MOZ_STACK_CLASS LayerMetricsWrapper final {
    return empty;
  }

  Maybe<uint64_t> GetStickyPositionAnimationId() const {
    MOZ_ASSERT(IsValid());
    // This function is only really needed for template-compatibility with
    // WebRenderScrollDataWrapper. Although it will be called, the return
    // value is not used.
    return Nothing();
  }

  Maybe<uint64_t> GetZoomAnimationId() const {
    MOZ_ASSERT(IsValid());
    // This function is only really needed for template-compatibility with
+12 −2
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ struct APZCTreeManager::TreeBuildingState {
  // a layers update, and then moved into APZCTreeManager.
  std::vector<FixedPositionInfo> mFixedPositionInfo;
  std::vector<RootScrollbarInfo> mRootScrollbarInfo;
  std::vector<StickyPositionInfo> mStickyPositionInfo;
};

class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver {
@@ -484,6 +485,12 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,
                *(node->GetFixedPositionAnimationId()),
                node->GetFixedPosSides());
          }
          // GetStickyPositionAnimationId is only set when webrender is enabled.
          if (node->GetStickyPositionAnimationId().isSome()) {
            state.mStickyPositionInfo.emplace_back(
                *(node->GetStickyPositionAnimationId()),
                node->GetFixedPosSides());
          }
          if (apzc && node->IsPrimaryHolder()) {
            state.mScrollTargets[apzc->GetGuid()] = node;
          }
@@ -631,6 +638,7 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,

    mRootScrollbarInfo = std::move(state.mRootScrollbarInfo);
    mFixedPositionInfo = std::move(state.mFixedPositionInfo);
    mStickyPositionInfo = std::move(state.mStickyPositionInfo);
  }

  for (size_t i = 0; i < state.mNodesToDestroy.Length(); i++) {
@@ -1176,7 +1184,8 @@ HitTestingTreeNode* APZCTreeManager::PrepareNodeForLayer(
                          aLayer.GetFixedPositionAnimationId());
    node->SetStickyPosData(aLayer.GetStickyScrollContainerId(),
                           aLayer.GetStickyScrollRangeOuter(),
                           aLayer.GetStickyScrollRangeInner());
                           aLayer.GetStickyScrollRangeInner(),
                           aLayer.GetStickyPositionAnimationId());
    return node;
  }

@@ -1405,7 +1414,8 @@ HitTestingTreeNode* APZCTreeManager::PrepareNodeForLayer(
                        aLayer.GetFixedPositionAnimationId());
  node->SetStickyPosData(aLayer.GetStickyScrollContainerId(),
                         aLayer.GetStickyScrollRangeOuter(),
                         aLayer.GetStickyScrollRangeInner());
                         aLayer.GetStickyScrollRangeInner(),
                         aLayer.GetStickyPositionAnimationId());
  return node;
}

+28 −2
Original line number Diff line number Diff line
@@ -816,8 +816,8 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
   */
  bool mUsingAsyncZoomContainer;

  /** A lock that protects mApzcMap, mScrollThumbInfo, mRootScrollbarInfo, and
   * mFixedPositionInfo.
  /** A lock that protects mApzcMap, mScrollThumbInfo, mRootScrollbarInfo,
   * mFixedPositionInfo, and mStickyPositionInfo.
   */
  mutable mozilla::Mutex mMapLock;

@@ -933,6 +933,32 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
   */
  std::vector<FixedPositionInfo> mFixedPositionInfo;

  /**
   * A helper structure to store all the information needed to compute the
   * async transform for a sticky position element on the sampler thread.
   */
  struct StickyPositionInfo {
    uint64_t mStickyPositionAnimationId;
    SideBits mFixedPosSides;

    StickyPositionInfo(const uint64_t& aStickyPositionAnimationId,
                       const SideBits aFixedPosSides)
        : mStickyPositionAnimationId(aStickyPositionAnimationId),
          mFixedPosSides(aFixedPosSides) {}
  };
  /**
   * If this APZCTreeManager is being used with WebRender, this vector gets
   * populated during a layers update. It holds a package of information needed
   * to compute and set the async transforms on sticky position content. This
   * information is extracted from the HitTestingTreeNodes for the WebRender
   * case because accessing the HitTestingTreeNodes requires holding the tree
   * lock which we cannot do on the WR sampler thread. mStickyPositionInfo,
   * however, can be accessed while just holding the mMapLock which is safe to
   * do on the sampler thread. mMapLock must be acquired while accessing or
   * modifying mStickyPositionInfo.
   */
  std::vector<StickyPositionInfo> mStickyPositionInfo;

  /* Holds the zoom constraints for scrollable layers, as determined by the
   * the main-thread gecko code. This can only be accessed on the updater
   * thread. */
+7 −1
Original line number Diff line number Diff line
@@ -177,10 +177,12 @@ void HitTestingTreeNode::SetPrevSibling(HitTestingTreeNode* aSibling) {
void HitTestingTreeNode::SetStickyPosData(
    ScrollableLayerGuid::ViewID aStickyPosTarget,
    const LayerRectAbsolute& aScrollRangeOuter,
    const LayerRectAbsolute& aScrollRangeInner) {
    const LayerRectAbsolute& aScrollRangeInner,
    const Maybe<uint64_t>& aStickyPositionAnimationId) {
  mStickyPosTarget = aStickyPosTarget;
  mStickyScrollRangeOuter = aScrollRangeOuter;
  mStickyScrollRangeInner = aScrollRangeInner;
  mStickyPositionAnimationId = aStickyPositionAnimationId;
}

ScrollableLayerGuid::ViewID HitTestingTreeNode::GetStickyPosTarget() const {
@@ -195,6 +197,10 @@ const LayerRectAbsolute& HitTestingTreeNode::GetStickyScrollRangeInner() const {
  return mStickyScrollRangeInner;
}

Maybe<uint64_t> HitTestingTreeNode::GetStickyPositionAnimationId() const {
  return mStickyPositionAnimationId;
}

void HitTestingTreeNode::MakeRoot() {
  mParent = nullptr;

Loading