Mesa (master): python: Use transfer object to read from a surface.

Michał Król michal at kemper.freedesktop.org
Mon Mar 16 15:48:46 UTC 2009


Module: Mesa
Branch: master
Commit: d8445e8fe1cea08e4b3e6f510a82360b76977937
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d8445e8fe1cea08e4b3e6f510a82360b76977937

Author: Michal Krol <michal at vmware.com>
Date:   Mon Mar 16 16:48:18 2009 +0100

python: Use transfer object to read from a surface.

---

 src/gallium/state_trackers/python/st_sample.c |   48 ++++++++++++++++--------
 1 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c
index 7765df3..092b7f3 100644
--- a/src/gallium/state_trackers/python/st_sample.c
+++ b/src/gallium/state_trackers/python/st_sample.c
@@ -524,26 +524,42 @@ st_sample_pixel_block(enum pipe_format format,
 void
 st_sample_surface(struct pipe_surface *surface, float *rgba) 
 {
-   const struct pipe_format_block *block = &surface->block;
-   unsigned rgba_stride = surface->width*4;
+   struct pipe_screen *screen = surface->texture->screen;
+   uint rgba_stride = surface->width * 4;
+   struct pipe_transfer *transfer;
    void *raw;
-   unsigned x, y;
 
-   raw = pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_READ);
-   if(!raw)
+   transfer = screen->get_tex_transfer(screen,
+                                       surface->texture,
+                                       surface->face,
+                                       surface->level,
+                                       surface->zslice,
+                                       PIPE_TRANSFER_READ,
+                                       0, 0,
+                                       surface->width,
+                                       surface->height);
+   if (!transfer)
       return;
 
-   for (y = 0; y < surface->nblocksy; ++y) {
-      for(x = 0; x < surface->nblocksx; ++x) {
-         st_sample_pixel_block(surface->format,
-                               block,
-                               (uint8_t*)raw + y*surface->stride + x*block->size, 
-                               rgba + y*block->height*rgba_stride + x*block->width*4,
-                               rgba_stride,
-                               MIN2(block->width, surface->width - x*block->width), 
-                               MIN2(block->height, surface->height - y*block->height));
-       }
+   raw = screen->transfer_map(screen, transfer);
+   if (raw) {
+      const struct pipe_format_block *block = &transfer->block;
+      uint x, y;
+
+      for (y = 0; y < transfer->nblocksy; ++y) {
+         for (x = 0; x < transfer->nblocksx; ++x) {
+            st_sample_pixel_block(surface->format,
+                                  block,
+                                  (uint8_t *) raw + y * transfer->stride + x * block->size,
+                                  rgba + y * block->height * rgba_stride + x * block->width * 4,
+                                  rgba_stride,
+                                  MIN2(block->width, surface->width - x*block->width),
+                                  MIN2(block->height, surface->height - y*block->height));
+         }
+      }
+
+      screen->transfer_unmap(screen, transfer);
    }
    
-   pipe_surface_unmap(surface);
+   screen->tex_transfer_destroy(transfer);
 }




More information about the mesa-commit mailing list