From 3012934a6d1496fe64cd4e1137def8afadfb6987 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 21 Dec 2022 10:21:35 -0600 Subject: [PATCH] ttk: Use weston_matrix_init_transform in toy toolkit Setup the cairo matrix with our new transform function. Signed-off-by: Derek Foreman --- clients/meson.build | 1 + clients/window.c | 79 ++++++--------------------------------------- 2 files changed, 10 insertions(+), 70 deletions(-) diff --git a/clients/meson.build b/clients/meson.build index a9f9a398..00bef17e 100644 --- a/clients/meson.build +++ b/clients/meson.build @@ -20,6 +20,7 @@ srcs_toytoolkit = [ deps_toytoolkit = [ dep_wayland_client, dep_lib_cairo_shared, + dep_matrix_c, dep_xkbcommon, dependency('wayland-cursor'), cc.find_library('util'), diff --git a/clients/window.c b/clients/window.c index 0d9d6cec..1dfa43c6 100644 --- a/clients/window.c +++ b/clients/window.c @@ -61,6 +61,7 @@ #include "relative-pointer-unstable-v1-client-protocol.h" #include "shared/os-compatibility.h" #include "shared/string-helpers.h" +#include "libweston/matrix.h" #include "window.h" #include "viewporter-client-protocol.h" @@ -1592,78 +1593,16 @@ static void widget_cairo_update_transform(struct widget *widget, cairo_t *cr) { struct surface *surface = widget->surface; - double angle; + struct weston_matrix matrix; cairo_matrix_t m; - enum wl_output_transform transform; - int surface_width, surface_height; - int translate_x, translate_y; - int32_t scale; - surface_width = surface->allocation.width; - surface_height = surface->allocation.height; - - transform = surface->buffer_transform; - scale = surface->buffer_scale; - - switch (transform) { - case WL_OUTPUT_TRANSFORM_FLIPPED: - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - cairo_matrix_init(&m, -1, 0, 0, 1, 0, 0); - break; - default: - cairo_matrix_init_identity(&m); - break; - } - - switch (transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - default: - angle = 0; - translate_x = 0; - translate_y = 0; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - angle = 0; - translate_x = surface_width; - translate_y = 0; - break; - case WL_OUTPUT_TRANSFORM_90: - angle = M_PI + M_PI_2; - translate_x = 0; - translate_y = surface_width; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - angle = M_PI + M_PI_2; - translate_x = 0; - translate_y = 0; - break; - case WL_OUTPUT_TRANSFORM_180: - angle = M_PI; - translate_x = surface_width; - translate_y = surface_height; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - angle = M_PI; - translate_x = 0; - translate_y = surface_height; - break; - case WL_OUTPUT_TRANSFORM_270: - angle = M_PI_2; - translate_x = surface_height; - translate_y = 0; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - angle = M_PI_2; - translate_x = surface_height; - translate_y = surface_width; - break; - } - - cairo_scale(cr, scale, scale); - cairo_translate(cr, translate_x, translate_y); - cairo_rotate(cr, angle); + weston_matrix_init_transform(&matrix, surface->buffer_transform, + 0, 0, + surface->allocation.width, + surface->allocation.height, + surface->buffer_scale); + cairo_matrix_init(&m, matrix.d[0], matrix.d[4], matrix.d[1], + matrix.d[5], matrix.d[12], matrix.d[13]); cairo_transform(cr, &m); }