From 1179090250a76b1eb61b34f46ed8660bf89bb38f Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Fri, 18 Jul 2014 06:21:24 -0700 Subject: [PATCH] Bug 1039883 - release Tiled layer's gralloc when an application is background r=nical --- gfx/layers/client/ClientTiledThebesLayer.cpp | 1 + gfx/layers/client/TiledContentClient.cpp | 7 ++++--- gfx/layers/client/TiledContentClient.h | 2 +- gfx/layers/composite/CompositableHost.h | 2 +- gfx/layers/composite/TiledContentHost.cpp | 13 +++++++++++++ gfx/layers/composite/TiledContentHost.h | 3 +++ gfx/layers/ipc/ISurfaceAllocator.cpp | 6 ++++++ gfx/layers/ipc/ISurfaceAllocator.h | 2 ++ gfx/layers/ipc/SharedBufferManagerChild.cpp | 19 +++++++++++++++---- gfx/layers/ipc/SharedBufferManagerChild.h | 5 ++++- gfx/layers/opengl/GrallocTextureClient.cpp | 6 ++++-- 11 files changed, 54 insertions(+), 12 deletions(-) diff --git a/gfx/layers/client/ClientTiledThebesLayer.cpp b/gfx/layers/client/ClientTiledThebesLayer.cpp index 86a3c0eff47a..7f5c7c8cfa09 100644 --- a/gfx/layers/client/ClientTiledThebesLayer.cpp +++ b/gfx/layers/client/ClientTiledThebesLayer.cpp @@ -47,6 +47,7 @@ ClientTiledThebesLayer::ClearCachedResources() if (mContentClient) { mContentClient->ClearCachedResources(); } + mValidRegion.SetEmpty(); } void diff --git a/gfx/layers/client/TiledContentClient.cpp b/gfx/layers/client/TiledContentClient.cpp index f1682a592a47..047b403836d5 100644 --- a/gfx/layers/client/TiledContentClient.cpp +++ b/gfx/layers/client/TiledContentClient.cpp @@ -101,8 +101,8 @@ TiledContentClient::TiledContentClient(ClientTiledThebesLayer* aThebesLayer, void TiledContentClient::ClearCachedResources() { - mTiledBuffer.DiscardBackBuffers(); - mLowPrecisionTiledBuffer.DiscardBackBuffers(); + mTiledBuffer.DiscardBuffers(); + mLowPrecisionTiledBuffer.DiscardBuffers(); } void @@ -678,10 +678,11 @@ ClientTiledLayerBuffer::Release() } void -ClientTiledLayerBuffer::DiscardBackBuffers() +ClientTiledLayerBuffer::DiscardBuffers() { for (size_t i = 0; i < mRetainedTiles.Length(); i++) { if (mRetainedTiles[i].IsPlaceholderTile()) continue; + mRetainedTiles[i].DiscardFrontBuffer(); mRetainedTiles[i].DiscardBackBuffer(); } } diff --git a/gfx/layers/client/TiledContentClient.h b/gfx/layers/client/TiledContentClient.h index d73461c8c894..776d68c4a771 100644 --- a/gfx/layers/client/TiledContentClient.h +++ b/gfx/layers/client/TiledContentClient.h @@ -380,7 +380,7 @@ public: void Release(); - void DiscardBackBuffers(); + void DiscardBuffers(); const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; } diff --git a/gfx/layers/composite/CompositableHost.h b/gfx/layers/composite/CompositableHost.h index acf7799d0c88..8f6b3cddebb0 100644 --- a/gfx/layers/composite/CompositableHost.h +++ b/gfx/layers/composite/CompositableHost.h @@ -235,7 +235,7 @@ public: // detached in any case. if aLayer is null, then we will only detach if we are // not async. // Only force detach if the IPDL tree is being shutdown. - void Detach(Layer* aLayer = nullptr, AttachFlags aFlags = NO_FLAGS) + virtual void Detach(Layer* aLayer = nullptr, AttachFlags aFlags = NO_FLAGS) { if (!mKeepAttached || aLayer == mLayer || diff --git a/gfx/layers/composite/TiledContentHost.cpp b/gfx/layers/composite/TiledContentHost.cpp index e01815893eca..68cb1583cf0c 100644 --- a/gfx/layers/composite/TiledContentHost.cpp +++ b/gfx/layers/composite/TiledContentHost.cpp @@ -233,6 +233,19 @@ TiledContentHost::Attach(Layer* aLayer, } void +TiledContentHost::Detach(Layer* aLayer, + AttachFlags aFlags /* = NO_FLAGS */) +{ + if (!mKeepAttached || aLayer == mLayer || aFlags & FORCE_DETACH) { + mTiledBuffer = TiledLayerBufferComposite(); + mLowPrecisionTiledBuffer = TiledLayerBufferComposite(); + mOldTiledBuffer = TiledLayerBufferComposite(); + mOldLowPrecisionTiledBuffer = TiledLayerBufferComposite(); + } + CompositableHost::Detach(aLayer,aFlags); +} + +void TiledContentHost::UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, const SurfaceDescriptorTiles& aTiledDescriptor) { diff --git a/gfx/layers/composite/TiledContentHost.h b/gfx/layers/composite/TiledContentHost.h index 7ae497ca0207..508af2289ef1 100644 --- a/gfx/layers/composite/TiledContentHost.h +++ b/gfx/layers/composite/TiledContentHost.h @@ -229,6 +229,9 @@ public: Compositor* aCompositor, AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE; + virtual void Detach(Layer* aLayer = nullptr, + AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE; + #ifdef MOZ_DUMP_PAINTING virtual void Dump(std::stringstream& aStream, const char* aPrefix="", diff --git a/gfx/layers/ipc/ISurfaceAllocator.cpp b/gfx/layers/ipc/ISurfaceAllocator.cpp index 929ff47d46e2..ae81b75a392e 100644 --- a/gfx/layers/ipc/ISurfaceAllocator.cpp +++ b/gfx/layers/ipc/ISurfaceAllocator.cpp @@ -327,5 +327,11 @@ ISurfaceAllocator::DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle) SharedBufferManagerChild::GetSingleton()->DeallocGrallocBuffer(*aHandle); } +void +ISurfaceAllocator::DropGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle) +{ + SharedBufferManagerChild::GetSingleton()->DropGrallocBuffer(*aHandle); +} + } // namespace layers } // namespace mozilla diff --git a/gfx/layers/ipc/ISurfaceAllocator.h b/gfx/layers/ipc/ISurfaceAllocator.h index 0c7b7007414a..d0a070847b41 100644 --- a/gfx/layers/ipc/ISurfaceAllocator.h +++ b/gfx/layers/ipc/ISurfaceAllocator.h @@ -162,6 +162,8 @@ public: void DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle); + void DropGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle); + virtual bool IPCOpen() const { return true; } virtual bool IsSameProcess() const = 0; diff --git a/gfx/layers/ipc/SharedBufferManagerChild.cpp b/gfx/layers/ipc/SharedBufferManagerChild.cpp index bb2a1e6c0610..40c66fd45cc6 100644 --- a/gfx/layers/ipc/SharedBufferManagerChild.cpp +++ b/gfx/layers/ipc/SharedBufferManagerChild.cpp @@ -317,18 +317,29 @@ SharedBufferManagerChild::DeallocGrallocBufferNow(const mozilla::layers::MaybeMa #endif } -bool SharedBufferManagerChild::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle) +void +SharedBufferManagerChild::DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle) { #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC - NS_ASSERTION(handle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TGrallocBufferRef, "shouldn't go this way"); - int64_t bufferKey = handle.get_GrallocBufferRef().mKey; + int64_t bufferKey = -1; + if (aHandle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) { + bufferKey = aHandle.get_MagicGrallocBufferHandle().mRef.mKey; + } else if (aHandle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TGrallocBufferRef) { + bufferKey = aHandle.get_GrallocBufferRef().mKey; + } else { + return; + } { MutexAutoLock lock(mBufferMutex); - NS_ASSERTION(mBuffers.count(bufferKey) != 0, "No such buffer"); mBuffers.erase(bufferKey); } #endif +} + +bool SharedBufferManagerChild::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle) +{ + DropGrallocBuffer(aHandle); return true; } diff --git a/gfx/layers/ipc/SharedBufferManagerChild.h b/gfx/layers/ipc/SharedBufferManagerChild.h index 734fb03e9b44..8f6f11ec30f7 100644 --- a/gfx/layers/ipc/SharedBufferManagerChild.h +++ b/gfx/layers/ipc/SharedBufferManagerChild.h @@ -104,7 +104,10 @@ public: void DeallocGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer); - virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle); + void + DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle); + + virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle); #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC android::sp GetGraphicBuffer(int64_t key); diff --git a/gfx/layers/opengl/GrallocTextureClient.cpp b/gfx/layers/opengl/GrallocTextureClient.cpp index c20934320c8e..d8212cfcb78b 100644 --- a/gfx/layers/opengl/GrallocTextureClient.cpp +++ b/gfx/layers/opengl/GrallocTextureClient.cpp @@ -47,9 +47,11 @@ GrallocTextureClientOGL::GrallocTextureClientOGL(ISurfaceAllocator* aAllocator, GrallocTextureClientOGL::~GrallocTextureClientOGL() { MOZ_COUNT_DTOR(GrallocTextureClientOGL); - if (ShouldDeallocateInDestructor()) { - ISurfaceAllocator* allocator = GetAllocator(); + ISurfaceAllocator* allocator = GetAllocator(); + if (ShouldDeallocateInDestructor()) { allocator->DeallocGrallocBuffer(&mGrallocHandle); + } else { + allocator->DropGrallocBuffer(&mGrallocHandle); } } -- 2.11.4.GIT