Bug 1447299 - Move the sampler thread util functions from APZThreadUtils to APZSampler. r=botond

Note that this also makes the utility functions instance methods,
because each APZSampler might have a different sampler thread instance.

MozReview-Commit-ID: 9dY8ZzVX6lR

--HG--
extra : rebase_source : 4dd58400aee5d9f2063abe0a912488b28ff74f9f
This commit is contained in:
Kartikaya Gupta 2018-03-28 14:56:41 -04:00
Родитель 4bbad90793
Коммит 3c26f7183f
12 изменённых файлов: 112 добавлений и 74 удалений

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

@ -104,6 +104,25 @@ public:
void MarkAsyncTransformAppliedToContent(const LayerMetricsWrapper& aLayer); void MarkAsyncTransformAppliedToContent(const LayerMetricsWrapper& aLayer);
bool HasUnusedAsyncTransform(const LayerMetricsWrapper& aLayer); bool HasUnusedAsyncTransform(const LayerMetricsWrapper& aLayer);
/**
* This can be used to assert that the current thread is the
* sampler thread (which samples the async transform).
* This does nothing if thread assertions are disabled.
*/
void AssertOnSamplerThread();
/**
* Runs the given task on the APZ "sampler thread" for this APZSampler. If
* this function is called from the sampler thread itself then the task is
* run immediately without getting queued.
*/
void RunOnSamplerThread(already_AddRefed<Runnable> aTask);
/**
* Returns true if currently on the APZSampler's "sampler thread".
*/
bool IsSamplerThread();
protected: protected:
virtual ~APZSampler(); virtual ~APZSampler();

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

