Merge branch '7.8'
authorBrian Paul <brianp@vmware.com>
Wed, 17 Mar 2010 16:13:51 +0000 (10:13 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 17 Mar 2010 16:13:51 +0000 (10:13 -0600)
Conflicts:

src/mesa/state_tracker/st_cb_drawpixels.c

1  2 
src/mesa/state_tracker/st_cb_drawpixels.c

index 75be79fd4b01ecade82b77f36baa42c8f31d2275,7c611cb4ec965802b984c71434f9c2e858e2d252..72a2ddb379ba37ba85f37c7b0647caf78aaaaf4a
@@@ -964,10 -934,12 +964,12 @@@ st_CopyPixels(GLcontext *ctx, GLint src
     struct st_renderbuffer *rbRead;
     void *driver_vp, *driver_fp;
     struct pipe_texture *pt;
 +   struct pipe_sampler_view *sv;
     GLfloat *color;
     enum pipe_format srcFormat, texFormat;
 -   int ptw, pth;
     GLboolean invertTex = GL_FALSE;
+    GLint readX, readY, readW, readH;
+    struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
  
     pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
  
        invertTex = !invertTex;
     }
  
 -   /* Need to use POT texture? */
 -   ptw = width;
 -   pth = height;
 -   if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
 -      int l2pt, maxSize;
 -
 -      l2pt = util_logbase2(width);
 -      if (1<<l2pt != width) {
 -         ptw = 1<<(l2pt+1);
 -      }
 -      l2pt = util_logbase2(height);
 -      if (1<<l2pt != height) {
 -         pth = 1<<(l2pt+1);
 -      }
 -
 -      /* Check against maximum texture size */
 -      maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
 -      assert(ptw <= maxSize);
 -      assert(pth <= maxSize);
 -   }
 -
 -   pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
 -                          ptw, pth, 1,
 -                          PIPE_TEXTURE_USAGE_SAMPLER);
+    /* Clip the read region against the src buffer bounds.
+     * We'll still allocate a temporary buffer/texture for the original
+     * src region size but we'll only read the region which is on-screen.
+     * This may mean that we draw garbage pixels into the dest region, but
+     * that's expected.
+     */
+    readX = srcx;
+    readY = srcy;
+    readW = width;
+    readH = height;
+    _mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &unpack);
+    readW = MAX2(0, readW);
+    readH = MAX2(0, readH);
 +   /* alloc temporary texture */
 +   pt = alloc_texture(st, width, height, texFormat);
     if (!pt)
        return;
  
 +   sv = st_sampler_view_from_texture(st->pipe, pt);
 +   if (!sv) {
 +      pipe_texture_reference(&pt, NULL);
 +      return;
 +   }
 +
     /* Make temporary texture which is a copy of the src region.
-     * We'll draw a quad with this texture to draw the dest image.
      */
     if (srcFormat == texFormat) {
        /* copy source framebuffer surface into mipmap/texture */
        if (type == GL_COLOR) {
           /* alternate path using get/put_tile() */
           GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-          pipe_get_tile_rgba(pipe, ptRead, 0, 0, width, height, buf);
-          pipe_put_tile_rgba(pipe, ptTex, 0, 0, width, height, buf);
 -         pipe_get_tile_rgba(ptRead, readX, readY, readW, readH, buf);
 -         pipe_put_tile_rgba(ptTex, unpack.SkipPixels, unpack.SkipRows,
++         pipe_get_tile_rgba(pipe, ptRead, readX, readY, readW, readH, buf);
++         pipe_put_tile_rgba(pipe, ptTex, unpack.SkipPixels, unpack.SkipRows,
+                             readW, readH, buf);
           free(buf);
        }
        else {
           /* GL_DEPTH */
           GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
-          pipe_get_tile_z(pipe, ptRead, 0, 0, width, height, buf);
-          pipe_put_tile_z(pipe, ptTex, 0, 0, width, height, buf);
 -         pipe_get_tile_z(ptRead, readX, readY, readW, readH, buf);
 -         pipe_put_tile_z(ptTex, unpack.SkipPixels, unpack.SkipRows,
 -                            readW, readH, buf);
++         pipe_get_tile_z(pipe, ptRead, readX, readY, readW, readH, buf);
++         pipe_put_tile_z(pipe, ptTex, unpack.SkipPixels, unpack.SkipRows,
++                         readW, readH, buf);
           free(buf);
        }
  
 -      screen->tex_transfer_destroy(ptRead);
 -      screen->tex_transfer_destroy(ptTex);
 +      pipe->tex_transfer_destroy(pipe, ptRead);
 +      pipe->tex_transfer_destroy(pipe, ptTex);
     }
  
-    /* draw textured quad */
+    /* OK, the texture 'pt' contains the src image/pixels.  Now draw a
+     * textured quad with that texture.
+     */
     draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
                        width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
 -                      pt
 +                      sv
                        driver_vp, 
                        driver_fp,
                        color, invertTex);