mesa/st: keep surface_copy arguments positive
authorKeith Whitwell <keithw@vmware.com>
Thu, 7 May 2009 18:48:06 +0000 (19:48 +0100)
committerKeith Whitwell <keithw@vmware.com>
Fri, 8 May 2009 13:57:30 +0000 (14:57 +0100)
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.

src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_texture.c

index 08dc7c930e281961feefdd3e684d720d9709a58c..89725cfe8dcbc668a9fdfab297cc889303d85923 100644 (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 */
index 98f109fc6598c8bedef48787c8aa8b6769fa7bb9..b182106fd56e32df9a47cb8af6102376604c5340 100644 (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);