Bug 915869 - Let the GrallocBufferActor keep an _array_ of backrefs to TextureHosts referencing it - r=nical

This commit is contained in:
Benoit Jacob 2013-09-17 14:48:08 -04:00
parent c37a134542
commit 2dcf3bf15d
3 changed files with 42 additions and 33 deletions

View File

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

View File

@ -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<DeprecatedTextureHost*, 2> mDeprecatedTextureHosts;
friend class ISurfaceAllocator;
};

View File

@ -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<GrallocBufferActor*>(aSurfaceDescriptor.get_SurfaceDescriptorGralloc().bufferParent());
actor->SetDeprecatedTextureHost(aDeprecatedTextureHost);
if (aSurfaceDescriptor && IsSurfaceDescriptorValid(*aSurfaceDescriptor)) {
GrallocBufferActor* actor = static_cast<GrallocBufferActor*>(aSurfaceDescriptor->get_SurfaceDescriptorGralloc().bufferParent());
actor->AddDeprecatedTextureHost(aDeprecatedTextureHost);
}
}
static void
RemoveDeprecatedTextureHostFromGrallocBufferActor(DeprecatedTextureHost* aDeprecatedTextureHost, const SurfaceDescriptor* aSurfaceDescriptor)
{
if (aSurfaceDescriptor && IsSurfaceDescriptorValid(*aSurfaceDescriptor)) {
GrallocBufferActor* actor = static_cast<GrallocBufferActor*>(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