In .:
authorGeoff Norton <grompf@sublimeintervention.com>
Wed, 23 Jan 2008 14:03:22 +0000 (14:03 -0000)
committerGeoff Norton <grompf@sublimeintervention.com>
Wed, 23 Jan 2008 14:03:22 +0000 (14:03 -0000)
2008-01-23  Geoff Norton  <gnorton@novell.com>

* carbonFunctions.cs: If we get a -ve size from carbon, swizzle to
0 to prevent a OOM from cairo malloc.  Remove support for
GetCGContextForNSView as its deprecated and doesn't work.
* gdipFunctions.cs: Refactor the environment variable support out
and make the Carbon driver the default on a Mac.  Fix RunningOnUnix
to report true on the mac.
* Graphics.cs: Drop support for CocoaDrawable.

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

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

index f3c08a62e103232e77426c10f114ec0f1a7edda9..3f329baa93eb8588191575a8ec52fdb81cb764cc 100644 (file)
@@ -1,3 +1,13 @@
+2008-01-23  Geoff Norton  <gnorton@novell.com>
+
+       * carbonFunctions.cs: If we get a -ve size from carbon, swizzle to 
+       0 to prevent a OOM from cairo malloc.  Remove support for
+       GetCGContextForNSView as its deprecated and doesn't work.
+       * gdipFunctions.cs: Refactor the environment variable support out
+       and make the Carbon driver the default on a Mac.  Fix RunningOnUnix
+       to report true on the mac.
+       * Graphics.cs: Drop support for CocoaDrawable.
+
 2008-01-21  Geoff Norton  <gnorton@novell.com>
 
        * Graphics.cs: Support Graphics.FromHwnd (IntPtr.Zero) on X11
