зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
4bbad90793
Коммит
3c26f7183f
|
@ -104,6 +104,25 @@ public:
|
|||
void MarkAsyncTransformAppliedToContent(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:
|
||||
virtual ~APZSampler();
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ void
|
|||
APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
|
||||
const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
if (aOldApzcTreeManager) {
|
||||
aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
|
||||
|
@ -287,7 +287,7 @@ APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
|
|||
void
|
||||
APZCTreeManager::NotifyLayerTreeRemoved(LayersId aLayersId)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
mFocusState.RemoveFocusTarget(aLayersId);
|
||||
|
||||
|
@ -482,7 +482,7 @@ APZCTreeManager::UpdateFocusState(LayersId aRootLayerTreeId,
|
|||
LayersId aOriginatingLayersId,
|
||||
const FocusTarget& aFocusTarget)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
if (!gfxPrefs::APZKeyboardEnabled()) {
|
||||
return;
|
||||
|
@ -500,7 +500,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
|
|||
LayersId aOriginatingLayersId,
|
||||
uint32_t aPaintSequenceNumber)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
LayerMetricsWrapper root(aRoot);
|
||||
UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint,
|
||||
|
@ -514,7 +514,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
|
|||
LayersId aOriginatingLayersId,
|
||||
uint32_t aPaintSequenceNumber)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
WebRenderScrollDataWrapper wrapper(&aScrollData);
|
||||
UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
|
||||
|
@ -526,7 +526,7 @@ APZCTreeManager::PushStateToWR(wr::TransactionBuilder& aTxn,
|
|||
const TimeStamp& aSampleTime,
|
||||
nsTArray<wr::WrTransformProperty>& aTransformArray)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
RecursiveMutexAutoLock lock(mTreeLock);
|
||||
|
||||
|
@ -1960,13 +1960,13 @@ void
|
|||
APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
|
||||
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
|
||||
// nsBaseWidget (as opposed to over PAPZCTreeManager). We want this function
|
||||
// to run on the sampler thread, so bounce it over.
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
APZThreadUtils::RunOnSamplerThread(
|
||||
GetSampler()->RunOnSamplerThread(
|
||||
NewRunnableMethod<ScrollableLayerGuid, Maybe<ZoomConstraints>>(
|
||||
"APZCTreeManager::UpdateZoomConstraints",
|
||||
this,
|
||||
|
@ -1976,7 +1976,7 @@ APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
|
|||
return;
|
||||
}
|
||||
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
RecursiveMutexAutoLock lock(mTreeLock);
|
||||
RefPtr<HitTestingTreeNode> node = GetTargetNode(aGuid, nullptr);
|
||||
|
@ -2071,7 +2071,7 @@ APZCTreeManager::AdjustScrollForSurfaceShift(const ScreenPoint& aShift)
|
|||
void
|
||||
APZCTreeManager::ClearTree()
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
mToolbarAnimator->ClearTreeManager();
|
||||
|
@ -3027,7 +3027,7 @@ bool
|
|||
APZCTreeManager::GetAPZTestData(LayersId aLayersId,
|
||||
APZTestData* aOutData)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
MutexAutoLock lock(mTestDataLock);
|
||||
auto it = mTestData.find(aLayersId);
|
||||
if (it == mTestData.end()) {
|
||||
|
@ -3199,6 +3199,21 @@ APZCTreeManager::ComputeTransformForScrollThumb(
|
|||
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
|
||||
APZCTreeManager::SetDPI(float aDpiValue)
|
||||
{
|
||||
|
|
|
@ -526,10 +526,15 @@ public:
|
|||
bool aScrollbarIsDescendant,
|
||||
AsyncTransformComponentMatrix* aOutClipTransform);
|
||||
|
||||
// Assert that the current thread is the sampler thread for this APZCTM.
|
||||
void AssertOnSamplerThread();
|
||||
|
||||
protected:
|
||||
// Protected destructor, to discourage deletion outside of Release():
|
||||
virtual ~APZCTreeManager();
|
||||
|
||||
APZSampler* GetSampler() const;
|
||||
|
||||
// Protected hooks for gtests subclass
|
||||
virtual AsyncPanZoomController* NewAPZCInstance(LayersId aLayersId,
|
||||
GeckoContentController* aController);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "APZCTreeManager.h"
|
||||
#include "AsyncPanZoomController.h"
|
||||
#include "mozilla/layers/APZThreadUtils.h"
|
||||
#include "mozilla/layers/CompositorThread.h"
|
||||
#include "mozilla/layers/LayerMetricsWrapper.h"
|
||||
#include "TreeTraversal.h"
|
||||
|
@ -213,5 +214,38 @@ APZSampler::HasUnusedAsyncTransform(const LayerMetricsWrapper& aLayer)
|
|||
&& !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 mozilla
|
||||
|
|
|
@ -848,7 +848,7 @@ AsyncPanZoomController::GetInputQueue() const {
|
|||
void
|
||||
AsyncPanZoomController::Destroy()
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
CancelAnimation(CancelAnimationFlags::ScrollSnap);
|
||||
|
||||
|
@ -3481,7 +3481,7 @@ AsyncPanZoomController::RequestContentRepaint(const FrameMetrics& aFrameMetrics,
|
|||
bool AsyncPanZoomController::UpdateAnimation(const TimeStamp& aSampleTime,
|
||||
nsTArray<RefPtr<Runnable>>* aOutDeferredTasks)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
// 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
|
||||
|
@ -3540,7 +3540,7 @@ AsyncPanZoomController::GetOverscrollTransform(AsyncTransformConsumer aMode) con
|
|||
|
||||
bool AsyncPanZoomController::AdvanceAnimations(const TimeStamp& aSampleTime)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
// Don't send any state-change notifications until the end of the function,
|
||||
// because we may go through some intermediate states while we finish
|
||||
|
@ -3819,7 +3819,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const ScrollMetadata& aScrollMe
|
|||
bool aIsFirstPaint,
|
||||
bool aThisLayerTreeUpdated)
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
RecursiveMutexAutoLock lock(mRecursiveMutex);
|
||||
bool isDefault = mScrollMetadata.IsDefault();
|
||||
|
@ -4083,6 +4083,14 @@ const ScrollMetadata& AsyncPanZoomController::GetScrollMetadata() const {
|
|||
return mScrollMetadata;
|
||||
}
|
||||
|
||||
void
|
||||
AsyncPanZoomController::AssertOnSamplerThread() const
|
||||
{
|
||||
if (APZCTreeManager* treeManagerLocal = GetApzcTreeManager()) {
|
||||
treeManagerLocal->AssertOnSamplerThread();
|
||||
}
|
||||
}
|
||||
|
||||
APZCTreeManager* AsyncPanZoomController::GetApzcTreeManager() const {
|
||||
mRecursiveMutex.AssertNotCurrentThreadIn();
|
||||
return mTreeManager;
|
||||
|
@ -4437,7 +4445,7 @@ void AsyncPanZoomController::UpdateSharedCompositorFrameMetrics()
|
|||
|
||||
void AsyncPanZoomController::ShareCompositorFrameMetrics()
|
||||
{
|
||||
APZThreadUtils::AssertOnSamplerThread();
|
||||
AssertOnSamplerThread();
|
||||
|
||||
// Only create the shared memory buffer if it hasn't already been created,
|
||||
// we are using progressive tile painting, and we have a
|
||||
|
|
|
@ -753,6 +753,8 @@ protected:
|
|||
*/
|
||||
APZCTreeManager* GetApzcTreeManager() const;
|
||||
|
||||
void AssertOnSamplerThread() const;
|
||||
|
||||
/**
|
||||
* Convert ScreenPoint relative to the screen to LayoutDevicePoint relative
|
||||
* to the parent document. This excludes the transient compositor transform.
|
||||
|
|
|
@ -70,7 +70,9 @@ FocusState::Update(LayersId aRootLayerTreeId,
|
|||
LayersId aOriginatingLayersId,
|
||||
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);
|
||||
|
||||
FS_LOG("Update with rlt=%" PRIu64 ", olt=%" PRIu64 ", ft=(%s, %" PRIu64 ")\n",
|
||||
|
@ -182,7 +184,8 @@ FocusState::Update(LayersId aRootLayerTreeId,
|
|||
void
|
||||
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);
|
||||
|
||||
mFocusTree.erase(aLayersId);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "gfxPrefs.h"
|
||||
#include "LayersLogging.h" // for Stringify
|
||||
#include "mozilla/gfx/Point.h" // for Point4D
|
||||
#include "mozilla/layers/APZThreadUtils.h" // for AssertOnSamplerThread
|
||||
#include "mozilla/layers/APZUtils.h" // for CompleteAsyncTransform
|
||||
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform::operator Matrix4x4()
|
||||
#include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics
|
||||
|
@ -58,7 +57,8 @@ HitTestingTreeNode::~HitTestingTreeNode() = default;
|
|||
void
|
||||
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;
|
||||
mLastChild = nullptr;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "APZTestCommon.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "mozilla/layers/APZSampler.h"
|
||||
|
||||
class APZCBasicTester : public APZCTesterBase {
|
||||
public:
|
||||
|
@ -29,6 +30,7 @@ protected:
|
|||
APZThreadUtils::SetControllerThread(MessageLoop::current());
|
||||
|
||||
tm = new TestAPZCTreeManager(mcc);
|
||||
sampler = new APZSampler(tm);
|
||||
apzc = new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior);
|
||||
apzc->SetFrameMetrics(TestFrameMetrics());
|
||||
apzc->GetScrollMetadata().SetIsLayersIdRoot(true);
|
||||
|
@ -115,6 +117,7 @@ protected:
|
|||
|
||||
AsyncPanZoomController::GestureBehavior mGestureBehavior;
|
||||
RefPtr<TestAPZCTreeManager> tm;
|
||||
RefPtr<APZSampler> sampler;
|
||||
RefPtr<TestAsyncPanZoomController> apzc;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "APZTestCommon.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "mozilla/layers/APZSampler.h"
|
||||
|
||||
class APZCTreeManagerTester : public APZCTesterBase {
|
||||
protected:
|
||||
|
@ -25,6 +26,7 @@ protected:
|
|||
APZThreadUtils::SetControllerThread(MessageLoop::current());
|
||||
|
||||
manager = new TestAPZCTreeManager(mcc);
|
||||
sampler = new APZSampler(manager);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
|
@ -54,6 +56,7 @@ protected:
|
|||
RefPtr<Layer> root;
|
||||
|
||||
RefPtr<TestAPZCTreeManager> manager;
|
||||
RefPtr<APZSampler> sampler;
|
||||
|
||||
protected:
|
||||
static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId,
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "mozilla/layers/APZThreadUtils.h"
|
||||
|
||||
#include "mozilla/layers/CompositorThread.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
|
@ -66,39 +64,6 @@ APZThreadUtils::IsControllerThread()
|
|||
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)
|
||||
|
||||
} // namespace layers
|
||||
|
|
|
@ -51,25 +51,6 @@ public:
|
|||
* Returns true if currently on APZ "controller thread".
|
||||
*/
|
||||
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>.
|
||||
|
|
Загрузка…
Ссылка в новой задаче