Bug 1039883 - release Tiled layer's gralloc when an application is background r=nical

This commit is contained in:
Sotaro Ikeda 2014-07-18 06:21:24 -07:00
Родитель 9222a1a27e
Коммит 1179090250
11 изменённых файлов: 54 добавлений и 12 удалений

Просмотреть файл

@ -47,6 +47,7 @@ ClientTiledThebesLayer::ClearCachedResources()
if (mContentClient) { if (mContentClient) {
mContentClient->ClearCachedResources(); mContentClient->ClearCachedResources();
} }
mValidRegion.SetEmpty();
} }
void void

Просмотреть файл

@ -101,8 +101,8 @@ TiledContentClient::TiledContentClient(ClientTiledThebesLayer* aThebesLayer,
void void
TiledContentClient::ClearCachedResources() TiledContentClient::ClearCachedResources()
{ {
mTiledBuffer.DiscardBackBuffers(); mTiledBuffer.DiscardBuffers();
mLowPrecisionTiledBuffer.DiscardBackBuffers(); mLowPrecisionTiledBuffer.DiscardBuffers();
} }
void void
@ -678,10 +678,11 @@ ClientTiledLayerBuffer::Release()
} }
void void
ClientTiledLayerBuffer::DiscardBackBuffers() ClientTiledLayerBuffer::DiscardBuffers()
{ {
for (size_t i = 0; i < mRetainedTiles.Length(); i++) { for (size_t i = 0; i < mRetainedTiles.Length(); i++) {
if (mRetainedTiles[i].IsPlaceholderTile()) continue; if (mRetainedTiles[i].IsPlaceholderTile()) continue;
mRetainedTiles[i].DiscardFrontBuffer();
mRetainedTiles[i].DiscardBackBuffer(); mRetainedTiles[i].DiscardBackBuffer();
} }
} }

Просмотреть файл

@ -380,7 +380,7 @@ public:
void Release(); void Release();
void DiscardBackBuffers(); void DiscardBuffers();
const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; } const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; }

Просмотреть файл

@ -235,7 +235,7 @@ public:
// detached in any case. if aLayer is null, then we will only detach if we are // detached in any case. if aLayer is null, then we will only detach if we are
// not async. // not async.
// Only force detach if the IPDL tree is being shutdown. // 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 || if (!mKeepAttached ||
aLayer == mLayer || aLayer == mLayer ||

Просмотреть файл

@ -232,6 +232,19 @@ TiledContentHost::Attach(Layer* aLayer,
static_cast<ThebesLayerComposite*>(aLayer)->EnsureTiled(); static_cast<ThebesLayerComposite*>(aLayer)->EnsureTiled();
} }
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 void
TiledContentHost::UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, TiledContentHost::UseTiledLayerBuffer(ISurfaceAllocator* aAllocator,
const SurfaceDescriptorTiles& aTiledDescriptor) const SurfaceDescriptorTiles& aTiledDescriptor)

Просмотреть файл

@ -229,6 +229,9 @@ public:
Compositor* aCompositor, Compositor* aCompositor,
AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE; AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE;
virtual void Detach(Layer* aLayer = nullptr,
AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE;
#ifdef MOZ_DUMP_PAINTING #ifdef MOZ_DUMP_PAINTING
virtual void Dump(std::stringstream& aStream, virtual void Dump(std::stringstream& aStream,
const char* aPrefix="", const char* aPrefix="",

Просмотреть файл

@ -327,5 +327,11 @@ ISurfaceAllocator::DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle)
SharedBufferManagerChild::GetSingleton()->DeallocGrallocBuffer(*aHandle); SharedBufferManagerChild::GetSingleton()->DeallocGrallocBuffer(*aHandle);
} }
void
ISurfaceAllocator::DropGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle)
{
SharedBufferManagerChild::GetSingleton()->DropGrallocBuffer(*aHandle);
}
} // namespace layers } // namespace layers
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -162,6 +162,8 @@ public:
void DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle); void DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle);
void DropGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle);
virtual bool IPCOpen() const { return true; } virtual bool IPCOpen() const { return true; }
virtual bool IsSameProcess() const = 0; virtual bool IsSameProcess() const = 0;

Просмотреть файл

@ -317,18 +317,29 @@ SharedBufferManagerChild::DeallocGrallocBufferNow(const mozilla::layers::MaybeMa
#endif #endif
} }
bool SharedBufferManagerChild::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle) void
SharedBufferManagerChild::DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle)
{ {
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
NS_ASSERTION(handle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TGrallocBufferRef, "shouldn't go this way"); int64_t bufferKey = -1;
int64_t bufferKey = handle.get_GrallocBufferRef().mKey; 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); MutexAutoLock lock(mBufferMutex);
NS_ASSERTION(mBuffers.count(bufferKey) != 0, "No such buffer");
mBuffers.erase(bufferKey); mBuffers.erase(bufferKey);
} }
#endif #endif
}
bool SharedBufferManagerChild::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle)
{
DropGrallocBuffer(aHandle);
return true; return true;
} }

Просмотреть файл

@ -104,7 +104,10 @@ public:
void void
DeallocGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer); 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 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key); android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key);

Просмотреть файл

@ -47,9 +47,11 @@ GrallocTextureClientOGL::GrallocTextureClientOGL(ISurfaceAllocator* aAllocator,
GrallocTextureClientOGL::~GrallocTextureClientOGL() GrallocTextureClientOGL::~GrallocTextureClientOGL()
{ {
MOZ_COUNT_DTOR(GrallocTextureClientOGL); MOZ_COUNT_DTOR(GrallocTextureClientOGL);
if (ShouldDeallocateInDestructor()) {
ISurfaceAllocator* allocator = GetAllocator(); ISurfaceAllocator* allocator = GetAllocator();
if (ShouldDeallocateInDestructor()) {
allocator->DeallocGrallocBuffer(&mGrallocHandle); allocator->DeallocGrallocBuffer(&mGrallocHandle);
} else {
allocator->DropGrallocBuffer(&mGrallocHandle);
} }
} }