X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Drawing%2FSystem.Drawing%2FgdipFunctions.cs;h=c42b38a20bc841fd273be353c3a5e9f7e37d830b;hb=411a37af27905eaa44dac1a31f6387a11c0b0244;hp=5147116609f3fe81556720b34429d83ad6c459e1;hpb=18751d4475cda0456b25597c3d4f9634c14f8a68;p=mono.git diff --git a/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs b/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs index 5147116609f..c42b38a20bc 100644 --- a/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs +++ b/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs @@ -7,7 +7,7 @@ // Sanjay Gupta (gsanjay@novell.com) // Ravindra (rkumar@novell.com) // Peter Dennis Bartok (pbartok@novell.com) -// Sebastien Pouliot +// Sebastien Pouliot // // Copyright (C) 2004 - 2007 Novell, Inc (http://www.novell.com) // @@ -43,11 +43,18 @@ using System.Runtime.InteropServices.ComTypes; namespace System.Drawing { + internal partial class SafeNativeMethods + { + internal partial class Gdip : GDIPlus + { + + } + } + /// /// GDI+ API Functions /// - [SuppressUnmanagedCodeSecurity] - internal static class GDIPlus { + internal /*static*/ class GDIPlus { public const int FACESIZE = 32; public const int LANG_NEUTRAL = 0; public static IntPtr Display = IntPtr.Zero; @@ -55,27 +62,29 @@ namespace System.Drawing public static bool UseCarbonDrawable = false; public static bool UseCocoaDrawable = false; + private const string GdiPlus = "gdiplus"; + #region gdiplus.dll functions // startup / shutdown - [DllImport("gdiplus.dll")] + [DllImport(GdiPlus)] static internal extern Status GdiplusStartup(ref ulong token, ref GdiplusStartupInput input, ref GdiplusStartupOutput output); - [DllImport("gdiplus.dll")] + [DllImport(GdiPlus)] static internal extern void GdiplusShutdown(ref ulong token); - + internal static ulong GdiPlusToken = 0; static void ProcessExit (object sender, EventArgs e) - { + { // Called all pending objects and claim any pending handle before // shutting down - GC.Collect (); + GC.Collect (); GC.WaitForPendingFinalizers (); -#if false +#if false GdiPlusToken = 0; // This causes crashes in because this call occurs before all - // managed GDI+ objects are finalized. When they are finalized + // managed GDI+ objects are finalized. When they are finalized // they call into a shutdown GDI+ and we crash. GdiplusShutdown (ref GdiPlusToken); @@ -91,8 +100,14 @@ namespace System.Drawing static GDIPlus () { +#if NETSTANDARD1_6 + bool isUnix = !RuntimeInformation.IsOSPlatform (OSPlatform.Windows); +#else int platform = (int) Environment.OSVersion.Platform; - if ((platform == 4) || (platform == 6) || (platform == 128)) { + bool isUnix = (platform == 4) || (platform == 6) || (platform == 128); +#endif + + if (isUnix) { if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null || Environment.GetEnvironmentVariable ("MONO_MWF_MAC_FORCE_X11") != null) { UseX11Drawable = true; } else { @@ -126,7 +141,9 @@ namespace System.Drawing } // under MS 1.x this event is raised only for the default application domain +#if !NETSTANDARD1_6 AppDomain.CurrentDomain.ProcessExit += new EventHandler (ProcessExit); +#endif } static public bool RunningOnWindows () @@ -138,62 +155,62 @@ namespace System.Drawing { return UseX11Drawable || UseCarbonDrawable || UseCocoaDrawable; } - + // Copies a Ptr to an array of Points and releases the memory static public void FromUnManagedMemoryToPointI (IntPtr prt, Point [] pts) - { + { int nPointSize = Marshal.SizeOf (pts[0]); IntPtr pos = prt; for (int i=0; i 0 && buf != IntPtr.Zero) { Marshal.Copy (managedBuf, 0, (IntPtr) (buf.ToInt64()), bytesRead); } @@ -1800,7 +1817,7 @@ namespace System.Drawing if (!stream.CanSeek && (bufsz == 10) && peek) { // Special 'hack' to support peeking of the type for gdi+ on non-seekable streams } - + if (peek) { if (stream.CanSeek) { // If we are peeking bytes, then go back to original position before peeking @@ -1810,7 +1827,7 @@ namespace System.Drawing } } } - + return bytesRead; } @@ -1826,7 +1843,7 @@ namespace System.Drawing } } - public long StreamSeekImpl (int offset, int whence) + public long StreamSeekImpl (int offset, int whence) { // Make sure we have a valid 'whence'. if ((whence < 0) || (whence > 2)) @@ -1867,7 +1884,7 @@ namespace System.Drawing } } - public int StreamPutBytesImpl (IntPtr buf, int bufsz) + public int StreamPutBytesImpl (IntPtr buf, int bufsz) { if (bufsz > managedBuf.Length) managedBuf = new byte[bufsz]; @@ -1887,10 +1904,10 @@ namespace System.Drawing return null; } } - + public void StreamCloseImpl () { - stream.Close (); + stream.Dispose (); } public StreamCloseDelegate CloseDelegate { @@ -1904,7 +1921,7 @@ namespace System.Drawing return null; } } - + public long StreamSizeImpl () { try { @@ -1927,49 +1944,49 @@ namespace System.Drawing } } - + /* Mac only function calls */ - [DllImport("gdiplus.dll")] + [DllImport(GdiPlus)] internal static extern Status GdipCreateFromContext_macosx (IntPtr cgref, int width, int height, out IntPtr graphics); /* Linux only function calls*/ - [DllImport("gdiplus.dll")] + [DllImport(GdiPlus)] internal static extern Status GdipSetVisibleClip_linux (IntPtr graphics, ref Rectangle rect); - - [DllImport("gdiplus.dll")] + + [DllImport(GdiPlus)] internal static extern Status GdipCreateFromXDrawable_linux (IntPtr drawable, IntPtr display, out IntPtr graphics); - + // Stream functions for non-Win32 (libgdiplus specific) - [DllImport("gdiplus.dll")] - static internal extern Status GdipLoadImageFromDelegate_linux (StreamGetHeaderDelegate getHeader, - StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, + [DllImport(GdiPlus)] + static internal extern Status GdipLoadImageFromDelegate_linux (StreamGetHeaderDelegate getHeader, + StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, out IntPtr image); - [DllImport("gdiplus.dll")] - static internal extern Status GdipSaveImageToDelegate_linux (IntPtr image, StreamGetBytesDelegate getBytes, - StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, - StreamSizeDelegate size, ref Guid encoderClsID, IntPtr encoderParameters); + [DllImport(GdiPlus)] + static internal extern Status GdipSaveImageToDelegate_linux (IntPtr image, StreamGetBytesDelegate getBytes, + StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, + StreamSizeDelegate size, ref Guid encoderClsID, IntPtr encoderParameters); - [DllImport("gdiplus.dll")] - static internal extern Status GdipCreateMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader, - StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, + [DllImport(GdiPlus)] + static internal extern Status GdipCreateMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader, + StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, out IntPtr metafile); - [DllImport("gdiplus.dll")] - static internal extern Status GdipGetMetafileHeaderFromDelegate_linux (StreamGetHeaderDelegate getHeader, - StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, + [DllImport(GdiPlus)] + static internal extern Status GdipGetMetafileHeaderFromDelegate_linux (StreamGetHeaderDelegate getHeader, + StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr header); - [DllImport("gdiplus.dll")] - static internal extern Status GdipRecordMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader, - StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, - StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect, + [DllImport(GdiPlus)] + static internal extern Status GdipRecordMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader, + StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, + StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile); - [DllImport("gdiplus.dll")] - static internal extern Status GdipRecordMetafileFromDelegateI_linux (StreamGetHeaderDelegate getHeader, - StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, - StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect, + [DllImport(GdiPlus)] + static internal extern Status GdipRecordMetafileFromDelegateI_linux (StreamGetHeaderDelegate getHeader, + 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")]