]> O.S.I.I.S - jp/vkvg.git/commitdiff
recording wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 9 Jan 2022 10:44:25 +0000 (11:44 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 11 Jan 2022 15:41:25 +0000 (16:41 +0100)
include/vkvg.h
src/recording/vkvg_record_internal.c
src/recording/vkvg_record_internal.h
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h

index 9fc397eb9a98774f8d76224df3900f90e0a5146e..18f603e4799f1956b168de31f239edef08e706f0 100644 (file)
@@ -86,13 +86,13 @@ extern "C" {
 #define VKVG_LOG_INFO_PTS      0x00000004
 #define VKVG_LOG_INFO_PATH     0x00000008
 #define VKVG_LOG_INFO_CMD      0x00000010
-#define VKVG_LOG_INFO_VBO      0x00000010
-#define VKVG_LOG_INFO_IBO      0x00000010
-#define VKVG_LOG_INFO_VAO      VKVG_LOG_INFO_VBO|VKVG_LOG_INFO_IBO
+#define VKVG_LOG_INFO_VBO      0x00000020
+#define VKVG_LOG_INFO_IBO      0x00000040
+#define VKVG_LOG_INFO_VAO      (VKVG_LOG_INFO_VBO|VKVG_LOG_INFO_IBO)
 #define VKVG_LOG_DBG_ARRAYS    0x00001000
 #define VKVG_LOG_FULL          0xffffffff
 
-#define VKVG_LOG_INFO          VKVG_LOG_INFO_PTS|VKVG_LOG_INFO_PATH|VKVG_LOG_INFO_CMD|VKVG_LOG_INFO_VAO
+#define VKVG_LOG_INFO          0x00008000//(VKVG_LOG_INFO_PTS|VKVG_LOG_INFO_PATH|VKVG_LOG_INFO_CMD|VKVG_LOG_INFO_VAO)
 #ifdef DEBUG
 extern uint32_t vkvg_log_level;
        #ifdef VKVG_WIRED_DEBUG
index 83a6288d4dc86918be5a3ba6eeb23cf71c27382f..6f03fdb941ed8f5c5b2de81094212dcdb30787fa 100644 (file)
@@ -39,6 +39,14 @@ vkvg_recording_t* _new_recording () {
        return rec;
 }
 void _destroy_recording (vkvg_recording_t* rec) {
+       if (!rec)
+               return;
+       for (uint32_t i=0; i<rec->commandsCount; i++) {
+               if (rec->commands[i].cmd == VKVG_CMD_SET_SOURCE)
+                       vkvg_pattern_destroy((VkvgPattern)(rec->buffer + rec->commands[i].dataOffset));
+               else if (rec->commands[i].cmd == VKVG_CMD_SET_SOURCE_SURFACE)
+                       vkvg_surface_destroy ((VkvgSurface)(rec->buffer + rec->commands[i].dataOffset + 2 * sizeof(float)));
+       }
        free(rec->commands);
        free(rec->buffer);
        free(rec);
@@ -80,13 +88,18 @@ void* _advance_recording_buffer_unchecked (vkvg_recording_t* rec, size_t size) {
                *(float*)buff = (float)va_arg(args, double);                                    \
                buff = _advance_recording_buffer_unchecked (rec, sizeof(float));\
        }
-#define STORE_BOOLS(floatcount)                                                                                        \
-       for (i=0; i<floatcount; i++) {                                                                          \
+#define STORE_BOOLS(count)                                                                                             \
+       for (i=0; i<count; i++) {                                                                                       \
                buff = _ensure_recording_buffer (rec, sizeof(bool));                    \
                *(bool*)buff = (bool)va_arg(args, int);                                                 \
-               buff = _advance_recording_buffer_unchecked (rec, sizeof(bool)); \
+               _advance_recording_buffer_unchecked (rec, sizeof(bool));                \
+       }
+#define STORE_UINT32(count)                                                                                            \
+       for (i=0; i<count; i++) {                                                                                       \
+               buff = _ensure_recording_buffer (rec, sizeof(uint32_t));                \
+               *(uint32_t*)buff = (uint32_t)va_arg(args, uint32_t);                            \
+               buff = _advance_recording_buffer_unchecked (rec, sizeof(uint32_t));     \
        }
-
 
 void _record (vkvg_recording_t* rec,...) {
        va_list args;
@@ -102,181 +115,333 @@ void _record (vkvg_recording_t* rec,...) {
        r->cmd = cmd;
        r->dataOffset = rec->bufferSize;
 
-       void* buff;
+       char* buff;
+       int i = 0;
 
+       if (cmd & VKVG_CMD_PATH_COMMANDS) {
+               if ((cmd & VKVG_CMD_PATHPROPS_COMMANDS) == VKVG_CMD_PATHPROPS_COMMANDS) {
+                       switch (r->cmd) {
+                       case VKVG_CMD_SET_LINE_WIDTH:
+                               STORE_FLOATS(1);
+                               break;
+                       case VKVG_CMD_SET_LINE_JOIN:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SET_LINE_CAP:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SET_OPERATOR:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SET_FILL_RULE:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SET_DASH:
+                               break;
+                       }
+               } else {
+                       switch (cmd) {
+                       case VKVG_CMD_MOVE_TO:
+                       case VKVG_CMD_LINE_TO:
+                       case VKVG_CMD_REL_MOVE_TO:
+                       case VKVG_CMD_REL_LINE_TO:
+                               STORE_FLOATS(2);
+                               break;
+                       case VKVG_CMD_RECTANGLE:
+                       case VKVG_CMD_QUADRATIC_TO:
+                       case VKVG_CMD_REL_QUADRATIC_TO:
+                               STORE_FLOATS(4);
+                               break;
+                       case VKVG_CMD_ARC:
+                       case VKVG_CMD_ARC_NEG:
+                               STORE_FLOATS(5);
+                               break;
+                       case VKVG_CMD_CURVE_TO:
+                       case VKVG_CMD_REL_CURVE_TO:
+                               STORE_FLOATS(6);
+                               break;
+                       case VKVG_CMD_ELLIPTICAL_ARC_TO:
+                       case VKVG_CMD_REL_ELLIPTICAL_ARC_TO:
+                               STORE_FLOATS(5);
+                               STORE_BOOLS(2);
+                               break;
+                       case VKVG_CMD_NEW_PATH:
+                       case VKVG_CMD_NEW_SUB_PATH:
+                       case VKVG_CMD_CLOSE_PATH:
+                               break;
+                       }
+               }
+       } else if (!(r->cmd & VKVG_CMD_DRAW_COMMANDS)) {
+               if (r->cmd & VKVG_CMD_TRANSFORM_COMMANDS) {
+                       switch (r->cmd) {
+                       case VKVG_CMD_TRANSLATE:
+                       case VKVG_CMD_SCALE:
+                               STORE_FLOATS(2);
+                               break;
+                       case VKVG_CMD_ROTATE:
+                               STORE_FLOATS(1);
+                               break;
+                       case VKVG_CMD_IDENTITY_MATRIX:
+                               break;
+                       case VKVG_CMD_SET_MATRIX:
+                       case VKVG_CMD_TRANSFORM:
+                               {
+                                       buff = _ensure_recording_buffer (rec, sizeof(vkvg_matrix_t));
+                                       vkvg_matrix_t* mat = (vkvg_matrix_t*)va_arg(args, vkvg_matrix_t*);
+                                       memcpy(buff, mat, sizeof(vkvg_matrix_t));
+                                       buff = _advance_recording_buffer_unchecked (rec, sizeof(vkvg_matrix_t));
 
-       int i = 0;
-       switch (cmd) {
-       case VKVG_CMD_MOVE_TO:
-       case VKVG_CMD_LINE_TO:
-       case VKVG_CMD_REL_MOVE_TO:
-       case VKVG_CMD_REL_LINE_TO:
-               STORE_FLOATS(2);
-               break;
-       case VKVG_CMD_SAVE:
-       case VKVG_CMD_RESTORE:
-       case VKVG_CMD_NEW_PATH:
-       case VKVG_CMD_NEW_SUB_PATH:
-       case VKVG_CMD_CLOSE_PATH:
-       case VKVG_CMD_PAINT:
-       case VKVG_CMD_FILL:
-       case VKVG_CMD_STROKE:
-       case VKVG_CMD_CLIP:
-       case VKVG_CMD_CLEAR:
-       case VKVG_CMD_FILL_PRESERVE:
-       case VKVG_CMD_STROKE_PRESERVE:
-       case VKVG_CMD_CLIP_PRESERVE:
-               break;
-       case VKVG_CMD_RECTANGLE:
-       //case VKVG_CMD_ELLIPSE:
-       case VKVG_CMD_SET_SOURCE_RGBA:
-       case VKVG_CMD_QUADRATIC_TO:
-       case VKVG_CMD_REL_QUADRATIC_TO:
-               STORE_FLOATS(4);
-               break;
-       case VKVG_CMD_ARC:
-       case VKVG_CMD_ARC_NEG:
-               STORE_FLOATS(5);
-               break;
-       case VKVG_CMD_CURVE_TO:
-       case VKVG_CMD_REL_CURVE_TO:
-               STORE_FLOATS(6);
-               break;
-       case VKVG_CMD_ELLIPTICAL_ARC_TO:
-               STORE_FLOATS(5);
-               STORE_BOOLS(2);
-               break;
-       case VKVG_CMD_SET_SOURCE_RGB:
-               STORE_FLOATS(3);
-               break;
-       case VKVG_CMD_REL_ELLIPTICAL_ARC_TO:
-               STORE_FLOATS(5);
-               STORE_BOOLS(2);
-               break;
-       case VKVG_CMD_SET_SOURCE:
-               buff = _ensure_recording_buffer (rec, sizeof(VkvgPattern));
-               *(VkvgPattern*)buff = va_arg(args, VkvgPattern);
-               _advance_recording_buffer_unchecked (rec, sizeof(VkvgPattern));
-               break;
-       case VKVG_CMD_SET_SOURCE_SURFACE:
-               STORE_FLOATS(2);
-               buff = _ensure_recording_buffer (rec, sizeof(VkvgSurface));
-               *(VkvgSurface*)buff = va_arg(args, VkvgSurface);
-               _advance_recording_buffer_unchecked (rec, sizeof(VkvgSurface));
-               break;
+                               }
+                               break;
+                       }
+               } else if (r->cmd & VKVG_CMD_PATTERN_COMMANDS) {
+                       switch (r->cmd) {
+                       case VKVG_CMD_SET_SOURCE_RGBA:
+                               STORE_FLOATS(4);
+                               break;
+                       case VKVG_CMD_SET_SOURCE_RGB:
+                               STORE_FLOATS(3);
+                               break;
+                       case VKVG_CMD_SET_SOURCE_COLOR:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SET_SOURCE:
+                               {
+                                       buff = _ensure_recording_buffer (rec, sizeof(VkvgPattern));
+                                       VkvgPattern pat = (VkvgPattern)va_arg(args, VkvgPattern);
+                                       vkvg_pattern_reference(pat);
+                                       VkvgPattern* pPat = (VkvgPattern*)buff;
+                                       *pPat = pat;
+                                       _advance_recording_buffer_unchecked (rec, sizeof(VkvgPattern));
+                               }
+                               break;
+                       case VKVG_CMD_SET_SOURCE_SURFACE:
+                               STORE_FLOATS(2);
+                               {
+                                       buff = _ensure_recording_buffer (rec, sizeof(VkvgSurface));
+                                       VkvgSurface surf = (VkvgSurface)va_arg(args, VkvgSurface);
+                                       vkvg_surface_reference(surf);
+                                       *(VkvgSurface*)buff = surf;
+                                       _advance_recording_buffer_unchecked (rec, sizeof(VkvgSurface));
+                               }
+                               break;
+                       }
+               } else if (r->cmd & VKVG_CMD_TEXT_COMMANDS) {
+                       char* txt;
+                       int txtLen;
+                       switch (r->cmd) {
+                       case VKVG_CMD_SET_FONT_SIZE:
+                               STORE_UINT32(1);
+                               break;
+                       case VKVG_CMD_SHOW_TEXT:
+                       case VKVG_CMD_SET_FONT_FACE:
+                               txt = (char*)va_arg(args, char*);
+                               txtLen = strlen(txt);
+                               buff = _ensure_recording_buffer (rec, txtLen * sizeof(char));
+                               strcpy(buff, txt);
+                               _advance_recording_buffer_unchecked (rec, txtLen * sizeof(char));
+                               break;
+                       case VKVG_CMD_SET_FONT_PATH:
+                               break;
+                       }
+               }
        }
        va_end(args);
 }
 void _replay_command (VkvgContext ctx, VkvgRecording rec, uint32_t index) {
        vkvg_record_t* r = &rec->commands[index];
        float* floats = (float*)(rec->buffer + r->dataOffset);
-       switch (r->cmd) {
-       case VKVG_CMD_SAVE:
-               vkvg_save (ctx);
-               break;
-       case VKVG_CMD_RESTORE:
-               vkvg_restore (ctx);
-               break;
-       case VKVG_CMD_NEW_PATH:
-               vkvg_new_path (ctx);
-               break;
-       case VKVG_CMD_NEW_SUB_PATH:
-               vkvg_new_sub_path (ctx);
-               break;
-       case VKVG_CMD_CLOSE_PATH:
-               vkvg_close_path (ctx);
-               break;
-       case VKVG_CMD_PAINT:
-               vkvg_paint (ctx);
-               break;
-       case VKVG_CMD_FILL:
-               vkvg_fill (ctx);
-               break;
-       case VKVG_CMD_STROKE:
-               vkvg_stroke (ctx);
-               break;
-       case VKVG_CMD_CLIP:
-               vkvg_clip (ctx);
-               break;
-       case VKVG_CMD_CLEAR:
-               vkvg_clear (ctx);
-               break;
-       case VKVG_CMD_FILL_PRESERVE:
-               vkvg_fill_preserve (ctx);
-               break;
-       case VKVG_CMD_STROKE_PRESERVE:
-               vkvg_stroke_preserve (ctx);
-               break;
-       case VKVG_CMD_CLIP_PRESERVE:
-               vkvg_clip_preserve (ctx);
-               break;
-       case VKVG_CMD_RECTANGLE:
-               vkvg_rectangle (ctx, floats[0], floats[1], floats[2], floats[3]);
-               break;
-       case VKVG_CMD_ARC:
-               vkvg_arc (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
-               break;
-       case VKVG_CMD_ARC_NEG:
-               vkvg_arc (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
-               break;
-       /*case VKVG_CMD_ELLIPSE:
-               vkvg_ellipse (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
-               break;*/
-       case VKVG_CMD_MOVE_TO:
-               vkvg_move_to(ctx, floats[0], floats[1]);
-               break;
-       case VKVG_CMD_LINE_TO:
-               vkvg_line_to(ctx, floats[0], floats[1]);
-               break;
-       case VKVG_CMD_CURVE_TO:
-               vkvg_curve_to (ctx, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5]);
-               break;
-       case VKVG_CMD_ELLIPTICAL_ARC_TO:
-               {
-                       bool* flags = (bool*)&floats[5];
-                       vkvg_elliptic_arc_to (ctx, floats[0], floats[1], flags[0], flags[1], floats[2], floats[3], floats[4]);
+       uint32_t* uints = (uint32_t*)floats;
+       if (r->cmd&VKVG_CMD_PATH_COMMANDS) {
+               if ((r->cmd&VKVG_CMD_RELATIVE_COMMANDS)==VKVG_CMD_RELATIVE_COMMANDS) {
+                       switch (r->cmd) {
+                       case VKVG_CMD_REL_MOVE_TO:
+                               vkvg_rel_move_to(ctx, floats[0], floats[1]);
+                               return;
+                       case VKVG_CMD_REL_LINE_TO:
+                               vkvg_rel_line_to(ctx, floats[0], floats[1]);
+                               return;
+                       case VKVG_CMD_REL_CURVE_TO:
+                               vkvg_rel_curve_to (ctx, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5]);
+                               return;
+                       case VKVG_CMD_REL_QUADRATIC_TO:
+                               vkvg_rel_quadratic_to (ctx, floats[0], floats[1], floats[2], floats[3]);
+                               return;
+                       case VKVG_CMD_REL_ELLIPTICAL_ARC_TO:
+                               {
+                                       bool* flags = (bool*)&floats[5];
+                                       vkvg_rel_elliptic_arc_to (ctx, floats[0], floats[1], flags[0], flags[1], floats[2], floats[3], floats[4]);
+                               }
+                               return;
+                       }
+               }else if ((r->cmd&VKVG_CMD_PATHPROPS_COMMANDS)==VKVG_CMD_PATHPROPS_COMMANDS) {
+                       switch (r->cmd) {
+                       case VKVG_CMD_SET_LINE_WIDTH:
+                               vkvg_set_line_width (ctx, floats[0]);
+                               return;
+                       case VKVG_CMD_SET_LINE_JOIN:
+                               vkvg_set_line_join (ctx, (vkvg_line_join_t)uints[0]);
+                               return;
+                       case VKVG_CMD_SET_LINE_CAP:
+                               vkvg_set_line_cap (ctx, (vkvg_line_cap_t)uints[0]);
+                               return;
+                       case VKVG_CMD_SET_OPERATOR:
+                               vkvg_set_operator (ctx, (vkvg_operator_t)uints[0]);
+                               return;
+                       case VKVG_CMD_SET_FILL_RULE:
+                               vkvg_set_fill_rule (ctx, (vkvg_fill_rule_t)uints[0]);
+                               return;
+                       case VKVG_CMD_SET_DASH:
+                               vkvg_set_dash(ctx, &floats[2],  uints[0], floats[1]);
+                               return;
+                       }
+               } else {
+                       switch (r->cmd) {
+                       case VKVG_CMD_NEW_PATH:
+                               vkvg_new_path (ctx);
+                               return;
+                       case VKVG_CMD_NEW_SUB_PATH:
+                               vkvg_new_sub_path (ctx);
+                               return;
+                       case VKVG_CMD_CLOSE_PATH:
+                               vkvg_close_path (ctx);
+                               return;
+                       case VKVG_CMD_RECTANGLE:
+                               vkvg_rectangle (ctx, floats[0], floats[1], floats[2], floats[3]);
+                               return;
+                       case VKVG_CMD_ARC:
+                               vkvg_arc (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
+                               return;
+                       case VKVG_CMD_ARC_NEG:
+                               vkvg_arc (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
+                               return;
+                       /*case VKVG_CMD_ELLIPSE:
+                               vkvg_ellipse (ctx, floats[0], floats[1], floats[2], floats[3], floats[4]);
+                               break;*/
+                       case VKVG_CMD_MOVE_TO:
+                               vkvg_move_to(ctx, floats[0], floats[1]);
+                               return;
+                       case VKVG_CMD_LINE_TO:
+                               vkvg_line_to(ctx, floats[0], floats[1]);
+                               return;
+                       case VKVG_CMD_CURVE_TO:
+                               vkvg_curve_to (ctx, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5]);
+                               return;
+                       case VKVG_CMD_ELLIPTICAL_ARC_TO:
+                               {
+                                       bool* flags = (bool*)&floats[5];
+                                       vkvg_elliptic_arc_to (ctx, floats[0], floats[1], flags[0], flags[1], floats[2], floats[3], floats[4]);
+                               }
+                               return;
+                       case VKVG_CMD_QUADRATIC_TO:
+                               vkvg_quadratic_to (ctx, floats[0], floats[1], floats[2], floats[3]);
+                               return;
+                       }
                }
-               break;
-       case VKVG_CMD_QUADRATIC_TO:
-               vkvg_quadratic_to (ctx, floats[0], floats[1], floats[2], floats[3]);
-               break;
-
-       case VKVG_CMD_REL_MOVE_TO:
-               vkvg_rel_move_to(ctx, floats[0], floats[1]);
-               break;
-       case VKVG_CMD_REL_LINE_TO:
-               vkvg_rel_line_to(ctx, floats[0], floats[1]);
-               break;
-       case VKVG_CMD_REL_CURVE_TO:
-               vkvg_rel_curve_to (ctx, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5]);
-               break;
-       case VKVG_CMD_REL_QUADRATIC_TO:
-               vkvg_rel_quadratic_to (ctx, floats[0], floats[1], floats[2], floats[3]);
-               break;
-       case VKVG_CMD_REL_ELLIPTICAL_ARC_TO:
-               {
-                       bool* flags = (bool*)&floats[5];
-                       vkvg_rel_elliptic_arc_to (ctx, floats[0], floats[1], flags[0], flags[1], floats[2], floats[3], floats[4]);
+       } else if (r->cmd & VKVG_CMD_DRAW_COMMANDS) {
+               switch (r->cmd) {
+               case VKVG_CMD_PAINT:
+                       vkvg_paint (ctx);
+                       return;
+               case VKVG_CMD_FILL:
+                       vkvg_fill (ctx);
+                       return;
+               case VKVG_CMD_STROKE:
+                       vkvg_stroke (ctx);
+                       return;
+               case VKVG_CMD_CLIP:
+                       vkvg_clip (ctx);
+                       return;
+               case VKVG_CMD_CLEAR:
+                       vkvg_clear (ctx);
+                       return;
+               case VKVG_CMD_FILL_PRESERVE:
+                       vkvg_fill_preserve (ctx);
+                       return;
+               case VKVG_CMD_STROKE_PRESERVE:
+                       vkvg_stroke_preserve (ctx);
+                       return;
+               case VKVG_CMD_CLIP_PRESERVE:
+                       vkvg_clip_preserve (ctx);
+                       return;
+               }
+       } else if (r->cmd & VKVG_CMD_TRANSFORM_COMMANDS) {
+               switch (r->cmd) {
+               case VKVG_CMD_TRANSLATE:
+                       vkvg_translate (ctx, floats[0], floats[1]);
+                       return;
+               case VKVG_CMD_SCALE:
+                       vkvg_scale (ctx, floats[0], floats[1]);
+                       return;
+               case VKVG_CMD_ROTATE:
+                       vkvg_rotate (ctx, floats[0]);
+                       return;
+               case VKVG_CMD_IDENTITY_MATRIX:
+                       vkvg_identity_matrix (ctx);
+                       return;
+               case VKVG_CMD_TRANSFORM:
+                       {
+                               vkvg_matrix_t* mat = (vkvg_matrix_t*)&floats[0];
+                               vkvg_transform (ctx, mat);
+                       }
+                       return;
+               case VKVG_CMD_SET_MATRIX:
+                       {
+                               vkvg_matrix_t* mat = (vkvg_matrix_t*)&floats[0];
+                               vkvg_set_matrix (ctx, mat);
+                       }
+                       return;
+               }
+       } else if (r->cmd & VKVG_CMD_PATTERN_COMMANDS) {
+               switch (r->cmd) {
+               case VKVG_CMD_SET_SOURCE_RGB:
+                       vkvg_set_source_rgb (ctx, floats[0], floats[1], floats[2]);
+                       return;
+               case VKVG_CMD_SET_SOURCE_RGBA:
+                       vkvg_set_source_rgba (ctx, floats[0], floats[1], floats[2], floats[3]);
+                       return;
+               case VKVG_CMD_SET_SOURCE_COLOR:
+                       vkvg_set_source_color (ctx, uints[0]);
+                       return;
+               case VKVG_CMD_SET_SOURCE:
+                       {
+                               VkvgPattern pat = *((VkvgPattern*)(rec->buffer + r->dataOffset));
+                               vkvg_set_source (ctx, pat);
+                       }
+                       return;
+               case VKVG_CMD_SET_SOURCE_SURFACE:
+                       {
+                               VkvgSurface surf = *((VkvgSurface*)&floats[2]);
+                               vkvg_set_source_surface (ctx, surf, floats[0], floats[1]);
+                       }
+                       return;
                }
-               break;
-       case VKVG_CMD_SET_SOURCE_RGB:
-               vkvg_set_source_rgb (ctx, floats[0], floats[1], floats[2]);
-               break;
-       case VKVG_CMD_SET_SOURCE_RGBA:
-               vkvg_set_source_rgba (ctx, floats[0], floats[1], floats[2], floats[3]);
-               break;
-       case VKVG_CMD_SET_SOURCE:
-               {
-                       VkvgPattern pat = (VkvgPattern)(rec->buffer + r->dataOffset);
-                       vkvg_set_source (ctx, pat);
+       } else if (r->cmd & VKVG_CMD_TEXT_COMMANDS) {
+               char* txt = (char*)floats;
+               switch (r->cmd) {
+               case VKVG_CMD_SET_FONT_SIZE:
+                       vkvg_set_font_size (ctx, uints[0]);
+                       return;
+               case VKVG_CMD_SET_FONT_FACE:
+                       vkvg_select_font_face (ctx, txt);
+                       return;
+               /*case VKVG_CMD_SET_FONT_PATH:
+                       vkvg_load_font_from_path (ctx, txt);
+                       return; */
+               case VKVG_CMD_SHOW_TEXT:
+                       vkvg_show_text (ctx, txt);
+                       return;
                }
-               break;
-       case VKVG_CMD_SET_SOURCE_SURFACE:
-               {
-                       VkvgSurface surf = (VkvgSurface)&floats[2];
-                       vkvg_set_source_surface (ctx, surf, floats[0], floats[1]);
+       } else {
+               switch (r->cmd) {
+               case VKVG_CMD_SAVE:
+                       vkvg_save (ctx);
+                       return;
+               case VKVG_CMD_RESTORE:
+                       vkvg_restore (ctx);
+                       return;
                }
-               break;
        }
+       LOG(VKVG_LOG_ERR, "[REPLAY] unimplemented command: %.4x\n", r->cmd);
 }
 
index 64b6ee488e587c4c1a03486e7252bd2a867c0b2f..836a3640e482aee455f839da9c444cea89d7039c 100644 (file)
 
 #define VKVG_CMD_PATH_COMMANDS         0x0100
 #define VKVG_CMD_DRAW_COMMANDS         0x0200
-#define VKVG_CMD_RELATIVE_COMMANDS     0x0400|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_PRESERVE_COMMANDS     0x0400|VKVG_CMD_DRAW_COMMANDS
+#define VKVG_CMD_RELATIVE_COMMANDS     (0x0400|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_PATHPROPS_COMMANDS    (0x1000|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_PRESERVE_COMMANDS     (0x0400|VKVG_CMD_DRAW_COMMANDS)
 #define VKVG_CMD_PATTERN_COMMANDS      0x0800
 #define VKVG_CMD_TRANSFORM_COMMANDS    0x2000
 #define VKVG_CMD_TEXT_COMMANDS         0x4000
 
-#define VKVG_CMD_NEW_PATH                      0x0001|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_NEW_SUB_PATH          0x0002|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_CLOSE_PATH                    0x0003|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_MOVE_TO                       0x0004|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_LINE_TO                       0x0005|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_RECTANGLE                     0x0006|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_ARC                           0x0007|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_ARC_NEG                       0x0008|VKVG_CMD_PATH_COMMANDS
-//#define VKVG_CMD_ELLIPSE                     0x0009|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_CURVE_TO                      0x000A|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_QUADRATIC_TO          0x000B|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_ELLIPTICAL_ARC_TO     0x000C|VKVG_CMD_PATH_COMMANDS
-
-#define VKVG_CMD_SET_LINE_WIDTH                0x1001|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_SET_LINE_JOIN         0x1002|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_SET_LINE_CAP          0x1003|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_SET_OPERATOR          0x1004|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_SET_FILL_RULE         0x1005|VKVG_CMD_PATH_COMMANDS
-#define VKVG_CMD_SET_DASH                      0x1006|VKVG_CMD_PATH_COMMANDS
-
-#define VKVG_CMD_TRANSLATE                     0x0001|VKVG_CMD_TRANSFORM_COMMANDS
-#define VKVG_CMD_ROTATE                                0x0002|VKVG_CMD_TRANSFORM_COMMANDS
-#define VKVG_CMD_SCALE                         0x0003|VKVG_CMD_TRANSFORM_COMMANDS
-#define VKVG_CMD_TRANSFORM                     0x0004|VKVG_CMD_TRANSFORM_COMMANDS
-#define VKVG_CMD_IDENTITY_MATRIX       0x0005|VKVG_CMD_TRANSFORM_COMMANDS
-
-#define VKVG_CMD_SET_MATRIX                    0x0006|VKVG_CMD_TRANSFORM_COMMANDS
-
-#define VKVG_CMD_SET_FONT_SIZE         0x0001|VKVG_CMD_TEXT_COMMANDS
-#define VKVG_CMD_SET_FONT_FACE         0x0002|VKVG_CMD_TEXT_COMMANDS
-#define VKVG_CMD_SET_FONT_PATH         0x0003|VKVG_CMD_TEXT_COMMANDS
-#define VKVG_CMD_SHOW_TEXT                     0x0004|VKVG_CMD_TEXT_COMMANDS
-
-#define VKVG_CMD_REL_MOVE_TO                   VKVG_CMD_MOVE_TO                |VKVG_CMD_RELATIVE_COMMANDS
-#define VKVG_CMD_REL_LINE_TO                   VKVG_CMD_LINE_TO                |VKVG_CMD_RELATIVE_COMMANDS
-#define VKVG_CMD_REL_CURVE_TO                  VKVG_CMD_CURVE_TO               |VKVG_CMD_RELATIVE_COMMANDS
-#define VKVG_CMD_REL_QUADRATIC_TO              VKVG_CMD_QUADRATIC_TO   |VKVG_CMD_RELATIVE_COMMANDS
-#define VKVG_CMD_REL_ELLIPTICAL_ARC_TO VKVG_CMD_ELLIPTICAL_ARC_TO      |VKVG_CMD_RELATIVE_COMMANDS
-
-#define VKVG_CMD_PAINT                         0x0001|VKVG_CMD_DRAW_COMMANDS
-#define VKVG_CMD_FILL                          0x0002|VKVG_CMD_DRAW_COMMANDS
-#define VKVG_CMD_STROKE                                0x0003|VKVG_CMD_DRAW_COMMANDS
-#define VKVG_CMD_CLIP                          0x0004|VKVG_CMD_DRAW_COMMANDS
-#define VKVG_CMD_CLEAR                         0x0005|VKVG_CMD_DRAW_COMMANDS
-
-#define VKVG_CMD_FILL_PRESERVE         VKVG_CMD_FILL   |VKVG_CMD_PRESERVE_COMMANDS
-#define VKVG_CMD_STROKE_PRESERVE       VKVG_CMD_STROKE |VKVG_CMD_PRESERVE_COMMANDS
-#define VKVG_CMD_CLIP_PRESERVE         VKVG_CMD_CLIP   |VKVG_CMD_PRESERVE_COMMANDS
-
-#define VKVG_CMD_SET_SOURCE_RGB                0x0001|VKVG_CMD_PATTERN_COMMANDS
-#define VKVG_CMD_SET_SOURCE_RGBA       0x0002|VKVG_CMD_PATTERN_COMMANDS
-#define VKVG_CMD_SET_SOURCE                    0x0003|VKVG_CMD_PATTERN_COMMANDS
-#define VKVG_CMD_SET_SOURCE_SURFACE    0x0004|VKVG_CMD_PATTERN_COMMANDS
+#define VKVG_CMD_NEW_PATH                      (0x0001|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_NEW_SUB_PATH          (0x0002|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_CLOSE_PATH                    (0x0003|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_MOVE_TO                       (0x0004|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_LINE_TO                       (0x0005|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_RECTANGLE                     (0x0006|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_ARC                           (0x0007|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_ARC_NEG                       (0x0008|VKVG_CMD_PATH_COMMANDS)
+//#define VKVG_CMD_ELLIPSE                     (0x0009|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_CURVE_TO                      (0x000A|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_QUADRATIC_TO          (0x000B|VKVG_CMD_PATH_COMMANDS)
+#define VKVG_CMD_ELLIPTICAL_ARC_TO     (0x000C|VKVG_CMD_PATH_COMMANDS)
+
+#define VKVG_CMD_SET_LINE_WIDTH                (0x0001|VKVG_CMD_PATHPROPS_COMMANDS)
+#define VKVG_CMD_SET_LINE_JOIN         (0x0002|VKVG_CMD_PATHPROPS_COMMANDS)
+#define VKVG_CMD_SET_LINE_CAP          (0x0003|VKVG_CMD_PATHPROPS_COMMANDS)
+#define VKVG_CMD_SET_OPERATOR          (0x0004|VKVG_CMD_PATHPROPS_COMMANDS)
+#define VKVG_CMD_SET_FILL_RULE         (0x0005|VKVG_CMD_PATHPROPS_COMMANDS)
+#define VKVG_CMD_SET_DASH                      (0x0006|VKVG_CMD_PATHPROPS_COMMANDS)
+
+#define VKVG_CMD_TRANSLATE                     (0x0001|VKVG_CMD_TRANSFORM_COMMANDS)
+#define VKVG_CMD_ROTATE                                (0x0002|VKVG_CMD_TRANSFORM_COMMANDS)
+#define VKVG_CMD_SCALE                         (0x0003|VKVG_CMD_TRANSFORM_COMMANDS)
+#define VKVG_CMD_TRANSFORM                     (0x0004|VKVG_CMD_TRANSFORM_COMMANDS)
+#define VKVG_CMD_IDENTITY_MATRIX       (0x0005|VKVG_CMD_TRANSFORM_COMMANDS)
+
+#define VKVG_CMD_SET_MATRIX                    (0x0006|VKVG_CMD_TRANSFORM_COMMANDS)
+
+#define VKVG_CMD_SET_FONT_SIZE         (0x0001|VKVG_CMD_TEXT_COMMANDS)
+#define VKVG_CMD_SET_FONT_FACE         (0x0002|VKVG_CMD_TEXT_COMMANDS)
+#define VKVG_CMD_SET_FONT_PATH         (0x0003|VKVG_CMD_TEXT_COMMANDS)
+#define VKVG_CMD_SHOW_TEXT                     (0x0004|VKVG_CMD_TEXT_COMMANDS)
+
+#define VKVG_CMD_REL_MOVE_TO                   (VKVG_CMD_MOVE_TO                       |VKVG_CMD_RELATIVE_COMMANDS)
+#define VKVG_CMD_REL_LINE_TO                   (VKVG_CMD_LINE_TO                       |VKVG_CMD_RELATIVE_COMMANDS)
+#define VKVG_CMD_REL_CURVE_TO                  (VKVG_CMD_CURVE_TO                      |VKVG_CMD_RELATIVE_COMMANDS)
+#define VKVG_CMD_REL_QUADRATIC_TO              (VKVG_CMD_QUADRATIC_TO          |VKVG_CMD_RELATIVE_COMMANDS)
+#define VKVG_CMD_REL_ELLIPTICAL_ARC_TO (VKVG_CMD_ELLIPTICAL_ARC_TO     |VKVG_CMD_RELATIVE_COMMANDS)
+
+#define VKVG_CMD_PAINT                         (0x0001|VKVG_CMD_DRAW_COMMANDS)
+#define VKVG_CMD_FILL                          (0x0002|VKVG_CMD_DRAW_COMMANDS)
+#define VKVG_CMD_STROKE                                (0x0003|VKVG_CMD_DRAW_COMMANDS)
+#define VKVG_CMD_CLIP                          (0x0004|VKVG_CMD_DRAW_COMMANDS)
+#define VKVG_CMD_CLEAR                         (0x0005|VKVG_CMD_DRAW_COMMANDS)
+
+#define VKVG_CMD_FILL_PRESERVE         (VKVG_CMD_FILL  |VKVG_CMD_PRESERVE_COMMANDS)
+#define VKVG_CMD_STROKE_PRESERVE       (VKVG_CMD_STROKE        |VKVG_CMD_PRESERVE_COMMANDS)
+#define VKVG_CMD_CLIP_PRESERVE         (VKVG_CMD_CLIP  |VKVG_CMD_PRESERVE_COMMANDS)
+
+#define VKVG_CMD_SET_SOURCE_RGB                (0x0001|VKVG_CMD_PATTERN_COMMANDS)
+#define VKVG_CMD_SET_SOURCE_RGBA       (0x0002|VKVG_CMD_PATTERN_COMMANDS)
+#define VKVG_CMD_SET_SOURCE_COLOR      (0x0003|VKVG_CMD_PATTERN_COMMANDS)
+#define VKVG_CMD_SET_SOURCE                    (0x0004|VKVG_CMD_PATTERN_COMMANDS)
+#define VKVG_CMD_SET_SOURCE_SURFACE    (0x0005|VKVG_CMD_PATTERN_COMMANDS)
 
 
 
@@ -103,7 +105,7 @@ typedef struct _vkvg_recording_t{
        uint32_t                commandsReservedCount;
        size_t                  bufferSize;
        size_t                  bufferReservedSize;
-       void*                   buffer;
+       char*                   buffer;
 }vkvg_recording_t;
 
 
@@ -114,8 +116,9 @@ void                                _replay_command         (VkvgContext ctx, VkvgRecording rec, uint32_t index);
 void                           _record                         (vkvg_recording_t* rec,...);
 
 #define RECORD(ctx,...) {\
-       if (ctx->recording)             \
+       if (ctx->recording)     {\
                _record (ctx->recording,__VA_ARGS__);\
+       }\
 }
 
 
index aaa39499928ebf754f76dd523e3a2544ca19cc77..adfd05e8ba2a0f6bc4f41786e8bc4c4ea9faa3c1 100644 (file)
@@ -352,21 +352,12 @@ void vkvg_close_path (VkvgContext ctx){
 
        _finish_path(ctx);
 }
-void _line_to (VkvgContext ctx, float x, float y) {
-       vec2 p = {x,y};
-       if (!_current_path_is_empty (ctx)){
-               //prevent adding the same point
-               if (vec2_equ (_get_current_position (ctx), p))
-                       return;
-       }
-       _add_point (ctx, x, y);
-}
 void vkvg_rel_line_to (VkvgContext ctx, float dx, float dy){
        if (ctx->status)
                return;
 
        RECORD(ctx, VKVG_CMD_REL_LINE_TO, dx, dy);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_line_to:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_line_to: %f, %f\n", dx, dy);
 
        if (_current_path_is_empty(ctx))
                _add_point(ctx, 0, 0);
@@ -379,7 +370,7 @@ void vkvg_line_to (VkvgContext ctx, float x, float y)
                return;
 
        RECORD(ctx, VKVG_CMD_LINE_TO, x, y);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: line_to:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: line_to: %f, %f\n", x, y);
        _line_to(ctx, x, y);
 }
 void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2){
@@ -387,7 +378,7 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa
                return;
 
        RECORD(ctx, VKVG_CMD_ARC, xc, yc, radius, a1, a2);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: arc:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: arc: %f,%f %f %f %f\n", xc, yc, radius, a1, a2);
 
        while (a2 < a1)//positive arc must have a1<a2
                a2 += 2.f*M_PIF;
@@ -437,7 +428,7 @@ void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_ARC_NEG, xc, yc, radius, a1, a2);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: arc_neg:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: %f,%f %f %f %f\n", xc, yc, radius, a1, a2);
        while (a2 > a1)
                a2 -= 2.f*M_PIF;
        if (a1 - a2 > a1 + 2.f * M_PIF) //limit arc to 2PI
@@ -487,18 +478,19 @@ void vkvg_rel_move_to (VkvgContext ctx, float x, float y)
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_REL_MOVE_TO, x, y);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_mote_to:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_mote_to: %f, %f\n", x, y);
        if (_current_path_is_empty(ctx))
                _add_point(ctx, 0, 0);
        vec2 cp = _get_current_position(ctx);
-       vkvg_move_to(ctx, cp.x + x, cp.y + y);
+       _finish_path(ctx);
+       _add_point (ctx, cp.x + x, cp.y + y);
 }
 void vkvg_move_to (VkvgContext ctx, float x, float y)
 {
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_MOVE_TO, x, y);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: move_to:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: move_to: %f,%f\n", x, y);
        _finish_path(ctx);
        _add_point (ctx, x, y);
 }
@@ -511,21 +503,8 @@ void vkvg_get_current_point (VkvgContext ctx, float* x, float* y) {
        *x = cp.x;
        *y = cp.y;
 }
-void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
-       if (ctx->status)
-               return;
-       RECORD(ctx, VKVG_CMD_REL_QUADRATIC_TO, x1, y1, x2, y2);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_quadratic_to:\n");
-       vec2 cp = _get_current_position(ctx);
-       vkvg_quadratic_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2);
-}
 const double quadraticFact = 2.0/3.0;
-void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
-       if (ctx->status)
-               return;
-       RECORD(ctx, VKVG_CMD_QUADRATIC_TO, x1, y1, x2, y2);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: quadratic_to:\n");
-
+void _quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
        float x0, y0;
        if (_current_path_is_empty(ctx)) {
                x0 = x1;
@@ -539,11 +518,22 @@ void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2)
                                        y2 + (y1 - y2) * quadraticFact,
                                        x2, y2);
 }
-void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
+void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
        if (ctx->status)
                return;
-       RECORD(ctx, VKVG_CMD_CURVE_TO, x1, y1, x2, y2, x3, y3);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: curve_to:\n");
+       RECORD(ctx, VKVG_CMD_QUADRATIC_TO, x1, y1, x2, y2);
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: quadratic_to: %f, %f, %f, %f\n", x1, y1, x2, y2);
+       _quadratic_to(ctx, x1, y1, x2, y2);
+}
+void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) {
+       if (ctx->status)
+               return;
+       RECORD(ctx, VKVG_CMD_REL_QUADRATIC_TO, x1, y1, x2, y2);
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_quadratic_to: %f, %f, %f, %f\n", x1, y1, x2, y2);
+       vec2 cp = _get_current_position(ctx);
+       _quadratic_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2);
+}
+void _curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
        //prevent running _recursive_bezier when all 4 curve points are equal
        if (EQUF(x1,x2) && EQUF(x2,x3) && EQUF(y1,y2) && EQUF(y2,y3)) {
                if (_current_path_is_empty(ctx) || (EQUF(_get_current_position(ctx).x,x1) && EQUF(_get_current_position(ctx).y,y1)))
@@ -567,13 +557,20 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo
                _add_point(ctx,x3,y3);
        _set_curve_end (ctx);
 }
