Bug 1312059 - Extract a MetricsSharingController interface for the APZC code to use when dealing with shared frame metrics. r?botond
MozReview-Commit-ID: th5jm4pfQs
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/public/MetricsSharingController.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=4 ts=8 et 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_MetricsSharingController_h
+#define mozilla_layers_MetricsSharingController_h
+
+#include "FrameMetrics.h"
+#include "mozilla/ipc/CrossProcessMutex.h"
+#include "mozilla/ipc/SharedMemoryBasic.h"
+#include "mozilla/RefCountType.h"
+
+namespace mozilla {
+namespace layers {
+
+class MetricsSharingController
+{
+public:
+ NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
+ NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
+
+ virtual base::ProcessId RemotePid() = 0;
+ virtual bool StartSharingMetrics(mozilla::ipc::SharedMemoryBasic::Handle aHandle,
+ CrossProcessMutexHandle aMutexHandle,
+ uint64_t aLayersId,
+ uint32_t aApzcId) = 0;
+ virtual bool StopSharingMetrics(FrameMetrics::ViewID aScrollId,
+ uint32_t aApzcId) = 0;
+
+protected:
+ virtual ~MetricsSharingController() {}
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // mozilla_layers_MetricsSharingController_h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -543,19 +543,20 @@ APZCTreeManager::PrepareNodeForLayer(con
// The APZC we get off the layer may have been destroyed previously if the
// layer was inactive or omitted from the layer tree for whatever reason
// from a layers update. If it later comes back it will have a reference to
// a destroyed APZC and so we need to throw that out and make a new one.
bool newApzc = (apzc == nullptr || apzc->IsDestroyed());
if (newApzc) {
apzc = NewAPZCInstance(aLayersId, state->mController);
apzc->SetCompositorController(aState.mCompositor);
- apzc->SetCompositorBridgeParent(aState.mCompositor);
- if (state->mCrossProcessParent != nullptr) {
- apzc->ShareFrameMetricsAcrossProcesses();
+ if (state->mCrossProcessParent) {
+ apzc->SetMetricsSharingController(state->CrossProcessSharingController());
+ } else {
+ apzc->SetMetricsSharingController(aState.mCompositor);
}
MOZ_ASSERT(node == nullptr);
node = new HitTestingTreeNode(apzc, true, aLayersId);
} else {
// If we are re-using a node for this layer clear the tree pointers
// so that it doesn't continue pointing to nodes that might no longer
// be in the tree. These pointers will get reset properly as we continue
// building the tree. Also remove it from the set of nodes that are going
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -48,19 +48,19 @@
#include "mozilla/gfx/Point.h" // for Point, RoundedToInt, etc
#include "mozilla/gfx/Rect.h" // for RoundedIn
#include "mozilla/gfx/ScaleFactor.h" // for ScaleFactor
#include "mozilla/layers/APZCTreeManager.h" // for ScrollableLayerGuid
#include "mozilla/layers/APZThreadUtils.h" // for AssertOnControllerThread, etc
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform
#include "mozilla/layers/AxisPhysicsModel.h" // for AxisPhysicsModel
#include "mozilla/layers/AxisPhysicsMSDModel.h" // for AxisPhysicsMSDModel
-#include "mozilla/layers/CompositorBridgeParent.h" // for CompositorBridgeParent
#include "mozilla/layers/CompositorController.h" // for CompositorController
#include "mozilla/layers/LayerTransactionParent.h" // for LayerTransactionParent
+#include "mozilla/layers/MetricsSharingController.h" // for MetricsSharingController
#include "mozilla/layers/ScrollInputMethods.h" // for ScrollInputMethod
#include "mozilla/mozalloc.h" // for operator new, etc
#include "mozilla/Unused.h" // for unused
#include "mozilla/FloatingPoint.h" // for FuzzyEquals*
#include "nsAlgorithm.h" // for clamped
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsDebug.h" // for NS_WARNING
#include "nsIDOMWindowUtils.h" // for nsIDOMWindowUtils
@@ -694,17 +694,16 @@ AsyncPanZoomController::AsyncPanZoomCont
const RefPtr<InputQueue>& aInputQueue,
GeckoContentController* aGeckoContentController,
GestureBehavior aGestures)
: mLayersId(aLayersId),
mGeckoContentController(aGeckoContentController),
mRefPtrMonitor("RefPtrMonitor"),
// mTreeManager must be initialized before GetFrameTime() is called
mTreeManager(aTreeManager),
- mSharingFrameMetricsAcrossProcesses(false),
mFrameMetrics(mScrollMetadata.GetMetrics()),
mMonitor("AsyncPanZoomController"),
mLastContentPaintMetrics(mLastContentPaintMetadata.GetMetrics()),
mX(this),
mY(this),
mPanDirRestricted(false),
mZoomConstraints(false, false,
mFrameMetrics.GetDevPixelsPerCSSPixel() * kViewportMinScale / ParentLayerToScreenScale(1),
@@ -726,31 +725,16 @@ AsyncPanZoomController::AsyncPanZoomCont
}
}
AsyncPanZoomController::~AsyncPanZoomController()
{
MOZ_ASSERT(IsDestroyed());
}
-PCompositorBridgeParent*
-AsyncPanZoomController::GetSharedFrameMetricsCompositor()
-{
- APZThreadUtils::AssertOnCompositorThread();
-
- if (mSharingFrameMetricsAcrossProcesses) {
- // |state| may be null here if the CrossProcessCompositorBridgeParent has already been destroyed.
- if (const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(mLayersId)) {
- return state->CrossProcessPCompositorBridge();
- }
- return nullptr;
- }
- return mCompositorBridgeParent.get();
-}
-
PlatformSpecificStateBase*
AsyncPanZoomController::GetPlatformSpecificState()
{
if (!mPlatformSpecificState) {
mPlatformSpecificState = MakeUnique<PlatformSpecificState>();
}
return mPlatformSpecificState.get();
}
@@ -784,20 +768,19 @@ AsyncPanZoomController::Destroy()
{ // scope the lock
MonitorAutoLock lock(mRefPtrMonitor);
mGeckoContentController = nullptr;
mGestureEventListener = nullptr;
}
mParent = nullptr;
mTreeManager = nullptr;
- PCompositorBridgeParent* compositor = GetSharedFrameMetricsCompositor();
// Only send the release message if the SharedFrameMetrics has been created.
- if (compositor && mSharedFrameMetricsBuffer) {
- Unused << compositor->SendReleaseSharedCompositorFrameMetrics(mFrameMetrics.GetScrollId(), mAPZCId);
+ if (mMetricsSharingController && mSharedFrameMetricsBuffer) {
+ Unused << mMetricsSharingController->StopSharingMetrics(mFrameMetrics.GetScrollId(), mAPZCId);
}
{ // scope the lock
ReentrantMonitorAutoEnter lock(mMonitor);
mSharedFrameMetricsBuffer = nullptr;
delete mSharedLock;
mSharedLock = nullptr;
}
@@ -2655,22 +2638,19 @@ void AsyncPanZoomController::ClearOversc
mY.ClearOverscroll();
}
void AsyncPanZoomController::SetCompositorController(CompositorController* aCompositorController)
{
mCompositorController = aCompositorController;
}
-void AsyncPanZoomController::SetCompositorBridgeParent(CompositorBridgeParent* aCompositorBridgeParent) {
- mCompositorBridgeParent = aCompositorBridgeParent;
-}
-
-void AsyncPanZoomController::ShareFrameMetricsAcrossProcesses() {
- mSharingFrameMetricsAcrossProcesses = true;
+void AsyncPanZoomController::SetMetricsSharingController(MetricsSharingController* aMetricsSharingController)
+{
+ mMetricsSharingController = aMetricsSharingController;
}
void AsyncPanZoomController::AdjustScrollForSurfaceShift(const ScreenPoint& aShift)
{
ReentrantMonitorAutoEnter lock(mMonitor);
CSSPoint adjustment =
ViewAs<ParentLayerPixel>(aShift, PixelCastJustification::ScreenIsParentLayerForRoot)
/ mFrameMetrics.GetZoom();
@@ -3876,54 +3856,54 @@ void AsyncPanZoomController::UpdateShare
if (frame && mSharedLock && gfxPrefs::ProgressivePaint()) {
mSharedLock->Lock();
*frame = mFrameMetrics;
mSharedLock->Unlock();
}
}
-void AsyncPanZoomController::ShareCompositorFrameMetrics() {
-
- PCompositorBridgeParent* compositor = GetSharedFrameMetricsCompositor();
+void AsyncPanZoomController::ShareCompositorFrameMetrics()
+{
+ APZThreadUtils::AssertOnCompositorThread();
// Only create the shared memory buffer if it hasn't already been created,
// we are using progressive tile painting, and we have a
- // compositor to pass the shared memory back to the content process/thread.
- if (!mSharedFrameMetricsBuffer && compositor && gfxPrefs::ProgressivePaint()) {
+ // controller to pass the shared memory back to the content process/thread.
+ if (!mSharedFrameMetricsBuffer && mMetricsSharingController && gfxPrefs::ProgressivePaint()) {
// Create shared memory and initialize it with the current FrameMetrics value
mSharedFrameMetricsBuffer = new ipc::SharedMemoryBasic;
FrameMetrics* frame = nullptr;
mSharedFrameMetricsBuffer->Create(sizeof(FrameMetrics));
mSharedFrameMetricsBuffer->Map(sizeof(FrameMetrics));
frame = static_cast<FrameMetrics*>(mSharedFrameMetricsBuffer->memory());
if (frame) {
{ // scope the monitor, only needed to copy the FrameMetrics.
ReentrantMonitorAutoEnter lock(mMonitor);
*frame = mFrameMetrics;
}
// Get the process id of the content process
- base::ProcessId otherPid = compositor->OtherPid();
+ base::ProcessId otherPid = mMetricsSharingController->RemotePid();
ipc::SharedMemoryBasic::Handle mem = ipc::SharedMemoryBasic::NULLHandle();
// Get the shared memory handle to share with the content process
mSharedFrameMetricsBuffer->ShareToProcess(otherPid, &mem);
// Get the cross process mutex handle to share with the content process
mSharedLock = new CrossProcessMutex("AsyncPanZoomControlLock");
CrossProcessMutexHandle handle = mSharedLock->ShareToProcess(otherPid);
// Send the shared memory handle and cross process handle to the content
// process by an asynchronous ipc call. Include the APZC unique ID
// so the content process know which APZC sent this shared FrameMetrics.
- if (!compositor->SendSharedCompositorFrameMetrics(mem, handle, mLayersId, mAPZCId)) {
+ if (!mMetricsSharingController->StartSharingMetrics(mem, handle, mLayersId, mAPZCId)) {
APZC_LOG("%p failed to share FrameMetrics with content process.", this);
}
}
}
}
Maybe<CSSPoint> AsyncPanZoomController::FindSnapPointNear(
const CSSPoint& aDestination, nsIScrollableFrame::ScrollUnit aUnit) {
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -39,20 +39,19 @@ namespace ipc {
class SharedMemoryBasic;
} // namespace ipc
namespace layers {
class AsyncDragMetrics;
struct ScrollableLayerGuid;
-class CompositorBridgeParent;
class CompositorController;
+class MetricsSharingController;
class GestureEventListener;
-class PCompositorBridgeParent;
struct AsyncTransform;
class AsyncPanZoomAnimation;
class AndroidFlingAnimation;
class GenericFlingAnimation;
class InputBlockState;
class TouchBlockState;
class PanGestureBlockState;
class OverscrollHandoffChain;
@@ -188,24 +187,21 @@ public:
bool aThisLayerTreeUpdated);
/**
* The platform implementation must set the compositor controller so that we can
* request composites.
*/
void SetCompositorController(CompositorController* aCompositorController);
- void SetCompositorBridgeParent(CompositorBridgeParent* aCompositorBridgeParent);
-
/**
- * Inform this APZC that it will be sharing its FrameMetrics with a cross-process
- * compositor so that the associated content process can access it. This is only
- * relevant when progressive painting is enabled.
+ * If we need to share the frame metrics with some other thread, this controller
+ * needs to be set and provides relevant information/APIs.
*/
- void ShareFrameMetricsAcrossProcesses();
+ void SetMetricsSharingController(MetricsSharingController* aMetricsSharingController);
// --------------------------------------------------------------------------
// These methods can be called from any thread.
//
/**
* Shut down the controller/UI thread state and prepare to be
* deleted (which may happen from any thread).
@@ -645,17 +641,17 @@ protected:
const ScreenIntPoint& aPoint,
mozilla::Modifiers aModifiers);
// Common processing at the end of a touch block.
void OnTouchEndOrCancel();
uint64_t mLayersId;
RefPtr<CompositorController> mCompositorController;
- RefPtr<CompositorBridgeParent> mCompositorBridgeParent;
+ RefPtr<MetricsSharingController> mMetricsSharingController;
/* 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
compositor thread. */
RefPtr<GeckoContentController> mGeckoContentController;
RefPtr<GestureEventListener> mGestureEventListener;
mutable Monitor mRefPtrMonitor;
@@ -665,22 +661,16 @@ protected:
// The APZCTreeManager owns the lifetime of the APZCs, so nulling this
// pointer out in Destroy() will prevent accessing deleted memory.
Atomic<APZCTreeManager*> mTreeManager;
/* Utility functions that return a addrefed pointer to the corresponding fields. */
already_AddRefed<GeckoContentController> GetGeckoContentController() const;
already_AddRefed<GestureEventListener> GetGestureEventListener() const;
- // If we are sharing our frame metrics with content across processes
- bool mSharingFrameMetricsAcrossProcesses;
- /* Utility function to get the Compositor with which we share the FrameMetrics.
- This function is only callable from the compositor thread. */
- PCompositorBridgeParent* GetSharedFrameMetricsCompositor();
-
PlatformSpecificStateBase* GetPlatformSpecificState();
protected:
// Both |mFrameMetrics| and |mLastContentPaintMetrics| are protected by the
// monitor. Do not read from or modify either of them without locking.
ScrollMetadata mScrollMetadata;
FrameMetrics& mFrameMetrics; // for convenience, refers to mScrollMetadata.mMetrics
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -174,16 +174,40 @@ CompositorBridgeParentBase::AllocUnsafeS
}
void
CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem)
{
PCompositorBridgeParent::DeallocShmem(aShmem);
}
+base::ProcessId
+CompositorBridgeParentBase::RemotePid()
+{
+ return OtherPid();
+}
+
+bool
+CompositorBridgeParentBase::StartSharingMetrics(ipc::SharedMemoryBasic::Handle aHandle,
+ CrossProcessMutexHandle aMutexHandle,
+ uint64_t aLayersId,
+ uint32_t aApzcId)
+{
+ return PCompositorBridgeParent::SendSharedCompositorFrameMetrics(
+ aHandle, aMutexHandle, aLayersId, aApzcId);
+}
+
+bool
+CompositorBridgeParentBase::StopSharingMetrics(FrameMetrics::ViewID aScrollId,
+ uint32_t aApzcId)
+{
+ return PCompositorBridgeParent::SendReleaseSharedCompositorFrameMetrics(
+ aScrollId, aApzcId);
+}
+
CompositorBridgeParent::LayerTreeState::LayerTreeState()
: mApzcTreeManagerParent(nullptr)
, mParent(nullptr)
, mLayerManager(nullptr)
, mCrossProcessParent(nullptr)
, mLayerTree(nullptr)
, mUpdatedPluginDataAvailable(false)
, mPendingCompositorUpdates(0)
@@ -2259,18 +2283,18 @@ private:
RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
// If true, we should send a RemotePaintIsReady message when the layer transaction
// is received
bool mNotifyAfterRemotePaint;
bool mDestroyCalled;
};
-PCompositorBridgeParent*
-CompositorBridgeParent::LayerTreeState::CrossProcessPCompositorBridge() const
+MetricsSharingController*
+CompositorBridgeParent::LayerTreeState::CrossProcessSharingController() const
{
return mCrossProcessParent;
}
void
CompositorBridgeParent::DidComposite(TimeStamp& aCompositeStart,
TimeStamp& aCompositeEnd)
{
--- a/gfx/layers/ipc/CompositorBridgeParent.h
+++ b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -26,16 +26,17 @@
#include "mozilla/dom/ipc/IdType.h"
#include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/SharedMemory.h"
#include "mozilla/layers/CompositorController.h"
#include "mozilla/layers/GeckoContentController.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for ShmemAllocator
#include "mozilla/layers/LayersMessages.h" // for TargetConfig
+#include "mozilla/layers/MetricsSharingController.h"
#include "mozilla/layers/PCompositorBridgeParent.h"
#include "mozilla/layers/APZTestData.h"
#include "mozilla/widget/CompositorWidget.h"
#include "nsISupportsImpl.h"
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
#include "mozilla/VsyncDispatcher.h"
class MessageLoop;
@@ -189,17 +190,18 @@ private:
mozilla::Monitor mSetDisplayMonitor;
RefPtr<CancelableRunnable> mSetDisplayTask;
#endif
#endif
};
class CompositorBridgeParentBase : public PCompositorBridgeParent,
public HostIPCAllocator,
- public ShmemAllocator
+ public ShmemAllocator,
+ public MetricsSharingController
{
public:
virtual void ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
const uint64_t& aTransactionId,
const TargetConfig& aTargetConfig,
const InfallibleTArray<PluginWindowData>& aPlugins,
bool aIsFirstPaint,
bool aScheduleComposite,
@@ -222,32 +224,42 @@ public:
APZTestData* aOutData) { }
virtual void SetConfirmedTargetAPZC(const LayerTransactionParent* aLayerTree,
const uint64_t& aInputBlockId,
const nsTArray<ScrollableLayerGuid>& aTargets) = 0;
virtual void UpdatePaintTime(LayerTransactionParent* aLayerTree, const TimeDuration& aPaintTime) {}
virtual ShmemAllocator* AsShmemAllocator() override { return this; }
+ virtual bool RecvSyncWithCompositor() override { return true; }
+
// HostIPCAllocator
virtual base::ProcessId GetChildProcessId() override;
virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
virtual void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override;
// ShmemAllocator
virtual bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
virtual bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
- virtual bool RecvSyncWithCompositor() override { return true; }
-
+ // MetricsSharingController
+ NS_IMETHOD_(MozExternalRefCountType) AddRef() override { return HostIPCAllocator::AddRef(); }
+ NS_IMETHOD_(MozExternalRefCountType) Release() override { return HostIPCAllocator::Release(); }
+ base::ProcessId RemotePid() override;
+ bool StartSharingMetrics(mozilla::ipc::SharedMemoryBasic::Handle aHandle,
+ CrossProcessMutexHandle aMutexHandle,
+ uint64_t aLayersId,
+ uint32_t aApzcId) override;
+ bool StopSharingMetrics(FrameMetrics::ViewID aScrollId,
+ uint32_t aApzcId) override;
};
class CompositorBridgeParent final : public CompositorBridgeParentBase
, public CompositorController
{
friend class CompositorVsyncScheduler;
friend class CompositorThreadHolder;
friend class InProcessCompositorSession;
@@ -463,17 +475,17 @@ public:
LayerTransactionParent* mLayerTree;
nsTArray<PluginWindowData> mPluginData;
bool mUpdatedPluginDataAvailable;
// Number of times the compositor has been reset without having been
// acknowledged by the child.
uint32_t mPendingCompositorUpdates;
- PCompositorBridgeParent* CrossProcessPCompositorBridge() const;
+ MetricsSharingController* CrossProcessSharingController() const;
};
/**
* Lookup the indirect shadow tree for |aId| and return it if it
* exists. Otherwise null is returned. This must only be called on
* the compositor thread.
*/
static LayerTreeState* GetIndirectShadowTree(uint64_t aId);
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -96,16 +96,17 @@ EXPORTS.gfxipc += [
EXPORTS.mozilla.dom += [
'apz/util/CheckerboardReportService.h',
]
EXPORTS.mozilla.layers += [
'apz/public/CompositorController.h',
'apz/public/GeckoContentController.h',
'apz/public/IAPZCTreeManager.h',
+ 'apz/public/MetricsSharingController.h',
# exporting things from apz/src is temporary until we extract a
# proper interface for the code there
'apz/src/APZCTreeManager.h',
'apz/src/APZUtils.h',
'apz/src/AsyncDragMetrics.h',
'apz/src/AsyncPanZoomAnimation.h',
'apz/src/TouchCounter.h',
'apz/testutil/APZTestData.h',