gl_common: fix coordinate mismatch

Xorg uses top left as origin, OpenGL uses lower left. So we need to flip
the y axis, and make sure we are using the right points as origin of
windows.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-01-28 01:14:36 +00:00
parent 3b21365e94
commit 198dcdb987
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 22 additions and 3 deletions

View File

@ -615,8 +615,27 @@ static void glx_compose(void *backend_data, session_t *ps, win *w, void *win_dat
struct _glx_data *gd = backend_data; struct _glx_data *gd = backend_data;
struct _glx_win_data *wd = win_data; struct _glx_win_data *wd = win_data;
gl_compose(&wd->texture, 0, 0, dst_x, dst_y, w->widthb, w->heightb, 0, 1, true, // OpenGL and Xorg uses different coordinate systems.
false, region, &gd->win_shader); // First, We need to flip the y axis of the paint region
region_t region_yflipped;
pixman_region32_init(&region_yflipped);
pixman_region32_copy(&region_yflipped, (region_t *)region);
int nrects;
auto rect = pixman_region32_rectangles(&region_yflipped, &nrects);
for (int i = 0; i < nrects; i++) {
auto tmp = rect[i].y1;
rect[i].y1 = ps->root_height - rect[i].y2;
rect[i].y2 = ps->root_height - tmp;
}
dump_region(&region_yflipped);
// Then, we still need to convert the origin of painting.
// Note, in GL coordinates, we need to specified the bottom left corner of the
// rectangle, while what we get from the arguments are the top left corner.
gl_compose(&wd->texture, 0, 0, dst_x, ps->root_height - dst_y - w->heightb, w->widthb,
w->heightb, 0, 1, true, false, &region_yflipped, &gd->win_shader);
pixman_region32_fini(&region_yflipped);
} }
backend_info_t glx_backend = { backend_info_t glx_backend = {