+void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
+       if (ctx->status)
+               return;
+       RECORD(ctx, VKVG_CMD_CURVE_TO, x1, y1, x2, y2, x3, y3);
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: curve_to %f,%f %f,%f %f,%f:\n", x1, y1, x2, y2, x3, y3);
+       _curve_to (ctx, x1, y1, x2, y2, x3, y3);
+}
 void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
        if (ctx->status)
                return;
-       RECORD(ctx, VKVG_CMD_REL_CURVE_TO, x1, y1, x2, y2, x3, y3);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_curve_to:\n");
+       RECORD(ctx, (uint32_t)VKVG_CMD_REL_CURVE_TO, x1, y1, x2, y2, x3, y3);
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel curve_to %f,%f %f,%f %f,%f:\n", x1, y1, x2, y2, x3, y3);
        vec2 cp = _get_current_position(ctx);
-       vkvg_curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3);
+       _curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3);
 }
 void vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float w, float h){
        if (ctx->status)
@@ -587,7 +584,7 @@ vkvg_status_t vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float
        if (ctx->status)
                return ctx->status;
        RECORD(ctx, VKVG_CMD_RECTANGLE, x, y, w, h);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rectangle:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: rectangle: %f,%f,%f,%f\n", x, y, w, h);
        _finish_path (ctx);
 
        if (w <= 0 || h <= 0)
@@ -939,6 +936,7 @@ void vkvg_paint (VkvgContext ctx){
 void vkvg_set_source_color (VkvgContext ctx, uint32_t c) {
        if (ctx->status)
                return;
+       RECORD(ctx, VKVG_CMD_SET_SOURCE_COLOR, c);
        ctx->curColor = c;
        _update_cur_pattern (ctx, NULL);
 }
@@ -1354,7 +1352,7 @@ void vkvg_translate (VkvgContext ctx, float dx, float dy){
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_TRANSLATE, dx, dy);
-       LOG(VKVG_LOG_INFO_CMD, "CMD: translate:\n");
+       LOG(VKVG_LOG_INFO_CMD, "CMD: translate: %f, %f\n", dx, dy);
        _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy);
        _set_mat_inv_and_vkCmdPush (ctx);
@@ -1363,7 +1361,7 @@ void vkvg_scale (VkvgContext ctx, float sx, float sy){
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_SCALE, sx, sy);
-       LOG(VKVG_LOG_INFO_CMD, "CMD: scale:\n");
+       LOG(VKVG_LOG_INFO_CMD, "CMD: scale: %f, %f\n", sx, sy);
        _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy);
        _set_mat_inv_and_vkCmdPush (ctx);
