From 8356d12e6af269e2d23eac580c355645a63f324d Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Tue, 5 Jan 2021 13:25:38 +0100 Subject: [PATCH] Gradient update fix Gradient didnt update after setting new parameters (like new color stops, center point or radius). This fix solves the problem. Could be tested with evas-vg-gradient-manipulation.c example. Shape was added into Efl_Canvas_Vg_Gradient_Data for efl_canvas_vg_node_change() calling. gd->gradient_render_pre_tvg() is now called in renderer loop. Fixed for svg-gradient. Change-Id: I401984cf5f163520dad0c46489ebb24b72325258 --- src/lib/evas/canvas/efl_canvas_vg_gradient.c | 2 ++ src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c | 8 ++++++-- src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c | 8 ++++++-- src/lib/evas/canvas/efl_canvas_vg_shape.c | 18 +++++++++++------- src/lib/evas/canvas/evas_vg_private.h | 3 ++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/lib/evas/canvas/efl_canvas_vg_gradient.c b/src/lib/evas/canvas/efl_canvas_vg_gradient.c index 5a7e339..b28b8c6 100644 --- a/src/lib/evas/canvas/efl_canvas_vg_gradient.c +++ b/src/lib/evas/canvas/efl_canvas_vg_gradient.c @@ -36,6 +36,8 @@ _gradient_stop_set(Evas_Vg_Gradient *obj, const Efl_Gfx_Gradient_Stop *colors, u tvg_gradient_set_color_stops(gd->gradient, color_stops, length); free(color_stops); + + if (gd->shape) efl_canvas_vg_node_change(gd->shape); } static void diff --git a/src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c b/src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c index 72adb64..2c402c4 100644 --- a/src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c +++ b/src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c @@ -99,8 +99,7 @@ _efl_canvas_vg_gradient_linear_render_pre(Evas_Object_Protected_Data *vg_pd EINA } #else static void -_gradient_linear_render_pre_tvg(Efl_Canvas_Vg_Node *nd EINA_UNUSED, - Efl_Canvas_Vg_Gradient_Data *gd, +_gradient_linear_render_pre_tvg(Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape) { if (!gd || !shape) return; @@ -123,6 +122,7 @@ _efl_canvas_vg_gradient_linear_efl_object_constructor(Eo *obj, gd->gradient_render_pre_tvg = _gradient_linear_render_pre_tvg; gd->spread = EFL_GFX_GRADIENT_SPREAD_PAD; gd->gradient = tvg_linear_gradient_new(); + gd->shape = NULL; #endif nd->data = pd; @@ -201,6 +201,8 @@ evas_vg_gradient_linear_start_set(Evas_Vg_Gradient_Linear *obj, double x, double tvg_linear_gradient_get(gd->gradient, NULL, NULL, &x2, &y2); tvg_linear_gradient_set(gd->gradient, x, y, x2, y2); + + if (gd->shape) efl_canvas_vg_node_change(gd->shape); #else efl_gfx_gradient_linear_start_set(obj, x, y); #endif @@ -239,6 +241,8 @@ evas_vg_gradient_linear_end_set(Evas_Vg_Gradient_Linear *obj, double x, double y tvg_linear_gradient_get(gd->gradient, &x1, &y1, NULL, NULL); tvg_linear_gradient_set(gd->gradient, x1, y1, x, y); + + if (gd->shape) efl_canvas_vg_node_change(gd->shape); #else efl_gfx_gradient_linear_end_set(obj, x, y); #endif diff --git a/src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c b/src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c index b5f589f..20e46a7 100644 --- a/src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c +++ b/src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c @@ -117,8 +117,7 @@ _efl_canvas_vg_gradient_radial_render_pre(Evas_Object_Protected_Data *vg_pd EINA } #else static void -_gradient_radial_render_pre_tvg(Efl_Canvas_Vg_Node *nd EINA_UNUSED, - Efl_Canvas_Vg_Gradient_Data *gd, +_gradient_radial_render_pre_tvg(Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape) { if (!gd || !gd->gradient || !shape) return; @@ -140,6 +139,7 @@ _efl_canvas_vg_gradient_radial_efl_object_constructor(Eo *obj, Efl_Canvas_Vg_Gra gd->gradient_render_pre_tvg = _gradient_radial_render_pre_tvg; gd->spread = EFL_GFX_GRADIENT_SPREAD_PAD; gd->gradient = tvg_radial_gradient_new(); + gd->shape = NULL; #endif nd->data = pd; @@ -224,6 +224,8 @@ evas_vg_gradient_radial_center_set(Evas_Vg_Gradient_Radial *obj, double x, doubl tvg_radial_gradient_get(gd->gradient, NULL, NULL, &r); tvg_radial_gradient_set(gd->gradient, x, y, r); + + if (gd->shape) efl_canvas_vg_node_change(gd->shape); #else efl_gfx_gradient_radial_center_set(obj, x, y); #endif @@ -262,6 +264,8 @@ evas_vg_gradient_radial_radius_set(Evas_Vg_Gradient_Radial *obj, double r) tvg_radial_gradient_get(gd->gradient, &x, &y, NULL); tvg_radial_gradient_set(gd->gradient, x, y, r); + + if (gd->shape) efl_canvas_vg_node_change(gd->shape); #else efl_gfx_gradient_radial_radius_set(obj, r); #endif diff --git a/src/lib/evas/canvas/efl_canvas_vg_shape.c b/src/lib/evas/canvas/efl_canvas_vg_shape.c index 7340fca..4096be1 100644 --- a/src/lib/evas/canvas/efl_canvas_vg_shape.c +++ b/src/lib/evas/canvas/efl_canvas_vg_shape.c @@ -614,13 +614,8 @@ _efl_canvas_vg_shape_fill_set(Eo *obj EINA_UNUSED, efl_unref(tmp); #ifdef HAVE_THORVG - Efl_Canvas_Vg_Gradient_Data *gd = NULL; - gd = efl_data_scope_get(pd->fill, EFL_CANVAS_VG_GRADIENT_CLASS); - - if (efl_isa(pd->fill, EFL_CANVAS_VG_GRADIENT_LINEAR_CLASS)) - tvg_shape_set_linear_gradient(pd->shape, gd->gradient); - else if (efl_isa(pd->fill, EFL_CANVAS_VG_GRADIENT_RADIAL_CLASS)) - tvg_shape_set_radial_gradient(pd->shape, gd->gradient); + Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(pd->fill, EFL_CANVAS_VG_GRADIENT_CLASS); + if (gd) gd->gradient_render_pre_tvg(gd, pd->shape); #endif } @@ -771,6 +766,15 @@ _efl_canvas_vg_shape_render_pre_tvg(EINA_UNUSED Evas_Object_Protected_Data *vg_p efl_gfx_color_get(obj, &r, &g, &b, &a); tvg_shape_set_fill_color(sd->shape, r, g, b, a); } + else if (efl_isa(sd->fill, EFL_CANVAS_VG_GRADIENT_CLASS)) + { + Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(sd->fill, EFL_CANVAS_VG_GRADIENT_CLASS); + if (gd) + { + gd->shape = obj; + gd->gradient_render_pre_tvg(gd, sd->shape); + } + } if (scene) tvg_scene_push(scene, sd->shape); diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h index 3902b64..788b8d6 100644 --- a/src/lib/evas/canvas/evas_vg_private.h +++ b/src/lib/evas/canvas/evas_vg_private.h @@ -145,7 +145,8 @@ struct _Efl_Canvas_Vg_Gradient_Data #ifdef HAVE_THORVG Tvg_Gradient *gradient; - void (*gradient_render_pre_tvg)(Efl_Canvas_Vg_Node *nd, Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape); + Evas_Vg_Shape *shape; + void (*gradient_render_pre_tvg)(Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape); #endif }; -- 2.7.4