Bug 764125; store a reference to the backing surface in DrawTargetCairo; r=Bas
authorNicholas Cameron <ncameron@mozilla.com>
Tue, 24 Jul 2012 22:18:38 +1200
changeset 100534 0aaf4ca5e3b1d4984c50b4963f9d9135e88b7a50
parent 100533 fb9dbab5aff6746519c2265864ee86ff661f63a9
child 100535 436db785018e693e5bf1054f0cd600f22d6ffa05
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs764125
milestone17.0a1
Bug 764125; store a reference to the backing surface in DrawTargetCairo; r=Bas
gfx/2d/DrawTargetCairo.cpp
gfx/2d/DrawTargetCairo.h
gfx/2d/SourceSurfaceCairo.cpp
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -240,16 +240,19 @@ DrawTargetCairo::DrawTargetCairo()
 
 DrawTargetCairo::~DrawTargetCairo()
 {
   MarkSnapshotsIndependent();
   if (mPathObserver) {
     mPathObserver->ForgetDrawTarget();
   }
   cairo_destroy(mContext);
+  if (mSurface) {
+    cairo_surface_destroy(mSurface);
+  }
 }
 
 IntSize
 DrawTargetCairo::GetSize()
 {
   return mSize;
 }
 
@@ -718,16 +721,18 @@ DrawTargetCairo::CreateSimilarDrawTarget
 
   return NULL;
 }
 
 bool
 DrawTargetCairo::Init(cairo_surface_t* aSurface, const IntSize& aSize)
 {
   mContext = cairo_create(aSurface);
+  mSurface = aSurface;
+  cairo_surface_reference(mSurface);
   mSize = aSize;
 
   return true;
 }
 
 void *
 DrawTargetCairo::GetNativeSurface(NativeSurfaceType aType)
 {
--- a/gfx/2d/DrawTargetCairo.h
+++ b/gfx/2d/DrawTargetCairo.h
@@ -152,16 +152,17 @@ private: // methods
   void WillChange(const Path* aPath = NULL);
 
   // Call if there is any reason to disassociate all snapshots from this draw
   // target; for example, because we're going to be destroyed.
   void MarkSnapshotsIndependent();
 
 private: // data
   cairo_t* mContext;
+  cairo_surface_t* mSurface;
   IntSize mSize;
   std::vector<SourceSurfaceCairo*> mSnapshots;
   mutable RefPtr<CairoPathContext> mPathObserver;
 };
 
 }
 }
 
--- a/gfx/2d/SourceSurfaceCairo.cpp
+++ b/gfx/2d/SourceSurfaceCairo.cpp
@@ -98,16 +98,17 @@ SourceSurfaceCairo::DrawTargetWillChange
     cairo_surface_t* surface = cairo_surface_create_similar(mSurface,
                                                             GfxFormatToCairoContent(mFormat),
                                                             mSize.width, mSize.height);
     cairo_t* ctx = cairo_create(surface);
     cairo_pattern_t* pat = cairo_pattern_create_for_surface(mSurface);
     cairo_set_source(ctx, pat);
     cairo_paint(ctx);
     cairo_destroy(ctx);
+    cairo_pattern_destroy(pat);
 
     // Swap in this new surface.
     cairo_surface_destroy(mSurface);
     mSurface = surface;
   }
 }
 
 void