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

@ -90,14 +90,14 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
return NULL; return NULL;
} }
struct wlr_texture *tex = wlr_texture_from_buffer(renderer, buffer); struct wlr_raster *raster = wlr_raster_create(buffer);
if (tex == NULL) { if (!raster) {
return NULL; return NULL;
} }
struct wlr_buffer *dst = wlr_swapchain_acquire(surf->swapchain, NULL); struct wlr_buffer *dst = wlr_swapchain_acquire(surf->swapchain, NULL);
if (!dst) { if (!dst) {
wlr_texture_destroy(tex); wlr_raster_unlock(raster);
return NULL; return NULL;
} }
@ -107,16 +107,15 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
if (!wlr_renderer_begin_with_buffer(renderer, dst)) { if (!wlr_renderer_begin_with_buffer(renderer, dst)) {
wlr_buffer_unlock(dst); wlr_buffer_unlock(dst);
wlr_texture_destroy(tex); wlr_raster_unlock(raster);
return NULL; return NULL;
} }
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 }); wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
wlr_render_texture_with_matrix(renderer, tex, mat, 1.0f); wlr_render_raster_with_matrix(renderer, raster, mat, 1.0f);
wlr_renderer_end(renderer); wlr_renderer_end(renderer);
wlr_raster_unlock(raster);
wlr_texture_destroy(tex);
return dst; return dst;
} }

View file

@ -56,9 +56,8 @@ static void render_surface(struct wlr_surface *surface,
struct render_data *rdata = data; struct render_data *rdata = data;
struct wlr_output *output = rdata->output; struct wlr_output *output = rdata->output;
struct wlr_texture *texture = wlr_texture_from_buffer(output->renderer, struct wlr_raster *raster = wlr_raster_create(surface->current.buffer);
surface->current.buffer); if (raster == NULL) {
if (texture == NULL) {
return; return;
} }
@ -75,11 +74,11 @@ static void render_surface(struct wlr_surface *surface,
wlr_matrix_project_box(matrix, &box, transform, 0, wlr_matrix_project_box(matrix, &box, transform, 0,
output->transform_matrix); output->transform_matrix);
wlr_render_texture_with_matrix(rdata->renderer, texture, matrix, 1); wlr_render_raster_with_matrix(rdata->renderer, raster, matrix, 1);
wlr_surface_send_frame_done(surface, rdata->when); wlr_surface_send_frame_done(surface, rdata->when);
wlr_texture_destroy(texture); wlr_raster_unlock(raster);
} }
static void output_handle_frame(struct wl_listener *listener, void *data) { static void output_handle_frame(struct wl_listener *listener, void *data) {

View file

@ -29,7 +29,7 @@ struct sample_state {
struct wl_listener new_input; struct wl_listener new_input;
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wlr_allocator *allocator; struct wlr_allocator *allocator;
struct wlr_texture *cat_texture; struct wlr_raster *cat_raster;
struct wlr_output_layout *layout; struct wlr_output_layout *layout;
float x_offs, y_offs; float x_offs, y_offs;
float x_vel, y_vel; float x_vel, y_vel;
@ -134,7 +134,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_output_coords(sample->layout, output->output, wlr_output_layout_output_coords(sample->layout, output->output,
&local_x, &local_y); &local_x, &local_y);
wlr_render_texture(sample->renderer, sample->cat_texture, wlr_render_raster(sample->renderer, sample->cat_raster,
wlr_output->transform_matrix, local_x, local_y, 1.0f); wlr_output->transform_matrix, local_x, local_y, 1.0f);
} }
@ -279,9 +279,8 @@ int main(int argc, char *argv[]) {
state.new_input.notify = new_input_notify; state.new_input.notify = new_input_notify;
state.renderer = wlr_renderer_autocreate(wlr); state.renderer = wlr_renderer_autocreate(wlr);
state.cat_texture = wlr_texture_from_pixels(state.renderer, state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ABGR8888,
DRM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
cat_tex.pixel_data);
state.allocator = wlr_allocator_autocreate(wlr, state.renderer); state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
@ -292,7 +291,7 @@ int main(int argc, char *argv[]) {
} }
wl_display_run(display); wl_display_run(display);
wlr_texture_destroy(state.cat_texture); wlr_raster_unlock(state.cat_raster);
wl_display_destroy(state.display); wl_display_destroy(state.display);
wlr_output_layout_destroy(state.layout); wlr_output_layout_destroy(state.layout);

View file

@ -27,7 +27,7 @@ struct sample_state {
struct timespec last_frame; struct timespec last_frame;
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wlr_allocator *allocator; struct wlr_allocator *allocator;
struct wlr_texture *cat_texture; struct wlr_raster *cat_raster;
struct wl_list outputs; struct wl_list outputs;
enum wl_output_transform transform; enum wl_output_transform transform;
}; };
@ -65,7 +65,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
for (int y = -128 + (int)sample_output->y_offs; y < height; y += 128) { for (int y = -128 + (int)sample_output->y_offs; y < height; y += 128) {
for (int x = -128 + (int)sample_output->x_offs; x < width; x += 128) { for (int x = -128 + (int)sample_output->x_offs; x < width; x += 128) {
wlr_render_texture(sample->renderer, sample->cat_texture, wlr_render_raster(sample->renderer, sample->cat_raster,
wlr_output->transform_matrix, x, y, 1.0f); wlr_output->transform_matrix, x, y, 1.0f);
} }
} }
@ -256,10 +256,9 @@ int main(int argc, char *argv[]) {
wlr_backend_destroy(wlr); wlr_backend_destroy(wlr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
state.cat_texture = wlr_texture_from_pixels(state.renderer, state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ABGR8888,
DRM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
cat_tex.pixel_data); if (!state.cat_raster) {
if (!state.cat_texture) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM"); wlr_log(WLR_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -273,6 +272,6 @@ int main(int argc, char *argv[]) {
} }
wl_display_run(display); wl_display_run(display);
wlr_texture_destroy(state.cat_texture); wlr_raster_unlock(state.cat_raster);
wl_display_destroy(display); wl_display_destroy(display);
} }

