Bug 1449620 - Extract an APZUpdater class from APZSampler. r=botond

The APZUpdater class holds the methods that are to be run on the updater
thread. Note that there are a few differences between the APZSampler and
APZUpdater classes - most notably, APZSampler no longer has a
"RunOnSamplerThread" function because there should never be any need to
dispatch runnables to the sampler thread. There is still a
RunOnUpdaterThread in APZUpdater, as well as a mechanism for dispatching
runnables to the controller thread via the updater thread.

MozReview-Commit-ID: LLVWzRyhYWl

--HG--
extra : rebase_source : d3d2ae18b40f24473cab5567a48b67b8f478a733
This commit is contained in:
Kartikaya Gupta 2018-03-28 18:36:42 -04:00
Родитель bb7f1ae6d9
Коммит d6673c9aad
21 изменённых файлов: 503 добавлений и 332 удалений

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

@ -7,11 +7,7 @@
#ifndef mozilla_layers_APZSampler_h
#define mozilla_layers_APZSampler_h
#include "base/message_loop.h"
#include "LayersTypes.h"
#include "mozilla/layers/APZTestData.h"
#include "mozilla/layers/AsyncCompositionManager.h" // for AsyncTransform
#include "mozilla/Maybe.h"
#include "nsTArray.h"
#include "Units.h"
@ -27,16 +23,13 @@ struct WrTransformProperty;
namespace layers {
class APZCTreeManager;
class FocusTarget;
class Layer;
class LayerMetricsWrapper;
struct ScrollThumbData;
class WebRenderScrollData;
/**
* This interface is used to interact with the APZ code from the compositor
* thread. It internally redispatches the functions to the sampler thread
* in the case where the two threads are not the same.
* This interface exposes APZ methods related to "sampling" (i.e. reading the
* async transforms produced by APZ). These methods should all be called on
* the sampler thread.
*/
class APZSampler {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(APZSampler)
@ -44,40 +37,10 @@ class APZSampler {
public:
explicit APZSampler(const RefPtr<APZCTreeManager>& aApz);
bool HasTreeManager(const RefPtr<APZCTreeManager>& aApz);
void ClearTree();
void UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget);
void UpdateHitTestingTree(LayersId aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
void UpdateHitTestingTree(LayersId aRootLayerTreeId,
const WebRenderScrollData& aScrollData,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
void NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZSampler>& aOldSampler);
void NotifyLayerTreeRemoved(LayersId aLayersId);
bool PushStateToWR(wr::TransactionBuilder& aTxn,
const TimeStamp& aSampleTime,
nsTArray<wr::WrTransformProperty>& aTransformArray);
bool GetAPZTestData(LayersId aLayersId, APZTestData* aOutData);
void SetTestAsyncScrollOffset(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const CSSPoint& aOffset);
void SetTestAsyncZoom(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const LayerToParentLayerScale& aZoom);
bool SampleAnimations(const LayerMetricsWrapper& aLayer,
const TimeStamp& aSampleTime);
@ -114,28 +77,11 @@ public:
*/
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();
/**
* Dispatches the given task to the APZ "controller thread", but does it *from*
* the sampler thread. That is, if the thread on which this function is called
* is not the sampler thread, the task is first dispatched to the sampler thread.
* When the sampler thread runs it (or if this is called directly on the sampler
* thread), that is when the task gets dispatched to the controller thread.
* The controller thread then actually runs the task.
*/
void RunOnControllerThread(already_AddRefed<Runnable> aTask);
protected:
virtual ~APZSampler();

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

@ -0,0 +1,105 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_layers_APZUpdater_h
#define mozilla_layers_APZUpdater_h
#include "LayersTypes.h"
#include "mozilla/layers/APZTestData.h"
#include "nsThreadUtils.h"
#include "Units.h"
namespace mozilla {
namespace layers {
class APZCTreeManager;
class FocusTarget;
class Layer;
class WebRenderScrollData;
/**
* This interface is used to send updates or otherwise mutate APZ internal
* state. These functions is usually called from the compositor thread in
* response to IPC messages. The method implementations internally redispatch
* themselves to the updater thread in the case where the compositor thread
* is not the updater thread.
*/
class APZUpdater {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(APZUpdater)
public:
explicit APZUpdater(const RefPtr<APZCTreeManager>& aApz);
bool HasTreeManager(const RefPtr<APZCTreeManager>& aApz);
void ClearTree();
void UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget);
void UpdateHitTestingTree(LayersId aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
void UpdateHitTestingTree(LayersId aRootLayerTreeId,
const WebRenderScrollData& aScrollData,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
void NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZUpdater>& aOldUpdater);
void NotifyLayerTreeRemoved(LayersId aLayersId);
bool GetAPZTestData(LayersId aLayersId, APZTestData* aOutData);
void SetTestAsyncScrollOffset(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const CSSPoint& aOffset);
void SetTestAsyncZoom(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const LayerToParentLayerScale& aZoom);
/**
* This can be used to assert that the current thread is the
* updater thread (which samples the async transform).
* This does nothing if thread assertions are disabled.
*/
void AssertOnUpdaterThread();
/**
* Runs the given task on the APZ "updater thread" for this APZUpdater. If
* this function is called from the updater thread itself then the task is
* run immediately without getting queued.
*/
void RunOnUpdaterThread(already_AddRefed<Runnable> aTask);
/**
* Returns true if currently on the APZUpdater's "updater thread".
*/
bool IsUpdaterThread();
/**
* Dispatches the given task to the APZ "controller thread", but does it *from*
* the updater thread. That is, if the thread on which this function is called
* is not the updater thread, the task is first dispatched to the updater thread.
* When the updater thread runs it (or if this is called directly on the updater
* thread), that is when the task gets dispatched to the controller thread.
* The controller thread then actually runs the task.
*/
void RunOnControllerThread(already_AddRefed<Runnable> aTask);
protected:
virtual ~APZUpdater();
private:
RefPtr<APZCTreeManager> mApz;
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_layers_APZUpdater_h

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

@ -23,6 +23,7 @@
#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/APZUpdater.h" // for APZUpdater
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform
#include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics
#include "mozilla/layers/CompositorBridgeParent.h" // for CompositorBridgeParent, etc
@ -226,6 +227,7 @@ APZCTreeManager::APZCTreeManager(LayersId aRootLayersId)
: mInputQueue(new InputQueue()),
mRootLayersId(aRootLayersId),
mSampler(nullptr),
mUpdater(nullptr),
mTreeLock("APZCTreeLock"),
mHitResultForInputBlock(CompositorHitTestInfo::eInvisibleToHitTest),
mRetainedTouchIdentifier(-1),
@ -256,11 +258,19 @@ APZCTreeManager::SetSampler(APZSampler* aSampler)
mSampler = aSampler;
}
void
APZCTreeManager::SetUpdater(APZUpdater* aUpdater)
{
// We're either setting the updater or clearing it
MOZ_ASSERT((mUpdater == nullptr) != (aUpdater == nullptr));
mUpdater = aUpdater;
}
void
APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
if (aOldApzcTreeManager) {
aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
@ -287,7 +297,7 @@ APZCTreeManager::NotifyLayerTreeAdopted(LayersId aLayersId,
void
APZCTreeManager::NotifyLayerTreeRemoved(LayersId aLayersId)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
mFocusState.RemoveFocusTarget(aLayersId);
@ -482,7 +492,7 @@ APZCTreeManager::UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
if (!gfxPrefs::APZKeyboardEnabled()) {
return;
@ -500,7 +510,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
LayerMetricsWrapper root(aRoot);
UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint,
@ -514,7 +524,7 @@ APZCTreeManager::UpdateHitTestingTree(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
WebRenderScrollDataWrapper wrapper(&aScrollData);
UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
@ -1913,7 +1923,7 @@ APZCTreeManager::ZoomToRect(const ScrollableLayerGuid& aGuid,
const CSSRect& aRect,
const uint32_t aFlags)
{
// We could probably move this to run on the sampler thread if needed, but
// We could probably move this to run on the updater thread if needed, but
// either way we should restrict it to a single thread. For now let's use the
// controller thread.
APZThreadUtils::AssertOnControllerThread();
@ -1962,13 +1972,13 @@ void
APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
const Maybe<ZoomConstraints>& aConstraints)
{
if (!GetSampler()->IsSamplerThread()) {
if (!GetUpdater()->IsUpdaterThread()) {
// 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.
// to run on the updater thread, so bounce it over.
MOZ_ASSERT(XRE_IsParentProcess());
GetSampler()->RunOnSamplerThread(
GetUpdater()->RunOnUpdaterThread(
NewRunnableMethod<ScrollableLayerGuid, Maybe<ZoomConstraints>>(
"APZCTreeManager::UpdateZoomConstraints",
this,
@ -1978,7 +1988,7 @@ APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
return;
}
AssertOnSamplerThread();
AssertOnUpdaterThread();
RecursiveMutexAutoLock lock(mTreeLock);
RefPtr<HitTestingTreeNode> node = GetTargetNode(aGuid, nullptr);
@ -2073,7 +2083,7 @@ APZCTreeManager::AdjustScrollForSurfaceShift(const ScreenPoint& aShift)
void
APZCTreeManager::ClearTree()
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
#if defined(MOZ_WIDGET_ANDROID)
mToolbarAnimator->ClearTreeManager();
@ -3028,7 +3038,7 @@ bool
APZCTreeManager::GetAPZTestData(LayersId aLayersId,
APZTestData* aOutData)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
MutexAutoLock lock(mTestDataLock);
auto it = mTestData.find(aLayersId);
if (it == mTestData.end()) {
@ -3215,6 +3225,21 @@ APZCTreeManager::AssertOnSamplerThread()
GetSampler()->AssertOnSamplerThread();
}
APZUpdater*
APZCTreeManager::GetUpdater() const
{
// We should always have an updater here, since in practice the updater
// is destroyed at the same time that this APZCTreeManager instance is.
MOZ_ASSERT(mUpdater);
return mUpdater;
}
void
APZCTreeManager::AssertOnUpdaterThread()
{
GetUpdater()->AssertOnUpdaterThread();
}
void
APZCTreeManager::SetDPI(float aDpiValue)
{

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

@ -46,6 +46,7 @@ class Layer;
class AsyncPanZoomController;
class APZCTreeManagerParent;
class APZSampler;
class APZUpdater;
class CompositorBridgeParent;
class OverscrollHandoffChain;
struct OverscrollHandoffState;
@ -81,7 +82,7 @@ struct ScrollThumbData;
* This class manages the tree of AsyncPanZoomController instances. There is one
* instance of this class owned by each CompositorBridgeParent, and it contains as
* many AsyncPanZoomController instances as there are scrollable container layers.
* This class generally lives on the sampler thread, although some functions
* This class generally lives on the updater thread, although some functions
* may be called from other threads as noted; thread safety is ensured internally.
*
* The bulk of the work of this class happens as part of the UpdateHitTestingTree
@ -118,6 +119,7 @@ public:
explicit APZCTreeManager(LayersId aRootLayersId);
void SetSampler(APZSampler* aSampler);
void SetUpdater(APZUpdater* aUpdater);
/**
* Notifies this APZCTreeManager that the associated compositor is now
@ -125,7 +127,7 @@ public:
* 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.
* This function must be called on the updater thread.
*/
void NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZCTreeManager>& aOldTreeManager);
@ -135,14 +137,14 @@ public:
* associated compositor has been removed/destroyed. Note that this does
* NOT get called during shutdown situations, when the root layer tree is
* also getting destroyed.
* This function must be called on the sampler thread.
* This function must be called on the updater thread.
*/
void NotifyLayerTreeRemoved(LayersId aLayersId);
/**
* Rebuild the focus state based on the focus target from the layer tree update
* that just occurred.
* This must be called on the sampler thread.
* This must be called on the updater thread.
*
* @param aRootLayerTreeId The layer tree ID of the root layer corresponding
* to this APZCTreeManager
@ -158,7 +160,7 @@ public:
* Preserve nodes and APZC instances where possible, but retire those whose
* layers are no longer in the layer tree.
*
* This must be called on the sampler thread as it walks the layer tree.
* This must be called on the updater thread as it walks the layer tree.
*
* @param aRootLayerTreeId The layer tree ID of the root layer corresponding
* to this APZCTreeManager
@ -336,7 +338,7 @@ public:
* lifetime of this APZCTreeManager, when this APZCTreeManager is no longer
* needed. Failing to call this function may prevent objects from being freed
* properly.
* This must be called on the sampler thread.
* This must be called on the updater thread.
*/
void ClearTree();
@ -528,12 +530,15 @@ public:
// Assert that the current thread is the sampler thread for this APZCTM.
void AssertOnSamplerThread();
// Assert that the current thread is the updater thread for this APZCTM.
void AssertOnUpdaterThread();
protected:
// Protected destructor, to discourage deletion outside of Release():
virtual ~APZCTreeManager();
APZSampler* GetSampler() const;
APZUpdater* GetUpdater() const;
// Protected hooks for gtests subclass
virtual AsyncPanZoomController* NewAPZCInstance(LayersId aLayersId,
@ -705,6 +710,12 @@ private:
* pointer should always be valid.
*/
APZSampler* MOZ_NON_OWNING_REF mSampler;
/* Pointer to the APZUpdater instance that is bound to this APZCTreeManager.
* The updater has a RefPtr to this class, and this non-owning raw pointer
* back to the APZUpdater is nulled out in the updater's destructor, so this
* pointer should always be valid.
*/
APZUpdater* MOZ_NON_OWNING_REF mUpdater;
/* 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
@ -716,7 +727,7 @@ private:
RefPtr<HitTestingTreeNode> mRootNode;
/* Holds the zoom constraints for scrollable layers, as determined by the
* the main-thread gecko code. This can only be accessed on the sampler
* the main-thread gecko code. This can only be accessed on the updater
* thread. */
std::unordered_map<ScrollableLayerGuid, ZoomConstraints, ScrollableLayerGuidHash> mZoomConstraints;
/* A list of keyboard shortcuts to use for translating keyboard inputs into

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

@ -29,104 +29,6 @@ APZSampler::~APZSampler()
mApz->SetSampler(nullptr);
}
bool
APZSampler::HasTreeManager(const RefPtr<APZCTreeManager>& aApz)
{
return aApz.get() == mApz.get();
}
void
APZSampler::ClearTree()
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnSamplerThread(NewRunnableMethod(
"APZSampler::ClearTree",
mApz,
&APZCTreeManager::ClearTree));
}
void
APZSampler::UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnSamplerThread(NewRunnableMethod<LayersId, LayersId, FocusTarget>(
"APZSampler::UpdateFocusState",
mApz,
&APZCTreeManager::UpdateFocusState,
aRootLayerTreeId,
aOriginatingLayersId,
aFocusTarget));
}
void
APZSampler::UpdateHitTestingTree(LayersId aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
AssertOnSamplerThread();
mApz->UpdateHitTestingTree(aRootLayerTreeId, aRoot, aIsFirstPaint,
aOriginatingLayersId, aPaintSequenceNumber);
}
void
APZSampler::UpdateHitTestingTree(LayersId aRootLayerTreeId,
const WebRenderScrollData& aScrollData,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
// use the local variable to resolve the function overload.
auto func = static_cast<void (APZCTreeManager::*)(LayersId,
const WebRenderScrollData&,
bool,
LayersId,
uint32_t)>
(&APZCTreeManager::UpdateHitTestingTree);
RunOnSamplerThread(NewRunnableMethod<LayersId,
WebRenderScrollData,
bool,
LayersId,
uint32_t>(
"APZSampler::UpdateHitTestingTree",
mApz,
func,
aRootLayerTreeId,
aScrollData,
aIsFirstPaint,
aOriginatingLayersId,
aPaintSequenceNumber));
}
void
APZSampler::NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZSampler>& aOldSampler)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnSamplerThread(NewRunnableMethod<LayersId, RefPtr<APZCTreeManager>>(
"APZSampler::NotifyLayerTreeAdopted",
mApz,
&APZCTreeManager::NotifyLayerTreeAdopted,
aLayersId,
aOldSampler ? aOldSampler->mApz : nullptr));
}
void
APZSampler::NotifyLayerTreeRemoved(LayersId aLayersId)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnSamplerThread(NewRunnableMethod<LayersId>(
"APZSampler::NotifyLayerTreeRemoved",
mApz,
&APZCTreeManager::NotifyLayerTreeRemoved,
aLayersId));
}
bool
APZSampler::PushStateToWR(wr::TransactionBuilder& aTxn,
const TimeStamp& aSampleTime,
@ -137,69 +39,6 @@ APZSampler::PushStateToWR(wr::TransactionBuilder& aTxn,
return mApz->PushStateToWR(aTxn, aSampleTime, aTransformArray);
}
bool
APZSampler::GetAPZTestData(LayersId aLayersId,
APZTestData* aOutData)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
bool ret = false;
SynchronousTask waiter("APZSampler::GetAPZTestData");
RunOnSamplerThread(NS_NewRunnableFunction(
"APZSampler::GetAPZTestData",
[&]() {
AutoCompleteTask notifier(&waiter);
ret = apz->GetAPZTestData(aLayersId, aOutData);
}
));
// Wait until the task posted above has run and populated aOutData and ret
waiter.Wait();
return ret;
}
void
APZSampler::SetTestAsyncScrollOffset(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const CSSPoint& aOffset)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
RunOnSamplerThread(NS_NewRunnableFunction(
"APZSampler::SetTestAsyncScrollOffset",
[=]() {
RefPtr<AsyncPanZoomController> apzc = apz->GetTargetAPZC(aLayersId, aScrollId);
if (apzc) {
apzc->SetTestAsyncScrollOffset(aOffset);
} else {
NS_WARNING("Unable to find APZC in SetTestAsyncScrollOffset");
}
}
));
}
void
APZSampler::SetTestAsyncZoom(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const LayerToParentLayerScale& aZoom)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
RunOnSamplerThread(NS_NewRunnableFunction(
"APZSampler::SetTestAsyncZoom",
[=]() {
RefPtr<AsyncPanZoomController> apzc = apz->GetTargetAPZC(aLayersId, aScrollId);
if (apzc) {
apzc->SetTestAsyncZoom(aZoom);
} else {
NS_WARNING("Unable to find APZC in SetTestAsyncZoom");
}
}
));
}
bool
APZSampler::SampleAnimations(const LayerMetricsWrapper& aLayer,
const TimeStamp& aSampleTime)
@ -314,41 +153,11 @@ APZSampler::AssertOnSamplerThread()
}
}
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();
}
void
APZSampler::RunOnControllerThread(already_AddRefed<Runnable> aTask)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnSamplerThread(NewRunnableFunction(
"APZSampler::RunOnControllerThread",
&APZThreadUtils::RunOnControllerThread,
Move(aTask)));
}
} // namespace layers
} // namespace mozilla

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

@ -0,0 +1,238 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/APZUpdater.h"
#include "APZCTreeManager.h"
#include "AsyncPanZoomController.h"
#include "base/task.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/SynchronousTask.h"
#include "mozilla/layers/WebRenderScrollData.h"
namespace mozilla {
namespace layers {
APZUpdater::APZUpdater(const RefPtr<APZCTreeManager>& aApz)
: mApz(aApz)
{
MOZ_ASSERT(aApz);
mApz->SetUpdater(this);
}
APZUpdater::~APZUpdater()
{
mApz->SetUpdater(nullptr);
}
bool
APZUpdater::HasTreeManager(const RefPtr<APZCTreeManager>& aApz)
{
return aApz.get() == mApz.get();
}
void
APZUpdater::ClearTree()
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnUpdaterThread(NewRunnableMethod(
"APZUpdater::ClearTree",
mApz,
&APZCTreeManager::ClearTree));
}
void
APZUpdater::UpdateFocusState(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aFocusTarget)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnUpdaterThread(NewRunnableMethod<LayersId, LayersId, FocusTarget>(
"APZUpdater::UpdateFocusState",
mApz,
&APZCTreeManager::UpdateFocusState,
aRootLayerTreeId,
aOriginatingLayersId,
aFocusTarget));
}
void
APZUpdater::UpdateHitTestingTree(LayersId aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
AssertOnUpdaterThread();
mApz->UpdateHitTestingTree(aRootLayerTreeId, aRoot, aIsFirstPaint,
aOriginatingLayersId, aPaintSequenceNumber);
}
void
APZUpdater::UpdateHitTestingTree(LayersId aRootLayerTreeId,
const WebRenderScrollData& aScrollData,
bool aIsFirstPaint,
LayersId aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
// use the local variable to resolve the function overload.
auto func = static_cast<void (APZCTreeManager::*)(LayersId,
const WebRenderScrollData&,
bool,
LayersId,
uint32_t)>
(&APZCTreeManager::UpdateHitTestingTree);
RunOnUpdaterThread(NewRunnableMethod<LayersId,
WebRenderScrollData,
bool,
LayersId,
uint32_t>(
"APZUpdater::UpdateHitTestingTree",
mApz,
func,
aRootLayerTreeId,
aScrollData,
aIsFirstPaint,
aOriginatingLayersId,
aPaintSequenceNumber));
}
void
APZUpdater::NotifyLayerTreeAdopted(LayersId aLayersId,
const RefPtr<APZUpdater>& aOldUpdater)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnUpdaterThread(NewRunnableMethod<LayersId, RefPtr<APZCTreeManager>>(
"APZUpdater::NotifyLayerTreeAdopted",
mApz,
&APZCTreeManager::NotifyLayerTreeAdopted,
aLayersId,
aOldUpdater ? aOldUpdater->mApz : nullptr));
}
void
APZUpdater::NotifyLayerTreeRemoved(LayersId aLayersId)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnUpdaterThread(NewRunnableMethod<LayersId>(
"APZUpdater::NotifyLayerTreeRemoved",
mApz,
&APZCTreeManager::NotifyLayerTreeRemoved,
aLayersId));
}
bool
APZUpdater::GetAPZTestData(LayersId aLayersId,
APZTestData* aOutData)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
bool ret = false;
SynchronousTask waiter("APZUpdater::GetAPZTestData");
RunOnUpdaterThread(NS_NewRunnableFunction(
"APZUpdater::GetAPZTestData",
[&]() {
AutoCompleteTask notifier(&waiter);
ret = apz->GetAPZTestData(aLayersId, aOutData);
}
));
// Wait until the task posted above has run and populated aOutData and ret
waiter.Wait();
return ret;
}
void
APZUpdater::SetTestAsyncScrollOffset(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const CSSPoint& aOffset)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
RunOnUpdaterThread(NS_NewRunnableFunction(
"APZUpdater::SetTestAsyncScrollOffset",
[=]() {
RefPtr<AsyncPanZoomController> apzc = apz->GetTargetAPZC(aLayersId, aScrollId);
if (apzc) {
apzc->SetTestAsyncScrollOffset(aOffset);
} else {
NS_WARNING("Unable to find APZC in SetTestAsyncScrollOffset");
}
}
));
}
void
APZUpdater::SetTestAsyncZoom(LayersId aLayersId,
const FrameMetrics::ViewID& aScrollId,
const LayerToParentLayerScale& aZoom)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<APZCTreeManager> apz = mApz;
RunOnUpdaterThread(NS_NewRunnableFunction(
"APZUpdater::SetTestAsyncZoom",
[=]() {
RefPtr<AsyncPanZoomController> apzc = apz->GetTargetAPZC(aLayersId, aScrollId);
if (apzc) {
apzc->SetTestAsyncZoom(aZoom);
} else {
NS_WARNING("Unable to find APZC in SetTestAsyncZoom");
}
}
));
}
void
APZUpdater::AssertOnUpdaterThread()
{
if (APZThreadUtils::GetThreadAssertionsEnabled()) {
MOZ_ASSERT(IsUpdaterThread());
}
}
void
APZUpdater::RunOnUpdaterThread(already_AddRefed<Runnable> aTask)
{
RefPtr<Runnable> task = aTask;
MessageLoop* loop = CompositorThreadHolder::Loop();
if (!loop) {
// Could happen during startup
NS_WARNING("Dropping task posted to updater thread");
return;
}
if (IsUpdaterThread()) {
task->Run();
} else {
loop->PostTask(task.forget());
}
}
bool
APZUpdater::IsUpdaterThread()
{
return CompositorThreadHolder::IsInCompositorThread();
}
void
APZUpdater::RunOnControllerThread(already_AddRefed<Runnable> aTask)
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RunOnUpdaterThread(NewRunnableFunction(
"APZUpdater::RunOnControllerThread",
&APZThreadUtils::RunOnControllerThread,
Move(aTask)));
}
} // namespace layers
} // namespace mozilla

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

@ -848,7 +848,7 @@ AsyncPanZoomController::GetInputQueue() const {
void
AsyncPanZoomController::Destroy()
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
CancelAnimation(CancelAnimationFlags::ScrollSnap);
@ -3819,7 +3819,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const ScrollMetadata& aScrollMe
bool aIsFirstPaint,
bool aThisLayerTreeUpdated)
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
RecursiveMutexAutoLock lock(mRecursiveMutex);
bool isDefault = mScrollMetadata.IsDefault();
@ -4091,6 +4091,14 @@ AsyncPanZoomController::AssertOnSamplerThread() const
}
}
void
AsyncPanZoomController::AssertOnUpdaterThread() const
{
if (APZCTreeManager* treeManagerLocal = GetApzcTreeManager()) {
treeManagerLocal->AssertOnUpdaterThread();
}
}
APZCTreeManager* AsyncPanZoomController::GetApzcTreeManager() const {
mRecursiveMutex.AssertNotCurrentThreadIn();
return mTreeManager;
@ -4445,7 +4453,7 @@ void AsyncPanZoomController::UpdateSharedCompositorFrameMetrics()
void AsyncPanZoomController::ShareCompositorFrameMetrics()
{
AssertOnSamplerThread();
AssertOnUpdaterThread();
// Only create the shared memory buffer if it hasn't already been created,
// we are using progressive tile painting, and we have a

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

@ -240,6 +240,10 @@ public:
bool UpdateAnimation(const TimeStamp& aSampleTime,
nsTArray<RefPtr<Runnable>>* aOutDeferredTasks);
// --------------------------------------------------------------------------
// These methods must only be called on the updater thread.
//
/**
* A shadow layer update has arrived. |aScrollMetdata| is the new ScrollMetadata
* for the container layer corresponding to this APZC.
@ -754,6 +758,7 @@ protected:
APZCTreeManager* GetApzcTreeManager() const;
void AssertOnSamplerThread() const;
void AssertOnUpdaterThread() const;
/**
* Convert ScreenPoint relative to the screen to LayoutDevicePoint relative
@ -794,7 +799,7 @@ protected:
/* Access to the following two fields is protected by the mRefPtrMonitor,
since they are accessed on the UI thread but can be cleared on the
sampler thread. */
updater thread. */
RefPtr<GeckoContentController> mGeckoContentController;
RefPtr<GestureEventListener> mGestureEventListener;
mutable Monitor mRefPtrMonitor;

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

@ -70,7 +70,7 @@ FocusState::Update(LayersId aRootLayerTreeId,
LayersId aOriginatingLayersId,
const FocusTarget& aState)
{
// This runs on the sampler thread, it's not worth passing around extra raw
// This runs on the updater thread, it's not worth passing around extra raw
// pointers just to assert it.
MutexAutoLock lock(mMutex);
@ -184,7 +184,7 @@ FocusState::Update(LayersId aRootLayerTreeId,
void
FocusState::RemoveFocusTarget(LayersId aLayersId)
{
// This runs on the sampler thread, it's not worth passing around extra raw
// This runs on the updater thread, it's not worth passing around extra raw
// pointers just to assert it.
MutexAutoLock lock(mMutex);

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

@ -138,7 +138,7 @@ private:
private:
// All methods should hold this lock, since this class is accessed via both
// the sampler and controller threads.
// the updater and controller threads.
mutable Mutex mMutex;
// The set of focus targets received indexed by their layer tree ID

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

@ -57,7 +57,7 @@ HitTestingTreeNode::~HitTestingTreeNode() = default;
void
HitTestingTreeNode::Destroy()
{
// This runs on the sampler thread, it's not worth passing around extra raw
// This runs on the updater thread, it's not worth passing around extra raw
// pointers just to assert it.
mPrevSibling = nullptr;

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

@ -14,6 +14,7 @@
#include "APZTestCommon.h"
#include "gfxPrefs.h"
#include "mozilla/layers/APZSampler.h"
#include "mozilla/layers/APZUpdater.h"
class APZCBasicTester : public APZCTesterBase {
public:
@ -30,6 +31,7 @@ protected:
APZThreadUtils::SetControllerThread(MessageLoop::current());
tm = new TestAPZCTreeManager(mcc);
updater = new APZUpdater(tm);
sampler = new APZSampler(tm);
apzc = new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior);
apzc->SetFrameMetrics(TestFrameMetrics());
@ -118,6 +120,7 @@ protected:
AsyncPanZoomController::GestureBehavior mGestureBehavior;
RefPtr<TestAPZCTreeManager> tm;
RefPtr<APZSampler> sampler;
RefPtr<APZUpdater> updater;
RefPtr<TestAsyncPanZoomController> apzc;
};

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

@ -16,6 +16,7 @@
#include "gfxPlatform.h"
#include "gfxPrefs.h"
#include "mozilla/layers/APZSampler.h"
#include "mozilla/layers/APZUpdater.h"
class APZCTreeManagerTester : public APZCTesterBase {
protected:
@ -26,6 +27,7 @@ protected:
APZThreadUtils::SetControllerThread(MessageLoop::current());
manager = new TestAPZCTreeManager(mcc);
updater = new APZUpdater(manager);
sampler = new APZSampler(manager);
}
@ -57,6 +59,7 @@ protected:
RefPtr<TestAPZCTreeManager> manager;
RefPtr<APZSampler> sampler;
RefPtr<APZUpdater> updater;
protected:
static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId,

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

@ -15,6 +15,7 @@
#include "nsTArray.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT
#include "mozilla/DebugOnly.h" // for DebugOnly
#include "mozilla/GfxMessageUtils.h" // for ParamTraits specializations
#include "mozilla/ToString.h" // for ToString
#include "mozilla/gfx/CompositorHitTestInfo.h"
#include "ipc/IPCMessageUtils.h"

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

@ -7,22 +7,22 @@
#include "mozilla/layers/APZCTreeManagerParent.h"
#include "apz/src/APZCTreeManager.h"
#include "mozilla/layers/APZSampler.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/APZUpdater.h"
namespace mozilla {
namespace layers {
APZCTreeManagerParent::APZCTreeManagerParent(LayersId aLayersId,
RefPtr<APZCTreeManager> aAPZCTreeManager,
RefPtr<APZSampler> aAPZSampler)
RefPtr<APZUpdater> aAPZUpdater)
: mLayersId(aLayersId)
, mTreeManager(Move(aAPZCTreeManager))
, mSampler(Move(aAPZSampler))
, mUpdater(Move(aAPZUpdater))
{
MOZ_ASSERT(mTreeManager != nullptr);
MOZ_ASSERT(mSampler != nullptr);
MOZ_ASSERT(mSampler->HasTreeManager(mTreeManager));
MOZ_ASSERT(mUpdater != nullptr);
MOZ_ASSERT(mUpdater->HasTreeManager(mTreeManager));
}
APZCTreeManagerParent::~APZCTreeManagerParent()
@ -31,19 +31,19 @@ APZCTreeManagerParent::~APZCTreeManagerParent()
void
APZCTreeManagerParent::ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager,
RefPtr<APZSampler> aAPZSampler)
RefPtr<APZUpdater> aAPZUpdater)
{
MOZ_ASSERT(aAPZCTreeManager != nullptr);
MOZ_ASSERT(aAPZSampler != nullptr);
MOZ_ASSERT(aAPZSampler->HasTreeManager(aAPZCTreeManager));
MOZ_ASSERT(aAPZUpdater != nullptr);
MOZ_ASSERT(aAPZUpdater->HasTreeManager(aAPZCTreeManager));
mTreeManager = Move(aAPZCTreeManager);
mSampler = Move(aAPZSampler);
mUpdater = Move(aAPZUpdater);
}
mozilla::ipc::IPCResult
APZCTreeManagerParent::RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap)
{
mSampler->RunOnControllerThread(NewRunnableMethod<KeyboardMap>(
mUpdater->RunOnControllerThread(NewRunnableMethod<KeyboardMap>(
"layers::IAPZCTreeManager::SetKeyboardMap",
mTreeManager,
&IAPZCTreeManager::SetKeyboardMap,
@ -64,7 +64,7 @@ APZCTreeManagerParent::RecvZoomToRect(
return IPC_FAIL_NO_REASON(this);
}
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<ScrollableLayerGuid, CSSRect, uint32_t>(
"layers::IAPZCTreeManager::ZoomToRect",
mTreeManager,
@ -78,7 +78,7 @@ APZCTreeManagerParent::RecvContentReceivedInputBlock(
const uint64_t& aInputBlockId,
const bool& aPreventDefault)
{
mSampler->RunOnControllerThread(NewRunnableMethod<uint64_t, bool>(
mUpdater->RunOnControllerThread(NewRunnableMethod<uint64_t, bool>(
"layers::IAPZCTreeManager::ContentReceivedInputBlock",
mTreeManager,
&IAPZCTreeManager::ContentReceivedInputBlock,
@ -100,7 +100,7 @@ APZCTreeManagerParent::RecvSetTargetAPZC(
return IPC_FAIL_NO_REASON(this);
}
}
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<uint64_t,
StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>(
"layers::IAPZCTreeManager::SetTargetAPZC",
@ -130,7 +130,7 @@ APZCTreeManagerParent::RecvUpdateZoomConstraints(
mozilla::ipc::IPCResult
APZCTreeManagerParent::RecvSetDPI(const float& aDpiValue)
{
mSampler->RunOnControllerThread(NewRunnableMethod<float>(
mUpdater->RunOnControllerThread(NewRunnableMethod<float>(
"layers::IAPZCTreeManager::SetDPI",
mTreeManager,
&IAPZCTreeManager::SetDPI,
@ -143,7 +143,7 @@ APZCTreeManagerParent::RecvSetAllowedTouchBehavior(
const uint64_t& aInputBlockId,
nsTArray<TouchBehaviorFlags>&& aValues)
{
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<uint64_t,
StoreCopyPassByRRef<nsTArray<TouchBehaviorFlags>>>(
"layers::IAPZCTreeManager::SetAllowedTouchBehavior",
@ -166,7 +166,7 @@ APZCTreeManagerParent::RecvStartScrollbarDrag(
return IPC_FAIL_NO_REASON(this);
}
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<ScrollableLayerGuid, AsyncDragMetrics>(
"layers::IAPZCTreeManager::StartScrollbarDrag",
mTreeManager,
@ -189,7 +189,7 @@ APZCTreeManagerParent::RecvStartAutoscroll(
// mLayersId stores the parent process's layers id, while nsBaseWidget is
// sending the child process's layers id).
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<ScrollableLayerGuid, ScreenPoint>(
"layers::IAPZCTreeManager::StartAutoscroll",
mTreeManager,
@ -204,7 +204,7 @@ APZCTreeManagerParent::RecvStopAutoscroll(const ScrollableLayerGuid& aGuid)
{
// See RecvStartAutoscroll() for why we don't check the layers id.
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<ScrollableLayerGuid>(
"layers::IAPZCTreeManager::StopAutoscroll",
mTreeManager,
@ -217,7 +217,7 @@ APZCTreeManagerParent::RecvStopAutoscroll(const ScrollableLayerGuid& aGuid)
mozilla::ipc::IPCResult
APZCTreeManagerParent::RecvSetLongTapEnabled(const bool& aLongTapEnabled)
{
mSampler->RunOnControllerThread(
mUpdater->RunOnControllerThread(
NewRunnableMethod<bool>(
"layers::IAPZCTreeManager::SetLongTapEnabled",
mTreeManager,

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

@ -13,7 +13,7 @@ namespace mozilla {
namespace layers {
class APZCTreeManager;
class APZSampler;
class APZUpdater;
class APZCTreeManagerParent
: public PAPZCTreeManagerParent
@ -22,7 +22,7 @@ public:
APZCTreeManagerParent(LayersId aLayersId,
RefPtr<APZCTreeManager> aAPZCTreeManager,
RefPtr<APZSampler> mAPZSampler);
RefPtr<APZUpdater> mAPZUpdater);
virtual ~APZCTreeManagerParent();
LayersId GetLayersId() const { return mLayersId; }
@ -32,7 +32,7 @@ public:
* is adopted by another compositor, and we need to switch APZCTreeManagers.
*/
void ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager,
RefPtr<APZSampler> aAPZSampler);
RefPtr<APZUpdater> aAPZUpdater);
mozilla::ipc::IPCResult
RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap) override;
@ -88,7 +88,7 @@ public:
private:
LayersId mLayersId;
RefPtr<APZCTreeManager> mTreeManager;
RefPtr<APZSampler> mSampler;
RefPtr<APZUpdater> mUpdater;
};
} // namespace layers

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

@ -43,6 +43,7 @@
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
#include "mozilla/layers/APZSampler.h" // for APZSampler
#include "mozilla/layers/APZThreadUtils.h" // for APZThreadUtils
#include "mozilla/layers/APZUpdater.h" // for APZUpdater
#include "mozilla/layers/AsyncCompositionManager.h"
#include "mozilla/layers/BasicCompositor.h" // for BasicCompositor
#include "mozilla/layers/Compositor.h" // for Compositor
@ -381,8 +382,10 @@ CompositorBridgeParent::Initialize()
if (mOptions.UseAPZ()) {
MOZ_ASSERT(!mApzcTreeManager);
MOZ_ASSERT(!mApzSampler);
MOZ_ASSERT(!mApzUpdater);
mApzcTreeManager = new APZCTreeManager(mRootLayerTreeID);
mApzSampler = new APZSampler(mApzcTreeManager);
mApzUpdater = new APZUpdater(mApzcTreeManager);
}
mCompositorBridgeID = 0;
@ -633,9 +636,11 @@ CompositorBridgeParent::ActorDestroy(ActorDestroyReason why)
mCompositionManager = nullptr;
MOZ_ASSERT((mApzSampler != nullptr) == (mApzcTreeManager != nullptr));
if (mApzSampler) {
mApzSampler->ClearTree();
MOZ_ASSERT((mApzUpdater != nullptr) == (mApzcTreeManager != nullptr));
if (mApzUpdater) {
mApzSampler = nullptr;
mApzUpdater->ClearTree();
mApzUpdater = nullptr;
mApzcTreeManager = nullptr;
}
@ -859,10 +864,10 @@ CompositorBridgeParent::NotifyShadowTreeTransaction(LayersId aId, bool aIsFirstP
}
#endif
if (mApzSampler) {
mApzSampler->UpdateFocusState(mRootLayerTreeID, aId, aFocusTarget);
if (mApzUpdater) {
mApzUpdater->UpdateFocusState(mRootLayerTreeID, aId, aFocusTarget);
if (aHitTestUpdate) {
mApzSampler->UpdateHitTestingTree(mRootLayerTreeID,
mApzUpdater->UpdateHitTestingTree(mRootLayerTreeID,
mLayerManager->GetRoot(), aIsFirstPaint, aId, aPaintSequenceNumber);
}
}
@ -1096,9 +1101,9 @@ CompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId& aLayersId)
MOZ_ASSERT(XRE_IsGPUProcess());
// We should only ever get this if APZ is enabled in this compositor.
MOZ_ASSERT(mOptions.UseAPZ());
// The mApzcTreeManager and mApzSampler should have been created via RecvInitialize()
// The mApzcTreeManager and mApzUpdater should have been created via RecvInitialize()
MOZ_ASSERT(mApzcTreeManager);
MOZ_ASSERT(mApzSampler);
MOZ_ASSERT(mApzUpdater);
// The main process should pass in 0 because we assume mRootLayerTreeID
MOZ_ASSERT(!aLayersId.IsValid());
@ -1106,7 +1111,7 @@ CompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId& aLayersId)
CompositorBridgeParent::LayerTreeState& state = sIndirectLayerTrees[mRootLayerTreeID];
MOZ_ASSERT(state.mParent.get() == this);
MOZ_ASSERT(!state.mApzcTreeManagerParent);
state.mApzcTreeManagerParent = new APZCTreeManagerParent(mRootLayerTreeID, mApzcTreeManager, mApzSampler);
state.mApzcTreeManagerParent = new APZCTreeManagerParent(mRootLayerTreeID, mApzcTreeManager, mApzUpdater);
return state.mApzcTreeManagerParent;
}
@ -1125,9 +1130,9 @@ CompositorBridgeParent::AllocateAPZCTreeManagerParent(const MonitorAutoLock& aPr
{
MOZ_ASSERT(aState.mParent == this);
MOZ_ASSERT(mApzcTreeManager);
MOZ_ASSERT(mApzSampler);
MOZ_ASSERT(mApzUpdater);
MOZ_ASSERT(!aState.mApzcTreeManagerParent);
aState.mApzcTreeManagerParent = new APZCTreeManagerParent(aLayersId, mApzcTreeManager, mApzSampler);
aState.mApzcTreeManagerParent = new APZCTreeManagerParent(aLayersId, mApzcTreeManager, mApzUpdater);
}
PAPZParent*
@ -1172,6 +1177,12 @@ CompositorBridgeParent::GetAPZSampler()
return mApzSampler;
}
RefPtr<APZUpdater>
CompositorBridgeParent::GetAPZUpdater()
{
return mApzUpdater;
}
CompositorBridgeParent*
CompositorBridgeParent::GetCompositorBridgeParentFromLayersId(const LayersId& aLayersId)
{
@ -1230,15 +1241,15 @@ CompositorBridgeParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
Layer* root = aLayerTree->GetRoot();
mLayerManager->SetRoot(root);
if (mApzSampler && !aInfo.isRepeatTransaction()) {
mApzSampler->UpdateFocusState(mRootLayerTreeID,
if (mApzUpdater && !aInfo.isRepeatTransaction()) {
mApzUpdater->UpdateFocusState(mRootLayerTreeID,
mRootLayerTreeID,
aInfo.focusTarget());
if (aHitTestUpdate) {
AutoResolveRefLayers resolve(mCompositionManager);
mApzSampler->UpdateHitTestingTree(
mApzUpdater->UpdateHitTestingTree(
mRootLayerTreeID, root, aInfo.isFirstPaint(),
mRootLayerTreeID, aInfo.paintSequenceNumber());
}
@ -1359,9 +1370,9 @@ CompositorBridgeParent::SetTestAsyncScrollOffset(
const FrameMetrics::ViewID& aScrollId,
const CSSPoint& aPoint)
{
if (mApzSampler) {
if (mApzUpdater) {
MOZ_ASSERT(aLayersId.IsValid());
mApzSampler->SetTestAsyncScrollOffset(aLayersId, aScrollId, aPoint);
mApzUpdater->SetTestAsyncScrollOffset(aLayersId, aScrollId, aPoint);
}
}
@ -1371,9 +1382,9 @@ CompositorBridgeParent::SetTestAsyncZoom(
const FrameMetrics::ViewID& aScrollId,
const LayerToParentLayerScale& aZoom)
{
if (mApzSampler) {
if (mApzUpdater) {
MOZ_ASSERT(aLayersId.IsValid());
mApzSampler->SetTestAsyncZoom(aLayersId, aScrollId, aZoom);
mApzUpdater->SetTestAsyncZoom(aLayersId, aScrollId, aZoom);
}
}
@ -1392,9 +1403,9 @@ void
CompositorBridgeParent::GetAPZTestData(const LayersId& aLayersId,
APZTestData* aOutData)
{
if (mApzSampler) {
if (mApzUpdater) {
MOZ_ASSERT(aLayersId.IsValid());
mApzSampler->GetAPZTestData(aLayersId, aOutData);
mApzUpdater->GetAPZTestData(aLayersId, aOutData);
}
}
@ -1683,7 +1694,7 @@ CompositorBridgeParent::RecvMapAndNotifyChildCreated(const LayersId& aChild,
mozilla::ipc::IPCResult
CompositorBridgeParent::RecvAdoptChild(const LayersId& child)
{
RefPtr<APZSampler> oldApzSampler;
RefPtr<APZUpdater> oldApzUpdater;
APZCTreeManagerParent* parent;
{
MonitorAutoLock lock(*sIndirectLayerTreesLock);
@ -1691,7 +1702,7 @@ CompositorBridgeParent::RecvAdoptChild(const LayersId& child)
// We currently don't support adopting children from one compositor to
// another if the two compositors don't have the same options.
MOZ_ASSERT(sIndirectLayerTrees[child].mParent->mOptions == mOptions);
oldApzSampler = sIndirectLayerTrees[child].mParent->mApzSampler;
oldApzUpdater = sIndirectLayerTrees[child].mParent->mApzUpdater;
}
NotifyChildCreated(child);
if (sIndirectLayerTrees[child].mLayerTree) {
@ -1717,21 +1728,21 @@ CompositorBridgeParent::RecvAdoptChild(const LayersId& child)
parent = sIndirectLayerTrees[child].mApzcTreeManagerParent;
}
if (oldApzSampler) {
if (oldApzUpdater) {
// We don't support moving a child from an APZ-enabled compositor to a
// APZ-disabled compositor. The mOptions assertion above should already
// ensure this, since APZ-ness is one of the things in mOptions. Note
// however it is possible for mApzSampler to be non-null here with
// oldApzSampler null, because the child may not have been previously
// however it is possible for mApzUpdater to be non-null here with
// oldApzUpdater null, because the child may not have been previously
// composited.
MOZ_ASSERT(mApzSampler);
MOZ_ASSERT(mApzUpdater);
}
if (mApzSampler) {
if (mApzUpdater) {
if (parent) {
MOZ_ASSERT(mApzcTreeManager);
parent->ChildAdopted(mApzcTreeManager, mApzSampler);
parent->ChildAdopted(mApzcTreeManager, mApzUpdater);
}
mApzSampler->NotifyLayerTreeAdopted(child, oldApzSampler);
mApzUpdater->NotifyLayerTreeAdopted(child, oldApzUpdater);
}
return IPC_OK();
}
@ -1823,7 +1834,7 @@ EraseLayerState(LayersId aId)
if (iter != sIndirectLayerTrees.end()) {
CompositorBridgeParent* parent = iter->second.mParent;
if (parent) {
if (RefPtr<APZSampler> apz = parent->GetAPZSampler()) {
if (RefPtr<APZUpdater> apz = parent->GetAPZUpdater()) {
apz->NotifyLayerTreeRemoved(aId);
}
}

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

@ -64,6 +64,7 @@ namespace layers {
class APZCTreeManager;
class APZCTreeManagerParent;
class APZSampler;
class APZUpdater;
class AsyncCompositionManager;
class AsyncImagePipelineManager;
class Compositor;
@ -461,6 +462,7 @@ public:
AndroidDynamicToolbarAnimator* GetAndroidDynamicToolbarAnimator();
#endif
RefPtr<APZSampler> GetAPZSampler();
RefPtr<APZUpdater> GetAPZUpdater();
CompositorOptions GetOptions() const {
return mOptions;
@ -623,6 +625,7 @@ protected:
RefPtr<APZCTreeManager> mApzcTreeManager;
RefPtr<APZSampler> mApzSampler;
RefPtr<APZUpdater> mApzUpdater;
RefPtr<CompositorVsyncScheduler> mCompositorScheduler;
// This makes sure the compositorParent is not destroyed before receiving

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

@ -19,7 +19,7 @@
#include "mozilla/ipc/Transport.h" // for Transport
#include "mozilla/layers/AnimationHelper.h" // for CompositorAnimationStorage
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
#include "mozilla/layers/APZSampler.h" // for APZSampler
#include "mozilla/layers/APZUpdater.h" // for APZUpdater
#include "mozilla/layers/AsyncCompositionManager.h"
#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/layers/CompositorThread.h"
@ -134,9 +134,9 @@ CrossProcessCompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId&
// Note: we immediately call ClearTree since otherwise the APZCTM will
// retain a reference to itself, through the checkerboard observer.
RefPtr<APZCTreeManager> temp = new APZCTreeManager(LayersId{0});
RefPtr<APZSampler> tempSampler = new APZSampler(temp);
tempSampler->ClearTree();
return new APZCTreeManagerParent(aLayersId, temp, tempSampler);
RefPtr<APZUpdater> tempUpdater = new APZUpdater(temp);
tempUpdater->ClearTree();
return new APZCTreeManagerParent(aLayersId, temp, tempUpdater);
}
state.mParent->AllocateAPZCTreeManagerParent(lock, aLayersId, state);

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

@ -94,6 +94,7 @@ EXPORTS.mozilla.layers += [
'AnimationInfo.h',
'apz/public/APZInputBridge.h',
'apz/public/APZSampler.h',
'apz/public/APZUpdater.h',
'apz/public/CompositorController.h',
'apz/public/GeckoContentController.h',
'apz/public/IAPZCTreeManager.h',
@ -298,6 +299,7 @@ UNIFIED_SOURCES += [
'apz/src/APZCTreeManager.cpp',
'apz/src/APZInputBridge.cpp',
'apz/src/APZSampler.cpp',
'apz/src/APZUpdater.cpp',
'apz/src/APZUtils.cpp',
'apz/src/AsyncPanZoomController.cpp',
'apz/src/AutoscrollAnimation.cpp',

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

@ -16,6 +16,7 @@
#include "mozilla/Range.h"
#include "mozilla/layers/AnimationHelper.h"
#include "mozilla/layers/APZSampler.h"
#include "mozilla/layers/APZUpdater.h"
#include "mozilla/layers/Compositor.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#include "mozilla/layers/CompositorThread.h"
@ -516,7 +517,7 @@ WebRenderBridgeParent::UpdateAPZ(bool aUpdateHitTestingTree)
if (!rootWrbp) {
return;
}
if (RefPtr<APZSampler> apz = cbp->GetAPZSampler()) {
if (RefPtr<APZUpdater> apz = cbp->GetAPZUpdater()) {
apz->UpdateFocusState(rootLayersId, GetLayersId(),
mScrollData.GetFocusTarget());
if (aUpdateHitTestingTree) {