Backed out 17 changesets (bug 897452) for OSX crashes on a CLOSED TREE.

Backed out changeset 11ad8608bc27 (bug 897452)
Backed out changeset 6bcc629e76f9 (bug 897452)
Backed out changeset b91c858a43f5 (bug 897452)
Backed out changeset 38ba49ee3e97 (bug 897452)
Backed out changeset ea184ef84762 (bug 897452)
Backed out changeset 686cc5122149 (bug 897452)
Backed out changeset 3685a8018e49 (bug 897452)
Backed out changeset be7ef6240068 (bug 897452)
Backed out changeset f95c20e70947 (bug 897452)
Backed out changeset 4a370d2a1c62 (bug 897452)
Backed out changeset 1222f6ab66d2 (bug 897452)
Backed out changeset 5e9d3c681ee9 (bug 897452)
Backed out changeset 3b9ddce12b7a (bug 897452)
Backed out changeset 7aec6387f3e9 (bug 897452)
Backed out changeset eb1fe464fdaf (bug 897452)
Backed out changeset 07deaa53b6fd (bug 897452)
Backed out changeset ddab7d071d69 (bug 897452)
This commit is contained in:
Ryan VanderMeulen 2013-12-11 14:52:50 -05:00
parent d4a4ea56aa
commit 469134ec10
52 changed files with 937 additions and 794 deletions

View File

@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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_ATOMICREFCOUNTEDWITHFINALIZE_H_
#define MOZILLA_ATOMICREFCOUNTEDWITHFINALIZE_H_
#include "mozilla/RefPtr.h"
namespace mozilla {
template<typename T>
class AtomicRefCountedWithFinalize
{
protected:
AtomicRefCountedWithFinalize()
: mRefCount(0)
{}
~AtomicRefCountedWithFinalize() {}
public:
void AddRef() {
MOZ_ASSERT(mRefCount >= 0);
++mRefCount;
}
void Release() {
MOZ_ASSERT(mRefCount > 0);
if (0 == --mRefCount) {
#ifdef DEBUG
mRefCount = detail::DEAD;
#endif
static_cast<T*>(this)->Finalize();
delete this;
}
}
private:
Atomic<int> mRefCount;
};
}
#endif

View File

@ -217,7 +217,6 @@ ImageContainer::ClearAllImages()
ImageBridgeChild::FlushAllImages(mImageClient, this, false);
return;
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
SetCurrentImageInternal(nullptr);
}

View File

@ -35,10 +35,11 @@ MacIOSurfaceTextureSourceBasic::GetFormat() const
}
MacIOSurfaceTextureHostBasic::MacIOSurfaceTextureHostBasic(
uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor
)
: TextureHost(aFlags)
: TextureHost(aID, aFlags)
{
mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
aDescriptor.scaleFactor(),

View File

@ -56,8 +56,9 @@ protected:
class MacIOSurfaceTextureHostBasic : public TextureHost
{
public:
MacIOSurfaceTextureHostBasic(TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor);
MacIOSurfaceTextureHostBasic(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor);
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;

View File

@ -13,7 +13,8 @@ namespace mozilla {
namespace layers {
TemporaryRef<TextureHost>
CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
CreateTextureHostBasic(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
{
@ -23,12 +24,12 @@ CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
const SurfaceDescriptorMacIOSurface& desc =
aDesc.get_SurfaceDescriptorMacIOSurface();
result = new MacIOSurfaceTextureHostBasic(aFlags, desc);
result = new MacIOSurfaceTextureHostBasic(aID, aFlags, desc);
break;
}
#endif
default: {
result = CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
result = CreateBackendIndependentTextureHost(aID, aDesc, aDeallocator, aFlags);
break;
}
}

View File

@ -58,7 +58,7 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
{
if (mBuffer &&
(mBuffer->IsImmutable() || mBuffer->GetSize() != aSize)) {
mBuffer->ForceRemove();
RemoveTextureClient(mBuffer);
mBuffer = nullptr;
}
@ -106,6 +106,14 @@ CanvasClient2D::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFla
mTextureInfo.mTextureFlags | aFlags);
}
void
CanvasClient2D::OnActorDestroy()
{
if (mBuffer) {
mBuffer->OnActorDestroy();
}
}
void
DeprecatedCanvasClient2D::Updated()
{
@ -157,6 +165,14 @@ DeprecatedCanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
mDeprecatedTextureClient->Unlock();
}
void
DeprecatedCanvasClient2D::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
}
void
DeprecatedCanvasClientSurfaceStream::Updated()
{
@ -225,5 +241,13 @@ DeprecatedCanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLaye
aLayer->Painted();
}
void
DeprecatedCanvasClientSurfaceStream::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
}
}
}

View File

@ -91,6 +91,8 @@ public:
mBuffer = nullptr;
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<TextureClient> mBuffer;
};
@ -115,6 +117,8 @@ public:
mDeprecatedTextureClient->SetDescriptorFromReply(aDescriptor);
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
};
@ -141,6 +145,8 @@ public:
mDeprecatedTextureClient->SetDescriptorFromReply(aDescriptor);
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
};

View File

@ -368,6 +368,17 @@ ClientLayerManager::ForwardTransaction()
->SetDescriptorFromReply(ots.textureId(), ots.image());
break;
}
case EditReply::TReplyTextureRemoved: {
// XXX - to manage reuse of gralloc buffers, we'll need to add some
// glue code here to find the TextureClient and invoke a callback to
// let the camera know that the gralloc buffer is not used anymore on
// the compositor side and that it can reuse it.
const ReplyTextureRemoved& rep = reply.get_ReplyTextureRemoved();
CompositableClient* compositable
= static_cast<CompositableChild*>(rep.compositableChild())->GetCompositableClient();
compositable->OnReplyTextureRemoved(rep.textureId());
break;
}
default:
NS_RUNTIMEABORT("not reached");

View File

@ -24,7 +24,8 @@ namespace mozilla {
namespace layers {
CompositableClient::CompositableClient(CompositableForwarder* aForwarder)
: mCompositableChild(nullptr)
: mNextTextureID(1)
, mCompositableChild(nullptr)
, mForwarder(aForwarder)
{
MOZ_COUNT_CTOR(CompositableClient);
@ -35,6 +36,23 @@ CompositableClient::~CompositableClient()
{
MOZ_COUNT_DTOR(CompositableClient);
Destroy();
FlushTexturesToRemoveCallbacks();
MOZ_ASSERT(mTexturesToRemove.Length() == 0, "would leak textures pending for deletion");
}
void
CompositableClient::FlushTexturesToRemoveCallbacks()
{
std::map<uint64_t,TextureClientData*>::iterator it
= mTexturesToRemoveCallbacks.begin();
std::map<uint64_t,TextureClientData*>::iterator stop
= mTexturesToRemoveCallbacks.end();
for (; it != stop; ++it) {
it->second->DeallocateSharedData(GetForwarder());
delete it->second;
}
mTexturesToRemoveCallbacks.clear();
}
LayersBackend
@ -233,16 +251,70 @@ CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat,
return result;
}
uint64_t
CompositableClient::NextTextureID()
{
++mNextTextureID;
// 0 is always an invalid ID
if (mNextTextureID == 0) {
++mNextTextureID;
}
return mNextTextureID;
}
bool
CompositableClient::AddTextureClient(TextureClient* aClient)
{
return aClient->InitIPDLActor(mForwarder);
aClient->SetID(NextTextureID());
return mForwarder->AddTexture(this, aClient);
}
void
CompositableClient::RemoveTextureClient(TextureClient* aClient)
{
MOZ_ASSERT(aClient);
mTexturesToRemove.AppendElement(TextureIDAndFlags(aClient->GetID(),
aClient->GetFlags()));
if (aClient->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) {
TextureClientData* data = aClient->DropTextureData();
if (data) {
mTexturesToRemoveCallbacks[aClient->GetID()] = data;
}
}
aClient->ClearID();
aClient->MarkInvalid();
}
void
CompositableClient::OnReplyTextureRemoved(uint64_t aTextureID)
{
std::map<uint64_t,TextureClientData*>::iterator it
= mTexturesToRemoveCallbacks.find(aTextureID);
if (it != mTexturesToRemoveCallbacks.end()) {
it->second->DeallocateSharedData(GetForwarder());
delete it->second;
mTexturesToRemoveCallbacks.erase(it);
}
}
void
CompositableClient::OnTransaction()
{
for (unsigned i = 0; i < mTexturesToRemove.Length(); ++i) {
const TextureIDAndFlags& texture = mTexturesToRemove[i];
mForwarder->RemoveTexture(this, texture.mID, texture.mFlags);
}
mTexturesToRemove.Clear();
}
void
CompositableChild::ActorDestroy(ActorDestroyReason why)
{
if (mCompositableClient && why == AbnormalShutdown) {
mCompositableClient->OnActorDestroy();
}
}
} // namespace layers
} // namespace mozilla

View File

