From c63d94483b1e52817ca01ca82a867a78ebd39fa6 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 24 Mar 2018 18:30:28 -0400 Subject: Redesign wlr_texture - Textures are now immutable (apart from those created from raw pixels), no more invalid textures - Move all wl_drm stuff in wlr_renderer - Most of wlr_texture fields are now private - Remove some duplicated DMA-BUF code in the DRM backend - Add more assertions - Stride is now always given as bytes rather than pixels - Drop wl_shm functions Fun fact: this patch has been written 10,000 meters up in the air. --- render/wlr_renderer.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'render/wlr_renderer.c') diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 622aa1dd..d5a4d19f 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,15 @@ void wlr_renderer_init(struct wlr_renderer *renderer, const struct wlr_renderer_impl *impl) { + assert(impl->begin); + assert(impl->clear); + assert(impl->scissor); + assert(impl->render_texture_with_matrix); + assert(impl->render_quad); + assert(impl->render_ellipse); + assert(impl->formats); + assert(impl->format_supported); + assert(impl->texture_from_pixels); renderer->impl = impl; } @@ -22,7 +32,9 @@ void wlr_renderer_begin(struct wlr_renderer *r, int width, int height) { } void wlr_renderer_end(struct wlr_renderer *r) { - r->impl->end(r); + if (r->impl->end) { + r->impl->end(r); + } } void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]) { @@ -33,16 +45,15 @@ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box) { r->impl->scissor(r, box); } -struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { - return r->impl->texture_create(r); -} - bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, const float projection[static 9], int x, int y, float alpha) { + int width, height; + wlr_texture_get_size(texture, &width, &height); + float mat[9]; wlr_matrix_identity(mat); wlr_matrix_translate(mat, x, y); - wlr_matrix_scale(mat, texture->width, texture->height); + wlr_matrix_scale(mat, width, height); wlr_matrix_multiply(mat, projection, mat); return wlr_render_texture_with_matrix(r, texture, mat, alpha); @@ -69,15 +80,29 @@ const enum wl_shm_format *wlr_renderer_get_formats( return r->impl->formats(r, len); } -bool wlr_renderer_buffer_is_drm(struct wlr_renderer *r, - struct wl_resource *buffer) { - return r->impl->buffer_is_drm(r, buffer); +bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *r, + struct wl_resource *resource) { + if (!r->impl->resource_is_wl_drm_buffer) { + return false; + } + return r->impl->resource_is_wl_drm_buffer(r, resource); +} + +void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *r, + struct wl_resource *buffer, int *width, int *height) { + if (!r->impl->wl_drm_buffer_get_size) { + return; + } + return r->impl->wl_drm_buffer_get_size(r, buffer, width, height); } bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt, uint32_t stride, uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data) { + if (!r->impl->read_pixels) { + return false; + } return r->impl->read_pixels(r, fmt, stride, width, height, src_x, src_y, dst_x, dst_y, data); } -- cgit v1.2.3 From 793c3b30473bcad488eae9266b67ccfdf3106231 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 12:41:51 -0400 Subject: render: add simple functions to render rectangles and ellipses --- examples/tablet.c | 18 ++++++++--------- include/wlr/render/interface.h | 4 ++-- include/wlr/render/wlr_renderer.h | 16 ++++++++++++--- render/gles2/renderer.c | 8 ++++---- render/wlr_renderer.c | 41 +++++++++++++++++++++++++++++---------- rootston/output.c | 2 +- 6 files changed, 60 insertions(+), 29 deletions(-) (limited to 'render/wlr_renderer.c') diff --git a/examples/tablet.c b/examples/tablet.c index 65c559cb..9379fac3 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -49,7 +49,6 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[9]; float distance = 0.8f * (1 - sample->distance); float tool_color[4] = { distance, distance, distance, 1 }; for (size_t i = 0; sample->button && i < 4; ++i) { @@ -61,12 +60,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts float pad_height = sample->height_mm * scale; float left = width / 2.0f - pad_width / 2.0f; float top = height / 2.0f - pad_height / 2.0f; - struct wlr_box box = { + const struct wlr_box box = { .x = left, .y = top, .width = pad_width, .height = pad_height, }; - wlr_matrix_project_box(matrix, &box, 0, 0, wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, sample->pad_color, matrix); + wlr_render_rect(sample->renderer, &box, sample->pad_color, + wlr_output->transform_matrix); if (sample->proximity) { struct wlr_box box = { @@ -75,16 +74,17 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts .width = 16 * (sample->pressure + 1), .height = 16 * (sample->pressure + 1), }; - wlr_matrix_project_box(matrix, &box, 0, sample->ring, - wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, tool_color, matrix); + float matrix[9]; + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, + sample->ring, wlr_output->transform_matrix); + wlr_render_quad_with_matrix(sample->renderer, tool_color, matrix); + box.x += sample->x_tilt; box.y += sample->y_tilt; box.width /= 2; box.height /= 2; - wlr_matrix_project_box(matrix, &box, 0, 0, + wlr_render_rect(sample->renderer, &box, tool_color, wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, tool_color, matrix); } wlr_renderer_end(sample->renderer); diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 7f25c0ff..d4cd35f8 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -27,9 +27,9 @@ struct wlr_renderer_impl { bool (*render_texture_with_matrix)(struct wlr_renderer *renderer, struct wlr_texture *texture, const float matrix[static 9], float alpha); - void (*render_quad)(struct wlr_renderer *renderer, + void (*render_quad_with_matrix)(struct wlr_renderer *renderer, const float color[static 4], const float matrix[static 9]); - void (*render_ellipse)(struct wlr_renderer *renderer, + void (*render_ellipse_with_matrix)(struct wlr_renderer *renderer, const float color[static 4], const float matrix[static 9]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index 6f0d2ecc..5c78089e 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -36,14 +36,24 @@ bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, bool wlr_render_texture_with_matrix(struct wlr_renderer *r, struct wlr_texture *texture, const float matrix[static 9], float alpha); /** - * Renders a solid quad in the specified color. + * Renders a solid rectangle in the specified color. */ -void wlr_render_colored_quad(struct wlr_renderer *r, +void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]); +/** + * Renders a solid quadrangle in the specified color with the specified matrix. + */ +void wlr_render_quad_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]); /** * Renders a solid ellipse in the specified color. */ -void wlr_render_colored_ellipse(struct wlr_renderer *r, +void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]); +/** + * Renders a solid ellipse in the specified color with the specified matrix. + */ +void wlr_render_ellipse_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]); /** * Returns a list of pixel formats supported by this renderer. diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9403c0ed..61665a07 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -144,7 +144,7 @@ static bool gles2_render_texture_with_matrix( } -static void gles2_render_quad(struct wlr_renderer *wlr_renderer, +static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -161,7 +161,7 @@ static void gles2_render_quad(struct wlr_renderer *wlr_renderer, GLES2_DEBUG_POP; } -static void gles2_render_ellipse(struct wlr_renderer *wlr_renderer, +static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -256,8 +256,8 @@ static const struct wlr_renderer_impl renderer_impl = { .scissor = gles2_scissor, .texture_create = gles2_renderer_texture_create, .render_texture_with_matrix = gles2_render_texture_with_matrix, - .render_quad = gles2_render_quad, - .render_ellipse = gles2_render_ellipse, + .render_quad_with_matrix = gles2_render_quad_with_matrix, + .render_ellipse_with_matrix = gles2_render_ellipse_with_matrix, .formats = gles2_renderer_formats, .buffer_is_drm = gles2_buffer_is_drm, .read_pixels = gles2_read_pixels, diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 622aa1dd..5598a0e7 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -39,13 +39,16 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, const float projection[static 9], int x, int y, float alpha) { - float mat[9]; - wlr_matrix_identity(mat); - wlr_matrix_translate(mat, x, y); - wlr_matrix_scale(mat, texture->width, texture->height); - wlr_matrix_multiply(mat, projection, mat); + const struct wlr_box box = { + .x = x, .y = y, + .width = texture->width, .height = texture->height, + }; - return wlr_render_texture_with_matrix(r, texture, mat, alpha); + float matrix[9]; + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + return wlr_render_texture_with_matrix(r, texture, matrix, alpha); } bool wlr_render_texture_with_matrix(struct wlr_renderer *r, @@ -54,14 +57,32 @@ bool wlr_render_texture_with_matrix(struct wlr_renderer *r, return r->impl->render_texture_with_matrix(r, texture, matrix, alpha); } -void wlr_render_colored_quad(struct wlr_renderer *r, +void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]) { + float matrix[9]; + wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + wlr_render_quad_with_matrix(r, color, matrix); +} + +void wlr_render_quad_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]) { - r->impl->render_quad(r, color, matrix); + r->impl->render_quad_with_matrix(r, color, matrix); +} + +void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]) { + float matrix[9]; + wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + wlr_render_ellipse_with_matrix(r, color, matrix); } -void wlr_render_colored_ellipse(struct wlr_renderer *r, +void wlr_render_ellipse_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]) { - r->impl->render_ellipse(r, color, matrix); + r->impl->render_ellipse_with_matrix(r, color, matrix); } const enum wl_shm_format *wlr_renderer_get_formats( diff --git a/rootston/output.c b/rootston/output.c index 1284c928..c75935af 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -363,7 +363,7 @@ static void render_decorations(struct roots_view *view, pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_colored_quad(renderer, color, matrix); + wlr_render_quad_with_matrix(renderer, color, matrix); } damage_finish: -- cgit v1.2.3