evas: Fix async filters following changes in EO

EO is now extremely restrictive wrt. threads so that efl_data_scope_get()
can't work outside the main loop. This patch fixes the usage to create
sw buffers as shared objects (accessible from both the main loop and evas
async thread) and use plain old pointers where possible.

The buffers now have no parent because efl_add(CLASS, obj_from_mainloop)
does not work with shared objects. This is bad, as the buffers conceptually
belong to the main loop, and only need to be accessible from the draw thread
for a few calls. The main loop determines their lifecycle.

Fixes T4628
This commit is contained in:
Jean-Philippe Andre 2016-10-06 12:09:53 +09:00
parent 258cfbbe80
commit 0f7dfdedfd
3 changed files with 36 additions and 24 deletions

View File

@ -20,6 +20,7 @@ typedef struct _Evas_Filter_Post_Render_Data Evas_Filter_Post_Render_Data;
struct _Evas_Filter_Data
{
const Evas_Object_Filter_Data *data;
Evas_Object_Protected_Data *obj;
Eina_Bool has_cb;
SLK(lck);
Eina_List *post_data;
@ -75,9 +76,8 @@ _filter_end_sync(Evas_Filter_Context *ctx, Evas_Object_Protected_Data *obj,
static void
_render_post_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
Eo *eo_obj = data;
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Filter_Data *pd = efl_data_scope_get(eo_obj, MY_CLASS);
Evas_Filter_Data *pd = data;
Evas_Object_Protected_Data *obj = pd->obj;
Eina_List *post_data;
Evas_Filter_Post_Render_Data *task;
@ -96,16 +96,14 @@ _render_post_cb(void *data, const Efl_Event *event EINA_UNUSED)
static void
_filter_cb(Evas_Filter_Context *ctx, void *data, Eina_Bool success)
{
Eo *eo_obj = data;
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Filter_Data *pd = efl_data_scope_get(eo_obj, MY_CLASS);
Evas_Filter_Post_Render_Data *post_data;
Evas_Filter_Data *pd = data;
if (!pd)
return;
if (!pd->data->async)
{
_filter_end_sync(ctx, obj, pd, success);
_filter_end_sync(ctx, pd->obj, pd, success);
return;
}
@ -267,7 +265,7 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
{
// Post render callback is not required anymore
Evas *e = obj->layer->evas->evas;
efl_event_callback_del(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, eo_obj);
efl_event_callback_del(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, pd);
pd->has_cb = EINA_FALSE;
}
@ -327,10 +325,10 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
if (do_async && !pd->has_cb)
{
Evas *e = obj->layer->evas->evas;
efl_event_callback_add(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, eo_obj);
efl_event_callback_add(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, pd);
pd->has_cb = EINA_TRUE;
}
evas_filter_context_post_run_callback_set(filter, _filter_cb, eo_obj);
evas_filter_context_post_run_callback_set(filter, _filter_cb, pd);
ok = evas_filter_run(filter);
fcow = FCOW_BEGIN(pd);
@ -357,7 +355,7 @@ EOLIAN static void
_efl_canvas_filter_internal_efl_gfx_filter_filter_program_set(Eo *eo_obj, Evas_Filter_Data *pd,
const char *code, const char *name)
{
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Object_Protected_Data *obj = pd->obj;
Evas_Filter_Program *pgm = NULL;
Evas_Object_Filter_Data *fcow;
Eina_Bool alpha;
@ -410,7 +408,7 @@ EOLIAN static void
_efl_canvas_filter_internal_efl_gfx_filter_filter_source_set(Eo *eo_obj, Evas_Filter_Data *pd,
const char *name, Efl_Gfx *eo_source)
{
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Object_Protected_Data *obj = pd->obj;
Evas_Filter_Proxy_Binding *pb, *pb_old = NULL;
Evas_Object_Protected_Data *source = NULL;
Evas_Object_Filter_Data *fcow = NULL;
@ -504,7 +502,7 @@ _efl_canvas_filter_internal_efl_gfx_filter_filter_state_set(Eo *eo_obj, Evas_Fil
const char *next_state, double next_val,
double pos)
{
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Object_Protected_Data *obj = pd->obj;
evas_object_async_block(obj);
if ((cur_state != pd->data->state.cur.name) || (cur_val != pd->data->state.cur.value) ||
@ -589,6 +587,7 @@ _efl_canvas_filter_internal_efl_object_constructor(Eo *eo_obj, Evas_Filter_Data
obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
pd->data = eina_cow_alloc(evas_object_filter_cow);
pd->obj = efl_data_ref(eo_obj, EFL_CANVAS_OBJECT_CLASS);
SLKI(pd->lck);
return obj;
@ -597,7 +596,7 @@ _efl_canvas_filter_internal_efl_object_constructor(Eo *eo_obj, Evas_Filter_Data
EOLIAN static void
_efl_canvas_filter_internal_efl_object_destructor(Eo *eo_obj, Evas_Filter_Data *pd)
{
Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
Evas_Object_Protected_Data *obj = pd->obj;
Evas_Filter_Data_Binding *db;
Eina_Inlist *il;
@ -628,9 +627,10 @@ finish:
if (pd->has_cb)
{
Evas *e = obj->layer->evas->evas;
efl_event_callback_del(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, eo_obj);
efl_event_callback_del(e, EFL_CANVAS_EVENT_RENDER_POST, _render_post_cb, pd);
}
SLKD(pd->lck);
efl_data_unref(eo_obj, pd->obj);
efl_destructor(efl_super(eo_obj, MY_CLASS));
}

View File

@ -13,7 +13,7 @@
typedef struct {
Ector_Software_Buffer_Base_Data *base;
Evas *evas;
Evas_Public_Data *evas;
RGBA_Image *image;
} Evas_Ector_Software_Buffer_Data;
@ -39,7 +39,7 @@ _evas_ector_software_buffer_evas_ector_buffer_engine_image_set(Eo *obj, Evas_Ect
return;
}
pd->evas = efl_xref(evas, obj);
pd->evas = efl_data_xref(evas, EVAS_CANVAS_CLASS, obj);
evas_cache_image_ref(&im->cache_entry);
pd->image = im;
@ -51,10 +51,15 @@ _evas_ector_software_buffer_evas_ector_buffer_engine_image_get(Eo *obj EINA_UNUS
Evas_Ector_Software_Buffer_Data *pd,
Evas **evas, void **image)
{
Evas_Public_Data *e = efl_data_scope_get(pd->evas, EVAS_CANVAS_CLASS);
if (evas) *evas = pd->evas;
if (e->engine.func->gl_surface_read_pixels)
if (!pd->evas)
{
INF("evas_ector_buffer_engine_image_set was not called on this image");
if (evas) *evas = NULL;
if (image) *image = NULL;
return;
}
if (evas) *evas = pd->evas->evas;
if (pd->evas->engine.func->gl_surface_read_pixels)
{
ERR("Invalid: requesting engine_image from a GL image from a simple SW buffer!");
if (image) *image = NULL;
@ -86,7 +91,8 @@ _evas_ector_software_buffer_efl_object_destructor(Eo *obj, Evas_Ector_Software_B
{
efl_data_xunref(obj, pd->base, obj);
evas_cache_image_drop(&pd->image->cache_entry);
efl_xunref(pd->evas, obj);
if (pd->evas)
efl_data_xunref(pd->evas->evas, pd->evas, obj);
efl_destructor(efl_super(obj, MY_CLASS));
}

View File

@ -4283,7 +4283,10 @@ eng_ector_buffer_wrap(void *data EINA_UNUSED, Evas *e, void *engine_image, Eina_
if (!ie) return NULL;
buf = efl_add(EVAS_ECTOR_SOFTWARE_BUFFER_CLASS, e, evas_ector_buffer_engine_image_set(efl_added, e, ie));
if (!efl_domain_current_push(EFL_ID_DOMAIN_SHARED))
return NULL;
buf = efl_add(EVAS_ECTOR_SOFTWARE_BUFFER_CLASS, NULL, evas_ector_buffer_engine_image_set(efl_added, e, ie));
efl_domain_current_pop();
return buf;
}
@ -4302,7 +4305,10 @@ eng_ector_buffer_new(void *data EINA_UNUSED, Evas *evas, void *pixels,
if ((flags & (ECTOR_BUFFER_FLAG_RENDERABLE | ECTOR_BUFFER_FLAG_DRAWABLE)) == 0)
{
buf = efl_add(ECTOR_SOFTWARE_BUFFER_CLASS, evas, ector_buffer_pixels_set(efl_added, pixels, width, height, stride, cspace, writeable, l, r, t, b));
if (!efl_domain_current_push(EFL_ID_DOMAIN_SHARED))
return NULL;
buf = efl_add(ECTOR_SOFTWARE_BUFFER_CLASS, NULL, ector_buffer_pixels_set(efl_added, pixels, width, height, stride, cspace, writeable, l, r, t, b));
efl_domain_current_pop();
}
else
{