<ItemGroup>
<PackageReference Include="vke" Version="0.2.0-beta" />
+ <PackageReference Include="vkvg.net" Version="0.5.0-beta" />
<ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" />
</ItemGroup>
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
{
+++ /dev/null
-// 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
- }
-}
-
+++ /dev/null
-// 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);
- }
-}
+++ /dev/null
-// 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
+++ /dev/null
-// 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})");
- }
- }
-}
+++ /dev/null
-// 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
- }
-}
-
+++ /dev/null
-// 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);
- }
-}
+++ /dev/null
-// 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