Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / mesa / state_tracker / st_cb_readpixels.c
index 67c3b9adbb9b62fcb322653025e3acda678999ed..6ab03ec9391d6e916047323e3bcec2f4f86aeee2 100644 (file)
 #include "st_debug.h"
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_cb_bitmap.h"
 #include "st_cb_readpixels.h"
 #include "st_cb_fbo.h"
-#include "st_texture.h"
-#include "st_inlines.h"
 
 /**
  * Special case for reading stencil buffer.
@@ -63,22 +62,26 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
                        GLvoid *pixels)
 {
    struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct pipe_context *pipe = ctx->st->pipe;
+   struct pipe_context *pipe = st_context(ctx)->pipe;
    struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
    struct pipe_transfer *pt;
    ubyte *stmap;
    GLint j;
 
+   if (strb->Base.Wrapped) {
+      strb = st_renderbuffer(strb->Base.Wrapped);
+   }
+
    if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
       y = ctx->DrawBuffer->Height - y - height;
    }
 
    /* Create a read transfer from the renderbuffer's texture */
 
-   pt = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture,
-                                      0, 0, 0,
-                                      PIPE_TRANSFER_READ, x, y,
-                                      width, height);
+   pt = pipe_get_transfer(pipe, strb->texture,
+                          0, 0, 0,  /* face, level, zslice */
+                          PIPE_TRANSFER_READ,
+                          x, y, width, height);
 
    /* map the stencil buffer */
    stmap = pipe_transfer_map(pipe, pt);
@@ -220,7 +223,7 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
    /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/
 
    {
-      struct pipe_context *pipe = ctx->st->pipe;
+      struct pipe_context *pipe = st_context(ctx)->pipe;
       struct pipe_transfer *trans;
       const GLubyte *map;
       GLubyte *dst;
@@ -231,10 +234,10 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
          y = strb->texture->height0 - y - height;
       }
 
-      trans = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture,
-                                            0, 0, 0,
-                                            PIPE_TRANSFER_READ, x, y,
-                                            width, height);
+      trans = pipe_get_transfer(pipe, strb->texture,
+                                0, 0, 0,  /* face, level, zslice */
+                                PIPE_TRANSFER_READ,
+                                x, y, width, height);
       if (!trans) {
          return GL_FALSE;
       }
@@ -322,7 +325,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
               const struct gl_pixelstore_attrib *pack,
               GLvoid *dest)
 {
-   struct pipe_context *pipe = ctx->st->pipe;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
    GLfloat temp[MAX_WIDTH][4];
    const GLbitfield transferOps = ctx->_ImageTransferState;
    GLsizei i, j;
@@ -337,7 +341,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
    /* XXX convolution not done yet */
    assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0);
 
-   st_validate_state(ctx->st);
+   st_validate_state(st);
 
    /* Do all needed clipping here, so that we can forget about it later */
    if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
@@ -345,12 +349,12 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   st_flush_bitmap_cache(st);
+
    dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
    if (!dest)
       return;
 
-   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
    if (format == GL_STENCIL_INDEX ||
        format == GL_DEPTH_STENCIL) {
       st_read_stencil_pixels(ctx, x, y, width, height,
@@ -359,6 +363,9 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
    }
    else if (format == GL_DEPTH_COMPONENT) {
       strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
+      if (strb->Base.Wrapped) {
+         strb = st_renderbuffer(strb->Base.Wrapped);
+      }
    }
    else {
       /* Read color buffer */
@@ -394,10 +401,10 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
    }
 
    /* Create a read transfer from the renderbuffer's texture */
-   trans = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture,
-                                         0, 0, 0,
-                                         PIPE_TRANSFER_READ, x, y,
-                                         width, height);
+   trans = pipe_get_transfer(pipe, strb->texture,
+                             0, 0, 0,  /* face, level, zslice */
+                             PIPE_TRANSFER_READ,
+                             x, y, width, height);
 
    /* determine bottom-to-top vs. top-to-bottom order */
    if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {