2007-11-07 Geoff Norton <gnorton@novell.com>
authorGeoff Norton <grompf@sublimeintervention.com>
Wed, 7 Nov 2007 18:28:11 +0000 (18:28 -0000)
committerGeoff Norton <grompf@sublimeintervention.com>
Wed, 7 Nov 2007 18:28:11 +0000 (18:28 -0000)
    * carbonFunctions.cs: Add CFRelease prototype.
    * Graphics.cs: When we're disposing the graphics context clean up the
    CGContext that we've created for it.

svn path=/trunk/mcs/; revision=89143

mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Graphics.cs
mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs

index 02a578ae3f8e33d83d8f1c781ce2c6bce1e5ca31..93472461c18f87a88846adc3d2f74036edf0e5ae 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-07  Geoff Norton  <gnorton@novell.com>
+
+       * carbonFunctions.cs: Add CFRelease prototype.
+       * Graphics.cs: When we're disposing the graphics context clean up the
+       CGContext that we've created for it.
+
 2007-11-06  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Bitmap.cs: Add a private, parameter-less, ctor for Bitmap so XML
index cd433fa995637b73484808e580c704d4c8d8d154..1d530035c193b46fac9e2de342357d28501fc6f3 100644 (file)
@@ -49,6 +49,7 @@ namespace System.Drawing
 #endif
        {
                internal IntPtr nativeObject = IntPtr.Zero;
+               internal IntPtr cgContext;
                private bool disposed = false;
                private static float defDpiX = 0;
                private static float defDpiY = 0;
@@ -276,8 +277,11 @@ namespace System.Drawing
                                status = GDIPlus.GdipDeleteGraphics (nativeObject);
                                nativeObject = IntPtr.Zero;
                                GDIPlus.CheckStatus (status);
+                               if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && cgContext != IntPtr.Zero)
+                                       Carbon.CFRelease (cgContext);
                                disposed = true;                                
                        }
+
                        GC.SuppressFinalize(this);
                }
 
@@ -1658,8 +1662,8 @@ namespace System.Drawing
 
                        Status status = GDIPlus.GdipFlush (nativeObject, intention);
                         GDIPlus.CheckStatus (status);                    
-                       if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && GDIPlus.Display != IntPtr.Zero)
-                               Carbon.CGContextSynchronize (GDIPlus.Display);
+                       if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && cgContext != IntPtr.Zero)
+                               Carbon.CGContextSynchronize (cgContext);
                }
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]               
@@ -1692,18 +1696,22 @@ namespace System.Drawing
                        IntPtr graphics;
 
                        if (GDIPlus.UseCocoaDrawable) {
-                               CarbonContext cgContext = Carbon.GetCGContextForNSView (hwnd);
-                               GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
+                               CarbonContext context = Carbon.GetCGContextForNSView (hwnd);
+                               GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
+                               
+                               Graphics g = new Graphics (graphics);
+                               g.cgContext = context.ctx;
                                
-                               GDIPlus.Display = cgContext.ctx;
-                               return new Graphics (graphics);
+                               return g;
                        }
                        if (GDIPlus.UseQuartzDrawable) {
-                               CarbonContext cgContext = Carbon.GetCGContextForView (hwnd);
-                               GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
+                               CarbonContext context = Carbon.GetCGContextForView (hwnd);
+                               GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
+                               
+                               Graphics g = new Graphics (graphics);
+                               g.cgContext = context.ctx;
                                
-                               GDIPlus.Display = cgContext.ctx;
-                               return new Graphics (graphics);
+                               return g;
                        }
                        if (GDIPlus.UseX11Drawable) {
                                if (GDIPlus.Display == IntPtr.Zero) {
index 7587b89ac116479e37ea9edcfc7edb11e11c5ee4..affe0b6e108aaaf5bd0aae1cbd98cf5032130e98 100644 (file)
@@ -229,6 +229,8 @@ namespace System.Drawing {
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern IntPtr GetWindowPort (IntPtr hWnd);
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+               internal static extern int CFRelease (IntPtr cgContext);
+               [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern int CGContextClipToRect (IntPtr cgContext, HIRect clip);
                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern int CGContextClipToRects (IntPtr cgContext, HIRect [] clip_rects, int count);