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:
parent
db66a64aab
commit
4fab505b96
|
@ -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,37 +750,32 @@ 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
|
* glReadPixels() returns bottom row first. We need to read into a
|
||||||
* read into a temporary buffer and y-flip it.
|
* temporary buffer and y-flip it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tmp_data = malloc(stride * rect->height);
|
tmp_data = malloc(stride * rect->height);
|
||||||
if (!tmp_data)
|
if (!tmp_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tmp = pixman_image_create_bits(fmt->pixman_format,
|
tmp = pixman_image_create_bits(fmt->pixman_format, rect->width,
|
||||||
rect->width, rect->height,
|
rect->height, tmp_data, stride);
|
||||||
tmp_data, stride);
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
free(tmp_data);
|
free(tmp_data);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_target = pixman_image_get_data(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
pixman_image_t *image;
|
|
||||||
pixman_transform_t flip;
|
|
||||||
|
|
||||||
image = pixman_image_create_bits_no_clear(fmt->pixman_format,
|
image = pixman_image_create_bits_no_clear(fmt->pixman_format,
|
||||||
rect->width,
|
rect->width, rect->height,
|
||||||
rect->height,
|
|
||||||
pixels, stride);
|
pixels, stride);
|
||||||
abort_oom_if_null(image);
|
abort_oom_if_null(image);
|
||||||
|
|
||||||
|
@ -801,7 +797,6 @@ gl_renderer_do_read_pixels(struct gl_renderer *gr,
|
||||||
pixman_image_unref(image);
|
pixman_image_unref(image);
|
||||||
pixman_image_unref(tmp);
|
pixman_image_unref(tmp);
|
||||||
free(tmp_data);
|
free(tmp_data);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue