Bug 894405 - fix leaks on a CLOSED TREE
authorJames Willcox <jwillcox@mozilla.com>
Fri, 19 Jul 2013 00:23:07 -0400
changeset 139233 a8aa3006efb903d78f93a817bbc35bf8fef512fc
parent 139232 c99f3b6eecd5baa662984f72fdb847ee03b9d6bf
child 139234 c3061aed82c9d9585259d8b91a9c89aded27dcb4
push id1890
push userryanvm@gmail.com
push dateFri, 19 Jul 2013 17:44:21 +0000
treeherderfx-team@20848adc9980 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs894405
milestone25.0a1
Bug 894405 - fix leaks on a CLOSED TREE
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -349,16 +349,32 @@ SurfaceStreamHostOGL::DeleteTextures()
 }
 
 void
 SurfaceStreamHostOGL::SwapTexturesImpl(const SurfaceDescriptor& aImage,
                                        nsIntRegion* aRegion)
 {
   MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceStreamDescriptor,
              "Invalid descriptor");
+
+  mStreamGL = nullptr;
+
+  if (aImage.type() == SurfaceDescriptor::TSurfaceStreamDescriptor) {
+    // Bug 894405
+    //
+    // The SurfaceStream's GLContext was refed before being passed up to us, so
+    // we need to ensure it gets unrefed when we are finished.
+    const SurfaceStreamDescriptor& streamDesc =
+        aImage.get_SurfaceStreamDescriptor();
+
+    SurfaceStream* surfStream = SurfaceStream::FromHandle(streamDesc.handle());
+    if (surfStream) {
+      mStreamGL = dont_AddRef(surfStream->GLContext());
+    }
+  } 
 }
 
 void
 SurfaceStreamHostOGL::Unlock()
 {
   // We don't know what this is unless we're locked
   mFormat = gfx::FORMAT_UNKNOWN;
 }
@@ -917,38 +933,16 @@ SurfaceStreamHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTextureHandle,
                      false,
                      GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
-void
-SurfaceStreamHostOGL::SetBuffer(SurfaceDescriptor* aBuffer, ISurfaceAllocator* aAllocator)
-{
-  MOZ_ASSERT(!mBuffer, "Will leak the old mBuffer");
-  mBuffer = aBuffer;
-  mDeAllocator = aAllocator;
-
-  if (mBuffer && mBuffer->type() == SurfaceDescriptor::TSurfaceStreamDescriptor) {
-    // Bug 894405
-    //
-    // The SurfaceStream's GLContext was refed before being passed up to us, so
-    // we need to ensure it gets unrefed when we are finished.
-    const SurfaceStreamDescriptor& streamDesc =
-        mBuffer->get_SurfaceStreamDescriptor();
-
-    SurfaceStream* surfStream = SurfaceStream::FromHandle(streamDesc.handle());
-    if (surfStream) {
-      mStreamGL = dont_AddRef(surfStream->GLContext());
-    }
-  } 
-}
-
 already_AddRefed<gfxImageSurface>
 TiledDeprecatedTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTextureHandle,
                      false,
                      GetTextureFormat())
     : nullptr;
   return surf.forget();
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -480,18 +480,16 @@ public:
   ContentType GetContentType() {
     return (mFormat == gfx::FORMAT_B8G8R8A8) ?
              gfxASurface::CONTENT_COLOR_ALPHA :
              gfxASurface::CONTENT_COLOR;
   }
 
   virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE;
 
-  virtual void SetBuffer(SurfaceDescriptor* aBuffer, ISurfaceAllocator* aAllocator) MOZ_OVERRIDE;
-
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual const char* Name() { return "SurfaceStreamHostOGL"; }
 #endif
 
   SurfaceStreamHostOGL()
     : mGL(nullptr)
     , mTextureHandle(0)
     , mTextureTarget(LOCAL_GL_TEXTURE_2D)