From 5784f8dca22600b25569ede999cdc795bc8bb8ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 12 Jan 2022 15:06:17 +0100 Subject: [PATCH] vkvg.net for vkvg backend --- Backends/VkvgBackend/Crow.VkvgBackend.csproj | 1 + Backends/VkvgBackend/src/DefaultBackend.cs | 4 +- Backends/VkvgBackend/src/Device.cs | 56 ------------ Backends/VkvgBackend/src/FontExtents.cs | 62 ------------- Backends/VkvgBackend/src/Gradient.cs | 31 ------- Backends/VkvgBackend/src/Matrix.cs | 92 ------------------- Backends/VkvgBackend/src/Surface.cs | 95 -------------------- Backends/VkvgBackend/src/TextExtents.cs | 60 ------------- Backends/VkvgBackend/src/TextRun.cs | 56 ------------ 9 files changed, 4 insertions(+), 453 deletions(-) delete mode 100644 Backends/VkvgBackend/src/Device.cs delete mode 100644 Backends/VkvgBackend/src/FontExtents.cs delete mode 100644 Backends/VkvgBackend/src/Gradient.cs delete mode 100644 Backends/VkvgBackend/src/Matrix.cs delete mode 100644 Backends/VkvgBackend/src/Surface.cs delete mode 100644 Backends/VkvgBackend/src/TextExtents.cs delete mode 100644 Backends/VkvgBackend/src/TextRun.cs diff --git a/Backends/VkvgBackend/Crow.VkvgBackend.csproj b/Backends/VkvgBackend/Crow.VkvgBackend.csproj index 54fd15f5..13386d36 100644 --- a/Backends/VkvgBackend/Crow.VkvgBackend.csproj +++ b/Backends/VkvgBackend/Crow.VkvgBackend.csproj @@ -15,6 +15,7 @@ + diff --git a/Backends/VkvgBackend/src/DefaultBackend.cs b/Backends/VkvgBackend/src/DefaultBackend.cs index b84ffa7d..8521d503 100644 --- a/Backends/VkvgBackend/src/DefaultBackend.cs +++ b/Backends/VkvgBackend/src/DefaultBackend.cs @@ -12,7 +12,9 @@ using Glfw; using vke; using Vulkan; using static Vulkan.Vk; -using Device = vke.Device; +using Device = vkvg.Device; +using vkvg; +using SampleCount = Drawing2D.SampleCount; namespace Crow.VkvgBackend { diff --git a/Backends/VkvgBackend/src/Device.cs b/Backends/VkvgBackend/src/Device.cs deleted file mode 100644 index 24d52c73..00000000 --- a/Backends/VkvgBackend/src/Device.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2018-2021 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using System.IO; -using Drawing2D; - -namespace Crow.VkvgBackend -{ - public class Device: IDevice - { - - IntPtr handle = IntPtr.Zero; - - #region CTORS & DTOR - public Device (IntPtr instance, IntPtr phy, IntPtr dev, uint qFamIdx, SampleCount samples = SampleCount.Sample_1, uint qIndex = 0) - { - handle = NativeMethods.vkvg_device_create_from_vk_multisample (instance, phy, dev, qFamIdx, qIndex, samples, false); - } - ~Device () - { - Dispose (false); - } - #endregion - - public void AddReference () => NativeMethods.vkvg_device_reference (handle); - public uint References () => NativeMethods.vkvg_device_get_reference_count (handle); - - public IntPtr Handle => handle; - - #region IDevice implementation - public void GetDpy (out int hdpy, out int vdpy) => NativeMethods.vkvg_device_get_dpy (handle, out hdpy, out vdpy); - public void SetDpy (int hdpy, int vdpy) => NativeMethods.vkvg_device_set_dpy (handle, hdpy, vdpy); - #endregion - - - #region IDisposable implementation - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || handle == IntPtr.Zero) - return; - - NativeMethods.vkvg_device_destroy (handle); - handle = IntPtr.Zero; - } - #endregion - } -} - diff --git a/Backends/VkvgBackend/src/FontExtents.cs b/Backends/VkvgBackend/src/FontExtents.cs deleted file mode 100644 index f5614c2f..00000000 --- a/Backends/VkvgBackend/src/FontExtents.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2018-2022 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.Runtime.InteropServices; - -namespace Crow.VkvgBackend -{ - [StructLayout (LayoutKind.Sequential)] - internal struct FontExtents : IEquatable - { - float ascent; - float descent; - float height; - float maxXAdvance; - float maxYAdvance; - - public float Ascent { - get => ascent; - set { ascent = value; } - } - - public float Descent { - get => descent; - set { descent = value; } - } - - public float Height { - get => height; - set { height = value; } - } - - public float MaxXAdvance { - get => maxXAdvance; - set { maxXAdvance = value; } - } - - public float MaxYAdvance { - get => maxYAdvance; - set { maxYAdvance = value; } - } - - public FontExtents (float ascent, float descent, float height, float maxXAdvance, float maxYAdvance) - { - this.ascent = ascent; - this.descent = descent; - this.height = height; - this.maxXAdvance = maxXAdvance; - this.maxYAdvance = maxYAdvance; - } - - public override int GetHashCode () => HashCode.Combine (ascent, descent, height, maxXAdvance, maxYAdvance); - public override bool Equals (object obj) => obj is FontExtents fe ? Equals (fe) : false; - - public bool Equals(FontExtents other) => - ascent == other.ascent && descent == other.descent && height == other.height && - maxXAdvance == other.maxXAdvance && maxYAdvance == other.maxYAdvance; - - public static bool operator == (FontExtents extents, FontExtents other) => extents.Equals (other); - public static bool operator != (FontExtents extents, FontExtents other) => !extents.Equals (other); - } -} diff --git a/Backends/VkvgBackend/src/Gradient.cs b/Backends/VkvgBackend/src/Gradient.cs deleted file mode 100644 index d2432d66..00000000 --- a/Backends/VkvgBackend/src/Gradient.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2018-2021 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Drawing2D; - -namespace Crow.VkvgBackend -{ - public class Gradient : Pattern, IGradient - { - protected Gradient(IntPtr handle) : base (handle) { } - public void AddColorStop (double offset, Color c) - => NativeMethods.vkvg_pattern_add_color_stop(handle, (float)offset, c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f); - public void AddColorStop(float offset, float r, float g, float b, float a = 1f) - => NativeMethods.vkvg_pattern_add_color_stop(handle, offset, r, g, b, a); - } - public class LinearGradient : Gradient { - public LinearGradient (float x0, float y0, float x1, float y1) - : base (NativeMethods.vkvg_pattern_create_linear(x0, y0, x1, y1)) { - - } - } - public class RadialGradient : Gradient { - public RadialGradient ( float cx0, float cy0, float radius0, - float cx1, float cy1, float radius1) - : base (NativeMethods.vkvg_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1)) { - - } - } -} \ No newline at end of file diff --git a/Backends/VkvgBackend/src/Matrix.cs b/Backends/VkvgBackend/src/Matrix.cs deleted file mode 100644 index 0907362e..00000000 --- a/Backends/VkvgBackend/src/Matrix.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2018-2020 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -namespace Crow.VkvgBackend { - public struct Matrix { - float xx; float yx; - float xy; float yy; - float x0; float y0; - - public float XX { get { return xx; } set { xx = value; } } - public float YX { get { return yx; } set { yx = value; } } - public float XY { get { return xy; } set { xy = value; } } - public float YY { get { return yy; } set { yy = value; } } - public float X0 { get { return x0; } set { x0 = value; } } - public float Y0 { get { return y0; } set { y0 = value; } } - - public static Matrix Create (float xx, float yx, float xy, float yy, float x0, float y0) { - Matrix tmp; - NativeMethods.vkvg_matrix_init (out tmp, xx, yx, xy, yy, x0, y0); - return tmp; - } - public static Matrix CreateTranslation (float tx, float ty) { - Matrix tmp; - NativeMethods.vkvg_matrix_init_translate (out tmp, tx, ty); - return tmp; - } - public static Matrix CreateRotation (float radian) { - Matrix tmp; - NativeMethods.vkvg_matrix_init_rotate (out tmp, radian); - return tmp; - } - public static Matrix CreateScale (float sx, float sy) { - Matrix tmp; - NativeMethods.vkvg_matrix_init_scale (out tmp, sx, sy); - return tmp; - } - public static Matrix Identity { - get { - Matrix tmp; - NativeMethods.vkvg_matrix_init_identity (out tmp); - return tmp; - } - } - - public void Translate (float tx, float ty) { - Matrix tmp = this; - NativeMethods.vkvg_matrix_translate (ref tmp, tx, ty); - xx = tmp.xx; yx = tmp.yx; - xy = tmp.xy; yy = tmp.yy; - x0 = tmp.x0; y0 = tmp.y0; - } - public void Rotate (float radian) { - Matrix tmp = this; - NativeMethods.vkvg_matrix_rotate (ref tmp, radian); - xx = tmp.xx; yx = tmp.yx; - xy = tmp.xy; yy = tmp.yy; - x0 = tmp.x0; y0 = tmp.y0; - } - public void Scale (float sx, float sy) { - Matrix tmp = this; - NativeMethods.vkvg_matrix_scale (ref tmp, sx, sy); - xx = tmp.xx; yx = tmp.yx; - xy = tmp.xy; yy = tmp.yy; - x0 = tmp.x0; y0 = tmp.y0; - } - public void Invert () { - Matrix tmp = this; - NativeMethods.vkvg_matrix_invert (ref tmp); - xx = tmp.xx; yx = tmp.yx; - xy = tmp.xy; yy = tmp.yy; - x0 = tmp.x0; y0 = tmp.y0; - } - public void TransformDistance (ref float dx, ref float dy) { - NativeMethods.vkvg_matrix_transform_distance (ref this, ref dx, ref dy); - } - public void TransformPoint (ref float px, ref float py) { - NativeMethods.vkvg_matrix_transform_distance (ref this, ref px, ref py); - } - - public static Matrix operator *(Matrix a, Matrix b) { - Matrix tmp; - NativeMethods.vkvg_matrix_multiply (out tmp, ref a, ref b); - return tmp; - } - - public override string ToString () { - return string.Format ($"({xx};{yx};{xy};{yy};{x0};{y0})"); - } - } -} diff --git a/Backends/VkvgBackend/src/Surface.cs b/Backends/VkvgBackend/src/Surface.cs deleted file mode 100644 index e900478a..00000000 --- a/Backends/VkvgBackend/src/Surface.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2018-2021 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Drawing2D; - -namespace Crow.VkvgBackend -{ - public class Surface: ISurface - { - internal IntPtr handle = IntPtr.Zero; - Device vkvgDev; - - #region CTOR - public Surface (Device device, int width, int height) - { - vkvgDev = device; - if (width <= 0 || height <= 0) - handle = NativeMethods.vkvg_surface_create (device.Handle, 1, 1); - else - handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)height); - } - public Surface (Device device, Span data, int width, int heigth) - { - vkvgDev = device; - handle = NativeMethods.vkvg_surface_create_from_bitmap (device.Handle, ref data.GetPinnableReference(), (uint)width, (uint)heigth); - } - public Surface (Device device, string imgPath) { - vkvgDev = device; - handle = NativeMethods.vkvg_surface_create_from_image (device.Handle, imgPath); - } - public Surface (Device device, IntPtr surfHandle) { - vkvgDev = device; - handle = surfHandle; - AddReference (); - } - - Surface (IntPtr devHandle, int width, int height) - { - handle = NativeMethods.vkvg_surface_create (devHandle, (uint)width, (uint)height); - } - #endregion - ~Surface () - { - Dispose (false); - } - public IntPtr VkImage => NativeMethods.vkvg_surface_get_vk_image (handle); - public int Width => NativeMethods.vkvg_surface_get_width (handle); - public int Height => NativeMethods.vkvg_surface_get_height (handle); - - public void AddReference () => NativeMethods.vkvg_surface_reference (handle); - public uint References () => NativeMethods.vkvg_surface_get_reference_count (handle); - - public ISurface CreateSimilar(int width, int height) => new Surface (vkvgDev, width, height); - - public void Resize(int width, int height) - { - NativeMethods.vkvg_surface_destroy (handle); - handle = NativeMethods.vkvg_surface_create (vkvgDev.Handle, (uint)width, (uint)height); - } - - public void Flush () { - //throw new NotImplementedException (); - } - - public void WriteToPng (string path) { - NativeMethods.vkvg_surface_write_to_png (handle, path); - } - public void WriteTo (IntPtr bitmap) { - NativeMethods.vkvg_surface_write_to_memory (handle, bitmap); - } - public void Clear () { - NativeMethods.vkvg_surface_clear (handle); - } - - #region IDisposable implementation - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || handle == IntPtr.Zero) - return; - - NativeMethods.vkvg_surface_destroy (handle); - handle = IntPtr.Zero; - } - #endregion - } -} - diff --git a/Backends/VkvgBackend/src/TextExtents.cs b/Backends/VkvgBackend/src/TextExtents.cs deleted file mode 100644 index 8afb7392..00000000 --- a/Backends/VkvgBackend/src/TextExtents.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2018-2022 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using System.Runtime.InteropServices; - -namespace Crow.VkvgBackend -{ - [StructLayout (LayoutKind.Sequential)] - internal struct TextExtents : IEquatable - { - float xBearing; - float yBearing; - float width; - float height; - float xAdvance; - float yAdvance; - - public float XBearing { - get => xBearing; - set { xBearing = value; } - } - - public float YBearing { - get => yBearing; - set { yBearing = value; } - } - - public float Width { - get => width; - set { width = value; } - } - - public float Height { - get => height; - set { height = value; } - } - - public float XAdvance { - get => xAdvance; - set { xAdvance = value; } - } - - public float YAdvance { - get => yAdvance; - set { yAdvance = value; } - } - - public override int GetHashCode () => - HashCode.Combine (xBearing, yBearing, width, height, xAdvance, yAdvance); - public override bool Equals (object obj) => obj is TextExtents te ? Equals (te) : false; - - public bool Equals(TextExtents other) => - xBearing == other.xBearing && yBearing == other.yBearing && width == other.width && height == other.height && - xAdvance == other.xAdvance && yAdvance == other.yAdvance; - public static bool operator == (TextExtents extents, TextExtents other) => extents.Equals (other); - public static bool operator != (TextExtents extents, TextExtents other )=> !extents.Equals (other); - } -} diff --git a/Backends/VkvgBackend/src/TextRun.cs b/Backends/VkvgBackend/src/TextRun.cs deleted file mode 100644 index 94b94f56..00000000 --- a/Backends/VkvgBackend/src/TextRun.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2018-2021 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Drawing2D; - -namespace Crow.VkvgBackend -{ - public class TextRun : IDisposable { - - IntPtr handle = IntPtr.Zero; - - #region CTORS & DTOR - protected TextRun(IntPtr handle) { - this.handle = handle; - } - public TextRun(string text) { - handle = NativeMethods.vkvg_text_run_create (handle, Context.TerminateUtf8(text)); - } - - ~TextRun() { - Dispose (false); - } - #endregion - - //public void AddReference () { - // NativeMethods.vkvg_pattern_reference (handle); - //} - //public uint References () => NativeMethods.vkvg_pattern_get_reference_count (handle); - - public IntPtr Handle { get { return handle; } } - - public Drawing2D.TextExtents Extents { - get { - NativeMethods.vkvg_text_run_get_extents (handle, out TextExtents e); - return new Drawing2D.TextExtents (e.XBearing, e.YBearing, e.Width, e.Height, e.XAdvance, e.YAdvance); - } - } - - #region IDisposable implementation - public void Dispose () { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) { - if (!disposing || handle == IntPtr.Zero) - return; - - NativeMethods.vkvg_text_run_destroy (handle); - handle = IntPtr.Zero; - } - #endregion - } -} \ No newline at end of file -- 2.47.3