From e1121dae1a987263d8ad976b839514cdbaf6a32f Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Thu, 20 Apr 2017 10:38:04 -0400 Subject: [PATCH] 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 --- gfx/layers/apz/src/APZCTreeManager.cpp | 51 ++++++++++++++++---------- gfx/layers/apz/src/APZCTreeManager.h | 13 ++++++- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 58299cf2fb4a..af0cf45ae1ad 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -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 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(root, - [&](LayerMetricsWrapper aLayerMetrics) + ForEachNode(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 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 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 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 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 HitTestingTreeNode* +APZCTreeManager::PrepareNodeForLayer(const ScrollNode& aLayer, const FrameMetrics& aMetrics, uint64_t aLayersId, const gfx::Matrix4x4& aAncestorTransform, diff --git a/gfx/layers/apz/src/APZCTreeManager.h b/gfx/layers/apz/src/APZCTreeManager.h index 6f401fdc9255..7e61d69dff14 100644 --- a/gfx/layers/apz/src/APZCTreeManager.h +++ b/gfx/layers/apz/src/APZCTreeManager.h @@ -436,6 +436,13 @@ private: typedef bool (*GuidComparator)(const ScrollableLayerGuid&, const ScrollableLayerGuid&); /* Helpers */ + template + 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 RecycleOrCreateNode(TreeBuildingState& aState, AsyncPanZoomController* aApzc, uint64_t aLayersId); - HitTestingTreeNode* PrepareNodeForLayer(const LayerMetricsWrapper& aLayer, + template + 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 + void PrintAPZCInfo(const ScrollNode& aLayer, const AsyncPanZoomController* apzc); void NotifyScrollbarDragRejected(const ScrollableLayerGuid& aGuid) const;