@ -132,6 +132,12 @@ public:
*/
virtual bool AddTextureClient(TextureClient* aClient);
/**
* Tells the Compositor to delete the TextureHost corresponding to this
* TextureClient.
*/
virtual void RemoveTextureClient(TextureClient* aClient);
/**
* A hook for the Compositable to execute whatever it held off for next transaction.
*/
@ -142,11 +148,47 @@ public:
*/
virtual void OnDetach() {}
/**
* When texture deallocation must happen on the client side, we need to first
* ensure that the compositor has already let go of the data in order
* to safely deallocate it.
*
* This is implemented by registering a callback to postpone deallocation or
* recycling of the shared data.
*
* This hook is called when the compositor notifies the client that it is not
* holding any more references to the shared data so that this compositable
* can run the corresponding callback.
*/
void OnReplyTextureRemoved(uint64_t aTextureID);
/**
* Run all he registered callbacks (see the comment for OnReplyTextureRemoved).
* Only call this if you know what you are doing.
*/
void FlushTexturesToRemoveCallbacks();
/**
* Our IPDL actor is being destroyed, get rid of any shmem resources now.
*/
virtual void OnActorDestroy() = 0;
protected:
// return the next texture ID
uint64_t NextTextureID();
struct TextureIDAndFlags {
TextureIDAndFlags(uint64_t aID, TextureFlags aFlags)
: mID(aID), mFlags(aFlags) {}
uint64_t mID;
TextureFlags mFlags;
};
// The textures to destroy in the next transaction;
nsTArray<TextureIDAndFlags> mTexturesToRemove;
std::map<uint64_t, TextureClientData*> mTexturesToRemoveCallbacks;
uint64_t mNextTextureID;
CompositableChild* mCompositableChild;
CompositableForwarder* mForwarder;
friend class CompositableChild;
};
/**
@ -180,11 +222,7 @@ public:
return mCompositableClient;
}
virtual void ActorDestroy(ActorDestroyReason) MOZ_OVERRIDE {
if (mCompositableClient) {
mCompositableClient->mCompositableChild = nullptr;
}
}
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
void SetAsyncID(uint64_t aID) { mID = aID; }
uint64_t GetAsyncID() const

View File

@ -148,6 +148,9 @@ ContentClientRemoteBuffer::EndPaint()
// decided we didn't need one yet because the region to draw was empty.
SetBufferProvider(nullptr);
SetBufferProviderOnWhite(nullptr);
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
RemoveTextureClient(mOldTextures[i]);
}
mOldTextures.Clear();
if (mTextureClient) {
@ -295,6 +298,20 @@ ContentClientRemoteBuffer::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion)
mFrontAndBackBufferDiffer = true;
}
void
ContentClientRemoteBuffer::OnActorDestroy()
{
if (mTextureClient) {
mTextureClient->OnActorDestroy();
}
if (mTextureClientOnWhite) {
mTextureClientOnWhite->OnActorDestroy();
}
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
mOldTextures[i]->OnActorDestroy();
}
}
void
DeprecatedContentClientRemoteBuffer::DestroyBuffers()
{
@ -480,6 +497,21 @@ DeprecatedContentClientRemoteBuffer::SwapBuffers(const nsIntRegion& aFrontUpdate
}
}
void
DeprecatedContentClientRemoteBuffer::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
if (mDeprecatedTextureClientOnWhite) {
mDeprecatedTextureClientOnWhite->OnActorDestroy();
}
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
mOldTextures[i]->OnActorDestroy();
}
}
void
ContentClientDoubleBuffered::CreateFrontBuffer(const nsIntRect& aBufferRect)
{
@ -634,6 +666,26 @@ ContentClientDoubleBuffered::UpdateDestinationFrom(const RotatedBuffer& aSource,
}
}
void
ContentClientDoubleBuffered::OnActorDestroy()
{
if (mTextureClient) {
mTextureClient->OnActorDestroy();
}
if (mTextureClientOnWhite) {
mTextureClientOnWhite->OnActorDestroy();
}
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
mOldTextures[i]->OnActorDestroy();
}
if (mFrontClient) {
mFrontClient->OnActorDestroy();
}
if (mFrontClientOnWhite) {
mFrontClientOnWhite->OnActorDestroy();
}
}
DeprecatedContentClientDoubleBuffered::~DeprecatedContentClientDoubleBuffered()
{
if (mDeprecatedTextureClient) {
@ -734,6 +786,26 @@ DeprecatedContentClientDoubleBuffered::SwapBuffers(const nsIntRegion& aFrontUpda
DeprecatedContentClientRemoteBuffer::SwapBuffers(aFrontUpdatedRegion);
}
void
DeprecatedContentClientDoubleBuffered::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
if (mDeprecatedTextureClientOnWhite) {
mDeprecatedTextureClientOnWhite->OnActorDestroy();
}
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
mOldTextures[i]->OnActorDestroy();
}
if (mFrontClient) {
mFrontClient->OnActorDestroy();
}
if (mFrontClientOnWhite) {
mFrontClientOnWhite->OnActorDestroy();
}
}
struct AutoDeprecatedTextureClient {
AutoDeprecatedTextureClient()
: mTexture(nullptr)

View File

@ -159,6 +159,8 @@ public:
{
MOZ_CRASH("Should not be called on non-remote ContentClient");
}
virtual void OnActorDestroy() MOZ_OVERRIDE {}
};
/**
@ -236,6 +238,8 @@ public:
return mTextureInfo;
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
void DestroyBuffers();
@ -336,6 +340,8 @@ public:
return mTextureInfo;
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
void DestroyBuffers();
@ -396,6 +402,8 @@ public:
virtual void SyncFrontBufferToBackBuffer() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
virtual void CreateFrontBuffer(const nsIntRect& aBufferRect) MOZ_OVERRIDE;
virtual void DestroyFrontBuffer() MOZ_OVERRIDE;
@ -433,6 +441,8 @@ public:
virtual void SyncFrontBufferToBackBuffer() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
virtual void CreateFrontBufferAndNotify(const nsIntRect& aBufferRect) MOZ_OVERRIDE;
virtual void DestroyFrontBuffer() MOZ_OVERRIDE;
@ -539,6 +549,8 @@ public:
}
}
virtual void OnActorDestroy() MOZ_OVERRIDE {}
private:
enum BufferType{

View File

@ -101,7 +101,7 @@ void
ImageClientSingle::FlushAllImages(bool aExceptFront)
{
if (!aExceptFront && mFrontBuffer) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
}
@ -110,11 +110,11 @@ void
ImageClientBuffered::FlushAllImages(bool aExceptFront)
{
if (!aExceptFront && mFrontBuffer) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
if (mBackBuffer) {
mBackBuffer->ForceRemove();
RemoveTextureClient(mBackBuffer);
mBackBuffer = nullptr;
}
}
@ -145,7 +145,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
}
if (mFrontBuffer) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
}
mFrontBuffer = texture;
if (!AddTextureClient(texture)) {
@ -162,7 +162,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
}
if (mFrontBuffer && mFrontBuffer->IsImmutable()) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
@ -205,7 +205,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
if (mFrontBuffer) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
@ -226,7 +226,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
if (mFrontBuffer &&
(mFrontBuffer->IsImmutable() || mFrontBuffer->GetSize() != size)) {
mFrontBuffer->ForceRemove();
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
@ -280,6 +280,25 @@ ImageClientBuffered::UpdateImage(ImageContainer* aContainer,
return ImageClientSingle::UpdateImage(aContainer, aContentFlags);
}
void
ImageClientSingle::OnActorDestroy()
{
if (mFrontBuffer) {
mFrontBuffer->OnActorDestroy();
}
}
void
ImageClientBuffered::OnActorDestroy()
{
if (mFrontBuffer) {
mFrontBuffer->OnActorDestroy();
}
if (mBackBuffer) {
mBackBuffer->OnActorDestroy();
}
}
bool
ImageClientSingle::AddTextureClient(TextureClient* aTexture)
{
@ -465,6 +484,14 @@ ImageClientBridge::ImageClientBridge(CompositableForwarder* aFwd,
{
}
void
DeprecatedImageClientSingle::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
}
bool
ImageClientBridge::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags)
{

View File

@ -102,6 +102,8 @@ public:
virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
RefPtr<TextureClient> mFrontBuffer;
// Some layers may want to enforce some flags to all their textures
@ -125,6 +127,8 @@ public:
virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
RefPtr<TextureClient> mBackBuffer;
};
@ -169,6 +173,8 @@ public:
virtual already_AddRefed<Image> CreateImage(const uint32_t *aFormats,
uint32_t aNumFormats) MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
TextureInfo mTextureInfo;
@ -210,6 +216,8 @@ public:
return nullptr;
}
virtual void OnActorDestroy() MOZ_OVERRIDE {}
protected:
uint64_t mAsyncContainerID;
ShadowableLayer* mLayer;

View File

@ -19,7 +19,6 @@
#include "mozilla/layers/ShadowLayers.h" // for ShadowLayerForwarder
#include "mozilla/layers/SharedPlanarYCbCrImage.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "mozilla/layers/PTextureChild.h"
#include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
#include "ImageContainer.h" // for PlanarYCbCrImage, etc
@ -39,126 +38,6 @@ using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
/**
* TextureChild is the content-side incarnation of the PTexture IPDL actor.
*
* TextureChild is used to synchronize a texture client and its corresponding
* TextureHost if needed (a TextureClient that is not shared with the compositor
* does not have a TextureChild)
*
* During the deallocation phase, a TextureChild may hold its recently destroyed
* TextureClient's data until the compositor side confirmed that it is safe to
* deallocte or recycle the it.
*/
class TextureChild : public PTextureChild
{
public:
TextureChild()
: mForwarder(nullptr)
, mTextureData(nullptr)
, mTextureClient(nullptr)
{
MOZ_COUNT_CTOR(TextureChild);
}
~TextureChild()
{
MOZ_COUNT_DTOR(TextureChild);
}
bool Recv__delete__() MOZ_OVERRIDE;
/**
* Only used during the deallocation phase iff we need synchronization between
* the client and host side for deallocation (that is, when the data is going
* to be deallocated or recycled on the client side).
*/
void SetTextureData(TextureClientData* aData)
{
mTextureData = aData;
}
void DeleteTextureData();
CompositableForwarder* GetForwarder() { return mForwarder; }
ISurfaceAllocator* GetAllocator() { return mForwarder; }
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
private:
CompositableForwarder* mForwarder;
TextureClientData* mTextureData;
TextureClient* mTextureClient;
friend class TextureClient;
};
void
TextureChild::DeleteTextureData()
{
if (mTextureData) {
mTextureData->DeallocateSharedData(GetAllocator());
delete mTextureData;
mTextureData = nullptr;
}
}
bool
TextureChild::Recv__delete__()
{
DeleteTextureData();
return true;
}
void
TextureChild::ActorDestroy(ActorDestroyReason why)
{
if (mTextureClient) {
mTextureClient->mActor = nullptr;
}
}
// static
PTextureChild*
TextureClient::CreateIPDLActor()
{
return new TextureChild();
}
// static
bool
TextureClient::DestroyIPDLActor(PTextureChild* actor)
{
delete actor;
return true;
}
bool
TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
{
MOZ_ASSERT(!mActor);
MOZ_ASSERT(aForwarder);
SurfaceDescriptor desc;
if (!ToSurfaceDescriptor(desc)) {
return false;
}
mActor = static_cast<TextureChild*>(aForwarder->CreateEmptyTextureChild());
mActor->mForwarder = aForwarder;
mActor->mTextureClient = this;
mShared = true;
return mActor->SendInit(desc, GetFlags());
}
PTextureChild*
TextureClient::GetIPDLActor()
{
return mActor;
}
class ShmemTextureClientData : public TextureClientData
{
public:
@ -201,7 +80,6 @@ public:
virtual void DeallocateSharedData(ISurfaceAllocator*)
{
delete[] mBuffer;
mBuffer = nullptr;
}
private:
@ -233,43 +111,14 @@ ShmemTextureClient::DropTextureData()
}
TextureClient::TextureClient(TextureFlags aFlags)
: mActor(nullptr)
: mID(0)
, mFlags(aFlags)
, mShared(false)
, mValid(true)
{}
TextureClient::~TextureClient()
{
// All the destruction code that may lead to virtual method calls must
// be in Finalize() which is called just before the destructor.
}
void TextureClient::ForceRemove()
{
if (mValid && mActor) {
if (GetFlags() & TEXTURE_DEALLOCATE_CLIENT) {
mActor->SetTextureData(DropTextureData());
mActor->SendRemoveTextureSync();
mActor->DeleteTextureData();
} else {
mActor->SendRemoveTexture();
}
}
MarkInvalid();
}
void
TextureClient::Finalize()
{
if (mActor) {
// this will call ForceRemove in the right thread, using a sync proxy if needed
mActor->GetForwarder()->RemoveTexture(this);
// mActor has a raw pointer to us, mActor->mTextureClient. Null it before we die.
mActor->mTextureClient = nullptr;
}
}
{}
bool
TextureClient::ShouldDeallocateInDestructor() const
@ -388,8 +237,8 @@ MemoryTextureClient::MemoryTextureClient(CompositableClient* aCompositable,
MemoryTextureClient::~MemoryTextureClient()
{
MOZ_COUNT_DTOR(MemoryTextureClient);
if (mBuffer && ShouldDeallocateInDestructor()) {
// if the buffer has never been shared we must deallocate it or it would
if (ShouldDeallocateInDestructor() && mBuffer) {
// if the buffer has never been shared we must deallocate it or ir would
// leak.
GfxMemoryImageReporter::WillFree(mBuffer);
delete mBuffer;
@ -564,6 +413,15 @@ DeprecatedTextureClient::~DeprecatedTextureClient()
MOZ_ASSERT(mDescriptor.type() == SurfaceDescriptor::T__None, "Need to release surface!");
}
void
DeprecatedTextureClient::OnActorDestroy()
{
if (ISurfaceAllocator::IsShmem(&mDescriptor)) {
mDescriptor = SurfaceDescriptor();
}
}
DeprecatedTextureClientShmem::DeprecatedTextureClientShmem(CompositableForwarder* aForwarder,
const TextureInfo& aTextureInfo)
: DeprecatedTextureClient(aForwarder, aTextureInfo)

View File

@ -24,7 +24,6 @@
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsISupportsImpl.h" // for TextureImage::AddRef, etc
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
class gfxReusableSurfaceWrapper;
class gfxASurface;
@ -40,8 +39,6 @@ class CompositableClient;
class PlanarYCbCrImage;
class PlanarYCbCrData;
class Image;
class PTextureChild;
class TextureChild;
/**
* TextureClient is the abstraction that allows us to share data between the
@ -114,13 +111,14 @@ public:
* host side, there is nothing to do.
* On the other hand, if the client data must be deallocated on the client
* side, the CompositableClient will ask the TextureClient to drop its shared
* data in the form of a TextureClientData object. This data will be kept alive
* until the host side confirms that it is not using the data anymore and that
* it is completely safe to deallocate the shared data.
* data in the form of a TextureClientData object. The compositable will keep
* this object until it has received from the host side the confirmation that
* the compositor is not using the texture and that it is completely safe to
* deallocate the shared data.
*
* See:
* - The PTexture IPDL protocol
* - CompositableChild in TextureClient.cpp
* - CompositableClient::RemoveTextureClient
* - CompositableClient::OnReplyTextureRemoved
*/
class TextureClientData {
public:
@ -151,8 +149,7 @@ public:
* In order to send several different buffers to the compositor side, use
* several TextureClients.
*/
class TextureClient
: public AtomicRefCountedWithFinalize<TextureClient>
class TextureClient : public AtomicRefCounted<TextureClient>
{
public:
TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
@ -180,15 +177,28 @@ public:
virtual bool ImplementsLocking() const { return false; }
/**
* Allocate and deallocate a TextureChild actor.
* Sets this texture's ID.
*
* TextureChild is an implementation detail of TextureHost that is not
* exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
* are for use with the maging IPDL protocols only (so that they can
* implement AllocPextureChild and DeallocPTextureChild).
* This ID is used to match a texture client with his corresponding TextureHost.
* Only the CompositableClient should be allowed to set or clear the ID.
* Zero is always an invalid ID.
* For a given compositableClient, there can never be more than one texture
* client with the same non-zero ID.
* Texture clients from different compositables may have the same ID.
*/
static PTextureChild* CreateIPDLActor();
static bool DestroyIPDLActor(PTextureChild* actor);
void SetID(uint64_t aID)
{
MOZ_ASSERT(mID == 0 && aID != 0);
mID = aID;
mShared = true;
}
void ClearID()
{
MOZ_ASSERT(mID != 0);
mID = 0;
}
uint64_t GetID() const { return mID; }
virtual bool IsAllocated() const = 0;
@ -239,36 +249,9 @@ public:
*/
void MarkInvalid() { mValid = false; }
/**
* Create and init the TextureChild/Parent IPDL actor pair.
*
* Should be called only once per TextureClient.
*/
bool InitIPDLActor(CompositableForwarder* aForwarder);
/**
* Return a pointer to the IPDLActor.
*
* This is to be used with IPDL messages only. Do not store the returned
* pointer.
*/
PTextureChild* GetIPDLActor();
/**
* TODO[nical] doc!
*/
void ForceRemove();
private:
/**
* Called once, just before the destructor.
*
* Here goes the shut-down code that uses virtual methods.
* Must only be called by Release().
*/
void Finalize();
friend class AtomicRefCountedWithFinalize<TextureClient>;
// If a texture client holds a reference to shmem, it should override this
// method to forget about the shmem _without_ releasing it.
virtual void OnActorDestroy() {}
protected:
void AddFlags(TextureFlags aFlags)
@ -277,12 +260,10 @@ protected:
mFlags |= aFlags;
}
TextureChild* mActor;
uint64_t mID;
TextureFlags mFlags;
bool mShared;
bool mValid;
friend class TextureChild;
};
/**
@ -380,6 +361,11 @@ public:
ipc::Shmem& GetShmem() { return mShmem; }
virtual void OnActorDestroy() MOZ_OVERRIDE
{
mShmem = ipc::Shmem();
}
protected:
ipc::Shmem mShmem;
RefPtr<ISurfaceAllocator> mAllocator;
@ -556,6 +542,8 @@ public:
virtual gfxContentType GetContentType() = 0;
void OnActorDestroy();
protected:
DeprecatedTextureClient(CompositableForwarder* aForwarder,
const TextureInfo& aTextureInfo);

View File

@ -252,6 +252,14 @@ public:
static BasicTiledLayerBuffer OpenDescriptor(ISurfaceAllocator* aAllocator,
const SurfaceDescriptorTiles& aDescriptor);
void OnActorDestroy()
{
for (size_t i = 0; i < mRetainedTiles.Length(); i++) {
if (mRetainedTiles[i].IsPlaceholderTile()) continue;
mRetainedTiles[i].mDeprecatedTextureClient->OnActorDestroy();
}
}
protected:
BasicTiledLayerTile ValidateTile(BasicTiledLayerTile aTile,
const nsIntPoint& aTileRect,
@ -341,6 +349,12 @@ public:
};
void LockCopyAndWrite(TiledBufferType aType);
virtual void OnActorDestroy() MOZ_OVERRIDE
{
mTiledBuffer.OnActorDestroy();
mLowPrecisionTiledBuffer.OnActorDestroy();
}
private:
BasicTiledLayerBuffer mTiledBuffer;
BasicTiledLayerBuffer mLowPrecisionTiledBuffer;

View File

@ -36,22 +36,82 @@ CompositableHost::CompositableHost(const TextureInfo& aTextureInfo)
CompositableHost::~CompositableHost()
{
MOZ_COUNT_DTOR(CompositableHost);
RefPtr<TextureHost> it = mFirstTexture;
while (it) {
if (!(it->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)) {
it->DeallocateSharedData();
}
it = it->GetNextSibling();
}
}
void
CompositableHost::UseTextureHost(TextureHost* aTexture)
CompositableHost::AddTextureHost(TextureHost* aTexture)
{
if (!aTexture) {
return;
}
aTexture->SetCompositor(GetCompositor());
MOZ_ASSERT(aTexture);
MOZ_ASSERT(GetTextureHost(aTexture->GetID()) == nullptr,
"A texture is already present with this ID");
RefPtr<TextureHost> second = mFirstTexture;
mFirstTexture = aTexture;
aTexture->SetNextSibling(second);
aTexture->SetCompositableBackendSpecificData(GetCompositableBackendSpecificData());
}
void
CompositableHost::RemoveTextureHost(TextureHost* aTexture)
{
uint64_t textureID = aTexture->GetID();
if (mFirstTexture && mFirstTexture->GetID() == textureID) {
mFirstTexture = mFirstTexture->GetNextSibling();
aTexture->SetNextSibling(nullptr);
}
RefPtr<TextureHost> it = mFirstTexture;
while (it) {
if (it->GetNextSibling() &&
it->GetNextSibling()->GetID() == textureID) {
it->SetNextSibling(it->GetNextSibling()->GetNextSibling());
aTexture->SetNextSibling(nullptr);
}
it = it->GetNextSibling();
}
if (!mFirstTexture && mBackendData) {
mBackendData->ClearData();
}
}
TextureHost*
CompositableHost::GetTextureHost(uint64_t aTextureID)
{
RefPtr<TextureHost> it = mFirstTexture;
while (it) {
if (it->GetID() == aTextureID) {
return it;
}
it = it->GetNextSibling();
}
return nullptr;
}
void
CompositableHost::OnActorDestroy()
{
TextureHost* it = mFirstTexture;
while (it) {
it->OnActorDestroy();
it = it->GetNextSibling();
}
}
void
CompositableHost::SetCompositor(Compositor* aCompositor)
{
mCompositor = aCompositor;
RefPtr<TextureHost> it = mFirstTexture;
while (!!it) {
it->SetCompositor(aCompositor);
it = it->GetNextSibling();
}
}
bool
@ -204,6 +264,13 @@ void
CompositableParent::ActorDestroy(ActorDestroyReason why)
{
if (mHost) {
// XXX: sadness warning. We should be able to do this whenever we get ActorDestroy,
// not just for abnormal shutdowns (which is the only case we _need_ to - so that
// we don't double release our shmems). But, for some reason, that causes a
// crash, we don't know why. (Bug 925773).
if (why == AbnormalShutdown) {
mHost->OnActorDestroy();
}
mHost->Detach(nullptr, CompositableHost::FORCE_DETACH);
}
}

View File

@ -108,6 +108,12 @@ public:
mBackendData = aBackendData;
}
/**
* Our IPDL actor is being destroyed, get rid of any shmem resources now and
* don't worry about compositing anymore.
*/
virtual void OnActorDestroy();
// If base class overrides, it should still call the parent implementation
virtual void SetCompositor(Compositor* aCompositor);
@ -288,13 +294,23 @@ public:
virtual void PrintInfo(nsACString& aTo, const char* aPrefix) { }
virtual void UseTextureHost(TextureHost* aTexture);
void AddTextureHost(TextureHost* aTexture);
virtual void UseTextureHost(TextureHost* aTexture) {}
// If a texture host is flagged for deferred removal, the compositable will
// get an option to run any cleanup code early, that is when it would have
// been run if the texture host was not marked deferred.
// If the compositable does not cleanup the texture host now, it is the
// compositable's responsibility to cleanup the texture host before the
// texture host dies.
virtual void RemoveTextureHost(TextureHost* aTexture);
TextureHost* GetTextureHost(uint64_t aTextureID);
protected:
TextureInfo mTextureInfo;
Compositor* mCompositor;
Layer* mLayer;
RefPtr<CompositableBackendSpecificData> mBackendData;
RefPtr<TextureHost> mFirstTexture;
bool mAttached;
bool mKeepAttached;
};

View File

@ -32,6 +32,8 @@ ContentHostBase::ContentHostBase(const TextureInfo& aTextureInfo)
ContentHostBase::~ContentHostBase()
{
DestroyTextureHost();
DestroyTextureHostOnWhite();
}
TextureHost*
@ -40,6 +42,50 @@ ContentHostBase::GetAsTextureHost()
return mTextureHost;
}
void
ContentHostBase::DestroyTextureHost()
{
// The third clause in the if statement checks that we are in fact done with
// this texture. We don't want to prematurely deallocate a texture we might
// use again or double deallocate. Deallocation will happen in
// RemoveTextureHost.
// Note that GetTextureHost is linear in the number of texture hosts, but as
// long as that number is small (I expect a maximum of 6 for now) then it
// should be ok.
if (mTextureHost &&
mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED &&
!GetTextureHost(mTextureHost->GetID())) {
MOZ_ASSERT(!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_CLIENT));
mTextureHost->DeallocateSharedData();
}
mTextureHost = nullptr;
}
void
ContentHostBase::DestroyTextureHostOnWhite()
{
if (mTextureHostOnWhite &&
mTextureHostOnWhite->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED &&
!GetTextureHost(mTextureHostOnWhite->GetID())) {
MOZ_ASSERT(!(mTextureHostOnWhite->GetFlags() & TEXTURE_DEALLOCATE_CLIENT));
mTextureHostOnWhite->DeallocateSharedData();
}
mTextureHostOnWhite = nullptr;
}
void
ContentHostBase::RemoveTextureHost(TextureHost* aTexture)
{
if ((aTexture->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED) &&
!(mTextureHost && mTextureHost == aTexture) &&
!(mTextureHostOnWhite && mTextureHostOnWhite == aTexture)) {
MOZ_ASSERT(!(aTexture->GetFlags() & TEXTURE_DEALLOCATE_CLIENT));
aTexture->DeallocateSharedData();
}
CompositableHost::RemoveTextureHost(aTexture);
}
class MOZ_STACK_CLASS AutoLockTextureHost
{
public:
@ -240,10 +286,10 @@ void
ContentHostBase::UseTextureHost(TextureHost* aTexture)
{
if (aTexture->GetFlags() & TEXTURE_ON_WHITE) {
mTextureHost = nullptr;
DestroyTextureHost();
mTextureHostOnWhite = aTexture;
} else {
mTextureHostOnWhite = nullptr;
DestroyTextureHostOnWhite();
mTextureHost = aTexture;
}
}
@ -289,6 +335,18 @@ ContentHostBase::Dump(FILE* aFile,
}
#endif
void
ContentHostBase::OnActorDestroy()
{
if (mTextureHost) {
mTextureHost->OnActorDestroy();
}
if (mTextureHostOnWhite) {
mTextureHostOnWhite->OnActorDestroy();
}
CompositableHost::OnActorDestroy();
}
DeprecatedContentHostBase::DeprecatedContentHostBase(const TextureInfo& aTextureInfo)
: ContentHost(aTextureInfo)
, mPaintWillResample(false)
@ -315,6 +373,23 @@ DeprecatedContentHostBase::DestroyFrontHost()
mDeprecatedTextureHostOnWhite = nullptr;
}
void
DeprecatedContentHostBase::OnActorDestroy()
{
if (mDeprecatedTextureHost) {
mDeprecatedTextureHost->OnActorDestroy();
}
if (mDeprecatedTextureHostOnWhite) {
mDeprecatedTextureHostOnWhite->OnActorDestroy();
}
if (mNewFrontHost) {
mNewFrontHost->OnActorDestroy();
}
if (mNewFrontHostOnWhite) {
mNewFrontHostOnWhite->OnActorDestroy();
}
}
void
DeprecatedContentHostBase::Composite(EffectChain& aEffectChain,
float aOpacity,
@ -773,6 +848,29 @@ DeprecatedContentHostDoubleBuffered::DestroyTextures()
// don't touch mDeprecatedTextureHost, we might need it for compositing
}
void
DeprecatedContentHostDoubleBuffered::OnActorDestroy()
{
if (mDeprecatedTextureHost) {
mDeprecatedTextureHost->OnActorDestroy();
}
if (mDeprecatedTextureHostOnWhite) {
mDeprecatedTextureHostOnWhite->OnActorDestroy();
}
if (mNewFrontHost) {
mNewFrontHost->OnActorDestroy();
}
if (mNewFrontHostOnWhite) {
mNewFrontHostOnWhite->OnActorDestroy();
}
if (mBackHost) {
mBackHost->OnActorDestroy();
}
if (mBackHostOnWhite) {
mBackHostOnWhite->OnActorDestroy();
}
}
void
DeprecatedContentHostDoubleBuffered::UpdateThebes(const ThebesBufferData& aData,
const nsIntRegion& aUpdated,

View File

@ -117,8 +117,12 @@ public:
virtual void UseTextureHost(TextureHost* aTexture) MOZ_OVERRIDE;
virtual void RemoveTextureHost(TextureHost* aTexture) MOZ_OVERRIDE;
virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; }
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
virtual nsIntPoint GetOriginOffset()
{
@ -127,6 +131,10 @@ protected:
bool PaintWillResample() { return mPaintWillResample; }
// These must be called before forgetting mTextureHost or mTextureHostOnWhite
void DestroyTextureHost();
void DestroyTextureHostOnWhite();
nsIntRect mBufferRect;
nsIntPoint mBufferRotation;
RefPtr<TextureHost> mTextureHost;
@ -177,6 +185,8 @@ public:
// destroy our front buffer so that we can continue to composite.
virtual void DestroyTextures() = 0;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
virtual nsIntPoint GetOriginOffset()
{
@ -249,6 +259,8 @@ public:
const TextureInfo& aTextureInfo) MOZ_OVERRIDE;
virtual void DestroyTextures() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
#ifdef MOZ_DUMP_PAINTING
virtual void Dump(FILE* aFile=nullptr,
const char* aPrefix="",

View File

@ -38,16 +38,18 @@ ImageHost::~ImageHost() {}
void
ImageHost::UseTextureHost(TextureHost* aTexture)
{
if (mFrontBuffer) {
// XXX - When we implement sharing textures between several compositables
// we will need to not remove the compositor if there is another compositable
// using the texture.
mFrontBuffer->SetCompositor(nullptr);
}
CompositableHost::UseTextureHost(aTexture);
mFrontBuffer = aTexture;
}
void
ImageHost::RemoveTextureHost(TextureHost* aTexture)
{
CompositableHost::RemoveTextureHost(aTexture);
if (mFrontBuffer && mFrontBuffer->GetID() == aTexture->GetID()) {
mFrontBuffer = nullptr;
}
}
TextureHost*
ImageHost::GetAsTextureHost()
{
@ -72,10 +74,6 @@ ImageHost::Composite(EffectChain& aEffectChain,
if (!mFrontBuffer) {
return;
}
// Make sure the front buffer has a compositor
mFrontBuffer->SetCompositor(GetCompositor());
if (!mFrontBuffer->Lock()) {
NS_WARNING("failed to lock front buffer");
return;
@ -156,15 +154,6 @@ ImageHost::Composite(EffectChain& aEffectChain,
mFrontBuffer->Unlock();
}
void
ImageHost::SetCompositor(Compositor* aCompositor)
{
if (mFrontBuffer && mCompositor != aCompositor) {
mFrontBuffer->SetCompositor(aCompositor);
}
CompositableHost::SetCompositor(aCompositor);
}
void
ImageHost::PrintInfo(nsACString& aTo, const char* aPrefix)
{

View File

@ -55,9 +55,9 @@ public:
virtual void UseTextureHost(TextureHost* aTexture) MOZ_OVERRIDE;
virtual TextureHost* GetAsTextureHost() MOZ_OVERRIDE;
virtual void RemoveTextureHost(TextureHost* aTexture) MOZ_OVERRIDE;
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual TextureHost* GetAsTextureHost() MOZ_OVERRIDE;
virtual void SetPictureRect(const nsIntRect& aPictureRect) MOZ_OVERRIDE
{
@ -67,6 +67,13 @@ public:
virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE
{
if (mFrontBuffer) {
mFrontBuffer->OnActorDestroy();
}
}
virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
#ifdef MOZ_DUMP_PAINTING
@ -127,6 +134,13 @@ public:
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE
{
if (mDeprecatedTextureHost) {
mDeprecatedTextureHost->OnActorDestroy();
}
}
virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
#ifdef MOZ_DUMP_PAINTING

View File

@ -18,68 +18,12 @@
#include "nsAString.h"
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsPrintfCString.h" // for nsPrintfCString
#include "mozilla/layers/PTextureParent.h"
struct nsIntPoint;
namespace mozilla {
namespace layers {
/**
* TextureParent is the host-side IPDL glue between TextureClient and TextureHost.
* It is an IPDL actor just like LayerParent, CompositableParent, etc.
*/
class TextureParent : public PTextureParent
{
public:
TextureParent(ISurfaceAllocator* aAllocator);
~TextureParent();
bool RecvInit(const SurfaceDescriptor& aSharedData,
const TextureFlags& aFlags) MOZ_OVERRIDE;
virtual bool RecvRemoveTexture() MOZ_OVERRIDE;
virtual bool RecvRemoveTextureSync() MOZ_OVERRIDE;
TextureHost* GetTextureHost() { return mTextureHost; }
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
ISurfaceAllocator* mAllocator;
RefPtr<TextureHost> mTextureHost;
};
// static
PTextureParent*
TextureHost::CreateIPDLActor(ISurfaceAllocator* aAllocator)
{
return new TextureParent(aAllocator);
}
// static
bool
TextureHost::DestroyIPDLActor(PTextureParent* actor)
{
delete actor;
return true;
}
// static
bool
TextureHost::SendDeleteIPDLActor(PTextureParent* actor)
{
return PTextureParent::Send__delete__(actor);
}
// static
TextureHost*
TextureHost::AsTextureHost(PTextureParent* actor)
{
return actor? static_cast<TextureParent*>(actor)->mTextureHost : nullptr;
}
// implemented in TextureOGL.cpp
TemporaryRef<DeprecatedTextureHost> CreateDeprecatedTextureHostOGL(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
@ -137,32 +81,35 @@ DeprecatedTextureHost::CreateDeprecatedTextureHost(SurfaceDescriptorType aDescri
}
// implemented in TextureHostOGL.cpp
TemporaryRef<TextureHost> CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
TemporaryRef<TextureHost> CreateTextureHostOGL(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);
// implemented in TextureHostBasic.cpp
TemporaryRef<TextureHost> CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);
TemporaryRef<TextureHost> CreateTextureHostBasic(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);
// static
TemporaryRef<TextureHost>
TextureHost::Create(const SurfaceDescriptor& aDesc,
TextureHost::Create(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
{
switch (Compositor::GetBackend()) {
case LAYERS_OPENGL:
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
return CreateTextureHostOGL(aID, aDesc, aDeallocator, aFlags);
case LAYERS_BASIC:
return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
return CreateTextureHostBasic(aID, aDesc, aDeallocator, aFlags);
#ifdef MOZ_WIDGET_GONK
case LAYERS_NONE:
// Power on video reqests to allocate TextureHost,
// when Compositor is still not present. This is a very hacky workaround.
// See Bug 944420.
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
return CreateTextureHostOGL(aID, aDesc, aDeallocator, aFlags);
#endif
#ifdef XP_WIN
case LAYERS_D3D11:
@ -176,7 +123,8 @@ TextureHost::Create(const SurfaceDescriptor& aDesc,
}
TemporaryRef<TextureHost>
CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
CreateBackendIndependentTextureHost(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
{
@ -184,7 +132,8 @@ CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
switch (aDesc.type()) {
case SurfaceDescriptor::TSurfaceDescriptorShmem: {
const SurfaceDescriptorShmem& descriptor = aDesc.get_SurfaceDescriptorShmem();
result = new ShmemTextureHost(descriptor.data(),
result = new ShmemTextureHost(aID,
descriptor.data(),
descriptor.format(),
aDeallocator,
aFlags);
@ -192,7 +141,8 @@ CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
}
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
const SurfaceDescriptorMemory& descriptor = aDesc.get_SurfaceDescriptorMemory();
result = new MemoryTextureHost(reinterpret_cast<uint8_t*>(descriptor.data()),
result = new MemoryTextureHost(aID,
reinterpret_cast<uint8_t*>(descriptor.data()),
descriptor.format(),
aFlags);
break;
@ -211,23 +161,17 @@ TextureHost::SetCompositableBackendSpecificData(CompositableBackendSpecificData*
}
TextureHost::TextureHost(TextureFlags aFlags)
: mFlags(aFlags)
TextureHost::TextureHost(uint64_t aID,
TextureFlags aFlags)
: mID(aID)
, mNextTexture(nullptr)
, mFlags(aFlags)
{}
TextureHost::~TextureHost()
{
}
void TextureHost::Finalize()
{
if (GetFlags() & TEXTURE_DEALLOCATE_DEFERRED) {
MOZ_ASSERT(!(GetFlags() & TEXTURE_DEALLOCATE_CLIENT));
DeallocateSharedData();
DeallocateDeviceData();
}
}
void
TextureHost::PrintInfo(nsACString& aTo, const char* aPrefix)
{
@ -309,7 +253,7 @@ DeprecatedTextureHost::SwapTextures(const SurfaceDescriptor& aImage,
}
void
DeprecatedTextureHost::OnShutdown()
DeprecatedTextureHost::OnActorDestroy()
{
if (ISurfaceAllocator::IsShmem(mBuffer)) {
*mBuffer = SurfaceDescriptor();
@ -335,9 +279,10 @@ DeprecatedTextureHost::SetBuffer(SurfaceDescriptor* aBuffer, ISurfaceAllocator*
mDeAllocator = aAllocator;
}
BufferTextureHost::BufferTextureHost(gfx::SurfaceFormat aFormat,
BufferTextureHost::BufferTextureHost(uint64_t aID,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureHost(aFlags)
: TextureHost(aID, aFlags)
, mCompositor(nullptr)
, mFormat(aFormat)
, mUpdateSerial(1)
@ -439,19 +384,6 @@ BufferTextureHost::MaybeUpload(nsIntRegion *aRegion)
bool
BufferTextureHost::Upload(nsIntRegion *aRegion)
{
if (!GetBuffer()) {
// We don't have a buffer; a possible cause is that the IPDL actor
// is already dead. This inevitably happens as IPDL actors can die
// at any time, so we want to silently return in this case.
return false;
}
if (!mCompositor) {
NS_WARNING("Tried to upload without a compositor. Skipping texture upload...");
// If we are in this situation it means we should have called SetCompositor
// earlier. It is conceivable that on certain rare conditions with async-video
// we may end up here for the first frame, but this should not happen repeatedly.
return false;
}
if (mFormat == gfx::FORMAT_UNKNOWN) {
NS_WARNING("BufferTextureHost: unsupported format!");
return false;
@ -562,11 +494,12 @@ BufferTextureHost::GetAsSurface()
return result.forget();
}
ShmemTextureHost::ShmemTextureHost(const ipc::Shmem& aShmem,
ShmemTextureHost::ShmemTextureHost(uint64_t aID,
const ipc::Shmem& aShmem,
gfx::SurfaceFormat aFormat,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
: BufferTextureHost(aFormat, aFlags)
: BufferTextureHost(aID, aFormat, aFlags)
, mShmem(new ipc::Shmem(aShmem))
, mDeallocator(aDeallocator)
{
@ -587,22 +520,12 @@ ShmemTextureHost::DeallocateSharedData()
MOZ_ASSERT(mDeallocator,
"Shared memory would leak without a ISurfaceAllocator");
mDeallocator->DeallocShmem(*mShmem);
delete mShmem;
mShmem = nullptr;
}
}
void
ShmemTextureHost::ForgetSharedData()
{
if (mShmem) {
delete mShmem;
mShmem = nullptr;
}
}
void
ShmemTextureHost::OnShutdown()
ShmemTextureHost::OnActorDestroy()
{
delete mShmem;
mShmem = nullptr;
@ -613,10 +536,11 @@ uint8_t* ShmemTextureHost::GetBuffer()
return mShmem ? mShmem->get<uint8_t>() : nullptr;
}
MemoryTextureHost::MemoryTextureHost(uint8_t* aBuffer,
MemoryTextureHost::MemoryTextureHost(uint64_t aID,
uint8_t* aBuffer,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: BufferTextureHost(aFormat, aFlags)
: BufferTextureHost(aID, aFormat, aFlags)
, mBuffer(aBuffer)
{
MOZ_COUNT_CTOR(MemoryTextureHost);
@ -640,82 +564,10 @@ MemoryTextureHost::DeallocateSharedData()
mBuffer = nullptr;
}
void
MemoryTextureHost::ForgetSharedData()
{
mBuffer = nullptr;
}
uint8_t* MemoryTextureHost::GetBuffer()
{
return mBuffer;
}
TextureParent::TextureParent(ISurfaceAllocator* aAllocator)
: mAllocator(aAllocator)
{
MOZ_COUNT_CTOR(TextureParent);
}
TextureParent::~TextureParent()
{
MOZ_COUNT_DTOR(TextureParent);
mTextureHost = nullptr;
}
bool
TextureParent::RecvInit(const SurfaceDescriptor& aSharedData,
const TextureFlags& aFlags)
{
mTextureHost = TextureHost::Create(aSharedData,
mAllocator,
aFlags);
return !!mTextureHost;
}
bool
TextureParent::RecvRemoveTexture()
{
return PTextureParent::Send__delete__(this);
}
bool
TextureParent::RecvRemoveTextureSync()
{
// we don't need to send a reply in the synchronous case since the child side
// has the guarantee that this message has been handled synchronously.
return PTextureParent::Send__delete__(this);
}
void
TextureParent::ActorDestroy(ActorDestroyReason why)
{
if (!mTextureHost) {
return;
}
switch (why) {
case AncestorDeletion:
NS_WARNING("PTexture deleted after ancestor");
// fall-through to deletion path
case Deletion:
if (!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) &&
!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED)) {
mTextureHost->DeallocateSharedData();
}
break;
case NormalShutdown:
case AbnormalShutdown:
mTextureHost->OnShutdown();
break;
case FailedConstructor:
NS_RUNTIMEABORT("FailedConstructor isn't possible in PTexture");
}
mTextureHost->ForgetSharedData();
mTextureHost = nullptr;
}
} // namespace
} // namespace

View File

@ -23,7 +23,6 @@
#include "nsRegion.h" // for nsIntRegion
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
#include "nscore.h" // for nsACString
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
class gfxImageSurface;
class gfxReusableSurfaceWrapper;
@ -47,9 +46,8 @@ class TextureSourceOGL;
class TextureSourceD3D9;
class TextureSourceD3D11;
class TextureSourceBasic;
class DataTextureSource;
class PTextureParent;
class TextureParent;
class DataTextureSource;
/**
* A view on a TextureHost where the texture is internally represented as tiles
@ -259,28 +257,19 @@ private:
* The Lock/Unlock mecanism here mirrors Lock/Unlock in TextureClient.
*
*/
class TextureHost
: public AtomicRefCountedWithFinalize<TextureHost>
class TextureHost : public RefCounted<TextureHost>
{
/**
* Called once, just before the destructor.
*
* Here goes the shut-down code that uses virtual methods.
* Must only be called by Release().
*/
void Finalize();
friend class AtomicRefCountedWithFinalize<TextureHost>;
public:
TextureHost(TextureFlags aFlags);
TextureHost(uint64_t aID,
TextureFlags aFlags);
virtual ~TextureHost();
/**
* Factory method.
*/
static TemporaryRef<TextureHost> Create(const SurfaceDescriptor& aDesc,
static TemporaryRef<TextureHost> Create(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);
@ -343,15 +332,27 @@ public:
virtual void DeallocateSharedData() {}
/**
* Should be overridden in order to force the TextureHost to drop all references
* to it's shared data.
* An ID to differentiate TextureHosts of a given CompositableHost.
*
* This is important to ensure the correctness of the deallocation protocol.
* A TextureHost and its corresponding TextureClient always have the same ID.
* TextureHosts of a given CompositableHost always have different IDs.
* TextureHosts of different CompositableHosts, may have the same ID.
* Zero is always an invalid ID.
*/
virtual void ForgetSharedData() {}
uint64_t GetID() const { return mID; }
virtual gfx::IntSize GetSize() const = 0;
/**
* TextureHosts are kept as a linked list in their compositable
* XXX - This is just a poor man's PTexture. The purpose of this list is
* to keep TextureHost alive which should be independent from compositables.
* It will be removed when we add the PTetxure protocol (which will more
* gracefully handle the lifetime of textures). See bug 897452
*/
TextureHost* GetNextSibling() const { return mNextTexture; }
void SetNextSibling(TextureHost* aNext) { mNextTexture = aNext; }
/**
* Debug facility.
* XXX - cool kids use Moz2D. See bug 882113.
@ -370,27 +371,6 @@ public:
TextureFlags GetFlags() { return mFlags; }
/**
* Allocate and deallocate a TextureParent actor.
*
* TextureParent< is an implementation detail of TextureHost that is not
* exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
* are for use with the managing IPDL protocols only (so that they can
* implement AllocPTextureParent and DeallocPTextureParent).
*/
static PTextureParent* CreateIPDLActor(ISurfaceAllocator* aAllocator);
static bool DestroyIPDLActor(PTextureParent* actor);
/**
* Destroy the TextureChild/Parent pair.
*/
static bool SendDeleteIPDLActor(PTextureParent* actor);
/**
* Get the TextureHost corresponding to the actor passed in parameter.
*/
static TextureHost* AsTextureHost(PTextureParent* actor);
/**
* Specific to B2G's Composer2D
* XXX - more doc here
@ -406,12 +386,14 @@ public:
// If a texture host holds a reference to shmem, it should override this method
// to forget about the shmem _without_ releasing it.
virtual void OnShutdown() {}
virtual void OnActorDestroy() {}
virtual const char *Name() { return "TextureHost"; }
virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
protected:
uint64_t mID;
RefPtr<TextureHost> mNextTexture;
TextureFlags mFlags;
RefPtr<CompositableBackendSpecificData> mCompositableBackendData;
};
@ -432,7 +414,8 @@ protected:
class BufferTextureHost : public TextureHost
{
public:
BufferTextureHost(gfx::SurfaceFormat aFormat,
BufferTextureHost(uint64_t aID,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
~BufferTextureHost();
@ -487,7 +470,8 @@ protected:
class ShmemTextureHost : public BufferTextureHost
{
public:
ShmemTextureHost(const mozilla::ipc::Shmem& aShmem,
ShmemTextureHost(uint64_t aID,
const mozilla::ipc::Shmem& aShmem,
gfx::SurfaceFormat aFormat,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);
@ -496,13 +480,11 @@ public:
virtual void DeallocateSharedData() MOZ_OVERRIDE;
virtual void ForgetSharedData() MOZ_OVERRIDE;
virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
virtual const char *Name() MOZ_OVERRIDE { return "ShmemTextureHost"; }
virtual void OnShutdown() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
mozilla::ipc::Shmem* mShmem;
@ -518,7 +500,8 @@ protected:
class MemoryTextureHost : public BufferTextureHost
{
public:
MemoryTextureHost(uint8_t* aBuffer,
MemoryTextureHost(uint64_t aID,
uint8_t* aBuffer,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
@ -526,8 +509,6 @@ public:
virtual void DeallocateSharedData() MOZ_OVERRIDE;
virtual void ForgetSharedData() MOZ_OVERRIDE;
virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
virtual const char *Name() MOZ_OVERRIDE { return "MemoryTextureHost"; }
@ -730,7 +711,7 @@ public:
// see bug 865908 about fixing this.
virtual void ForgetBuffer() {}
void OnShutdown();
void OnActorDestroy();
protected:
/**
@ -833,7 +814,8 @@ private:
* Not all SurfaceDescriptor types are supported
*/
TemporaryRef<TextureHost>
CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
CreateBackendIndependentTextureHost(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags);

View File

@ -119,6 +119,16 @@ public:
mCompositor = aCompositor;
}
void OnActorDestroy()
{
Iterator end = TilesEnd();
for (Iterator it = TilesBegin(); it != end; ++it) {
if (it->mDeprecatedTextureHost) {
it->mDeprecatedTextureHost->OnActorDestroy();
}
}
}
protected:
TiledTexture ValidateTile(TiledTexture aTile,
const nsIntPoint& aTileRect,
@ -239,6 +249,12 @@ public:
Compositor* aCompositor,
AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE
{
mVideoMemoryTiledBuffer.OnActorDestroy();
mLowPrecisionVideoMemoryTiledBuffer.OnActorDestroy();
}
#ifdef MOZ_DUMP_PAINTING
virtual void Dump(FILE* aFile=nullptr,
const char* aPrefix="",

View File

@ -29,8 +29,6 @@ class ThebesBufferData;
class DeprecatedTextureClient;
class TextureClient;
class BasicTiledLayerBuffer;
class PTextureChild;
class TextureClientData;
/**
* A transaction is a set of changes that happenned on the content side, that
@ -95,14 +93,6 @@ public:
virtual void PaintedTiledLayerBuffer(CompositableClient* aCompositable,
const SurfaceDescriptorTiles& aTiledDescriptor) = 0;
/**
* Create an unitialized TextureChild.
*
* This does not trigger the the creation of a TextureHost on the compositor
* side (see PTexture::Init).
*/
virtual PTextureChild* CreateEmptyTextureChild() = 0;
/**
* Communicate to the compositor that the texture identified by aCompositable
* and aTextureId has been updated to aImage.
@ -160,10 +150,25 @@ public:
virtual void DestroyedThebesBuffer(const SurfaceDescriptor& aBackBufferToDestroy) = 0;
/**
* Tell the compositor side to delete the TextureHost corresponding to the
* TextureClient passed in parameter.
* Tell the compositor side to create a TextureHost that corresponds to
* aClient.
*/
virtual void RemoveTexture(TextureClient* aTexture) = 0;
virtual bool AddTexture(CompositableClient* aCompositable,
TextureClient* aClient) = 0;
/**
* Tell the compositor side to delete the TextureHost corresponding to
* aTextureID.
* By default the shared Data is deallocated along with the TextureHost, but
* this behaviour can be overriden by the TextureFlags passed here.
* XXX - This is kind of bad, but for now we have to do this, because of some
* edge cases caused by the lifetime of the TextureHost being limited by the
* lifetime of the CompositableHost. We should be able to remove this flags
* parameter when we remove the lifetime constraint.
*/
virtual void RemoveTexture(CompositableClient* aCompositable,
uint64_t aTextureID,
TextureFlags aFlags) = 0;
/**
* Tell the CompositableHost on the compositor side what texture to use for

View File

@ -222,8 +222,12 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
}
case CompositableOperation::TOpUseTexture: {
const OpUseTexture& op = aEdit.get_OpUseTexture();
if (op.textureID() == 0) {
NS_WARNING("Invalid texture ID");
break;
}
CompositableHost* compositable = AsCompositable(op);
RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent());
RefPtr<TextureHost> tex = compositable->GetTextureHost(op.textureID());
MOZ_ASSERT(tex.get());
compositable->UseTextureHost(tex);
@ -233,17 +237,75 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
}
break;
}
case CompositableOperation::TOpAddTexture: {
const OpAddTexture& op = aEdit.get_OpAddTexture();
if (op.textureID() == 0) {
NS_WARNING("Invalid texture ID");
break;
}
CompositableHost* compositable = AsCompositable(op);
RefPtr<TextureHost> tex = TextureHost::Create(op.textureID(),
op.data(),
this,
op.textureFlags());
MOZ_ASSERT(tex.get());
tex->SetCompositor(compositable->GetCompositor());
// set CompositableBackendSpecificData
// on gonk, create EGLImage if possible.
// create EGLImage during buffer swap could reduce the graphic driver's task
// during rendering.
compositable->AddTextureHost(tex);
MOZ_ASSERT(compositable->GetTextureHost(op.textureID()) == tex.get());
break;
}
case CompositableOperation::TOpRemoveTexture: {
const OpRemoveTexture& op = aEdit.get_OpRemoveTexture();
if (op.textureID() == 0) {
NS_WARNING("Invalid texture ID");
break;
}
CompositableHost* compositable = AsCompositable(op);
RefPtr<TextureHost> texture = compositable->GetTextureHost(op.textureID());
MOZ_ASSERT(texture);
TextureFlags flags = texture->GetFlags();
if (!(flags & TEXTURE_DEALLOCATE_CLIENT) &&
!(flags & TEXTURE_DEALLOCATE_DEFERRED)) {
texture->DeallocateSharedData();
}
compositable->RemoveTextureHost(texture);
// if it is not the host that deallocates the shared data, then we need
// to notfy the client side to tell when it is safe to deallocate or
// reuse it.
if (flags & TEXTURE_DEALLOCATE_CLIENT) {
replyv.push_back(ReplyTextureRemoved(op.compositableParent(), nullptr,
op.textureID()));
}
break;
}
case CompositableOperation::TOpUpdateTexture: {
const OpUpdateTexture& op = aEdit.get_OpUpdateTexture();
if (op.textureID() == 0) {
NS_WARNING("Invalid texture ID");
break;
}
CompositableHost* compositable = AsCompositable(op);
MOZ_ASSERT(compositable);
RefPtr<TextureHost> texture = TextureHost::AsTextureHost(op.textureParent());
RefPtr<TextureHost> texture = compositable->GetTextureHost(op.textureID());
MOZ_ASSERT(texture);
texture->Updated(op.region().type() == MaybeRegion::TnsIntRegion
? &op.region().get_nsIntRegion()
: nullptr); // no region means invalidate the entire surface
compositable->UseTextureHost(texture);
break;
}

View File

@ -36,7 +36,6 @@
#include "nsThreadUtils.h" // for NS_IsMainThread
#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop
#include "mozilla/StaticPtr.h" // for StaticRefPtr
#include "mozilla/layers/TextureClient.h"
struct nsIntRect;
@ -104,12 +103,46 @@ struct AutoEndTransaction {
CompositableTransaction* mTxn;
};
bool
ImageBridgeChild::AddTexture(CompositableClient* aCompositable,
TextureClient* aTexture)
{
SurfaceDescriptor descriptor;
if (!aTexture->ToSurfaceDescriptor(descriptor)) {
NS_WARNING("ImageBridge: Failed to serialize a TextureClient");
return false;
}
mTxn->AddEdit(OpAddTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture->GetID(),
descriptor,
aTexture->GetFlags()));
return true;
}
void
ImageBridgeChild::RemoveTexture(CompositableClient* aCompositable,
uint64_t aTexture,
TextureFlags aFlags)
{
if (aFlags & TEXTURE_DEALLOCATE_CLIENT) {
// if deallocation happens on the host side, we need the transaction
// to be synchronous.
mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture,
aFlags));
} else {
mTxn->AddNoSwapEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture,
aFlags));
}
}
void
ImageBridgeChild::UseTexture(CompositableClient* aCompositable,
TextureClient* aTexture)
{
mTxn->AddNoSwapEdit(OpUseTexture(nullptr, aCompositable->GetIPDLActor(),
nullptr, aTexture->GetIPDLActor()));
aTexture->GetID()));
}
void
@ -120,7 +153,7 @@ ImageBridgeChild::UpdatedTexture(CompositableClient* aCompositable,
MaybeRegion region = aRegion ? MaybeRegion(*aRegion)
: MaybeRegion(null_t());
mTxn->AddNoSwapEdit(OpUpdateTexture(nullptr, aCompositable->GetIPDLActor(),
nullptr, aTexture->GetIPDLActor(),
aTexture->GetID(),
region));
}
@ -432,6 +465,7 @@ void ImageBridgeChild::FlushAllImagesNow(ImageClient* aClient, ImageContainer* a
aClient->FlushAllImages(aExceptFront);
aClient->OnTransaction();
sImageBridgeChildSingleton->EndTransaction();
aClient->FlushTexturesToRemoveCallbacks();
}
void
@ -489,6 +523,18 @@ ImageBridgeChild::EndTransaction()
->SetDescriptorFromReply(ots.textureId(), ots.image());
break;
}
case EditReply::TReplyTextureRemoved: {
// We receive this reply when a Texture is removed and when it is not
// the responsibility of the compositor side to deallocate memory.
// This would be, for instance, the place to implement a mechanism to
// notify the B2G camera that the gralloc buffer is not used by the
// compositor anymore and that it can be recycled.
const ReplyTextureRemoved& rep = reply.get_ReplyTextureRemoved();
CompositableClient* compositable
= static_cast<CompositableChild*>(rep.compositableChild())->GetCompositableClient();
compositable->OnReplyTextureRemoved(rep.textureId());
break;
}
default:
NS_RUNTIMEABORT("not reached");
}
@ -894,54 +940,5 @@ ImageBridgeChild::AllocGrallocBuffer(const gfxIntSize& aSize,
#endif
}
PTextureChild*
ImageBridgeChild::AllocPTextureChild()
{
return TextureClient::CreateIPDLActor();
}
bool
ImageBridgeChild::DeallocPTextureChild(PTextureChild* actor)
{
return TextureClient::DestroyIPDLActor(actor);
}
PTextureChild*
ImageBridgeChild::CreateEmptyTextureChild()
{
return SendPTextureConstructor();
}
static void RemoveTextureSync(TextureClient* aTexture, ReentrantMonitor* aBarrier, bool* aDone)
{
aTexture->ForceRemove();
ReentrantMonitorAutoEnter autoMon(*aBarrier);
*aDone = true;
aBarrier->NotifyAll();
}
void ImageBridgeChild::RemoveTexture(TextureClient* aTexture)
{
if (InImageBridgeChildThread()) {
aTexture->ForceRemove();
return;
}
ReentrantMonitor barrier("RemoveTexture Lock");
ReentrantMonitorAutoEnter autoMon(barrier);
bool done = false;
sImageBridgeChildSingleton->GetMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(&RemoveTextureSync, aTexture, &barrier, &done));
// should stop the thread until the ImageClient has been created on
// the other thread
while (!done) {
barrier.Wait();
}
}
} // layers
} // mozilla

View File

@ -195,12 +195,6 @@ public:
virtual bool
DeallocPGrallocBufferChild(PGrallocBufferChild* actor) MOZ_OVERRIDE;
virtual PTextureChild*
AllocPTextureChild() MOZ_OVERRIDE;
virtual bool
DeallocPTextureChild(PTextureChild* actor) MOZ_OVERRIDE;
/**
* Allocate a gralloc SurfaceDescriptor remotely.
*/
@ -260,6 +254,19 @@ public:
virtual void Connect(CompositableClient* aCompositable) MOZ_OVERRIDE;
/**
* See CompositableForwarder::AddTexture
*/
virtual bool AddTexture(CompositableClient* aCompositable,
TextureClient* aClient) MOZ_OVERRIDE;
/**
* See CompositableForwarder::RemoveTexture
*/
virtual void RemoveTexture(CompositableClient* aCompositable,
uint64_t aTextureID,
TextureFlags aFlags) MOZ_OVERRIDE;
/**
* See CompositableForwarder::UpdatedTexture
*/
@ -273,8 +280,6 @@ public:
virtual void UseTexture(CompositableClient* aCompositable,
TextureClient* aClient) MOZ_OVERRIDE;
virtual void RemoveTexture(TextureClient* aTexture) MOZ_OVERRIDE;
virtual void PaintedTiledLayerBuffer(CompositableClient* aCompositable,
const SurfaceDescriptorTiles& aTileLayerDescriptor) MOZ_OVERRIDE
{
@ -373,8 +378,6 @@ public:
*/
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem);
virtual PTextureChild* CreateEmptyTextureChild() MOZ_OVERRIDE;
protected:
ImageBridgeChild();
bool DispatchAllocShmemInternal(size_t aSize,

View File

@ -30,7 +30,6 @@
#include "nsTArray.h" // for nsTArray, nsTArray_Impl
#include "nsTArrayForwardDeclare.h" // for InfallibleTArray
#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop
#include "mozilla/layers/TextureHost.h"
using namespace base;
using namespace mozilla::ipc;
@ -128,16 +127,6 @@ ImageBridgeParent::Create(Transport* aTransport, ProcessId aOtherProcess)
bool ImageBridgeParent::RecvStop()
{
// If there is any texture still alive we have to force it to deallocate the
// device data (GL textures, etc.) now because shortly after SenStop() returns
// on the child side the widget will be destroyed along with it's associated
// GL context.
InfallibleTArray<PTextureParent*> textures;
ManagedPTextureParent(textures);
for (unsigned int i = 0; i < textures.Length(); ++i) {
RefPtr<TextureHost> tex = TextureHost::AsTextureHost(textures[i]);
tex->DeallocateDeviceData();
}
return true;
}
@ -189,18 +178,6 @@ bool ImageBridgeParent::DeallocPCompositableParent(PCompositableParent* aActor)
return true;
}
PTextureParent*
ImageBridgeParent::AllocPTextureParent()
{
return TextureHost::CreateIPDLActor(this);
}
bool
ImageBridgeParent::DeallocPTextureParent(PTextureParent* actor)
{
return TextureHost::DestroyIPDLActor(actor);
}
MessageLoop * ImageBridgeParent::GetMessageLoop() {
return mMessageLoop;
}

View File

@ -65,9 +65,6 @@ public:
uint64_t*) MOZ_OVERRIDE;
bool DeallocPCompositableParent(PCompositableParent* aActor) MOZ_OVERRIDE;
virtual PTextureParent* AllocPTextureParent() MOZ_OVERRIDE;
virtual bool DeallocPTextureParent(PTextureParent* actor) MOZ_OVERRIDE;
bool RecvStop() MOZ_OVERRIDE;
MessageLoop * GetMessageLoop();

View File

@ -13,7 +13,6 @@
#include "mozilla/mozalloc.h" // for operator delete, etc
#include "nsDebug.h" // for NS_RUNTIMEABORT, etc
#include "nsTArray.h" // for nsTArray
#include "mozilla/layers/TextureClient.h"
namespace mozilla {
namespace layers {
@ -97,17 +96,5 @@ LayerTransactionChild::ActorDestroy(ActorDestroyReason why)
#endif
}
PTextureChild*
LayerTransactionChild::AllocPTextureChild()
{
return TextureClient::CreateIPDLActor();
}
bool
LayerTransactionChild::DeallocPTextureChild(PTextureChild* actor)
{
return TextureClient::DestroyIPDLActor(actor);
}
} // namespace layers
} // namespace mozilla

View File

@ -58,10 +58,6 @@ protected:
virtual PCompositableChild* AllocPCompositableChild(const TextureInfo& aInfo) MOZ_OVERRIDE;
virtual bool DeallocPCompositableChild(PCompositableChild* actor) MOZ_OVERRIDE;
virtual PTextureChild* AllocPTextureChild() MOZ_OVERRIDE;
virtual bool DeallocPTextureChild(PTextureChild* actor) MOZ_OVERRIDE;
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
void AddIPDLReference() {

View File

@ -39,7 +39,6 @@
#include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
#include "GeckoProfiler.h"
#include "mozilla/layers/TextureHost.h"
typedef std::vector<mozilla::layers::EditReply> EditReplyVector;
@ -601,17 +600,5 @@ LayerTransactionParent::DeallocPCompositableParent(PCompositableParent* actor)
return true;
}
PTextureParent*
LayerTransactionParent::AllocPTextureParent()
{
return TextureHost::CreateIPDLActor(this);
}
bool
LayerTransactionParent::DeallocPTextureParent(PTextureParent* actor)
{
return TextureHost::DestroyIPDLActor(actor);
}
} // namespace layers
} // namespace mozilla

View File

@ -106,9 +106,6 @@ protected:
virtual PCompositableParent* AllocPCompositableParent(const TextureInfo& aInfo) MOZ_OVERRIDE;
virtual bool DeallocPCompositableParent(PCompositableParent* actor) MOZ_OVERRIDE;
virtual PTextureParent* AllocPTextureParent() MOZ_OVERRIDE;
virtual bool DeallocPTextureParent(PTextureParent* actor) MOZ_OVERRIDE;
void Attach(ShadowLayerParent* aLayerParent,
CompositableParent* aCompositable,
bool aIsAsyncVideo);

View File

@ -11,7 +11,6 @@ include protocol PCompositor;
include protocol PGrallocBuffer;
include protocol PLayer;
include protocol PRenderFrame;
include protocol PTexture;
include "gfxipc/ShadowLayerUtils.h";
include "mozilla/GfxMessageUtils.h";
@ -301,13 +300,34 @@ struct OpUpdatePictureRect {
nsIntRect picture;
};
/**
* Provides the compositor side with enough information to create a
* TextureHost.
*/
struct OpAddTexture {
PCompositable compositable;
uint64_t textureID;
SurfaceDescriptor data;
uint32_t textureFlags;
};
/**
* Tells the compositor-side to remove the corresponding TextureHost and
* deallocate its data.
*/
struct OpRemoveTexture {
PCompositable compositable;
uint64_t textureID;
uint32_t flags;
};
/**
* Tells the compositor-side which texture to use (for example, as front buffer
* if there is several textures for double buffering)
*/
struct OpUseTexture {
PCompositable compositable;
PTexture texture;
uint64_t textureID;
};
union MaybeRegion {
@ -317,7 +337,7 @@ union MaybeRegion {
struct OpUpdateTexture {
PCompositable compositable;
PTexture texture;
uint64_t textureID;
MaybeRegion region;
};
@ -334,6 +354,8 @@ union CompositableOperation {
OpPaintTiledLayerBuffer;
OpAddTexture;
OpRemoveTexture;
OpUpdateTexture;
OpUseTexture;
};
@ -377,11 +399,18 @@ struct OpTextureSwap {
SurfaceDescriptor image;
};
struct ReplyTextureRemoved {
PCompositable compositable;
uint64_t textureId;
};
// Unit of a "changeset reply". This is a weird abstraction, probably
// only to be used for buffer swapping.
union EditReply {
OpContentBufferSwap;
OpTextureSwap;
ReplyTextureRemoved;
};
} // namespace

View File

@ -7,7 +7,6 @@ include LayersSurfaces;
include LayersMessages;
include protocol PGrallocBuffer;
include protocol PCompositable;
include protocol PTexture;
include ProtocolTypes;
include "mozilla/GfxMessageUtils.h";
@ -26,7 +25,6 @@ intr protocol PImageBridge
{
manages PCompositable;
manages PGrallocBuffer;
manages PTexture;
parent:
@ -51,7 +49,6 @@ parent:
sync Stop();
sync PCompositable(TextureInfo aInfo) returns (uint64_t id);
async PTexture();
};

View File

@ -12,7 +12,6 @@ include protocol PCompositor;
include protocol PGrallocBuffer;
include protocol PLayer;
include protocol PRenderFrame;
include protocol PTexture;
include "mozilla/GfxMessageUtils.h";
@ -34,7 +33,6 @@ sync protocol PLayerTransaction {
manages PLayer;
manages PCompositable;
manages PGrallocBuffer;
manages PTexture;
parent:
/**
@ -68,7 +66,6 @@ parent:
returns (MaybeMagicGrallocBufferHandle handle);
async PLayer();
async PCompositable(TextureInfo aTextureInfo);
async PTexture();
// The isFirstPaint flag can be used to indicate that this is the first update
// for a particular document.

View File

@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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 LayersSurfaces;
include protocol PLayerTransaction;
include protocol PImageBridge;
include protocol PGrallocBuffer;
include "mozilla/GfxMessageUtils.h";
using struct mozilla::layers::FrameMetrics from "FrameMetrics.h";
namespace mozilla {
namespace layers {
/**
* PTexture is the IPDL glue between a TextureClient and a TextureHost.
*/
sync protocol PTexture {
manager PImageBridge or PLayerTransaction;
child:
async __delete__();
parent:
/**
* Set the shared data and create the TextureHost on the parent side.
*/
async Init(SurfaceDescriptor aSharedData, uint32_t aTextureFlags);
/**
* Asynchronously tell the Compositor side to remove the texture.
*/
async RemoveTexture();
/**
* Synchronously tell the compositor side to remove the texture.
*/
sync RemoveTextureSync();
};
} // layers
} // mozilla

View File

@ -13,7 +13,6 @@
#include "mozilla/layers/ShadowLayers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/TextureHost.h"
#include "mozilla/unused.h"
#include "nsXULAppAPI.h"

View File

@ -15,6 +15,10 @@
#include "mozilla/layers/PGrallocBufferChild.h"
#include "mozilla/layers/PGrallocBufferParent.h"
// used only for hacky fix in gecko 23 for bug 862324
// see bug 865908 about fixing this.
#include "TextureHost.h"
#define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
@ -25,8 +29,6 @@ namespace layers {
class MaybeMagicGrallocBufferHandle;
class SurfaceDescriptorGralloc;
class TextureHost;
class DeprecatedTextureHost;
/**
* This class exists to share the underlying GraphicBuffer resources

View File

@ -407,6 +407,39 @@ ShadowLayerForwarder::UpdatePictureRect(CompositableClient* aCompositable,
mTxn->AddNoSwapPaint(OpUpdatePictureRect(nullptr, aCompositable->GetIPDLActor(), aRect));
}
bool
ShadowLayerForwarder::AddTexture(CompositableClient* aCompositable,
TextureClient* aTexture)
{
SurfaceDescriptor descriptor;
if (!aTexture->ToSurfaceDescriptor(descriptor)) {
NS_WARNING("Failed to serialize a TextureClient");
return false;
}
CheckSurfaceDescriptor(&descriptor);
MOZ_ASSERT(aCompositable);
MOZ_ASSERT(aCompositable->GetIPDLActor());
MOZ_ASSERT(aTexture->GetFlags() != 0);
mTxn->AddEdit(OpAddTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture->GetID(),
descriptor,
aTexture->GetFlags()));
return true;
}
void
ShadowLayerForwarder::RemoveTexture(CompositableClient* aCompositable,
uint64_t aTexture,
TextureFlags aFlags)
{
mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture,
aFlags));
if (aFlags & TEXTURE_DEALLOCATE_CLIENT) {
mTxn->MarkSyncTransaction();
}
}
void
ShadowLayerForwarder::UpdatedTexture(CompositableClient* aCompositable,
TextureClient* aTexture,
@ -416,11 +449,11 @@ ShadowLayerForwarder::UpdatedTexture(CompositableClient* aCompositable,
: MaybeRegion(null_t());
if (aTexture->GetFlags() & TEXTURE_IMMEDIATE_UPLOAD) {
mTxn->AddPaint(OpUpdateTexture(nullptr, aCompositable->GetIPDLActor(),
nullptr, aTexture->GetIPDLActor(),
aTexture->GetID(),
region));
} else {
mTxn->AddNoSwapPaint(OpUpdateTexture(nullptr, aCompositable->GetIPDLActor(),
nullptr, aTexture->GetIPDLActor(),
aTexture->GetID(),
region));
}
}
@ -430,13 +463,7 @@ ShadowLayerForwarder::UseTexture(CompositableClient* aCompositable,
TextureClient* aTexture)
{
mTxn->AddEdit(OpUseTexture(nullptr, aCompositable->GetIPDLActor(),
nullptr, aTexture->GetIPDLActor()));
}
void
ShadowLayerForwarder::RemoveTexture(TextureClient* aTexture)
{
aTexture->ForceRemove();
aTexture->GetID()));
}
bool
@ -962,13 +989,6 @@ void ShadowLayerForwarder::AttachAsyncCompositable(uint64_t aCompositableID,
aCompositableID));
}
PTextureChild*
ShadowLayerForwarder::CreateEmptyTextureChild()
{
return mShadowManager->SendPTextureConstructor();
}
void ShadowLayerForwarder::SetShadowManager(PLayerTransactionChild* aShadowManager)
{
mShadowManager = static_cast<LayerTransactionChild*>(aShadowManager);

View File

@ -149,8 +149,6 @@ public:
*/
void Connect(CompositableClient* aCompositable);
virtual PTextureChild* CreateEmptyTextureChild() MOZ_OVERRIDE;
virtual void CreatedSingleBuffer(CompositableClient* aCompositable,
const SurfaceDescriptor& aDescriptor,
const TextureInfo& aTextureInfo,
@ -279,8 +277,6 @@ public:
TextureIdentifier aTextureId,
SurfaceDescriptor* aDescriptor) MOZ_OVERRIDE;
virtual void RemoveTexture(TextureClient* aTexture) MOZ_OVERRIDE;
/**
* Same as above, but performs an asynchronous layer transaction
*/
@ -309,6 +305,19 @@ public:
void UpdatePictureRect(CompositableClient* aCompositable,
const nsIntRect& aRect);
/**
* See CompositableForwarder::AddTexture
*/
virtual bool AddTexture(CompositableClient* aCompositable,
TextureClient* aClient) MOZ_OVERRIDE;
/**
* See CompositableForwarder::RemoveTexture
*/
virtual void RemoveTexture(CompositableClient* aCompositable,
uint64_t aTextureID,
TextureFlags aFlags) MOZ_OVERRIDE;
/**
* See CompositableForwarder::UpdatedTexture
*/

View File

@ -98,7 +98,6 @@ EXPORTS.gfxipc += [
]
EXPORTS.mozilla.layers += [
'AtomicRefCountedWithFinalize.h',
'basic/BasicCompositor.h',
'basic/MacIOSurfaceTextureHostBasic.h',
'basic/TextureHostBasic.h',
@ -291,7 +290,6 @@ IPDL_SOURCES = [
'ipc/PImageBridge.ipdl',
'ipc/PLayer.ipdl',
'ipc/PLayerTransaction.ipdl',
'ipc/PTexture.ipdl',
]
MSVC_ENABLE_PGO = True

View File

@ -95,7 +95,6 @@ GrallocTextureSourceOGL::GrallocTextureSourceOGL(CompositorOGL* aCompositor,
, mGraphicBuffer(aGraphicBuffer)
, mEGLImage(0)
, mFormat(aFormat)
, mNeedsReset(true)
{
MOZ_ASSERT(mGraphicBuffer.get());
}
@ -170,14 +169,6 @@ GrallocTextureSourceOGL::GetFormat() const {
void
GrallocTextureSourceOGL::SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData)
{
if (mCompositableBackendData != aBackendData) {
mNeedsReset = true;
}
if (!mNeedsReset) {
return;
}
mCompositableBackendData = aBackendData;
if (!mCompositor) {
@ -196,7 +187,6 @@ GrallocTextureSourceOGL::SetCompositableBackendSpecificData(CompositableBackendS
// create new EGLImage
mEGLImage = gl()->CreateEGLImageForNativeBuffer(mGraphicBuffer->getNativeBuffer());
gl()->fEGLImageTargetTexture2D(textureTarget, mEGLImage);
mNeedsReset = false;
}
gfx::IntSize
@ -220,9 +210,10 @@ GrallocTextureSourceOGL::DeallocateDeviceData()
}
}
GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags,
GrallocTextureHostOGL::GrallocTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const NewSurfaceDescriptorGralloc& aDescriptor)
: TextureHost(aFlags)
: TextureHost(aID, aFlags)
{
mGrallocActor =
static_cast<GrallocBufferActor*>(aDescriptor.bufferParent());
@ -282,14 +273,6 @@ GrallocTextureHostOGL::DeallocateSharedData()
PGrallocBufferParent::Send__delete__(mGrallocActor);
}
void
GrallocTextureHostOGL::ForgetSharedData()
{
if (mTextureSource) {
mTextureSource->ForgetBuffer();
}
}
void
GrallocTextureHostOGL::DeallocateDeviceData()
{

View File

@ -69,14 +69,14 @@ protected:
android::sp<android::GraphicBuffer> mGraphicBuffer;
EGLImage mEGLImage;
gfx::SurfaceFormat mFormat;
bool mNeedsReset;
};
class GrallocTextureHostOGL : public TextureHost
{
friend class GrallocBufferActor;
public:
GrallocTextureHostOGL(TextureFlags aFlags,
GrallocTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const NewSurfaceDescriptorGralloc& aDescriptor);
virtual ~GrallocTextureHostOGL();
@ -91,8 +91,6 @@ public:
virtual void DeallocateSharedData() MOZ_OVERRIDE;
virtual void ForgetSharedData() MOZ_OVERRIDE;
virtual void DeallocateDeviceData() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const;

View File

@ -34,9 +34,10 @@ MacIOSurfaceTextureSourceOGL::GetFormat() const
return mSurface->HasAlpha() ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_B8G8R8X8;
}
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor)
: TextureHost(aFlags)
: TextureHost(aID, aFlags)
{
mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
aDescriptor.scaleFactor(),

View File

@ -65,7 +65,8 @@ protected:
class MacIOSurfaceTextureHostOGL : public TextureHost
{
public:
MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor);
// SharedTextureHostOGL doesn't own any GL texture

View File

@ -87,7 +87,8 @@ CreateDeprecatedTextureHostOGL(SurfaceDescriptorType aDescriptorType,
TemporaryRef<TextureHost>
CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
CreateTextureHostOGL(uint64_t aID,
const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
{
@ -95,13 +96,13 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
switch (aDesc.type()) {
case SurfaceDescriptor::TSurfaceDescriptorShmem:
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
result = CreateBackendIndependentTextureHost(aDesc,
result = CreateBackendIndependentTextureHost(aID, aDesc,
aDeallocator, aFlags);
break;
}
case SurfaceDescriptor::TSharedTextureDescriptor: {
const SharedTextureDescriptor& desc = aDesc.get_SharedTextureDescriptor();
result = new SharedTextureHostOGL(aFlags,
result = new SharedTextureHostOGL(aID, aFlags,
desc.shareType(),
desc.handle(),
gfx::ToIntSize(desc.size()),
@ -112,7 +113,7 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
const SurfaceDescriptorMacIOSurface& desc =
aDesc.get_SurfaceDescriptorMacIOSurface();
result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
result = new MacIOSurfaceTextureHostOGL(aID, aFlags, desc);
break;
}
#endif
@ -120,7 +121,7 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TNewSurfaceDescriptorGralloc: {
const NewSurfaceDescriptorGralloc& desc =
aDesc.get_NewSurfaceDescriptorGralloc();
result = new GrallocTextureHostOGL(aFlags, desc);
result = new GrallocTextureHostOGL(aID, aFlags, desc);
break;
}
#endif
@ -375,12 +376,13 @@ SharedTextureSourceOGL::GetTextureTransform()
return handleDetails.mTextureTransform;
}
SharedTextureHostOGL::SharedTextureHostOGL(TextureFlags aFlags,
SharedTextureHostOGL::SharedTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
gl::SharedTextureShareType aShareType,
gl::SharedTextureHandle aSharedHandle,
gfx::IntSize aSize,
bool inverted)
: TextureHost(aFlags)
: TextureHost(aID, aFlags)
, mSize(aSize)
, mCompositor(nullptr)
, mSharedHandle(aSharedHandle)

View File

@ -298,7 +298,8 @@ protected:
class SharedTextureHostOGL : public TextureHost
{
public:
SharedTextureHostOGL(TextureFlags aFlags,
SharedTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
gl::SharedTextureShareType aShareType,
gl::SharedTextureHandle aSharedhandle,
gfx::IntSize aSize,

View File

@ -119,17 +119,20 @@ void TestTextureClientSurface(TextureClient* texture, gfxImageSurface* surface)
texture->Unlock();
// client serialization
texture->SetID(1);
SurfaceDescriptor descriptor;
ASSERT_TRUE(texture->ToSurfaceDescriptor(descriptor));
ASSERT_NE(descriptor.type(), SurfaceDescriptor::Tnull_t);
// host deserialization
RefPtr<TextureHost> host = CreateBackendIndependentTextureHost(descriptor, nullptr,
RefPtr<TextureHost> host = CreateBackendIndependentTextureHost(texture->GetID(),
descriptor, nullptr,
texture->GetFlags());
ASSERT_TRUE(host.get() != nullptr);
ASSERT_EQ(host->GetFlags(), texture->GetFlags());
ASSERT_EQ(host->GetID(), texture->GetID());
// host read
ASSERT_TRUE(host->Lock());
@ -142,6 +145,9 @@ void TestTextureClientSurface(TextureClient* texture, gfxImageSurface* surface)
hostDataSurface->Stride(),
SurfaceFormatToImageFormat(hostDataSurface->GetFormat()));
AssertSurfacesEqual(surface, hostSurface.get());
// host deallocation
host->DeallocateSharedData();
}
// Same as above, for YCbCr surfaces
@ -162,19 +168,22 @@ void TestTextureClientYCbCr(TextureClient* client, PlanarYCbCrData& ycbcrData) {
client->Unlock();
// client serialization
client->SetID(1);
SurfaceDescriptor descriptor;
ASSERT_TRUE(client->ToSurfaceDescriptor(descriptor));
ASSERT_NE(descriptor.type(), SurfaceDescriptor::Tnull_t);
// host deserialization
RefPtr<TextureHost> textureHost = CreateBackendIndependentTextureHost(descriptor, nullptr,
RefPtr<TextureHost> textureHost = CreateBackendIndependentTextureHost(client->GetID(),
descriptor, nullptr,
client->GetFlags());
RefPtr<BufferTextureHost> host = static_cast<BufferTextureHost*>(textureHost.get());
ASSERT_TRUE(host.get() != nullptr);
ASSERT_EQ(host->GetFlags(), client->GetFlags());
ASSERT_EQ(host->GetID(), client->GetID());
// This will work iff the compositor is not BasicCompositor
ASSERT_EQ(host->GetFormat(), mozilla::gfx::FORMAT_YUV);
@ -204,6 +213,9 @@ void TestTextureClientYCbCr(TextureClient* client, PlanarYCbCrData& ycbcrData) {
AssertYCbCrSurfacesEqual(&ycbcrData, &data);
host->Unlock();
// host deallocation
host->DeallocateSharedData();
}
TEST(Layers, TextureSerialization) {
@ -222,7 +234,7 @@ TEST(Layers, TextureSerialization) {
RefPtr<TextureClient> client
= new MemoryTextureClient(nullptr,
mozilla::gfx::ImageFormatToSurfaceFormat(surface->Format()),
TEXTURE_DEALLOCATE_CLIENT);
TEXTURE_FLAGS_DEFAULT);
TestTextureClientSurface(client, surface);
@ -258,7 +270,7 @@ TEST(Layers, TextureYCbCrSerialization) {
RefPtr<TextureClient> client
= new MemoryTextureClient(nullptr,
mozilla::gfx::FORMAT_YUV,
TEXTURE_DEALLOCATE_CLIENT);
TEXTURE_FLAGS_DEFAULT);
TestTextureClientYCbCr(client, clientData);