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
This commit is contained in:
Kris Taeleman 2020-04-04 01:02:03 +00:00
Родитель dcd22a4c33
Коммит b930c987dc
9 изменённых файлов: 152 добавлений и 13 удалений

Просмотреть файл

@ -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> template <class T>
struct ParamTraits<mozilla::gfx::IntRectTyped<T>> { struct ParamTraits<mozilla::gfx::IntRectTyped<T>> {
typedef mozilla::gfx::IntRectTyped<T> paramType; typedef mozilla::gfx::IntRectTyped<T> paramType;

Просмотреть файл

@ -455,6 +455,14 @@ class MOZ_STACK_CLASS LayerMetricsWrapper final {
return empty; 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 { Maybe<uint64_t> GetZoomAnimationId() const {
MOZ_ASSERT(IsValid()); MOZ_ASSERT(IsValid());
// This function is only really needed for template-compatibility with // This function is only really needed for template-compatibility with

Просмотреть файл

@ -152,6 +152,7 @@ struct APZCTreeManager::TreeBuildingState {
// a layers update, and then moved into APZCTreeManager. // a layers update, and then moved into APZCTreeManager.
std::vector<FixedPositionInfo> mFixedPositionInfo; std::vector<FixedPositionInfo> mFixedPositionInfo;
std::vector<RootScrollbarInfo> mRootScrollbarInfo; std::vector<RootScrollbarInfo> mRootScrollbarInfo;
std::vector<StickyPositionInfo> mStickyPositionInfo;
}; };
class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver { class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver {
@ -484,6 +485,12 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,
*(node->GetFixedPositionAnimationId()), *(node->GetFixedPositionAnimationId()),
node->GetFixedPosSides()); 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()) { if (apzc && node->IsPrimaryHolder()) {
state.mScrollTargets[apzc->GetGuid()] = node; state.mScrollTargets[apzc->GetGuid()] = node;
} }
@ -631,6 +638,7 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,
mRootScrollbarInfo = std::move(state.mRootScrollbarInfo); mRootScrollbarInfo = std::move(state.mRootScrollbarInfo);
mFixedPositionInfo = std::move(state.mFixedPositionInfo); mFixedPositionInfo = std::move(state.mFixedPositionInfo);
mStickyPositionInfo = std::move(state.mStickyPositionInfo);
} }
for (size_t i = 0; i < state.mNodesToDestroy.Length(); i++) { for (size_t i = 0; i < state.mNodesToDestroy.Length(); i++) {
@ -1176,7 +1184,8 @@ HitTestingTreeNode* APZCTreeManager::PrepareNodeForLayer(
aLayer.GetFixedPositionAnimationId()); aLayer.GetFixedPositionAnimationId());
node->SetStickyPosData(aLayer.GetStickyScrollContainerId(), node->SetStickyPosData(aLayer.GetStickyScrollContainerId(),
aLayer.GetStickyScrollRangeOuter(), aLayer.GetStickyScrollRangeOuter(),
aLayer.GetStickyScrollRangeInner()); aLayer.GetStickyScrollRangeInner(),
aLayer.GetStickyPositionAnimationId());
return node; return node;
} }
@ -1405,7 +1414,8 @@ HitTestingTreeNode* APZCTreeManager::PrepareNodeForLayer(
aLayer.GetFixedPositionAnimationId()); aLayer.GetFixedPositionAnimationId());
node->SetStickyPosData(aLayer.GetStickyScrollContainerId(), node->SetStickyPosData(aLayer.GetStickyScrollContainerId(),
aLayer.GetStickyScrollRangeOuter(), aLayer.GetStickyScrollRangeOuter(),
aLayer.GetStickyScrollRangeInner()); aLayer.GetStickyScrollRangeInner(),
aLayer.GetStickyPositionAnimationId());
return node; return node;
} }

Просмотреть файл

@ -816,8 +816,8 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
*/ */
bool mUsingAsyncZoomContainer; bool mUsingAsyncZoomContainer;
/** A lock that protects mApzcMap, mScrollThumbInfo, mRootScrollbarInfo, and /** A lock that protects mApzcMap, mScrollThumbInfo, mRootScrollbarInfo,
* mFixedPositionInfo. * mFixedPositionInfo, and mStickyPositionInfo.
*/ */
mutable mozilla::Mutex mMapLock; mutable mozilla::Mutex mMapLock;
@ -933,6 +933,32 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
*/ */
std::vector<FixedPositionInfo> mFixedPositionInfo; 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 /* Holds the zoom constraints for scrollable layers, as determined by the
* the main-thread gecko code. This can only be accessed on the updater * the main-thread gecko code. This can only be accessed on the updater
* thread. */ * thread. */

