Edje & evas filters: Properly pass data from EDC to Lua

Also fix a few issues
This commit is contained in:
Jean-Philippe Andre 2015-06-23 12:21:20 +09:00
parent 0df37da435
commit 15afea293f
5 changed files with 95 additions and 82 deletions

View File

@ -2443,22 +2443,16 @@ _edje_part_recalc_single_filter(Edje *ed,
Edje_Part_Description_Text *chosen_edt = (Edje_Part_Description_Text *) chosen_desc;
Edje_Part_Description_Text *edt = (Edje_Part_Description_Text *) desc;
filter = &chosen_edt->text.filter;
if (edt->text.filter.sources != filter->sources)
{
prev_sources = ep->typedata.text->filter.sources;
filter_sources = edt->text.filter.sources;
}
prev_sources = edt->text.filter.sources;
filter_sources = chosen_edt->text.filter.sources;
}
else if (ep->part->type == EDJE_PART_TYPE_IMAGE)
{
Edje_Part_Description_Image *chosen_edi = (Edje_Part_Description_Image *) chosen_desc;
Edje_Part_Description_Image *edi = (Edje_Part_Description_Image *) desc;
filter = &chosen_edi->image.filter;
if (edi->image.filter.sources != filter->sources)
{
prev_sources = edi->image.filter.sources;
filter_sources = chosen_edi->image.filter.sources;
}
prev_sources = edi->image.filter.sources;
filter_sources = chosen_edi->image.filter.sources;
}
else
{
@ -2474,7 +2468,75 @@ _edje_part_recalc_single_filter(Edje *ed,
return;
}
if (!filter->sources_set)
{
filter->sources_set = 1;
prev_sources = NULL;
}
eo_do(obj,
/* pass extra data items */
if (filter->data)
{
Eina_Iterator *it = eina_hash_iterator_tuple_new(filter->data);
Eina_Hash_Tuple *tup;
EINA_ITERATOR_FOREACH(it, tup)
{
const char *name = tup->key;
char *value = tup->data;
if (!value)
{
efl_gfx_filter_data_set(name, NULL);
}
else if (!strncmp(value, "color_class('", sizeof("color_class('") - 1))
{
/* special handling for color classes even tho they're not that great */
char *ccname, *buffer, *r;
Edje_Color_Class *cc;
ccname = strdup(value + sizeof("color_class('") - 1);
if (ccname)
{
r = strchr(ccname, '\'');
if (r)
{
*r = '\0';
cc = _edje_color_class_find(ed, ccname);
if (cc)
{
static const char fmt[] = "--\n"
"%s={r=%d,g=%d,b=%d,a=%d,"
"r2=%d,g2=%d,b2=%d,a2=%d,"
"r3=%d,g3=%d,b3=%d,a3=%d}";
int len = sizeof(fmt) + 20;
len += strlen(name);
buffer = alloca(len);
snprintf(buffer, len - 1, fmt, name,
(int) cc->r, (int) cc->g, (int) cc->b, (int) cc->a,
(int) cc->r2, (int) cc->g2, (int) cc->b2, (int) cc->a2,
(int) cc->r3, (int) cc->g3, (int) cc->b3, (int) cc->a3);
buffer[len - 1] = 0;
efl_gfx_filter_data_set(name, buffer);
}
else
{
ERR("Unknown color class: %s", ccname);
eina_hash_del(filter->data, tup->key, tup->data);
}
}
else
{
ERR("Failed to parse color class: %s", value);
eina_hash_del(filter->data, tup->key, tup->data);
}
free(ccname);
}
}
else
efl_gfx_filter_data_set(name, value);
}
eina_iterator_free(it);
}
efl_gfx_filter_program_set(code, filter->name);
if (prev_sources != filter_sources)
{
@ -2535,67 +2597,6 @@ _edje_part_recalc_single_filter(Edje *ed,
efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value,
NULL, 0.0, pos);
}
/* pass extra data items */
if (filter->data)
{
Eina_Iterator *it = eina_hash_iterator_tuple_new(filter->data);
Eina_Hash_Tuple *tup;
EINA_ITERATOR_FOREACH(it, tup)
{
const char *name = tup->key;
char *value = tup->data;
if (!value)
{
efl_gfx_filter_data_set(name, NULL);
}
else if (!strncmp(value, "color_class('", sizeof("color_class('") - 1))
{
/* special handling for color classes even tho they're not that great */
char *ccname, *buffer, *r;
Edje_Color_Class *cc;
ccname = strdup(value + sizeof("color_class('") - 1);
if (ccname)
{
r = strchr(ccname, '\'');
if (r)
{
*r = '\0';
cc = _edje_color_class_find(ed, ccname);
if (cc)
{
static const char *fmt =
"%s={r=%d,g=%d,b=%d,a=%d,"
"r2=%d,g2=%d,b2=%d,a2=%d,"
"r3=%d,g3=%d,b3=%d,a3=%d}";
int len = sizeof(fmt);
len += strlen(ccname);
buffer = alloca(len);
snprintf(buffer, len - 1, fmt, ccname,
cc->r, cc->g, cc->b, cc->a,
cc->r2, cc->g2, cc->b2, cc->a2,
cc->r3, cc->g3, cc->b3, cc->a3);
efl_gfx_filter_data_set(name, buffer);
}
else
{
ERR("Unknown color class: %s", ccname);
eina_hash_del(filter->data, tup->key, tup->data);
}
}
else
{
ERR("Failed to parse color class: %s", value);
eina_hash_del(filter->data, tup->key, tup->data);
}
free(ccname);
}
}
else
efl_gfx_filter_data_set(name, value);
}
eina_iterator_free(it);
}
);
}

