Evas filters: Add Eo APIs and some comments

The entry points on evas text are there!
This commit is contained in:
Jean-Philippe Andre 2013-12-09 20:55:38 +09:00
parent 98f745d140
commit 0450e027e7
2 changed files with 205 additions and 12 deletions

View File

@ -1846,6 +1846,8 @@ enum
EVAS_OBJ_TEXT_SUB_ID_STYLE_PAD_GET,
EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_SET,
EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_GET,
EVAS_OBJ_TEXT_SUB_ID_FILTER_PROGRAM_SET,
EVAS_OBJ_TEXT_SUB_ID_FILTER_OBJECT_BIND,
EVAS_OBJ_TEXT_SUB_ID_LAST
};
@ -2271,6 +2273,20 @@ enum
*/
#define evas_obj_text_ellipsis_get(ellipsis) EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_GET), EO_TYPECHECK(double *, ellipsis)
/**
* @def evas_obj_text_filter_program_set
* @since 1.9
* @note EXPERIMENTAL code
*/
#define evas_obj_text_filter_program_set(str) EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_FILTER_PROGRAM_SET), EO_TYPECHECK(const char *, str)
/**
* @def evas_obj_text_filter_object_bind
* @since 1.9
* @note EXPERIMENTAL code
*/
#define evas_obj_text_filter_object_bind(str, prxy) EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_FILTER_OBJECT_BIND), EO_TYPECHECK(const char *, str), EO_TYPECHECK(Eo *, prxy)
/**
* @}
*/

View File

