Bug 923945: Fix a memory leak when fetching OS X system color space. Also move system color space retrieval code from deprecated Color Manager APIs to Core Graphics. r=mstange
authorJosh Aas <joshmoz@gmail.com>
Mon, 07 Oct 2013 16:03:19 -0500
changeset 163857 4cae3629b4b583cce681d590f1337881380df248
parent 163856 e5fedcaa0f403caa63840956480033ac166c0064
child 163858 908cbc95f1666c6fc946a4681147d47b78fab5b4
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs923945
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 923945: Fix a memory leak when fetching OS X system color space. Also move system color space retrieval code from deprecated Color Manager APIs to Core Graphics. r=mstange
gfx/2d/QuartzSupport.mm
--- a/gfx/2d/QuartzSupport.mm
+++ b/gfx/2d/QuartzSupport.mm
@@ -453,36 +453,30 @@ MacIOSurface::CGLTexImageIOSurface2D(voi
                                                 GetDevicePixelWidth(),
                                                 GetDevicePixelHeight(),
                                                 LOCAL_GL_BGRA,
                                                 LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV,
                                                 mIOSurfacePtr, 0);
 }
 
 CGColorSpaceRef CreateSystemColorSpace() {
-    CMProfileRef system_profile = nullptr;
-    CGColorSpaceRef cspace = nullptr;
-
-    if (::CMGetSystemProfile(&system_profile) == noErr) {
-      // Create a colorspace with the systems profile
-      cspace = ::CGColorSpaceCreateWithPlatformColorSpace(system_profile);
-      ::CMCloseProfile(system_profile);
-    } else {
-      // Default to generic
-      cspace = ::CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
-    }
-
-    return cspace;
+  CGColorSpaceRef cspace = ::CGDisplayCopyColorSpace(::CGMainDisplayID());
+  if (!cspace) {
+    cspace = ::CGColorSpaceCreateDeviceRGB();
+  }
+  return cspace;
 }
 
 CGContextRef MacIOSurface::CreateIOSurfaceContext() {
+  CGColorSpaceRef cspace = CreateSystemColorSpace();
   CGContextRef ref = MacIOSurfaceLib::IOSurfaceContextCreate(mIOSurfacePtr,
                                                 GetDevicePixelWidth(),
                                                 GetDevicePixelHeight(),
-                                                8, 32, CreateSystemColorSpace(), 0x2002);
+                                                8, 32, cspace, 0x2002);
+  ::CGColorSpaceRelease(cspace);
   return ref;
 }
 
 nsCARenderer::~nsCARenderer() {
   Destroy();
 }
 
 void cgdata_release_callback(void *aCGData, const void *data, size_t size) {
@@ -634,19 +628,17 @@ nsresult nsCARenderer::SetupRenderer(voi
     CGColorSpaceRef colorSpace = CreateSystemColorSpace();
 
     mCGImage = ::CGImageCreate(aWidth * intScaleFactor, aHeight * intScaleFactor,
                 8, 32, aWidth * intScaleFactor * 4, colorSpace,
                 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
                 dataProvider, nullptr, true, kCGRenderingIntentDefault);
 
     ::CGDataProviderRelease(dataProvider);
-    if (colorSpace) {
-      ::CGColorSpaceRelease(colorSpace);
-    }
+    ::CGColorSpaceRelease(colorSpace);
     if (!mCGImage) {
       mUnsupportedWidth = aWidth;
       mUnsupportedHeight = aHeight;
       Destroy();
       return NS_ERROR_FAILURE;
     }
   }