Author: gnorton
Date: 2007-11-07 16:11:35 -0500 (Wed, 07 Nov 2007)
New Revision: 89163

Modified:
   trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
   trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs
Log:
2007-11-07  Geoff Norton  <[EMAIL PROTECTED]>

    * carbonFunctions.cs:
    * Graphics.cs: QDBeginCGContext does not support nested calls.
    We need to ref count our context but this will have clipping/CTM collisions
    Support old-style context creation as well.


Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2007-11-07 
20:46:10 UTC (rev 89162)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2007-11-07 
21:11:35 UTC (rev 89163)
@@ -1,5 +1,12 @@
 2007-11-07  Geoff Norton  <[EMAIL PROTECTED]>
 
+       * carbonFunctions.cs: 
+       * Graphics.cs: QDBeginCGContext does not support nested calls.
+       We need to ref count our context but this will have clipping/CTM 
collisions
+       Support old-style context creation as well.
+
+2007-11-07  Geoff Norton  <[EMAIL PROTECTED]>
+
        * carbonFunctions.cs: Code cleanup and refactor to use 
        QDBeginCGContext/QDEndCGContext
        * Graphics.cs: Refactor to use QDBeginCGContext/QDEndCGContext

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2007-11-07 
20:46:10 UTC (rev 89162)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2007-11-07 
21:11:35 UTC (rev 89163)
@@ -278,7 +278,7 @@
                                nativeObject = IntPtr.Zero;
                                GDIPlus.CheckStatus (status);
                                if ((GDIPlus.UseQuartzDrawable || 
GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero) {
-                                       Carbon.QDEndCGContext (context.port, 
ref context.ctx);
+                                       Carbon.ReleaseContext (context.port);
                                }
                                disposed = true;                                
                        }

Modified: trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs    
2007-11-07 20:46:10 UTC (rev 89162)
+++ trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs    
2007-11-07 21:11:35 UTC (rev 89163)
@@ -31,6 +31,7 @@
 #undef EnableNCClipping
 #undef DebugClipping
 #undef DebugDrawing
+#undef UseQDContext
 
 using System.Collections;
 using System.Reflection;
@@ -41,6 +42,9 @@
 
        [SuppressUnmanagedCodeSecurity]
        internal class Carbon {
+               internal static Hashtable contextReference = new Hashtable ();
+               internal static Hashtable contextMap = new Hashtable ();
+
 #if EnableClipping
                internal static Type handle_type;
                internal static FieldInfo handle_children_field;
@@ -95,7 +99,7 @@
                        window = GetControlOwner (handle);
                        port = GetWindowPort (window);
                        
-                       QDBeginCGContext (port, ref context);
+                       context = GetContext (port);
 
                        GetWindowBounds (window, 32, ref window_bounds);
                        HIViewGetBounds (handle, ref view_bounds);
@@ -201,6 +205,53 @@
 #endif
                        return new CarbonContext (port, context, 
(int)view_bounds.size.width, (int)view_bounds.size.height);
                }
+
+               internal static IntPtr GetContext (IntPtr port) {
+                       IntPtr context = IntPtr.Zero;
+
+#if UseQDContext
+                       if (contextMap [port] != null)
+                               context = (IntPtr) contextMap [port];
+
+                       if (context == IntPtr.Zero) {
+                               QDBeginCGContext (port, ref context);
+                               contextMap [port] = context;
+                       }
+
+                       if (contextReference [port] != null)
+                               contextReference [port] = ((int) 
contextReference [port]) + 1;
+                       else
+                               contextReference [port] = 1;
+#else
+                       CreateCGContextForPort (port, ref context);
+
+                       contextMap [port] = context;
+#endif
+
+                       return context;
+               }
+
+               internal static void ReleaseContext (IntPtr port) {
+                       IntPtr context = IntPtr.Zero;
+                       
+#if UseQDContext
+                       if (contextReference [port] != null) {
+                               contextReference [port] = ((int) 
contextReference [port]) - 1;
+
+                               if (0 >= (int) contextReference [port]) {
+                                       context = (IntPtr) contextMap [port];
+                                       QDEndCGContext (port, ref context);
+       
+                                       contextMap [port] = null;
+                                       contextReference [port] = null;
+                               }
+                       }
+#else
+                       context = (IntPtr) contextMap [port];
+                       CFRelease (context);
+#endif
+               }
+
                #region Cocoa Methods
                [DllImport("libobjc.dylib")]
                public static extern IntPtr objc_getClass(string className); 
@@ -227,6 +278,10 @@
                [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 void CreateCGContextForPort (IntPtr 
port, ref IntPtr context);
+               [DllImport 
("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+               internal static extern void CFRelease (IntPtr context);
+               [DllImport 
("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern void QDBeginCGContext (IntPtr port, ref 
IntPtr context);
                [DllImport 
("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
                internal static extern void QDEndCGContext (IntPtr port, ref 
IntPtr context);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to