]> O.S.I.I.S - jp/crow.git/commitdiff
split vkvgBackend class with specialized class for swapchain support to prepare vulka...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 3 Aug 2021 07:41:59 +0000 (09:41 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 3 Aug 2021 07:41:59 +0000 (09:41 +0200)
Crow/src/GraphicBackends/vkvg/NativeMethods.cs
Crow/src/GraphicBackends/vkvg/VulkanContext.cs
Crow/src/Interface.cs
Directory.Build.props

index c87cb1823a8fe8533bef79b31cb1f10fef4ee5fd..d96eab8fe303ea36d084eaf5f775bc786ba8347b 100644 (file)
@@ -7,138 +7,138 @@ using System.Runtime.InteropServices;
 
 namespace Crow.Drawing
 {
-    internal static class NativeMethods
-    {
-        const string libvkvg = "vkvg";
+       internal static class NativeMethods
+       {
+               const string libvkvg = "vkvg";
 
-        #region Device
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_device_create(IntPtr instance, IntPtr phy, IntPtr dev, uint qFamIdx, uint qIndex);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_device_destroy(IntPtr device);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_device_create_multisample(IntPtr inst, IntPtr phy, IntPtr vkdev, uint qFamIdx, uint qIndex, SampleCount samples, bool deferredResolve);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_device_reference(IntPtr dev);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern uint vkvg_device_get_reference_count(IntPtr dev);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_device_set_dpy(IntPtr dev, int hdpy, int vdpy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_device_get_dpy(IntPtr dev, out int hdpy, out int vdpy);
-        #endregion
+               #region Device
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_device_create(IntPtr instance, IntPtr phy, IntPtr dev, uint qFamIdx, uint qIndex);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_device_destroy(IntPtr device);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_device_create_multisample(IntPtr inst, IntPtr phy, IntPtr vkdev, uint qFamIdx, uint qIndex, SampleCount samples, bool deferredResolve);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_device_reference(IntPtr dev);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern uint vkvg_device_get_reference_count(IntPtr dev);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_device_set_dpy(IntPtr dev, int hdpy, int vdpy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_device_get_dpy(IntPtr dev, out int hdpy, out int vdpy);
+               #endregion
 
-        #region Context
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_create(IntPtr surface);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_destroy(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_flush(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_new_path(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_new_sub_path(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_close_path(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_line_to(IntPtr ctx, float x, float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_rel_line_to(IntPtr ctx, float x, float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_move_to(IntPtr ctx, float x, float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_rel_move_to(IntPtr ctx, float x, float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_arc(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_arc_negative(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_rel_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_rectangle(IntPtr ctx, float x, float y, float width, float height);
+               #region Context
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_create(IntPtr surface);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_destroy(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_flush(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_new_path(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_new_sub_path(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_close_path(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_line_to(IntPtr ctx, float x, float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_rel_line_to(IntPtr ctx, float x, float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_move_to(IntPtr ctx, float x, float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_rel_move_to(IntPtr ctx, float x, float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_arc(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_arc_negative(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_rel_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_rectangle(IntPtr ctx, float x, float y, float width, float height);
 
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_scale(IntPtr ctx, float sx, float sy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_translate(IntPtr ctx, float dx, float dy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_rotate(IntPtr ctx, float alpha);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_transform(IntPtr ctx, ref Matrix matrix);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_matrix(IntPtr ctx, ref Matrix matrix);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_get_matrix(IntPtr ctx, out Matrix matrix);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_identity_matrix(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_scale(IntPtr ctx, float sx, float sy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_translate(IntPtr ctx, float dx, float dy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_rotate(IntPtr ctx, float alpha);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_transform(IntPtr ctx, ref Matrix matrix);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_matrix(IntPtr ctx, ref Matrix matrix);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_get_matrix(IntPtr ctx, out Matrix matrix);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_identity_matrix(IntPtr ctx);
 
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_stroke(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_stroke_preserve(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_clip(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_clip_preserve(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_reset_clip(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_fill(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_fill_preserve(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_paint(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_source_rgba(IntPtr ctx, float r, float g, float b, float a);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_line_width(IntPtr ctx, float width);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_line_cap(IntPtr ctx, LineCap cap);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_line_join(IntPtr ctx, LineJoin join);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_operator(IntPtr ctx, Operator op);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern FillRule vkvg_get_fill_rule(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_fill_rule(IntPtr ctx, FillRule fr);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern Operator vkvg_get_operator(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_source_surface(IntPtr ctx, IntPtr surf, float x, float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_source(IntPtr ctx, IntPtr pattern);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_font_extents(IntPtr ctx, out FontExtents extents);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_text_extents(IntPtr ctx, byte[] utf8, out TextExtents extents);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_text_extents(IntPtr cr, ref byte utf8, out TextExtents extents);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_select_font_face(IntPtr ctx, string name);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_set_font_size(IntPtr ctx, uint size);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_show_text(IntPtr ctx, byte [] utf8);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_show_text(IntPtr cr, ref byte utf8);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_save(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_restore(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_clear(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern float vkvg_get_line_width(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern LineCap vkvg_get_line_cap(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern LineJoin vkvg_get_line_join(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_get_source(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_stroke(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_stroke_preserve(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_clip(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_clip_preserve(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_reset_clip(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_fill(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_fill_preserve(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_paint(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_source_rgba(IntPtr ctx, float r, float g, float b, float a);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_line_width(IntPtr ctx, float width);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_line_cap(IntPtr ctx, LineCap cap);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_line_join(IntPtr ctx, LineJoin join);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_operator(IntPtr ctx, Operator op);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern FillRule vkvg_get_fill_rule(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_fill_rule(IntPtr ctx, FillRule fr);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern Operator vkvg_get_operator(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_source_surface(IntPtr ctx, IntPtr surf, float x, float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_source(IntPtr ctx, IntPtr pattern);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_font_extents(IntPtr ctx, out FontExtents extents);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_text_extents(IntPtr ctx, byte[] utf8, out TextExtents extents);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_text_extents(IntPtr cr, ref byte utf8, out TextExtents extents);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_select_font_face(IntPtr ctx, string name);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_set_font_size(IntPtr ctx, uint size);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_show_text(IntPtr ctx, byte [] utf8);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_show_text(IntPtr cr, ref byte utf8);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_save(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_restore(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_clear(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern float vkvg_get_line_width(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern LineCap vkvg_get_line_cap(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern LineJoin vkvg_get_line_join(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_get_source(IntPtr ctx);
 
                [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
                internal static extern void vkvg_set_dash (IntPtr ctx, float[] dashes, uint dashCount, float offset);
@@ -147,129 +147,131 @@ namespace Crow.Drawing
                //void vkvg_get_dash (VkvgContext ctx, const float* dashes, uint32_t* num_dashes, float* offset
 
           [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_reference(IntPtr ctx);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern uint vkvg_get_reference_count(IntPtr ctx);
-        #endregion
+               internal static extern IntPtr vkvg_reference(IntPtr ctx);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern uint vkvg_get_reference_count(IntPtr ctx);
+               #endregion
 
-        #region TextRun
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_text_run_create(IntPtr ctx, byte[] utf8);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_text_run_destroy(IntPtr textRun);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_show_text_run(IntPtr ctx, IntPtr textRun);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_text_run_get_extents(IntPtr textRun, out TextExtents extents);
-        #endregion
+               #region TextRun
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_text_run_create(IntPtr ctx, byte[] utf8);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_text_run_destroy(IntPtr textRun);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_show_text_run(IntPtr ctx, IntPtr textRun);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_text_run_get_extents(IntPtr textRun, out TextExtents extents);
+               #endregion
 
-        #region Pattern
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create();
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_reference(IntPtr pat);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern uint vkvg_pattern_get_reference_count(IntPtr pat);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create_rgba(float r, float g, float b, float a);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create_rgb(float r, float g, float b);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create_for_surface(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create_linear(float x0, float y0, float x1, float y1);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_pattern_create_radial(float cx0, float cy0, float radius0,
-                                             float cx1, float cy1, float radius1);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_pattern_destroy(IntPtr pat);
+               #region Pattern
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create();
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_reference(IntPtr pat);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern uint vkvg_pattern_get_reference_count(IntPtr pat);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create_rgba(float r, float g, float b, float a);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create_rgb(float r, float g, float b);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create_for_surface(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create_linear(float x0, float y0, float x1, float y1);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_pattern_create_radial(float cx0, float cy0, float radius0,
+                                                                                        float cx1, float cy1, float radius1);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_pattern_destroy(IntPtr pat);
 
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_pattern_add_color_stop(IntPtr pat, float offset, float r, float g, float b, float a);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_pattern_set_extend(IntPtr pat, Extend extend);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_pattern_set_filter(IntPtr pat, Filter filter);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_pattern_add_color_stop(IntPtr pat, float offset, float r, float g, float b, float a);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_pattern_set_extend(IntPtr pat, Extend extend);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_pattern_set_filter(IntPtr pat, Filter filter);
 
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern Extend vkvg_pattern_get_extend(IntPtr pat);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern Filter vkvg_pattern_get_filter(IntPtr pat);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern PatternType vkvg_pattern_get_type(IntPtr pat);
-        #endregion
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern Extend vkvg_pattern_get_extend(IntPtr pat);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern Filter vkvg_pattern_get_filter(IntPtr pat);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern PatternType vkvg_pattern_get_type(IntPtr pat);
+               #endregion
 
-        #region Matrices
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_init_identity(out Matrix matrix);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_init(out Matrix matrix,
-           float xx, float yx,
-           float xy, float yy,
-           float x0, float y0);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_init_translate(out Matrix matrix, float tx, float ty);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_init_scale(out Matrix matrix, float sx, float sy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_init_rotate(out Matrix matrix, float radians);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_translate(ref Matrix matrix, float tx, float ty);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_scale(ref Matrix matrix, float sx, float sy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_rotate(ref Matrix matrix, float radians);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_multiply(out Matrix result, ref Matrix a, ref Matrix b);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_transform_distance(ref Matrix matrix, ref float dx, ref float dy);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_transform_point(ref Matrix matrix, ref float x, ref float y);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_matrix_invert(ref Matrix matrix);
-        #endregion
+               #region Matrices
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_init_identity(out Matrix matrix);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_init(out Matrix matrix,
+                  float xx, float yx,
+                  float xy, float yy,
+                  float x0, float y0);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_init_translate(out Matrix matrix, float tx, float ty);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_init_scale(out Matrix matrix, float sx, float sy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_init_rotate(out Matrix matrix, float radians);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_translate(ref Matrix matrix, float tx, float ty);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_scale(ref Matrix matrix, float sx, float sy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_rotate(ref Matrix matrix, float radians);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_multiply(out Matrix result, ref Matrix a, ref Matrix b);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_transform_distance(ref Matrix matrix, ref float dx, ref float dy);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_transform_point(ref Matrix matrix, ref float x, ref float y);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_matrix_invert(ref Matrix matrix);
+               #endregion
 
-        #region Surface
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create(IntPtr device, uint width, uint height);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create_from_image(IntPtr dev, string filePath);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create_from_svg(IntPtr dev, string filePath);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create_from_svg_fragment(IntPtr dev, byte[] filePath);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create_from_bitmap(IntPtr dev, ref byte data, uint width, uint height);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_surface_destroy(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_get_vk_image(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern int vkvg_surface_get_width(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern int vkvg_surface_get_height(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_surface_clear(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_reference(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern uint vkvg_surface_get_reference_count(IntPtr surf);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_surface_write_to_png(IntPtr surf, [MarshalAs(UnmanagedType.LPStr)]string path);
-        #endregion
+               #region Surface
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_create(IntPtr device, uint width, uint height);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_create_from_image(IntPtr dev, string filePath);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_create_from_svg(IntPtr dev, string filePath);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_create_from_svg_fragment(IntPtr dev, byte[] filePath);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_create_from_bitmap(IntPtr dev, ref byte data, uint width, uint height);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_surface_destroy(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_get_vk_image(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern int vkvg_surface_get_width(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern int vkvg_surface_get_height(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_surface_clear(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr vkvg_surface_reference(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern uint vkvg_surface_get_reference_count(IntPtr surf);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_surface_write_to_png(IntPtr surf, [MarshalAs(UnmanagedType.LPStr)]string path);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_surface_write_to_memory(IntPtr surf, IntPtr pBitmap);
+               #endregion
 
-        #region NSVG
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr nsvg_load_file(IntPtr dev, string filePath);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr nsvg_load(IntPtr dev, ref byte fragment);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void nsvg_destroy(IntPtr nsvgImage);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void nsvg_get_size(IntPtr nsvgImage, out int width, out int height);
-        [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern void vkvg_render_svg(IntPtr ctx, IntPtr nsvgImage, string subId);
-        #endregion
-    }
+               #region NSVG
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr nsvg_load_file(IntPtr dev, string filePath);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern IntPtr nsvg_load(IntPtr dev, ref byte fragment);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void nsvg_destroy(IntPtr nsvgImage);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void nsvg_get_size(IntPtr nsvgImage, out int width, out int height);
+               [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void vkvg_render_svg(IntPtr ctx, IntPtr nsvgImage, string subId);
+               #endregion
+       }
 }
 
index e27f36947c44606eb49d178f5a629e784e562b91..6b1ce5e5aa016ce27bb1763fac35bfede77fb255 100644 (file)
@@ -13,23 +13,82 @@ using static Vulkan.Vk;
 using Device = vke.Device;
 
 namespace Crow.Drawing {
+       /// <summary>
+       /// Base class for offscreen vulkan context without swapchain
+       /// </summary>
+       public class VulkanContextBase : IDisposable {
+               protected Instance instance;    
+               protected PhysicalDevice phy;
+               protected vke.Device dev;               
+               protected Queue graphicQueue;//for vkvg, we must have at least a graphic queue
+
+               public void WaitIdle() => dev.WaitIdle ();
+
+               public VulkanContextBase () {}          
+               public VulkanContextBase (ref byte[] pBitmap) {
+#if DEBUG
+                       instance = new Instance (Ext.I.VK_EXT_debug_utils);
+#else
+                       instance = new Instance ();
+#endif
+                       phy = instance.GetAvailablePhysicalDevice ().FirstOrDefault ();
+                       VkPhysicalDeviceFeatures enabledFeatures = default;
+                       dev = new vke.Device (phy);
+                       graphicQueue = new Queue (dev, VkQueueFlags.Graphics);
+                       dev.Activate (enabledFeatures);
+               }
+
+               public Crow.Drawing.Device CreateVkvgDevice () => 
+                       new Crow.Drawing.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, graphicQueue.qFamIndex, SampleCount.Sample_8);
+               public virtual void CreateSurface (Device vkvgDevice, int width, int height, ref Surface surf) {
+                       surf?.Dispose ();
+                       surf = new Surface (vkvgDevice, width, height);                 
+               }
+
+               #region IDisposable Support
+               protected bool isDisposed;
+               protected virtual void Dispose (bool disposing) {
+                       if (!isDisposed) {
+                               dev.WaitIdle ();
+
+                               if (disposing) {
+                                       dev.Dispose ();
+                                       instance.Dispose ();
+                               } else
+                                       Debug.WriteLine ("a VulkanContext has not been correctly disposed");
+
+                               isDisposed = true;
+                       }
+               }
+               ~VulkanContextBase () {
+                       Dispose (false);
+               }
+               public void Dispose () {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+               #endregion
+       }
        /// <summary>
        /// Base class to build vulkan application.
        /// Provide default swapchain with its command pool and buffers per image and the main present queue
        /// </summary>
-       public class VulkanContext : IDisposable {
+       public class VulkanContext : VulkanContextBase {
+               public override void CreateSurface (Device vkvgDevice, int width, int height, ref Surface surf) {
+                       WaitIdle();
+
+                       blitSource?.Dispose ();
+                       surf?.Dispose ();
+                       surf = new Surface (vkvgDevice, width, height);
+                       buildBlitCommand (surf);
+
+                       WaitIdle();
+               }
 
-               /** GLFW window native pointer. */
-               IntPtr hWin;
+               uint width, height;
+               IntPtr hWin;/** GLFW window native pointer. */
                /**Vulkan Surface */
                protected VkSurfaceKHR hSurf;
-               /**vke Instance encapsulating a VkInstance. */
-               protected Instance instance;    
-               /**vke Physical device associated with this window*/
-               protected PhysicalDevice phy;
-               /**vke logical device */                        
-               protected vke.Device dev;
-               protected PresentQueue presentQueue;
                protected SwapChain swapChain;
                protected CommandPool cmdPool;
                protected PrimaryCommandBuffer[] cmds;
@@ -45,23 +104,18 @@ namespace Crow.Drawing {
                uint frameCount;
                Stopwatch frameChrono;
 
-               string[] EnabledInstanceExtensions => new string[] { Ext.I.VK_EXT_debug_utils };
-
-               string[] EnabledDeviceExtensions => new string[] { Ext.D.VK_KHR_swapchain };
-
-               uint width, height;
-               public void WaitIdle() => dev.WaitIdle ();
                public VulkanContext (IntPtr hWin, uint _width, uint _height, bool vsync = false) {
                        this.hWin = hWin;
-                       //Instance.VALIDATION = true;
-                       //Instance.RENDER_DOC_CAPTURE = true;
 
                        SwapChain.IMAGES_USAGE = VkImageUsageFlags.ColorAttachment | VkImageUsageFlags.TransferDst;
                        SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm;
 
+                       //Instance.VALIDATION = true;
+                       //Instance.RENDER_DOC_CAPTURE = true;
                        List<string> instExts = new List<string> (Glfw3.GetRequiredInstanceExtensions ());
-                       if (EnabledInstanceExtensions != null)
-                               instExts.AddRange (EnabledInstanceExtensions);
+#if DEBUG
+                       instExts.Add (Ext.I.VK_EXT_debug_utils);
+#endif
 
                        instance = new Instance (instExts.ToArray());
                        hSurf = instance.CreateSurface (hWin);
@@ -73,19 +127,19 @@ namespace Crow.Drawing {
                        //First create the c# device class
                        dev = new vke.Device (phy);
 
-                       presentQueue = new PresentQueue (dev, VkQueueFlags.Graphics, hSurf);
+                       graphicQueue = new PresentQueue (dev, VkQueueFlags.Graphics, hSurf);
 
                        //activate the device to have effective queues created accordingly to what's available
-                       dev.Activate (enabledFeatures, EnabledDeviceExtensions);
+                       dev.Activate (enabledFeatures, Ext.D.VK_KHR_swapchain);
 
-                       swapChain = new SwapChain (presentQueue as PresentQueue, _width, _height, SwapChain.PREFERED_FORMAT,
+                       swapChain = new SwapChain (graphicQueue as PresentQueue, _width, _height, SwapChain.PREFERED_FORMAT,
                                vsync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.ImmediateKHR);
                        swapChain.Activate ();
 
                        width = swapChain.Width;
                        height = swapChain.Height;
 
-                       cmdPool = new CommandPool (dev, presentQueue.qFamIndex, VkCommandPoolCreateFlags.ResetCommandBuffer);
+                       cmdPool = new CommandPool (dev, graphicQueue.qFamIndex, VkCommandPoolCreateFlags.ResetCommandBuffer);
                        cmds = cmdPool.AllocateCommandBuffer (swapChain.ImageCount);
 
                        drawComplete = new VkSemaphore[swapChain.ImageCount];
@@ -99,12 +153,10 @@ namespace Crow.Drawing {
                        cmdPool.SetName ("main CmdPool");                       
                }
 
-               public Crow.Drawing.Device CreateVkvgDevice () => 
-                       new Crow.Drawing.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, SampleCount.Sample_8);
 
                internal vke.Image blitSource;
                
-               public void BuildBlitCommand (Crow.Drawing.Surface surf) {
+               void buildBlitCommand (Crow.Drawing.Surface surf) {
                        //Console.WriteLine ($"build blit w:{width} h:{height}");
                        cmdPool.Reset();
                        
@@ -161,17 +213,13 @@ namespace Crow.Drawing {
                                return false;
                        WaitAndResetDrawFence();
 
-                       presentQueue.Submit (cmds[idx], swapChain.presentComplete, drawComplete[idx], drawFence);
-                       presentQueue.Present (swapChain, drawComplete[idx]);
+                       graphicQueue.Submit (cmds[idx], swapChain.presentComplete, drawComplete[idx], drawFence);
+                       (graphicQueue as PresentQueue).Present (swapChain, drawComplete[idx]);
 
                        WaitIdle();
                        return true;
                }
-
-               #region IDisposable Support
-               protected bool isDisposed;
-
-               protected virtual void Dispose (bool disposing) {
+               protected override void Dispose (bool disposing) {
                        if (!isDisposed) {
                                dev.WaitIdle ();
 
@@ -184,24 +232,11 @@ namespace Crow.Drawing {
 
                                vkDestroySurfaceKHR (instance.Handle, hSurf, IntPtr.Zero);
 
-                               if (disposing) {
+                               if (disposing)
                                        cmdPool.Dispose ();
-                                       dev.Dispose ();
-                                       instance.Dispose ();
-                               } else
-                                       Debug.WriteLine ("a VkWindow has not been correctly disposed");
 
-                               isDisposed = true;
+                               base.Dispose (disposing);
                        }
                }
-
-               ~VulkanContext () {
-                       Dispose (false);
-               }
-               public void Dispose () {
-                       Dispose (true);
-                       GC.SuppressFinalize (this);
-               }
-               #endregion
        }
 }
index 99187ba73af34aa7aabc45d3faf1947b04c2fdfd..21191f08052e76c9be329e87ad7d1f2b949ea3ee 100644 (file)
@@ -136,6 +136,11 @@ namespace Crow
                        hWin = glfwWindowHandle;
                        PerformanceMeasure.InitMeasures ();
                }
+#if VKVG               
+               public const bool HaveVkvgBackend = true;
+#else
+               public const bool HaveVkvgBackend = false;
+#endif
                public Interface (int width = 800, int height = 600, bool startUIThread = true, bool createSurface = true)
                {
                        CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
@@ -188,7 +193,6 @@ namespace Crow
 #if VKVG
                VulkanContext vkCtx;
                internal Device vkvgDevice;
-               vke.Image vkvgSurfaceImage;
 #endif
                protected void initSurface ()
                {
@@ -208,8 +212,7 @@ namespace Crow
 #if VKVG
                        vkCtx = new VulkanContext (hWin, (uint)clientRectangle.Width, (uint)clientRectangle.Height);
                        vkvgDevice = vkCtx.CreateVkvgDevice ();
-                       surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);                 
-                       vkCtx.BuildBlitCommand (surf);
+                       vkCtx.CreateSurface (vkvgDevice, clientRectangle.Width, clientRectangle.Height, ref surf);                      
 #else
                        switch (Environment.OSVersion.Platform) {
                        case PlatformID.MacOSX:
@@ -1097,12 +1100,9 @@ namespace Crow
                }
 #if VKVG
                void resizeVulkanContext () {
-                       vkCtx.WaitIdle();
-                       vkCtx.blitSource?.Dispose ();
-                       surf?.Dispose ();
-                       surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);                         
-                       vkCtx.BuildBlitCommand (surf);
-                       vkCtx.WaitIdle();
+
+                       vkCtx.CreateSurface (vkvgDevice, clientRectangle.Width, clientRectangle.Height, ref surf);
+
                        foreach (Widget g in GraphicTree)
                                g.RegisterForLayouting (LayoutingType.All);
 
index 58a32622f04d2912c452c49847d751b5d4c31d04..16d2c0c0446374e8f1a022600a75524f99217bae 100644 (file)
@@ -6,7 +6,7 @@
                <Authors>Jean-Philippe Bruyère</Authors>           
                <LangVersion>7.3</LangVersion>
                
-               <CrowVersion>0.9.7</CrowVersion>
+               <CrowVersion>1.0.0</CrowVersion>
                <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
 
                <!-- If you dont have a native libstb on your system, enable the managed version of stb here