View File

@ -1285,6 +1285,7 @@ struct _Edje_Part_Description_Spec_Filter
Eina_List *sources; /* "part" or "buffer:part" */
Eina_Hash *data; /* "name" --> "data" */
Eina_Bool checked_data : 1; // checked whether this is a data item or embedded string
Eina_Bool sources_set : 1;
Eina_Bool no_free : 1;
};

View File

@ -65,6 +65,7 @@ mixin Evas.Filter (Efl.Gfx.Filter)
Efl.Gfx.Filter.padding.get;
Efl.Gfx.Filter.source_set;
Efl.Gfx.Filter.source_get;
Efl.Gfx.Filter.data_set;
@virtual .input_alpha;
@virtual .input_render;
@virtual .dirty;

View File

@ -520,7 +520,7 @@ _evas_filter_efl_gfx_filter_data_set(Eo *obj EINA_UNUSED, Evas_Filter_Data *pd,
return;
}
EINA_COW_WRITE_BEGIN(evas_object_filter_cow, fcow, Evas_Object_Filter_Data, fcow)
EINA_COW_WRITE_BEGIN(evas_object_filter_cow, pd->data, Evas_Object_Filter_Data, fcow)
{
if (!fcow->data)
fcow->data = eina_hash_string_small_new(free);
@ -529,7 +529,7 @@ _evas_filter_efl_gfx_filter_data_set(Eo *obj EINA_UNUSED, Evas_Filter_Data *pd,
evas_filter_program_data_set_all(fcow->chain, fcow->data);
fcow->changed = 1;
}
EINA_COW_WRITE_END(evas_object_filter_cow, fcow, fcow);
EINA_COW_WRITE_END(evas_object_filter_cow, pd->data, fcow);
}
#include "evas_filter.eo.c"

View File

@ -2570,7 +2570,7 @@ _legacy_strdup(const char *str)
}
#endif
static void
static Eina_Bool
_filter_program_state_set(Evas_Filter_Program *pgm)
{
lua_State *L = pgm->L;
@ -2646,8 +2646,12 @@ _filter_program_state_set(Evas_Filter_Program *pgm)
{
if ((value[0] == '-') && (value[1] == '-') && value[2] == '\n')
{
int i = luaL_dostring(L, value);
ERR("i %d", i);
if (luaL_dostring(L, value) != 0)
{
eina_iterator_free(it);
ERR("Failed to run value: %s", lua_tostring(L, -1));
return EINA_FALSE;
}
}
else
{
@ -2658,17 +2662,20 @@ _filter_program_state_set(Evas_Filter_Program *pgm)
else
{
lua_pushnil(L);
lua_setglobal(L, name);
}
}
eina_iterator_free(it);
}
return EINA_TRUE;
#undef JOINC
#undef SETFIELD
#undef SETCOLOR
}
static void
static Eina_Bool
_filter_program_reset(Evas_Filter_Program *pgm)
{
Evas_Filter_Instruction *instr;
@ -2696,7 +2703,7 @@ _filter_program_reset(Evas_Filter_Program *pgm)
_filter_program_buffers_set(pgm);
// Reset state table
_filter_program_state_set(pgm);
return _filter_program_state_set(pgm);
}
/** Parse a style program */
@ -2733,10 +2740,13 @@ evas_filter_program_parse(Evas_Filter_Program *pgm, const char *str)
if (ok)
{
pgm->lua_func = luaL_ref(L, LUA_REGISTRYINDEX);
_filter_program_reset(pgm);
lua_getglobal(L, _lua_errfunc_name);
lua_rawgeti(L, LUA_REGISTRYINDEX, pgm->lua_func);
ok = !lua_pcall(L, 0, LUA_MULTRET, -2);
ok =_filter_program_reset(pgm);
if (ok)
{
lua_getglobal(L, _lua_errfunc_name);
lua_rawgeti(L, LUA_REGISTRYINDEX, pgm->lua_func);
ok = !lua_pcall(L, 0, LUA_MULTRET, -2);
}
}
if (!ok)