Bug 997699 - Move CompositableParent to the .cpp. r=bjacob

This commit is contained in:
Nicolas Silva 2014-04-25 17:15:58 +02:00
parent 673c634324
commit 60f62b5e76
6 changed files with 130 additions and 152 deletions

View File

@ -22,8 +22,49 @@ namespace layers {
class Compositor; class Compositor;
/**
* IPDL actor used by CompositableHost to match with its corresponding
* CompositableClient on the content side.
*
* CompositableParent is owned by the IPDL system. It's deletion is triggered
* by either the CompositableChild's deletion, or by the IPDL communication
* goind down.
*/
class CompositableParent : public PCompositableParent
{
public:
CompositableParent(CompositableParentManager* aMgr,
const TextureInfo& aTextureInfo,
uint64_t aID = 0)
{
MOZ_COUNT_CTOR(CompositableParent);
mHost = CompositableHost::Create(aTextureInfo);
mHost->SetAsyncID(aID);
if (aID) {
CompositableMap::Set(aID, this);
}
}
~CompositableParent()
{
MOZ_COUNT_DTOR(CompositableParent);
CompositableMap::Erase(mHost->GetAsyncID());
}
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
{
if (mHost) {
mHost->Detach(nullptr, CompositableHost::FORCE_DETACH);
}
}
RefPtr<CompositableHost> mHost;
};
CompositableHost::CompositableHost(const TextureInfo& aTextureInfo) CompositableHost::CompositableHost(const TextureInfo& aTextureInfo)
: mTextureInfo(aTextureInfo) : mTextureInfo(aTextureInfo)
, mAsyncID(0)
, mCompositorID(0)
, mCompositor(nullptr) , mCompositor(nullptr)
, mLayer(nullptr) , mLayer(nullptr)
, mFlashCounter(0) , mFlashCounter(0)
@ -41,6 +82,28 @@ CompositableHost::~CompositableHost()
} }
} }
PCompositableParent*
CompositableHost::CreateIPDLActor(CompositableParentManager* aMgr,
const TextureInfo& aTextureInfo,
uint64_t aID)
{
return new CompositableParent(aMgr, aTextureInfo, aID);
}
bool
CompositableHost::DestroyIPDLActor(PCompositableParent* aActor)
{
delete aActor;
return true;
}
CompositableHost*
CompositableHost::FromIPDLActor(PCompositableParent* aActor)
{
MOZ_ASSERT(aActor);
return static_cast<CompositableParent*>(aActor)->mHost;
}
void void
CompositableHost::UseTextureHost(TextureHost* aTexture) CompositableHost::UseTextureHost(TextureHost* aTexture)
{ {
@ -171,43 +234,14 @@ CompositableHost::DumpTextureHost(FILE* aFile, TextureHost* aTexture)
} }
#endif #endif
void
CompositableParent::ActorDestroy(ActorDestroyReason why)
{
if (mHost) {
mHost->Detach(nullptr, CompositableHost::FORCE_DETACH);
}
}
CompositableParent::CompositableParent(CompositableParentManager* aMgr,
const TextureInfo& aTextureInfo,
uint64_t aID)
: mManager(aMgr)
, mType(aTextureInfo.mCompositableType)
, mID(aID)
, mCompositorID(0)
{
MOZ_COUNT_CTOR(CompositableParent);
mHost = CompositableHost::Create(aTextureInfo);
if (aID) {
CompositableMap::Set(aID, this);
}
}
CompositableParent::~CompositableParent()
{
MOZ_COUNT_DTOR(CompositableParent);
CompositableMap::Erase(mID);
}
namespace CompositableMap { namespace CompositableMap {
typedef std::map<uint64_t, CompositableParent*> CompositableMap_t; typedef std::map<uint64_t, PCompositableParent*> CompositableMap_t;
static CompositableMap_t* sCompositableMap = nullptr; static CompositableMap_t* sCompositableMap = nullptr;
bool IsCreated() { bool IsCreated() {
return sCompositableMap != nullptr; return sCompositableMap != nullptr;
} }
CompositableParent* Get(uint64_t aID) PCompositableParent* Get(uint64_t aID)
{ {
if (!IsCreated() || aID == 0) { if (!IsCreated() || aID == 0) {
return nullptr; return nullptr;
@ -218,7 +252,7 @@ CompositableParent* Get(uint64_t aID)
} }
return it->second; return it->second;
} }
void Set(uint64_t aID, CompositableParent* aParent) void Set(uint64_t aID, PCompositableParent* aParent)
{ {
if (!IsCreated() || aID == 0) { if (!IsCreated() || aID == 0) {
return; return;

View File

@ -51,6 +51,7 @@ class Compositor;
class ISurfaceAllocator; class ISurfaceAllocator;
class ThebesBufferData; class ThebesBufferData;
class TiledLayerComposer; class TiledLayerComposer;
class CompositableParentManager;
struct EffectChain; struct EffectChain;
/** /**
@ -307,8 +308,28 @@ public:
mFlashCounter = mFlashCounter >= DIAGNOSTIC_FLASH_COUNTER_MAX mFlashCounter = mFlashCounter >= DIAGNOSTIC_FLASH_COUNTER_MAX
? DIAGNOSTIC_FLASH_COUNTER_MAX : mFlashCounter + 1; ? DIAGNOSTIC_FLASH_COUNTER_MAX : mFlashCounter + 1;
} }
static PCompositableParent*
CreateIPDLActor(CompositableParentManager* mgr,
const TextureInfo& textureInfo,
uint64_t asyncID);
static bool DestroyIPDLActor(PCompositableParent* actor);
static CompositableHost* FromIPDLActor(PCompositableParent* actor);
uint64_t GetCompositorID() const { return mCompositorID; }
uint64_t GetAsyncID() const { return mAsyncID; }
void SetCompositorID(uint64_t aID) { mCompositorID = aID; }
void SetAsyncID(uint64_t aID) { mAsyncID = aID; }
protected: protected:
TextureInfo mTextureInfo; TextureInfo mTextureInfo;
uint64_t mAsyncID;
uint64_t mCompositorID;
Compositor* mCompositor; Compositor* mCompositor;
Layer* mLayer; Layer* mLayer;
RefPtr<CompositableBackendSpecificData> mBackendData; RefPtr<CompositableBackendSpecificData> mBackendData;
@ -317,65 +338,6 @@ protected:
bool mKeepAttached; bool mKeepAttached;
}; };
class CompositableParentManager;
/**
* IPDL actor used by CompositableHost to match with its corresponding
* CompositableClient on the content side.
*
* CompositableParent is owned by the IPDL system. It's deletion is triggered
* by either the CompositableChild's deletion, or by the IPDL communication
* goind down.
*/
class CompositableParent : public PCompositableParent
{
public:
CompositableParent(CompositableParentManager* aMgr,
const TextureInfo& aTextureInfo,
uint64_t aID = 0);
~CompositableParent();
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
CompositableHost* GetCompositableHost() const
{
return mHost;
}
void SetCompositableHost(CompositableHost* aHost)
{
mHost = aHost;
}
CompositableType GetType() const
{
return mType;
}
CompositableParentManager* GetCompositableManager() const
{
return mManager;
}
void SetCompositorID(uint64_t aCompositorID)
{
mCompositorID = aCompositorID;
}
uint64_t GetCompositorID() const
{
return mCompositorID;
}
private:
RefPtr<CompositableHost> mHost;
CompositableParentManager* mManager;
CompositableType mType;
uint64_t mID;
uint64_t mCompositorID;
};
/** /**
* Global CompositableMap, to use in the compositor thread only. * Global CompositableMap, to use in the compositor thread only.
* *
@ -406,8 +368,8 @@ private:
namespace CompositableMap { namespace CompositableMap {
void Create(); void Create();
void Destroy(); void Destroy();
CompositableParent* Get(uint64_t aID); PCompositableParent* Get(uint64_t aID);
void Set(uint64_t aID, CompositableParent* aParent); void Set(uint64_t aID, PCompositableParent* aParent);
void Erase(uint64_t aID); void Erase(uint64_t aID);
void Clear(); void Clear();
} // CompositableMap } // CompositableMap

View File

@ -32,10 +32,10 @@ namespace layers {
class ClientTiledLayerBuffer; class ClientTiledLayerBuffer;
class Compositor; class Compositor;
template<typename T> template<typename Op>
CompositableHost* AsCompositable(const T& op) CompositableHost* AsCompositable(const Op& op)
{ {
return static_cast<CompositableParent*>(op.compositableParent())->GetCompositableHost(); return CompositableHost::FromIPDLActor(op.compositableParent());
} }
// This function can in some cases fail and return false without it being a bug. // This function can in some cases fail and return false without it being a bug.
@ -52,12 +52,12 @@ CompositableHost* AsCompositable(const T& op)
template<typename T> template<typename T>
bool ScheduleComposition(const T& op) bool ScheduleComposition(const T& op)
{ {
CompositableParent* comp = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* comp = AsCompositable(op);
if (!comp || !comp->GetCompositorID()) { uint64_t id = comp->GetCompositorID();
if (!comp || !id) {
return false; return false;
} }
CompositorParent* cp CompositorParent* cp = CompositorParent::GetCompositor(id);
= CompositorParent::GetCompositor(comp->GetCompositorID());
if (!cp) { if (!cp) {
return false; return false;
} }
@ -73,13 +73,10 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
case CompositableOperation::TOpCreatedIncrementalTexture: { case CompositableOperation::TOpCreatedIncrementalTexture: {
MOZ_LAYERS_LOG(("[ParentSide] Created texture")); MOZ_LAYERS_LOG(("[ParentSide] Created texture"));
const OpCreatedIncrementalTexture& op = aEdit.get_OpCreatedIncrementalTexture(); const OpCreatedIncrementalTexture& op = aEdit.get_OpCreatedIncrementalTexture();
CompositableHost* compositable = AsCompositable(op);
CompositableParent* compositableParent =
static_cast<CompositableParent*>(op.compositableParent());
CompositableHost* compositable = compositableParent->GetCompositableHost();
bool success = bool success =
compositable->CreatedIncrementalTexture(compositableParent->GetCompositableManager(), compositable->CreatedIncrementalTexture(this,
op.textureInfo(), op.textureInfo(),
op.bufferRect()); op.bufferRect());
if (!success) { if (!success) {
@ -91,9 +88,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer"));
const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion();
CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = AsCompositable(op);
CompositableHost* compositable =
compositableParent->GetCompositableHost();
Layer* layer = compositable->GetLayer(); Layer* layer = compositable->GetLayer();
if (!layer || layer->GetType() != Layer::TYPE_THEBES) { if (!layer || layer->GetType() != Layer::TYPE_THEBES) {
return false; return false;
@ -113,7 +108,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
return false; return false;
} }
replyv.push_back( replyv.push_back(
OpContentBufferSwap(compositableParent, nullptr, frontUpdatedRegion)); OpContentBufferSwap(op.compositableParent(), nullptr, frontUpdatedRegion));
RenderTraceInvalidateEnd(thebes, "FF00FF"); RenderTraceInvalidateEnd(thebes, "FF00FF");
// return texure data to client if necessary // return texure data to client if necessary
@ -125,9 +120,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
const OpPaintTextureIncremental& op = aEdit.get_OpPaintTextureIncremental(); const OpPaintTextureIncremental& op = aEdit.get_OpPaintTextureIncremental();
CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = AsCompositable(op);
CompositableHost* compositable =
compositableParent->GetCompositableHost();
SurfaceDescriptor desc = op.image(); SurfaceDescriptor desc = op.image();
@ -140,8 +133,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
} }
case CompositableOperation::TOpUpdatePictureRect: { case CompositableOperation::TOpUpdatePictureRect: {
const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect(); const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect();
CompositableHost* compositable CompositableHost* compositable = AsCompositable(op);
= static_cast<CompositableParent*>(op.compositableParent())->GetCompositableHost();
MOZ_ASSERT(compositable); MOZ_ASSERT(compositable);
compositable->SetPictureRect(op.picture()); compositable->SetPictureRect(op.picture());
break; break;
@ -149,9 +141,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
case CompositableOperation::TOpUseTiledLayerBuffer: { case CompositableOperation::TOpUseTiledLayerBuffer: {
MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer"));
const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer(); const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer();
CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = AsCompositable(op);
CompositableHost* compositable =
compositableParent->GetCompositableHost();
TiledLayerComposer* tileComposer = compositable->AsTiledLayerComposer(); TiledLayerComposer* tileComposer = compositable->AsTiledLayerComposer();
NS_ASSERTION(tileComposer, "compositable is not a tile composer"); NS_ASSERTION(tileComposer, "compositable is not a tile composer");

View File

@ -193,13 +193,12 @@ ImageBridgeParent::AllocPCompositableParent(const TextureInfo& aInfo,
{ {
uint64_t id = GenImageContainerID(); uint64_t id = GenImageContainerID();
*aID = id; *aID = id;
return new CompositableParent(this, aInfo, id); return CompositableHost::CreateIPDLActor(this, aInfo, id);
} }
bool ImageBridgeParent::DeallocPCompositableParent(PCompositableParent* aActor) bool ImageBridgeParent::DeallocPCompositableParent(PCompositableParent* aActor)
{ {
delete aActor; return CompositableHost::DestroyIPDLActor(aActor);
return true;
} }
PTextureParent* PTextureParent*

View File

@ -60,13 +60,6 @@ cast(const PLayerParent* in)
static_cast<const ShadowLayerParent*>(in)); static_cast<const ShadowLayerParent*>(in));
} }
static CompositableParent*
cast(const PCompositableParent* in)
{
return const_cast<CompositableParent*>(
static_cast<const CompositableParent*>(in));
}
template<class OpCreateT> template<class OpCreateT>
static ShadowLayerParent* static ShadowLayerParent*
AsLayerComposite(const OpCreateT& op) AsLayerComposite(const OpCreateT& op)
@ -508,24 +501,26 @@ LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset,
} }
case Edit::TOpAttachCompositable: { case Edit::TOpAttachCompositable: {
const OpAttachCompositable& op = edit.get_OpAttachCompositable(); const OpAttachCompositable& op = edit.get_OpAttachCompositable();
if (!Attach(cast(op.layerParent()), cast(op.compositableParent()), false)) { CompositableHost* host = CompositableHost::FromIPDLActor(op.compositableParent());
if (!Attach(cast(op.layerParent()), host, false)) {
return false; return false;
} }
cast(op.compositableParent())->SetCompositorID( host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID());
mLayerManager->GetCompositor()->GetCompositorID());
break; break;
} }
case Edit::TOpAttachAsyncCompositable: { case Edit::TOpAttachAsyncCompositable: {
const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable();
CompositableParent* compositableParent = CompositableMap::Get(op.containerID()); PCompositableParent* compositableParent = CompositableMap::Get(op.containerID());
if (!compositableParent) { if (!compositableParent) {
NS_ERROR("CompositableParent not found in the map"); NS_ERROR("CompositableParent not found in the map");
return false; return false;
} }
if (!Attach(cast(op.layerParent()), compositableParent, true)) { CompositableHost* host = CompositableHost::FromIPDLActor(compositableParent);
if (!Attach(cast(op.layerParent()), host, true)) {
return false; return false;
} }
compositableParent->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID());
host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID());
break; break;
} }
default: default:
@ -694,9 +689,13 @@ LayerTransactionParent::RecvSetAsyncScrollOffset(PLayerParent* aLayer,
bool bool
LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent,
CompositableParent* aCompositable, CompositableHost* aCompositable,
bool aIsAsyncVideo) bool aIsAsync)
{ {
if (!aCompositable) {
return false;
}
Layer* baselayer = aLayerParent->AsLayer(); Layer* baselayer = aLayerParent->AsLayer();
if (!baselayer) { if (!baselayer) {
return false; return false;
@ -709,21 +708,16 @@ LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent,
Compositor* compositor Compositor* compositor
= static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor(); = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor();
CompositableHost* compositable = aCompositable->GetCompositableHost(); if (!layer->SetCompositableHost(aCompositable)) {
if (!compositable) {
return false;
}
if (!layer->SetCompositableHost(compositable)) {
// not all layer types accept a compositable, see bug 967824 // not all layer types accept a compositable, see bug 967824
return false; return false;
} }
compositable->Attach(aLayerParent->AsLayer(), aCompositable->Attach(aLayerParent->AsLayer(),
compositor, compositor,
aIsAsyncVideo aIsAsync
? CompositableHost::ALLOW_REATTACH ? CompositableHost::ALLOW_REATTACH
| CompositableHost::KEEP_ATTACHED | CompositableHost::KEEP_ATTACHED
: CompositableHost::NO_FLAGS); : CompositableHost::NO_FLAGS);
return true; return true;
} }
@ -789,14 +783,13 @@ LayerTransactionParent::DeallocPLayerParent(PLayerParent* actor)
PCompositableParent* PCompositableParent*
LayerTransactionParent::AllocPCompositableParent(const TextureInfo& aInfo) LayerTransactionParent::AllocPCompositableParent(const TextureInfo& aInfo)
{ {
return new CompositableParent(this, aInfo); return CompositableHost::CreateIPDLActor(this, aInfo, 0);
} }
bool bool
LayerTransactionParent::DeallocPCompositableParent(PCompositableParent* actor) LayerTransactionParent::DeallocPCompositableParent(PCompositableParent* aActor)
{ {
delete actor; return CompositableHost::DestroyIPDLActor(aActor);
return true;
} }
PTextureParent* PTextureParent*

View File

@ -121,7 +121,7 @@ protected:
virtual bool DeallocPTextureParent(PTextureParent* actor) MOZ_OVERRIDE; virtual bool DeallocPTextureParent(PTextureParent* actor) MOZ_OVERRIDE;
bool Attach(ShadowLayerParent* aLayerParent, bool Attach(ShadowLayerParent* aLayerParent,
CompositableParent* aCompositable, CompositableHost* aCompositable,
bool aIsAsyncVideo); bool aIsAsyncVideo);
void AddIPDLReference() { void AddIPDLReference() {