Bug 1014355 - Fix ownership issue in X11TextureClient. r=cwiiis, a=lmandel
authorNicolas Silva <nsilva@mozilla.com>
Wed, 18 Jun 2014 19:11:12 +0200
changeset 208340 4e6018ad263903b6d931ec4c8ff6b2417a1a1548
parent 208339 358992828820708e12f17a511554fe368012d058
child 208341 defd74bd5e9d97dfdb81be9bc06e234387a487cf
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscwiiis, lmandel
bugs1014355
milestone32.0a2
Bug 1014355 - Fix ownership issue in X11TextureClient. r=cwiiis, a=lmandel
gfx/layers/basic/TextureClientX11.cpp
gfx/layers/composite/X11TextureHost.cpp
--- a/gfx/layers/basic/TextureClientX11.cpp
+++ b/gfx/layers/basic/TextureClientX11.cpp
@@ -59,38 +59,44 @@ TextureClientX11::Unlock()
 bool
 TextureClientX11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
 {
   MOZ_ASSERT(IsValid());
   if (!mSurface) {
     return false;
   }
 
+  if (!(mFlags & TextureFlags::DEALLOCATE_CLIENT)) {
+    // Pass to the host the responsibility of freeing the pixmap. ReleasePixmap means
+    // the underlying pixmap will not be deallocated in mSurface's destructor.
+    // ToSurfaceDescriptor is at most called once per TextureClient.
+    mSurface->ReleasePixmap();
+  }
+
   aOutDescriptor = SurfaceDescriptorX11(mSurface);
   return true;
 }
 
 bool
 TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags)
 {
   MOZ_ASSERT(IsValid());
+  MOZ_ASSERT(!IsAllocated());
   //MOZ_ASSERT(mFormat != gfx::FORMAT_YUV, "This TextureClient cannot use YCbCr data");
 
   gfxContentType contentType = ContentForFormat(mFormat);
   nsRefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, contentType);
   if (!surface || surface->GetType() != gfxSurfaceType::Xlib) {
     NS_ERROR("creating Xlib surface failed!");
     return false;
   }
 
   mSize = aSize;
   mSurface = static_cast<gfxXlibSurface*>(surface.get());
 
-  // The host is always responsible for freeing the pixmap.
-  mSurface->ReleasePixmap();
   return true;
 }
 
 TemporaryRef<DrawTarget>
 TextureClientX11::GetAsDrawTarget()
 {
   MOZ_ASSERT(IsValid());
   if (!mSurface) {
--- a/gfx/layers/composite/X11TextureHost.cpp
+++ b/gfx/layers/composite/X11TextureHost.cpp
@@ -20,19 +20,19 @@ using namespace mozilla::gfx;
 
 X11TextureHost::X11TextureHost(TextureFlags aFlags,
                                const SurfaceDescriptorX11& aDescriptor)
  : TextureHost(aFlags)
 {
   nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
   mSurface = surface.get();
 
-  // The host always frees the pixmap.
-  MOZ_ASSERT(!(aFlags & TextureFlags::DEALLOCATE_CLIENT));
-  mSurface->TakePixmap();
+  if (!(aFlags & TextureFlags::DEALLOCATE_CLIENT)) {
+    mSurface->TakePixmap();
+  }
 }
 
 bool
 X11TextureHost::Lock()
 {
   if (!mCompositor) {
     return false;
   }