mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-21 06:46:46 -04:00
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:
parent
45ad3d47ad
commit
248a33a026
20 changed files with 142 additions and 166 deletions
|
|
@ -90,14 +90,14 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_texture *tex = wlr_texture_from_buffer(renderer, buffer);
|
||||
if (tex == NULL) {
|
||||
struct wlr_raster *raster = wlr_raster_create(buffer);
|
||||
if (!raster) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_buffer *dst = wlr_swapchain_acquire(surf->swapchain, NULL);
|
||||
if (!dst) {
|
||||
wlr_texture_destroy(tex);
|
||||
wlr_raster_unlock(raster);
|
||||
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)) {
|
||||
wlr_buffer_unlock(dst);
|
||||
wlr_texture_destroy(tex);
|
||||
wlr_raster_unlock(raster);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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_texture_destroy(tex);
|
||||
wlr_raster_unlock(raster);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,9 +56,8 @@ static void render_surface(struct wlr_surface *surface,
|
|||
struct render_data *rdata = data;
|
||||
struct wlr_output *output = rdata->output;
|
||||
|
||||
struct wlr_texture *texture = wlr_texture_from_buffer(output->renderer,
|
||||
surface->current.buffer);
|
||||
if (texture == NULL) {
|
||||
struct wlr_raster *raster = wlr_raster_create(surface->current.buffer);
|
||||
if (raster == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,11 +74,11 @@ static void render_surface(struct wlr_surface *surface,
|
|||
wlr_matrix_project_box(matrix, &box, transform, 0,
|
||||
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_texture_destroy(texture);
|
||||
wlr_raster_unlock(raster);
|
||||
}
|
||||
|
||||
static void output_handle_frame(struct wl_listener *listener, void *data) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ struct sample_state {
|
|||
struct wl_listener new_input;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_allocator *allocator;
|
||||
struct wlr_texture *cat_texture;
|
||||
struct wlr_raster *cat_raster;
|
||||
struct wlr_output_layout *layout;
|
||||
float x_offs, y_offs;
|
||||
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,
|
||||
&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);
|
||||
}
|
||||
|
||||
|
|
@ -279,9 +279,8 @@ int main(int argc, char *argv[]) {
|
|||
state.new_input.notify = new_input_notify;
|
||||
|
||||
state.renderer = wlr_renderer_autocreate(wlr);
|
||||
state.cat_texture = wlr_texture_from_pixels(state.renderer,
|
||||
DRM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
|
||||
cat_tex.pixel_data);
|
||||
state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ABGR8888,
|
||||
cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
|
||||
state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
|
||||
|
||||
|
|
@ -292,7 +291,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_raster_unlock(state.cat_raster);
|
||||
|
||||
wl_display_destroy(state.display);
|
||||
wlr_output_layout_destroy(state.layout);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ struct sample_state {
|
|||
struct timespec last_frame;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_allocator *allocator;
|
||||
struct wlr_texture *cat_texture;
|
||||
struct wlr_raster *cat_raster;
|
||||
struct wl_list outputs;
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -256,10 +256,9 @@ int main(int argc, char *argv[]) {
|
|||
wlr_backend_destroy(wlr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
state.cat_texture = wlr_texture_from_pixels(state.renderer,
|
||||
DRM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
|
||||
cat_tex.pixel_data);
|
||||
if (!state.cat_texture) {
|
||||
state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ABGR8888,
|
||||
cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
if (!state.cat_raster) {
|
||||
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
@ -273,6 +272,6 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_raster_unlock(state.cat_raster);
|
||||
wl_display_destroy(display);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ struct sample_state {
|
|||
struct wl_display *display;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_allocator *allocator;
|
||||
struct wlr_texture *cat_texture;
|
||||
struct wlr_raster *cat_raster;
|
||||
struct wl_list touch_points;
|
||||
struct timespec last_frame;
|
||||
struct wl_listener new_output;
|
||||
|
|
@ -81,9 +81,9 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
|||
|
||||
struct touch_point *p;
|
||||
wl_list_for_each(p, &sample->touch_points, link) {
|
||||
int x = (int)(p->x * width) - sample->cat_texture->width / 2;
|
||||
int y = (int)(p->y * height) - sample->cat_texture->height / 2;
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
int x = (int)(p->x * width) - sample->cat_raster->width / 2;
|
||||
int y = (int)(p->y * height) - sample->cat_raster->height / 2;
|
||||
wlr_render_raster(sample->renderer, sample->cat_raster,
|
||||
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");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
state.cat_texture = wlr_texture_from_pixels(state.renderer,
|
||||
DRM_FORMAT_ARGB8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
|
||||
cat_tex.pixel_data);
|
||||
if (!state.cat_texture) {
|
||||
state.cat_raster = wlr_raster_from_pixels(DRM_FORMAT_ARGB8888,
|
||||
cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
if (!state.cat_raster) {
|
||||
wlr_log(WLR_ERROR, "Could not start compositor, OOM");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
@ -281,6 +280,6 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_raster_unlock(state.cat_raster);
|
||||
wl_display_destroy(display);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_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_raster *wlr_raster);
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,6 @@ struct wlr_vk_texture {
|
|||
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_raster *wlr_raster);
|
||||
VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/render/wlr_texture.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_raster.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_box;
|
||||
|
|
@ -29,8 +30,8 @@ struct wlr_renderer_impl {
|
|||
void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
|
||||
bool (*raster_upload)(struct wlr_renderer *renderer,
|
||||
struct wlr_raster *raster);
|
||||
bool (*render_subtexture_with_matrix)(struct wlr_renderer *renderer,
|
||||
struct wlr_texture *texture, const struct wlr_fbox *box,
|
||||
bool (*render_subraster_with_matrix)(struct wlr_renderer *renderer,
|
||||
struct wlr_raster *raster, const struct wlr_fbox *box,
|
||||
const float matrix[static 9], float alpha);
|
||||
void (*render_quad_with_matrix)(struct wlr_renderer *renderer,
|
||||
const float color[static 4], const float matrix[static 9]);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
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);
|
||||
/**
|
||||
* 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,
|
||||
struct wlr_texture *texture, const float matrix[static 9], float alpha);
|
||||
bool wlr_render_raster_with_matrix(struct wlr_renderer *r,
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* Renders a solid rectangle in the specified color.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ struct wlr_output_cursor {
|
|||
struct wl_list link;
|
||||
|
||||
// only when using a software cursor without a surface
|
||||
struct wlr_texture *texture;
|
||||
struct wlr_raster *raster;
|
||||
|
||||
// only when using a cursor surface
|
||||
struct wlr_surface *surface;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_damage_ring.h>
|
||||
#include <wlr/types/wlr_raster.h>
|
||||
|
||||
struct wlr_output;
|
||||
struct wlr_output_layout;
|
||||
|
|
@ -147,7 +148,7 @@ struct wlr_scene_buffer {
|
|||
// private state
|
||||
|
||||
uint64_t active_outputs;
|
||||
struct wlr_texture *texture;
|
||||
struct wlr_raster *raster;
|
||||
struct wlr_fbox src_box;
|
||||
int dst_width, dst_height;
|
||||
enum wl_output_transform transform;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,8 +93,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
|||
struct wlr_renderer *renderer = cursor->output->renderer;
|
||||
assert(renderer);
|
||||
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (texture == NULL) {
|
||||
if (!cursor->raster) {
|
||||
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);
|
||||
for (int i = 0; i < nrects; ++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);
|
||||
|
||||
|
|
@ -231,28 +230,28 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
|
||||
float scale = output->scale;
|
||||
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
scale = cursor->surface->current.scale;
|
||||
transform = cursor->surface->current.transform;
|
||||
}
|
||||
if (texture == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_allocator *allocator = output->allocator;
|
||||
struct wlr_renderer *renderer = output->renderer;
|
||||
assert(allocator != NULL && renderer != NULL);
|
||||
|
||||
int width = texture->width;
|
||||
int height = texture->height;
|
||||
if (!cursor->raster) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int width = cursor->raster->width;
|
||||
int height = cursor->raster->height;
|
||||
if (output->impl->get_cursor_size) {
|
||||
// Apply hardware limitations on buffer size
|
||||
output->impl->get_cursor_size(cursor->output, &width, &height);
|
||||
if ((int)texture->width > width || (int)texture->height > height) {
|
||||
wlr_log(WLR_DEBUG, "Cursor texture too large (%dx%d), "
|
||||
"exceeds hardware limitations (%dx%d)", texture->width,
|
||||
texture->height, width, height);
|
||||
if ((int)cursor->raster->width > width || (int)cursor->raster->height > height) {
|
||||
wlr_log(WLR_DEBUG, "Cursor raster too large (%dx%d), "
|
||||
"exceeds hardware limitations (%dx%d)", cursor->raster->width,
|
||||
cursor->raster->height, width, height);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -284,8 +283,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
}
|
||||
|
||||
struct wlr_box cursor_box = {
|
||||
.width = texture->width * output->scale / scale,
|
||||
.height = texture->height * output->scale / scale,
|
||||
.width = cursor->raster->width * output->scale / scale,
|
||||
.height = cursor->raster->height * output->scale / scale,
|
||||
};
|
||||
|
||||
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_render_texture_with_matrix(renderer, texture, matrix, 1.0);
|
||||
wlr_render_raster_with_matrix(renderer, cursor->raster, matrix, 1.0);
|
||||
|
||||
wlr_renderer_end(renderer);
|
||||
|
||||
|
|
@ -333,21 +332,16 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
|
|||
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
|
||||
// cursor position is outdated
|
||||
output->impl->move_cursor(cursor->output,
|
||||
(int)cursor->x, (int)cursor->y);
|
||||
|
||||
struct wlr_buffer *buffer = NULL;
|
||||
if (texture != NULL) {
|
||||
buffer = render_cursor_buffer(cursor);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to render cursor buffer");
|
||||
return false;
|
||||
}
|
||||
buffer = render_cursor_buffer(cursor);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to render cursor buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_box hotspot = {
|
||||
|
|
@ -407,15 +401,16 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
|
|||
|
||||
output_cursor_update_visible(cursor);
|
||||
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
cursor->texture = NULL;
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
cursor->raster = NULL;
|
||||
|
||||
cursor->enabled = false;
|
||||
if (buffer != NULL) {
|
||||
cursor->texture = wlr_texture_from_buffer(renderer, buffer);
|
||||
if (cursor->texture == NULL) {
|
||||
cursor->raster = wlr_raster_create(buffer);
|
||||
if (!cursor->raster) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cursor->enabled = true;
|
||||
}
|
||||
|
||||
|
|
@ -435,18 +430,14 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor,
|
|||
output_cursor_damage_whole(cursor);
|
||||
}
|
||||
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
cursor->raster = NULL;
|
||||
|
||||
struct wlr_surface *surface = cursor->surface;
|
||||
assert(surface != NULL);
|
||||
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
cursor->texture = NULL;
|
||||
|
||||
if (surface->current.buffer) {
|
||||
cursor->texture = wlr_texture_from_buffer(cursor->output->renderer,
|
||||
surface->current.buffer);
|
||||
if (cursor->texture == NULL) {
|
||||
return;
|
||||
}
|
||||
cursor->raster = wlr_raster_create(surface->current.buffer);
|
||||
}
|
||||
|
||||
// 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);
|
||||
cursor->output->hardware_cursor = NULL;
|
||||
}
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
wl_list_remove(&cursor->link);
|
||||
free(cursor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
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);
|
||||
}
|
||||
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
scene_buffer->texture = NULL;
|
||||
wlr_raster_unlock(scene_buffer->raster);
|
||||
scene_buffer->raster = NULL;
|
||||
wlr_buffer_unlock(scene_buffer->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);
|
||||
}
|
||||
|
||||
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,
|
||||
int *width, int *height) {
|
||||
*width = 0;
|
||||
|
|
@ -821,8 +810,8 @@ static void render_rect(struct wlr_output *output,
|
|||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
static void render_texture(struct wlr_output *output,
|
||||
pixman_region32_t *output_damage, struct wlr_texture *texture,
|
||||
static void render_raster(struct wlr_output *output,
|
||||
pixman_region32_t *output_damage, struct wlr_raster *raster,
|
||||
const struct wlr_fbox *src_box, const struct wlr_box *dst_box,
|
||||
const float matrix[static 9]) {
|
||||
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};
|
||||
if (wlr_fbox_empty(src_box)) {
|
||||
default_src_box.width = texture->width;
|
||||
default_src_box.height = texture->height;
|
||||
default_src_box.width = raster->width;
|
||||
default_src_box.height = raster->height;
|
||||
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);
|
||||
for (int i = 0; i < nrects; ++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);
|
||||
|
|
@ -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);
|
||||
scale_box(&dst_box, output->scale);
|
||||
|
||||
struct wlr_texture *texture;
|
||||
float matrix[9];
|
||||
enum wl_output_transform transform;
|
||||
switch (node->type) {
|
||||
|
|
@ -889,18 +877,16 @@ static void render_node_iterator(struct wlr_scene_node *node,
|
|||
return;
|
||||
}
|
||||
|
||||
struct wlr_renderer *renderer = output->renderer;
|
||||
texture = scene_buffer_get_texture(scene_buffer, renderer);
|
||||
if (texture == NULL) {
|
||||
return;
|
||||
if (!scene_buffer->raster) {
|
||||
scene_buffer->raster = wlr_raster_create(scene_buffer->buffer);
|
||||
}
|
||||
|
||||
transform = wlr_output_transform_invert(scene_buffer->transform);
|
||||
wlr_matrix_project_box(matrix, &dst_box, transform, 0.0,
|
||||
output->transform_matrix);
|
||||
|
||||
render_texture(output, output_damage, texture, &scene_buffer->src_box,
|
||||
&dst_box, matrix);
|
||||
render_raster(output, output_damage, scene_buffer->raster,
|
||||
&scene_buffer->src_box, &dst_box, matrix);
|
||||
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_present, scene_output);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -226,14 +226,18 @@ static bool frame_shm_copy(struct wlr_screencopy_frame_v1 *frame,
|
|||
static bool blit_dmabuf(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_v1_buffer *dst_dmabuf,
|
||||
struct wlr_buffer *src_buffer) {
|
||||
struct wlr_buffer *dst_buffer = wlr_buffer_lock(&dst_dmabuf->base);
|
||||
|
||||
struct wlr_texture *src_tex =
|
||||
wlr_texture_from_buffer(renderer, src_buffer);
|
||||
if (src_tex == NULL) {
|
||||
goto error_src_tex;
|
||||
struct wlr_raster *raster = wlr_raster_create(src_buffer);
|
||||
if (!raster){
|
||||
return false;
|
||||
}
|
||||
|
||||
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];
|
||||
wlr_matrix_identity(mat);
|
||||
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_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_texture_destroy(src_tex);
|
||||
wlr_raster_unlock(raster);
|
||||
wlr_buffer_unlock(dst_buffer);
|
||||
return true;
|
||||
|
||||
error_renderer_begin:
|
||||
wlr_texture_destroy(src_tex);
|
||||
error_src_tex:
|
||||
wlr_raster_unlock(raster);
|
||||
wlr_buffer_unlock(dst_buffer);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue