diff options
author | j-p <jp.bruyere@live.be> | 2018-05-05 04:43:53 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2018-05-05 04:43:53 +0300 |
commit | 56f8556df851117e3f7e529c399853c355ae1107 (patch) | |
tree | f10009c6d9f42f035663dffe82d0b2d159602397 /mcs/class/Mono.Cairo | |
parent | 89b6b4b2868314a802e22ed8f579e9d17e62300c (diff) |
[Mono.Cairo] Add OpenGL texture Surface support (#2443)
* Add OpenGL texture Surface support
* reorganize with EGL,WGL,GLX Device classes, and a single GLSurface class
Diffstat (limited to 'mcs/class/Mono.Cairo')
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo.dll.sources | 6 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/Device.cs | 101 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/EGLDevice.cs | 41 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/GLSurface.cs | 61 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/GLXDevice.cs | 49 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/NativeMethods.cs | 73 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/Surface.cs | 2 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/SurfaceType.cs | 14 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/WGLDevice.cs | 45 |
9 files changed, 391 insertions, 1 deletions
diff --git a/mcs/class/Mono.Cairo/Mono.Cairo.dll.sources b/mcs/class/Mono.Cairo/Mono.Cairo.dll.sources index 880cdf2adc3..f5129cd9ddc 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo.dll.sources +++ b/mcs/class/Mono.Cairo/Mono.Cairo.dll.sources @@ -54,4 +54,8 @@ ./Mono.Cairo/Win32Surface.cs ./Mono.Cairo/XcbSurface.cs ./Mono.Cairo/XlibSurface.cs - +./Mono.Cairo/GLSurface.cs +./Mono.Cairo/Device.cs +./Mono.Cairo/GLXDevice.cs +./Mono.Cairo/EGLDevice.cs +./Mono.Cairo/WGLDevice.cs diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/Device.cs b/mcs/class/Mono.Cairo/Mono.Cairo/Device.cs new file mode 100644 index 00000000000..06715bc9e99 --- /dev/null +++ b/mcs/class/Mono.Cairo/Mono.Cairo/Device.cs @@ -0,0 +1,101 @@ +// +// Mono.Cairo.Device.cs +// +// Authors: +// JP Bruyère (jp_bruyere@hotmail.com) +// +// This is an OO wrapper API for the Cairo API +// +// Copyright (C) 2016 JP Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; + +namespace Cairo +{ + public class Device : IDisposable + { + IntPtr handle = IntPtr.Zero; + + protected Device() + { + } + + protected Device (IntPtr ptr) : this (ptr, true) + { + } + + protected Device (IntPtr handle, bool owner) + { + this.handle = handle; + if (!owner) + NativeMethods.cairo_device_reference (handle); + if (CairoDebug.Enabled) + CairoDebug.OnAllocated (handle); + } + + ~Device () + { + Dispose (false); + } + + public IntPtr Handle { + get { + return handle; + } + } + public string Status { + get { + return System.Runtime.InteropServices.Marshal.PtrToStringAuto(NativeMethods.cairo_status_to_string (NativeMethods.cairo_device_status (handle))); + } + } + public void SetThreadAware (bool value){ + NativeMethods.cairo_gl_device_set_thread_aware (handle, value ? 1 : 0); + } + public Status Acquire() + { + return NativeMethods.cairo_device_acquire (handle); + } + public void Release() + { + NativeMethods.cairo_device_release (handle); + } + + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || CairoDebug.Enabled) + CairoDebug.OnDisposed<Device> (handle, disposing); + + if (!disposing || handle == IntPtr.Zero) + return; + + NativeMethods.cairo_device_destroy (handle); + handle = IntPtr.Zero; + } + } +} + diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/EGLDevice.cs b/mcs/class/Mono.Cairo/Mono.Cairo/EGLDevice.cs new file mode 100644 index 00000000000..45c988a3849 --- /dev/null +++ b/mcs/class/Mono.Cairo/Mono.Cairo/EGLDevice.cs @@ -0,0 +1,41 @@ +// +// Mono.Cairo.Device.cs +// +// Authors: +// JP Bruyère (jp_bruyere@hotmail.com) +// +// This is an OO wrapper API for the Cairo API +// +// Copyright (C) 2016 JP Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; + +namespace Cairo +{ + public class EGLDevice : Device + { + public EGLDevice (IntPtr dpy, IntPtr gl_ctx) : base (NativeMethods.cairo_egl_device_create (dpy, gl_ctx), true) + { + } + } +} + diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/GLSurface.cs b/mcs/class/Mono.Cairo/Mono.Cairo/GLSurface.cs new file mode 100644 index 00000000000..9486c9cd13c --- /dev/null +++ b/mcs/class/Mono.Cairo/Mono.Cairo/GLSurface.cs @@ -0,0 +1,61 @@ +// +// Mono.Cairo.GLSurface.cs +// +// Authors: +// JP Bruyère (jp_bruyere@hotmail.com) +// +// This is an OO wrapper API for the Cairo API +// +// Copyright (C) 2016 JP Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +namespace Cairo { + + public class GLSurface : Surface + { + + public GLSurface (IntPtr ptr, bool own) : base (ptr, own) + {} + + public GLSurface (Device device, Cairo.Content content, uint tex, int width, int height) + : base (NativeMethods.cairo_gl_surface_create_for_texture (device.Handle, (uint)content, tex, width, height), true) + {} + + public GLSurface (EGLDevice device, IntPtr eglSurf, int width, int height) + : base (NativeMethods.cairo_gl_surface_create_for_egl (device.Handle, eglSurf, width, height), true) + {} + + public GLSurface (GLXDevice device, IntPtr window, int width, int height) + : base (NativeMethods.cairo_gl_surface_create_for_window (device.Handle, window, width, height),true) + {} + + public GLSurface (WGLDevice device, IntPtr hdc, int width, int height) + : base (NativeMethods.cairo_gl_surface_create_for_dc (device.Handle, hdc, width, height), true) + {} + + public void SwapBuffers(){ + NativeMethods.cairo_gl_surface_swapbuffers (this.Handle); + } + } +} diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/GLXDevice.cs b/mcs/class/Mono.Cairo/Mono.Cairo/GLXDevice.cs new file mode 100644 index 00000000000..189872a26ba --- /dev/null +++ b/mcs/class/Mono.Cairo/Mono.Cairo/GLXDevice.cs @@ -0,0 +1,49 @@ +// +// Mono.Cairo.Device.cs +// +// Authors: +// JP Bruyère (jp_bruyere@hotmail.com) +// +// This is an OO wrapper API for the Cairo API +// +// Copyright (C) 2016 JP Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; + +namespace Cairo +{ + public class GLXDevice : Device + { + public GLXDevice (IntPtr dpy, IntPtr gl_ctx) : base (NativeMethods.cairo_glx_device_create (dpy, gl_ctx), true) + { + } + + public IntPtr Display { + get { return NativeMethods.cairo_glx_device_get_display (Handle); } + } + + public IntPtr Context { + get { return NativeMethods.cairo_glx_device_get_context (Handle); } + } + } +} + diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/NativeMethods.cs b/mcs/class/Mono.Cairo/Mono.Cairo/NativeMethods.cs index 8509c6db25f..9726cb8c4e7 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/NativeMethods.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/NativeMethods.cs @@ -871,5 +871,78 @@ namespace Cairo [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] internal static extern void cairo_xlib_surface_set_size (IntPtr surface, int width, int height); + + #region GLSurface + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_gl_surface_create (IntPtr device, uint content, int width, int height); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_gl_surface_create_for_texture (IntPtr device, uint content, uint tex, int width, int height); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern void cairo_gl_surface_set_size (IntPtr surface, int width, int height); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern int cairo_gl_surface_get_width (IntPtr surface); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern int cairo_gl_surface_get_height (IntPtr surface); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern void cairo_gl_surface_swapbuffers (IntPtr surf); + #endregion + + #region GLX Functions + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_glx_device_create (IntPtr dpy, IntPtr gl_ctx); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_glx_device_get_display (IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_glx_device_get_context (IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_gl_surface_create_for_window (IntPtr device, IntPtr window, int width, int height); + #endregion + + #region WGL Fucntions + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_wgl_device_create (IntPtr hglrc); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_wgl_device_get_context (IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_gl_surface_create_for_dc (IntPtr device, IntPtr hdc, int width, int height); + #endregion + + #region EGL Functions + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_egl_device_create (IntPtr dpy, IntPtr gl_ctx); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_gl_surface_create_for_egl (IntPtr device, IntPtr eglSurface, int width, int height); + #endregion + + #region Device + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr cairo_device_reference (IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern Status cairo_device_status(IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern void cairo_device_destroy (IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern Status cairo_device_acquire(IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern void cairo_device_release(IntPtr device); + + [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] + internal static extern void cairo_gl_device_set_thread_aware(IntPtr device, int value); + #endregion } }
\ No newline at end of file diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/Surface.cs b/mcs/class/Mono.Cairo/Mono.Cairo/Surface.cs index 07e0d4d9975..d38b75556e5 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/Surface.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/Surface.cs @@ -86,6 +86,8 @@ namespace Cairo { return new DirectFBSurface (surface, owned); case SurfaceType.Svg: return new SvgSurface (surface, owned); + case SurfaceType.GL: + return new GLSurface (surface, owned); default: return new Surface (surface, owned); } diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/SurfaceType.cs b/mcs/class/Mono.Cairo/Mono.Cairo/SurfaceType.cs index 83dd4b684a2..9272fed17b2 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/SurfaceType.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/SurfaceType.cs @@ -3,6 +3,7 @@ // // Authors: // John Luke +// JP Bruyère // // (C) John Luke, 2006. // @@ -44,5 +45,18 @@ namespace Cairo { BeOS, DirectFB, Svg, + OS2, + Win32Printing, + QuartzImage, + Script, + Qt, + Recording, + VG, + GL, + Drm, + Tee, + Xml, + Skia, + SubSurface } } diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/WGLDevice.cs b/mcs/class/Mono.Cairo/Mono.Cairo/WGLDevice.cs new file mode 100644 index 00000000000..03f7e3a4987 --- /dev/null +++ b/mcs/class/Mono.Cairo/Mono.Cairo/WGLDevice.cs @@ -0,0 +1,45 @@ +// +// Mono.Cairo.Device.cs +// +// Authors: +// JP Bruyère (jp_bruyere@hotmail.com) +// +// This is an OO wrapper API for the Cairo API +// +// Copyright (C) 2016 JP Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; + +namespace Cairo +{ + public class WGLDevice : Device + { + public WGLDevice (IntPtr hglrc) : base (NativeMethods.cairo_wgl_device_create (hglrc), true) + { + } + + public IntPtr Context { + get { return NativeMethods.cairo_wgl_device_get_context (Handle); } + } + } +} + |