View file

@ -25,7 +25,7 @@ struct sample_state {
struct wl_display *display; struct wl_display *display;
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wlr_allocator *allocator; struct wlr_allocator *allocator;
struct wlr_texture *cat_texture; struct wlr_raster *cat_raster;
struct wl_list touch_points; struct wl_list touch_points;
struct timespec last_frame; struct timespec last_frame;
struct wl_listener new_output; struct wl_listener new_output;
@ -81,9 +81,9 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
struct touch_point *p; struct touch_point *p;
wl_list_for_each(p, &sample->touch_points, link) { wl_list_for_each(p, &sample->touch_points, link) {
int x = (int)(p->x * width) - sample->cat_texture->width / 2; int x = (int)(p->x * width) - sample->cat_raster->width / 2;
int y = (int)(p->y * height) - sample->cat_texture->height / 2; int y = (int)(p->y * height) - sample->cat_raster->height / 2;
wlr_render_texture(sample->renderer, sample->cat_texture, wlr_render_raster(sample->renderer, sample->cat_raster,
wlr_output->transform_matrix, x, y, 1.0f); wlr_output->transform_matrix, x, y, 1.0f);
} }
@ -264,10 +264,9 @@ int main(int argc, char *argv[]) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM"); wlr_log(WLR_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
state.cat_texture = wlr_texture_from_pixels(state.renderer, state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ARGB8888,
DRM_FORMAT_ARGB8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
cat_tex.pixel_data); if (!state.cat_raster) {
if (!state.cat_texture) {
wlr_log(WLR_ERROR, "Could not start compositor, OOM"); wlr_log(WLR_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -281,6 +280,6 @@ int main(int argc, char *argv[]) {
} }
wl_display_run(display); wl_display_run(display);
wlr_texture_destroy(state.cat_texture); wlr_raster_unlock(state.cat_raster);
wl_display_destroy(display); wl_display_destroy(display);
} }

View file

@ -123,8 +123,6 @@ const uint32_t *get_gles2_shm_formats(const struct wlr_gles2_renderer *renderer,
struct wlr_gles2_renderer *gles2_get_renderer( struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_renderer *wlr_renderer); struct wlr_renderer *wlr_renderer);
struct wlr_gles2_texture *gles2_get_texture(
struct wlr_texture *wlr_texture);
struct wlr_gles2_texture *gles2_raster_upload(struct wlr_gles2_renderer *renderer, struct wlr_gles2_texture *gles2_raster_upload(struct wlr_gles2_renderer *renderer,
struct wlr_raster *wlr_raster); struct wlr_raster *wlr_raster);

View file

@ -255,7 +255,6 @@ struct wlr_vk_texture {
struct wl_listener buffer_destroy; struct wl_listener buffer_destroy;
}; };
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture);
struct wlr_vk_texture *vulkan_raster_upload(struct wlr_vk_renderer *renderer, struct wlr_vk_texture *vulkan_raster_upload(struct wlr_vk_renderer *renderer,
struct wlr_raster *wlr_raster); struct wlr_raster *wlr_raster);
VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,

