namespace Crow.CairoBackend
{
public abstract class CairoBackendBase : IBackend {
- protected ISurface surf;
+ protected IntPtr hWin;
+ protected Surface surf;
/// <summary> Global font rendering settings for Cairo </summary>
FontOptions FontRenderingOptions;
/// <summary> Global font rendering settings for Cairo </summary>
public IRegion CreateRegion () => new Region ();
public IContext CreateContext (ISurface surf)
{
- Context gr = new Context (surf);
+ Context gr = new Context (surf as Surface);
gr.FontOptions = FontRenderingOptions;
gr.Antialias = Antialias;
return gr;
IContext ctx = existingContext;
if (ctx == null) {
disposeContextOnFlush = true;
- ctx = new Context (MainSurface);
+ ctx = new Context (surf);
} else
disposeContextOnFlush = false;
return ctx;
{
public class Context : IContext
{
- IntPtr handle = IntPtr.Zero;
+ internal IntPtr handle = IntPtr.Zero;
static int native_glyph_size, c_compiler_long_size;
}
}
- public Context (ISurface surface) : this (NativeMethods.cairo_create (surface.Handle), true)
+ internal Context (Surface surface) : this (NativeMethods.cairo_create (surface.handle), true)
{
}
- public Context (IntPtr handle, bool owner)
+ internal Context (IntPtr handle, bool owner)
{
this.handle = handle;
if (!owner)
}
[Obsolete]
- public Context (IntPtr state) : this (state, true)
+ internal Context (IntPtr state) : this (state, true)
{
}
}
}
- public IntPtr Handle => handle;
-
public Operator Operator {
set => NativeMethods.cairo_set_operator (handle, value);
get => NativeMethods.cairo_get_operator (handle);
get => NativeMethods.cairo_get_line_width (handle);
}
public LineCap LineCap {
- set {
- NativeMethods.cairo_set_line_cap (handle, value);
- }
-
- get {
- return NativeMethods.cairo_get_line_cap (handle);
- }
+ set => NativeMethods.cairo_set_line_cap (handle, value);
+ get => NativeMethods.cairo_get_line_cap (handle);
}
-
public LineJoin LineJoin {
- set {
- NativeMethods.cairo_set_line_join (handle, value);
- }
-
- get {
- return NativeMethods.cairo_get_line_join (handle);
- }
+ set => NativeMethods.cairo_set_line_join (handle, value);
+ get => NativeMethods.cairo_get_line_join (handle);
}
-
- public void SetDash (double [] dashes, double offset = 0)
- {
- NativeMethods.cairo_set_dash (handle, dashes, dashes.Length, offset);
- }
-
- [Obsolete("Use GetSource/SetSource")]
- public Pattern Pattern {
- set {
- SetSource (value);
- }
- get {
- return GetSource ();
- }
+ public double MiterLimit {
+ set => NativeMethods.cairo_set_miter_limit (handle, value);
+ get => NativeMethods.cairo_get_miter_limit (handle);
}
- //This is obsolete because it wasn't obvious it needed to be disposed
- [Obsolete("Use GetSource/SetSource")]
- public Pattern Source {
- set {
- SetSource (value);
- }
- get {
- return GetSource ();
- }
- }
+ public void SetDash (double [] dashes, double offset = 0)
+ => NativeMethods.cairo_set_dash (handle, dashes, dashes.Length, offset);
public void SetSource (Pattern source)
- {
- NativeMethods.cairo_set_source (handle, source.handle);
- }
-
+ => NativeMethods.cairo_set_source (handle, source.handle);
public Pattern GetSource ()
{
var ptr = NativeMethods.cairo_get_source (handle);
return Pattern.Lookup (ptr, false);
}
- public double MiterLimit {
- set {
- NativeMethods.cairo_set_miter_limit (handle, value);
- }
-
- get {
- return NativeMethods.cairo_get_miter_limit (handle);
- }
- }
public PointD CurrentPoint {
get {
}
}
- public bool HasCurrentPoint {
- get {
- return NativeMethods.cairo_has_current_point (handle);
- }
- }
+ public bool HasCurrentPoint => NativeMethods.cairo_has_current_point (handle);
public Surface GetTarget () => Surface.Lookup (NativeMethods.cairo_get_target (handle), false);
public void SetTarget (Surface target)
{
if (handle != IntPtr.Zero)
NativeMethods.cairo_destroy (handle);
- handle = NativeMethods.cairo_create (target.Handle);
+ handle = NativeMethods.cairo_create (target.handle);
}
public ScaledFont GetScaledFont ()
=> new ScaledFont (NativeMethods.cairo_get_scaled_font (handle), false);
//[Obsolete ("Use SetSource method (with double parameters)")]
public void SetSource (Surface source, int x = 0, int y = 0)
{
- NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y);
+ NativeMethods.cairo_set_source_surface (handle, source.handle, x, y);
}
public void SetSource (Surface source, double x, double y)
{
- NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y);
+ NativeMethods.cairo_set_source_surface (handle, source.handle, x, y);
}
public void SetSource (Surface source)
{
- NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0);
+ NativeMethods.cairo_set_source_surface (handle, source.handle, 0, 0);
}
#region Path methods
public void PaintWithAlpha (double alpha) => NativeMethods.cairo_paint_with_alpha (handle, alpha);
public void Mask (Pattern pattern) => NativeMethods.cairo_mask (handle, pattern.handle);
public void MaskSurface (Surface surface, double surface_x, double surface_y)
- => NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y);
+ => NativeMethods.cairo_mask_surface (handle, surface.handle, surface_x, surface_y);
public void Stroke () => NativeMethods.cairo_stroke (handle);
public void StrokePreserve () => NativeMethods.cairo_stroke_preserve (handle);
public Rectangle StrokeExtents ()
}
public void ShowText(string str)
- {
- NativeMethods.cairo_show_text (handle, TerminateUtf8 (str));
- }
-
-
+ => NativeMethods.cairo_show_text (handle, TerminateUtf8 (str));
public void TextPath(string str)
- {
- NativeMethods.cairo_text_path (handle, TerminateUtf8(str));
- }
-
+ => NativeMethods.cairo_text_path (handle, TerminateUtf8(str));
public void TextPath(byte[] utf8)
- {
- NativeMethods.cairo_text_path (handle, TerminateUtf8(utf8));
- }
-
+ => NativeMethods.cairo_text_path (handle, TerminateUtf8(utf8));
public TextExtents TextExtents(string s)
{
TextExtents extents;
public void Flush()
{
- throw new NotImplementedException();
+ //throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
- public void RenderSvg(IntPtr svgNativeHandle, string subId = null)
- {
- throw new NotImplementedException();
- }
+ public void RenderSvg(ISvgHandle svg, string subId = null)
+ => svg.Render (this, subId);
Matrix savedMat;
public void SaveTransformations()
=> NativeMethods.cairo_get_matrix (handle, out savedMat);
public void RestoreTransformations()
=> NativeMethods.cairo_set_matrix (handle, ref savedMat);
- public void SetSource(IPattern pat) => NativeMethods.cairo_set_source (handle, pat.Handle);
+ public void SetSource(IPattern pat) => NativeMethods.cairo_set_source (handle, (pat as Pattern).handle);
public void SetSource(ISurface surf, double x = 0, double y = 0)
- => NativeMethods.cairo_set_source_surface (handle, surf.Handle, x, y);
+ => NativeMethods.cairo_set_source_surface (handle, (surf as Surface).handle, x, y);
}
}
/// </summary>
/// <param name="width">backend surface width</param>
/// <param name="height">backend surface height</param>
- public DefaultBackend (IntPtr nativeWindoPointer, int width, int height)
- : base (nativeWindoPointer, width, height) { }
+ public DefaultBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height)
+ : base (ref nativeWindoPointer, out ownGlfwWinHandle, width, height) { }
public DefaultBackend (int width, int height) : base (width, height) {
}
namespace Crow.CairoBackend
{
public class EglBackend : CairoBackendBase {
- IntPtr hWin;
EGLDevice device;
/// <summary>
/// Create a new generic backend bound to the application surface
/// </summary>
/// <param name="width">backend surface width</param>
/// <param name="height">backend surface height</param>
- public EglBackend (IntPtr nativeWindoPointer, int width, int height) : base () {
- hWin = nativeWindoPointer;
+ public EglBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height) : base () {
+ if (nativeWindoPointer == IntPtr.Zero) {
+ Glfw3.Init ();
+ Glfw3.WindowHint (WindowAttribute.ClientApi, Constants.OpenglEsApi);
+ Glfw3.WindowHint (WindowAttribute.ContextVersionMajor, 3);
+ Glfw3.WindowHint (WindowAttribute.ContextVersionMinor, 2);
+ Glfw3.WindowHint (WindowAttribute.ContextCreationApi, Constants.EglContextApi);
+ Glfw3.WindowHint (WindowAttribute.Resizable, 1);
+ Glfw3.WindowHint (WindowAttribute.Decorated, 1);
+
+ hWin = Glfw3.CreateWindow (width, height, "win name", MonitorHandle.Zero, IntPtr.Zero);
+ if (hWin == IntPtr.Zero)
+ throw new Exception ("[GLFW3] Unable to create Window");
+
+ nativeWindoPointer = hWin;
+ ownGlfwWinHandle = true;
+ } else {
+ hWin = nativeWindoPointer;
+ ownGlfwWinHandle = false;
+ }
+
Glfw3.MakeContextCurrent (hWin);
Glfw3.SwapInterval (0);
=> NativeMethods.cairo_gl_surface_set_size(handle, width, height);
public void SwapBuffers(){
- NativeMethods.cairo_gl_surface_swapbuffers (this.Handle);
+ NativeMethods.cairo_gl_surface_swapbuffers (this.handle);
}
}
}
/// </summary>
/// <param name="width">backend surface width</param>
/// <param name="height">backend surface height</param>
- public ImageBackend (IntPtr nativeWindoPointer, int width, int height) : base () {
+ public ImageBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height) : base () {
+ if (nativeWindoPointer == IntPtr.Zero) {
+ Glfw3.Init ();
+ Glfw3.WindowHint (WindowAttribute.ClientApi, 0);
+ Glfw3.WindowHint (WindowAttribute.Resizable, 1);
+ Glfw3.WindowHint (WindowAttribute.Decorated, 1);
+
+ hWin = Glfw3.CreateWindow (width, height, "win name", MonitorHandle.Zero, IntPtr.Zero);
+ if (hWin == IntPtr.Zero)
+ throw new Exception ("[GLFW3] Unable to create Window");
+
+ nativeWindoPointer = hWin;
+ ownGlfwWinHandle = true;
+ } else {
+ hWin = nativeWindoPointer;
+ ownGlfwWinHandle = false;
+ }
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
{
}
- public override int Width => NativeMethods.cairo_image_surface_get_width (Handle);
- public override int Height => NativeMethods.cairo_image_surface_get_height (Handle);
+ public override int Width => NativeMethods.cairo_image_surface_get_width (handle);
+ public override int Height => NativeMethods.cairo_image_surface_get_height (handle);
public byte[] Data {
get {
- IntPtr ptr = NativeMethods.cairo_image_surface_get_data (Handle);
+ IntPtr ptr = NativeMethods.cairo_image_surface_get_data (handle);
int length = Height * Stride;
byte[] data = new byte[length];
Marshal.Copy (ptr, data, 0, length);
public IntPtr DataPtr {
get {
- return NativeMethods.cairo_image_surface_get_data (Handle);
+ return NativeMethods.cairo_image_surface_get_data (handle);
}
}
public Format Format {
- get { return NativeMethods.cairo_image_surface_get_format (Handle); }
+ get { return NativeMethods.cairo_image_surface_get_format (handle); }
}
public int Stride {
- get { return NativeMethods.cairo_image_surface_get_stride (Handle); }
+ get { return NativeMethods.cairo_image_surface_get_stride (handle); }
}
}
}
public void BeginPageSetup ()
{
- NativeMethods.cairo_ps_surface_dsc_begin_page_setup (Handle);
+ NativeMethods.cairo_ps_surface_dsc_begin_page_setup (handle);
}
public void BeginSetup ()
{
- NativeMethods.cairo_ps_surface_dsc_begin_setup (Handle);
+ NativeMethods.cairo_ps_surface_dsc_begin_setup (handle);
}
public void DscComment (string comment)
{
- NativeMethods.cairo_ps_surface_dsc_comment (Handle, comment);
+ NativeMethods.cairo_ps_surface_dsc_comment (handle, comment);
}
public void SetSize (double width, double height)
{
- NativeMethods.cairo_ps_surface_set_size (Handle, width, height);
+ NativeMethods.cairo_ps_surface_set_size (handle, width, height);
}
}
}
public class Pattern : IPattern
{
internal IntPtr handle;
- public IntPtr Handle => handle;
public static Pattern Lookup (IntPtr pattern, bool owner)
{
if (pattern == IntPtr.Zero)
[Obsolete ("Use the SurfacePattern constructor")]
public Pattern (Surface surface)
- : this ( NativeMethods.cairo_pattern_create_for_surface (surface.Handle), true)
+ : this ( NativeMethods.cairo_pattern_create_for_surface (surface.handle), true)
{
}
public void SetSize (double width, double height)
{
- NativeMethods.cairo_pdf_surface_set_size (Handle, width, height);
+ NativeMethods.cairo_pdf_surface_set_size (handle, width, height);
}
}
}
public class Surface : ISurface
{
- protected IntPtr handle = IntPtr.Zero;
+ internal IntPtr handle = IntPtr.Zero;
protected Surface()
{
public ISurface CreateSimilar (int width, int height) {
IntPtr p = NativeMethods.cairo_surface_create_similar (
- this.Handle, Content.ColorAlpha, width, height);
+ this.handle, Content.ColorAlpha, width, height);
return Surface.Lookup(p, true);
}
public void MarkDirty ()
{
- NativeMethods.cairo_surface_mark_dirty (Handle);
+ NativeMethods.cairo_surface_mark_dirty (handle);
}
public void MarkDirty (Rectangle rectangle)
{
- NativeMethods.cairo_surface_mark_dirty_rectangle (Handle, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
+ NativeMethods.cairo_surface_mark_dirty_rectangle (handle, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
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 {
- return handle;
- }
- }
-
public PointD DeviceOffset {
get {
double x, y;
}
public SurfacePattern (Surface surface)
- : base (NativeMethods.cairo_pattern_create_for_surface (surface.Handle), true)
+ : base (NativeMethods.cairo_pattern_create_for_surface (surface.handle), true)
{
}
public void RestrictToVersion (SvgVersion version)
{
- NativeMethods.cairo_svg_surface_restrict_to_version (Handle, version);
+ NativeMethods.cairo_svg_surface_restrict_to_version (handle, version);
}
}
}
}
public override void Resize (int width, int height)
{
- NativeMethods.cairo_xcb_surface_set_size (Handle, width, height);
+ NativeMethods.cairo_xcb_surface_set_size (handle, width, height);
}
}
}
public void SetDrawable (IntPtr drawable, int width, int height)
{
- NativeMethods.cairo_xlib_surface_set_drawable (Handle, drawable, width, height);
+ NativeMethods.cairo_xlib_surface_set_drawable (handle, drawable, width, height);
}
public override void Resize (int width, int height)
{
- NativeMethods.cairo_xlib_surface_set_size (Handle, width, height);
+ NativeMethods.cairo_xlib_surface_set_size (handle, width, height);
}
- public int Depth => NativeMethods.cairo_xlib_surface_get_depth (Handle);
- public IntPtr Display => NativeMethods.cairo_xlib_surface_get_display (Handle);
- public IntPtr Drawable => NativeMethods.cairo_xlib_surface_get_drawable (Handle);
- public override int Width => NativeMethods.cairo_xlib_surface_get_width (Handle);
- public override int Height => NativeMethods.cairo_xlib_surface_get_height (Handle);
+ public int Depth => NativeMethods.cairo_xlib_surface_get_depth (handle);
+ public IntPtr Display => NativeMethods.cairo_xlib_surface_get_display (handle);
+ public IntPtr Drawable => NativeMethods.cairo_xlib_surface_get_drawable (handle);
+ public override int Width => NativeMethods.cairo_xlib_surface_get_width (handle);
+ public override int Height => NativeMethods.cairo_xlib_surface_get_height (handle);
- public IntPtr Screen => NativeMethods.cairo_xlib_surface_get_screen (Handle);
- public IntPtr Visual=> NativeMethods.cairo_xlib_surface_get_visual (Handle);
+ public IntPtr Screen => NativeMethods.cairo_xlib_surface_get_screen (handle);
+ public IntPtr Visual=> NativeMethods.cairo_xlib_surface_get_visual (handle);
}
}
public void Render(IContext cr) =>
- rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
+ rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : (cr as Context).handle);
public void Render (IContext cr, string id) =>
- rsvg_handle_render_cairo_sub (Raw, cr == null ? IntPtr.Zero : cr.Handle, id);
+ rsvg_handle_render_cairo_sub (Raw, cr == null ? IntPtr.Zero : (cr as Context).handle, id);
[StructLayout(LayoutKind.Sequential)]
struct DimensionData {
</ItemGroup>
<ItemGroup>
- <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3" />
+ <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.155" />
+ <PackageReference Include="Svg.Skia" Version="0.5.10" />
<PackageReference Include="vke" Version="0.2.4-beta" />
- <!--<PackageReference Include="SkiaSharp" Version="2.80.3" />-->
+ <!--<PackageReference Include="SkiaSharp" Version=" 2.88.0-preview.155" />-->
<ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" />
</ItemGroup>
public class Context : IContext
{
VkSurface surf;
- SKCanvas canvas;
+ internal SKCanvas canvas;
SKPaint paint;
SKPath path;
FillRule fillRule = FillRule.NonZero;
SKBlendMode.Darken,
SKBlendMode.Lighten
};
+
internal Context (VkSurface surf)
{
+ this.surf = surf;
canvas = surf.Canvas;
paint = new SKPaint ();
}
Dispose(false);
}
- public IntPtr Handle => throw new NotImplementedException();
-
public double LineWidth {
get => (float)paint.StrokeWidth;
set => paint.StrokeWidth = (float)value;
if (font == null)
createDefaultFont ();
paint.GetFontMetrics (out SKFontMetrics m);
- return new FontExtents (m.Ascent, m.Descent, m.CapHeight, m.XMax, m.XHeight);
+ return new FontExtents (-m.Ascent, m.Descent, m.Descent - m.Ascent, m.MaxCharacterWidth, m.XHeight);
}
}
public Antialias Antialias {
MoveTo (dx + x, dx + y);
}
- public void RenderSvg(IntPtr svgNativeHandle, string subId = null)
- {
- //throw new NotImplementedException();
- }
+ public void RenderSvg(ISvgHandle svgHandle, string subId = null)
+ => svgHandle.Render (this, subId);
public void ResetClip()
{
SKFontStyleWidth.Normal, (SKFontStyleSlant)slant));
updatePaintFont ();
}
-
public void SetDash(double[] dashes, double offset = 0)
{
if (dashes == null || dashes.Length == 1) {
}
paint.PathEffect = SKPathEffect.CreateDash (dashes.Cast<float>().ToArray(), (float)offset);
}
-
public void SetFontSize(double scale)
{
if (font == null)
font.Size = (float)scale;
updatePaintFont ();
}
-
public void SetSource(IPattern pat)
{
- throw new NotImplementedException();
+ if (pat is Gradient gr)
+ paint.Shader = gr.shader;
}
-
public void SetSource(Color color)
{
+ paint.Shader = null;
paint.Color = (UInt32)color;
}
-
public void SetSource(double r, double g, double b, double a = 1)
{
- paint.Color = (UInt32)new Color (r, g, b, a);
+ paint.Shader = null;
+ paint.Color = (UInt32)new Color (a, r, g, b);
}
-
+ VkSurface sourceSurface;
public void SetSource(ISurface surf, double x = 0, double y = 0)
{
- if (!(surf is Surface s))
- return;
- canvas.DrawSurface (s.SkSurf, (float)x, (float)y);
- }
-
- public void ShowText(string text)
- {
- ShowText (text.AsSpan ());
- }
-
- public void ShowText(ReadOnlySpan<char> s, int tabSize = 4)
- {
- int size = s.Length * 4 + 1;
- Span<byte> bytes = size > 512 ? new byte[size] : stackalloc byte[size];
- int encodedBytes = s.ToUtf8 (bytes, tabSize);
- bytes[encodedBytes] = 0;
- ShowText (bytes.Slice (0, encodedBytes + 1));
- }
-
- public void ShowText(Span<byte> bytes)
- {
- SKPoint origin = (path == null) ? SKPoint.Empty : path.LastPoint;
- if (font == null)
- createDefaultFont ();
- SKTextBlob tb = SKTextBlob.Create (bytes, SKTextEncoding.Utf8, font, origin);
- canvas.DrawText (tb, origin.X, origin.Y, paint);
+ VkSurface s = surf as VkSurface;
+ s.Flush();
+ paint.Shader = SKShader.CreateImage(s.SkSurf.Snapshot(),
+ SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, SKMatrix.CreateTranslation ((float)x, (float)y));
+ //canvas.DrawSurface (s.SkSurf, (float)x, (float)y);
}
public void Stroke()
path?.Dispose ();
path = null;
}
-
- public Rectangle StrokeExtents()
- {
- throw new NotImplementedException();
- }
-
public void StrokePreserve()
{
if (path == null)
paint.IsStroke = true;
canvas.DrawPath (path, paint);
}
+ public Rectangle StrokeExtents()
+ {
+ throw new NotImplementedException();
+ }
public TextExtents TextExtents(ReadOnlySpan<char> s, int tabSize = 4)
{
TextExtents (s, tabSize, out Drawing2D.TextExtents e);
return e;
}
-
public void TextExtents(ReadOnlySpan<char> s, int tabSize, out TextExtents extents)
{
if (s.Length == 0) {
bytes[encodedBytes] = 0;
TextExtents (bytes.Slice (0, encodedBytes + 1), out extents);
}
-
public void TextExtents(Span<byte> bytes, out TextExtents extents)
{
if (font == null)
createDefaultFont ();
paint.GetFontMetrics (out SKFontMetrics metrics);
SKRect bounds = default;
- paint.MeasureText (bytes, ref bounds);
+ paint.MeasureText (bytes.Slice (0, bytes.Length - 1), ref bounds);
extents = new TextExtents (0,0,bounds.Width, bounds.Height, bounds.Width, bounds.Height);
}
-
- public void Translate(double dx, double dy)
+ public void ShowText(string text)
{
- canvas.Translate ((float)dx, (float)dy);
+ ShowText (text.AsSpan ());
}
+ public void ShowText(ReadOnlySpan<char> s, int tabSize = 4)
+ {
+ int size = s.Length * 4 + 1;
+ Span<byte> bytes = size > 512 ? new byte[size] : stackalloc byte[size];
+ int encodedBytes = s.ToUtf8 (bytes, tabSize);
+ bytes[encodedBytes] = 0;
+ ShowText (bytes.Slice (0, encodedBytes + 1));
+ }
+ public void ShowText(Span<byte> bytes)
+ {
+ SKPoint origin = (path == null) ? SKPoint.Empty : path.LastPoint;
+ if (font == null)
+ createDefaultFont ();
+ SKTextBlob tb = SKTextBlob.Create (bytes.Slice (0, bytes.Length - 1), SKTextEncoding.Utf8, font);
+
+ canvas.DrawText (tb, origin.X, origin.Y, paint);
+ }
+
+ public void Translate(double dx, double dy) => canvas.Translate ((float)dx, (float)dy);
public void Translate(PointD p) => Translate (p.X, p.Y);
{
public class DefaultBackend : VulkanBackend
{
- public DefaultBackend (IntPtr nativeWindoPointer, int width, int height)
- : base (nativeWindoPointer, width, height) {}
+ public DefaultBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height)
+ : base (ref nativeWindoPointer, out ownGlfwWinHandle, width, height) {}
public DefaultBackend (int width, int height)
: base (width, height) {}
}
--- /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 Drawing2D;
+using SkiaSharp;
+
+namespace Crow.SkiaBackend
+{
+ internal static class Extensions {
+ internal static SKColor ToSkiaColor (this Color c)
+ => new Color (c.A, c.R, c.G, c.B).Value;
+ }
+}
\ No newline at end of file
--- /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.Collections.Generic;
+using Drawing2D;
+using SkiaSharp;
+
+namespace Crow.SkiaBackend
+{
+ public abstract class Gradient : IGradient
+ {
+ internal SKShader shader;
+ protected SKPoint[] points;
+ protected List<SKColor> colorStops = new List<SKColor> ();
+ protected List<float> offsets = new List<float>();
+ protected SKShaderTileMode tileMode = SKShaderTileMode.Clamp;
+ protected Filter filter = Filter.Fast;
+ protected Gradient (SKPoint p0, SKPoint p1) {
+ points = new SKPoint[] {p0, p1};
+ }
+ ~Gradient()
+ {
+ Dispose(false);
+ }
+ public Extend Extend {
+ get => (Extend)tileMode;
+ set => tileMode = (SKShaderTileMode)value;
+ }
+ public Filter Filter {
+ get => throw new NotImplementedException();
+ set => throw new NotImplementedException();
+ }
+
+ public void AddColorStop (double offset, Color c) {
+ shader?.Dispose();
+ shader = null;
+ offsets.Add ((float)offset);
+ colorStops.Add (c.ToSkiaColor());
+ }
+ public void AddColorStop(float offset, float r, float g, float b, float a = 1f) {
+ shader?.Dispose();
+ shader = null;
+ offsets.Add ((float)offset);
+ colorStops.Add (new Color (a,r,g,b).Value);
+ }
+ internal abstract void Activate ();
+
+ #region IDisposable implementation
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposing)
+ return;
+ shader?.Dispose ();
+ }
+ #endregion
+ }
+ public class LinearGradient : Gradient {
+ public LinearGradient (float x0, float y0, float x1, float y1)
+ : base (new SKPoint (x0, y0), new SKPoint (x1, y1)) { }
+
+ internal override void Activate()
+ {
+ if (shader != null)
+ return;
+ shader = SKShader.CreateLinearGradient (points[0], points[1],
+ colorStops.ToArray(), offsets.ToArray(), tileMode);
+ }
+ }
+ public class RadialGradient : Gradient {
+ float[] radiuses;
+ public RadialGradient ( float cx0, float cy0, float radius0,
+ float cx1, float cy1, float radius1)
+ : base (new SKPoint (cx0, cy0), new SKPoint (cx1, cy1)) {
+ radiuses = new float[] {radius0, radius1};
+ }
+
+ internal override void Activate()
+ {
+ if (shader != null)
+ return;
+ shader = SKShader.CreateRadialGradient (points[0], radiuses[0],
+ colorStops.ToArray(), offsets.ToArray(), tileMode);
+ }
+ }
+}
\ No newline at end of file
}
};
rt = new GRBackendRenderTarget (width, height, (int)samples, imgInfo);
- skSurf = SKSurface.Create (gr, rt, SKColorType.Rgba8888);
+ skSurf = SKSurface.Create (gr, rt, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888, SKColorSpace.CreateSrgb());
}
~VkSurface ()
{
--- /dev/null
+// Copyright (c) 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;
+using SkiaSharp;
+using Svg.Skia;
+
+namespace Crow.SkiaBackend
+{
+ public sealed class SvgHandle : ISvgHandle {
+
+ SKSvg handle;
+
+ SvgHandle () {
+ handle = new SKSvg ();
+ }
+ internal SvgHandle (string file_name) : this ()
+ {
+ handle.Load (file_name);
+ }
+ internal SvgHandle (Stream stream) : this ()
+ {
+ handle.Load (stream);
+ }
+ internal static SvgHandle FromFragment (string framgment) {
+ SvgHandle svg = new SvgHandle();
+ svg.handle.FromSvg (framgment);
+ return svg;
+ }
+
+ public void Render(IContext cr)
+ {
+ Context ctx = cr as Context;
+ ctx.canvas.DrawPicture (handle.Picture);
+ }
+ public void Render (IContext cr, string id)
+ {
+ Context ctx = cr as Context;
+ ctx.canvas.DrawPicture (handle.Picture);
+ }
+ public Size Dimensions
+ => new Size ((int)handle.Drawable.Bounds.Width, (int)handle.Drawable.Bounds.Height);
+
+ public void Dispose() {
+ handle.Dispose ();
+ }
+
+ }
+}
Vk.vkGetDeviceProcAddr (device, n);
}
}
-
+ #region CTOR
/// <summary>
/// Create a new offscreen backend, used in perfTests
/// </summary>
dev.Activate (enabledFeatures);
}
- public VulkanBackend (IntPtr nativeWindoPointer, int width, int height) : base ()
+ public VulkanBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height)
+ : base ()
{
- hWin = nativeWindoPointer;
+ if (nativeWindoPointer == IntPtr.Zero) {
+ Glfw3.Init ();
+ Glfw3.WindowHint (WindowAttribute.ClientApi, 0);
+ Glfw3.WindowHint (WindowAttribute.Resizable, 1);
+ Glfw3.WindowHint (WindowAttribute.Decorated, 1);
+
+ hWin = Glfw3.CreateWindow (width, height, "win name", MonitorHandle.Zero, IntPtr.Zero);
+ if (hWin == IntPtr.Zero)
+ throw new Exception ("[GLFW3] Unable to create Window");
+
+ nativeWindoPointer = hWin;
+ ownGlfwWinHandle = true;
+ } else {
+ hWin = nativeWindoPointer;
+ ownGlfwWinHandle = false;
+ }
SwapChain.IMAGES_USAGE = VkImageUsageFlags.ColorAttachment | VkImageUsageFlags.TransferDst;
- SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm;
+ SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Srgb;
List<string> instExts = new List<string> (Glfw3.GetRequiredInstanceExtensions ());
#if DEBUG
phy = phys[0];
VkPhysicalDeviceFeatures enabledFeatures = default;
+
dev = new vke.Device (phy);
graphicQueue = new PresentQueue (dev, VkQueueFlags.Graphics, hSurf);
{
Dispose (false);
}
+ #endregion
public IContext CreateContext(ISurface surf) => new Context (surf as VkSurface);
public IGradient CreateGradient(GradientType gradientType, Rectangle bounds)
{
- throw new NotImplementedException();
+ switch (gradientType) {
+ case GradientType.Vertical:
+ return new LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
+ case GradientType.Horizontal:
+ return new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top);
+ case GradientType.Oblic:
+ return new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
+ case GradientType.Radial:
+ throw new NotImplementedException ();
+ }
+ return null;
}
public IRegion CreateRegion () => new Crow.SkiaBackend.Region ();
public ISurface CreateSurface(int width, int height)
- {
- return new VkSurface (dev, graphicQueue, gr, (int)width, (int)height, samples);
- }
-
+ => new VkSurface (dev, graphicQueue, gr, (int)width, (int)height, samples);
public ISurface CreateSurface(byte[] data, int width, int height)
{
throw new NotImplementedException();
}
public ISvgHandle LoadSvg(Stream stream)
- {
- throw new NotImplementedException();
- }
+ => new SvgHandle (stream);
public ISvgHandle LoadSvg(string svgFragment)
{
}
public void FlushUIFrame(IContext ctx)
{
+ //surf.Canvas.Flush ();
+ surf.Flush();
+
if (disposeContextOnFlush)
ctx.Dispose ();
clipping = null;
{
public class Context : IContext
{
+ internal IntPtr handle = IntPtr.Zero;
- IntPtr handle = IntPtr.Zero;
-
- public Context (ISurface surf)
+ internal Context (Surface surf)
{
- handle = NativeMethods.vkvg_create(surf.Handle);
+ handle = NativeMethods.vkvg_create(surf.handle);
this.FillRule = FillRule.NonZero;
}
~Context()
Dispose(false);
}
- public IntPtr Handle => handle;
-
public double LineWidth
{
get => NativeMethods.vkvg_get_line_width(handle);
set;
get;
}
- public void Arc(double xc, double yc, double radius, double a1, double a2)
- => NativeMethods.vkvg_arc(handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2);
- public void Arc (PointD center, double radius, double angle1, double angle2)
- => NativeMethods.vkvg_arc (handle, (float)center.X, (float)center.Y, (float)radius, (float)angle1, (float)angle2);
- public void ArcNegative (PointD center, double radius, double angle1, double angle2)
- => NativeMethods.vkvg_arc_negative (handle, (float)center.X, (float)center.Y, (float)radius, (float)angle1, (float)angle2);
- public void ArcNegative(double xc, double yc, double radius, double a1, double a2)
- {
- NativeMethods.vkvg_arc_negative(handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2);
- }
public void Clear() => NativeMethods.vkvg_clear(handle);
public void SetFontSize (double size) => NativeMethods.vkvg_set_font_size(handle, (uint)size);
public void ClosePath() => NativeMethods.vkvg_close_path (handle);
-
- public void CurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
- => NativeMethods.vkvg_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3);
-
+ public void NewPath() => NativeMethods.vkvg_new_path(handle);
+ public void NewSubPath() => NativeMethods.vkvg_new_sub_path(handle);
+ public void Arc(double xc, double yc, double radius, double a1, double a2)
+ => NativeMethods.vkvg_arc(handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2);
+ public void Arc (PointD center, double radius, double angle1, double angle2)
+ => NativeMethods.vkvg_arc (handle, (float)center.X, (float)center.Y, (float)radius, (float)angle1, (float)angle2);
+ public void ArcNegative (PointD center, double radius, double angle1, double angle2)
+ => NativeMethods.vkvg_arc_negative (handle, (float)center.X, (float)center.Y, (float)radius, (float)angle1, (float)angle2);
+ public void ArcNegative(double xc, double yc, double radius, double a1, double a2)
+ => NativeMethods.vkvg_arc_negative(handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2);
/*public IntPtr Handle => handle;
public void AddReference()
throw new NotImplementedException();
}
*/
- public void MoveTo(float x, float y)
- {
- NativeMethods.vkvg_move_to(handle, x, y);
- }
- public void RelMoveTo(float x, float y)
- {
- NativeMethods.vkvg_rel_move_to(handle, x, y);
- }
- public void LineTo(float x, float y)
- {
- NativeMethods.vkvg_line_to(handle, x, y);
- }
- public void LineTo(Point p)
- {
- NativeMethods.vkvg_line_to(handle, p.X, p.Y);
- }
- public void LineTo(PointD p)
- {
- NativeMethods.vkvg_line_to(handle, (float)p.X, (float)p.Y);
- }
- public void RelLineTo(float x, float y)
- {
- NativeMethods.vkvg_rel_line_to(handle, x, y);
- }
- public void CurveTo(float x1, float y1, float x2, float y2, float x3, float y3)
- {
- NativeMethods.vkvg_curve_to(handle, x1, y1, x2, y2, x3, y3);
- }
- public void RelCurveTo(float x1, float y1, float x2, float y2, float x3, float y3)
- {
- NativeMethods.vkvg_rel_curve_to(handle, x1, y1, x2, y2, x3, y3);
- }
-
- public void MoveTo(double x, double y)
- {
- NativeMethods.vkvg_move_to(handle, (float)x, (float)y);
- }
- public void RelMoveTo(double x, double y)
- {
- NativeMethods.vkvg_rel_move_to(handle, (float)x, (float)y);
- }
- public void LineTo(double x, double y)
- {
- NativeMethods.vkvg_line_to(handle, (float)x, (float)y);
- }
- public void RelLineTo(double x, double y)
- {
- NativeMethods.vkvg_rel_line_to(handle, (float)x, (float)y);
- }
+ //public void MoveTo(float x, float y) => NativeMethods.vkvg_move_to(handle, x, y);
+ public void MoveTo(double x, double y) => NativeMethods.vkvg_move_to(handle, (float)x, (float)y);
+ public void MoveTo(Point p) => NativeMethods.vkvg_move_to(handle, p.X, p.Y);
+ public void MoveTo(PointD p) => NativeMethods.vkvg_move_to(handle, (float)p.X, (float)p.Y);
+ //public void RelMoveTo(float x, float y) => NativeMethods.vkvg_rel_move_to(handle, x, y);
+ //public void LineTo(float x, float y) => NativeMethods.vkvg_line_to(handle, x, y);
+ public void LineTo(Point p) => NativeMethods.vkvg_line_to(handle, p.X, p.Y);
+ public void LineTo(PointD p) => NativeMethods.vkvg_line_to(handle, (float)p.X, (float)p.Y);
+ public void LineTo(double x, double y) => NativeMethods.vkvg_line_to(handle, (float)x, (float)y);
+ //public void RelLineTo(float x, float y) => NativeMethods.vkvg_rel_line_to(handle, x, y);
+ /*public void CurveTo(float x1, float y1, float x2, float y2, float x3, float y3)
+ => NativeMethods.vkvg_curve_to(handle, x1, y1, x2, y2, x3, y3);*/
+ public void CurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
+ => NativeMethods.vkvg_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3);
+ public void RelMoveTo(double x, double y) => NativeMethods.vkvg_rel_move_to(handle, (float)x, (float)y);
+ public void RelLineTo(double x, double y) => NativeMethods.vkvg_rel_line_to(handle, (float)x, (float)y);
public void RelCurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
- {
- NativeMethods.vkvg_rel_curve_to(handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3);
- }
+ => NativeMethods.vkvg_rel_curve_to(handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3);
+ //public void RelCurveTo(float x1, float y1, float x2, float y2, float x3, float y3)
+ // => NativeMethods.vkvg_rel_curve_to(handle, x1, y1, x2, y2, x3, y3);
+ public void Rectangle(double x, double y, double width, double height)
+ => NativeMethods.vkvg_rectangle (handle, (float)x, (float)y, (float)width, (float)height);
+ public void Rectangle(Rectangle r)
+ => NativeMethods.vkvg_rectangle (handle, (float)r.X, (float)r.Y, (float)r.Width, (float)r.Height);
+
- public void SetSource(Pattern pat)
- {
- NativeMethods.vkvg_set_source(handle, pat.Handle);
- }
public void SetSource(IPattern pat) {
if (pat is Pattern p)
- NativeMethods.vkvg_set_source (handle, p.Handle);
+ NativeMethods.vkvg_set_source (handle, p.handle);
}
public void SetSource (Color color)
{
- NativeMethods.vkvg_set_source_rgba (handle, (float)(color.R / 255.0), (float)(color.G / 255.0), (float)(color.B / 255.0), (float)(color.A / 255.0));
+ NativeMethods.vkvg_set_source_rgba (handle,
+ (float)(color.R / 255.0), (float)(color.G / 255.0), (float)(color.B / 255.0), (float)(color.A / 255.0));
}
public void SetSource(ISurface surf, double x = 0, double y = 0)
- {
- NativeMethods.vkvg_set_source_surface(handle, surf.Handle, (float)x, (float)y);
- }
+ => NativeMethods.vkvg_set_source_surface(handle, (surf as Surface).handle, (float)x, (float)y);
public void SetSource(double r, double g, double b, double a = 1.0)
- {
- NativeMethods.vkvg_set_source_rgba(handle, (float)r, (float)g, (float)b, (float)a);
- }
- public void RenderSvg(IntPtr nsvgImage, string subId = null)
- {
- NativeMethods.vkvg_render_svg(handle, nsvgImage, subId);
- }
-
+ => NativeMethods.vkvg_set_source_rgba(handle, (float)r, (float)g, (float)b, (float)a);
+ public void RenderSvg(ISvgHandle nsvgImage, string subId = null)
+ => nsvgImage.Render (this, subId);
Matrix savedMat = Matrix.Identity;
- public void SaveTransformations()
- {
- NativeMethods.vkvg_get_matrix (handle, out savedMat);
- }
-
- public void RestoreTransformations()
- {
- NativeMethods.vkvg_set_matrix (handle, ref savedMat);
- }
+ public void SaveTransformations() => NativeMethods.vkvg_get_matrix (handle, out savedMat);
+ public void RestoreTransformations() => NativeMethods.vkvg_set_matrix (handle, ref savedMat);
- Rectangle IContext.StrokeExtents()
- {
- throw new NotImplementedException();
- }
- public void Scale(double sx, double sy)
- {
- NativeMethods.vkvg_scale(handle, (float)sx, (float)sy);
- }
- public void Translate(double dx, double dy)
- {
- NativeMethods.vkvg_translate(handle, (float)dx, (float)dy);
- }
- public void Translate(PointD p)
- {
- NativeMethods.vkvg_translate(handle, (float)p.X, (float)p.Y);
- }
- public void Rotate(double alpha)
- {
- NativeMethods.vkvg_rotate(handle, (float)alpha);
- }
+ public void Scale(double sx, double sy) => NativeMethods.vkvg_scale(handle, (float)sx, (float)sy);
+ public void Translate(double dx, double dy) => NativeMethods.vkvg_translate(handle, (float)dx, (float)dy);
+ public void Translate(PointD p) => NativeMethods.vkvg_translate(handle, (float)p.X, (float)p.Y);
+ public void Rotate(double alpha) => NativeMethods.vkvg_rotate(handle, (float)alpha);
- public void Fill()
- {
- NativeMethods.vkvg_fill(handle);
- }
- public void FillPreserve()
- {
- NativeMethods.vkvg_fill_preserve(handle);
- }
- public void Stroke()
- {
- NativeMethods.vkvg_stroke(handle);
- }
- public void StrokePreserve()
- {
- NativeMethods.vkvg_stroke_preserve(handle);
- }
- public void NewPath()
- {
- NativeMethods.vkvg_new_path(handle);
- }
- public void NewSubPath()
- {
- NativeMethods.vkvg_new_sub_path(handle);
- }
- public void MoveTo(PointD p)
- {
- NativeMethods.vkvg_move_to(handle, (float)p.X, (float)p.Y);
- }
- public void MoveTo(Point p)
+ public void Fill() => NativeMethods.vkvg_fill(handle);
+ public void FillPreserve() => NativeMethods.vkvg_fill_preserve(handle);
+ public void Stroke() => NativeMethods.vkvg_stroke(handle);
+ public void StrokePreserve() => NativeMethods.vkvg_stroke_preserve(handle);
+ public Rectangle StrokeExtents()
{
- NativeMethods.vkvg_move_to(handle, p.X, p.Y);
+ throw new NotImplementedException();
}
-
-
public void PopGroupToSource()
{
throw new NotImplementedException();
}
-
public void PushGroup()
{
throw new NotImplementedException();
}
- public void Rectangle(double x, double y, double width, double height)
- => NativeMethods.vkvg_rectangle (handle, (float)x, (float)y, (float)width, (float)height);
- public void Rectangle(Rectangle r)
- => NativeMethods.vkvg_rectangle (handle, (float)r.X, (float)r.Y, (float)r.Width, (float)r.Height);
public void SelectFontFace(string family, FontSlant slant, FontWeight weight)
}
public void ShowText(TextRun textRun)
- {
- NativeMethods.vkvg_show_text_run(handle, textRun.Handle);
- }
+ => NativeMethods.vkvg_show_text_run(handle, textRun.Handle);
- public Rectangle StrokeExtents()
- {
- throw new NotImplementedException();
- }
#region IDisposable implementation
surf = new VkvgBackend.Surface (vkvgDev, (int)width, (int)height);
}
- public DefaultBackend (IntPtr nativeWindoPointer, int width, int height)
+ public DefaultBackend (ref IntPtr nativeWindoPointer, out bool ownGlfwWinHandle, int width, int height)
{
- hWin = nativeWindoPointer;
+ if (nativeWindoPointer == IntPtr.Zero) {
+ Glfw3.Init ();
+ Glfw3.WindowHint (WindowAttribute.ClientApi, 0);
+ Glfw3.WindowHint (WindowAttribute.Resizable, 1);
+ Glfw3.WindowHint (WindowAttribute.Decorated, 1);
+
+ hWin = Glfw3.CreateWindow (width, height, "win name", MonitorHandle.Zero, IntPtr.Zero);
+ if (hWin == IntPtr.Zero)
+ throw new Exception ("[GLFW3] Unable to create Window");
+
+ nativeWindoPointer = hWin;
+ ownGlfwWinHandle = true;
+ } else {
+ hWin = nativeWindoPointer;
+ ownGlfwWinHandle = false;
+ }
SwapChain.IMAGES_USAGE = VkImageUsageFlags.ColorAttachment | VkImageUsageFlags.TransferDst;
SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm;
vkvgDev = new Crow.VkvgBackend.Device (
instance.Handle, phy.Handle, dev.VkDev.Handle, graphicQueue.qFamIndex, samples);
+ vkvgDev.SetDpy (72,72);
createMainSurface ((uint)width, (uint)height);
}
public IRegion CreateRegion () => new Crow.VkvgBackend.Region ();
public IContext CreateContext (ISurface surf)
{
- Crow.VkvgBackend.Context gr = new Crow.VkvgBackend.Context (surf);
+ Crow.VkvgBackend.Context gr = new VkvgBackend.Context (surf as VkvgBackend.Surface);
return gr;
}
//IPattern CreatePattern (PatternType patternType);
IContext ctx = existingContext;
if (ctx == null) {
disposeContextOnFlush = true;
- ctx = new VkvgBackend.Context (MainSurface);
+ ctx = new VkvgBackend.Context (surf);
} else
disposeContextOnFlush = false;
{
public class Pattern : IPattern
{
- protected IntPtr handle = IntPtr.Zero;
- public IntPtr Handle => handle;
+ internal IntPtr handle = IntPtr.Zero;
#region CTORS & DTOR
protected Pattern(IntPtr handle)
}
public Pattern(Surface surf)
{
- handle = NativeMethods.vkvg_pattern_create_for_surface(surf.Handle);
+ handle = NativeMethods.vkvg_pattern_create_for_surface(surf.handle);
}
~Pattern()
}
public uint References() => NativeMethods.vkvg_pattern_get_reference_count(handle);
-
public Extend Extend
{
get => NativeMethods.vkvg_pattern_get_extend(handle);
{
public class Surface: ISurface
{
- IntPtr handle = IntPtr.Zero;
+ internal IntPtr handle = IntPtr.Zero;
Device vkvgDev;
#region CTOR
{
Dispose (false);
}
-
- public IntPtr Handle => handle;
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 sealed class SvgHandle : ISvgHandle {
- IntPtr handle;
+ internal IntPtr handle;
+ #region CTOR
public SvgHandle (Device dev, Span<byte> bytes)
{
/*int size = svgFragment.Length * 4 + 1;
{
handle = NativeMethods.nsvg_load_file (dev.Handle, file_name);
}
+ #endregion
public void Render(IContext cr) =>
- cr.RenderSvg (handle);
-
+ NativeMethods.vkvg_render_svg((cr as Context).handle, handle, null);
public void Render (IContext cr, string id) =>
- cr.RenderSvg (handle, id);
-
+ NativeMethods.vkvg_render_svg((cr as Context).handle, handle, id);
public Size Dimensions {
get {
NativeMethods.nsvg_get_size (handle, out int w, out int h);
<ItemGroup>
<ProjectReference Include="..\Drawing2D\Drawing2D.csproj" />
- <ProjectReference Include="..\Backends\SkiaBackend\SkiaBackend.csproj" />
- <!--<ProjectReference Include="..\Backends\CairoBackend\CairoBackend.csproj" />-->
+ <!--<ProjectReference Include="..\Backends\SkiaBackend\SkiaBackend.csproj" />-->
+ <ProjectReference Include="..\Backends\CairoBackend\CairoBackend.csproj" />
<!--<ProjectReference Include="..\Backends\VkvgBackend\VkvgBackend.csproj" />-->
</ItemGroup>
clientRectangle = new Rectangle (0, 0, width, height);
SingleThreaded = singleThreaded;
- if (createSurface)
- initSurface ();
+ initBackend ();
PerformanceMeasure.InitMeasures ();
manage VkWindow instance. */
static Dictionary<IntPtr, Interface> windows = new Dictionary<IntPtr, Interface> ();
/** GLFW window native pointer and current native handle for mouse cursor */
- IntPtr hWin;
+ protected IntPtr hWin;
+ /// <summary>
+ /// True if GLFW window has been created by the backend and should be disposed with the `Interface`, false otherwise.
+ /// </summary>
+ protected bool ownWindow;
protected IBackend backend;//backend device
/// <summary>Clipping rectangles on the root context</summary>
protected IRegion clipping;
static string backendDeviceTypeString = "Crow.CairoBackend.Device";
Cursor currentCursor;
- bool ownWindow;
/// <summary>
/// If `true`, UI updates will be handle in the `Run()` method, so in the main thread of the application along with GLFW events polling.
/// If `false`, A dedicated thread will be started for the UI updates.
public IntPtr SurfacePointer {
get {
lock(UpdateMutex)
- return MainSurface.Handle;
+ return IntPtr.Zero;// MainSurface.Handle;
}
}
}
protected virtual void initBackend () {
- backend = new Crow.Backends.DefaultBackend (hWin, clientRectangle.Width, clientRectangle.Height);
+ backend = new Crow.Backends.DefaultBackend (ref hWin, out ownWindow, clientRectangle.Width, clientRectangle.Height);
clipping = Backend.CreateRegion ();
- }
- /// <summary>
- /// Create the main rendering surface. The default is a GLFW window with a cairo surface bound to it.
- /// </summary>
- protected void initSurface ()
- {
- Glfw3.Init ();
-
-
- Glfw3.WindowHint (WindowAttribute.ClientApi, 0);
- /*Glfw3.WindowHint (WindowAttribute.ClientApi, Constants.OpenglEsApi);
- Glfw3.WindowHint (WindowAttribute.ContextVersionMajor, 3);
- Glfw3.WindowHint (WindowAttribute.ContextVersionMinor, 2);
- Glfw3.WindowHint (WindowAttribute.ContextCreationApi, Constants.EglContextApi);*/
-
- Glfw3.WindowHint (WindowAttribute.Resizable, 1);
- Glfw3.WindowHint (WindowAttribute.Decorated, 1);
-
- hWin = Glfw3.CreateWindow (clientRectangle.Width, clientRectangle.Height, "win name", MonitorHandle.Zero, IntPtr.Zero);
- if (hWin == IntPtr.Zero)
- throw new Exception ("[GLFW3] Unable to create Window");
- ownWindow = true;
-
registerGlfwCallbacks ();
-
- initBackend ();
}
/// <summary>
/// search for graphic object type in crow assembly, if not found,
}
ctx.SetSource (bmp, rb.X, rb.Y);
ctx.Paint ();
-#if VKVG
ctx.Flush ();
-#endif
+
DbgLogger.EndEvent(DbgEvtType.GOPaintCache);
}
protected virtual void UpdateCache(IContext ctx){
public interface IContext : IDisposable
{
- IntPtr Handle { get; }
-
double LineWidth { get; set; }
LineJoin LineJoin { get; set; }
LineCap LineCap { get; set; }
void SetSource (Color color);
void SetSource(double r, double g, double b, double a = 1.0);
void SetSource(ISurface surf, double x = 0f, double y = 0f);
- void RenderSvg(IntPtr svgNativeHandle, string subId = null);
+ void RenderSvg(ISvgHandle svgHandle, string subId = null);
void PushGroup ();
void PopGroupToSource ();
{
public interface IPattern : IDisposable
{
- IntPtr Handle { get; }
Extend Extend { get; set; }
Filter Filter { get; set; }
}
{
public interface ISurface: IDisposable
{
- IntPtr Handle { get; }
int Width { get; }
int Height { get; }
writer.WriteLine ("Path;MinEllapsed;MaxEllapsed;MeanEllapsed;MedianEllapsed;sigmaEllapsed;MinMem;MaxMem;MeanMem;MedianMem;sigmaMem;MinAlloc;MaxAlloc;MeanAlloc;MedianAlloc;sigmaAlloc");
}
- if (screenOutput)
- initSurface ();
- else
- initBackend ();
+ initBackend ();
initDictionaries ();
loadStyling ();
protected override void initBackend()
{
if (screenOutput)
- backend = new Crow.Backends.DefaultBackend (WindowHandle, clientRectangle.Width, clientRectangle.Height);
+ backend = new Crow.Backends.DefaultBackend (ref hWin, out ownWindow, clientRectangle.Width, clientRectangle.Height);
else
backend = new Crow.Backends.DefaultBackend (clientRectangle.Width, clientRectangle.Height);