@@ -1372,7 +1370,7 @@ void vkvg_rotate (VkvgContext ctx, float radians){
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_ROTATE, radians);
-       LOG(VKVG_LOG_INFO_CMD, "CMD: rotate:\n");
+       LOG(VKVG_LOG_INFO_CMD, "CMD: rotate: %f\n", radians);
        _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_rotate (&ctx->pushConsts.mat, radians);
        _set_mat_inv_and_vkCmdPush (ctx);
@@ -1381,7 +1379,7 @@ void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) {
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_TRANSFORM, matrix);
-       LOG(VKVG_LOG_INFO_CMD, "CMD: transform:\n");
+       LOG(VKVG_LOG_INFO_CMD, "CMD: transform: %f, %f, %f, %f, %f, %f\n", matrix->xx, matrix->yx, matrix->xy, matrix->yy, matrix->x0, matrix->y0);
        _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_t res;
        vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix);
@@ -1402,7 +1400,7 @@ void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_SET_MATRIX, matrix);
-       LOG(VKVG_LOG_INFO_CMD, "CMD: set_matrix:\n");
+       LOG(VKVG_LOG_INFO_CMD, "CMD: set_matrix: %f, %f, %f, %f, %f, %f\n", matrix->xx, matrix->yx, matrix->xy, matrix->yy, matrix->x0, matrix->y0);
        _emit_draw_cmd_undrawn_vertices(ctx);
        ctx->pushConsts.mat = (*matrix);
        _set_mat_inv_and_vkCmdPush (ctx);
