Bug 933082 - Part 4: let ClientLayerManager hold a ShadowLayerForwarder instead of inheriting from ShadowLayerForwarder. Make ISurfaceAllocator refcounted. Make SharedSurface_Gralloc keep its mAllocator alive - r=nical

This commit is contained in:
Benoit Jacob 2013-11-26 14:00:29 -05:00
parent 88e510bc64
commit 7031739d99
18 changed files with 75 additions and 61 deletions

View File

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "nsPresContext.h"
#include "nsDOMClassInfoID.h"
#include "nsError.h"

View File

@ -43,7 +43,7 @@ SurfaceFactory_Gralloc::SurfaceFactory_Gralloc(GLContext* prodGL,
MOZ_ASSERT(allocator);
mAllocator = allocator->asWeakPtr();
mAllocator = allocator;
}
SharedSurface_Gralloc*

View File

@ -38,7 +38,7 @@ public:
protected:
GLLibraryEGL* const mEGL;
WeakPtr<layers::ISurfaceAllocator> mAllocator;
RefPtr<layers::ISurfaceAllocator> mAllocator;
// We keep the SurfaceDescriptor around, because we'll end up
// using it often and it's handy to do so. The actual
// GraphicBuffer is kept alive by the sp<GraphicBuffer> in
@ -64,7 +64,7 @@ protected:
size,
hasAlpha)
, mEGL(egl)
, mAllocator(allocator->asWeakPtr())
, mAllocator(allocator)
, mDesc(desc)
, mProdTex(prodTex)
{}
@ -93,7 +93,7 @@ class SurfaceFactory_Gralloc
: public SurfaceFactory_GL
{
protected:
WeakPtr<layers::ISurfaceAllocator> mAllocator;
RefPtr<layers::ISurfaceAllocator> mAllocator;
public:
SurfaceFactory_Gralloc(GLContext* prodGL,

View File

@ -45,7 +45,7 @@ ClientCanvasLayer::Initialize(const Data& aData)
screen->PreserveBuffer());
SurfaceFactory_GL* factory = nullptr;
if (!mForceReadback) {
if (ClientManager()->GetCompositorBackendType() == mozilla::layers::LAYERS_OPENGL) {
if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LAYERS_OPENGL) {
if (mGLContext->GetEGLContext()) {
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
@ -55,7 +55,7 @@ ClientCanvasLayer::Initialize(const Data& aData)
} else {
// [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
#ifdef MOZ_WIDGET_GONK
factory = new SurfaceFactory_Gralloc(mGLContext, screen->Caps(), ClientManager());
factory = new SurfaceFactory_Gralloc(mGLContext, screen->Caps(), ClientManager()->AsShadowForwarder());
#else
// we could do readback here maybe
NS_NOTREACHED("isCrossProcess but not on native B2G!");
@ -106,13 +106,13 @@ ClientCanvasLayer::RenderLayer()
flags |= TEXTURE_DEALLOCATE_CLIENT;
}
mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
ClientManager(), flags);
ClientManager()->AsShadowForwarder(), flags);
if (!mCanvasClient) {
return;
}
if (HasShadow()) {
mCanvasClient->Connect();
ClientManager()->Attach(mCanvasClient, this);
ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
}
}

View File

