Bug 647710: Fix color profile leak. r=josh a=dveditz
authorBenoit Girard <b56girard@gmail.com>
Wed, 06 Apr 2011 16:00:45 -0700
changeset 63386 a2840fe77a5b168ba0244140bf142cec7b827c94
parent 63381 7bb8f4cb0fd021efe97d6a4963a056f4c7a41103
child 63387 46171fccbedad63dd408985d725422d69e2d7b1e
push id43
push userjosh@mozilla.com
push dateFri, 08 Apr 2011 18:35:08 +0000
reviewersjosh, dveditz
bugs647710
milestone2.0.1pre
Bug 647710: Fix color profile leak. r=josh a=dveditz
layout/generic/nsObjectFrame.cpp
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -533,16 +533,17 @@ private:
 #ifdef XP_MACOSX
   NP_CGContext                              mCGPluginPortCopy;
 #ifndef NP_NO_QUICKDRAW
   NP_Port                                   mQDPluginPortCopy;
 #endif
   PRInt32                                   mInCGPaintLevel;
   nsIOSurface                              *mIOSurface;
   nsCARenderer                              mCARenderer;
+  CGColorSpaceRef                           mColorProfile;
   static nsCOMPtr<nsITimer>                *sCATimer;
   static nsTArray<nsPluginInstanceOwner*>  *sCARefreshListeners;
   PRBool                                    mSentInitialTopLevelWindowEvent;
 #endif
 
   // Initially, the event loop nesting level we were created on, it's updated
   // if we detect the appshell is on a lower level as long as we're not stopped.
   // We delay DoStopPlugin() until the appshell reaches this level or lower.
@@ -3176,16 +3177,17 @@ nsPluginInstanceOwner::nsPluginInstanceO
 #ifdef XP_MACOSX
   memset(&mCGPluginPortCopy, 0, sizeof(NP_CGContext));
 #ifndef NP_NO_QUICKDRAW
   memset(&mQDPluginPortCopy, 0, sizeof(NP_Port));
 #endif
   mInCGPaintLevel = 0;
   mSentInitialTopLevelWindowEvent = PR_FALSE;
   mIOSurface = nsnull;
+  mColorProfile = nsnull;
   mPluginPortChanged = PR_FALSE;
 #endif
   mContentFocused = PR_FALSE;
   mWidgetVisible = PR_TRUE;
   mPluginWindowVisible = PR_FALSE;
   mNumCachedAttrs = 0;
   mNumCachedParams = 0;
   mCachedAttrParamNames = nsnull;
@@ -4372,18 +4374,18 @@ void nsPluginInstanceOwner::SetupCARefre
 
 void nsPluginInstanceOwner::RenderCoreAnimation(CGContextRef aCGContext, 
                                                 int aWidth, int aHeight)
 {
   if (aWidth == 0 || aHeight == 0)
     return;
 
   if (!mIOSurface || 
-     (mIOSurface->GetWidth() != (size_t)aWidth || 
-      mIOSurface->GetHeight() != (size_t)aHeight)) {
+      (mIOSurface->GetWidth() != (size_t)aWidth || 
+       mIOSurface->GetHeight() != (size_t)aHeight)) {
     if (mIOSurface) {
       delete mIOSurface;
     }
 
     // If the renderer is backed by an IOSurface, resize it as required.
     mIOSurface = nsIOSurface::CreateIOSurface(aWidth, aHeight);
     if (mIOSurface) {
       nsIOSurface *attachSurface = nsIOSurface::LookupSurface(
@@ -4394,16 +4396,20 @@ void nsPluginInstanceOwner::RenderCoreAn
         NS_ERROR("IOSurface attachment failed");
         delete attachSurface;
         delete mIOSurface;
         mIOSurface = NULL;
       }
     }
   }
 
+  if (!mColorProfile) {
+    mColorProfile = CreateSystemColorSpace();
+  }
+
   if (mCARenderer.isInit() == false) {
     void *caLayer = NULL;
     mInstance->GetValueFromPlugin(NPPVpluginCoreAnimationLayer, &caLayer);
     if (!caLayer) {
       return;
     }
 
     mCARenderer.SetupRenderer(caLayer, aWidth, aHeight);
@@ -4411,18 +4417,18 @@ void nsPluginInstanceOwner::RenderCoreAn
     // Setting up the CALayer requires resetting the painting otherwise we
     // get garbage for the first few frames.
     FixUpPluginWindow(ePluginPaintDisable);
     FixUpPluginWindow(ePluginPaintEnable);
   }
 
   CGImageRef caImage = NULL;
   nsresult rt = mCARenderer.Render(aWidth, aHeight, &caImage);
-  if (rt == NS_OK && mIOSurface) {
-    nsCARenderer::DrawSurfaceToCGContext(aCGContext, mIOSurface, CreateSystemColorSpace(),
+  if (rt == NS_OK && mIOSurface && mColorProfile) {
+    nsCARenderer::DrawSurfaceToCGContext(aCGContext, mIOSurface, mColorProfile,
                                          0, 0, aWidth, aHeight);
   } else if (rt == NS_OK && caImage != NULL) {
     // Significant speed up by resetting the scaling
     ::CGContextSetInterpolationQuality(aCGContext, kCGInterpolationNone );
     ::CGContextTranslateCTM(aCGContext, 0, aHeight);
     ::CGContextScaleCTM(aCGContext, 1.0, -1.0);
 
     ::CGContextDrawImage(aCGContext, CGRectMake(0,0,aWidth,aHeight), caImage);
@@ -5744,16 +5750,18 @@ nsPluginInstanceOwner::Destroy()
 #ifdef MAC_CARBON_PLUGINS
   // stop the timer explicitly to reduce reference count.
   CancelTimer();
 #endif
 #ifdef XP_MACOSX
   RemoveFromCARefreshTimer(this);
   if (mIOSurface)
     delete mIOSurface;
+  if (mColorProfile)
+    ::CGColorSpaceRelease(mColorProfile);  
 #endif
 
   // unregister context menu listener
   if (mCXMenuListener) {
     mCXMenuListener->Destroy(mContent);
     mCXMenuListener = nsnull;
   }