diff options
-rw-r--r-- | examples/compositor/main.c | 5 | ||||
-rw-r--r-- | include/wlr/types/wlr_surface.h | 14 | ||||
-rw-r--r-- | types/wlr_surface.c | 15 |
3 files changed, 25 insertions, 9 deletions
diff --git a/examples/compositor/main.c b/examples/compositor/main.c index 079f0243..16851614 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -8,6 +8,7 @@ #include <wlr/backend.h> #include <wlr/backend/session.h> #include <wlr/render.h> +#include <wlr/render/matrix.h> #include <wlr/render/gles2.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_surface.h> @@ -41,12 +42,14 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) { struct wl_resource *_res; float matrix[16]; + float transform[16]; wl_list_for_each(_res, &sample->compositor.surfaces, link) { struct wlr_surface *surface = wl_resource_get_user_data(_res); wlr_surface_flush_damage(surface); if (surface->texture->valid) { + wlr_matrix_translate(&transform, 200, 200, 0); wlr_surface_get_matrix(surface, &matrix, - &wlr_output->transform_matrix, 200, 200); + &wlr_output->transform_matrix, &transform); wlr_render_with_matrix(sample->renderer, surface->texture, &matrix); struct wlr_frame_callback *cb, *cnext; diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 811097ad..9b13d9cc 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -55,7 +55,17 @@ struct wlr_renderer; struct wlr_surface *wlr_surface_create(struct wl_resource *res, struct wlr_renderer *renderer); void wlr_surface_flush_damage(struct wlr_surface *surface); -void wlr_surface_get_matrix(struct wlr_surface *surface, float (*matrix)[16], - const float (*projection)[16], int x, int y); +/** + * Gets a matrix you can pass into wlr_render_with_matrix to display this + * surface. `matrix` is the output matrix, `projection` is the wlr_output + * projection matrix, and `transform` is any additional transformations you want + * to perform on the surface (or NULL/the identity matrix if you don't). + * `transform` is used before the surface is scaled, so its geometry extends + * from 0 to 1 in both dimensions. + */ +void wlr_surface_get_matrix(struct wlr_surface *surface, + float (*matrix)[16], + const float (*projection)[16], + const float (*transform)[16]); #endif diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 77acff02..6d023381 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -353,14 +353,17 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, } void wlr_surface_get_matrix(struct wlr_surface *surface, - float (*matrix)[16], const float (*projection)[16], int x, int y) { + float (*matrix)[16], + const float (*projection)[16], + const float (*transform)[16]) { int width = surface->texture->width / surface->current.scale; int height = surface->texture->height / surface->current.scale; - float world[16]; + float scale[16]; wlr_matrix_identity(matrix); - wlr_matrix_translate(&world, x, y, 0); - wlr_matrix_mul(matrix, &world, matrix); - wlr_matrix_scale(&world, width, height, 1); - wlr_matrix_mul(matrix, &world, matrix); + if (transform) { + wlr_matrix_mul(matrix, transform, matrix); + } + wlr_matrix_scale(&scale, width, height, 1); + wlr_matrix_mul(matrix, &scale, matrix); wlr_matrix_mul(projection, matrix, matrix); } |