Просмотреть файл

@ -177,10 +177,12 @@ void HitTestingTreeNode::SetPrevSibling(HitTestingTreeNode* aSibling) {
void HitTestingTreeNode::SetStickyPosData( void HitTestingTreeNode::SetStickyPosData(
ScrollableLayerGuid::ViewID aStickyPosTarget, ScrollableLayerGuid::ViewID aStickyPosTarget,
const LayerRectAbsolute& aScrollRangeOuter, const LayerRectAbsolute& aScrollRangeOuter,
const LayerRectAbsolute& aScrollRangeInner) { const LayerRectAbsolute& aScrollRangeInner,
const Maybe<uint64_t>& aStickyPositionAnimationId) {
mStickyPosTarget = aStickyPosTarget; mStickyPosTarget = aStickyPosTarget;
mStickyScrollRangeOuter = aScrollRangeOuter; mStickyScrollRangeOuter = aScrollRangeOuter;
mStickyScrollRangeInner = aScrollRangeInner; mStickyScrollRangeInner = aScrollRangeInner;
mStickyPositionAnimationId = aStickyPositionAnimationId;
} }
ScrollableLayerGuid::ViewID HitTestingTreeNode::GetStickyPosTarget() const { ScrollableLayerGuid::ViewID HitTestingTreeNode::GetStickyPosTarget() const {
@ -195,6 +197,10 @@ const LayerRectAbsolute& HitTestingTreeNode::GetStickyScrollRangeInner() const {
return mStickyScrollRangeInner; return mStickyScrollRangeInner;
} }
Maybe<uint64_t> HitTestingTreeNode::GetStickyPositionAnimationId() const {
return mStickyPositionAnimationId;
}
void HitTestingTreeNode::MakeRoot() { void HitTestingTreeNode::MakeRoot() {
mParent = nullptr; mParent = nullptr;

Просмотреть файл

@ -136,10 +136,12 @@ class HitTestingTreeNode {
/* Sticky pos info */ /* Sticky pos info */
void SetStickyPosData(ScrollableLayerGuid::ViewID aStickyPosTarget, void SetStickyPosData(ScrollableLayerGuid::ViewID aStickyPosTarget,
const LayerRectAbsolute& aScrollRangeOuter, const LayerRectAbsolute& aScrollRangeOuter,
const LayerRectAbsolute& aScrollRangeInner); const LayerRectAbsolute& aScrollRangeInner,
const Maybe<uint64_t>& aStickyPositionAnimationId);
ScrollableLayerGuid::ViewID GetStickyPosTarget() const; ScrollableLayerGuid::ViewID GetStickyPosTarget() const;
const LayerRectAbsolute& GetStickyScrollRangeOuter() const; const LayerRectAbsolute& GetStickyScrollRangeOuter() const;
const LayerRectAbsolute& GetStickyScrollRangeInner() const; const LayerRectAbsolute& GetStickyScrollRangeInner() const;
Maybe<uint64_t> GetStickyPositionAnimationId() const;
/* Convert |aPoint| into the LayerPixel space for the layer corresponding to /* Convert |aPoint| into the LayerPixel space for the layer corresponding to
* this node. |aTransform| is the complete (content + async) transform for * this node. |aTransform| is the complete (content + async) transform for
@ -205,6 +207,9 @@ class HitTestingTreeNode {
ScrollableLayerGuid::ViewID mStickyPosTarget; ScrollableLayerGuid::ViewID mStickyPosTarget;
LayerRectAbsolute mStickyScrollRangeOuter; LayerRectAbsolute mStickyScrollRangeOuter;
LayerRectAbsolute mStickyScrollRangeInner; LayerRectAbsolute mStickyScrollRangeInner;
// This is only set if WebRender is enabled. It holds the animation id that
// we use to adjust sticky position content for the toolbar.
Maybe<uint64_t> mStickyPositionAnimationId;
/* Let {L,M} be the {layer, scrollable metrics} pair that this node /* Let {L,M} be the {layer, scrollable metrics} pair that this node
* corresponds to in the layer tree. mEventRegions contains the event regions * corresponds to in the layer tree. mEventRegions contains the event regions

Просмотреть файл

@ -23,6 +23,7 @@ WebRenderLayerScrollData::WebRenderLayerScrollData()
mEventRegionsOverride(EventRegionsOverride::NoOverride), mEventRegionsOverride(EventRegionsOverride::NoOverride),
mFixedPositionSides(mozilla::SideBits::eNone), mFixedPositionSides(mozilla::SideBits::eNone),
mFixedPosScrollContainerId(ScrollableLayerGuid::NULL_SCROLL_ID), mFixedPosScrollContainerId(ScrollableLayerGuid::NULL_SCROLL_ID),
mStickyPosScrollContainerId(ScrollableLayerGuid::NULL_SCROLL_ID),
mRenderRoot(wr::RenderRoot::Default) {} mRenderRoot(wr::RenderRoot::Default) {}
WebRenderLayerScrollData::~WebRenderLayerScrollData() = default; WebRenderLayerScrollData::~WebRenderLayerScrollData() = default;

Просмотреть файл

@ -124,6 +124,34 @@ class WebRenderLayerScrollData final {
return mFixedPosScrollContainerId; return mFixedPosScrollContainerId;
} }
void SetStickyPositionScrollContainerId(ScrollableLayerGuid::ViewID aId) {
mStickyPosScrollContainerId = aId;
}
ScrollableLayerGuid::ViewID GetStickyPositionScrollContainerId() const {
return mStickyPosScrollContainerId;
}
void SetStickyScrollRangeOuter(const LayerRectAbsolute& scrollRange) {
mStickyScrollRangeOuter = scrollRange;
}
const LayerRectAbsolute& GetStickyScrollRangeOuter() const {
return mStickyScrollRangeOuter;
}
void SetStickyScrollRangeInner(const LayerRectAbsolute& scrollRange) {
mStickyScrollRangeInner = scrollRange;
}
const LayerRectAbsolute& GetStickyScrollRangeInner() const {
return mStickyScrollRangeInner;
}
void SetStickyPositionAnimationId(const uint64_t& aId) {
mStickyPositionAnimationId = Some(aId);
}
Maybe<uint64_t> GetStickyPositionAnimationId() const {
return mStickyPositionAnimationId;
}
wr::RenderRoot GetRenderRoot() { return mRenderRoot; } wr::RenderRoot GetRenderRoot() { return mRenderRoot; }
void SetZoomAnimationId(const uint64_t& aId) { mZoomAnimationId = Some(aId); } void SetZoomAnimationId(const uint64_t& aId) { mZoomAnimationId = Some(aId); }
@ -171,6 +199,10 @@ class WebRenderLayerScrollData final {
Maybe<uint64_t> mFixedPositionAnimationId; Maybe<uint64_t> mFixedPositionAnimationId;
SideBits mFixedPositionSides; SideBits mFixedPositionSides;
ScrollableLayerGuid::ViewID mFixedPosScrollContainerId; ScrollableLayerGuid::ViewID mFixedPosScrollContainerId;
ScrollableLayerGuid::ViewID mStickyPosScrollContainerId;
LayerRectAbsolute mStickyScrollRangeOuter;
LayerRectAbsolute mStickyScrollRangeInner;
Maybe<uint64_t> mStickyPositionAnimationId;
wr::RenderRoot mRenderRoot; wr::RenderRoot mRenderRoot;
Maybe<uint64_t> mZoomAnimationId; Maybe<uint64_t> mZoomAnimationId;
Maybe<ScrollableLayerGuid::ViewID> mAsyncZoomContainerId; Maybe<ScrollableLayerGuid::ViewID> mAsyncZoomContainerId;
@ -274,6 +306,10 @@ struct ParamTraits<mozilla::layers::WebRenderLayerScrollData> {
WriteParam(aMsg, aParam.mFixedPositionAnimationId); WriteParam(aMsg, aParam.mFixedPositionAnimationId);
WriteParam(aMsg, aParam.mFixedPositionSides); WriteParam(aMsg, aParam.mFixedPositionSides);
WriteParam(aMsg, aParam.mFixedPosScrollContainerId); WriteParam(aMsg, aParam.mFixedPosScrollContainerId);
WriteParam(aMsg, aParam.mStickyPosScrollContainerId);
WriteParam(aMsg, aParam.mStickyScrollRangeOuter);
WriteParam(aMsg, aParam.mStickyScrollRangeInner);
WriteParam(aMsg, aParam.mStickyPositionAnimationId);
WriteParam(aMsg, aParam.mRenderRoot); WriteParam(aMsg, aParam.mRenderRoot);
WriteParam(aMsg, aParam.mZoomAnimationId); WriteParam(aMsg, aParam.mZoomAnimationId);
WriteParam(aMsg, aParam.mAsyncZoomContainerId); WriteParam(aMsg, aParam.mAsyncZoomContainerId);
@ -295,6 +331,10 @@ struct ParamTraits<mozilla::layers::WebRenderLayerScrollData> {
ReadParam(aMsg, aIter, &aResult->mFixedPositionAnimationId) && ReadParam(aMsg, aIter, &aResult->mFixedPositionAnimationId) &&
ReadParam(aMsg, aIter, &aResult->mFixedPositionSides) && ReadParam(aMsg, aIter, &aResult->mFixedPositionSides) &&
ReadParam(aMsg, aIter, &aResult->mFixedPosScrollContainerId) && ReadParam(aMsg, aIter, &aResult->mFixedPosScrollContainerId) &&
ReadParam(aMsg, aIter, &aResult->mStickyPosScrollContainerId) &&
ReadParam(aMsg, aIter, &aResult->mStickyScrollRangeOuter) &&
ReadParam(aMsg, aIter, &aResult->mStickyScrollRangeInner) &&
ReadParam(aMsg, aIter, &aResult->mStickyPositionAnimationId) &&
ReadParam(aMsg, aIter, &aResult->mRenderRoot) && ReadParam(aMsg, aIter, &aResult->mRenderRoot) &&
ReadParam(aMsg, aIter, &aResult->mZoomAnimationId) && ReadParam(aMsg, aIter, &aResult->mZoomAnimationId) &&
ReadParam(aMsg, aIter, &aResult->mAsyncZoomContainerId); ReadParam(aMsg, aIter, &aResult->mAsyncZoomContainerId);

Просмотреть файл

@ -332,23 +332,41 @@ class MOZ_STACK_CLASS WebRenderScrollDataWrapper final {
ScrollableLayerGuid::ViewID GetStickyScrollContainerId() const { ScrollableLayerGuid::ViewID GetStickyScrollContainerId() const {
MOZ_ASSERT(IsValid()); MOZ_ASSERT(IsValid());
// TODO: Bug 1610731 Implement this for WebRender. if (AtBottomLayer()) {
return mLayer->GetStickyPositionScrollContainerId();
}
return ScrollableLayerGuid::NULL_SCROLL_ID; return ScrollableLayerGuid::NULL_SCROLL_ID;
} }
const LayerRectAbsolute& GetStickyScrollRangeOuter() const { const LayerRectAbsolute& GetStickyScrollRangeOuter() const {
MOZ_ASSERT(IsValid()); MOZ_ASSERT(IsValid());
static const LayerRectAbsolute dummy;
// TODO: Bug 1610731 Implement this for WebRender. if (AtBottomLayer()) {
return dummy; return mLayer->GetStickyScrollRangeOuter();
}
static const LayerRectAbsolute empty;
return empty;
} }
const LayerRectAbsolute& GetStickyScrollRangeInner() const { const LayerRectAbsolute& GetStickyScrollRangeInner() const {
MOZ_ASSERT(IsValid()); MOZ_ASSERT(IsValid());
static const LayerRectAbsolute dummy;
// TODO: Bug 1610731 Implement this for WebRender. if (AtBottomLayer()) {
return dummy; return mLayer->GetStickyScrollRangeInner();
}
static const LayerRectAbsolute empty;
return empty;
}
Maybe<uint64_t> GetStickyPositionAnimationId() const {
MOZ_ASSERT(IsValid());
if (AtBottomLayer()) {
return mLayer->GetStickyPositionAnimationId();
}
return Nothing();
} }
Maybe<uint64_t> GetZoomAnimationId() const { Maybe<uint64_t> GetZoomAnimationId() const {