View file

@ -14,6 +14,7 @@
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h> #include <wlr/render/wlr_texture.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_raster.h>
#include <wlr/render/dmabuf.h> #include <wlr/render/dmabuf.h>
struct wlr_box; struct wlr_box;
@ -29,8 +30,8 @@ struct wlr_renderer_impl {
void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
bool (*raster_upload)(struct wlr_renderer *renderer, bool (*raster_upload)(struct wlr_renderer *renderer,
struct wlr_raster *raster); struct wlr_raster *raster);
bool (*render_subtexture_with_matrix)(struct wlr_renderer *renderer, bool (*render_subraster_with_matrix)(struct wlr_renderer *renderer,
struct wlr_texture *texture, const struct wlr_fbox *box, struct wlr_raster *raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha); const float matrix[static 9], float alpha);
void (*render_quad_with_matrix)(struct wlr_renderer *renderer, void (*render_quad_with_matrix)(struct wlr_renderer *renderer,
const float color[static 4], const float matrix[static 9]); const float color[static 4], const float matrix[static 9]);

View file

@ -57,21 +57,21 @@ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box);
bool wlr_renderer_raster_upload(struct wlr_renderer *r, bool wlr_renderer_raster_upload(struct wlr_renderer *r,
struct wlr_raster *raster); struct wlr_raster *raster);
/** /**
* Renders the requested texture. * Renders the requested 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); const float projection[static 9], int x, int y, float alpha);
/** /**
* Renders the requested texture using the provided matrix. * Renders the requested raster using the provided matrix.
*/ */
bool wlr_render_texture_with_matrix(struct wlr_renderer *r, bool wlr_render_raster_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const float matrix[static 9], float alpha); struct wlr_raster *raster, const float matrix[static 9], float alpha);
/** /**
* Renders the requested texture using the provided matrix, after cropping it * Renders the requested raster using the provided matrix, after cropping it
* to the provided rectangle. * to the provided rectangle.
*/ */
bool wlr_render_subtexture_with_matrix(struct wlr_renderer *r, bool wlr_render_subraster_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const struct wlr_fbox *box, struct wlr_raster *raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha); const float matrix[static 9], float alpha);
/** /**
* Renders a solid rectangle in the specified color. * Renders a solid rectangle in the specified color.

View file

@ -34,7 +34,7 @@ struct wlr_output_cursor {
struct wl_list link; struct wl_list link;
// only when using a software cursor without a surface // only when using a software cursor without a surface
struct wlr_texture *texture; struct wlr_raster *raster;
// only when using a cursor surface // only when using a cursor surface
struct wlr_surface *surface; struct wlr_surface *surface;

View file

@ -23,6 +23,7 @@
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_damage_ring.h> #include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_raster.h>
struct wlr_output; struct wlr_output;
struct wlr_output_layout; struct wlr_output_layout;
@ -147,7 +148,7 @@ struct wlr_scene_buffer {
// private state // private state
uint64_t active_outputs; uint64_t active_outputs;
struct wlr_texture *texture; struct wlr_raster *raster;
struct wlr_fbox src_box; struct wlr_fbox src_box;
int dst_width, dst_height; int dst_width, dst_height;
enum wl_output_transform transform; enum wl_output_transform transform;

View file

@ -246,15 +246,17 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer,
pop_gles2_debug(renderer); pop_gles2_debug(renderer);
} }
static bool gles2_render_subtexture_with_matrix( static bool gles2_render_subraster_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture, struct wlr_renderer *wlr_renderer, struct wlr_raster *wlr_raster,
const struct wlr_fbox *box, const float matrix[static 9], const struct wlr_fbox *box, const float matrix[static 9],
float alpha) { float alpha) {
struct wlr_gles2_renderer *renderer = struct wlr_gles2_renderer *renderer =
gles2_get_renderer_in_context(wlr_renderer); gles2_get_renderer_in_context(wlr_renderer);
struct wlr_gles2_texture *texture = struct wlr_gles2_texture *texture =
gles2_get_texture(wlr_texture); gles2_raster_upload(renderer, wlr_raster);
assert(texture->renderer == renderer); if (!texture) {
return false;
}
struct wlr_gles2_tex_shader *shader = NULL; struct wlr_gles2_tex_shader *shader = NULL;
@ -305,10 +307,10 @@ static bool gles2_render_subtexture_with_matrix(
glUniform1i(shader->tex, 0); glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha); glUniform1f(shader->alpha, alpha);
const GLfloat x1 = box->x / wlr_texture->width; const GLfloat x1 = box->x / wlr_raster->width;
const GLfloat y1 = box->y / wlr_texture->height; const GLfloat y1 = box->y / wlr_raster->height;
const GLfloat x2 = (box->x + box->width) / wlr_texture->width; const GLfloat x2 = (box->x + box->width) / wlr_raster->width;
const GLfloat y2 = (box->y + box->height) / wlr_texture->height; const GLfloat y2 = (box->y + box->height) / wlr_raster->height;
const GLfloat texcoord[] = { const GLfloat texcoord[] = {
x2, y1, // top right x2, y1, // top right
x1, y1, // top left x1, y1, // top left
@ -549,7 +551,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.clear = gles2_clear, .clear = gles2_clear,
.scissor = gles2_scissor, .scissor = gles2_scissor,
.raster_upload = _gles2_raster_upload, .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, .render_quad_with_matrix = gles2_render_quad_with_matrix,
.get_shm_texture_formats = gles2_get_shm_texture_formats, .get_shm_texture_formats = gles2_get_shm_texture_formats,
.get_dmabuf_texture_formats = gles2_get_dmabuf_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; 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) { struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_gles2(wlr_texture)); assert(wlr_texture_is_gles2(wlr_texture));
return (struct wlr_gles2_texture *)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; 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( static struct wlr_pixman_texture *pixman_texture_create(
struct wlr_pixman_renderer *renderer, uint32_t drm_format, struct wlr_pixman_renderer *renderer, uint32_t drm_format,
uint32_t width, uint32_t height) { 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); pixman_transform_from_pixman_f_transform(transform, &ftr);
} }
static bool pixman_render_subtexture_with_matrix( static bool pixman_render_subraster_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture, struct wlr_renderer *wlr_renderer, struct wlr_raster *wlr_raster,
const struct wlr_fbox *fbox, const float matrix[static 9], const struct wlr_fbox *fbox, const float matrix[static 9],
float alpha) { float alpha) {
struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer); 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_buffer *buffer = renderer->current_buffer;
struct wlr_pixman_texture *texture = raster_upload(renderer, wlr_raster);
if (!texture){
return false;
}
if (texture->buffer != NULL) { if (texture->buffer != NULL) {
void *data; void *data;
@ -530,7 +527,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.clear = pixman_clear, .clear = pixman_clear,
.scissor = pixman_scissor, .scissor = pixman_scissor,
.raster_upload = pixman_raster_upload, .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, .render_quad_with_matrix = pixman_render_quad_with_matrix,
.get_shm_texture_formats = pixman_get_shm_texture_formats, .get_shm_texture_formats = pixman_get_shm_texture_formats,
.get_render_formats = pixman_get_render_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, static bool vulkan_render_subraster_with_matrix(struct wlr_renderer *wlr_renderer,
struct wlr_texture *wlr_texture, const struct wlr_fbox *box, struct wlr_raster *wlr_raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha) { const float matrix[static 9], float alpha) {
struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer); struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer);
VkCommandBuffer cb = renderer->cb; VkCommandBuffer cb = renderer->cb;
struct wlr_vk_texture *texture = vulkan_get_texture(wlr_texture); struct wlr_vk_texture *texture = vulkan_raster_upload(renderer, wlr_raster);
assert(texture->renderer == renderer); if (!texture) {
return false;
}
if (texture->dmabuf_imported && !texture->owned) { if (texture->dmabuf_imported && !texture->owned) {
// Store this texture in the list of textures that need to be // Store this texture in the list of textures that need to be
// acquired before rendering and released after rendering. // 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; struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(final_matrix, vert_pcr_data.mat4); 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[0] = box->x / wlr_raster->width;
vert_pcr_data.uv_off[1] = box->y / wlr_texture->height; vert_pcr_data.uv_off[1] = box->y / wlr_raster->height;
vert_pcr_data.uv_size[0] = box->width / wlr_texture->width; vert_pcr_data.uv_size[0] = box->width / wlr_raster->width;
vert_pcr_data.uv_size[1] = box->height / wlr_texture->height; vert_pcr_data.uv_size[1] = box->height / wlr_raster->height;
vkCmdPushConstants(cb, renderer->pipe_layout, vkCmdPushConstants(cb, renderer->pipe_layout,
VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(vert_pcr_data), &vert_pcr_data); 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, .clear = vulkan_clear,
.scissor = vulkan_scissor, .scissor = vulkan_scissor,
.raster_upload = _vulkan_raster_upload, .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, .render_quad_with_matrix = vulkan_render_quad_with_matrix,
.get_shm_texture_formats = vulkan_get_shm_texture_formats, .get_shm_texture_formats = vulkan_get_shm_texture_formats,
.get_dmabuf_texture_formats = vulkan_get_dmabuf_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; 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)); assert(wlr_texture_is_vk(wlr_texture));
return (struct wlr_vk_texture *)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->clear);
assert(impl->scissor); assert(impl->scissor);
assert(impl->raster_upload); assert(impl->raster_upload);
assert(impl->render_subtexture_with_matrix); assert(impl->render_subraster_with_matrix);
assert(impl->render_quad_with_matrix); assert(impl->render_quad_with_matrix);
assert(impl->get_shm_texture_formats); assert(impl->get_shm_texture_formats);
assert(impl->get_render_buffer_caps); 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); 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) { const float projection[static 9], int x, int y, float alpha) {
struct wlr_box box = { struct wlr_box box = {
.x = x, .x = x,
.y = y, .y = y,
.width = texture->width, .width = raster->width,
.height = texture->height, .height = raster->height,
}; };
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
projection); 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, bool wlr_render_raster_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const float matrix[static 9], struct wlr_raster *raster, const float matrix[static 9],
float alpha) { float alpha) {
struct wlr_fbox box = { struct wlr_fbox box = {
.x = 0, .x = 0,
.y = 0, .y = 0,
.width = texture->width, .width = raster->width,
.height = texture->height, .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, bool wlr_render_subraster_with_matrix(struct wlr_renderer *r,
struct wlr_texture *texture, const struct wlr_fbox *box, struct wlr_raster *raster, const struct wlr_fbox *box,
const float matrix[static 9], float alpha) { const float matrix[static 9], float alpha) {
assert(r->rendering); assert(r->rendering);
return r->impl->render_subtexture_with_matrix(r, texture, return r->impl->render_subraster_with_matrix(r, raster,
box, matrix, alpha); box, matrix, alpha);
} }

View file

@ -93,8 +93,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
struct wlr_renderer *renderer = cursor->output->renderer; struct wlr_renderer *renderer = cursor->output->renderer;
assert(renderer); assert(renderer);
struct wlr_texture *texture = cursor->texture; if (!cursor->raster) {
if (texture == NULL) {
return; return;
} }
@ -118,7 +117,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects); pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
for (int i = 0; i < nrects; ++i) { for (int i = 0; i < nrects; ++i) {
output_scissor(cursor->output, &rects[i]); output_scissor(cursor->output, &rects[i]);
wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0f); wlr_render_raster_with_matrix(renderer, cursor->raster, matrix, 1.0f);
} }
wlr_renderer_scissor(renderer, NULL); wlr_renderer_scissor(renderer, NULL);
@ -231,28 +230,28 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
float scale = output->scale; float scale = output->scale;
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
struct wlr_texture *texture = cursor->texture;
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
scale = cursor->surface->current.scale; scale = cursor->surface->current.scale;
transform = cursor->surface->current.transform; transform = cursor->surface->current.transform;
} }
if (texture == NULL) {
return NULL;
}
struct wlr_allocator *allocator = output->allocator; struct wlr_allocator *allocator = output->allocator;
struct wlr_renderer *renderer = output->renderer; struct wlr_renderer *renderer = output->renderer;
assert(allocator != NULL && renderer != NULL); assert(allocator != NULL && renderer != NULL);
int width = texture->width; if (!cursor->raster) {
int height = texture->height; return NULL;
}
int width = cursor->raster->width;
int height = cursor->raster->height;
if (output->impl->get_cursor_size) { if (output->impl->get_cursor_size) {
// Apply hardware limitations on buffer size // Apply hardware limitations on buffer size
output->impl->get_cursor_size(cursor->output, &width, &height); output->impl->get_cursor_size(cursor->output, &width, &height);
if ((int)texture->width > width || (int)texture->height > height) { if ((int)cursor->raster->width > width || (int)cursor->raster->height > height) {
wlr_log(WLR_DEBUG, "Cursor texture too large (%dx%d), " wlr_log(WLR_DEBUG, "Cursor raster too large (%dx%d), "
"exceeds hardware limitations (%dx%d)", texture->width, "exceeds hardware limitations (%dx%d)", cursor->raster->width,
texture->height, width, height); cursor->raster->height, width, height);
return NULL; return NULL;
} }
} }
@ -284,8 +283,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
} }
struct wlr_box cursor_box = { struct wlr_box cursor_box = {
.width = texture->width * output->scale / scale, .width = cursor->raster->width * output->scale / scale,
.height = texture->height * output->scale / scale, .height = cursor->raster->height * output->scale / scale,
}; };
float output_matrix[9]; float output_matrix[9];
@ -313,7 +312,7 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
} }
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 }); wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0); wlr_render_raster_with_matrix(renderer, cursor->raster, matrix, 1.0);
wlr_renderer_end(renderer); wlr_renderer_end(renderer);
@ -333,21 +332,16 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
return false; return false;
} }
// TODO: try using the surface buffer directly
struct wlr_texture *texture = cursor->texture;
// If the cursor was hidden or was a software cursor, the hardware // If the cursor was hidden or was a software cursor, the hardware
// cursor position is outdated // cursor position is outdated
output->impl->move_cursor(cursor->output, output->impl->move_cursor(cursor->output,
(int)cursor->x, (int)cursor->y); (int)cursor->x, (int)cursor->y);
struct wlr_buffer *buffer = NULL; struct wlr_buffer *buffer = NULL;
if (texture != NULL) { buffer = render_cursor_buffer(cursor);
buffer = render_cursor_buffer(cursor); if (buffer == NULL) {
if (buffer == NULL) { wlr_log(WLR_ERROR, "Failed to render cursor buffer");
wlr_log(WLR_ERROR, "Failed to render cursor buffer"); return false;
return false;
}
} }
struct wlr_box hotspot = { struct wlr_box hotspot = {
@ -407,15 +401,16 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
output_cursor_update_visible(cursor); output_cursor_update_visible(cursor);
wlr_texture_destroy(cursor->texture); wlr_raster_unlock(cursor->raster);
cursor->texture = NULL; cursor->raster = NULL;
cursor->enabled = false; cursor->enabled = false;
if (buffer != NULL) { if (buffer != NULL) {
cursor->texture = wlr_texture_from_buffer(renderer, buffer); cursor->raster = wlr_raster_create(buffer);
if (cursor->texture == NULL) { if (!cursor->raster) {
return false; return false;
} }
cursor->enabled = true; cursor->enabled = true;
} }
@ -435,18 +430,14 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor,
output_cursor_damage_whole(cursor); output_cursor_damage_whole(cursor);
} }
wlr_raster_unlock(cursor->raster);
cursor->raster = NULL;
struct wlr_surface *surface = cursor->surface; struct wlr_surface *surface = cursor->surface;
assert(surface != NULL); assert(surface != NULL);
wlr_texture_destroy(cursor->texture);
cursor->texture = NULL;
if (surface->current.buffer) { if (surface->current.buffer) {
cursor->texture = wlr_texture_from_buffer(cursor->output->renderer, cursor->raster = wlr_raster_create(surface->current.buffer);
surface->current.buffer);
if (cursor->texture == NULL) {
return;
}
} }
// Some clients commit a cursor surface with a NULL buffer to hide it. // Some clients commit a cursor surface with a NULL buffer to hide it.
@ -593,7 +584,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
output_set_hardware_cursor(cursor->output, NULL, 0, 0); output_set_hardware_cursor(cursor->output, NULL, 0, 0);
cursor->output->hardware_cursor = NULL; cursor->output->hardware_cursor = NULL;
} }
wlr_texture_destroy(cursor->texture); wlr_raster_unlock(cursor->raster);
wl_list_remove(&cursor->link); wl_list_remove(&cursor->link);
free(cursor); free(cursor);
} }

View file

@ -101,7 +101,7 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) {
} }
} }
wlr_texture_destroy(scene_buffer->texture); wlr_raster_unlock(scene_buffer->raster);
wlr_buffer_unlock(scene_buffer->buffer); wlr_buffer_unlock(scene_buffer->buffer);
} else if (node->type == WLR_SCENE_NODE_TREE) { } else if (node->type == WLR_SCENE_NODE_TREE) {
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node); struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
@ -345,8 +345,8 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
scene_node_damage_whole(&scene_buffer->node); scene_node_damage_whole(&scene_buffer->node);
} }
wlr_texture_destroy(scene_buffer->texture); wlr_raster_unlock(scene_buffer->raster);
scene_buffer->texture = NULL; scene_buffer->raster = NULL;
wlr_buffer_unlock(scene_buffer->buffer); wlr_buffer_unlock(scene_buffer->buffer);
if (buffer) { if (buffer) {
@ -475,17 +475,6 @@ void wlr_scene_buffer_send_frame_done(struct wlr_scene_buffer *scene_buffer,
wlr_signal_emit_safe(&scene_buffer->events.frame_done, now); wlr_signal_emit_safe(&scene_buffer->events.frame_done, now);
} }
static struct wlr_texture *scene_buffer_get_texture(
struct wlr_scene_buffer *scene_buffer, struct wlr_renderer *renderer) {
if (scene_buffer->texture != NULL) {
return scene_buffer->texture;
}
scene_buffer->texture =
wlr_texture_from_buffer(renderer, scene_buffer->buffer);
return scene_buffer->texture;
}
static void scene_node_get_size(struct wlr_scene_node *node, static void scene_node_get_size(struct wlr_scene_node *node,
int *width, int *height) { int *width, int *height) {
*width = 0; *width = 0;
@ -821,8 +810,8 @@ static void render_rect(struct wlr_output *output,
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
} }
static void render_texture(struct wlr_output *output, static void render_raster(struct wlr_output *output,
pixman_region32_t *output_damage, struct wlr_texture *texture, pixman_region32_t *output_damage, struct wlr_raster *raster,
const struct wlr_fbox *src_box, const struct wlr_box *dst_box, const struct wlr_fbox *src_box, const struct wlr_box *dst_box,
const float matrix[static 9]) { const float matrix[static 9]) {
struct wlr_renderer *renderer = output->renderer; struct wlr_renderer *renderer = output->renderer;
@ -830,8 +819,8 @@ static void render_texture(struct wlr_output *output,
struct wlr_fbox default_src_box = {0}; struct wlr_fbox default_src_box = {0};
if (wlr_fbox_empty(src_box)) { if (wlr_fbox_empty(src_box)) {
default_src_box.width = texture->width; default_src_box.width = raster->width;
default_src_box.height = texture->height; default_src_box.height = raster->height;
src_box = &default_src_box; src_box = &default_src_box;
} }
@ -845,7 +834,7 @@ static void render_texture(struct wlr_output *output,
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) { for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]); scissor_output(output, &rects[i]);
wlr_render_subtexture_with_matrix(renderer, texture, src_box, matrix, 1.0); wlr_render_subraster_with_matrix(renderer, raster, src_box, matrix, 1.0);
} }
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
@ -870,7 +859,6 @@ static void render_node_iterator(struct wlr_scene_node *node,
scene_node_get_size(node, &dst_box.width, &dst_box.height); scene_node_get_size(node, &dst_box.width, &dst_box.height);
scale_box(&dst_box, output->scale); scale_box(&dst_box, output->scale);
struct wlr_texture *texture;
float matrix[9]; float matrix[9];
enum wl_output_transform transform; enum wl_output_transform transform;
switch (node->type) { switch (node->type) {
@ -889,18 +877,16 @@ static void render_node_iterator(struct wlr_scene_node *node,
return; return;
} }
struct wlr_renderer *renderer = output->renderer; if (!scene_buffer->raster) {
texture = scene_buffer_get_texture(scene_buffer, renderer); scene_buffer->raster = wlr_raster_create(scene_buffer->buffer);
if (texture == NULL) {
return;
} }
transform = wlr_output_transform_invert(scene_buffer->transform); transform = wlr_output_transform_invert(scene_buffer->transform);
wlr_matrix_project_box(matrix, &dst_box, transform, 0.0, wlr_matrix_project_box(matrix, &dst_box, transform, 0.0,
output->transform_matrix); output->transform_matrix);
render_texture(output, output_damage, texture, &scene_buffer->src_box, render_raster(output, output_damage, scene_buffer->raster,
&dst_box, matrix); &scene_buffer->src_box, &dst_box, matrix);
wlr_signal_emit_safe(&scene_buffer->events.output_present, scene_output); wlr_signal_emit_safe(&scene_buffer->events.output_present, scene_output);
break; break;

View file

@ -226,14 +226,18 @@ static bool frame_shm_copy(struct wlr_screencopy_frame_v1 *frame,
static bool blit_dmabuf(struct wlr_renderer *renderer, static bool blit_dmabuf(struct wlr_renderer *renderer,
struct wlr_dmabuf_v1_buffer *dst_dmabuf, struct wlr_dmabuf_v1_buffer *dst_dmabuf,
struct wlr_buffer *src_buffer) { struct wlr_buffer *src_buffer) {
struct wlr_buffer *dst_buffer = wlr_buffer_lock(&dst_dmabuf->base); struct wlr_raster *raster = wlr_raster_create(src_buffer);
if (!raster){
struct wlr_texture *src_tex = return false;
wlr_texture_from_buffer(renderer, src_buffer);
if (src_tex == NULL) {
goto error_src_tex;
} }
if (!wlr_renderer_raster_upload(renderer, raster)) {
wlr_raster_unlock(raster);
return false;
}
struct wlr_buffer *dst_buffer = wlr_buffer_lock(&dst_dmabuf->base);
float mat[9]; float mat[9];
wlr_matrix_identity(mat); wlr_matrix_identity(mat);
wlr_matrix_scale(mat, dst_buffer->width, dst_buffer->height); wlr_matrix_scale(mat, dst_buffer->width, dst_buffer->height);
@ -243,17 +247,16 @@ static bool blit_dmabuf(struct wlr_renderer *renderer,
} }
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 }); wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
wlr_render_texture_with_matrix(renderer, src_tex, mat, 1.0f); wlr_render_raster_with_matrix(renderer, raster, mat, 1.0f);
wlr_renderer_end(renderer); wlr_renderer_end(renderer);
wlr_texture_destroy(src_tex); wlr_raster_unlock(raster);
wlr_buffer_unlock(dst_buffer); wlr_buffer_unlock(dst_buffer);
return true; return true;
error_renderer_begin: error_renderer_begin:
wlr_texture_destroy(src_tex); wlr_raster_unlock(raster);
error_src_tex:
wlr_buffer_unlock(dst_buffer); wlr_buffer_unlock(dst_buffer);
return false; return false;
} }