Author: gnorton
Date: 2007-11-07 16:35:12 -0500 (Wed, 07 Nov 2007)
New Revision: 89166
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: Use QDBeginCGContext / QDEndCGContext to leverage OS caching
of CGContexts when possible. If we are still using the context returned by
QDBeginCGContext, then create a new CGContext for this graphics object.
Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2007-11-07
21:31:41 UTC (rev 89165)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2007-11-07
21:35:12 UTC (rev 89166)
@@ -1,6 +1,13 @@
2007-11-07 Geoff Norton <[EMAIL PROTECTED]>
* carbonFunctions.cs:
+ * Graphics.cs: Use QDBeginCGContext / QDEndCGContext to leverage OS
caching
+ of CGContexts when possible. If we are still using the context
returned by
+ QDBeginCGContext, then create a new CGContext for this graphics object.
+
+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/Graphics.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs 2007-11-07
21:31:41 UTC (rev 89165)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs 2007-11-07
21:35:12 UTC (rev 89166)
@@ -278,7 +278,7 @@
nativeObject = IntPtr.Zero;
GDIPlus.CheckStatus (status);
if ((GDIPlus.UseQuartzDrawable ||
GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero) {
- Carbon.ReleaseContext (context.port);
+ Carbon.ReleaseContext (context.port,
context.ctx);
}
disposed = true;
}
Modified: trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs
2007-11-07 21:31:41 UTC (rev 89165)
+++ trunk/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs
2007-11-07 21:35:12 UTC (rev 89166)
@@ -31,7 +31,6 @@
#undef EnableNCClipping
#undef DebugClipping
#undef DebugDrawing
-#undef UseQDContext
using System.Collections;
using System.Reflection;
@@ -43,7 +42,7 @@
[SuppressUnmanagedCodeSecurity]
internal class Carbon {
internal static Hashtable contextReference = new Hashtable ();
- internal static Hashtable contextMap = new Hashtable ();
+ internal static object lockobj = new object ();
#if EnableClipping
internal static Type handle_type;
@@ -209,47 +208,27 @@
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;
+ lock (lockobj) {
+ if (contextReference [port] != null) {
+ CreateCGContextForPort (port, ref
context);
+ } else {
+ QDBeginCGContext (port, ref context);
+ contextReference [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];
+ internal static void ReleaseContext (IntPtr port, IntPtr
context) {
+ lock (lockobj) {
+ if (contextReference [port] != null && context
== (IntPtr) contextReference [port]) {
QDEndCGContext (port, ref context);
-
- contextMap [port] = null;
contextReference [port] = null;
+ } else {
+ CFRelease (context);
}
}
-#else
- context = (IntPtr) contextMap [port];
- CFRelease (context);
-#endif
}
#region Cocoa Methods
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches