Bug 916118 - Simplify the deallocation flags in TextureClient/Host. r=nrc

This commit is contained in:
Nicolas Silva 2013-09-26 18:00:23 +02:00
parent f43d24af2c
commit bc11135ff0
16 changed files with 30 additions and 41 deletions

View File

@ -60,12 +60,11 @@ const TextureFlags TEXTURE_TILE = 1 << 15;
// from the previous texture. // from the previous texture.
const TextureFlags TEXTURE_COPY_PREVIOUS = 1 << 24; const TextureFlags TEXTURE_COPY_PREVIOUS = 1 << 24;
// Who is responsible for deallocating the shared data. // Who is responsible for deallocating the shared data.
// if none of the following two flags is set, the shared data will not be // if TEXTURE_DEALLOCATE_CLIENT is set, the shared data is deallocated on the
// deallocated by the layers system. It is not necessarily a leak, it could // client side and requires some extra synchronizaion to ensure race-free
// be a choice from another part of gecko that wants to keep the data alive // deallocation.
// for some reason. The default behaviour is to deallocate on the host side. // The default behaviour is to deallocate on the host side.
const TextureFlags TEXTURE_DEALLOCATE_CLIENT = 1 << 25; const TextureFlags TEXTURE_DEALLOCATE_CLIENT = 1 << 25;
const TextureFlags TEXTURE_DEALLOCATE_HOST = 1 << 26;
// After being shared ith the compositor side, an immutable texture is never // After being shared ith the compositor side, an immutable texture is never
// modified, it can only be read. It is safe to not Lock/Unlock immutable // modified, it can only be read. It is safe to not Lock/Unlock immutable
// textures. // textures.
@ -80,8 +79,7 @@ const TextureFlags TEXTURE_IMMEDIATE_UPLOAD = 1 << 28;
const TextureFlags TEXTURE_DOUBLE_BUFFERED = 1 << 29; const TextureFlags TEXTURE_DOUBLE_BUFFERED = 1 << 29;
// the default flags // the default flags
const TextureFlags TEXTURE_FLAGS_DEFAULT = TEXTURE_DEALLOCATE_HOST const TextureFlags TEXTURE_FLAGS_DEFAULT = TEXTURE_FRONT;
| TEXTURE_FRONT;
static inline bool static inline bool
TextureRequiresLocking(TextureFlags aFlags) TextureRequiresLocking(TextureFlags aFlags)

View File

@ -290,8 +290,7 @@ GrallocImage::GetTextureClient()
return nullptr; return nullptr;
} }
const SurfaceDescriptorGralloc& desc = sd.get_SurfaceDescriptorGralloc(); const SurfaceDescriptorGralloc& desc = sd.get_SurfaceDescriptorGralloc();
TextureFlags flags = desc.external() ? TEXTURE_DEALLOCATE_CLIENT TextureFlags flags = desc.external() ? TEXTURE_DEALLOCATE_CLIENT : 0;
: TEXTURE_DEALLOCATE_HOST;
if (desc.isRBSwapped()) { if (desc.isRBSwapped()) {
flags |= TEXTURE_RB_SWAPPED; flags |= TEXTURE_RB_SWAPPED;
} }

View File

@ -225,7 +225,6 @@ AppendToString(nsACString& s, TextureFlags flags,
AppendFlag(TEXTURE_DISALLOW_BIGIMAGE); AppendFlag(TEXTURE_DISALLOW_BIGIMAGE);
AppendFlag(TEXTURE_ALLOW_REPEAT); AppendFlag(TEXTURE_ALLOW_REPEAT);
AppendFlag(TEXTURE_NEW_TILE); AppendFlag(TEXTURE_NEW_TILE);
AppendFlag(TEXTURE_DEALLOCATE_HOST);
#undef AppendFlag #undef AppendFlag
} }

View File

@ -42,11 +42,11 @@ CanvasClient::CreateCanvasClient(CanvasClientType aType,
{ {
if (aType == CanvasClientGLContext && if (aType == CanvasClientGLContext &&
aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) { aForwarder->GetCompositorBackendType() == LAYERS_OPENGL) {
aFlags &= ~TEXTURE_DEALLOCATE_HOST; aFlags &= TEXTURE_DEALLOCATE_CLIENT;
return new DeprecatedCanvasClientSurfaceStream(aForwarder, aFlags); return new DeprecatedCanvasClientSurfaceStream(aForwarder, aFlags);
} }
if (gfxPlatform::GetPlatform()->UseDeprecatedTextures()) { if (gfxPlatform::GetPlatform()->UseDeprecatedTextures()) {
aFlags &= ~TEXTURE_DEALLOCATE_HOST; aFlags &= TEXTURE_DEALLOCATE_CLIENT;
return new DeprecatedCanvasClient2D(aForwarder, aFlags); return new DeprecatedCanvasClient2D(aForwarder, aFlags);
} }
return new CanvasClient2D(aForwarder, aFlags); return new CanvasClient2D(aForwarder, aFlags);

View File

@ -98,12 +98,12 @@ ClientCanvasLayer::RenderLayer()
} }
if (!mGLContext) { if (!mGLContext) {
// GLContext's SurfaceStream handles ownership itself,
// and doesn't require layers to do any deallocation.
flags |= TEXTURE_DEALLOCATE_HOST;
// We don't support locking for buffer surfaces currently // We don't support locking for buffer surfaces currently
flags |= TEXTURE_IMMEDIATE_UPLOAD; flags |= TEXTURE_IMMEDIATE_UPLOAD;
} else {
// GLContext's SurfaceStream handles ownership itself,
// and doesn't require layers to do any deallocation.
flags |= TEXTURE_DEALLOCATE_CLIENT;
} }
mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(), mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
ClientManager(), flags); ClientManager(), flags);

