wlr_renderer: Switch texture rendering functions to take wlr_raster

Implements automatic texture uploading as both wlr_scene and cursor
handling both are simplified as a result.
This commit is contained in:
Alexander Orzechowski 2022-06-26 22:29:22 -04:00
parent 45ad3d47ad
commit 248a33a026
20 changed files with 142 additions and 166 deletions

View file

@ -246,15 +246,17 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer,
pop_gles2_debug(renderer);
}
static bool gles2_render_subtexture_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
static bool gles2_render_subraster_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_raster *wlr_raster,
const struct wlr_fbox *box, const float matrix[static 9],
float alpha) {
struct wlr_gles2_renderer *renderer =
gles2_get_renderer_in_context(wlr_renderer);
struct wlr_gles2_texture *texture =
gles2_get_texture(wlr_texture);
assert(texture->renderer == renderer);
gles2_raster_upload(renderer, wlr_raster);
if (!texture) {
return false;
}
struct wlr_gles2_tex_shader *shader = NULL;
@ -305,10 +307,10 @@ static bool gles2_render_subtexture_with_matrix(
glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha);
const GLfloat x1 = box->x / wlr_texture->width;
const GLfloat y1 = box->y / wlr_texture->height;
const GLfloat x2 = (box->x + box->width) / wlr_texture->width;
const GLfloat y2 = (box->y + box->height) / wlr_texture->height;
const GLfloat x1 = box->x / wlr_raster->width;
const GLfloat y1 = box->y / wlr_raster->height;
const GLfloat x2 = (box->x + box->width) / wlr_raster->width;
const GLfloat y2 = (box->y + box->height) / wlr_raster->height;
const GLfloat texcoord[] = {
x2, y1, // top right
x1, y1, // top left
@ -549,7 +551,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.clear = gles2_clear,
.scissor = gles2_scissor,
.raster_upload = _gles2_raster_upload,
.render_subtexture_with_matrix = gles2_render_subtexture_with_matrix,
.render_subraster_with_matrix = gles2_render_subraster_with_matrix,
.render_quad_with_matrix = gles2_render_quad_with_matrix,
.get_shm_texture_formats = gles2_get_shm_texture_formats,
.get_dmabuf_texture_formats = gles2_get_dmabuf_texture_formats,

View file

@ -23,7 +23,7 @@ bool wlr_texture_is_gles2(struct wlr_texture *wlr_texture) {
return wlr_texture->impl == &texture_impl;
}
struct wlr_gles2_texture *gles2_get_texture(
static struct wlr_gles2_texture *gles2_get_texture(
struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_gles2(wlr_texture));
return (struct wlr_gles2_texture *)wlr_texture;

View file

@ -40,12 +40,6 @@ bool wlr_texture_is_pixman(struct wlr_texture *texture) {
return texture->impl == &texture_impl;
}
static struct wlr_pixman_texture *get_texture(
struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_pixman(wlr_texture));
return (struct wlr_pixman_texture *)wlr_texture;
}
static struct wlr_pixman_texture *pixman_texture_create(
struct wlr_pixman_renderer *renderer, uint32_t drm_format,
uint32_t width, uint32_t height) {
@ -310,13 +304,16 @@ static void matrix_to_pixman_transform(struct pixman_transform *transform,
pixman_transform_from_pixman_f_transform(transform, &ftr);
}
static bool pixman_render_subtexture_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
static bool pixman_render_subraster_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_raster *wlr_raster,
const struct wlr_fbox *fbox, const float matrix[static 9],
float alpha) {
struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer);
struct wlr_pixman_texture *texture = get_texture(wlr_texture);
struct wlr_pixman_buffer *buffer = renderer->current_buffer;
struct wlr_pixman_texture *texture = raster_upload(renderer, wlr_raster);
if (!texture){
return false;
}
if (texture->buffer != NULL) {
void *data;
@ -530,7 +527,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.clear = pixman_clear,
.scissor = pixman_scissor,
.raster_upload = pixman_raster_upload,
.render_subtexture_with_matrix = pixman_render_subtexture_with_matrix,
.render_subraster_with_matrix = pixman_render_subraster_with_matrix,
.render_quad_with_matrix = pixman_render_quad_with_matrix,
.get_shm_texture_formats = pixman_get_shm_texture_formats,
.get_render_formats = pixman_get_render_formats,

View file

@ -740,14 +740,17 @@ static void vulkan_end(struct wlr_renderer *wlr_renderer) {
}
}
static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_renderer,
struct wlr_texture *wlr_texture, const struct wlr_fbox *box,
static bool vulkan_render_subraster_with_matrix(struct wlr_renderer *wlr_renderer,
struct wlr_raster *wlr_raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha) {
struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer);
VkCommandBuffer cb = renderer->cb;
struct wlr_vk_texture *texture = vulkan_get_texture(wlr_texture);
assert(texture->renderer == renderer);
struct wlr_vk_texture *texture = vulkan_raster_upload(renderer, wlr_raster);
if (!texture) {
return false;
}
if (texture->dmabuf_imported && !texture->owned) {
// Store this texture in the list of textures that need to be
// acquired before rendering and released after rendering.
@ -776,10 +779,10 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render
struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(final_matrix, vert_pcr_data.mat4);
vert_pcr_data.uv_off[0] = box->x / wlr_texture->width;
vert_pcr_data.uv_off[1] = box->y / wlr_texture->height;
vert_pcr_data.uv_size[0] = box->width / wlr_texture->width;
vert_pcr_data.uv_size[1] = box->height / wlr_texture->height;
vert_pcr_data.uv_off[0] = box->x / wlr_raster->width;
vert_pcr_data.uv_off[1] = box->y / wlr_raster->height;
vert_pcr_data.uv_size[0] = box->width / wlr_raster->width;
vert_pcr_data.uv_size[1] = box->height / wlr_raster->height;
vkCmdPushConstants(cb, renderer->pipe_layout,
VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(vert_pcr_data), &vert_pcr_data);
@ -990,7 +993,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.clear = vulkan_clear,
.scissor = vulkan_scissor,
.raster_upload = _vulkan_raster_upload,
.render_subtexture_with_matrix = vulkan_render_subtexture_with_matrix,
.render_subraster_with_matrix = vulkan_render_subraster_with_matrix,
.render_quad_with_matrix = vulkan_render_quad_with_matrix,
.get_shm_texture_formats = vulkan_get_shm_texture_formats,
.get_dmabuf_texture_formats = vulkan_get_dmabuf_texture_formats,

View file

@ -18,7 +18,7 @@ bool wlr_texture_is_vk(struct wlr_texture *wlr_texture) {
return wlr_texture->impl == &texture_impl;
}
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture) {
static struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_vk(wlr_texture));
return (struct wlr_vk_texture *)wlr_texture;
}

View file

@ -36,7 +36,7 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
assert(impl->clear);
assert(impl->scissor);
assert(impl->raster_upload);
assert(impl->render_subtexture_with_matrix);
assert(impl->render_subraster_with_matrix);
assert(impl->render_quad_with_matrix);
assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps);
@ -119,39 +119,39 @@ bool wlr_renderer_raster_upload(struct wlr_renderer *r,
return r->impl->raster_upload(r, raster);
}
bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
bool wlr_render_raster(struct wlr_renderer *r, struct wlr_raster *raster,
const float projection[static 9], int x, int y, float alpha) {
struct wlr_box box = {
.x = x,
.y = y,
.width = texture->width,
.height = texture->height,
.width = raster->width,
.height = raster->height,
};
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);
return wlr_render_raster_with_matrix(r, raster, matrix, alpha);
}
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const float matrix[static 9],
bool wlr_render_raster_with_matrix(struct wlr_renderer *r,
struct wlr_raster *raster, const float matrix[static 9],
float alpha) {
struct wlr_fbox box = {
.x = 0,
.y = 0,
.width = texture->width,
.height = texture->height,
.width = raster->width,
.height = raster->height,
};
return wlr_render_subtexture_with_matrix(r, texture, &box, matrix, alpha);
return wlr_render_subraster_with_matrix(r, raster, &box, matrix, alpha);
}
bool wlr_render_subtexture_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const struct wlr_fbox *box,
bool wlr_render_subraster_with_matrix(struct wlr_renderer *r,
struct wlr_raster *raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha) {
assert(r->rendering);
return r->impl->render_subtexture_with_matrix(r, texture,
return r->impl->render_subraster_with_matrix(r, raster,
box, matrix, alpha);
}