From 0117f7cb51f5fae3783503d1e46fc239c001cfc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 30 Apr 2019 22:27:05 +0200 Subject: [PATCH] dont save/restore path datas --- include/vkvg.h | 5 +++-- src/vkvg_context.c | 33 ++++----------------------------- src/vkvg_context_internal.c | 12 +++++++++--- src/vkvg_context_internal.h | 17 +++++------------ src/vkvg_surface.c | 1 + 5 files changed, 22 insertions(+), 46 deletions(-) diff --git a/include/vkvg.h b/include/vkvg.h index 9649561..618fe7f 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -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); diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 5e6ecf8..03a2a46 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -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; diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 21e7ac0..2010e19 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -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); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 363ee77..3ae31bb 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -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; diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index ddcaf54..a15f700 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -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) { -- 2.47.3