libweston: always use the transform matrix for coordinate conversion

We always set it up correctly, even if transforms are disabled. The code
is simpler if we always use the matrix instead of having two cases.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2022-11-08 16:36:49 -06:00
parent 2dc8680d71
commit 8bf90010dd
1 changed files with 26 additions and 36 deletions

View File

@ -649,28 +649,23 @@ WL_EXPORT void
weston_view_to_global_float(struct weston_view *view,
float sx, float sy, float *x, float *y)
{
struct weston_vector v = { { sx, sy, 0.0f, 1.0f } };
assert(!view->transform.dirty);
if (view->transform.enabled) {
struct weston_vector v = { { sx, sy, 0.0f, 1.0f } };
weston_matrix_transform(&view->transform.matrix, &v);
weston_matrix_transform(&view->transform.matrix, &v);
if (fabsf(v.f[3]) < 1e-6) {
weston_log("warning: numerical instability in "
"%s(), divisor = %g\n", __func__,
v.f[3]);
*x = 0;
*y = 0;
return;
}
*x = v.f[0] / v.f[3];
*y = v.f[1] / v.f[3];
} else {
*x = sx + view->geometry.x;
*y = sy + view->geometry.y;
if (fabsf(v.f[3]) < 1e-6) {
weston_log("warning: numerical instability in "
"%s(), divisor = %g\n", __func__,
v.f[3]);
*x = 0;
*y = 0;
return;
}
*x = v.f[0] / v.f[3];
*y = v.f[1] / v.f[3];
}
WL_EXPORT pixman_box32_t
@ -1467,28 +1462,23 @@ WL_EXPORT void
weston_view_from_global_float(struct weston_view *view,
float x, float y, float *vx, float *vy)
{
struct weston_vector v = { { x, y, 0.0f, 1.0f } };
assert(!view->transform.dirty);
if (view->transform.enabled) {
struct weston_vector v = { { x, y, 0.0f, 1.0f } };
weston_matrix_transform(&view->transform.inverse, &v);
weston_matrix_transform(&view->transform.inverse, &v);
if (fabsf(v.f[3]) < 1e-6) {
weston_log("warning: numerical instability in "
"weston_view_from_global(), divisor = %g\n",
v.f[3]);
*vx = 0;
*vy = 0;
return;
}
*vx = v.f[0] / v.f[3];
*vy = v.f[1] / v.f[3];
} else {
*vx = x - view->geometry.x;
*vy = y - view->geometry.y;
if (fabsf(v.f[3]) < 1e-6) {
weston_log("warning: numerical instability in "
"weston_view_from_global(), divisor = %g\n",
v.f[3]);
*vx = 0;
*vy = 0;
return;
}
*vx = v.f[0] / v.f[3];
*vy = v.f[1] / v.f[3];
}
WL_EXPORT void