@ -1,5 +1,6 @@
#include "evas_common_private.h" /* Includes evas_bidi_utils stuff. */
#include "evas_private.h"
#include "evas_filter.h"
#include "Eo.h"
@ -38,7 +39,10 @@ struct _Evas_Object_Text
double ellipsis;
Evas_Font_Size size;
unsigned char style;
Evas_Text_Style_Type style;
// special effects. VERY EXPERIMENTAL for now.
Evas_Filter_Program *special_effect;
} cur, prev;
struct {
@ -786,7 +790,10 @@ _evas_object_text_layout(Evas_Object *eo_obj, Evas_Object_Text *o, Eina_Unicode
}
}
evas_text_style_pad_get(o->cur.style, &l, &r, NULL, NULL);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &l, &r, NULL, NULL);
else
evas_filter_program_padding_get(o->cur.special_effect, &l, &r, NULL, NULL);
/* Handle ellipsis */
if (pos && (o->cur.ellipsis >= 0.0) && (advance + l + r > obj->cur->geometry.w) && (obj->cur->geometry.w > 0))
@ -1335,7 +1342,10 @@ _text_char_pos_get(Eo *eo_obj, void *_pd, va_list *list)
Eina_Bool int_ret = _evas_object_text_char_coords_get(eo_obj, o, (size_t) pos,
&x, &y, &w, &h);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
else
evas_filter_program_padding_get(o->cur.special_effect, &l, &r, &t, &b);
y += o->max_ascent - t;
x -= l;
if (x < 0)
@ -1419,7 +1429,10 @@ _text_char_coords_get(Eo *eo_obj, void *_pd, va_list *list)
int int_ret = _evas_object_text_char_at_coords(eo_obj, o, x, y - o->max_ascent,
&rx, &ry, &rw, &rh);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
else
evas_filter_program_padding_get(o->cur.special_effect, &l, &r, &t, &b);
ry += o->max_ascent - t;
rx -= l;
if (rx < 0)
@ -1741,7 +1754,10 @@ _text_style_pad_get(Eo *eo_obj EINA_UNUSED, void *_pd, va_list *list)
int sl = 0, sr = 0, st = 0, sb = 0;
const Evas_Object_Text *o = _pd;
/* use temps to be certain we have initialized values */
evas_text_style_pad_get(o->cur.style, &sl, &sr, &st, &sb);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &sl, &sr, &st, &sb);
else
evas_filter_program_padding_get(o->cur.special_effect, &sl, &sr, &st, &sb);
if (l) *l = sl;
if (r) *r = sr;
if (t) *t = st;
@ -1984,7 +2000,8 @@ static void
evas_object_text_render(Evas_Object *eo_obj EINA_UNUSED,
Evas_Object_Protected_Data *obj,
void *type_private_data,
void *output, void *context, void *surface, int x, int y, Eina_Bool do_async)
void *output, void *context, void *surface,
int x, int y, Eina_Bool do_async)
{
int i, j;
Evas_Object_Text *o = type_private_data;
@ -1998,10 +2015,13 @@ evas_object_text_render(Evas_Object *eo_obj EINA_UNUSED,
{0, 1, 2, 1, 0}
};
int sl = 0, st = 0;
int shad_dst, shad_sz, dx, dy, haveshad;
int shad_dst = 0, shad_sz = 0, dx = 0, dy = 0, haveshad = 0;
/* render object to surface with context, and offxet by x,y */
evas_text_style_pad_get(o->cur.style, &sl, NULL, &st, NULL);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &sl, NULL, &st, NULL);
else
evas_filter_program_padding_get(o->cur.special_effect, &sl, NULL, &st, NULL);
ENFN->context_multiplier_unset(output, context);
ENFN->context_render_op_set(output, context, obj->cur->render_op);
/* FIXME: This clipping is just until we fix inset handling correctly. */
@ -2010,6 +2030,7 @@ evas_object_text_render(Evas_Object *eo_obj EINA_UNUSED,
obj->cur->geometry.y + y,
obj->cur->geometry.w,
obj->cur->geometry.h);
/*
ENFN->context_color_set(output,
context,
@ -2077,8 +2098,90 @@ evas_object_text_render(Evas_Object *eo_obj EINA_UNUSED,
&it->text_props, \
do_async);
/* FIXME/WARNING
* The code below is EXPERIMENTAL, and not to be considered usable or even
* remotely similar to its final form. You've been warned :)
*/
if (o->cur.special_effect)
{
int X, Y, W, H;
Evas_Filter_Context *filter;
int inbuf = 1;
int outbuf = 2;
int targetbuf;
RGBA_Image *input;
void *filter_ctx;
Eina_Bool ok;
filter = evas_filter_context_new(obj->layer->evas);
ok = evas_filter_context_program_use(filter, eo_obj, o->cur.special_effect);
if (!filter || !ok)
{
ERR("Parsing failed?");
evas_filter_context_destroy(filter);
goto normal_render;
}
// Proxies
evas_filter_context_proxy_render_all(filter, eo_obj, EINA_FALSE);
targetbuf = evas_filter_buffer_image_new(filter, surface);
W = obj->cur->geometry.w;
H = obj->cur->geometry.h;
X = obj->cur->geometry.x;
Y = obj->cur->geometry.y;
filter_ctx = ENFN->context_new(ENDT);
ENFN->context_color_set(ENDT, filter_ctx, 255, 255, 255, 255);
// Alloc input now
evas_filter_buffer_data_set(filter, inbuf, NULL, W, H, EINA_TRUE);
input = evas_filter_buffer_backing_get(filter, inbuf);
// Render text to input buffer
{
int ox, oy;
ox = 0;
oy = 0;
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
if ((o->font) && (it->text_props.len > 0))
{
evas_font_draw_async_check(obj, output,
filter_ctx,
input,
o->font,
sl + ox + it->x,
st + oy + (int) o->max_ascent,
W, H,
W, H,
&it->text_props,
do_async);
}
}
// FIXME: This final blend is not necessary. Needs to be removed.
evas_filter_command_blend_add(filter, filter_ctx, outbuf, targetbuf,
X + x, Y + y);
ENFN->context_free(ENDT, filter_ctx);
// Add post-run callback and run filter
evas_filter_context_autodestroy(filter);
evas_filter_run(filter, do_async);
INF("Effect rendering done. Return.");
return;
}
/* End of the EXPERIMENTAL code */
normal_render:
/* shadows */
shad_dst = shad_sz = dx = dy = haveshad = 0;
switch (o->cur.style & EVAS_TEXT_STYLE_MASK_BASIC)
{
case EVAS_TEXT_STYLE_SHADOW:
@ -2490,7 +2593,10 @@ _evas_object_text_recalc(Evas_Object *eo_obj, Eina_Unicode *text)
w = _evas_object_text_horiz_advance_get(o);
h = _evas_object_text_vert_advance_get(eo_obj, o);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
else
evas_filter_program_padding_get(o->cur.special_effect, &l, &r, &t, &b);
if (o->cur.ellipsis >= 0.0)
{
@ -2509,9 +2615,12 @@ _evas_object_text_recalc(Evas_Object *eo_obj, Eina_Unicode *text)
}
else
{
int t = 0, b = 0;
int t = 0, b = 0, l = 0, r = 0;
evas_text_style_pad_get(o->cur.style, NULL, NULL, &t, &b);
if (!o->cur.special_effect)
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
else
evas_filter_program_padding_get(o->cur.special_effect, &l, &r, &t, &b);
eo_do_super(eo_obj, MY_CLASS,
evas_obj_size_set(0, o->max_ascent + o->max_descent + t + b));
@ -2521,6 +2630,70 @@ _evas_object_text_recalc(Evas_Object *eo_obj, Eina_Unicode *text)
o->last_computed.h = obj->cur->geometry.h;
}
/* EXPERIMENTAL CODE BEGIN */
static void
_filter_program_set(Eo *eo_obj, void *_pd, va_list *list)
{
Evas_Object_Text *o = _pd;
const char *arg = va_arg(list, const char *);
Evas_Object_Protected_Data *obj;
Evas_Filter_Program *pgm = NULL;
if (!o) return;
// Parse filter program
evas_filter_program_del(o->cur.special_effect);
if (arg)
{
pgm = evas_filter_program_new("Evas_Text: Filter Program");
if (!evas_filter_program_parse(pgm, arg))
{
ERR("Parsing failed!");
evas_filter_program_del(pgm);
pgm = NULL;
}
}
o->cur.special_effect = pgm;
// Update object
obj = eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
_evas_object_text_items_clear(o);
o->changed = 1;
_evas_object_text_recalc(eo_obj, o->cur.text);
evas_object_change(eo_obj, obj);
evas_object_clip_dirty(eo_obj, obj);
evas_object_coords_recalc(eo_obj, obj);
evas_object_inform_call_resize(eo_obj);
}
static void
_filter_object_bind(Eo *eo_obj, void *_pd, va_list *list)
{
Evas_Object_Text *o = _pd;
Evas_Object_Protected_Data *obj;
Evas_Filter_Program *pgm = NULL;
const char *name = va_arg(list, const char *);
Evas_Object *proxy = va_arg(list, Evas_Object *);
pgm = o->cur.special_effect;
if (!pgm) return;
evas_filter_program_proxy_source_bind(pgm, name, proxy);
// Update object
obj = eo_data_scope_get(eo_obj, EVAS_OBJ_CLASS);
_evas_object_text_items_clear(o);
o->changed = 1;
_evas_object_text_recalc(eo_obj, o->cur.text);
evas_object_change(eo_obj, obj);
evas_object_clip_dirty(eo_obj, obj);
evas_object_coords_recalc(eo_obj, obj);
evas_object_inform_call_resize(eo_obj);
}
/* EXPERIMENTAL CODE END */
static void
_class_constructor(Eo_Class *klass)
{
@ -2561,6 +2734,8 @@ _class_constructor(Eo_Class *klass)
EO_OP_FUNC(EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_STYLE_PAD_GET), _text_style_pad_get),
EO_OP_FUNC(EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_SET), _text_ellipsis_set),
EO_OP_FUNC(EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_GET), _text_ellipsis_get),
EO_OP_FUNC(EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_FILTER_PROGRAM_SET), _filter_program_set),
EO_OP_FUNC(EVAS_OBJ_TEXT_ID(EVAS_OBJ_TEXT_SUB_ID_FILTER_OBJECT_BIND), _filter_object_bind),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
@ -2598,6 +2773,8 @@ static const Eo_Op_Description op_desc[] = {
EO_OP_DESCRIPTION(EVAS_OBJ_TEXT_SUB_ID_STYLE_PAD_GET, "Gets the text style pad of a text object."),
EO_OP_DESCRIPTION(EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_SET, "Gets the ellipsis of a text object."),
EO_OP_DESCRIPTION(EVAS_OBJ_TEXT_SUB_ID_ELLIPSIS_GET, "Sets the ellipsis of a text object."),
EO_OP_DESCRIPTION(EVAS_OBJ_TEXT_SUB_ID_FILTER_PROGRAM_SET, "Text special effects: Set the style program (string)."),
EO_OP_DESCRIPTION(EVAS_OBJ_TEXT_SUB_ID_FILTER_OBJECT_BIND, "Text special effects: Bind an Evas_Object to a name for proxy rendering."),
EO_OP_DESCRIPTION_SENTINEL
};
static const Eo_Class_Description class_desc = {