View File

@ -231,7 +231,7 @@ CompositableClient::RemoveTextureClient(TextureClient* aClient)
MOZ_ASSERT(aClient); MOZ_ASSERT(aClient);
mTexturesToRemove.AppendElement(TextureIDAndFlags(aClient->GetID(), mTexturesToRemove.AppendElement(TextureIDAndFlags(aClient->GetID(),
aClient->GetFlags())); aClient->GetFlags()));
if (!(aClient->GetFlags() & TEXTURE_DEALLOCATE_HOST)) { if (aClient->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) {
TextureClientData* data = aClient->DropTextureData(); TextureClientData* data = aClient->DropTextureData();
if (data) { if (data) {
mTexturesToRemoveCallbacks[aClient->GetID()] = data; mTexturesToRemoveCallbacks[aClient->GetID()] = data;

View File

@ -201,7 +201,7 @@ ContentClientRemoteBuffer::BuildDeprecatedTextureClients(ContentType aType,
mContentType = aType; mContentType = aType;
mSize = gfx::IntSize(aRect.width, aRect.height); mSize = gfx::IntSize(aRect.width, aRect.height);
mTextureInfo.mTextureFlags = aFlags | TEXTURE_DEALLOCATE_HOST; mTextureInfo.mTextureFlags = aFlags & ~TEXTURE_DEALLOCATE_CLIENT;
if (!CreateAndAllocateDeprecatedTextureClient(mDeprecatedTextureClient)) { if (!CreateAndAllocateDeprecatedTextureClient(mDeprecatedTextureClient)) {
return; return;

View File

@ -404,7 +404,7 @@ private:
void NotifyBufferCreated(ContentType aType, uint32_t aFlags) void NotifyBufferCreated(ContentType aType, uint32_t aFlags)
{ {
mTextureInfo.mTextureFlags = aFlags | TEXTURE_DEALLOCATE_HOST; mTextureInfo.mTextureFlags = aFlags & ~TEXTURE_DEALLOCATE_CLIENT;
mContentType = aType; mContentType = aType;
mForwarder->CreatedIncrementalBuffer(this, mForwarder->CreatedIncrementalBuffer(this,

View File

@ -165,7 +165,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
bool bufferCreated = false; bool bufferCreated = false;
if (!mFrontBuffer) { if (!mFrontBuffer) {
mFrontBuffer = CreateBufferTextureClient(gfx::FORMAT_YUV, TEXTURE_DEALLOCATE_HOST); mFrontBuffer = CreateBufferTextureClient(gfx::FORMAT_YUV, TEXTURE_FLAGS_DEFAULT);
gfx::IntSize ySize(data->mYSize.width, data->mYSize.height); gfx::IntSize ySize(data->mYSize.width, data->mYSize.height);
gfx::IntSize cbCrSize(data->mCbCrSize.width, data->mCbCrSize.height); gfx::IntSize cbCrSize(data->mCbCrSize.width, data->mCbCrSize.height);
if (!mFrontBuffer->AsTextureClientYCbCr()->AllocateForYCbCr(ySize, cbCrSize, data->mStereoMode)) { if (!mFrontBuffer->AsTextureClientYCbCr()->AllocateForYCbCr(ySize, cbCrSize, data->mStereoMode)) {
@ -226,7 +226,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
gfxImageFormat format gfxImageFormat format
= gfxPlatform::GetPlatform()->OptimalFormatForContent(surface->GetContentType()); = gfxPlatform::GetPlatform()->OptimalFormatForContent(surface->GetContentType());
mFrontBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format), mFrontBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format),
TEXTURE_DEALLOCATE_HOST); TEXTURE_FLAGS_DEFAULT);
MOZ_ASSERT(mFrontBuffer->AsTextureClientSurface()); MOZ_ASSERT(mFrontBuffer->AsTextureClientSurface());
mFrontBuffer->AsTextureClientSurface()->AllocateForSurface(size); mFrontBuffer->AsTextureClientSurface()->AllocateForSurface(size);

View File

@ -398,7 +398,7 @@ DeprecatedTextureClientShmem::ReleaseResources()
ShadowLayerForwarder::CloseDescriptor(mDescriptor); ShadowLayerForwarder::CloseDescriptor(mDescriptor);
} }
if (mTextureInfo.mTextureFlags & TEXTURE_DEALLOCATE_HOST) { if (!(mTextureInfo.mTextureFlags & TEXTURE_DEALLOCATE_CLIENT)) {
mDescriptor = SurfaceDescriptor(); mDescriptor = SurfaceDescriptor();
return; return;
} }

View File

@ -195,13 +195,6 @@ protected:
void AddFlags(TextureFlags aFlags) void AddFlags(TextureFlags aFlags)
{ {
MOZ_ASSERT(!IsSharedWithCompositor()); MOZ_ASSERT(!IsSharedWithCompositor());
// make sure we don't deallocate on both client and host;
MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT && aFlags & TEXTURE_DEALLOCATE_HOST));
if (aFlags & TEXTURE_DEALLOCATE_CLIENT) {
mFlags &= ~TEXTURE_DEALLOCATE_HOST;
} else if (aFlags & TEXTURE_DEALLOCATE_HOST) {
mFlags &= ~TEXTURE_DEALLOCATE_CLIENT;
}
mFlags |= aFlags; mFlags |= aFlags;
} }

View File

@ -39,7 +39,7 @@ CompositableHost::~CompositableHost()
RefPtr<TextureHost> it = mFirstTexture; RefPtr<TextureHost> it = mFirstTexture;
while (it) { while (it) {
if (it->GetFlags() & TEXTURE_DEALLOCATE_HOST) { if (!(it->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)) {
it->DeallocateSharedData(); it->DeallocateSharedData();
} }
it = it->GetNextSibling(); it = it->GetNextSibling();

View File

@ -260,7 +260,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
TextureFlags flags = texture->GetFlags(); TextureFlags flags = texture->GetFlags();
if (flags & TEXTURE_DEALLOCATE_HOST) { if (!(flags & TEXTURE_DEALLOCATE_CLIENT)) {
texture->DeallocateSharedData(); texture->DeallocateSharedData();
} }
@ -269,7 +269,7 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
// if it is not the host that deallocates the shared data, then we need // 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 // to notfy the client side to tell when it is safe to deallocate or
// reuse it. // reuse it.
if (!(flags & TEXTURE_DEALLOCATE_HOST)) { if (flags & TEXTURE_DEALLOCATE_CLIENT) {
replyv.push_back(ReplyTextureRemoved(op.compositableParent(), nullptr, replyv.push_back(ReplyTextureRemoved(op.compositableParent(), nullptr,
op.textureID())); op.textureID()));
} }

View File

@ -122,14 +122,14 @@ ImageBridgeChild::RemoveTexture(CompositableClient* aCompositable,
uint64_t aTexture, uint64_t aTexture,
TextureFlags aFlags) TextureFlags aFlags)
{ {
if (aFlags & TEXTURE_DEALLOCATE_HOST) { if (aFlags & TEXTURE_DEALLOCATE_CLIENT) {
// if deallocation happens on the host side, we don't need the transaction // if deallocation happens on the host side, we need the transaction
// to be synchronous. // to be synchronous.
mTxn->AddNoSwapEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(), mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture, aTexture,
aFlags)); aFlags));
} else { } else {
mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(), mTxn->AddNoSwapEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture, aTexture,
aFlags)); aFlags));
} }

View File

@ -411,7 +411,7 @@ ShadowLayerForwarder::RemoveTexture(CompositableClient* aCompositable,
mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(), mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture, aTexture,
aFlags)); aFlags));
if (!(aFlags & TEXTURE_DEALLOCATE_HOST)) { if (aFlags & TEXTURE_DEALLOCATE_CLIENT) {
mTxn->MarkSyncTransaction(); mTxn->MarkSyncTransaction();
} }
} }

View File

@ -21,8 +21,8 @@ SharedTextureClientOGL::SharedTextureClientOGL(TextureFlags aFlags)
, mHandle(0) , mHandle(0)
, mInverted(false) , mInverted(false)
{ {
MOZ_ASSERT(!(aFlags & (TEXTURE_DEALLOCATE_CLIENT|TEXTURE_DEALLOCATE_HOST)), MOZ_ASSERT(aFlags & TEXTURE_DEALLOCATE_CLIENT,
"SharedTextureClientOGL doesn't know how to release textures!"); "SharedTextureClientOGL is always owned externally");
} }
SharedTextureClientOGL::~SharedTextureClientOGL() SharedTextureClientOGL::~SharedTextureClientOGL()