This commit is contained in:
Nicholas Cameron 2013-11-19 17:39:24 +13:00
commit fcc7cf881b
21 changed files with 288 additions and 7 deletions

View File

@ -105,6 +105,14 @@ CanvasClient2D::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFla
mTextureInfo.mTextureFlags | aFlags);
}
void
CanvasClient2D::OnActorDestroy()
{
if (mBuffer) {
mBuffer->OnActorDestroy();
}
}
void
DeprecatedCanvasClient2D::Updated()
{
@ -156,6 +164,14 @@ DeprecatedCanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
mDeprecatedTextureClient->Unlock();
}
void
DeprecatedCanvasClient2D::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
}
void
DeprecatedCanvasClientSurfaceStream::Updated()
{
@ -224,5 +240,13 @@ DeprecatedCanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLaye
aLayer->Painted();
}
void
DeprecatedCanvasClientSurfaceStream::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
}
}
}

View File

@ -91,9 +91,12 @@ public:
mBuffer = nullptr;
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<TextureClient> mBuffer;
};
class DeprecatedCanvasClient2D : public CanvasClient
{
public:
@ -114,6 +117,8 @@ public:
mDeprecatedTextureClient->SetDescriptorFromReply(aDescriptor);
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
};
@ -140,6 +145,8 @@ public:
mDeprecatedTextureClient->SetDescriptorFromReply(aDescriptor);
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
};

View File

@ -35,7 +35,6 @@ CompositableClient::~CompositableClient()
Destroy();
FlushTexturesToRemoveCallbacks();
MOZ_ASSERT(mTexturesToRemove.Length() == 0, "would leak textures pending for deletion");
}
@ -87,6 +86,7 @@ CompositableClient::Destroy()
if (!mCompositableChild) {
return;
}
mCompositableChild->SetClient(nullptr);
mCompositableChild->Destroy();
mCompositableChild = nullptr;
}
@ -257,5 +257,13 @@ CompositableClient::OnTransaction()
mTexturesToRemove.Clear();
}
void
CompositableChild::ActorDestroy(ActorDestroyReason why)
{
if (mCompositableClient && why == AbnormalShutdown) {
mCompositableClient->OnActorDestroy();
}
}
} // namespace layers
} // namespace mozilla

View File

@ -161,6 +161,12 @@ public:
* 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:
struct TextureIDAndFlags {
TextureIDAndFlags(uint64_t aID, TextureFlags aFlags)
@ -207,6 +213,8 @@ public:
return mCompositableClient;
}
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
void SetAsyncID(uint64_t aID) { mID = aID; }
uint64_t GetAsyncID() const
{

View File

@ -327,6 +327,21 @@ ContentClientRemoteBuffer::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion)
}
}
void
ContentClientRemoteBuffer::OnActorDestroy()
{
if (mDeprecatedTextureClient) {
mDeprecatedTextureClient->OnActorDestroy();
}
if (mDeprecatedTextureClientOnWhite) {
mDeprecatedTextureClientOnWhite->OnActorDestroy();
}
for (size_t i = 0; i < mOldTextures.Length(); ++i) {
mOldTextures[i]->OnActorDestroy();
}
}
ContentClientDoubleBuffered::~ContentClientDoubleBuffered()
{
if (mDeprecatedTextureClient) {
@ -427,6 +442,26 @@ ContentClientDoubleBuffered::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion)
ContentClientRemoteBuffer::SwapBuffers(aFrontUpdatedRegion);
}
void
ContentClientDoubleBuffered::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