index 463094baa9bc9621cf0cd54b8788134960cef2cc..0463817564a4c54bbdd89956196191f0bb074b1c 100644 (file)
@@ -188,7 +188,7 @@ namespace System.Drawing
 
                        if (GDIPlus.UseX11Drawable) {
                                CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
-                       } else if (GDIPlus.UseCocoaDrawable || GDIPlus.UseQuartzDrawable) {
+                       } else if (GDIPlus.UseCarbonDrawable) {
                                CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
                        } else {
                                CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
@@ -274,7 +274,7 @@ namespace System.Drawing
                {
                        Status status;
                        if (! disposed) {
-                               if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero) {
+                               if (GDIPlus.UseCarbonDrawable && context.ctx != IntPtr.Zero) {
                                        Flush ();
                                        Carbon.CGContextSynchronize (context.ctx);
                                        Carbon.ReleaseContext (context.port, context.ctx);
@@ -1665,7 +1665,7 @@ namespace System.Drawing
 
                        Status status = GDIPlus.GdipFlush (nativeObject, intention);
                         GDIPlus.CheckStatus (status);                    
-                       if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero)
+                       if (GDIPlus.UseCarbonDrawable && context.ctx != IntPtr.Zero)
                                Carbon.CGContextSynchronize (context.ctx);
                }
 
@@ -1698,21 +1698,9 @@ namespace System.Drawing
                {
                        IntPtr graphics;
 
-                       if (GDIPlus.UseCocoaDrawable) {
-                               throw new NotImplementedException ();
-/* TODO: Fix this code to handle the new libgdiplus
-                               CarbonContext context = Carbon.GetCGContextForNSView (hwnd);
-                               GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
-                               
-                               Graphics g = new Graphics (graphics);
-                               g.context = context;
-                               
-                               return g;
-*/
-                       }
-                       if (GDIPlus.UseQuartzDrawable) {
+                       if (GDIPlus.UseCarbonDrawable) {
                                CarbonContext context = Carbon.GetCGContextForView (hwnd);
-                               GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
+                               GDIPlus.GdipCreateFromContext_macosx (context.ctx, context.width, context.height, out graphics);
                                
                                Graphics g = new Graphics (graphics);
                                g.context = context;
index a0179ebde8eaf3f047ccc271678a4bfd034fdcff..21883b3588ded6b2801e128f7d357c4db5f9f682 100644 (file)
@@ -51,15 +51,6 @@ namespace System.Drawing {
                        }
                }
 
-               internal static CarbonContext GetCGContextForNSView (IntPtr handle) {
-                       IntPtr context = IntPtr.Zero;
-                       Rect view_bounds = new Rect ();
-
-                       context = objc_msgSend (objc_msgSend (objc_getClass ("NSGraphicsContext"), sel_registerName ("currentContext")), sel_registerName ("graphicsPort"));
-                       objc_msgSend_stret (ref view_bounds, handle, sel_registerName ("bounds"));
-                       return new CarbonContext (IntPtr.Zero, context, (int)view_bounds.size.width, (int)view_bounds.size.height);
-               }
-
                internal static CarbonContext GetCGContextForView (IntPtr handle) {
                        IntPtr context = IntPtr.Zero;
                        IntPtr port = IntPtr.Zero;
@@ -88,6 +79,9 @@ namespace System.Drawing {
                        HIViewGetBounds (handle, ref view_bounds);
 
                        HIViewConvertRect (ref view_bounds, handle, IntPtr.Zero);
+                       
+                       if (view_bounds.size.height < 0) view_bounds.size.height = 0;
+                       if (view_bounds.size.width < 0) view_bounds.size.width = 0;
 
                        CGContextTranslateCTM (context, view_bounds.origin.x, (window_bounds.bottom - window_bounds.top) - (view_bounds.origin.y + view_bounds.size.height));
 
index 0376ce47f54f1f6e67f8b84872379b43c0902f4f..2f150b27851d6ffb08a5e21601ea94c9a1ba5097 100644 (file)
@@ -59,9 +59,8 @@ namespace System.Drawing
                public const int FACESIZE = 32;
                public const int LANG_NEUTRAL = 0;
                public static IntPtr Display = IntPtr.Zero;
-               public static bool UseX11Drawable;
-               public static bool UseQuartzDrawable = (Environment.GetEnvironmentVariable ("MONO_MWF_USE_CARBON_BACKEND") != null);
-               public static bool UseCocoaDrawable = (Environment.GetEnvironmentVariable ("MONO_GDIP_USE_COCOA_BACKEND") != null);
+               public static bool UseX11Drawable = false;
+               public static bool UseCarbonDrawable = false;
 
                #region gdiplus.dll functions
 
@@ -99,10 +98,27 @@ namespace System.Drawing
 
                static GDIPlus ()
                {
-                       // check for Unix platforms - see FAQ for more details
-                       // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
                        int platform = (int) Environment.OSVersion.Platform;
-                       UseX11Drawable = ((platform == 4) || (platform == 128));
+                       if ((platform == 4) || (platform == 128)) {
+                               if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null || Environment.GetEnvironmentVariable ("MONO_MWF_MAC_FORCE_X11") != null) {
+                                       UseX11Drawable = true;
+                               } else {
+                                       IntPtr buf = Marshal.AllocHGlobal (8192);
+                                       // This is kind of a hack but gets us sysname from uname (struct utsname *name) on
+                                       // linux and darwin
+                                       if (uname (buf) != 0) {
+                                               // WTH: We couldn't detect the OS; lets default to X11
+                                               UseX11Drawable = true;
+                                       } else {
+                                               string os = Marshal.PtrToStringAnsi (buf);
+                                               if (os == "Darwin")
+                                                       UseCarbonDrawable = true;
+                                               else
+                                                       UseX11Drawable = true;
+                                       }
+                                       Marshal.FreeHGlobal (buf);
+                               }
+                       }
 
                        GdiplusStartupInput input = GdiplusStartupInput.MakeGdiplusStartupInput();
                        GdiplusStartupOutput output = GdiplusStartupOutput.MakeGdiplusStartupOutput();
@@ -122,12 +138,12 @@ namespace System.Drawing
 
                static public bool RunningOnWindows ()
                {
-                       return !UseX11Drawable;
+                       return !UseX11Drawable && !UseCarbonDrawable;
                }
 
                static public bool RunningOnUnix ()
                {
-                       return UseX11Drawable;
+                       return UseX11Drawable || UseCarbonDrawable;
                }
                
                // Copies a Ptr to an array of Points and releases the memory
@@ -1922,7 +1938,7 @@ namespace System.Drawing
                
                /* Mac only function calls */
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipCreateFromQuartz_macosx (IntPtr cgref, int width, int height, out IntPtr graphics);
+               internal static extern Status GdipCreateFromContext_macosx (IntPtr cgref, int width, int height, out IntPtr graphics);
 
                /* Linux only function calls*/
                [DllImport("gdiplus.dll")]
@@ -1963,6 +1979,9 @@ namespace System.Drawing
                        StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, 
                        StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect, 
                        MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+
+               [DllImport ("libc")]
+               static extern int uname (IntPtr buf);
 #endregion
        }
 }