]> O.S.I.I.S - jp/vkvg.git/commitdiff
dont save/restore path datas
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 30 Apr 2019 20:27:05 +0000 (22:27 +0200)
committerj-p <jp_bruyere@hotmail.com>
Wed, 1 May 2019 12:47:26 +0000 (14:47 +0200)
include/vkvg.h
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_surface.c

index 96495612b5978be6f20d2ce4f3667f32fe3dba6f..618fe7f8b1e057c522cbf8941f20922aa9c0402e 100644 (file)
@@ -173,9 +173,10 @@ uint32_t    vkvg_device_get_reference_count (VkvgDevice dev);
 void        vkvg_device_set_dpy             (VkvgDevice dev, int hdpy, int vdpy);
 void        vkvg_device_get_dpy             (VkvgDevice dev, int* hdpy, int* vdpy);
 
-VkvgSurface vkvg_surface_create                        (VkvgDevice dev, uint32_t width, uint32_t height);
+VkvgSurface vkvg_surface_create             (VkvgDevice dev, uint32_t width, uint32_t height);
 VkvgSurface vkvg_surface_create_from_image  (VkvgDevice dev, const char* filePath);
-VkvgSurface vkvg_surface_create_for_VkhImage (VkvgDevice dev, void* vkhImg);
+VkvgSurface vkvg_surface_create_from_svg    (VkvgDevice dev, const char* filePath);
+VkvgSurface vkvg_surface_create_for_VkhImage(VkvgDevice dev, void* vkhImg);
 // VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img, uint32_t width, uint32_t height);
 VkvgSurface vkvg_surface_reference          (VkvgSurface surf);
 uint32_t    vkvg_surface_get_reference_count(VkvgSurface surf);
index 5e6ecf8a39409d44c95acc8787030add361924ab..03a2a467106cec4b5ea24770e5f022efd5f48d5d 100644 (file)
@@ -55,7 +55,7 @@ VkvgContext vkvg_create(VkvgSurface surf)
     ctx->lineWidth      = 1;
     ctx->pSurf          = surf;
     ctx->curOperator    = VKVG_OPERATOR_OVER;
