mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 05:18:08 +02:00
st/mesa: avoid large stack allocations in readpixels code
This commit is contained in:
parent
aa28efe60d
commit
77ea102735
1 changed files with 10 additions and 1 deletions
|
|
@ -328,7 +328,7 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei h
|
|||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
GLfloat temp[MAX_WIDTH][4];
|
||||
GLfloat (*temp)[4];
|
||||
const GLbitfield transferOps = ctx->_ImageTransferState;
|
||||
GLsizei i, j;
|
||||
GLint yStep, dfStride;
|
||||
|
|
@ -381,6 +381,13 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei h
|
|||
return;
|
||||
}
|
||||
|
||||
/* allocate temp pixel row buffer */
|
||||
temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
|
||||
if (!temp) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == GL_RGBA && type == GL_FLOAT) {
|
||||
/* write tile(row) directly into user's buffer */
|
||||
df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
|
||||
|
|
@ -533,6 +540,8 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei h
|
|||
}
|
||||
}
|
||||
|
||||
free(temp);
|
||||
|
||||
pipe->transfer_destroy(pipe, trans);
|
||||
|
||||
_mesa_unmap_pbo_dest(ctx, &clippedPacking);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue