This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 406aee1eb504f54a3859b1430e03c7fa0673505c
Author: Cedric BAIL <[email protected]>
AuthorDate: Thu Nov 26 14:09:49 2026 -0600
evas:vg: size the render surface from the transformed bounds
The surface a vector tree set with root_node_set() is rasterized into
was sized from the untransformed path bounds of the root's children.
A shape with a transformation was clipped to the rectangle its path
occupied before the transform: a translated square was cut off or
vanished, a rotated or scaled one was truncated.
Container bounds now apply each child's matrix, stroke gap included,
and the root bounds the root's own matrix. They are still computed
only when the object changed.
The viewbox scaling of that surface size is dropped. A root set by
the user is not mapped by the viewbox, and the tree edje gets from a
loaded file is already mapped to the object size by the loader, so
the scaled surface never matched its content. Mapping user roots by
the viewbox instead would scale edje's interpolated SVG states twice;
a test compares that sequence with the plain file load.
Sizing the surface from the path bounds came with 442fae5c56.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/evas/canvas/efl_canvas_vg_container.c | 11 +-
src/lib/evas/canvas/efl_canvas_vg_node.c | 23 +++++
src/lib/evas/canvas/efl_canvas_vg_object.c | 17 +--
src/lib/evas/canvas/evas_vg_private.h | 1 +
src/tests/evas/evas_test_vg.c | 142 ++++++++++++++++++++++++++
src/tests/evas/images/vg_quarter_square.svg | 3 +
6 files changed, 181 insertions(+), 16 deletions(-)
diff --git a/src/lib/evas/canvas/efl_canvas_vg_container.c b/src/lib/evas/canvas/efl_canvas_vg_container.c
index 6733a82cc7..3ac015a983 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_container.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_container.c
@@ -456,6 +456,7 @@ _efl_canvas_vg_container_efl_gfx_path_bounds_get(const Eo *obj EINA_UNUSED,
EINA_LIST_FOREACH(pd->children, l, child)
{
Eina_Position2D pos = efl_gfx_entity_position_get(child);
+ const Eina_Matrix3 *child_matrix = efl_canvas_vg_node_transformation_get(child);
double miterlimit = 0.0, stroke_gap = 0.0;
int stroke_gap_int;
@@ -469,8 +470,6 @@ _efl_canvas_vg_container_efl_gfx_path_bounds_get(const Eo *obj EINA_UNUSED,
if (first)
{
efl_gfx_path_bounds_get(child, r);
- r->pos.x += pos.x;
- r->pos.y += pos.y;
if (stroke_gap_int > 0)
{
r->pos.x -= stroke_gap_int / 2;
@@ -478,13 +477,14 @@ _efl_canvas_vg_container_efl_gfx_path_bounds_get(const Eo *obj EINA_UNUSED,
r->size.w += stroke_gap_int;
r->size.h += stroke_gap_int;
}
+ efl_canvas_vg_bounds_transform(child_matrix, r);
+ r->pos.x += pos.x;
+ r->pos.y += pos.y;
first = EINA_FALSE;
}
else
{
efl_gfx_path_bounds_get(child, &s);
- s.pos.x += pos.x;
- s.pos.y += pos.y;
if (stroke_gap_int > 0)
{
s.pos.x -= stroke_gap_int / 2;
@@ -492,6 +492,9 @@ _efl_canvas_vg_container_efl_gfx_path_bounds_get(const Eo *obj EINA_UNUSED,
s.size.w += stroke_gap_int;
s.size.h += stroke_gap_int;
}
+ efl_canvas_vg_bounds_transform(child_matrix, &s);
+ s.pos.x += pos.x;
+ s.pos.y += pos.y;
eina_rectangle_union(&r->rect, &s.rect);
}
}
diff --git a/src/lib/evas/canvas/efl_canvas_vg_node.c b/src/lib/evas/canvas/efl_canvas_vg_node.c
index 342c2106a3..a46eea5a4e 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_node.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_node.c
@@ -74,6 +74,29 @@ _efl_canvas_vg_node_transformation_set(Eo *obj,
pd->flags |= EFL_GFX_CHANGE_FLAG_MATRIX;
}
+void
+efl_canvas_vg_bounds_transform(const Eina_Matrix3 *m, Eina_Rect *bounds)
+{
+ Eina_Quad q;
+ double min_x, min_y, max_x, max_y;
+ int x, y;
+
+ if (!m) return;
+
+ eina_matrix3_point_transform(m, bounds->x, bounds->y, &q.x0, &q.y0);
+ eina_matrix3_point_transform(m, bounds->x + bounds->w, bounds->y, &q.x1, &q.y1);
+ eina_matrix3_point_transform(m, bounds->x + bounds->w, bounds->y + bounds->h, &q.x2, &q.y2);
+ eina_matrix3_point_transform(m, bounds->x, bounds->y + bounds->h, &q.x3, &q.y3);
+ min_x = fmin(fmin(q.x0, q.x1), fmin(q.x2, q.x3));
+ min_y = fmin(fmin(q.y0, q.y1), fmin(q.y2, q.y3));
+ max_x = fmax(fmax(q.x0, q.x1), fmax(q.x2, q.x3));
+ max_y = fmax(fmax(q.y0, q.y1), fmax(q.y2, q.y3));
+
+ x = floor(min_x);
+ y = floor(min_y);
+ EINA_RECT_SET(*bounds, x, y, ceil(max_x) - x, ceil(max_y) - y);
+}
+
const Eina_Matrix3 *
_efl_canvas_vg_node_transformation_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Node_Data *pd)
{
diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.c b/src/lib/evas/canvas/efl_canvas_vg_object.c
index 5c020280a8..7eefc691d6 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_object.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_object.c
@@ -820,7 +820,11 @@ _user_vg_entry_render(Evas_Object_Protected_Data *obj,
// Get changed boundary and fit the size.
if (pd->changed)
- efl_gfx_path_bounds_get(user_entry->root, &user_entry->path_bounds);
+ {
+ efl_gfx_path_bounds_get(user_entry->root, &user_entry->path_bounds);
+ efl_canvas_vg_bounds_transform(efl_canvas_vg_node_transformation_get(user_entry->root),
+ &user_entry->path_bounds);
+ }
if (user_entry->path_bounds.w != 0 && user_entry->path_bounds.h != 0)
{
@@ -832,17 +836,6 @@ _user_vg_entry_render(Evas_Object_Protected_Data *obj,
// If size of the drawing area is 0, no render.
else return;
- if (pd->viewbox.w != 0 && pd->viewbox.h !=0)
- {
- double sx = 0, sy= 0;
- sx = (double)w / (double)pd->viewbox.w;
- sy = (double)h / (double)pd->viewbox.h;
- render_rect.x = (render_rect.x - pd->viewbox.x) * sx;
- render_rect.y = (render_rect.y - pd->viewbox.y) * sy;
- render_rect.w *= sx;
- render_rect.h *= sy;
- }
-
//if the size doesn't match, drop previous cache surface.
if ((user_entry->w != render_rect.w ) ||
(user_entry->h != render_rect.h))
diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h
index 86c8d97660..90ba208171 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -176,6 +176,7 @@ _maybe_set_gl_comp(Ector_Surface *ector,
void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd);
void efl_canvas_vg_node_change(Efl_VG *node);
void efl_canvas_vg_container_vg_obj_update(Efl_VG *obj, Efl_Canvas_Vg_Node_Data *nd);
+void efl_canvas_vg_bounds_transform(const Eina_Matrix3 *m, Eina_Rect *bounds);
void efl_canvas_vg_container_blend_buffer_clear(Efl_VG *obj, Efl_Canvas_Vg_Container_Data *cd);
static inline void
diff --git a/src/tests/evas/evas_test_vg.c b/src/tests/evas/evas_test_vg.c
index 72e0050475..4f5e5f9011 100644
--- a/src/tests/evas/evas_test_vg.c
+++ b/src/tests/evas/evas_test_vg.c
@@ -13,6 +13,7 @@
#define EFL_BETA_API_SUPPORT 1
#define EFL_EO_API_SUPPORT 1
+#include <math.h>
#include <stdio.h>
#include <Evas.h>
@@ -320,6 +321,143 @@ EFL_START_TEST(evas_vg_shape_dash_is_released)
}
EFL_END_TEST
+// A node's transformation moves what it draws, and the surface the shapes
+// are rasterized into has to cover the result, not the untransformed path.
+static void
+_build_transformed_shape(Evas *e, const Eina_Matrix3 *m)
+{
+ Eo *vg, *shape;
+
+ vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, e);
+ efl_gfx_entity_size_set(vg, EINA_SIZE2D(WIN_W, WIN_H));
+ efl_gfx_entity_visible_set(vg, EINA_TRUE);
+
+ shape = efl_add(EFL_CANVAS_VG_SHAPE_CLASS, vg);
+ efl_gfx_path_append_rect(shape, 0, 0, 50, 50, 0, 0);
+ efl_gfx_color_set(shape, 255, 255, 255, 255);
+ if (m) efl_canvas_vg_node_transformation_set(shape, m);
+
+ efl_canvas_vg_object_root_node_set(vg, shape);
+}
+
+static void
+_build_translated_shape(Evas *e)
+{
+ Eina_Matrix3 m;
+
+ eina_matrix3_identity(&m);
+ eina_matrix3_translate(&m, 100, 100);
+ _build_transformed_shape(e, &m);
+}
+
+static void
+_build_scaled_shape(Evas *e)
+{
+ Eina_Matrix3 m;
+
+ eina_matrix3_identity(&m);
+ eina_matrix3_scale(&m, 2, 2);
+ _build_transformed_shape(e, &m);
+}
+
+static void
+_build_rotated_shape(Evas *e)
+{
+ Eina_Matrix3 m;
+
+ // A diamond: the square turned by 45 degrees, its corner at (128, 128).
+ eina_matrix3_identity(&m);
+ eina_matrix3_translate(&m, 128, 128);
+ eina_matrix3_rotate(&m, M_PI_4);
+ _build_transformed_shape(e, &m);
+}
+
+static void
+_assert_scene_pixels(void (*build)(Evas *e), int in_x, int in_y,
+ int out_x, int out_y)
+{
+ unsigned int in = 0, out = 0;
+
+ if (!_scene_sample("buffer", build, 2, in_x, in_y, &in)) return;
+ ck_assert(_scene_sample("buffer", build, 2, out_x, out_y, &out));
+
+ ck_assert_msg((in & 0xff) > 200,
+ "(%d, %d) should be drawn, got %08x", in_x, in_y, in);
+ ck_assert_msg((out & 0xff) < 50,
+ "(%d, %d) should not be drawn, got %08x", out_x, out_y, out);
+}
+
+EFL_START_TEST(evas_vg_translated_shape_is_not_clipped)
+{
+ // Moved to (100, 100) - (150, 150), away from its untransformed bounds.
+ _assert_scene_pixels(_build_translated_shape, 125, 125, 25, 25);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_vg_scaled_shape_is_not_clipped)
+{
+ // Scaled to (0, 0) - (100, 100): (90, 90) lies beyond the 50 unit square.
+ _assert_scene_pixels(_build_scaled_shape, 90, 90, 110, 110);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_vg_rotated_shape_is_not_clipped)
+{
+ // (128, 175) is inside the diamond and far from the 50 unit square, while
+ // (100, 135) is inside the diamond's bounding box but outside the diamond.
+ _assert_scene_pixels(_build_rotated_shape, 128, 175, 100, 135);
+}
+EFL_END_TEST
+
+// What Edje does for an interpolated SVG state: load the file, keep the
+// viewbox the loader reports, interpolate a copy of the tree and set it as
+// the root node. The loader already mapped the viewbox to the object size,
+// so the result has to look like the plain file.
+static void
+_build_loaded_svg(Evas *e)
+{
+ Eo *vg;
+
+ vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, e);
+ efl_gfx_entity_size_set(vg, EINA_SIZE2D(WIN_W, WIN_H));
+ efl_gfx_entity_visible_set(vg, EINA_TRUE);
+ efl_file_simple_load(vg, TESTS_SRC_DIR "/images/vg_quarter_square.svg", NULL);
+}
+
+static void
+_build_interpolated_svg(Evas *e)
+{
+ Eo *vg, *src, *dest, *root;
+ Eina_Rect viewbox;
+
+ vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, e);
+ efl_gfx_entity_size_set(vg, EINA_SIZE2D(WIN_W, WIN_H));
+ efl_gfx_entity_visible_set(vg, EINA_TRUE);
+
+ efl_file_simple_load(vg, TESTS_SRC_DIR "/images/vg_quarter_square.svg", NULL);
+ src = ""
+ viewbox = efl_canvas_vg_object_viewbox_get(vg);
+ efl_file_simple_load(vg, TESTS_SRC_DIR "/images/vg_quarter_square.svg", NULL);
+ dest = efl_ref(efl_canvas_vg_object_root_node_get(vg));
+
+ root = efl_duplicate(src);
+ efl_canvas_vg_object_viewbox_set(vg, viewbox);
+ ck_assert(efl_gfx_path_interpolate(root, src, dest, 0));
+ efl_canvas_vg_object_root_node_set(vg, root);
+
+ efl_unref(root);
+ efl_unref(src);
+ efl_unref(dest);
+}
+
+EFL_START_TEST(evas_vg_interpolated_svg_matches_loaded_svg)
+{
+ // The 25 unit square of a 50 unit viewbox covers 128 pixels of 256.
+ _assert_scene_pixels(_build_loaded_svg, 120, 120, 136, 136);
+ _assert_scene_pixels(_build_interpolated_svg, 120, 120, 136, 136);
+}
+EFL_END_TEST
+
void evas_test_vg(TCase *tc)
{
tcase_add_test(tc, evas_vg_mixed_sizes_group_opacity);
@@ -327,4 +465,8 @@ void evas_test_vg(TCase *tc)
tcase_add_test(tc, evas_vg_tiny_surface_cache);
tcase_add_test(tc, evas_vg_radial_without_solution_pads_to_first_stop);
tcase_add_test(tc, evas_vg_shape_dash_is_released);
+ tcase_add_test(tc, evas_vg_translated_shape_is_not_clipped);
+ tcase_add_test(tc, evas_vg_scaled_shape_is_not_clipped);
+ tcase_add_test(tc, evas_vg_rotated_shape_is_not_clipped);
+ tcase_add_test(tc, evas_vg_interpolated_svg_matches_loaded_svg);
}
diff --git a/src/tests/evas/images/vg_quarter_square.svg b/src/tests/evas/images/vg_quarter_square.svg
new file mode 100644
index 0000000000..d993f40a28
--- /dev/null
+++ b/src/tests/evas/images/vg_quarter_square.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50">
+ <rect x="0" y="0" width="25" height="25" fill="#ffffff"/>
+</svg>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.