This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/287/head
in repository efl.
View the commit online.
commit 06b0c918ba1f5fcb9ee2a8fa35aeeb27d241e261
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 22:45:34 2026 -0600
evas/gl: apply the perspective of a mapped face once
evas_map_util_3d_perspective() leaves the projected position in the
corners. The GL engine gave those to a matrix that divides by depth
again, so near corners went further out and far ones came in, cut off
at the bounding box of the face. It has done so since 1.23, when the
corners it was handed stopped being the unprojected ones.
The engine now hands the matrix the point its divide brings back to
where the corner is. Any center to divide around gives the same picture,
so it divides around the middle of the target, and the viewport no
longer moves to put the eye there. That also loses two errors: the
viewport was placed wrongly for render-to-texture with the eye off the
middle row, and angled faces sat half a pixel from flat ones.
Faces after the first of a map with more than four points now get its
focal length, and a face with a corner behind the eye is drawn flat, as
the software engine does.
The map tests run on GL too when there is a display: the accuracy checks
of the software rasterizer, the same scenes on both engines, and the
outline of an angled face against a flat one.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../evas/engines/gl_common/evas_gl_common.h | 5 +-
.../evas/engines/gl_common/evas_gl_context.c | 148 +++------
src/modules/evas/engines/gl_common/evas_gl_image.c | 3 +
src/tests/evas/evas_test_map.c | 361 +++++++++++++++++++--
4 files changed, 391 insertions(+), 126 deletions(-)
diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index b11f0886b3..3a09b14cf5 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -244,8 +244,7 @@ struct _Evas_GL_Shared
int rot;
int mflip;
// persp map
- int foc, z0, px, py;
- int ax, ay;
+ int foc;
int offx, offy;
GLfloat proj[16];
Eina_Bool needs_shaders_flush : 1;
@@ -328,7 +327,7 @@ struct _Evas_Engine_GL_Context
int references;
int w, h;
int rot;
- int foc, z0, px, py;
+ int foc;
RGBA_Draw_Context *dc;
unsigned long long frame_cnt;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index 318a00c188..e8b1a2ac1c 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -508,8 +508,8 @@ matrix_ortho(GLfloat *m,
rotf = (((rot / 90) & 0x3) * M_PI) / 2.0;
- tx = -0.5 * (1.0 - orth);
- ty = -0.5 * (1.0 - orth);
+ tx = 0.0;
+ ty = 0.0;
if (rot == 90)
{
@@ -745,98 +745,21 @@ _evas_gl_common_viewport_set(Evas_Engine_GL_Context *gc)
gc->shared->rot = rot;
gc->shared->mflip = m;
gc->shared->foc = foc;
- gc->shared->z0 = gc->z0;
- gc->shared->px = gc->px;
- gc->shared->py = gc->py;
gc->change.size = 0;
gc->shared->offx = offx;
gc->shared->offy = offy;
- if (foc == 0)
- {
- if ((rot == 0) || (rot == 180))
- glViewport(offx, offy, w, h);
- else
- glViewport(offx, offy, h, w);
- // std matrix
- if (m == 1)
- matrix_ortho(gc->shared->proj,
- 0, w, 0, h,
- -1000000.0, 1000000.0,
- rot, w, h,
- 1, 1.0);
- // v flipped matrix for render-to-texture
- else
- matrix_ortho(gc->shared->proj,
- 0, w, h, 0,
- -1000000.0, 1000000.0,
- rot, w, h,
- 1, 1.0);
- }
+ if ((rot == 0) || (rot == 180))
+ glViewport(offx, offy, w, h);
else
- {
- int px, py, vx, vy, vw = 0, vh = 0, ax = 0, ay = 0, ppx = 0, ppy = 0;
-
- px = gc->shared->px;
- py = gc->shared->py;
-
- if ((rot == 0 ) || (rot == 90 )) ppx = px;
- else if ((rot == 180) || (rot == 270)) ppx = w - px;
- if ((rot == 0 ) || (rot == 270)) ppy = py;
- else if ((rot == 90 ) || (rot == 180)) ppy = h - py;
-
- vx = ((w / 2) - ppx);
- if (vx >= 0)
- {
- vw = w + (2 * vx);
- if ((rot == 0 ) || (rot == 90 )) ax = 2 * vx;
- else if ((rot == 180) || (rot == 270)) ax = 0;
- }
- else
- {
- vw = w - (2 * vx);
- if ((rot == 0 ) || (rot == 90 )) ax = 0;
- else if ((rot == 180) || (rot == 270)) ax = ppx - px;
- vx = 0;
- }
-
- vy = ((h / 2) - ppy);
- if (vy < 0)
- {
- vh = h - (2 * vy);
- if (rot == 0) ay = 0;
- else if ((rot == 90 ) || (rot == 180) || (rot == 270)) ay = ppy - py;
- vy = -vy;
- }
- else
- {
- vh = h + (2 * vy);
- if ((rot == 0 ) || (rot == 270)) ay = 2 * vy;
- else if ((rot == 90 ) || (rot == 180)) ay = 0;
- vy = 0;
- }
-
- if (m == -1) ay = vy * 2;
-
- if ((rot == 0) || (rot == 180))
- glViewport(offx + (-2 * vx), offy + (-2 * vy), vw, vh);
- else
- glViewport(offx + (-2 * vy), offy + (-2 * vx), vh, vw);
- if (m == 1)
- matrix_ortho(gc->shared->proj,
- 0, vw, 0, vh,
- -1000000.0, 1000000.0,
- rot, vw, vh,
- foc, 0.0);
- else
- matrix_ortho(gc->shared->proj,
- 0, vw, vh, 0,
- -1000000.0, 1000000.0,
- rot, vw, vh,
- foc, 0.0);
- gc->shared->ax = ax;
- gc->shared->ay = ay;
- }
+ glViewport(offx, offy, h, w);
+ /* With a focal length the matrix divides by depth, around the middle of
+ * the viewport. The v flipped one is for render-to-texture. */
+ matrix_ortho(gc->shared->proj,
+ 0, w, (m == 1) ? 0 : h, (m == 1) ? h : 0,
+ -1000000.0, 1000000.0,
+ rot, w, h,
+ foc ? foc : 1, foc ? 0.0 : 1.0);
// FIXME: Is this heavy work?
it = eina_hash_iterator_data_new(gc->shared->shaders_hash);
@@ -3092,6 +3015,24 @@ evas_gl_common_context_rgb_a_pair_push(Evas_Engine_GL_Context *gc,
PUSH_6_COLORS(pn, r, g, b, a);
}
+/* A face needs the depth divide when its corners are at different depths,
+ * all in front of the eye. With one behind it, the corners were not all
+ * projected and the face is drawn where they are, as the software engine
+ * does. */
+static Eina_Bool
+_map_face_is_flat(const RGBA_Map_Point *p)
+{
+ int foc = p[0].foc >> FP, z0 = p[0].z0 >> FP;
+ int i;
+
+ if (foc <= 0) return EINA_TRUE;
+ if ((p[0].z == p[1].z) && (p[1].z == p[2].z) && (p[2].z == p[3].z))
+ return EINA_TRUE;
+ for (i = 0; i < 4; i++)
+ if ((p[i].fz - z0 + foc) <= 0) return EINA_TRUE;
+ return EINA_FALSE;
+}
+
void
evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
Evas_GL_Texture *tex,
@@ -3133,11 +3074,7 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
(A_VAL(&(p[2].col)) < 0xff) || (A_VAL(&(p[3].col)) < 0xff))
blend = EINA_TRUE;
- if (((p[0].z == p[1].z) && (p[1].z == p[2].z) && (p[2].z == p[3].z)) ||
- (p[0].foc <= 0))
- {
- flat = EINA_TRUE;
- }
+ flat = _map_face_is_flat(p);
if (!clip) cx = cy = cw = ch = 0;
@@ -3211,9 +3148,6 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
{
shader_array_flush(gc);
gc->foc = p[0].foc >> FP;
- gc->z0 = p[0].z0 >> FP;
- gc->px = p[0].px >> FP;
- gc->py = p[0].py >> FP;
gc->change.size = 1;
_evas_gl_common_viewport_set(gc);
}
@@ -3312,11 +3246,20 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
}
else
{
+ /* The matrix divides by depth around the middle of the target,
+ * and fx, fy are where the corner already is on screen: hand it
+ * the point that the divide brings there. Any center gives the
+ * same outline, and the texture only follows the depths. */
+ const RGBA_Map_Point *at = &p[points[i]];
+ float foc = p[0].foc >> FP, z0 = p[0].z0 >> FP;
+ float depth = at->fz + (foc - z0);
+ float spread = depth / foc;
+ float mid_x = gc->shared->w / 2.0f, mid_y = gc->shared->h / 2.0f;
+
PUSH_VERTEX(pn,
- (p[points[i]].fx) + gc->shared->ax,
- (p[points[i]].fy) + gc->shared->ay,
- (p[points[i]].fz)
- + (gc->shared->foc - gc->shared->z0));
+ mid_x + ((at->fx - mid_x) * spread),
+ mid_y + ((at->fy - mid_y) * spread),
+ depth);
}
PUSH_TEXUV(pn,
tx[points[i]],
@@ -3353,9 +3296,6 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
{
shader_array_flush(gc);
gc->foc = 0;
- gc->z0 = 0;
- gc->px = 0;
- gc->py = 0;
gc->change.size = 1;
_evas_gl_common_viewport_set(gc);
}
diff --git a/src/modules/evas/engines/gl_common/evas_gl_image.c b/src/modules/evas/engines/gl_common/evas_gl_image.c
index a31ba9928a..6c6dc28ccc 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_image.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_image.c
@@ -1202,6 +1202,9 @@ evas_gl_common_image_map_draw(Evas_Engine_GL_Context *gc, Evas_GL_Image *im,
while (npoints >= 4)
{
+ /* only the first point of a map carries its perspective */
+ p[offset].z0 = p[0].z0;
+ p[offset].foc = p[0].foc;
evas_gl_common_context_image_map_push(gc, im->tex, npoints, &p[offset],
c, cx, cy, cw, ch,
mtex, mx, my, mw, mh, mask_smooth, mask_color,
diff --git a/src/tests/evas/evas_test_map.c b/src/tests/evas/evas_test_map.c
index dccfd24bac..33b0d7356b 100644
--- a/src/tests/evas/evas_test_map.c
+++ b/src/tests/evas/evas_test_map.c
@@ -214,23 +214,119 @@ _persp_face_check(const unsigned int *pixels, int stride, const Persp_Face *face
wrong, checked, worst, worst_x, worst_y);
}
+#define PERSP_W 500
+#define PERSP_H 300
+
+/* The engine the perspective checks draw with. GL needs a display: without
+ * one its tests have nothing to run on, as the other GL tests here. */
+static const char *_map_engine = "buffer";
+
+typedef struct
+{
+ Ecore_Evas *ee;
+ Evas_Object *snap;
+ Eina_Tmpstr *file;
+ unsigned int *pixels;
+ Eina_Bool saved;
+} Map_Canvas;
+
+static void
+_map_canvas_save(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+ Map_Canvas *c = data;
+
+ c->saved = evas_object_image_save(c->snap, c->file, NULL, NULL);
+}
+
+static Eina_Bool
+_map_canvas_new(Map_Canvas *c)
+{
+ memset(c, 0, sizeof(*c));
+ if (!strcmp(_map_engine, "buffer"))
+ c->ee = ecore_evas_buffer_new(PERSP_W, PERSP_H);
+ else
+ c->ee = ecore_evas_new(_map_engine, 0, 0, PERSP_W, PERSP_H, NULL);
+ if (!c->ee)
+ {
+ printf("Could not create a %s canvas, skipping.\n", _map_engine);
+ return EINA_FALSE;
+ }
+ ecore_evas_show(c->ee);
+ ecore_evas_manual_render_set(c->ee, EINA_TRUE);
+ c->pixels = malloc(PERSP_W * PERSP_H * sizeof(*c->pixels));
+ fail_if(!c->pixels);
+ return EINA_TRUE;
+}
+
+/* Renders the canvas and returns a copy of the whole frame */
+static const unsigned int *
+_map_canvas_pixels(Map_Canvas *c)
+{
+ Ecore_Evas *loader;
+ Evas_Object *im;
+ const unsigned int *frame;
+ Evas *e = ecore_evas_get(c->ee);
+ int fd, w = 0, h = 0;
+
+ evas_damage_rectangle_add(e, 0, 0, PERSP_W, PERSP_H);
+ if (!strcmp(_map_engine, "buffer"))
+ {
+ ecore_evas_manual_render(c->ee);
+ memcpy(c->pixels, ecore_evas_buffer_pixels_get(c->ee),
+ PERSP_W * PERSP_H * sizeof(*c->pixels));
+ return c->pixels;
+ }
+
+ /* GL frames are read back through a snapshot over everything else */
+ c->snap = evas_object_image_filled_add(e);
+ evas_object_image_snapshot_set(c->snap, EINA_TRUE);
+ evas_object_resize(c->snap, PERSP_W, PERSP_H);
+ evas_object_show(c->snap);
+ fd = eina_file_mkstemp("evas_test_map_XXXXXX.png", &c->file);
+ fail_if(fd < 0);
+ close(fd);
+ c->saved = EINA_FALSE;
+ evas_event_callback_add(e, EVAS_CALLBACK_RENDER_POST, _map_canvas_save, c);
+ ecore_evas_manual_render(c->ee);
+ evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, _map_canvas_save);
+ fail_if(!c->saved);
+
+ loader = ecore_evas_buffer_new(1, 1);
+ im = evas_object_image_add(ecore_evas_get(loader));
+ evas_object_image_file_set(im, c->file, NULL);
+ evas_object_image_size_get(im, &w, &h);
+ fail_if((w != PERSP_W) || (h != PERSP_H));
+ frame = evas_object_image_data_get(im, EINA_FALSE);
+ fail_if(!frame);
+ memcpy(c->pixels, frame, PERSP_W * PERSP_H * sizeof(*c->pixels));
+ evas_object_del(im);
+ ecore_evas_free(loader);
+ unlink(c->file);
+ eina_tmpstr_del(c->file);
+ evas_object_del(c->snap);
+ return c->pixels;
+}
+
+static void
+_map_canvas_free(Map_Canvas *c)
+{
+ ecore_evas_free(c->ee);
+ free(c->pixels);
+}
+
static void
_persp_check(const Persp_Face *faces, int count, Eina_Bool smooth,
Eina_Bool anti_alias)
{
- Ecore_Evas *ee;
- Evas *e;
+ Map_Canvas c;
Evas_Object *img;
Evas_Map *map;
unsigned int *source;
const unsigned int *pixels;
int i, x, y;
- ee = ecore_evas_buffer_new(500, 300);
- ecore_evas_show(ee);
- e = ecore_evas_get(ee);
-
- img = evas_object_image_filled_add(e);
+ if (!_map_canvas_new(&c)) return;
+ img = evas_object_image_filled_add(ecore_evas_get(c.ee));
evas_object_image_size_set(img, PERSP_TEX, PERSP_TEX);
source = evas_object_image_data_get(img, EINA_TRUE);
for (y = 0; y < PERSP_TEX; y++)
@@ -249,14 +345,13 @@ _persp_check(const Persp_Face *faces, int count, Eina_Bool smooth,
evas_object_anti_alias_set(img, anti_alias);
evas_object_map_set(img, map);
evas_object_map_enable_set(img, EINA_TRUE);
- ecore_evas_manual_render(ee);
- pixels = ecore_evas_buffer_pixels_get(ee);
+ pixels = _map_canvas_pixels(&c);
for (i = 0; i < count; i++)
- _persp_face_check(pixels, 500, &faces[i]);
+ _persp_face_check(pixels, PERSP_W, &faces[i]);
evas_map_free(map);
- ecore_evas_free(ee);
+ _map_canvas_free(&c);
}
/* right edge twice as far */
@@ -314,16 +409,15 @@ EFL_END_TEST
static void
_persp_shade_check(const Persp_Face *face, Eina_Bool smooth, Eina_Bool anti_alias)
{
- Ecore_Evas *ee;
+ Map_Canvas canvas;
Evas_Object *img;
Evas_Map *map;
unsigned int *source;
const unsigned int *pixels;
int i, x, y, checked = 0, wrong = 0, worst = 0;
- ee = ecore_evas_buffer_new(500, 300);
- ecore_evas_show(ee);
- img = evas_object_image_filled_add(ecore_evas_get(ee));
+ if (!_map_canvas_new(&canvas)) return;
+ img = evas_object_image_filled_add(ecore_evas_get(canvas.ee));
evas_object_image_size_set(img, PERSP_TEX, PERSP_TEX);
source = evas_object_image_data_get(img, EINA_TRUE);
memset(source, 0xff, PERSP_TEX * PERSP_TEX * sizeof(*source));
@@ -345,8 +439,7 @@ _persp_shade_check(const Persp_Face *face, Eina_Bool smooth, Eina_Bool anti_alia
evas_object_anti_alias_set(img, anti_alias);
evas_object_map_set(img, map);
evas_object_map_enable_set(img, EINA_TRUE);
- ecore_evas_manual_render(ee);
- pixels = ecore_evas_buffer_pixels_get(ee);
+ pixels = _map_canvas_pixels(&canvas);
for (x = face->left + 3; x < face->right - 3; x++)
{
@@ -356,7 +449,7 @@ _persp_shade_check(const Persp_Face *face, Eina_Bool smooth, Eina_Bool anti_alia
for (y = face->far_top + 3; y < face->far_bottom - 3; y++)
{
- const int shade = (pixels[(y * 500) + x] >> 16) & 0xff;
+ const int shade = (pixels[(y * PERSP_W) + x] >> 16) & 0xff;
const int off = abs(shade - (int)((first + last) / 2));
checked++;
@@ -370,7 +463,7 @@ _persp_shade_check(const Persp_Face *face, Eina_Bool smooth, Eina_Bool anti_alia
wrong, checked, worst);
evas_map_free(map);
- ecore_evas_free(ee);
+ _map_canvas_free(&canvas);
}
EFL_START_TEST(evas_object_map_perspective_colors)
@@ -529,6 +622,233 @@ EFL_START_TEST(evas_object_map_anti_alias_edge_colors)
}
EFL_END_TEST
+/* One scene drawn by both engines: four faces, each a quarter of a smooth
+ * gradient so that a texel or two of difference stays a few levels. */
+typedef struct
+{
+ const char *name;
+ int x[8], y[8], z[8];
+ int points;
+ double turn_y; /* degrees about the scene's middle */
+ int foc; /* 0 for none */
+ int cx, cy; /* the eye, away from the middle of the canvas */
+ /* inside a mapped parent, which is drawn in a surface of its own: the
+ * face and the eye are then drawn away from their canvas positions */
+ Eina_Bool nested;
+} Map_Scene;
+
+static const Map_Scene _map_scenes[] =
+{
+ { "turned face", { 150, 350, 350, 150 }, { 50, 50, 250, 250 }, { 0 }, 4, 40, 300, 180, 110 },
+ { "turned the other way", { 100, 300, 300, 100 }, { 60, 60, 240, 240 }, { 0 }, 4, -55, 200, 180, 110 },
+ { "off center", { 30, 230, 230, 30 }, { 20, 20, 140, 140 }, { 0, 150, 150, 0 }, 4, 0, 200, 180, 110 },
+ { "eye low and right", { 150, 350, 350, 150 }, { 50, 50, 250, 250 }, { 0 }, 4, 40, 300,
+ 340, 230 },
+ { "inside a mapped parent", { 150, 350, 350, 150 }, { 50, 50, 250, 250 }, { 0 }, 4, 40, 300,
+ 180, 110, EINA_TRUE },
+ /* not an upright rectangle, which would be drawn as a plain image */
+ { "corner behind the eye", { 150, 390, 350, 150 }, { 80, 60, 220, 220 },
+ { 0, -400, 0, 0 }, 4, 0, 300, 180, 110 },
+};
+
+static unsigned int *
+_map_scene_render(const char *engine, const Map_Scene *scene, Eina_Bool smooth)
+{
+ Map_Canvas c;
+ Evas *e;
+ Evas_Object *bg, *img;
+ Evas_Map *map;
+ unsigned int *source, *copy;
+ int i, x, y;
+
+ _map_engine = engine;
+ if (!_map_canvas_new(&c))
+ {
+ _map_engine = "buffer";
+ return NULL;
+ }
+ e = ecore_evas_get(c.ee);
+ bg = evas_object_rectangle_add(e);
+ evas_object_resize(bg, PERSP_W, PERSP_H);
+ evas_object_show(bg);
+
+ img = evas_object_image_filled_add(e);
+ evas_object_image_size_set(img, PERSP_TEX, PERSP_TEX);
+ source = evas_object_image_data_get(img, EINA_TRUE);
+ for (y = 0; y < PERSP_TEX; y++)
+ for (x = 0; x < PERSP_TEX; x++)
+ source[(y * PERSP_TEX) + x] = 0xff000000 | ((x / 2) << 16) | ((y / 2) << 8) | 0x40;
+ evas_object_image_data_set(img, source);
+ evas_object_image_data_update_add(img, 0, 0, PERSP_TEX, PERSP_TEX);
+ evas_object_resize(img, PERSP_TEX, PERSP_TEX);
+ evas_object_show(img);
+
+ map = evas_map_new(scene->points);
+ for (i = 0; i < scene->points; i++)
+ {
+ int corner = i % 4;
+
+ evas_map_point_coord_set(map, i, scene->x[i], scene->y[i], scene->z[i]);
+ evas_map_point_image_uv_set(map, i, ((corner == 1) || (corner == 2)) ? PERSP_TEX : 0,
+ (corner >= 2) ? PERSP_TEX : 0);
+ }
+ evas_map_util_3d_rotate(map, 0, scene->turn_y, 0, PERSP_W / 2, PERSP_H / 2, 0);
+ evas_map_util_3d_perspective(map, scene->cx, scene->cy, 0, scene->foc);
+ evas_map_smooth_set(map, smooth);
+ evas_object_map_set(img, map);
+ evas_object_map_enable_set(img, EINA_TRUE);
+ if (scene->nested)
+ {
+ Evas_Object *parent;
+ Evas_Map *still;
+
+ parent = evas_object_box_add(e);
+ evas_object_geometry_set(parent, 100, 30, 300, 240);
+ evas_object_smart_member_add(img, parent);
+ evas_object_show(parent);
+ /* a map that moves nothing, which still makes a surface */
+ still = evas_map_new(4);
+ evas_map_util_points_populate_from_object(still, parent);
+ evas_object_map_set(parent, still);
+ evas_object_map_enable_set(parent, EINA_TRUE);
+ evas_map_free(still);
+ }
+
+ copy = malloc(PERSP_W * PERSP_H * sizeof(*copy));
+ fail_if(!copy);
+ memcpy(copy, _map_canvas_pixels(&c), PERSP_W * PERSP_H * sizeof(*copy));
+ evas_map_free(map);
+ _map_canvas_free(&c);
+ _map_engine = "buffer";
+ return copy;
+}
+
+/* Edges are not placed identically, so this is for wrong shapes and texture:
+ * pixels far apart, more of them than a few edges hold */
+EFL_START_TEST(evas_object_map_gl_matches_software)
+{
+ size_t i;
+ int failed = 0;
+
+ for (i = 0; i < EINA_C_ARRAY_LENGTH(_map_scenes); i++)
+ {
+ unsigned int *gl, *sw;
+ int k, differ = 0;
+
+ gl = _map_scene_render("opengl_x11", &_map_scenes[i], EINA_TRUE);
+ if (!gl) return;
+ sw = _map_scene_render("buffer", &_map_scenes[i], EINA_TRUE);
+ for (k = 0; k < (PERSP_W * PERSP_H); k++)
+ {
+ int shift;
+
+ for (shift = 0; shift < 24; shift += 8)
+ if (abs((int)((gl[k] >> shift) & 0xff) - (int)((sw[k] >> shift) & 0xff)) > 12)
+ {
+ differ++;
+ break;
+ }
+ }
+ if (differ > 800)
+ {
+ fprintf(stderr, "%s: %d pixels differ from software\n",
+ _map_scenes[i].name, differ);
+ failed++;
+ }
+ free(gl);
+ free(sw);
+ }
+ ck_assert_int_eq(failed, 0);
+}
+EFL_END_TEST
+
+/* The checks the software rasterizer passes, on a GL canvas */
+EFL_START_TEST(evas_object_map_gl_perspective)
+{
+ const Persp_Face faces[2] =
+ {
+ { 10, 210, 10, 290, 80, 220, 2 },
+ { 250, 450, 10, 290, 80, 220, 2 },
+ };
+
+ _map_engine = "opengl_x11";
+ _persp_check(&_persp_slight, 1, EINA_TRUE, EINA_FALSE);
+ _persp_check(&_persp_steep, 1, EINA_TRUE, EINA_FALSE);
+ _persp_check(faces, 2, EINA_FALSE, EINA_FALSE);
+ _persp_shade_check(&_persp_slight, EINA_TRUE, EINA_FALSE);
+ _map_engine = "buffer";
+}
+EFL_END_TEST
+
+/* The pixels a white face covers on a black GL canvas */
+static unsigned int *
+_gl_coverage(const Persp_Face *face, Eina_Bool angled)
+{
+ Map_Canvas c;
+ Evas_Object *bg, *rect;
+ Evas_Map *map;
+ unsigned int *copy;
+ int i;
+
+ if (!_map_canvas_new(&c)) return NULL;
+ bg = evas_object_rectangle_add(ecore_evas_get(c.ee));
+ evas_object_color_set(bg, 0, 0, 0, 255);
+ evas_object_resize(bg, PERSP_W, PERSP_H);
+ evas_object_show(bg);
+ rect = evas_object_image_filled_add(ecore_evas_get(c.ee));
+ evas_object_image_size_set(rect, PERSP_TEX, PERSP_TEX);
+ copy = evas_object_image_data_get(rect, EINA_TRUE);
+ memset(copy, 0xff, PERSP_TEX * PERSP_TEX * sizeof(*copy));
+ evas_object_image_data_set(rect, copy);
+ evas_object_image_data_update_add(rect, 0, 0, PERSP_TEX, PERSP_TEX);
+ evas_object_resize(rect, PERSP_TEX, PERSP_TEX);
+ evas_object_show(rect);
+
+ map = evas_map_new(4);
+ _persp_face_set(map, 0, face);
+ if (angled)
+ evas_map_util_3d_perspective(map, 0, 150, 0, PERSP_FOC);
+ else
+ {
+ /* the same corners on screen, without depth */
+ const int x[4] = { face->left, face->right, face->right, face->left };
+ const int y[4] = { face->top, face->far_top, face->far_bottom, face->bottom };
+
+ for (i = 0; i < 4; i++)
+ evas_map_point_coord_set(map, i, x[i], y[i], 0);
+ }
+ evas_object_map_set(rect, map);
+ evas_object_map_enable_set(rect, EINA_TRUE);
+
+ copy = malloc(PERSP_W * PERSP_H * sizeof(*copy));
+ fail_if(!copy);
+ memcpy(copy, _map_canvas_pixels(&c), PERSP_W * PERSP_H * sizeof(*copy));
+ evas_map_free(map);
+ _map_canvas_free(&c);
+ return copy;
+}
+
+/* Dividing by depth must not move a face: it covers what a flat face with
+ * the same corners does. */
+EFL_START_TEST(evas_object_map_gl_perspective_outline)
+{
+ const Persp_Face face = { 10, 410, 10, 290, 80, 220, 2 };
+ unsigned int *flat, *angled;
+ int i, differ = 0;
+
+ _map_engine = "opengl_x11";
+ flat = _gl_coverage(&face, EINA_FALSE);
+ angled = flat ? _gl_coverage(&face, EINA_TRUE) : NULL;
+ _map_engine = "buffer";
+ if (!flat) return;
+ for (i = 0; i < (PERSP_W * PERSP_H); i++)
+ if (((flat[i] & 0xff) > 128) != ((angled[i] & 0xff) > 128)) differ++;
+ ck_assert_msg(differ <= 20, "%d pixels are covered by only one of the two", differ);
+ free(flat);
+ free(angled);
+}
+EFL_END_TEST
+
void evas_test_map(TCase *tc)
{
tcase_add_test(tc, evas_object_map_api);
@@ -541,4 +861,7 @@ void evas_test_map(TCase *tc)
tcase_add_test(tc, evas_object_map_perspective_colors_anti_alias);
tcase_add_test(tc, evas_object_map_anti_alias_edges);
tcase_add_test(tc, evas_object_map_anti_alias_edge_colors);
+ tcase_add_test(tc, evas_object_map_gl_matches_software);
+ tcase_add_test(tc, evas_object_map_gl_perspective);
+ tcase_add_test(tc, evas_object_map_gl_perspective_outline);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.