Bug 1447299 - Have the APZCTreeManager keep a pointer to the sampler. r?botond
MozReview-Commit-ID: 28YcJr5Ure6
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -16,16 +16,17 @@
#include "InputData.h" // for InputData, etc
#include "Layers.h" // for Layer, etc
#include "mozilla/dom/MouseEventBinding.h" // for MouseEvent constants
#include "mozilla/dom/Touch.h" // for Touch
#include "mozilla/gfx/gfxVars.h" // for gfxVars
#include "mozilla/gfx/GPUParent.h" // for GPUParent
#include "mozilla/gfx/Logging.h" // for gfx::TreeLog
#include "mozilla/gfx/Point.h" // for Point
+#include "mozilla/layers/APZSampler.h" // for APZSampler
#include "mozilla/layers/APZThreadUtils.h" // for AssertOnControllerThread, etc
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform
#include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics
#include "mozilla/layers/CompositorBridgeParent.h" // for CompositorBridgeParent, etc
#include "mozilla/layers/LayerMetricsWrapper.h"
#include "mozilla/layers/WebRenderScrollDataWrapper.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/mozalloc.h" // for operator new
@@ -219,16 +220,17 @@ private:
FocusState& mFocusState;
InputData& mEvent;
bool mMayChangeFocus;
};
APZCTreeManager::APZCTreeManager(uint64_t aRootLayersId)
: mInputQueue(new InputQueue()),
mRootLayersId(aRootLayersId),
+ mSampler(nullptr),
mTreeLock("APZCTreeLock"),
mHitResultForInputBlock(CompositorHitTestInfo::eInvisibleToHitTest),
mRetainedTouchIdentifier(-1),
mInScrollbarTouchDrag(false),
mApzcTreeLog("apzctree"),
mTestDataLock("APZTestDataLock"),
mDPI(160.0)
{
@@ -244,16 +246,23 @@ APZCTreeManager::APZCTreeManager(uint64_
#endif // (MOZ_WIDGET_ANDROID)
}
APZCTreeManager::~APZCTreeManager()
{
}
void
+APZCTreeManager::SetSampler(APZSampler* aSampler)
+{
+ MOZ_ASSERT(!mSampler);
+ mSampler = aSampler;
+}
+
+void
APZCTreeManager::NotifyLayerTreeAdopted(uint64_t aLayersId,
const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
{
APZThreadUtils::AssertOnSamplerThread();
if (aOldApzcTreeManager) {
aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
// While we could move the focus target information from the old APZC tree
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -39,16 +39,17 @@ class WebRenderAPI;
struct WrTransformProperty;
}
namespace layers {
class Layer;
class AsyncPanZoomController;
class APZCTreeManagerParent;
+class APZSampler;
class CompositorBridgeParent;
class OverscrollHandoffChain;
struct OverscrollHandoffState;
class FocusTarget;
struct FlingHandoffState;
struct ScrollableLayerGuidHash;
class LayerMetricsWrapper;
class InputQueue;
@@ -110,16 +111,18 @@ class APZCTreeManager : public IAPZCTree
// sole purpose of this struct is to shorten the argument list to
// UpdateHitTestingTree. All the state that we don't need to
// push on the stack during recursion and pop on unwind is stored here.
struct TreeBuildingState;
public:
explicit APZCTreeManager(uint64_t aRootLayersId);
+ void SetSampler(APZSampler* aSampler);
+
/**
* Notifies this APZCTreeManager that the associated compositor is now
* responsible for managing another layers id, which got moved over from
* some other compositor. That other compositor's APZCTreeManager is also
* provided. This allows APZCTreeManager to transfer any necessary state
* from the old APZCTreeManager related to that layers id.
* This function must be called on the sampler thread.
*/
@@ -685,16 +688,22 @@ protected:
* figure out where they're going. Protected so gtests can access it.
*/
RefPtr<InputQueue> mInputQueue;
private:
/* Layers id for the root CompositorBridgeParent that owns this APZCTreeManager. */
uint64_t mRootLayersId;
+ /* Pointer to the APZSampler instance that is bound to this APZCTreeManager.
+ * The sampler has a RefPtr to this class that is not nulled out until it
+ * is destroyed, so we keep a non-owning raw pointer back to the APZSampler.
+ */
+ APZSampler* MOZ_NON_OWNING_REF mSampler;
+
/* Whenever walking or mutating the tree rooted at mRootNode, mTreeLock must be held.
* This lock does not need to be held while manipulating a single APZC instance in
* isolation (that is, if its tree pointers are not being accessed or mutated). The
* lock also needs to be held when accessing the mRootNode instance variable, as that
* is considered part of the APZC tree management state.
* IMPORTANT: See the note about lock ordering at the top of this file. */
mutable mozilla::RecursiveMutex mTreeLock;
RefPtr<HitTestingTreeNode> mRootNode;
--- a/gfx/layers/apz/src/APZSampler.cpp
+++ b/gfx/layers/apz/src/APZSampler.cpp
@@ -13,16 +13,18 @@
#include "TreeTraversal.h"
namespace mozilla {
namespace layers {
APZSampler::APZSampler(const RefPtr<APZCTreeManager>& aApz)
: mApz(aApz)
{
+ MOZ_ASSERT(aApz);
+ mApz->SetSampler(this);
}
APZSampler::~APZSampler()
{
}
void
APZSampler::ClearTree()