aboutsummaryrefslogtreecommitdiff
path: root/include/wlr/render
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-06-21 22:39:29 +0200
committerSimon Ser <contact@emersion.fr>2023-04-25 17:25:10 +0200
commit756dedae20eead72af6cfc7f724d0b2af6597eeb (patch)
tree219cc22f7ea39667cd71213cae5fe920c621bc9d /include/wlr/render
parent17ad03448082f525fef515c4c45f56d151bbc46a (diff)
Add a new renderer API
Goals: - Extensibility: we need to be able to add new params to the calls to render a texture/rect. For instance we'll need to add fences to the render texture operation for explicit sync purposes. - No implicit state: no more bind_buffer, begin, end. - No matrices: these hurt Pixman and we don't need them. - Clip regions for optimized damage repainting. Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3188
Diffstat (limited to 'include/wlr/render')
-rw-r--r--include/wlr/render/interface.h17
-rw-r--r--include/wlr/render/wlr_renderer.h68
2 files changed, 85 insertions, 0 deletions
diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h
index 07b26fbc..85a98202 100644
--- a/include/wlr/render/interface.h
+++ b/include/wlr/render/interface.h
@@ -48,6 +48,8 @@ struct wlr_renderer_impl {
uint32_t (*get_render_buffer_caps)(struct wlr_renderer *renderer);
struct wlr_texture *(*texture_from_buffer)(struct wlr_renderer *renderer,
struct wlr_buffer *buffer);
+ struct wlr_render_pass *(*begin_buffer_pass)(struct wlr_renderer *renderer,
+ struct wlr_buffer *buffer);
};
void wlr_renderer_init(struct wlr_renderer *renderer,
@@ -62,4 +64,19 @@ struct wlr_texture_impl {
void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *rendener,
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
+struct wlr_render_pass {
+ const struct wlr_render_pass_impl *impl;
+};
+
+void wlr_render_pass_init(struct wlr_render_pass *pass,
+ const struct wlr_render_pass_impl *impl);
+
+struct wlr_render_pass_impl {
+ bool (*submit)(struct wlr_render_pass *pass);
+ void (*add_texture)(struct wlr_render_pass *pass,
+ const struct wlr_render_texture_options *options);
+ void (*add_rect)(struct wlr_render_pass *pass,
+ const struct wlr_render_rect_options *options);
+};
+
#endif
diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h
index 0e08fe24..f6b58df5 100644
--- a/include/wlr/render/wlr_renderer.h
+++ b/include/wlr/render/wlr_renderer.h
@@ -12,6 +12,7 @@
#include <stdint.h>
#include <wayland-server-core.h>
#include <wlr/render/wlr_texture.h>
+#include <wlr/util/box.h>
struct wlr_backend;
struct wlr_renderer_impl;
@@ -155,4 +156,71 @@ int wlr_renderer_get_drm_fd(struct wlr_renderer *r);
*/
void wlr_renderer_destroy(struct wlr_renderer *renderer);
+/**
+ * A render pass accumulates drawing operations until submitted to the GPU.
+ */
+struct wlr_render_pass;
+
+/**
+ * Begin a new render pass with the supplied destination buffer.
+ *
+ * Callers must call wlr_render_pass_submit() once they are done with the
+ * render pass.
+ */
+struct wlr_render_pass *wlr_renderer_begin_buffer_pass(
+ struct wlr_renderer *renderer, struct wlr_buffer *buffer);
+
+/**
+ * Submit the render pass.
+ *
+ * The render pass cannot be used after this function is called.
+ */
+bool wlr_render_pass_submit(struct wlr_render_pass *render_pass);
+
+struct wlr_render_texture_options {
+ /* Source texture */
+ struct wlr_texture *texture;
+ /* Source coordinates, leave empty to render the whole texture */
+ struct wlr_fbox src_box;
+ /* Destination coordinates, width/height default to the texture size */
+ struct wlr_box dst_box;
+ /* Opacity between 0 (transparent) and 1 (opaque), leave NULL for opaque */
+ const float *alpha;
+ /* Clip region, leave NULL to disable clipping */
+ const pixman_region32_t *clip;
+ /* Transform applied to the source texture */
+ enum wl_output_transform transform;
+};
+
+/**
+ * Render a texture.
+ */
+void wlr_render_pass_add_texture(struct wlr_render_pass *render_pass,
+ const struct wlr_render_texture_options *options);
+
+/**
+ * A color value.
+ *
+ * Each channel has values between 0 and 1 inclusive. The R, G, B
+ * channels need to be pre-multiplied by A.
+ */
+struct wlr_render_color {
+ float r, g, b, a;
+};
+
+struct wlr_render_rect_options {
+ /* Rectangle coordinates */
+ struct wlr_box box;
+ /* Source color */
+ struct wlr_render_color color;
+ /* Clip region, leave NULL to disable clipping */
+ const pixman_region32_t *clip;
+};
+
+/**
+ * Render a rectangle.
+ */
+void wlr_render_pass_add_rect(struct wlr_render_pass *render_pass,
+ const struct wlr_render_rect_options *options);
+
#endif