]> O.S.I.I.S - jp/crow.git/commitdiff
vkvg.net for vkvg backend
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 12 Jan 2022 14:06:17 +0000 (15:06 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 12 Jan 2022 14:06:17 +0000 (15:06 +0100)
Backends/VkvgBackend/Crow.VkvgBackend.csproj
Backends/VkvgBackend/src/DefaultBackend.cs
Backends/VkvgBackend/src/Device.cs [deleted file]
Backends/VkvgBackend/src/FontExtents.cs [deleted file]
Backends/VkvgBackend/src/Gradient.cs [deleted file]
Backends/VkvgBackend/src/Matrix.cs [deleted file]
Backends/VkvgBackend/src/Surface.cs [deleted file]
Backends/VkvgBackend/src/TextExtents.cs [deleted file]
Backends/VkvgBackend/src/TextRun.cs [deleted file]

index 54fd15f540a56668c693b37dd3975b33cb8102df..13386d36228151c2290c07b8b8ceccff6a2b346c 100644 (file)
@@ -15,6 +15,7 @@
 
   <ItemGroup>
     <PackageReference Include="vke" Version="0.2.0-beta" />
+    <PackageReference Include="vkvg.net" Version="0.5.0-beta" />
     <ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" />
   </ItemGroup>
 
index b84ffa7d578b8f859a4518c67808d76ac6dfa87e..8521d503c5512ee2d29ea651332d72827e0789e6 100644 (file)
@@ -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 (file)
index 24d52c7..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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 (file)
index f5614c2..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2018-2022  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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<FontExtents>
-       {
-               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 (file)
index d2432d6..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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 (file)
index 0907362..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2018-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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 (file)
index e900478..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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<byte> 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 (file)
index 8afb739..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2018-2022  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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<TextExtents>
-       {
-               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 (file)
index 94b94f5..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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