-    ctx->curFillRule    = VKVG_FILL_RULE_EVEN_ODD;
+    ctx->curFillRule    = VKVG_FILL_RULE_NON_ZERO;
 
     push_constants pc = {
             {.height=1},
@@ -98,6 +98,7 @@ VkvgContext vkvg_create(VkvgSurface surf)
 
     _init_cmd_buff          (ctx);
     _clear_path             (ctx);
+    vkvg_reset_clip         (ctx);
 
     ctx->references = 1;
     ctx->status = VKVG_STATUS_SUCCESS;
@@ -478,9 +479,9 @@ void vkvg_fill_preserve (VkvgContext ctx){
     if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full
         vkvg_flush(ctx);
 
+    _check_cmd_buff_state(ctx);
 
     if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){
-        _check_cmd_buff_state(ctx);
         _poly_fill (ctx);
         _bind_draw_pipeline (ctx);
         CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
@@ -488,8 +489,8 @@ void vkvg_fill_preserve (VkvgContext ctx){
         CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
     }else{
         //CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
+        CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
         _fill_ec(ctx);
-        //CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
     }
 }
 void vkvg_stroke_preserve (VkvgContext ctx)
@@ -757,18 +758,6 @@ void vkvg_save (VkvgContext ctx){
     VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
     _submit_ctx_cmd(ctx);
 
-    sav->sizePoints = ctx->sizePoints;
-    sav->pointCount = ctx->pointCount;
-
-    sav->points = (vec2*)malloc (sav->pointCount * sizeof(vec2));
-    memcpy (sav->points, ctx->points, sav->pointCount * sizeof(vec2));
-
-    sav->pathPtr    = ctx->pathPtr;
-    sav->sizePathes = ctx->sizePathes;
-
-    sav->pathes = (uint32_t*)malloc (sav->pathPtr * sizeof(uint32_t));
-    memcpy (sav->pathes, ctx->pathes, sav->pathPtr * sizeof(uint32_t));
-
     sav->lineWidth  = ctx->lineWidth;
     sav->curOperator= ctx->curOperator;
     sav->lineCap    = ctx->lineCap;
@@ -835,20 +824,6 @@ void vkvg_restore (VkvgContext ctx){
     VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
     _submit_ctx_cmd(ctx);
 
-    ctx->sizePoints = sav->sizePoints;
-    ctx->pointCount = sav->pointCount;
-
-    ctx->points = (vec2*)realloc ( ctx->points, ctx->sizePoints * sizeof(vec2));
-    memset (ctx->points, 0, ctx->sizePoints * sizeof(vec2));
-    memcpy (ctx->points, sav->points, ctx->pointCount * sizeof(vec2));
-
-    ctx->pathPtr    = sav->pathPtr;
-    ctx->sizePathes = sav->sizePathes;
-
-    ctx->pathes = (uint32_t*)realloc (ctx->pathes, ctx->sizePathes * sizeof(uint32_t));
-    memset (ctx->pathes, 0, ctx->sizePathes * sizeof(uint32_t));
-    memcpy (ctx->pathes, sav->pathes, ctx->pathPtr * sizeof(uint32_t));
-
     ctx->lineWidth  = sav->lineWidth;
     ctx->curOperator= sav->curOperator;
     ctx->lineCap    = sav->lineCap;
index 21e7ac0e66cd0c5d2ce2f3a85f541ffbe4434d8c..2010e194d362e8f5d237fd8206675727109bc7ac 100644 (file)
@@ -628,8 +628,6 @@ bool ptInTriangle(vec2 p, vec2 p0, vec2 p1, vec2 p2) {
 }
 
 void _free_ctx_save (vkvg_context_save_t* sav){
-    free(sav->pathes);
-    free(sav->points);
     free(sav->selectedFont.fontFile);
     vkh_image_destroy   (sav->stencilMS);
     free (sav);
@@ -874,12 +872,17 @@ void _fill_ec (VkvgContext ctx){
         _add_vertex(ctx, v);
 
         ear_clip_point* ecp_current = ecps;
+        uint32_t tries = 0;
 
         while (ecps_count > 3) {
+            if (tries > ecps_count) {
+                break;
+            }
             ear_clip_point* v0 = ecp_current->next,
                     *v1 = ecp_current, *v2 = ecp_current->next->next;
             if (ecp_zcross (v0, v2, v1)<0){
                 ecp_current = ecp_current->next;
+                tries++;
                 continue;
             }
             ear_clip_point* vP = v2->next;
@@ -895,8 +898,11 @@ void _fill_ec (VkvgContext ctx){
                 _add_triangle_indices (ctx, v0->idx, v1->idx, v2->idx);
                 v1->next = v2;
                 ecps_count --;
-            }else
+                tries = 0;
+            }else{
                 ecp_current = ecp_current->next;
+                tries++;
+            }
         }
         if (ecps_count == 3)
             _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx);
index 363ee772a0c9cf069ce8c6529ec9a14c4a22a264..3ae31bb738dd2b1d323adc01c54c2977dff77ea1 100644 (file)
@@ -53,13 +53,6 @@ typedef struct _vkvg_context_save_t{
 
     VkhImage    stencilMS;
     uint32_t    stencilRef;
-    vec2*              points;     //points array
-    size_t             sizePoints; //reserved size
-    uint32_t   pointCount; //effective points count
-
-    uint32_t   pathPtr;
-    uint32_t*  pathes;
-    size_t             sizePathes;
 
     float       lineWidth;
 
@@ -68,11 +61,11 @@ typedef struct _vkvg_context_save_t{
     vkvg_line_join_t    lineJoint;
     vkvg_fill_rule_t    curFillRule;
 
-    _vkvg_font_t    selectedFont;     //hold current face and size before cache addition
-    _vkvg_font_t*   currentFont;      //font ready for lookup
-    vkvg_direction_t   textDirection;
-    push_constants  pushConsts;
-    VkvgPattern     pattern;
+    _vkvg_font_t        selectedFont;     //hold current face and size before cache addition
+    _vkvg_font_t*       currentFont;      //font ready for lookup
+    vkvg_direction_t    textDirection;
+    push_constants      pushConsts;
+    VkvgPattern         pattern;
 
 }vkvg_context_save_t;
 
index ddcaf54094b3a7c31489e6b5a635f02f921a1eb5..a15f7001b209f779a42b4cd090b10e98e1acf6a4 100644 (file)
@@ -307,6 +307,7 @@ VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath
 
     return surf;
 }
+VkvgSurface vkvg_surface_create_from_svg (VkvgDevice dev, const char* filePath) {}
 
 void vkvg_surface_destroy(VkvgSurface surf)
 {