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 e20d3733a4
commit 60377d7d5a
6 changed files with 130 additions and 152 deletions

View File

@ -22,8 +22,49 @@ namespace layers {
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)
: mTextureInfo(aTextureInfo)
, mAsyncID(0)
, mCompositorID(0)
, mCompositor(nullptr)
, mLayer(nullptr)
, 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
CompositableHost::UseTextureHost(TextureHost* aTexture)
{
@ -171,43 +234,14 @@ CompositableHost::DumpTextureHost(FILE* aFile, TextureHost* aTexture)
}
#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 {
typedef std::map<uint64_t, CompositableParent*> CompositableMap_t;
typedef std::map<uint64_t, PCompositableParent*> CompositableMap_t;
static CompositableMap_t* sCompositableMap = nullptr;
bool IsCreated() {
return sCompositableMap != nullptr;
}
CompositableParent* Get(uint64_t aID)
PCompositableParent* Get(uint64_t aID)
{
if (!IsCreated() || aID == 0) {
return nullptr;
@ -218,7 +252,7 @@ CompositableParent* Get(uint64_t aID)
}
return it->second;
}
void Set(uint64_t aID, CompositableParent* aParent)
void Set(uint64_t aID, PCompositableParent* aParent)
{
if (!IsCreated() || aID == 0) {
return;

View File

@ -51,6 +51,7 @@ class Compositor;
class ISurfaceAllocator;
class ThebesBufferData;
class TiledLayerComposer;
class CompositableParentManager;
struct EffectChain;
/**
@ -307,8 +308,28 @@ public:
mFlashCounter = mFlashCounter >= DIAGNOSTIC_FLASH_COUNTER_MAX
? 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:
TextureInfo mTextureInfo;
uint64_t mAsyncID;
uint64_t mCompositorID;
Compositor* mCompositor;
Layer* mLayer;
RefPtr<CompositableBackendSpecificData> mBackendData;
@ -317,65 +338,6 @@ protected:
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.
*
@ -406,8 +368,8 @@ private:
namespace CompositableMap {
void Create();
void Destroy();
CompositableParent* Get(uint64_t aID);
void Set(uint64_t aID, CompositableParent* aParent);
PCompositableParent* Get(uint64_t aID);
void Set(uint64_t aID, PCompositableParent* aParent);
void Erase(uint64_t aID);
void Clear();
} // CompositableMap

View File

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

View File

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

View File

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

View File

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