@@ -1415,7 +1413,7 @@ void vkvg_elliptic_arc_to (VkvgContext ctx, float x2, float y2, bool largeArc, b
        if (ctx->status)
                return;
        RECORD(ctx, VKVG_CMD_ELLIPTICAL_ARC_TO, x2, y2, rx, ry, phi, largeArc, sweepFlag);
-       LOG(VKVG_LOG_INFO_CMD, "\tCMD: elliptic_arc_to:\n");
+       LOG(VKVG_LOG_INFO_CMD, "\tCMD: elliptic_arc_to: x2:%10.5f y2:%10.5f large:%d sweep:%d rx:%10.5f ry:%10.5f phi:%10.5f \n", x2,y2,largeArc,sweepFlag,rx,ry,phi);
        float x1, y1;
        vkvg_get_current_point(ctx, &x1, &y1);
        _elliptic_arc(ctx, x1, y1, x2, y2, largeArc, sweepFlag, rx, ry, phi);
index b0a32fbf295b4e81195573f964065f739ca5095c..1858232c9b248d852356409ea4231823a7b7ef2e 100644 (file)
@@ -1369,7 +1369,15 @@ void _recursive_bezier (VkvgContext ctx, float distanceTolerance,
        _recursive_bezier (ctx, distanceTolerance,x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1);
 }
 #pragma warning(default:4127)
-
+void _line_to (VkvgContext ctx, float x, float y) {
+       vec2 p = {x,y};
+       if (!_current_path_is_empty (ctx)){
+               //prevent adding the same point
+               if (vec2_equ (_get_current_position (ctx), p))
+                       return;
+       }
+       _add_point (ctx, x, y);
+}
 void _elliptic_arc (VkvgContext ctx, float x1, float y1, float x2, float y2, bool largeArc, bool counterClockWise, float _rx, float _ry, float phi) {
        if (ctx->status)
                return;
@@ -1457,7 +1465,7 @@ void _elliptic_arc (VkvgContext ctx, float x1, float y1, float x2, float y2, boo
                _set_curve_start (ctx);
                _add_point (ctx, xy.x, xy.y);
        }else{
-               vkvg_line_to(ctx, xy.x, xy.y);
+               _line_to(ctx, xy.x, xy.y);
                _set_curve_start (ctx);
        }
 
index de0a56b4054616ab51b09d7e4195348c229b324c..41bba6de9f397a364720f89adebb0909e7b756c1 100644 (file)
@@ -298,6 +298,6 @@ void _recursive_bezier(VkvgContext ctx, float distanceTolerance,
 void _bezier (VkvgContext ctx,
                          float x1, float y1, float x2, float y2,
                          float x3, float y3, float x4, float y4);
-
-void _elliptic_arc (VkvgContext ctx, float x1, float y1, float x2, float y2, bool largeArc, bool counterClockWise, float _rx, float _ry, float phi);
+void _line_to          (VkvgContext ctx, float x, float y);
+void _elliptic_arc     (VkvgContext ctx, float x1, float y1, float x2, float y2, bool largeArc, bool counterClockWise, float _rx, float _ry, float phi);
 #endif