render: introduce wlr_render_texture_pass

Split texture rendering out of wlr_render_pass and introduce a
dedicated wlr_render_texture_pass interface.

Remove the add_texture hook from wlr_render_pass_impl and route
texture rendering through renderer->texture_pass instead.
This commit is contained in:
YaoBing Xiao 2026-03-13 12:36:51 +08:00
parent 33a27b055c
commit fee962af36
11 changed files with 222 additions and 8 deletions

View file

@ -286,7 +286,6 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
static const struct wlr_render_pass_impl render_pass_impl = {
.submit = render_pass_submit,
.add_texture = render_pass_add_texture,
};
static const char *reset_status_str(GLenum status) {
@ -391,3 +390,41 @@ struct wlr_gles2_render_rect_pass *wlr_gles2_render_rect_pass_from_pass(
return pass;
}
static void render_texture_pass_destroy(struct wlr_render_texture_pass *pass) {
struct wlr_gles2_render_texture_pass *gles2_pass =
wlr_gles2_render_texture_pass_from_pass(pass);
free(gles2_pass);
}
static const struct wlr_render_texture_pass_impl render_texture_pass_impl = {
.destroy = render_texture_pass_destroy,
.render = render_pass_add_texture,
};
struct wlr_render_texture_pass *wlr_gles2_render_texture_pass_create(void) {
struct wlr_gles2_render_texture_pass *pass = calloc(1, sizeof(*pass));
if (pass == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_gles2_render_texture_pass");
return NULL;
}
wlr_render_texture_pass_init(&pass->base, &render_texture_pass_impl);
return &pass->base;
}
bool wlr_render_texture_pass_is_gles2(const struct wlr_render_texture_pass *texture_pass) {
return texture_pass != NULL && texture_pass->impl == &render_texture_pass_impl;
}
struct wlr_gles2_render_texture_pass *wlr_gles2_render_texture_pass_from_pass(
struct wlr_render_texture_pass *texture_pass) {
if (!wlr_render_texture_pass_is_gles2(texture_pass)) {
return NULL;
}
struct wlr_gles2_render_texture_pass *pass =
wl_container_of(texture_pass, pass, base);
return pass;
}

View file

@ -17,7 +17,7 @@
void wlr_render_pass_init(struct wlr_render_pass *render_pass,
const struct wlr_render_pass_impl *impl) {
assert(impl->submit && impl->add_texture);
assert(impl->submit);
*render_pass = (struct wlr_render_pass){
.impl = impl,
};
@ -38,7 +38,7 @@ void wlr_render_pass_add_texture(struct wlr_render_pass *render_pass,
(uint32_t)(box->y + box->height) <= options->texture->height);
}
render_pass->impl->add_texture(render_pass, options);
render_pass->renderer->texture_pass->impl->render(render_pass, options);
}
void wlr_render_pass_add_rect(struct wlr_render_pass *render_pass,
@ -142,3 +142,56 @@ struct wlr_render_rect_pass *get_or_create_render_rect_pass(
return renderer->rect_pass;
}
}
void wlr_render_texture_pass_init(struct wlr_render_texture_pass *render_pass,
const struct wlr_render_texture_pass_impl *impl) {
assert(impl->render);
*render_pass = (struct wlr_render_texture_pass){
.impl = impl,
};
wl_signal_init(&render_pass->events.destroy);
}
void wlr_render_texture_pass_destroy(struct wlr_render_texture_pass *render_pass) {
if (render_pass == NULL) {
return;
}
wl_signal_emit_mutable(&render_pass->events.destroy, NULL);
assert(wl_list_empty(&render_pass->events.destroy.listener_list));
if (render_pass->impl->destroy != NULL) {
render_pass->impl->destroy(render_pass);
}
}
struct wlr_render_texture_pass *get_or_create_render_texture_pass(
struct wlr_renderer *renderer) {
if (renderer == NULL) {
return NULL;
}
if (renderer->texture_pass == NULL) {
struct wlr_render_texture_pass *pass = NULL;
if (wlr_renderer_is_pixman(renderer)) {
pass = wlr_pixman_render_texture_pass_create();
}
#if WLR_HAS_GLES2_RENDERER
else if (wlr_renderer_is_gles2(renderer)) {
pass = wlr_gles2_render_texture_pass_create();
}
#endif
#if WLR_HAS_VULKAN_RENDERER
else if (wlr_renderer_is_vk(renderer)) {
pass = wlr_vk_render_texture_pass_create();
}
#endif
renderer->texture_pass = pass;
return pass;
} else {
return renderer->texture_pass;
}
}

