mesa/st: keep surface_copy arguments positive

The src/dest x,y, and w,h arguments of the pipe->surface_copy
function are unsigned and the drivers aren't expecting negative
(or extremly-large unsigned) values as inputs.  Trim the requests
at the state-tracker level before passing down.
This commit is contained in:
Keith Whitwell
2009-05-07 19:48:06 +01:00
parent 507f4e7a74
commit e90beb93a8
2 changed files with 68 additions and 3 deletions

View File

@@ -910,6 +910,34 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
st_validate_state(st);
if (srcx < 0) {
width -= -srcx;
dstx += -srcx;
srcx = 0;
}
if (srcy < 0) {
height -= -srcy;
dsty += -srcy;
srcy = 0;
}
if (dstx < 0) {
width -= -dstx;
srcx += -dstx;
dstx = 0;
}
if (dsty < 0) {
height -= -dsty;
srcy += -dsty;
dsty = 0;
}
if (width < 0 || height < 0)
return;
if (type == GL_STENCIL) {
/* can't use texturing to do stencil */
copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
@@ -951,15 +979,24 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
}
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
srcy = ctx->DrawBuffer->Height - srcy - height;
if (srcy < 0) {
height -= -srcy;
srcy = 0;
}
if (height < 0)
return;
}
pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, texFormat, 0,
width, height, 1,
PIPE_TEXTURE_USAGE_SAMPLER);
if (!pt)
return;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
srcy = ctx->DrawBuffer->Height - srcy - height;
}
if (srcFormat == texFormat) {
/* copy source framebuffer surface into mipmap/texture */

View File

@@ -1337,6 +1337,34 @@ st_copy_texsubimage(GLcontext *ctx,
return;
}
if (srcX < 0) {
width -= -srcX;
destX += -srcX;
srcX = 0;
}
if (srcY < 0) {
height -= -srcY;
destY += -srcY;
srcY = 0;
}
if (destX < 0) {
width -= -destX;
srcX += -destX;
destX = 0;
}
if (destY < 0) {
height -= -destY;
srcY += -destY;
destY = 0;
}
if (width < 0 || height < 0)
return;
assert(strb);
assert(strb->surface);
assert(stImage->pt);