@ -92,9 +92,9 @@ public:
{
NS_ASSERTION(ClientManager()->InConstruction(),
"Can only set properties in construction phase");
ClientManager()->InsertAfter(ClientManager()->Hold(this),
ClientManager()->Hold(aChild),
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
ClientManager()->AsShadowForwarder()->InsertAfter(ClientManager()->Hold(this),
ClientManager()->Hold(aChild),
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
ContainerLayer::InsertAfter(aChild, aAfter);
}
@ -102,8 +102,8 @@ public:
{
NS_ASSERTION(ClientManager()->InConstruction(),
"Can only set properties in construction phase");
ClientManager()->RemoveChild(ClientManager()->Hold(this),
ClientManager()->Hold(aChild));
ClientManager()->AsShadowForwarder()->RemoveChild(ClientManager()->Hold(this),
ClientManager()->Hold(aChild));
ContainerLayer::RemoveChild(aChild);
}
@ -111,9 +111,9 @@ public:
{
NS_ASSERTION(ClientManager()->InConstruction(),
"Can only set properties in construction phase");
ClientManager()->RepositionChild(ClientManager()->Hold(this),
ClientManager()->Hold(aChild),
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
ClientManager()->AsShadowForwarder()->RepositionChild(ClientManager()->Hold(this),
ClientManager()->Hold(aChild),
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
ContainerLayer::RepositionChild(aChild, aAfter);
}

View File

@ -143,7 +143,7 @@ ClientImageLayer::RenderLayer()
flags |= TEXTURE_DISALLOW_BIGIMAGE;
}
mImageClient = ImageClient::CreateImageClient(type,
ClientManager(),
ClientManager()->AsShadowForwarder(),
flags);
if (type == BUFFER_BRIDGE) {
static_cast<ImageClientBridge*>(mImageClient.get())->SetLayer(this);
@ -154,7 +154,7 @@ ClientImageLayer::RenderLayer()
}
if (HasShadow() && !mContainer->IsAsync()) {
mImageClient->Connect();
ClientManager()->Attach(mImageClient, this);
ClientManager()->AsShadowForwarder()->Attach(mImageClient, this);
}
if (!mImageClient->UpdateImage(mContainer, GetContentFlags())) {
return;

View File

@ -20,7 +20,7 @@
#include "mozilla/layers/LayersMessages.h" // for EditReply, etc
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/PLayerChild.h" // for PLayerChild
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "nsAString.h"
#include "nsIWidget.h" // for nsIWidget
#include "nsTArray.h" // for AutoInfallibleTArray
@ -44,6 +44,7 @@ ClientLayerManager::ClientLayerManager(nsIWidget* aWidget)
, mTransactionIncomplete(false)
, mCompositorMightResample(false)
, mNeedsComposite(false)
, mForwarder(new ShadowLayerForwarder)
{
MOZ_COUNT_CTOR(ClientLayerManager);
}
@ -58,7 +59,7 @@ ClientLayerManager::~ClientLayerManager()
int32_t
ClientLayerManager::GetMaxTextureSize() const
{
return ShadowLayerForwarder::GetMaxTextureSize();
return mForwarder->GetMaxTextureSize();
}
void
@ -82,7 +83,7 @@ ClientLayerManager::SetRoot(Layer* aLayer)
if (mRoot) {
Hold(mRoot);
}
ShadowLayerForwarder::SetRoot(Hold(aLayer));
mForwarder->SetRoot(Hold(aLayer));
NS_ASSERTION(aLayer, "Root can't be null");
NS_ASSERTION(aLayer->Manager() == this, "Wrong manager");
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
@ -96,7 +97,7 @@ ClientLayerManager::Mutated(Layer* aLayer)
LayerManager::Mutated(aLayer);
NS_ASSERTION(InConstruction() || InDrawing(), "wrong phase");
ShadowLayerForwarder::Mutated(Hold(aLayer));
mForwarder->Mutated(Hold(aLayer));
}
void
@ -129,7 +130,7 @@ ClientLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
nsIntRect clientBounds;
mWidget->GetClientBounds(clientBounds);
clientBounds.x = clientBounds.y = 0;
ShadowLayerForwarder::BeginTransaction(mTargetBounds, mTargetRotation, clientBounds, orientation);
mForwarder->BeginTransaction(mTargetBounds, mTargetRotation, clientBounds, orientation);
// If we're drawing on behalf of a context with async pan/zoom
// enabled, then the entire buffer of thebes layers might be
@ -264,9 +265,9 @@ ClientLayerManager::MakeSnapshotIfRequired()
nsIntRect bounds;
mWidget->GetBounds(bounds);
SurfaceDescriptor inSnapshot, snapshot;
if (AllocSurfaceDescriptor(bounds.Size(),
GFX_CONTENT_COLOR_ALPHA,
&inSnapshot) &&
if (mForwarder->AllocSurfaceDescriptor(bounds.Size(),
GFX_CONTENT_COLOR_ALPHA,
&inSnapshot) &&
// The compositor will usually reuse |snapshot| and return
// it through |outSnapshot|, but if it doesn't, it's
// responsible for freeing |snapshot|.
@ -277,7 +278,7 @@ ClientLayerManager::MakeSnapshotIfRequired()
mShadowTarget->DrawSurface(source, source->GetSize());
}
if (IsSurfaceDescriptorValid(snapshot)) {
ShadowLayerForwarder::DestroySharedSurface(&snapshot);
mForwarder->DestroySharedSurface(&snapshot);
}
}
}
@ -312,7 +313,7 @@ ClientLayerManager::ForwardTransaction()
// forward this transaction's changeset to our LayerManagerComposite
bool sent;
AutoInfallibleTArray<EditReply, 10> replies;
if (HasShadowManager() && ShadowLayerForwarder::EndTransaction(&replies, &sent)) {
if (HasShadowManager() && mForwarder->EndTransaction(&replies, &sent)) {
for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) {
const EditReply& reply = replies[i];
@ -393,21 +394,21 @@ bool
ClientLayerManager::IsCompositingCheap()
{
// Whether compositing is cheap depends on the parent backend.
return mShadowManager &&
LayerManager::IsCompositingCheap(GetCompositorBackendType());
return mForwarder->mShadowManager &&
LayerManager::IsCompositingCheap(mForwarder->GetCompositorBackendType());
}
void
ClientLayerManager::SetIsFirstPaint()
{
ShadowLayerForwarder::SetIsFirstPaint();
mForwarder->SetIsFirstPaint();
}
void
ClientLayerManager::ClearCachedResources(Layer* aSubtree)
{
MOZ_ASSERT(!HasShadowManager() || !aSubtree);
if (PLayerTransactionChild* manager = GetShadowManager()) {
if (LayerTransactionChild* manager = mForwarder->GetShadowManager()) {
manager->SendClearCachedResources();
}
if (aSubtree) {
@ -430,7 +431,7 @@ ClientLayerManager::ClearLayer(Layer* aLayer)
void
ClientLayerManager::GetBackendName(nsAString& aName)
{
switch (GetCompositorBackendType()) {
switch (mForwarder->GetCompositorBackendType()) {
case LAYERS_BASIC: aName.AssignLiteral("Basic"); return;
case LAYERS_OPENGL: aName.AssignLiteral("OpenGL"); return;
case LAYERS_D3D9: aName.AssignLiteral("Direct3D 9"); return;

View File

@ -34,8 +34,7 @@ class CompositorChild;
class ImageLayer;
class PLayerChild;
class ClientLayerManager : public LayerManager,
public ShadowLayerForwarder
class ClientLayerManager : public LayerManager
{
typedef nsTArray<nsRefPtr<Layer> > LayerRefArray;
@ -45,7 +44,7 @@ public:
virtual ShadowLayerForwarder* AsShadowForwarder()
{
return this;
return mForwarder;
}
virtual int32_t GetMaxTextureSize() const;
@ -75,7 +74,7 @@ public:
virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE
{
return mTextureFactoryIdentifier;
return mForwarder->GetTextureFactoryIdentifier();
}
virtual void FlushRendering() MOZ_OVERRIDE;
@ -85,7 +84,7 @@ public:
ShadowableLayer* Hold(Layer* aLayer);
bool HasShadowManager() const { return ShadowLayerForwarder::HasShadowManager(); }
bool HasShadowManager() const { return mForwarder->HasShadowManager(); }
virtual bool IsCompositingCheap();
virtual bool HasShadowManagerInternal() const { return HasShadowManager(); }
@ -206,6 +205,8 @@ private:
bool mTransactionIncomplete;
bool mCompositorMightResample;
bool mNeedsComposite;
RefPtr<ShadowLayerForwarder> mForwarder;
};
class ClientLayer : public ShadowableLayer
@ -255,12 +256,12 @@ CreateShadowFor(ClientLayer* aLayer,
ClientLayerManager* aMgr,
CreatedMethod aMethod)
{
PLayerChild* shadow = aMgr->ConstructShadowFor(aLayer);
PLayerChild* shadow = aMgr->AsShadowForwarder()->ConstructShadowFor(aLayer);
// XXX error handling
NS_ABORT_IF_FALSE(shadow, "failed to create shadow");
aLayer->SetShadow(shadow);
(aMgr->*aMethod)(aLayer);
(aMgr->AsShadowForwarder()->*aMethod)(aLayer);
aMgr->Hold(aLayer->AsLayer());
}

View File

@ -94,12 +94,12 @@ ClientThebesLayer::RenderLayer()
}
if (!mContentClient) {
mContentClient = ContentClient::CreateContentClient(ClientManager());
mContentClient = ContentClient::CreateContentClient(ClientManager()->AsShadowForwarder());
if (!mContentClient) {
return;
}
mContentClient->Connect();
ClientManager()->Attach(mContentClient, this);
ClientManager()->AsShadowForwarder()->Attach(mContentClient, this);
MOZ_ASSERT(mContentClient->GetForwarder());
}
@ -154,7 +154,7 @@ already_AddRefed<ThebesLayer>
ClientLayerManager::CreateThebesLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
if (Preferences::GetBool("layers.force-tiles") && GetCompositorBackendType() == LAYERS_OPENGL) {
if (Preferences::GetBool("layers.force-tiles") && AsShadowForwarder()->GetCompositorBackendType() == LAYERS_OPENGL) {
nsRefPtr<ClientTiledThebesLayer> layer =
new ClientTiledThebesLayer(this);
CREATE_SHADOW(Thebes);

View File

@ -134,7 +134,7 @@ ClientTiledThebesLayer::RenderLayer()
mContentClient = new TiledContentClient(this, ClientManager());
mContentClient->Connect();
ClientManager()->Attach(mContentClient, this);
ClientManager()->AsShadowForwarder()->Attach(mContentClient, this);
MOZ_ASSERT(mContentClient->GetForwarder());
}

View File

@ -316,7 +316,7 @@ BasicTiledLayerBuffer::ValidateTileInternal(BasicTiledLayerTile aTile,
{
if (aTile.IsPlaceholderTile()) {
RefPtr<DeprecatedTextureClient> textureClient =
new DeprecatedTextureClientTile(mManager, TextureInfo(BUFFER_TILED));
new DeprecatedTextureClientTile(mManager->AsShadowForwarder(), TextureInfo(BUFFER_TILED));
aTile.mDeprecatedTextureClient = static_cast<DeprecatedTextureClientTile*>(textureClient.get());
}
aTile.mDeprecatedTextureClient->EnsureAllocated(gfx::IntSize(GetTileLength(), GetTileLength()), GetContentType());

View File

@ -219,6 +219,11 @@ public:
return mMultiProcess;
}
const TextureFactoryIdentifier& GetTextureFactoryIdentifier() const
{
return mTextureFactoryIdentifier;
}
protected:
TextureFactoryIdentifier mTextureFactoryIdentifier;
bool mMultiProcess;

View File

@ -11,7 +11,7 @@
#include "gfxTypes.h"
#include "gfxPoint.h" // for gfxIntSize
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
#include "mozilla/WeakPtr.h"
#include "mozilla/RefPtr.h"
#include "nsIMemoryReporter.h" // for MemoryUniReporter
#include "mozilla/Atomics.h" // for Atomic
@ -73,10 +73,10 @@ bool ReleaseOwnedSurfaceDescriptor(const SurfaceDescriptor& aDescriptor);
* These methods should be only called in the ipdl implementor's thread, unless
* specified otherwise in the implementing class.
*/
class ISurfaceAllocator : public SupportsWeakPtr<ISurfaceAllocator>
class ISurfaceAllocator : public AtomicRefCounted<ISurfaceAllocator>
{
public:
ISurfaceAllocator() {}
ISurfaceAllocator() {}
/**
* Allocate shared memory that can be accessed by only one process at a time.
@ -140,7 +140,10 @@ protected:
SurfaceDescriptor* aBuffer);
~ISurfaceAllocator() {}
virtual ~ISurfaceAllocator() {}
friend class detail::RefCounted<ISurfaceAllocator, detail::AtomicRefCount>;
//friend class detail::RefCounted<ISurfaceAllocator, detail::AtomicRefCount>;
};
class GfxMemoryImageReporter MOZ_FINAL : public mozilla::MemoryUniReporter

View File

@ -199,7 +199,7 @@ ImageBridgeChild::UpdatePictureRect(CompositableClient* aCompositable,
}
// Singleton
static ImageBridgeChild *sImageBridgeChildSingleton = nullptr;
static StaticRefPtr<ImageBridgeChild> sImageBridgeChildSingleton;
static StaticRefPtr<ImageBridgeParent> sImageBridgeParentSingleton;
static Thread *sImageBridgeChildThread = nullptr;
@ -225,7 +225,6 @@ static void DeleteImageBridgeSync(ReentrantMonitor *aBarrier, bool *aDone)
NS_ABORT_IF_FALSE(InImageBridgeChildThread(),
"Should be in ImageBridgeChild thread.");
delete sImageBridgeChildSingleton;
sImageBridgeChildSingleton = nullptr;
sImageBridgeParentSingleton = nullptr;
*aDone = true;

View File

@ -9,7 +9,7 @@
#include "mozilla/layers/PGrallocBufferChild.h"
#include "mozilla/layers/PGrallocBufferParent.h"
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "mozilla/layers/ShadowLayers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/CompositorTypes.h"

View File

@ -23,7 +23,7 @@
#include "mozilla/layers/LayersMessages.h" // for Edit, etc
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "ShadowLayerUtils.h"
#include "mozilla/layers/TextureClient.h" // for TextureClient
#include "mozilla/mozalloc.h" // for operator new, etc
@ -984,5 +984,11 @@ void ShadowLayerForwarder::AttachAsyncCompositable(uint64_t aCompositableID,
aCompositableID));
}
void ShadowLayerForwarder::SetShadowManager(PLayerTransactionChild* aShadowManager)
{
mShadowManager = static_cast<LayerTransactionChild*>(aShadowManager);
}
} // namespace layers
} // namespace mozilla

View File

@ -46,6 +46,7 @@ class OptionalThebesBuffer;
class PLayerChild;
class PLayerTransactionChild;
class PLayerTransactionParent;
class LayerTransactionChild;
class RefLayerComposite;
class ShadowableLayer;
class Shmem;
@ -137,6 +138,7 @@ class ShadowLayerForwarder : public CompositableForwarder
friend class AutoOpenSurface;
friend class DeprecatedTextureClientShmem;
friend class ContentClientIncremental;
friend class ClientLayerManager;
public:
virtual ~ShadowLayerForwarder();
@ -339,16 +341,13 @@ public:
/**
* Set an actor through which layer updates will be pushed.
*/
void SetShadowManager(PLayerTransactionChild* aShadowManager)
{
mShadowManager = aShadowManager;
}
void SetShadowManager(PLayerTransactionChild* aShadowManager);
/**
* True if this is forwarding to a LayerManagerComposite.
*/
bool HasShadowManager() const { return !!mShadowManager; }
PLayerTransactionChild* GetShadowManager() const { return mShadowManager.get(); }
LayerTransactionChild* GetShadowManager() const { return mShadowManager.get(); }
virtual void WindowOverlayChanged() { mWindowOverlayChanged = true; }
@ -421,7 +420,7 @@ protected:
void CheckSurfaceDescriptor(const SurfaceDescriptor* aDescriptor) const {}
#endif
RefPtr<PLayerTransactionChild> mShadowManager;
RefPtr<LayerTransactionChild> mShadowManager;
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
// from ISurfaceAllocator

View File

@ -3694,7 +3694,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (mGeckoChild->GetLayerManager()->GetBackendType() == LAYERS_CLIENT) {
ClientLayerManager *manager = static_cast<ClientLayerManager*>(mGeckoChild->GetLayerManager());
manager->WindowOverlayChanged();
manager->AsShadowForwarder()->WindowOverlayChanged();
}
}