View file

@ -230,7 +230,6 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
static const struct wlr_render_pass_impl render_pass_impl = {
.submit = render_pass_submit,
.add_texture = render_pass_add_texture,
};
static void render_rect_pass_destroy(struct wlr_render_rect_pass *pass) {
@ -272,6 +271,45 @@ struct wlr_pixman_render_rect_pass *wlr_pixman_render_rect_pass_from_pass(
return pass;
}
static void render_texture_pass_destroy(struct wlr_render_texture_pass *pass) {
struct wlr_pixman_render_texture_pass *pixman_pass =
wlr_pixman_render_texture_pass_from_pass(pass);
free(pixman_pass);
}
static const struct wlr_render_texture_pass_impl render_texture_pass_impl = {
.destroy = render_texture_pass_destroy,
.render = render_pass_add_texture,
};
struct wlr_render_texture_pass *wlr_pixman_render_texture_pass_create(void) {
struct wlr_pixman_render_texture_pass *pass = malloc(sizeof(*pass));
if (pass == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_pixman_render_texture_pass");
return NULL;
}
wlr_render_texture_pass_init(&pass->base, &render_texture_pass_impl);
return &pass->base;
}
bool wlr_render_texture_pass_is_pixman(const struct wlr_render_texture_pass *texture_pass) {
return texture_pass->impl == &render_texture_pass_impl;
}
struct wlr_pixman_render_texture_pass *wlr_pixman_render_texture_pass_from_pass(
struct wlr_render_texture_pass *texture_pass) {
if (!wlr_render_texture_pass_is_pixman(texture_pass)) {
return NULL;
}
struct wlr_pixman_render_texture_pass *pixman_pass =
wl_container_of(texture_pass, pixman_pass, base);
return pixman_pass;
}
struct wlr_pixman_render_pass *begin_pixman_render_pass(
struct wlr_pixman_buffer *buffer) {
struct wlr_pixman_render_pass *pass = calloc(1, sizeof(*pass));

View file

@ -983,7 +983,6 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
static const struct wlr_render_pass_impl render_pass_impl = {
.submit = render_pass_submit,
.add_texture = render_pass_add_texture,
};
void vk_color_transform_destroy(struct wlr_addon *addon) {
@ -1393,3 +1392,41 @@ struct wlr_vk_render_rect_pass *wlr_vk_render_rect_pass_from_pass(
return pass;
}
static void render_texture_pass_destroy(struct wlr_render_texture_pass *pass) {
struct wlr_vk_render_texture_pass *vk_pass =
wlr_vk_render_texture_pass_from_pass(pass);
free(vk_pass);
}
static const struct wlr_render_texture_pass_impl render_texture_pass_impl = {
.destroy = render_texture_pass_destroy,
.render = render_pass_add_texture,
};
struct wlr_render_texture_pass *wlr_vk_render_texture_pass_create(void) {
struct wlr_vk_render_texture_pass *pass = calloc(1, sizeof(*pass));
if (pass == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_vk_render_texture_pass");
return NULL;
}
wlr_render_texture_pass_init(&pass->base, &render_texture_pass_impl);
return &pass->base;
}
bool wlr_render_texture_pass_is_vk(const struct wlr_render_texture_pass *texture_pass) {
return texture_pass->impl == &render_texture_pass_impl;
}
struct wlr_vk_render_texture_pass *wlr_vk_render_texture_pass_from_pass(
const struct wlr_render_texture_pass *texture_pass) {
if (!wlr_render_texture_pass_is_vk(texture_pass)) {
return NULL;
}
struct wlr_vk_render_texture_pass *vk_pass = wl_container_of(texture_pass, vk_pass, base);
return vk_pass;
}

View file

@ -54,6 +54,7 @@ void wlr_renderer_destroy(struct wlr_renderer *r) {
assert(wl_list_empty(&r->events.lost.listener_list));
wlr_render_rect_pass_destroy(r->rect_pass);
wlr_render_texture_pass_destroy(r->texture_pass);
if (r->impl && r->impl->destroy) {
r->impl->destroy(r);
} else {