bug 1028134 - Remove dangerous public destructor of gfxContext. r=bjacob
authorJonathan Kew <jkew@mozilla.com>
Sun, 22 Jun 2014 13:28:12 +0100
changeset 189957 93cd05e483cdaae67bdec1ffdb96c4245fe2b11a
parent 189956 f41bd6b296ea881fbfbb0c294f6fa7299e9fbea9
child 189958 e0d435b1340e83a46eaa93ba1eb1758860e57ccc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbjacob
bugs1028134
milestone33.0a1
bug 1028134 - Remove dangerous public destructor of gfxContext. r=bjacob
gfx/thebes/gfxContext.h
gfx/thebes/gfxPlatformGtk.cpp
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -18,59 +18,47 @@
 #include "nsAutoPtr.h"
 
 #include "mozilla/gfx/2D.h"
 
 typedef struct _cairo cairo_t;
 struct GlyphBufferAzure;
 template <typename T> class FallibleTArray;
 
-class gfxContext;
-
-namespace mozilla {
-template<>
-struct HasDangerousPublicDestructor<gfxContext>
-{
-  static const bool value = true;
-};
-}
-
 /**
  * This is the main class for doing actual drawing. It is initialized using
  * a surface and can be drawn on. It manages various state information like
  * a current transformation matrix (CTM), a current path, current color,
  * etc.
  *
  * All drawing happens by creating a path and then stroking or filling it.
  * The functions like Rectangle and Arc do not do any drawing themselves.
  * When a path is drawn (stroked or filled), it is filled/stroked with a
  * pattern set by SetPattern, SetColor or SetSource.
  *
  * Note that the gfxContext takes coordinates in device pixels,
  * as opposed to app units.
  */
-class gfxContext {
+class gfxContext MOZ_FINAL {
     NS_INLINE_DECL_REFCOUNTING(gfxContext)
 
 public:
     /**
      * Initialize this context from a surface.
      */
     gfxContext(gfxASurface *surface);
 
     /**
      * Initialize this context from a DrawTarget.
      * Strips any transform from aTarget.
      * aTarget will be flushed in the gfxContext's destructor.
      */
     gfxContext(mozilla::gfx::DrawTarget *aTarget,
                const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point());
 
-    ~gfxContext();
-
     /**
      * Create a new gfxContext wrapping aTarget and preserving aTarget's
      * transform. Note that the transform is moved from aTarget to the resulting
      * gfxContext, aTarget will no longer have its transform.
      */
     static already_AddRefed<gfxContext> ContextForDrawTarget(mozilla::gfx::DrawTarget* aTarget);
 
     /**
@@ -725,16 +713,18 @@ public:
      * Copy a PNG encoded Data URL to the clipboard.
      */
     void CopyAsDataURL();
 #endif
 
     static mozilla::gfx::UserDataKey sDontUseAsSourceKey;
 
 private:
+    ~gfxContext();
+
   friend class GeneralPattern;
   friend struct GlyphBufferAzure;
 
   typedef mozilla::gfx::Matrix Matrix;
   typedef mozilla::gfx::DrawTarget DrawTarget;
   typedef mozilla::gfx::Color Color;
   typedef mozilla::gfx::StrokeOptions StrokeOptions;
   typedef mozilla::gfx::Float Float;
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -120,19 +120,19 @@ gfxPlatformGtk::CreateOffscreenSurface(c
         newSurface = new gfxImageSurface(ThebesIntSize(size), imageFormat);
     }
 
     if (newSurface->CairoStatus()) {
         newSurface = nullptr; // surface isn't valid for some reason
     }
 
     if (newSurface && needsClear) {
-        gfxContext tmpCtx(newSurface);
-        tmpCtx.SetOperator(gfxContext::OPERATOR_CLEAR);
-        tmpCtx.Paint();
+        nsRefPtr<gfxContext> tmpCtx = new gfxContext(newSurface);
+        tmpCtx->SetOperator(gfxContext::OPERATOR_CLEAR);
+        tmpCtx->Paint();
     }
 
     return newSurface.forget();
 }
 
 nsresult
 gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
                             const nsACString& aGenericFamily,