Bug 1583380. Collect fixed position info on APZCTreeManager and use that to provide transforms to webrender via SampleForWebRender. r=botond

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Timothy Nikkel 2019-11-29 23:06:41 +00:00
Родитель fb46cff121
Коммит 51f49f02a6
2 изменённых файлов: 63 добавлений и 1 удалений

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

@ -152,6 +152,11 @@ struct APZCTreeManager::TreeBuildingState {
// is cleared back to Nothing(). Note that this is only used in the WebRender // is cleared back to Nothing(). Note that this is only used in the WebRender
// codepath. // codepath.
Maybe<uint64_t> mZoomAnimationId; Maybe<uint64_t> mZoomAnimationId;
// This is populated with all the HitTestingTreeNodes that have a fixed
// position animation id (which indicates that they need to be sampled for
// WebRender on the sampler thread).
std::vector<HitTestingTreeNode*> mFixedPositionNodesWithAnimationId;
}; };
class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver { class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver {
@ -473,6 +478,10 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,
if (node->IsScrollThumbNode() && node->GetScrollbarAnimationId()) { if (node->IsScrollThumbNode() && node->GetScrollbarAnimationId()) {
state.mScrollThumbs.push_back(node); state.mScrollThumbs.push_back(node);
} }
// GetFixedPositionAnimationId is only set when webrender is enabled.
if (node->GetFixedPositionAnimationId().isSome()) {
state.mFixedPositionNodesWithAnimationId.push_back(node);
}
if (apzc && node->IsPrimaryHolder()) { if (apzc && node->IsPrimaryHolder()) {
state.mScrollTargets[apzc->GetGuid()] = node; state.mScrollTargets[apzc->GetGuid()] = node;
} }
@ -618,6 +627,17 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot,
thumb->GetScrollbarData(), targetGuid, target->GetTransform(), thumb->GetScrollbarData(), targetGuid, target->GetTransform(),
target->IsAncestorOf(thumb)); target->IsAncestorOf(thumb));
} }
mFixedPositionInfo.clear();
// For non-webrender, state.mFixedPositionNodesWithAnimationId will be empty
// so this will be a no-op.
for (HitTestingTreeNode* fixedPos :
state.mFixedPositionNodesWithAnimationId) {
MOZ_ASSERT(fixedPos->GetFixedPositionAnimationId().isSome());
mFixedPositionInfo.emplace_back(
fixedPos->GetFixedPositionAnimationId().value(),
fixedPos->GetFixedPosSides());
}
} }
for (size_t i = 0; i < state.mNodesToDestroy.Length(); i++) { for (size_t i = 0; i < state.mNodesToDestroy.Length(); i++) {
@ -740,6 +760,21 @@ void APZCTreeManager::SampleForWebRender(wr::TransactionWrapper& aTxn,
transforms.AppendElement( transforms.AppendElement(
wr::ToWrTransformProperty(info.mThumbAnimationId, transform)); wr::ToWrTransformProperty(info.mThumbAnimationId, transform));
} }
for (const FixedPositionInfo& info : mFixedPositionInfo) {
ScreenPoint translation =
AsyncCompositionManager::ComputeFixedMarginsOffset(
mCompositorFixedLayerMargins, info.mFixedPosSides,
mGeckoFixedLayerMargins);
LayerToParentLayerMatrix4x4 transform =
LayerToParentLayerMatrix4x4::Translation(ViewAs<ParentLayerPixel>(
translation, PixelCastJustification::ScreenIsParentLayerForRoot));
transforms.AppendElement(
wr::ToWrTransformProperty(info.mFixedPositionAnimationId, transform));
}
aTxn.AppendTransformProperties(transforms); aTxn.AppendTransformProperties(transforms);
// Advance animations. It's important that this happens after // Advance animations. It's important that this happens after

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

@ -791,7 +791,8 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
*/ */
bool mUsingAsyncZoomContainer; bool mUsingAsyncZoomContainer;
/** A lock that protects mApzcMap and mScrollThumbInfo. */ /** A lock that protects mApzcMap, mScrollThumbInfo, and mFixedPositionInfo.
*/
mutable mozilla::Mutex mMapLock; mutable mozilla::Mutex mMapLock;
/** /**
* A map for quick access to get APZC instances by guid, without having to * A map for quick access to get APZC instances by guid, without having to
@ -842,6 +843,32 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge {
*/ */
std::vector<ScrollThumbInfo> mScrollThumbInfo; std::vector<ScrollThumbInfo> mScrollThumbInfo;
/**
* A helper structure to store all the information needed to compute the
* async transform for a fixed position element on the sampler thread.
*/
struct FixedPositionInfo {
uint64_t mFixedPositionAnimationId;
SideBits mFixedPosSides;
FixedPositionInfo(const uint64_t& aFixedPositionAnimationId,
const SideBits aFixedPosSides)
: mFixedPositionAnimationId(aFixedPositionAnimationId),
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 fixed 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. mFixedPositionInfo,
* 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 mFixedPositionInfo.
*/
std::vector<FixedPositionInfo> mFixedPositionInfo;
/* 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. */