evas vg: code refactoring.

keep internal variable and structre names consisteny.
no logical changes.
This commit is contained in:
Hermet Park 2018-12-07 17:14:15 +09:00
parent cfc66dd0bd
commit 093e32a0fb
6 changed files with 158 additions and 149 deletions

View File

@ -162,7 +162,7 @@ _efl_canvas_vg_object_root_node_set(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd, E
{
if (!pd->user_entry)
{
pd->user_entry = malloc(sizeof(User_Vg_Entry));
pd->user_entry = malloc(sizeof(Vg_User_Entry));
if (!pd->user_entry)
{
ERR("Failed to alloc user entry data while setting root node");
@ -255,12 +255,10 @@ _efl_canvas_vg_object_viewbox_align_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Vg
if (align_y) *align_y = pd->align_y;
}
// file set and save api implementation
EOLIAN static Eina_Bool
_efl_canvas_vg_object_efl_file_file_set(Eo *obj, Efl_Canvas_Vg_Object_Data *pd, const char *file, const char *key)
{
Evas_Cache_Vg_Entry *old_entry;
Vg_Cache_Entry *old_entry;
int w, h;
if (!file) return EINA_FALSE;
@ -480,7 +478,7 @@ _cache_vg_entry_render(Evas_Object_Protected_Data *obj,
void *engine, void *output, void *context, void *surface,
int x, int y, int w, int h, Eina_Bool do_async)
{
Evas_Cache_Vg_Entry *vg_entry = pd->vg_entry;
Vg_Cache_Entry *vg_entry = pd->vg_entry;
Efl_VG *root, *dupe_root;
// if the size changed in between path set and the draw call;
@ -528,7 +526,7 @@ _user_vg_entry_render(Evas_Object_Protected_Data *obj,
void *engine, void *output, void *context, void *surface,
int x, int y, int w, int h, Eina_Bool do_async)
{
User_Vg_Entry *user_entry = pd->user_entry;
Vg_User_Entry *user_entry = pd->user_entry;
//if the size doesn't match, drop previous cache surface.
if ((user_entry->w != w ) ||

View File

@ -9,17 +9,14 @@ typedef struct _Efl_Canvas_Vg_Gradient_Data Efl_Canvas_Vg_Gradient_Data;
typedef struct _Efl_Canvas_Vg_Interpolation Efl_Canvas_Vg_Interpolation;
typedef struct _Efl_Canvas_Vg_Object_Data Efl_Canvas_Vg_Object_Data;
typedef struct _Evas_Cache_Vg_Entry Evas_Cache_Vg_Entry;
typedef struct _Evas_Cache_Vg Evas_Cache_Vg;
struct _Evas_Cache_Vg
typedef struct _Vg_Cache
{
Eina_Hash *vg_hash;
Eina_Hash *active;
Eina_Hash *vfd_hash;
Eina_Hash *vg_entry_hash;
int ref;
};
} Vg_Cache;
struct _Evas_Cache_Vg_Entry
typedef struct _Vg_Cache_Entry
{
char *hash_key;
Eina_Stringshare *file;
@ -28,27 +25,29 @@ struct _Evas_Cache_Vg_Entry
int h;
Efl_VG *root;
int ref;
};
} Vg_Cache_Entry;
typedef struct _User_Vg_Entry
// holds the vg tree info set by the user
typedef struct _Vg_User_Entry
{
int w; // current surface width
int h; // current surface height
Efl_VG *root;
}User_Vg_Entry; // holds the vg tree info set by the user
} Vg_User_Entry;
struct _Efl_Canvas_Vg_Object_Data
{
Efl_VG *root;
Evas_Cache_Vg_Entry *vg_entry;
User_Vg_Entry *user_entry; // holds the user set vg tree
Eina_Rect fill;
Eina_Rect viewbox;
unsigned int width, height;
Eina_Array cleanup;
double align_x, align_y;
Efl_Canvas_Vg_Fill_Mode fill_mode;
Eina_Bool changed;
Efl_VG *root;
Vg_Cache_Entry *vg_entry;
Vg_User_Entry *user_entry; //holds the user set vg tree
Eina_Rect fill;
Eina_Rect viewbox;
unsigned int width, height;
Eina_Array cleanup;
double align_x, align_y;
Efl_Canvas_Vg_Fill_Mode fill_mode;
Eina_Bool changed : 1;
};
struct _Efl_Canvas_Vg_Node_Data
@ -59,7 +58,7 @@ struct _Efl_Canvas_Vg_Node_Data
Efl_Canvas_Vg_Node *mask;
Ector_Renderer *renderer;
Efl_VG *vg_obj;
Efl_VG *vg_obj; //...Not necessary!!
void (*render_pre)(Eo *obj, Eina_Matrix3 *parent, Ector_Surface *s, void *data, Efl_Canvas_Vg_Node_Data *nd);
void *data;
@ -101,9 +100,9 @@ struct _Efl_Canvas_Vg_Interpolation
void evas_cache_vg_init(void);
void evas_cache_vg_shutdown(void);
Evas_Cache_Vg_Entry* evas_cache_vg_entry_find(const char *file, const char *key, int w, int h);
Efl_VG* evas_cache_vg_tree_get(Evas_Cache_Vg_Entry *svg_entry);
void evas_cache_vg_entry_del(Evas_Cache_Vg_Entry *svg_entry);
Vg_Cache_Entry* evas_cache_vg_entry_find(const char *file, const char *key, int w, int h);
Efl_VG* evas_cache_vg_tree_get(Vg_Cache_Entry *svg_entry);
void evas_cache_vg_entry_del(Vg_Cache_Entry *svg_entry);
Vg_File_Data * evas_cache_vg_file_info(const char *file, const char *key);
Eina_Bool evas_vg_save_to_file(Vg_File_Data *evg_data, const char *file, const char *key, const char *flags);

View File

@ -1505,19 +1505,22 @@ struct _Evas_Image_Save_Func
struct _Vg_File_Data
{
Efl_VG *root;
Evas_Vg_Load_Func *loader;
Eina_Rectangle view_box;
Efl_VG *root;
Eina_Bool preserve_aspect;
Eina_Bool preserve_aspect : 1; //Used in SVG
};
struct _Evas_Vg_Load_Func
{
Vg_File_Data *(*file_data) (const char *file, const char *key, int *error);
Vg_File_Data *(*file_open) (const char *file, const char *key, int *error);
Eina_Bool (*file_close) (Vg_File_Data *vfd);
Eina_Bool (*file_data) (Vg_File_Data *vfd);
};
struct _Evas_Vg_Save_Func
{
int (*vg_save) (Vg_File_Data *vg, const char *file, const char *key, int compress);
int (*file_save) (Vg_File_Data *vfd, const char *file, const char *key, int compress);
};
#ifdef __cplusplus

View File

@ -6,7 +6,7 @@
#include "evas_private.h"
#include "evas_vg_private.h"
static Evas_Cache_Vg* vg_cache = NULL;
static Vg_Cache* vg_cache = NULL;
struct ext_loader_s
{
@ -15,6 +15,13 @@ struct ext_loader_s
const char *loader;
};
struct ext_saver_s
{
unsigned int length;
const char *extension;
const char *saver;
};
#define MATCHING(Ext, Module) { sizeof(Ext)-1, Ext, Module }
static const struct ext_loader_s loaders[] =
@ -31,6 +38,13 @@ static const char *loaders_name[] =
"eet", "svg"
};
static const struct ext_saver_s savers[] =
{ /* map extensions to savers to use for good first-guess tries */
MATCHING(".eet", "eet"),
MATCHING(".edj", "eet"),
MATCHING(".svg", "svg")
};
static Evas_Module *
_find_loader_module(const char *file)
{
@ -61,14 +75,19 @@ _vg_load_from_file(const char *file, const char *key)
Evas_Module *em;
Evas_Vg_Load_Func *loader;
int error = EVAS_LOAD_ERROR_GENERIC;
Vg_File_Data *evg_data = NULL;
Vg_File_Data *vfd;
unsigned int i;
em = _find_loader_module(file);
if (em)
{
loader = em->functions;
evg_data = loader->file_data(file, key, &error);
vfd = loader->file_open(file, key, &error);
if (vfd)
{
vfd->loader = loader;
return vfd;
}
}
else
{
@ -78,34 +97,18 @@ _vg_load_from_file(const char *file, const char *key)
if (em)
{
loader = em->functions;
evg_data = loader->file_data(file, key, &error);
if (evg_data)
return evg_data;
vfd = loader->file_open(file, key, &error);
{
vfd->loader = loader;
return vfd;
}
}
else
DBG("could not find module '%s'", loaders_name[i]);
}
INF("exhausted all means to load image '%s'", file);
}
return evg_data;
WRN("Exhausted all means to load vector file = %s", file);
return NULL;
}
// evg file save
struct ext_saver_s
{
unsigned int length;
const char *extension;
const char *saver;
};
static const struct ext_saver_s savers[] =
{ /* map extensions to savers to use for good first-guess tries */
MATCHING(".eet", "eet"),
MATCHING(".edj", "eet"),
MATCHING(".svg", "svg")
};
static Evas_Module *
_find_saver_module(const char *file)
{
@ -130,8 +133,28 @@ _find_saver_module(const char *file)
return em;
}
static void
_evas_cache_vg_data_free_cb(void *data)
{
Vg_File_Data *val = data;
efl_unref(val->root);
free(val);
}
static void
_evas_cache_vg_entry_free_cb(void *data)
{
Vg_Cache_Entry *vg_entry = data;
eina_stringshare_del(vg_entry->file);
eina_stringshare_del(vg_entry->key);
free(vg_entry->hash_key);
efl_unref(vg_entry->root);
free(vg_entry);
}
Eina_Bool
evas_vg_save_to_file(Vg_File_Data *evg_data, const char *file, const char *key, const char *flags)
evas_vg_save_to_file(Vg_File_Data *vfd, const char *file, const char *key, const char *flags)
{
Evas_Module *em;
Evas_Vg_Save_Func *saver;
@ -162,7 +185,7 @@ evas_vg_save_to_file(Vg_File_Data *evg_data, const char *file, const char *key,
if (em)
{
saver = em->functions;
error = saver->vg_save(evg_data, file, key, compress);
error = saver->file_save(vfd, file, key, compress);
}
if (error)
@ -171,28 +194,6 @@ evas_vg_save_to_file(Vg_File_Data *evg_data, const char *file, const char *key,
return EINA_TRUE;
}
static void
_evas_cache_vg_data_free_cb(void *data)
{
Vg_File_Data *val = data;
efl_unref(val->root);
free(val);
}
static void
_evas_cache_svg_entry_free_cb(void *data)
{
Evas_Cache_Vg_Entry *entry = data;
eina_stringshare_del(entry->file);
eina_stringshare_del(entry->key);
free(entry->hash_key);
efl_unref(entry->root);
free(entry);
}
void
evas_cache_vg_init(void)
{
@ -201,9 +202,15 @@ evas_cache_vg_init(void)
vg_cache->ref++;
return;
}
vg_cache = calloc(1, sizeof(Evas_Cache_Vg));
vg_cache->vg_hash = eina_hash_string_superfast_new(_evas_cache_vg_data_free_cb);
vg_cache->active = eina_hash_string_superfast_new(_evas_cache_svg_entry_free_cb);
vg_cache = calloc(1, sizeof(Vg_Cache));
if (!vg_cache)
{
CRI("Failed to alloc Vg_Cache");
return;
}
vg_cache->vfd_hash = eina_hash_string_superfast_new(_evas_cache_vg_data_free_cb);
vg_cache->vg_entry_hash = eina_hash_string_superfast_new(_evas_cache_vg_entry_free_cb);
vg_cache->ref++;
}
@ -212,9 +219,9 @@ evas_cache_vg_shutdown(void)
{
if (!vg_cache) return;
vg_cache->ref--;
if (vg_cache->ref) return;
eina_hash_free(vg_cache->vg_hash);
eina_hash_free(vg_cache->active);
if (vg_cache->ref > 0) return;
eina_hash_free(vg_cache->vfd_hash);
eina_hash_free(vg_cache->vg_entry_hash);
free(vg_cache);
vg_cache = NULL;
}
@ -222,89 +229,91 @@ evas_cache_vg_shutdown(void)
Vg_File_Data *
evas_cache_vg_file_info(const char *file, const char *key)
{
Vg_File_Data *vd;
Vg_File_Data *vfd;
Eina_Strbuf *hash_key;
hash_key = eina_strbuf_new();
eina_strbuf_append_printf(hash_key, "%s/%s", file, key);
vd = eina_hash_find(vg_cache->vg_hash, eina_strbuf_string_get(hash_key));
if (!vd)
vfd = eina_hash_find(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key));
if (!vfd)
{
vd = _vg_load_from_file(file, key);
//File is exists.
if (vd) eina_hash_add(vg_cache->vg_hash, eina_strbuf_string_get(hash_key), vd);
vfd = _vg_load_from_file(file, key);
//File exists.
if (vfd) eina_hash_add(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vfd);
}
eina_strbuf_free(hash_key);
return vd;
return vfd;
}
static void
_apply_transformation(Efl_VG *root, double w, double h, Vg_File_Data *vg_data)
_local_transformation(Efl_VG *root, double w, double h, Vg_File_Data *vfd)
{
double sx = 0, sy= 0, scale;
Eina_Matrix3 m;
if (vg_data->view_box.w)
sx = w/vg_data->view_box.w;
if (vg_data->view_box.h)
sy = h/vg_data->view_box.h;
if (vfd->view_box.w)
sx = w/vfd->view_box.w;
if (vfd->view_box.h)
sy = h/vfd->view_box.h;
scale = sx < sy ? sx: sy;
eina_matrix3_identity(&m);
// allign hcenter and vcenter
if (vg_data->preserve_aspect)
if (vfd->preserve_aspect)
{
eina_matrix3_translate(&m, (w - vg_data->view_box.w * scale)/2.0, (h - vg_data->view_box.h * scale)/2.0);
eina_matrix3_translate(&m, (w - vfd->view_box.w * scale)/2.0, (h - vfd->view_box.h * scale)/2.0);
eina_matrix3_scale(&m, scale, scale);
eina_matrix3_translate(&m, -vg_data->view_box.x, -vg_data->view_box.y);
eina_matrix3_translate(&m, -vfd->view_box.x, -vfd->view_box.y);
}
else
{
eina_matrix3_scale(&m, sx, sy);
eina_matrix3_translate(&m, -vg_data->view_box.x, -vg_data->view_box.y);
eina_matrix3_translate(&m, -vfd->view_box.x, -vfd->view_box.y);
}
efl_canvas_vg_node_transformation_set(root, &m);
}
static Efl_VG *
_evas_vg_dup_vg_tree(Vg_File_Data *fd, double w, double h)
_evas_vg_dup_vg_tree(Vg_File_Data *vfd, double w, double h)
{
Efl_VG *root;
if (!fd) return NULL;
if (!vfd) return NULL;
if (w < 1 || h < 1) return NULL;
root = efl_duplicate(fd->root);
_apply_transformation(root, w, h, fd);
root = efl_duplicate(vfd->root);
_local_transformation(root, w, h, vfd);
return root;
}
static void
_evas_cache_svg_vg_tree_update(Evas_Cache_Vg_Entry *entry)
_evas_cache_vg_tree_update(Vg_Cache_Entry *vg_entry)
{
Vg_File_Data *src_vg = NULL;
if(!entry) return;
Vg_File_Data *vfd = NULL;
if(!vg_entry) return;
if (!entry->file)
if (!vg_entry->file)
{
entry->root = NULL;
vg_entry->root = NULL;
return;
}
src_vg = evas_cache_vg_file_info(entry->file, entry->key);
vfd = evas_cache_vg_file_info(vg_entry->file, vg_entry->key);
entry->root = _evas_vg_dup_vg_tree(src_vg, entry->w, entry->h);
eina_stringshare_del(entry->file);
eina_stringshare_del(entry->key);
entry->file = NULL;
entry->key = NULL;
vg_entry->root = _evas_vg_dup_vg_tree(vfd, vg_entry->w, vg_entry->h);
eina_stringshare_del(vg_entry->file);
eina_stringshare_del(vg_entry->key);
vg_entry->file = NULL;
vg_entry->key = NULL;
}
Evas_Cache_Vg_Entry*
Vg_Cache_Entry*
evas_cache_vg_entry_find(const char *file, const char *key,
int w, int h)
{
Evas_Cache_Vg_Entry* se;
Vg_Cache_Entry* vg_entry;
Eina_Strbuf *hash_key;
if (!vg_cache) return NULL;
@ -312,45 +321,45 @@ evas_cache_vg_entry_find(const char *file, const char *key,
hash_key = eina_strbuf_new();
eina_strbuf_append_printf(hash_key, "%s/%s/%d/%d",
file, key, w, h);
se = eina_hash_find(vg_cache->active, eina_strbuf_string_get(hash_key));
if (!se)
vg_entry = eina_hash_find(vg_cache->vg_entry_hash, eina_strbuf_string_get(hash_key));
if (!vg_entry)
{
se = calloc(1, sizeof(Evas_Cache_Vg_Entry));
if (!se)
vg_entry = calloc(1, sizeof(Vg_Cache_Entry));
if (!vg_entry)
{
CRI("Failed to alloc Vg_Cache_Entry");
eina_strbuf_free(hash_key);
return NULL;
}
se->file = eina_stringshare_add(file);
se->key = eina_stringshare_add(key);
se->w = w;
se->h = h;
se->hash_key = eina_strbuf_string_steal(hash_key);
eina_hash_direct_add(vg_cache->active, se->hash_key, se);
vg_entry->file = eina_stringshare_add(file);
vg_entry->key = eina_stringshare_add(key);
vg_entry->w = w;
vg_entry->h = h;
vg_entry->hash_key = eina_strbuf_string_steal(hash_key);
eina_hash_direct_add(vg_cache->vg_entry_hash, vg_entry->hash_key, vg_entry);
}
eina_strbuf_free(hash_key);
se->ref++;
return se;
vg_entry->ref++;
return vg_entry;
}
Efl_VG*
evas_cache_vg_tree_get(Evas_Cache_Vg_Entry *entry)
evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry)
{
if (entry->root) return entry->root;
if (vg_entry->root) return vg_entry->root;
if (entry->file)
_evas_cache_svg_vg_tree_update(entry);
if (vg_entry->file)
_evas_cache_vg_tree_update(vg_entry);
return entry->root;
return vg_entry->root;
}
void
evas_cache_vg_entry_del(Evas_Cache_Vg_Entry *svg_entry)
evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry)
{
if (!svg_entry) return;
if (!vg_entry) return;
svg_entry->ref--;
vg_entry->ref--;
// FIXME implement delete logic (LRU)
}

View File

@ -13,7 +13,7 @@ static int _evas_vg_loader_eet_log_dom = -1;
#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_eet_log_dom, __VA_ARGS__)
static Vg_File_Data*
evas_vg_load_file_data_eet(const char *file, const char *key, int *error EINA_UNUSED)
evas_vg_load_file_open_eet(const char *file, const char *key, int *error EINA_UNUSED)
{
Eet_Data_Descriptor *svg_node_eet;
Svg_Node *node;
@ -44,7 +44,7 @@ evas_vg_load_file_data_eet(const char *file, const char *key, int *error EINA_UN
static Evas_Vg_Load_Func evas_vg_load_eet_func =
{
evas_vg_load_file_data_eet
evas_vg_load_file_open_eet
};
static int
@ -87,4 +87,4 @@ EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_VG_LOADER, vg_loader, eet);
#ifndef EVAS_STATIC_BUILD_VG_EET
EVAS_EINA_MODULE_DEFINE(vg_loader, eet);
#endif
#endif

View File

@ -2327,7 +2327,7 @@ _update_gradient(Svg_Node *node, Eina_List *grad_list)
}
static Vg_File_Data*
evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *error EINA_UNUSED)
evas_vg_load_file_open_svg(const char *file, const char *key EINA_UNUSED, int *error EINA_UNUSED)
{
Evas_SVG_Loader loader = {
NULL, NULL, NULL, NULL, NULL, 0, EINA_FALSE
@ -2377,7 +2377,7 @@ evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *e
static Evas_Vg_Load_Func evas_vg_load_svg_func =
{
evas_vg_load_file_data_svg
evas_vg_load_file_open_svg
};
static int