@ -260,7 +260,7 @@ void
APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId, APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZCTreeManager>& aOldApzcTreeManager) const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
if (aOldApzcTreeManager) { if (aOldApzcTreeManager) {
aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId); aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
@ -287,7 +287,7 @@ APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
void void
APZCTreeManager::NotifyLayerTreeRemoved(LayersId aLayersId) APZCTreeManager::NotifyLayerTreeRemoved(LayersId aLayersId)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
mFocusState.RemoveFocusTarget(aLayersId); mFocusState.RemoveFocusTarget(aLayersId);
@ -482,7 +482,7 @@ APZCTreeManager::UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId, LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget) const FocusTarget& aFocusTarget)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
if (!gfxPrefs::APZKeyboardEnabled()) { if (!gfxPrefs::APZKeyboardEnabled()) {
return; return;
@ -500,7 +500,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId, LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber) uint32_t aPaintSequenceNumber)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
LayerMetricsWrapper root(aRoot); LayerMetricsWrapper root(aRoot);
UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint, UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint,
@ -514,7 +514,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId, LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber) uint32_t aPaintSequenceNumber)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
WebRenderScrollDataWrapper wrapper(&aScrollData); WebRenderScrollDataWrapper wrapper(&aScrollData);
UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint, UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
@ -526,7 +526,7 @@ APZCTreeManager::PushStateToWR(wr::TransactionBuilder& aTxn,
const TimeStamp& aSampleTime, const TimeStamp& aSampleTime,
nsTArray<wr::WrTransformProperty>& aTransformArray) nsTArray<wr::WrTransformProperty>& aTransformArray)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
RecursiveMutexAutoLock lock(mTreeLock); RecursiveMutexAutoLock lock(mTreeLock);
@ -1960,13 +1960,13 @@ void
APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid, APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
const Maybe<ZoomConstraints>& aConstraints) const Maybe<ZoomConstraints>& aConstraints)
{ {
if (!APZThreadUtils::IsSamplerThread()) { if (!GetSampler()->IsSamplerThread()) {
// This can happen if we're in the UI process and got a call directly from // This can happen if we're in the UI process and got a call directly from
// nsBaseWidget (as opposed to over PAPZCTreeManager). We want this function // nsBaseWidget (as opposed to over PAPZCTreeManager). We want this function
// to run on the sampler thread, so bounce it over. // to run on the sampler thread, so bounce it over.
MOZ_ASSERT(XRE_IsParentProcess()); MOZ_ASSERT(XRE_IsParentProcess());
APZThreadUtils::RunOnSamplerThread( GetSampler()->RunOnSamplerThread(
NewRunnableMethod<ScrollableLayerGuid, Maybe<ZoomConstraints>>( NewRunnableMethod<ScrollableLayerGuid, Maybe<ZoomConstraints>>(
"APZCTreeManager::UpdateZoomConstraints", "APZCTreeManager::UpdateZoomConstraints",
this, this,
@ -1976,7 +1976,7 @@ APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
return; return;
} }
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
RecursiveMutexAutoLock lock(mTreeLock); RecursiveMutexAutoLock lock(mTreeLock);
RefPtr<HitTestingTreeNode> node = GetTargetNode(aGuid, nullptr); RefPtr<HitTestingTreeNode> node = GetTargetNode(aGuid, nullptr);
@ -2071,7 +2071,7 @@ APZCTreeManager::AdjustScrollForSurfaceShift(const ScreenPoint& aShift)
void void
APZCTreeManager::ClearTree() APZCTreeManager::ClearTree()
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
#if defined(MOZ_WIDGET_ANDROID) #if defined(MOZ_WIDGET_ANDROID)
mToolbarAnimator->ClearTreeManager(); mToolbarAnimator->ClearTreeManager();
@ -3027,7 +3027,7 @@ bool
APZCTreeManager::GetAPZTestData(LayersId aLayersId, APZCTreeManager::GetAPZTestData(LayersId aLayersId,
APZTestData* aOutData) APZTestData* aOutData)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
MutexAutoLock lock(mTestDataLock); MutexAutoLock lock(mTestDataLock);
auto it = mTestData.find(aLayersId); auto it = mTestData.find(aLayersId);
if (it == mTestData.end()) { if (it == mTestData.end()) {
@ -3199,6 +3199,21 @@ APZCTreeManager::ComputeTransformForScrollThumb(
return transform; return transform;
} }
APZSampler*
APZCTreeManager::GetSampler() const
{
// We should always have a sampler here, since in practice the sampler
// is destroyed at the same time that this APZCTreeMAnager instance is.
MOZ_ASSERT(mSampler);
return mSampler;
}
void
APZCTreeManager::AssertOnSamplerThread()
{
GetSampler()->AssertOnSamplerThread();
}
void void
APZCTreeManager::SetDPI(float aDpiValue) APZCTreeManager::SetDPI(float aDpiValue)
{ {

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

@ -526,10 +526,15 @@ public:
bool aScrollbarIsDescendant, bool aScrollbarIsDescendant,
AsyncTransformComponentMatrix* aOutClipTransform); AsyncTransformComponentMatrix* aOutClipTransform);
// Assert that the current thread is the sampler thread for this APZCTM.
void AssertOnSamplerThread();
protected: protected:
// Protected destructor, to discourage deletion outside of Release(): // Protected destructor, to discourage deletion outside of Release():
virtual ~APZCTreeManager(); virtual ~APZCTreeManager();
APZSampler* GetSampler() const;
// Protected hooks for gtests subclass // Protected hooks for gtests subclass
virtual AsyncPanZoomController* NewAPZCInstance(LayersId aLayersId, virtual AsyncPanZoomController* NewAPZCInstance(LayersId aLayersId,
GeckoContentController* aController); GeckoContentController* aController);

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

@ -8,6 +8,7 @@
#include "APZCTreeManager.h" #include "APZCTreeManager.h"
#include "AsyncPanZoomController.h" #include "AsyncPanZoomController.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorThread.h" #include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/LayerMetricsWrapper.h" #include "mozilla/layers/LayerMetricsWrapper.h"
#include "TreeTraversal.h" #include "TreeTraversal.h"
@ -213,5 +214,38 @@ APZSampler::HasUnusedAsyncTransform(const LayerMetricsWrapper& aLayer)
&& !AsyncTransformComponentMatrix(apzc->GetCurrentAsyncTransform(AsyncPanZoomController::eForCompositing)).IsIdentity(); && !AsyncTransformComponentMatrix(apzc->GetCurrentAsyncTransform(AsyncPanZoomController::eForCompositing)).IsIdentity();
} }
void
APZSampler::AssertOnSamplerThread()
{
if (APZThreadUtils::GetThreadAssertionsEnabled()) {
MOZ_ASSERT(IsSamplerThread());
}
}
void
APZSampler::RunOnSamplerThread(already_AddRefed<Runnable> aTask)
{
RefPtr<Runnable> task = aTask;
MessageLoop* loop = CompositorThreadHolder::Loop();
if (!loop) {
// Could happen during startup
NS_WARNING("Dropping task posted to sampler thread");
return;
}
if (IsSamplerThread()) {
task->Run();
} else {
loop->PostTask(task.forget());
}
}
bool
APZSampler::IsSamplerThread()
{
return CompositorThreadHolder::IsInCompositorThread();
}
} // namespace layers } // namespace layers
} // namespace mozilla } // namespace mozilla

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

@ -848,7 +848,7 @@ AsyncPanZoomController::GetInputQueue() const {
void void
AsyncPanZoomController::Destroy() AsyncPanZoomController::Destroy()
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
CancelAnimation(CancelAnimationFlags::ScrollSnap); CancelAnimation(CancelAnimationFlags::ScrollSnap);
@ -3481,7 +3481,7 @@ AsyncPanZoomController::RequestContentRepaint(const FrameMetrics& aFrameMetrics,
bool AsyncPanZoomController::UpdateAnimation(const TimeStamp& aSampleTime, bool AsyncPanZoomController::UpdateAnimation(const TimeStamp& aSampleTime,
nsTArray<RefPtr<Runnable>>* aOutDeferredTasks) nsTArray<RefPtr<Runnable>>* aOutDeferredTasks)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
// This function may get called multiple with the same sample time, because // This function may get called multiple with the same sample time, because
// there may be multiple layers with this APZC, and each layer invokes this // there may be multiple layers with this APZC, and each layer invokes this
@ -3540,7 +3540,7 @@ AsyncPanZoomController::GetOverscrollTransform(AsyncTransformConsumer aMode) con
bool AsyncPanZoomController::AdvanceAnimations(const TimeStamp& aSampleTime) bool AsyncPanZoomController::AdvanceAnimations(const TimeStamp& aSampleTime)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
// Don't send any state-change notifications until the end of the function, // Don't send any state-change notifications until the end of the function,
// because we may go through some intermediate states while we finish // because we may go through some intermediate states while we finish
@ -3819,7 +3819,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const ScrollMetadata& aScrollMe
bool aIsFirstPaint, bool aIsFirstPaint,
bool aThisLayerTreeUpdated) bool aThisLayerTreeUpdated)
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
RecursiveMutexAutoLock lock(mRecursiveMutex); RecursiveMutexAutoLock lock(mRecursiveMutex);
bool isDefault = mScrollMetadata.IsDefault(); bool isDefault = mScrollMetadata.IsDefault();
@ -4083,6 +4083,14 @@ const ScrollMetadata& AsyncPanZoomController::GetScrollMetadata() const {
return mScrollMetadata; return mScrollMetadata;
} }
void
AsyncPanZoomController::AssertOnSamplerThread() const
{
if (APZCTreeManager* treeManagerLocal = GetApzcTreeManager()) {
treeManagerLocal->AssertOnSamplerThread();
}
}
APZCTreeManager* AsyncPanZoomController::GetApzcTreeManager() const { APZCTreeManager* AsyncPanZoomController::GetApzcTreeManager() const {
mRecursiveMutex.AssertNotCurrentThreadIn(); mRecursiveMutex.AssertNotCurrentThreadIn();
return mTreeManager; return mTreeManager;
@ -4437,7 +4445,7 @@ void AsyncPanZoomController::UpdateSharedCompositorFrameMetrics()
void AsyncPanZoomController::ShareCompositorFrameMetrics() void AsyncPanZoomController::ShareCompositorFrameMetrics()
{ {
APZThreadUtils::AssertOnSamplerThread(); AssertOnSamplerThread();
// Only create the shared memory buffer if it hasn't already been created, // Only create the shared memory buffer if it hasn't already been created,
// we are using progressive tile painting, and we have a // we are using progressive tile painting, and we have a

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

@ -753,6 +753,8 @@ protected:
*/ */
APZCTreeManager* GetApzcTreeManager() const; APZCTreeManager* GetApzcTreeManager() const;
void AssertOnSamplerThread() const;
/** /**
* Convert ScreenPoint relative to the screen to LayoutDevicePoint relative * Convert ScreenPoint relative to the screen to LayoutDevicePoint relative
* to the parent document. This excludes the transient compositor transform. * to the parent document. This excludes the transient compositor transform.

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

@ -70,7 +70,9 @@ FocusState::Update(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId, LayersId aOriginatingLayersId,
const FocusTarget& aState) const FocusTarget& aState)
{ {
APZThreadUtils::AssertOnSamplerThread(); // This runs on the sampler thread, it's not worth passing around extra raw
// pointers just to assert it.
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
FS_LOG("Update with rlt=%" PRIu64 ", olt=%" PRIu64 ", ft=(%s, %" PRIu64 ")\n", FS_LOG("Update with rlt=%" PRIu64 ", olt=%" PRIu64 ", ft=(%s, %" PRIu64 ")\n",
@ -182,7 +184,8 @@ FocusState::Update(LayersId aRootLayerTreeId,
void void
FocusState::RemoveFocusTarget(LayersId aLayersId) FocusState::RemoveFocusTarget(LayersId aLayersId)
{ {
APZThreadUtils::AssertOnSamplerThread(); // This runs on the sampler thread, it's not worth passing around extra raw
// pointers just to assert it.
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
mFocusTree.erase(aLayersId); mFocusTree.erase(aLayersId);

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

@ -10,7 +10,6 @@
#include "gfxPrefs.h" #include "gfxPrefs.h"
#include "LayersLogging.h" // for Stringify #include "LayersLogging.h" // for Stringify
#include "mozilla/gfx/Point.h" // for Point4D #include "mozilla/gfx/Point.h" // for Point4D
#include "mozilla/layers/APZThreadUtils.h" // for AssertOnSamplerThread
#include "mozilla/layers/APZUtils.h" // for CompleteAsyncTransform #include "mozilla/layers/APZUtils.h" // for CompleteAsyncTransform
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform::operator Matrix4x4() #include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform::operator Matrix4x4()
#include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics #include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics
@ -58,7 +57,8 @@ HitTestingTreeNode::~HitTestingTreeNode() = default;
void void
HitTestingTreeNode::Destroy() HitTestingTreeNode::Destroy()
{ {
APZThreadUtils::AssertOnSamplerThread(); // This runs on the sampler thread, it's not worth passing around extra raw
// pointers just to assert it.
mPrevSibling = nullptr; mPrevSibling = nullptr;
mLastChild = nullptr; mLastChild = nullptr;

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

@ -13,6 +13,7 @@
#include "APZTestCommon.h" #include "APZTestCommon.h"
#include "gfxPrefs.h" #include "gfxPrefs.h"
#include "mozilla/layers/APZSampler.h"
class APZCBasicTester : public APZCTesterBase { class APZCBasicTester : public APZCTesterBase {
public: public:
@ -29,6 +30,7 @@ protected:
APZThreadUtils::SetControllerThread(MessageLoop::current()); APZThreadUtils::SetControllerThread(MessageLoop::current());
tm = new TestAPZCTreeManager(mcc); tm = new TestAPZCTreeManager(mcc);
sampler = new APZSampler(tm);
apzc = new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior); apzc = new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior);
apzc->SetFrameMetrics(TestFrameMetrics()); apzc->SetFrameMetrics(TestFrameMetrics());
apzc->GetScrollMetadata().SetIsLayersIdRoot(true); apzc->GetScrollMetadata().SetIsLayersIdRoot(true);
@ -115,6 +117,7 @@ protected:
AsyncPanZoomController::GestureBehavior mGestureBehavior; AsyncPanZoomController::GestureBehavior mGestureBehavior;
RefPtr<TestAPZCTreeManager> tm; RefPtr<TestAPZCTreeManager> tm;
RefPtr<APZSampler> sampler;
RefPtr<TestAsyncPanZoomController> apzc; RefPtr<TestAsyncPanZoomController> apzc;
}; };

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

@ -15,6 +15,7 @@
#include "APZTestCommon.h" #include "APZTestCommon.h"
#include "gfxPlatform.h" #include "gfxPlatform.h"
#include "gfxPrefs.h" #include "gfxPrefs.h"
#include "mozilla/layers/APZSampler.h"
class APZCTreeManagerTester : public APZCTesterBase { class APZCTreeManagerTester : public APZCTesterBase {
protected: protected:
@ -25,6 +26,7 @@ protected:
APZThreadUtils::SetControllerThread(MessageLoop::current()); APZThreadUtils::SetControllerThread(MessageLoop::current());
manager = new TestAPZCTreeManager(mcc); manager = new TestAPZCTreeManager(mcc);
sampler = new APZSampler(manager);
} }
virtual void TearDown() { virtual void TearDown() {
@ -54,6 +56,7 @@ protected:
RefPtr<Layer> root; RefPtr<Layer> root;
RefPtr<TestAPZCTreeManager> manager; RefPtr<TestAPZCTreeManager> manager;
RefPtr<APZSampler> sampler;
protected: protected:
static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId, static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId,

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

@ -6,8 +6,6 @@
#include "mozilla/layers/APZThreadUtils.h" #include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorThread.h"
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
@ -66,39 +64,6 @@ APZThreadUtils::IsControllerThread()
return sControllerThread == MessageLoop::current(); return sControllerThread == MessageLoop::current();
} }
/*static*/ void
APZThreadUtils::AssertOnSamplerThread()
{
if (GetThreadAssertionsEnabled()) {
MOZ_ASSERT(IsSamplerThread());
}
}
/*static*/ void
APZThreadUtils::RunOnSamplerThread(already_AddRefed<Runnable> aTask)
{
RefPtr<Runnable> task = aTask;
MessageLoop* loop = CompositorThreadHolder::Loop();
if (!loop) {
// Could happen during startup
NS_WARNING("Dropping task posted to sampler thread");
return;
}
if (IsSamplerThread()) {
task->Run();
} else {
loop->PostTask(task.forget());
}
}
/*static*/ bool
APZThreadUtils::IsSamplerThread()
{
return CompositorThreadHolder::IsInCompositorThread();
}
NS_IMPL_ISUPPORTS(GenericNamedTimerCallbackBase, nsITimerCallback, nsINamed) NS_IMPL_ISUPPORTS(GenericNamedTimerCallbackBase, nsITimerCallback, nsINamed)
} // namespace layers } // namespace layers

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

@ -51,25 +51,6 @@ public:
* Returns true if currently on APZ "controller thread". * Returns true if currently on APZ "controller thread".
*/ */
static bool IsControllerThread(); static bool IsControllerThread();
/**
* This can be used to assert that the current thread is the
* sampler thread (which samples the async transform).
* This does nothing if thread assertions are disabled.
*/
static void AssertOnSamplerThread();
/**
* Runs the given task on the APZ "sampler thread" for this platform. If
* this function is called from the sampler thread itself then the task is
* run immediately without getting queued.
*/
static void RunOnSamplerThread(already_AddRefed<Runnable> aTask);
/**
* Returns true if currently on the APZ "sampler thread".
*/
static bool IsSamplerThread();
}; };
// A base class for GenericNamedTimerCallback<Function>. // A base class for GenericNamedTimerCallback<Function>.