Bug 719628 - Fix the formatting and naming of ThebesSurfaceKey. r=mattwoodrow
authorJoe Drew <joe@drew.ca>
Fri, 27 Jan 2012 13:08:58 -0500
changeset 86833 151ed82c3193ad05d943099f3f41ab2d395bb379
parent 86832 64c5a333c0f63e2e0748c7bf02f82f4ecc40260e
child 86834 051f094b80a7dec261d96079733de0e29cbb2b63
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs719628
milestone12.0a1
Bug 719628 - Fix the formatting and naming of ThebesSurfaceKey. r=mattwoodrow
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformMac.cpp
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -524,34 +524,35 @@ gfxPlatform::GetScaledFontForFont(gfxFon
                                            aFont->GetAdjustedSize());
   return scaledFont;
 }
 
 cairo_user_data_key_t kDrawSourceSurface;
 static void
 DataSourceSurfaceDestroy(void *dataSourceSurface)
 {
-      static_cast<DataSourceSurface*>(dataSourceSurface)->Release();
+  static_cast<DataSourceSurface*>(dataSourceSurface)->Release();
 }
 
-void DestroyThebesSurface(void *data)
+UserDataKey kThebesSurfaceKey;
+void
+DestroyThebesSurface(void *data)
 {
   gfxASurface *surface = static_cast<gfxASurface*>(data);
   surface->Release();
 }
 
-UserDataKey ThebesSurfaceKey;
-
 // The semantics of this function are sort of weird. We snapshot the first
 // time and then return the snapshotted surface for the lifetime of the
 // draw target
 already_AddRefed<gfxASurface>
 gfxPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
-  void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
+  // If we have already created a thebes surface, we can just return it.
+  void *surface = aTarget->GetUserData(&kThebesSurfaceKey);
   if (surface) {
     nsRefPtr<gfxASurface> surf = static_cast<gfxASurface*>(surface);
     return surf.forget();
   }
 
   RefPtr<SourceSurface> source = aTarget->Snapshot();
   RefPtr<DataSourceSurface> data = source->GetDataSurface();
 
@@ -566,17 +567,17 @@ gfxPlatform::GetThebesSurfaceForDrawTarg
     new gfxImageSurface(data->GetData(), gfxIntSize(size.width, size.height),
                         data->Stride(), format);
 
   surf->SetData(&kDrawSourceSurface, data.forget().drop(), DataSourceSurfaceDestroy);
 
   // add a reference to be held by the drawTarget
   // careful, the reference graph is getting complicated here
   surf->AddRef();
-  aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
+  aTarget->AddUserData(&kThebesSurfaceKey, surf.get(), DestroyThebesSurface);
 
   return surf.forget();
 }
 
 RefPtr<DrawTarget>
 gfxPlatform::CreateOffscreenDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
   BackendType backend;
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -66,17 +66,17 @@ struct gfxFontStyle;
 class gfxUserFontSet;
 class gfxFontEntry;
 class gfxProxyFontEntry;
 class gfxPlatformFontList;
 class gfxTextRun;
 class nsIURI;
 class nsIAtom;
 
-extern mozilla::gfx::UserDataKey ThebesSurfaceKey;
+extern mozilla::gfx::UserDataKey kThebesSurfaceKey;
 void DestroyThebesSurface(void *data);
 
 extern cairo_user_data_key_t kDrawTarget;
 
 // pref lang id's for font prefs
 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
 // !!! don't use as bit mask, this may grow larger !!!
 
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -298,33 +298,33 @@ gfxPlatformMac::ReadAntiAliasingThreshol
 
     return threshold;
 }
 
 already_AddRefed<gfxASurface>
 gfxPlatformMac::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
   if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
-    void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
+    void *surface = aTarget->GetUserData(&kThebesSurfaceKey);
     if (surface) {
       nsRefPtr<gfxASurface> surf = static_cast<gfxQuartzSurface*>(surface);
       return surf.forget();
     } else {
       CGContextRef cg = static_cast<CGContextRef>(aTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
 
       //XXX: it would be nice to have an implicit conversion from IntSize to gfxIntSize
       IntSize intSize = aTarget->GetSize();
       gfxIntSize size(intSize.width, intSize.height);
 
       nsRefPtr<gfxASurface> surf =
         new gfxQuartzSurface(cg, size);
 
       // add a reference to be held by the drawTarget
       surf->AddRef();
-      aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
+      aTarget->AddUserData(&kThebesSurfaceKey, surf.get(), DestroyThebesSurface);
 
       return surf.forget();
     }
   }
 
   return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
 }
 
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -502,17 +502,17 @@ gfxWindowsPlatform::GetScaledFontForFont
   return scaledFont;
 }
 
 already_AddRefed<gfxASurface>
 gfxWindowsPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
 #ifdef XP_WIN
   if (aTarget->GetType() == BACKEND_DIRECT2D) {
-    void *surface = aTarget->GetUserData(&ThebesSurfaceKey);
+    void *surface = aTarget->GetUserData(&kThebesSurfaceKey);
     if (surface) {
       nsRefPtr<gfxASurface> surf = static_cast<gfxASurface*>(surface);
       return surf.forget();
     } else {
       RefPtr<ID3D10Texture2D> texture =
         static_cast<ID3D10Texture2D*>(aTarget->GetNativeSurface(NATIVE_SURFACE_D3D10_TEXTURE));
 
       if (!texture) {
@@ -521,17 +521,17 @@ gfxWindowsPlatform::GetThebesSurfaceForD
 
       aTarget->Flush();
 
       nsRefPtr<gfxASurface> surf =
         new gfxD2DSurface(texture, ContentForFormat(aTarget->GetFormat()));
 
       // add a reference to be held by the drawTarget
       surf->AddRef();
-      aTarget->AddUserData(&ThebesSurfaceKey, surf.get(), DestroyThebesSurface);
+      aTarget->AddUserData(&kThebesSurfaceKey, surf.get(), DestroyThebesSurface);
       /* "It might be worth it to clear cairo surfaces associated with a drawtarget.
 	  The strong reference means for example for D2D that cairo's scratch surface
 	  will be kept alive (well after a user being done) and consume extra VRAM.
 	  We can deal with this in a follow-up though." */
 
       // shouldn't this hold a reference?
       surf->SetData(&kDrawTarget, aTarget, NULL);
       return surf.forget();