Bug 1357754 - Extract a template function from UpdateHitTestingTree. r=botond

Currently the public UpdateHitTestingTree function takes a Layer* which
assumes there is a layer tree to traverse. However, with WebRender, that
is not the case. This patch has two conceptual changes.

The first change is to extract the innards of UpdateHitTestingTree to take
a LayerMetricsWrapper instead of a Layer* and traverse the layer tree
using that. This was already mostly happening but this makes the
Layer*/LayerMetricsWrapper boundary a little more explicit.

The second change is to make the extracted helper function templated, so
it accepts anything that is template-compatible with
LayerMetricsWrapper. I chose to use a template rather inheritance to
avoid the performance hit of virtual functions, since this code runs
relatively often.

This paves the way for adding a different kind of tree-traversal object
instead of the LayerMetricsWrapper while reusing the same logic to build
the hit-testing tree and APZC nodes.

MozReview-Commit-ID: 6SmnX6Bn2QV
This commit is contained in:
Kartikaya Gupta 2017-04-20 10:38:04 -04:00
Родитель 070cc4b9a7
Коммит e1121dae1a
2 изменённых файлов: 42 добавлений и 22 удалений

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

@ -213,12 +213,12 @@ APZCTreeManager::SetAllowedTouchBehavior(uint64_t aInputBlockId,
mInputQueue->SetAllowedTouchBehavior(aInputBlockId, aValues);
}
void
APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
template<class ScrollNode> void // ScrollNode is a LayerMetricsWrapper
APZCTreeManager::UpdateHitTestingTreeImpl(uint64_t aRootLayerTreeId,
const ScrollNode& aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
APZThreadUtils::AssertOnCompositorThread();
@ -268,11 +268,10 @@ APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
ancestorTransforms.push(Matrix4x4());
mApzcTreeLog << "[start]\n";
LayerMetricsWrapper root(aRoot);
mTreeLock.AssertCurrentThreadOwns();
ForEachNode<ReverseIterator>(root,
[&](LayerMetricsWrapper aLayerMetrics)
ForEachNode<ReverseIterator>(aRoot,
[&](ScrollNode aLayerMetrics)
{
mApzcTreeLog << aLayerMetrics.Name() << '\t';
@ -308,7 +307,7 @@ APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
layersId = (aLayerMetrics.AsRefLayer() ? aLayerMetrics.AsRefLayer()->GetReferentId() : layersId);
indents.push(gfx::TreeAutoIndent(mApzcTreeLog));
},
[&](LayerMetricsWrapper aLayerMetrics)
[&](ScrollNode aLayerMetrics)
{
next = parent;
parent = parent->GetParent();
@ -337,11 +336,23 @@ APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
#endif
}
void
APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
LayerMetricsWrapper root(aRoot);
UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint,
aOriginatingLayersId, aPaintSequenceNumber);
}
// Compute the clip region to be used for a layer with an APZC. This function
// is only called for layers which actually have scrollable metrics and an APZC.
static ParentLayerIntRegion
template<class ScrollNode> static ParentLayerIntRegion
ComputeClipRegion(GeckoContentController* aController,
const LayerMetricsWrapper& aLayer)
const ScrollNode& aLayer)
{
ParentLayerIntRegion clipRegion;
if (aLayer.GetClipRect()) {
@ -357,8 +368,8 @@ ComputeClipRegion(GeckoContentController* aController,
return clipRegion;
}
void
APZCTreeManager::PrintAPZCInfo(const LayerMetricsWrapper& aLayer,
template<class ScrollNode> void
APZCTreeManager::PrintAPZCInfo(const ScrollNode& aLayer,
const AsyncPanZoomController* apzc)
{
const FrameMetrics& metrics = aLayer.Metrics();
@ -386,8 +397,8 @@ APZCTreeManager::AttachNodeToTree(HitTestingTreeNode* aNode,
}
}
static EventRegions
GetEventRegions(const LayerMetricsWrapper& aLayer)
template<class ScrollNode> static EventRegions
GetEventRegions(const ScrollNode& aLayer)
{
if (aLayer.IsScrollInfoLayer()) {
ParentLayerIntRect compositionBounds(RoundedToInt(aLayer.Metrics().GetCompositionBounds()));
@ -419,9 +430,9 @@ APZCTreeManager::RecycleOrCreateNode(TreeBuildingState& aState,
return node.forget();
}
static EventRegionsOverride
template<class ScrollNode> static EventRegionsOverride
GetEventRegionsOverride(HitTestingTreeNode* aParent,
const LayerMetricsWrapper& aLayer)
const ScrollNode& aLayer)
{
// Make it so that if the flag is set on the layer tree, it automatically
// propagates to all the nodes in the corresponding subtree rooted at that
@ -457,8 +468,8 @@ APZCTreeManager::NotifyScrollbarDragRejected(const ScrollableLayerGuid& aGuid) c
state->mController->NotifyAsyncScrollbarDragRejected(aGuid.mScrollId);
}
HitTestingTreeNode*
APZCTreeManager::PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,
template<class ScrollNode> HitTestingTreeNode*
APZCTreeManager::PrepareNodeForLayer(const ScrollNode& aLayer,
const FrameMetrics& aMetrics,
uint64_t aLayersId,
const gfx::Matrix4x4& aAncestorTransform,

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

@ -436,6 +436,13 @@ private:
typedef bool (*GuidComparator)(const ScrollableLayerGuid&, const ScrollableLayerGuid&);
/* Helpers */
template<class ScrollNode>
void UpdateHitTestingTreeImpl(uint64_t aRootLayerTreeId,
const ScrollNode& aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
void AttachNodeToTree(HitTestingTreeNode* aNode,
HitTestingTreeNode* aParent,
HitTestingTreeNode* aNextSibling);
@ -466,7 +473,8 @@ private:
already_AddRefed<HitTestingTreeNode> RecycleOrCreateNode(TreeBuildingState& aState,
AsyncPanZoomController* aApzc,
uint64_t aLayersId);
HitTestingTreeNode* PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,
template<class ScrollNode>
HitTestingTreeNode* PrepareNodeForLayer(const ScrollNode& aLayer,
const FrameMetrics& aMetrics,
uint64_t aLayersId,
const gfx::Matrix4x4& aAncestorTransform,
@ -474,7 +482,8 @@ private:
HitTestingTreeNode* aNextSibling,
TreeBuildingState& aState);
void PrintAPZCInfo(const LayerMetricsWrapper& aLayer,
template<class ScrollNode>
void PrintAPZCInfo(const ScrollNode& aLayer,
const AsyncPanZoomController* apzc);
void NotifyScrollbarDragRejected(const ScrollableLayerGuid& aGuid) const;