aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2018-12-14 17:21:11 +0900
committerHermet Park <hermetpark@gmail.com>2018-12-14 17:21:11 +0900
commitfb2d3ea87b9890dfb24a100958036bad95a57a38 (patch)
tree00e0ec6f32fdc52c51045ad98da6805f6ef038fc
parenttrivial change. (diff)
downloadefl-devs/hermet/json.tar.gz
gfx path: update reserve method.devs/hermet/json
-rw-r--r--src/lib/efl/interfaces/efl_gfx_path.c46
-rw-r--r--src/lib/efl/interfaces/efl_gfx_path.eo5
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg_shape.c1
-rw-r--r--src/static_libs/vg_common/vg_common_json.c8
4 files changed, 28 insertions, 32 deletions
diff --git a/src/lib/efl/interfaces/efl_gfx_path.c b/src/lib/efl/interfaces/efl_gfx_path.c
index ec6f7ea260..7715e544e0 100644
--- a/src/lib/efl/interfaces/efl_gfx_path.c
+++ b/src/lib/efl/interfaces/efl_gfx_path.c
@@ -81,8 +81,8 @@ efl_gfx_path_grow(Efl_Gfx_Path_Command command,
{
pts_length += _efl_gfx_path_command_length(command);
- //grow twice
- if (pts_length >= pd->reserved_pts_cnt)
+ //grow up twice
+ if (pts_length > pd->reserved_pts_cnt)
{
double *pts_tmp = realloc(pd->points, sizeof(pd->points) * (pts_length * 2));
if (!pts_tmp) return EINA_FALSE;
@@ -94,14 +94,14 @@ efl_gfx_path_grow(Efl_Gfx_Path_Command command,
pd->points + pts_length - _efl_gfx_path_command_length(command);
}
- //grow twice
- if (cmd_length >= pd->reserved_cmd_cnt)
+ //grow up twice
+ if ((cmd_length + 1) > pd->reserved_cmd_cnt)
{
- Efl_Gfx_Path_Command *cmd_tmp =
- realloc(pd->commands, (cmd_length * 2) * sizeof (Efl_Gfx_Path_Command));
- if (!cmd_tmp) return EINA_FALSE;
- pd->reserved_cmd_cnt = cmd_length * 2;
- pd->commands = cmd_tmp;
+ Efl_Gfx_Path_Command *cmd_tmp =
+ realloc(pd->commands, (cmd_length * 2) * sizeof (Efl_Gfx_Path_Command));
+ if (!cmd_tmp) return EINA_FALSE;
+ pd->reserved_cmd_cnt = (cmd_length * 2);
+ pd->commands = cmd_tmp;
}
pd->commands_count = cmd_length + 1;
@@ -112,7 +112,6 @@ efl_gfx_path_grow(Efl_Gfx_Path_Command command,
// NULL terminate the stream
pd->commands[cmd_length] = EFL_GFX_PATH_COMMAND_TYPE_END;
-
pd->convex = EINA_FALSE;
return EINA_TRUE;
@@ -392,39 +391,36 @@ _efl_gfx_path_equal_commands(Eo *obj EINA_UNUSED,
}
EOLIAN static void
-_efl_gfx_path_reserve(Eo *obj EINA_UNUSED, Efl_Gfx_Path_Data *pd, unsigned int cmd_count)
+_efl_gfx_path_reserve(Eo *obj EINA_UNUSED, Efl_Gfx_Path_Data *pd,
+ unsigned int cmd_count, unsigned int pts_count)
{
if (pd->reserved_cmd_cnt < cmd_count)
{
- pd->reserved_cmd_cnt = cmd_count;
- pd->commands = realloc(pd->commands, sizeof(pd->commands) * cmd_count);
+ //+1 for path close.
+ pd->reserved_cmd_cnt = cmd_count + 1;
+ pd->commands = realloc(pd->commands, sizeof(pd->commands) * pd->reserved_cmd_cnt);
}
- unsigned int pts_cnt = cmd_count * 3;
-
- if (pd->reserved_pts_cnt < pts_cnt)
+ if (pd->reserved_pts_cnt < pts_count)
{
- pd->reserved_pts_cnt = pts_cnt;
- pd->points = realloc(pd->points, sizeof(pd->points) * pts_cnt);
+ pd->reserved_pts_cnt = pts_count;
+ pd->points = realloc(pd->points, sizeof(pd->points) * pts_count);
}
}
-#define DEFAULT_RESERVED_CMD_CNT 20
-#define DEFAULT_RESERVED_PTS_CNT (DEFAULT_RESERVED_CMD_CNT * 3)
-
EOLIAN static void
_efl_gfx_path_reset(Eo *obj, Efl_Gfx_Path_Data *pd)
{
Efl_Gfx_Path_Change_Event ev = { EFL_GFX_CHANGE_FLAG_PATH };
free(pd->commands);
- pd->reserved_cmd_cnt = DEFAULT_RESERVED_CMD_CNT;
- pd->commands = malloc(sizeof(Efl_Gfx_Path_Command) * pd->reserved_cmd_cnt);
+ pd->reserved_cmd_cnt = 0;
+ pd->commands = NULL;
pd->commands_count = 0;
free(pd->points);
- pd->reserved_pts_cnt = DEFAULT_RESERVED_PTS_CNT;
- pd->points = malloc(sizeof(double) * pd->reserved_pts_cnt);
+ pd->reserved_pts_cnt = 0;
+ pd->points = NULL;
pd->points_count = 0;
free(pd->path_data);
diff --git a/src/lib/efl/interfaces/efl_gfx_path.eo b/src/lib/efl/interfaces/efl_gfx_path.eo
index bb46902f7e..9ac5ff5eec 100644
--- a/src/lib/efl/interfaces/efl_gfx_path.eo
+++ b/src/lib/efl/interfaces/efl_gfx_path.eo
@@ -284,13 +284,14 @@ mixin Efl.Gfx.Path
}
reserve {
[[Reserve path commands buffer in advance. If you know the count of
- path commands coming, you can reserve commands buffer in advance
- to avoid buffer growing job.
+ path commands coming, you can reserve commands buffer in advance
+ to avoid buffer growing job.
@since 1.22
]]
params {
@in cmd_count: uint; [[Commands count to reserve]]
+ @in pts_count: uint; [[Pointers count to reserve]]
}
}
}
diff --git a/src/lib/evas/canvas/efl_canvas_vg_shape.c b/src/lib/evas/canvas/efl_canvas_vg_shape.c
index 438c47228c..106efeccfb 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_shape.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_shape.c
@@ -126,7 +126,6 @@ _efl_canvas_vg_shape_efl_object_constructor(Eo *obj, Efl_Canvas_Vg_Shape_Data *p
obj = efl_constructor(efl_super(obj, MY_CLASS));
- efl_gfx_path_reserve(obj, 20); //20: reserved command count
efl_gfx_shape_stroke_scale_set(obj, 1);
efl_gfx_shape_stroke_location_set(obj, 0.5);
efl_gfx_shape_stroke_cap_set(obj, EFL_GFX_CAP_BUTT);
diff --git a/src/static_libs/vg_common/vg_common_json.c b/src/static_libs/vg_common/vg_common_json.c
index 44e920b315..c7f8ca9ce6 100644
--- a/src/static_libs/vg_common/vg_common_json.c
+++ b/src/static_libs/vg_common/vg_common_json.c
@@ -17,16 +17,17 @@ _construct_drawable_nodes(Efl_VG *root, const LOTLayerNode *layer, int depth EIN
const LOTNode *node = layer->mNodeList.ptr[i];
if (!node) continue;
+ const float *data = node->mPath.ptPtr;
+ if (!data) continue;
+
Efl_VG* shape = evas_vg_shape_add(parent);
if (!shape) continue;
#if 0
for (int i = 0; i < depth; i++) printf(" ");
printf("%s (%p)\n", efl_class_name_get(efl_class_get(shape)), shape);
#endif
-
//0: Path
- const float *data = node->mPath.ptPtr;
- if (!data) continue;
+ efl_gfx_path_reserve(shape, node->mPath.elmCount, node->mPath.ptCount);
for (int i = 0; i < node->mPath.elmCount; i++)
{
@@ -254,7 +255,6 @@ vg_common_json_create_vg_node(Vg_File_Data *vfd)
printf("%s (%p)\n", efl_class_name_get(efl_class_get(vfd->root)), vfd->root);
#endif
_update_vg_tree(root, tree, 1);
-
#else
return EINA_FALSE;
#endif