render/pixman: drop legacy rendering API

master
Simon Ser 1 year ago
parent 4635717d82
commit 514caea437

@ -180,153 +180,6 @@ static void pixman_end(struct wlr_renderer *wlr_renderer) {
wlr_buffer_end_data_ptr_access(renderer->current_buffer->buffer);
}
static void pixman_clear(struct wlr_renderer *wlr_renderer,
const float color[static 4]) {
struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer);
struct wlr_pixman_buffer *buffer = renderer->current_buffer;
const struct pixman_color colour = {
.red = color[0] * 0xFFFF,
.green = color[1] * 0xFFFF,
.blue = color[2] * 0xFFFF,
.alpha = color[3] * 0xFFFF,
};
pixman_image_t *fill = pixman_image_create_solid_fill(&colour);
pixman_image_composite32(PIXMAN_OP_SRC, fill, NULL, buffer->image, 0, 0, 0,
0, 0, 0, renderer->width, renderer->height);
pixman_image_unref(fill);
}
static void pixman_scissor(struct wlr_renderer *wlr_renderer,
struct wlr_box *box) {
struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer);
struct wlr_pixman_buffer *buffer = renderer->current_buffer;
if (box != NULL) {
struct pixman_region32 region = {0};
pixman_region32_init_rect(&region, box->x, box->y, box->width,
box->height);
pixman_image_set_clip_region32(buffer->image, &region);
pixman_region32_fini(&region);
} else {
pixman_image_set_clip_region32(buffer->image, NULL);
}
}
static void matrix_to_pixman_transform(struct pixman_transform *transform,
const float mat[static 9]) {
struct pixman_f_transform ftr;
ftr.m[0][0] = mat[0];
ftr.m[0][1] = mat[1];
ftr.m[0][2] = mat[2];
ftr.m[1][0] = mat[3];
ftr.m[1][1] = mat[4];
ftr.m[1][2] = mat[5];
ftr.m[2][0] = mat[6];
ftr.m[2][1] = mat[7];
ftr.m[2][2] = mat[8];
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,
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;
if (texture->buffer != NULL && !begin_pixman_data_ptr_access(texture->buffer,
&texture->image, WLR_BUFFER_DATA_PTR_ACCESS_READ)) {
return false;
}
pixman_image_t *mask = NULL;
if (alpha != 1.0) {
struct pixman_color mask_colour = {0};
mask_colour.alpha = 0xFFFF * alpha;
mask = pixman_image_create_solid_fill(&mask_colour);
}
float m[9];
memcpy(m, matrix, sizeof(m));
wlr_matrix_scale(m, 1.0 / fbox->width, 1.0 / fbox->height);
struct pixman_transform transform = {0};
matrix_to_pixman_transform(&transform, m);
pixman_transform_invert(&transform, &transform);
pixman_image_set_transform(texture->image, &transform);
// TODO clip properly with src_x and src_y
pixman_image_composite32(PIXMAN_OP_OVER, texture->image, mask,
buffer->image, 0, 0, 0, 0, 0, 0, renderer->width,
renderer->height);
if (texture->buffer != NULL) {
wlr_buffer_end_data_ptr_access(texture->buffer);
}
if (mask != NULL) {
pixman_image_unref(mask);
}
return true;
}
static void pixman_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
const float color[static 4], const float matrix[static 9]) {
struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer);
struct wlr_pixman_buffer *buffer = renderer->current_buffer;
struct pixman_color colour = {
.red = color[0] * 0xFFFF,
.green = color[1] * 0xFFFF,
.blue = color[2] * 0xFFFF,
.alpha = color[3] * 0xFFFF,
};
pixman_image_t *fill = pixman_image_create_solid_fill(&colour);
float m[9];
memcpy(m, matrix, sizeof(m));
// TODO get the width/height from the caller instead of extracting them
float width, height;
if (matrix[1] == 0.0 && matrix[3] == 0.0) {
width = fabs(matrix[0]);
height = fabs(matrix[4]);
} else {
width = sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]);
height = sqrt(matrix[3] * matrix[3] + matrix[4] * matrix[4]);
}
wlr_matrix_scale(m, 1.0 / width, 1.0 / height);
pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, width,
height, NULL, 0);
// TODO find a way to fill the image without allocating 2 images
pixman_image_composite32(PIXMAN_OP_SRC, fill, NULL, image,
0, 0, 0, 0, 0, 0, width, height);
pixman_image_unref(fill);
struct pixman_transform transform = {0};
matrix_to_pixman_transform(&transform, m);
pixman_transform_invert(&transform, &transform);
pixman_image_set_transform(image, &transform);
pixman_image_composite32(PIXMAN_OP_OVER, image, NULL, buffer->image,
0, 0, 0, 0, 0, 0, renderer->width, renderer->height);
pixman_image_unref(image);
}
static const uint32_t *pixman_get_shm_texture_formats(
struct wlr_renderer *wlr_renderer, size_t *len) {
return get_pixman_drm_formats(len);
@ -513,10 +366,6 @@ static struct wlr_render_pass *pixman_begin_buffer_pass(struct wlr_renderer *wlr
static const struct wlr_renderer_impl renderer_impl = {
.begin = pixman_begin,
.end = pixman_end,
.clear = pixman_clear,
.scissor = pixman_scissor,
.render_subtexture_with_matrix = pixman_render_subtexture_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,
.texture_from_buffer = pixman_texture_from_buffer,

Loading…
Cancel
Save