From 2dcf3bf15d19d994b21f5ec8c9ad3bd87a9ea9f7 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 17 Sep 2013 14:48:08 -0400 Subject: [PATCH] Bug 915869 - Let the GrallocBufferActor keep an _array_ of backrefs to TextureHosts referencing it - r=nical --- gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp | 28 ++++++++------- gfx/layers/ipc/ShadowLayerUtilsGralloc.h | 5 +-- gfx/layers/opengl/TextureHostOGL.cpp | 42 ++++++++++++---------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp index dabd68601a0a..e90b70b3e5be 100644 --- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp +++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp @@ -216,7 +216,6 @@ int64_t GrallocReporter::sAmount = 0; GrallocBufferActor::GrallocBufferActor() : mAllocBytes(0) -, mDeprecatedTextureHost(nullptr) { static bool registered; if (!registered) { @@ -267,24 +266,27 @@ GrallocBufferActor::Create(const gfxIntSize& aSize, return actor; } -// used only for hacky fix in gecko 23 for bug 862324 +// used only for hacky fix for bug 862324 void GrallocBufferActor::ActorDestroy(ActorDestroyReason) { - if (mDeprecatedTextureHost) { - mDeprecatedTextureHost->ForgetBuffer(); + for (size_t i = 0; i < mDeprecatedTextureHosts.Length(); i++) { + mDeprecatedTextureHosts[i]->ForgetBuffer(); } - mDeprecatedTextureHost = nullptr; } -// used only for hacky fix in gecko 23 for bug 862324 -void GrallocBufferActor::SetDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost) +// used only for hacky fix for bug 862324 +void GrallocBufferActor::AddDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost) { - if (mDeprecatedTextureHost && - mDeprecatedTextureHost != aDeprecatedTextureHost) - { - mDeprecatedTextureHost->ForgetBuffer(); - } - mDeprecatedTextureHost = aDeprecatedTextureHost; + mDeprecatedTextureHosts.AppendElement(aDeprecatedTextureHost); +} + +// used only for hacky fix for bug 862324 +void GrallocBufferActor::RemoveDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost) +{ + mDeprecatedTextureHosts.RemoveElement(aDeprecatedTextureHost); + // that should be the only occurence, otherwise we'd leak this TextureHost... + // assert that that's not happening. + MOZ_ASSERT(!mDeprecatedTextureHosts.Contains(aDeprecatedTextureHost)); } /*static*/ already_AddRefed diff --git a/gfx/layers/ipc/ShadowLayerUtilsGralloc.h b/gfx/layers/ipc/ShadowLayerUtilsGralloc.h index 3ae4bbfb3e22..eb111d914314 100644 --- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.h +++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.h @@ -87,7 +87,8 @@ public: // used only for hacky fix in gecko 23 for bug 862324 // see bug 865908 about fixing this. - void SetDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost); + void AddDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost); + void RemoveDeprecatedTextureHost(DeprecatedTextureHost* aDeprecatedTextureHost); android::GraphicBuffer* GetGraphicBuffer(); @@ -104,7 +105,7 @@ private: // used only for hacky fix in gecko 23 for bug 862324 // see bug 865908 about fixing this. - DeprecatedTextureHost* mDeprecatedTextureHost; + nsAutoTArray mDeprecatedTextureHosts; friend class ISurfaceAllocator; }; diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index 07b0dda42b9d..706aa368ef6a 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -1108,11 +1108,20 @@ GrallocDeprecatedTextureHostOGL::DeleteTextures() // only used for hacky fix in gecko 23 for bug 862324 static void -RegisterDeprecatedTextureHostAtGrallocBufferActor(DeprecatedTextureHost* aDeprecatedTextureHost, const SurfaceDescriptor& aSurfaceDescriptor) +AddDeprecatedTextureHostToGrallocBufferActor(DeprecatedTextureHost* aDeprecatedTextureHost, const SurfaceDescriptor* aSurfaceDescriptor) { - if (IsSurfaceDescriptorValid(aSurfaceDescriptor)) { - GrallocBufferActor* actor = static_cast(aSurfaceDescriptor.get_SurfaceDescriptorGralloc().bufferParent()); - actor->SetDeprecatedTextureHost(aDeprecatedTextureHost); + if (aSurfaceDescriptor && IsSurfaceDescriptorValid(*aSurfaceDescriptor)) { + GrallocBufferActor* actor = static_cast(aSurfaceDescriptor->get_SurfaceDescriptorGralloc().bufferParent()); + actor->AddDeprecatedTextureHost(aDeprecatedTextureHost); + } +} + +static void +RemoveDeprecatedTextureHostFromGrallocBufferActor(DeprecatedTextureHost* aDeprecatedTextureHost, const SurfaceDescriptor* aSurfaceDescriptor) +{ + if (aSurfaceDescriptor && IsSurfaceDescriptorValid(*aSurfaceDescriptor)) { + GrallocBufferActor* actor = static_cast(aSurfaceDescriptor->get_SurfaceDescriptorGralloc().bufferParent()); + actor->RemoveDeprecatedTextureHost(aDeprecatedTextureHost); } } @@ -1130,11 +1139,6 @@ GrallocDeprecatedTextureHostOGL::SwapTexturesImpl(const SurfaceDescriptor& aImag { MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc); - if (mBuffer) { - // only done for hacky fix in gecko 23 for bug 862324. - RegisterDeprecatedTextureHostAtGrallocBufferActor(nullptr, *mBuffer); - } - const SurfaceDescriptorGralloc& desc = aImage.get_SurfaceDescriptorGralloc(); mGraphicBuffer = GrallocBufferActor::GetFrom(desc); mIsRBSwapped = desc.isRBSwapped(); @@ -1198,11 +1202,9 @@ GrallocDeprecatedTextureHostOGL::~GrallocDeprecatedTextureHostOGL() DeleteTextures(); // only done for hacky fix in gecko 23 for bug 862324. - if (mBuffer) { - // make sure that if the GrallocBufferActor survives us, it doesn't keep a dangling - // pointer to us. - RegisterDeprecatedTextureHostAtGrallocBufferActor(nullptr, *mBuffer); - } + // make sure that if the GrallocBufferActor survives us, it doesn't keep a dangling + // pointer to us. + RemoveDeprecatedTextureHostFromGrallocBufferActor(this, mBuffer); } bool @@ -1222,12 +1224,16 @@ void GrallocDeprecatedTextureHostOGL::SetBuffer(SurfaceDescriptor* aBuffer, ISurfaceAllocator* aAllocator) { MOZ_ASSERT(!mBuffer, "Will leak the old mBuffer"); + + if (aBuffer != mBuffer) { + // only done for hacky fix in gecko 23 for bug 862324. + // Doing this in SwapTextures is not enough, as the crash could occur right after SetBuffer. + RemoveDeprecatedTextureHostFromGrallocBufferActor(this, mBuffer); + AddDeprecatedTextureHostToGrallocBufferActor(this, aBuffer); + } + mBuffer = aBuffer; mDeAllocator = aAllocator; - - // only done for hacky fix in gecko 23 for bug 862324. - // Doing this in SwapTextures is not enough, as the crash could occur right after SetBuffer. - RegisterDeprecatedTextureHostAtGrallocBufferActor(this, *mBuffer); } LayerRenderState