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) {
mContentClient->ClearCachedResources();
}
mValidRegion.SetEmpty();
}
void

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

@ -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();
}
}

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

@ -380,7 +380,7 @@ public:
void Release();
void DiscardBackBuffers();
void DiscardBuffers();
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
// 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 ||

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

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

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

@ -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="",

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

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

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

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

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

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

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

@ -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<android::GraphicBuffer> GetGraphicBuffer(int64_t key);

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

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