From 7bf892ddb12973d64e26e3181a5e77f751f2bd9e Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Wed, 15 Sep 2021 10:41:02 +0200 Subject: [PATCH] evas vg: json/lottie memory usage optimization This patch fixes potential memory leaks and unnecessary allocations. Change-Id: I515c5a809dc5b23e433514aad177dcbda47beb75 --- src/static_libs/vg_common/vg_common_json.c | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/static_libs/vg_common/vg_common_json.c b/src/static_libs/vg_common/vg_common_json.c index 6a3fef3..7bc1ec8 100644 --- a/src/static_libs/vg_common/vg_common_json.c +++ b/src/static_libs/vg_common/vg_common_json.c @@ -50,11 +50,11 @@ _construct_drawable_nodes(Tvg_Paint *parent, const LOTLayerNode *layer, int dept continue; } - Tvg_Paint* shape = tvg_shape_new(); - const float *data = node->mPath.ptPtr; if (!data) continue; + Tvg_Paint* shape = tvg_shape_new(); + //0: Path uint32_t cmdCnt = node->mPath.elmCount; uint32_t ptsCnt = node->mPath.ptCount * sizeof(float) / sizeof(Tvg_Point); @@ -301,11 +301,9 @@ _construct_masks(Tvg_Paint *mtarget, LOTMask *masks, unsigned int mask_cnt, int return mtarget; } -static Eina_Bool +static void _update_vg_tree(Tvg_Paint *root, const LOTLayerNode *layer, int depth EINA_UNUSED) { - if (!layer->mVisible) return EINA_FALSE; - Tvg_Paint *ptree = NULL; //Note: We assume that if matte is valid, next layer must be a matte source. @@ -325,18 +323,23 @@ _update_vg_tree(Tvg_Paint *root, const LOTLayerNode *layer, int depth EINA_UNUSE printf("[layer %03d] matte:%d\n", i, matte_mode); #endif - //Source Layer - Tvg_Paint *ctree = tvg_scene_new(); - Eina_Bool hastree = _update_vg_tree(ctree, clayer, depth+1); - - if (matte_mode == TVG_COMPOSITE_METHOD_NONE) - { - tvg_scene_push(root, ctree); - } - else if (hastree == EINA_TRUE) + if ((clayer->mLayerList.size > 0 || clayer->mNodeList.size > 0) && clayer->mVisible) { - tvg_paint_set_composite_method(ptree, ctree, matte_mode); - mtarget = ctree; + //Source Layer + Tvg_Paint *ctree = tvg_scene_new(); + _update_vg_tree(ctree, clayer, depth+1); + + if (matte_mode == TVG_COMPOSITE_METHOD_NONE) + { + tvg_scene_push(root, ctree); + } + else + { + tvg_paint_set_composite_method(ptree, ctree, matte_mode); + mtarget = ctree; + } + + ptree = ctree; } //Remap Matte Mode @@ -364,12 +367,10 @@ _update_vg_tree(Tvg_Paint *root, const LOTLayerNode *layer, int depth EINA_UNUSE break; } - ptree = ctree; - if (clayer->mMaskList.size > 0) { mlayer = clayer; - if (!mtarget) mtarget = ctree; + if (!mtarget) mtarget = ptree; } else mtarget = NULL; @@ -382,8 +383,6 @@ _update_vg_tree(Tvg_Paint *root, const LOTLayerNode *layer, int depth EINA_UNUSE //Construct drawable nodes. if (layer->mNodeList.size > 0) _construct_drawable_nodes(root, layer, depth); - - return layer->mLayerList.size || layer->mNodeList.size; } #endif @@ -507,6 +506,7 @@ vg_common_json_create_vg_node(Vg_File_Data *vfd) cd->master_scene = EINA_TRUE; tvg_scene_clear(cd->scene, EINA_TRUE); + if (!tree->mVisible) return EINA_TRUE; _update_vg_tree(cd->scene, tree, 1); return EINA_TRUE; -- 2.7.4