From 09026f4328d0e578823062d6506ffdacac457b25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 24 Nov 2021 05:00:15 +0100 Subject: [PATCH] wip --- Backends/CairoBackend/src/Context.cs | 5 +++++ Backends/CairoBackend/src/Device.cs | 2 +- Backends/CairoBackend/src/EGLDevice.cs | 10 +++++++++- Backends/CairoBackend/src/GLSurface.cs | 7 +++++++ Backends/CairoBackend/src/Surface.cs | 18 +++++------------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Backends/CairoBackend/src/Context.cs b/Backends/CairoBackend/src/Context.cs index a28c7b0c..a4eac7a2 100644 --- a/Backends/CairoBackend/src/Context.cs +++ b/Backends/CairoBackend/src/Context.cs @@ -138,6 +138,11 @@ namespace Crow.CairoBackend return NativeMethods.cairo_status (handle); } } + public string StatusString { + get { + return System.Runtime.InteropServices.Marshal.PtrToStringAuto(NativeMethods.cairo_status_to_string (Status)); + } + } public IntPtr Handle => handle; diff --git a/Backends/CairoBackend/src/Device.cs b/Backends/CairoBackend/src/Device.cs index 4cbb180f..c87b494b 100644 --- a/Backends/CairoBackend/src/Device.cs +++ b/Backends/CairoBackend/src/Device.cs @@ -112,7 +112,7 @@ namespace Crow.CairoBackend public virtual ISurface CreateSurface(byte[] data, int width, int height) => new ImageSurface (data, Format.ARGB32, width, height, 4 * width); - public ISurface CreateSurface (IntPtr nativeWindoPointer, int width, int height) { + public virtual ISurface CreateSurface (IntPtr nativeWindoPointer, int width, int height) { switch (Environment.OSVersion.Platform) { case PlatformID.Unix: IntPtr disp = Glfw3.GetX11Display (); diff --git a/Backends/CairoBackend/src/EGLDevice.cs b/Backends/CairoBackend/src/EGLDevice.cs index 5305298b..83629374 100644 --- a/Backends/CairoBackend/src/EGLDevice.cs +++ b/Backends/CairoBackend/src/EGLDevice.cs @@ -28,14 +28,22 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; +using Drawing2D; namespace Crow.CairoBackend { public class EGLDevice : GLDevice { - public EGLDevice (IntPtr dpy, IntPtr gl_ctx) : base (NativeMethods.cairo_egl_device_create (dpy, gl_ctx), true) + public EGLDevice (IntPtr dpy, IntPtr gl_ctx, bool threadAwayre = false) : base (NativeMethods.cairo_egl_device_create (dpy, gl_ctx), true) { + SetThreadAware(threadAwayre); } + public override ISurface CreateSurface(int width, int height) + => new ImageSurface (Format.ARGB32, width, height); + public override ISurface CreateSurface (IntPtr nativeWindoPointer, int width, int height) { + return new GLSurface (this, Glfw.Glfw3.GetEGLSurface (nativeWindoPointer), width, height); + } + } } diff --git a/Backends/CairoBackend/src/GLSurface.cs b/Backends/CairoBackend/src/GLSurface.cs index ddbf0a4f..c7959dc3 100644 --- a/Backends/CairoBackend/src/GLSurface.cs +++ b/Backends/CairoBackend/src/GLSurface.cs @@ -52,6 +52,13 @@ namespace Crow.CairoBackend { 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 override void Flush () + { + base.Flush (); + SwapBuffers (); + } + public override int Width => NativeMethods.cairo_gl_surface_get_width (handle); + public override int Height => NativeMethods.cairo_gl_surface_get_height (handle); public void SwapBuffers(){ NativeMethods.cairo_gl_surface_swapbuffers (this.Handle); diff --git a/Backends/CairoBackend/src/Surface.cs b/Backends/CairoBackend/src/Surface.cs index 2d6fac10..8e797658 100644 --- a/Backends/CairoBackend/src/Surface.cs +++ b/Backends/CairoBackend/src/Surface.cs @@ -111,12 +111,9 @@ namespace Crow.CairoBackend { } - public Surface CreateSimilar ( - Content content, int width, int height) - { + public ISurface CreateSimilar (int width, int height) { IntPtr p = NativeMethods.cairo_surface_create_similar ( - this.Handle, content, width, height); - + this.Handle, Content.ColorAlpha, width, height); return Surface.Lookup(p, true); } @@ -152,7 +149,7 @@ namespace Crow.CairoBackend { return Status; } - public void Flush () + public virtual void Flush () { NativeMethods.cairo_surface_flush (handle); } @@ -166,8 +163,8 @@ namespace Crow.CairoBackend { { NativeMethods.cairo_surface_mark_dirty_rectangle (Handle, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); } - public virtual int Width => -1; - public virtual int Height => -1; + public virtual int Width => NativeMethods.cairo_image_surface_get_width (handle); + public virtual int Height => NativeMethods.cairo_image_surface_get_height (handle); public IntPtr Handle { get { @@ -235,10 +232,5 @@ namespace Crow.CairoBackend { { throw new NotImplementedException(); } - - public ISurface CreateSimilar(int width, int height) - { - throw new NotImplementedException(); - } } } -- 2.47.3