From 5115c7d935ec645f595d5165b19212fea5432794 Mon Sep 17 00:00:00 2001
From: nobled <nobled@dreamwidth.org>
Date: Tue, 11 Oct 2011 20:34:16 +0000
Subject: [PATCH 2/9] st/dri: factor out software texbuffer code

---
 src/gallium/state_trackers/dri/sw/dri_drawable.c |   72 ++++++++++++----------
 1 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c b/src/gallium/state_trackers/dri/sw/dri_drawable.c
index 05c64b6..66997fb 100644
--- a/src/gallium/state_trackers/dri/sw/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c
@@ -187,6 +187,44 @@ dri_drawable_validate_att(struct dri_drawable *drawable,
    drawable->base.validate(&drawable->base, statts, count, NULL);
 }
 
+static void
+drisw_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
+                    struct pipe_resource *res)
+{
+   struct st_context *stctx = (struct st_context *)ctx->st;
+   struct pipe_context *pipe = stctx->pipe;
+   struct pipe_transfer *tex_xfer;
+   char *map;
+   __DRIscreen *sPriv = dPriv->driScreenPriv;
+   int x, y, w, h, line, ximage_stride;
+
+   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h,
+                                         dPriv->loaderPrivate);
+
+   tex_xfer = pipe_get_transfer(pipe, res,
+                                0, 0,    /* level, layer */
+                                PIPE_TRANSFER_WRITE,
+                                x, y,
+                                w, h);
+
+   map = pipe_transfer_map(pipe, tex_xfer);
+
+   /* Copy the Drawable content to the mapped texture buffer */
+   sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
+                                  dPriv->loaderPrivate);
+
+   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
+      We assume 32 bit pixels. */
+   ximage_stride = w * 4;
+   for (line = h-1; line; --line) {
+      memmove(&map[line * tex_xfer->stride],
+              &map[line * ximage_stride], ximage_stride);
+   }
+
+   pipe_transfer_unmap(pipe, tex_xfer);
+   pipe_transfer_destroy(pipe, tex_xfer);
+}
+
 /**
  * These are used for GLX_EXT_texture_from_pixmap
  */
@@ -197,15 +235,7 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
    struct dri_context *ctx = dri_context(pDRICtx);
    struct dri_drawable *drawable = dri_drawable(dPriv);
    struct pipe_resource *res;
-   struct st_context *stctx = (struct st_context *)ctx->st;
-   struct pipe_context *pipe = stctx->pipe;
-   struct pipe_transfer *tex_xfer;
-   char *map;
-   __DRIscreen *sPriv = dPriv->driScreenPriv;
-   int x, y, w, h, line, ximage_stride;
 
-   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h, dPriv->loaderPrivate);
-         
    dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
 
    /* Use the pipe resource associated with the X drawable */
@@ -228,30 +258,8 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
          }
       }
 
-
-      tex_xfer = pipe_get_transfer(pipe, res,
-                                    0, 0,    // level, layer
-                                    PIPE_TRANSFER_WRITE,
-                                    x, y,
-                                    w, h);
-
-
-      map = pipe_transfer_map(pipe, tex_xfer);
- 
-      /* Copy the Drawable content to the mapped texture buffer */
-      sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
-				   dPriv->loaderPrivate);
-
-      /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
-         We assume 32 bit pixels. */
-      ximage_stride = w * 4;      
-      for (line = h-1; line; --line) {
-         memmove(&map[line * tex_xfer->stride], &map[line * ximage_stride], ximage_stride);
-      }
-
-      pipe_transfer_unmap(pipe, tex_xfer);
-
-      pipe_transfer_destroy(pipe, tex_xfer);
+      /* needed only for drisw: */
+      drisw_copy_drawable(ctx, dPriv, res);
 
       ctx->st->teximage(ctx->st,
             (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT,
-- 
1.7.6.msysgit.0

