gl-renderer: Prepare for reset to default pixel storage states

Prepare gl_renderer_do_read_pixels() so that the default pixel storage
states can be more easily reverted to default before return.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2024-07-22 17:10:46 +02:00 committed by Marius Vlad
parent db66a64aab
commit 4fab505b96
1 changed files with 40 additions and 45 deletions

View File

@ -729,9 +729,10 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
void *pixels, int stride, void *pixels, int stride,
const struct weston_geometry *rect) const struct weston_geometry *rect)
{ {
void *read_target;
pixman_image_t *tmp = NULL; pixman_image_t *tmp = NULL;
void *tmp_data = NULL; void *tmp_data = NULL;
pixman_image_t *image;
pixman_transform_t flip;
assert(fmt->gl_type != 0); assert(fmt->gl_type != 0);
assert(fmt->gl_format != 0); assert(fmt->gl_format != 0);
@ -749,59 +750,53 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
if (gr->has_pack_reverse) { if (gr->has_pack_reverse) {
/* Make glReadPixels() return top row first. */ /* Make glReadPixels() return top row first. */
glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE); glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
read_target = pixels; glReadPixels(rect->x, rect->y, rect->width, rect->height,
} else { fmt->gl_format, fmt->gl_type, pixels);
/* return true;
* glReadPixels() returns bottom row first. We need to }
* read into a temporary buffer and y-flip it.
*/
tmp_data = malloc(stride * rect->height);
if (!tmp_data)
return false;
tmp = pixman_image_create_bits(fmt->pixman_format, /*
rect->width, rect->height, * glReadPixels() returns bottom row first. We need to read into a
tmp_data, stride); * temporary buffer and y-flip it.
if (!tmp) { */
free(tmp_data);
return false;
}
read_target = pixman_image_get_data(tmp); tmp_data = malloc(stride * rect->height);
if (!tmp_data)
return false;
tmp = pixman_image_create_bits(fmt->pixman_format, rect->width,
rect->height, tmp_data, stride);
if (!tmp) {
free(tmp_data);
return false;
} }
glReadPixels(rect->x, rect->y, rect->width, rect->height, glReadPixels(rect->x, rect->y, rect->width, rect->height,
fmt->gl_format, fmt->gl_type, read_target); fmt->gl_format, fmt->gl_type, pixman_image_get_data(tmp));
if (tmp) { image = pixman_image_create_bits_no_clear(fmt->pixman_format,
pixman_image_t *image; rect->width, rect->height,
pixman_transform_t flip; pixels, stride);
abort_oom_if_null(image);
image = pixman_image_create_bits_no_clear(fmt->pixman_format, pixman_transform_init_scale(&flip, pixman_fixed_1,
rect->width, pixman_fixed_minus_1);
rect->height, pixman_transform_translate(&flip, NULL, 0,
pixels, stride); pixman_int_to_fixed(rect->height));
abort_oom_if_null(image); pixman_image_set_transform(tmp, &flip);
pixman_transform_init_scale(&flip, pixman_fixed_1, pixman_image_composite32(PIXMAN_OP_SRC,
pixman_fixed_minus_1); tmp, /* src */
pixman_transform_translate(&flip, NULL, 0, NULL, /* mask */
pixman_int_to_fixed(rect->height)); image, /* dest */
pixman_image_set_transform(tmp, &flip); 0, 0, /* src x,y */
0, 0, /* mask x,y */
0, 0, /* dest x,y */
rect->width, rect->height);
pixman_image_composite32(PIXMAN_OP_SRC, pixman_image_unref(image);
tmp, /* src */ pixman_image_unref(tmp);
NULL, /* mask */ free(tmp_data);
image, /* dest */
0, 0, /* src x,y */
0, 0, /* mask x,y */
0, 0, /* dest x,y */
rect->width, rect->height);
pixman_image_unref(image);
pixman_image_unref(tmp);
free(tmp_data);
}
return true; return true;
} }