aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/compositor/main.c4
-rw-r--r--include/wlr/types/wlr_surface.h2
-rw-r--r--types/wlr_surface.c14
3 files changed, 18 insertions, 2 deletions
diff --git a/examples/compositor/main.c b/examples/compositor/main.c
index 933e27c7..079f0243 100644
--- a/examples/compositor/main.c
+++ b/examples/compositor/main.c
@@ -45,8 +45,8 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
struct wlr_surface *surface = wl_resource_get_user_data(_res);
wlr_surface_flush_damage(surface);
if (surface->texture->valid) {
- wlr_texture_get_matrix(surface->texture, &matrix,
- &wlr_output->transform_matrix, 200, 200);
+ wlr_surface_get_matrix(surface, &matrix,
+ &wlr_output->transform_matrix, 200, 200);
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 60d8b2f6..d3104741 100644
--- a/include/wlr/types/wlr_surface.h
+++ b/include/wlr/types/wlr_surface.h
@@ -53,5 +53,7 @@ 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);
#endif
diff --git a/types/wlr_surface.c b/types/wlr_surface.c
index b1f273af..12220807 100644
--- a/types/wlr_surface.c
+++ b/types/wlr_surface.c
@@ -5,6 +5,7 @@
#include <wlr/egl.h>
#include <wlr/render/interface.h>
#include <wlr/types/wlr_surface.h>
+#include <wlr/render/matrix.h>
static void surface_destroy(struct wl_client *client, struct wl_resource *resource) {
wl_resource_destroy(resource);
@@ -268,3 +269,16 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res,
surface, destroy_surface);
return surface;
}
+
+void wlr_surface_get_matrix(struct wlr_surface *surface,
+ float (*matrix)[16], const float (*projection)[16], int x, int y) {
+ int width = surface->texture->width / surface->current.scale;
+ int height = surface->texture->height / surface->current.scale;
+ float world[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);
+ wlr_matrix_mul(projection, matrix, matrix);
+}