@ -163,6 +163,8 @@ public:
MOZ_CRASH("Should not be called on non-remote ContentClient");
}
virtual void OnActorDestroy() MOZ_OVERRIDE {}
private:
BasicLayerManager* mManager;
};
@ -247,6 +249,8 @@ public:
return mTextureInfo;
}
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
virtual nsIntRegion GetUpdatedRegion(const nsIntRegion& aRegionToDraw,
const nsIntRegion& aVisibleRegion,
@ -310,6 +314,8 @@ protected:
virtual void DestroyFrontBuffer() MOZ_OVERRIDE;
virtual void LockFrontBuffer() MOZ_OVERRIDE;
virtual void OnActorDestroy() MOZ_OVERRIDE;
private:
void UpdateDestinationFrom(const RotatedBuffer& aSource,
const nsIntRegion& aUpdateRegion);
@ -395,6 +401,8 @@ public:
}
}
virtual void OnActorDestroy() MOZ_OVERRIDE {}
private:
enum BufferType{

View File

@ -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

@ -390,6 +390,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

@ -216,6 +216,10 @@ public:
*/
void MarkInvalid() { mValid = false; }
// 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)
{
@ -316,6 +320,11 @@ public:
ipc::Shmem& GetShmem() { return mShmem; }
virtual void OnActorDestroy() MOZ_OVERRIDE
{
mShmem = ipc::Shmem();
}
protected:
ipc::Shmem mShmem;
ISurfaceAllocator* mAllocator;
@ -492,6 +501,8 @@ public:
virtual gfxContentType GetContentType() = 0;
void OnActorDestroy();
protected:
DeprecatedTextureClient(CompositableForwarder* aForwarder,
const TextureInfo& aTextureInfo);

View File

@ -201,6 +201,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,
@ -290,6 +298,12 @@ public:
};
void LockCopyAndWrite(TiledBufferType aType);
virtual void OnActorDestroy() MOZ_OVERRIDE
{
mTiledBuffer.OnActorDestroy();
mLowPrecisionTiledBuffer.OnActorDestroy();
}
private:
BasicTiledLayerBuffer mTiledBuffer;
BasicTiledLayerBuffer mLowPrecisionTiledBuffer;

View File

@ -237,7 +237,14 @@ void
CompositableParent::ActorDestroy(ActorDestroyReason why)
{
if (mHost) {
mHost->Detach();
// 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

@ -107,6 +107,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() = 0;
// If base class overrides, it should still call the parent implementation
virtual void SetCompositor(Compositor* aCompositor);
@ -237,6 +243,7 @@ public:
static const AttachFlags NO_FLAGS = 0;
static const AttachFlags ALLOW_REATTACH = 1;
static const AttachFlags KEEP_ATTACHED = 2;
static const AttachFlags FORCE_DETACH = 2;
virtual void Attach(Layer* aLayer,
Compositor* aCompositor,
@ -257,10 +264,12 @@ public:
// attached to that layer. If we are part of a normal layer, then we will be
// detached in any case. if aLayer is null, then we will only detach if we are
// not async.
void Detach(Layer* aLayer = nullptr)
// Only force detach if the IPDL tree is being shutdown.
void Detach(Layer* aLayer = nullptr, AttachFlags aFlags = NO_FLAGS)
{
if (!mKeepAttached ||
aLayer == mLayer) {
aLayer == mLayer ||
aFlags & FORCE_DETACH) {
SetLayer(nullptr);
SetCompositor(nullptr);
mAttached = false;

View File

@ -52,6 +52,23 @@ ContentHostBase::DestroyFrontHost()
mDeprecatedTextureHostOnWhite = nullptr;
}
void
ContentHostBase::OnActorDestroy()
{
if (mDeprecatedTextureHost) {
mDeprecatedTextureHost->OnActorDestroy();
}
if (mDeprecatedTextureHostOnWhite) {
mDeprecatedTextureHostOnWhite->OnActorDestroy();
}
if (mNewFrontHost) {
mNewFrontHost->OnActorDestroy();
}
if (mNewFrontHostOnWhite) {
mNewFrontHostOnWhite->OnActorDestroy();
}
}
void
ContentHostBase::Composite(EffectChain& aEffectChain,
float aOpacity,
@ -409,19 +426,16 @@ ContentHostDoubleBuffered::DestroyTextures()
"We won't be able to destroy our SurfaceDescriptor");
mNewFrontHost = nullptr;
}
if (mNewFrontHostOnWhite) {
MOZ_ASSERT(mNewFrontHostOnWhite->GetDeAllocator(),
"We won't be able to destroy our SurfaceDescriptor");
mNewFrontHostOnWhite = nullptr;
}
if (mBackHost) {
MOZ_ASSERT(mBackHost->GetDeAllocator(),
"We won't be able to destroy our SurfaceDescriptor");
mBackHost = nullptr;
}
if (mBackHostOnWhite) {
MOZ_ASSERT(mBackHostOnWhite->GetDeAllocator(),
"We won't be able to destroy our SurfaceDescriptor");
@ -431,6 +445,29 @@ ContentHostDoubleBuffered::DestroyTextures()
// don't touch mDeprecatedTextureHost, we might need it for compositing
}
void
ContentHostDoubleBuffered::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
ContentHostDoubleBuffered::UpdateThebes(const ThebesBufferData& aData,
const nsIntRegion& aUpdated,

View File

@ -127,6 +127,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()
{
@ -177,6 +179,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

@ -68,6 +68,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
@ -128,6 +135,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

@ -242,6 +242,15 @@ DeprecatedTextureHost::SwapTextures(const SurfaceDescriptor& aImage,
SetBuffer(mBuffer, mDeAllocator);
}
void
DeprecatedTextureHost::OnActorDestroy()
{
if (ISurfaceAllocator::IsShmem(mBuffer)) {
*mBuffer = SurfaceDescriptor();
mBuffer = nullptr;
}
}
void
DeprecatedTextureHost::PrintInfo(nsACString& aTo, const char* aPrefix)
{
@ -506,6 +515,13 @@ ShmemTextureHost::DeallocateSharedData()
}
}
void
ShmemTextureHost::OnActorDestroy()
{
delete mShmem;
mShmem = nullptr;
}
uint8_t* ShmemTextureHost::GetBuffer()
{
return mShmem ? mShmem->get<uint8_t>() : nullptr;

View File

@ -384,6 +384,10 @@ public:
virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData);
// If a texture host holds a reference to shmem, it should override this method
// to forget about the shmem _without_ releasing it.
virtual void OnActorDestroy() {}
virtual const char *Name() { return "TextureHost"; }
virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
@ -480,6 +484,8 @@ public:
virtual const char *Name() MOZ_OVERRIDE { return "ShmemTextureHost"; }
virtual void OnActorDestroy() MOZ_OVERRIDE;
protected:
mozilla::ipc::Shmem* mShmem;
ISurfaceAllocator* mDeallocator;
@ -710,6 +716,8 @@ public:
// see bug 865908 about fixing this.
virtual void ForgetBuffer() {}
void OnActorDestroy();
protected:
/**
* Should be implemented by the backend-specific DeprecatedTextureHost classes

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

@ -112,6 +112,13 @@ ISurfaceAllocator::AllocSurfaceDescriptorWithCaps(const gfxIntSize& aSize,
return true;
}
/* static */ bool
ISurfaceAllocator::IsShmem(SurfaceDescriptor* aSurface)
{
return aSurface && (aSurface->type() == SurfaceDescriptor::TShmem ||
aSurface->type() == SurfaceDescriptor::TYCbCrImage ||
aSurface->type() == SurfaceDescriptor::TRGBImage);
}
void
ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)

View File

@ -123,6 +123,10 @@ ISurfaceAllocator() {}
{
return nullptr;
}
// Returns true if aSurface wraps a Shmem.
static bool IsShmem(SurfaceDescriptor* aSurface);
protected:
// this method is needed for a temporary fix, will be removed after
// DeprecatedTextureClient/Host rework.