st/python: Move surface read/write methods to context.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Mar 2010 20:09:21 +0000 (21:09 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Mar 2010 20:22:23 +0000 (21:22 +0100)
src/gallium/state_trackers/python/p_context.i
src/gallium/state_trackers/python/p_texture.i
src/gallium/state_trackers/python/st_sample.c
src/gallium/state_trackers/python/st_sample.h

index df700bc663cf02406f3f49e72d0752570cbfa42d..a8e164a072bbd10b83939fc58e83f5965a6b42a7 100644 (file)
@@ -362,10 +362,253 @@ error1:
       pipe_surface_reference(&_dst, NULL);
    }
 
-   void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
-              unsigned stencil = 0)
+   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+   void
+   surface_read_raw(struct st_surface *surface,
+                    unsigned x, unsigned y, unsigned w, unsigned h,
+                    char **STRING, int *LENGTH)
+   {
+      struct pipe_texture *texture = surface->texture;
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      unsigned stride;
+
+      stride = util_format_get_stride(texture->format, w);
+      *LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
+      *STRING = (char *) malloc(*LENGTH);
+      if(!*STRING)
+         return;
+
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y, w, h);
+      if(transfer) {
+         pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+   }
+
+   %cstring_input_binary(const char *STRING, unsigned LENGTH);
+   void
+   surface_write_raw(struct st_surface *surface,
+                     unsigned x, unsigned y, unsigned w, unsigned h,
+                     const char *STRING, unsigned LENGTH, unsigned stride = 0)
    {
-      $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
+      struct pipe_texture *texture = surface->texture;
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+
+      if(stride == 0)
+         stride = util_format_get_stride(texture->format, w);
+
+      if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
+         SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
+
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_WRITE,
+                                          x, y, w, h);
+      if(!transfer)
+         SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
+
+      pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
+      pipe->tex_transfer_destroy(pipe, transfer);
+
+   fail:
+      return;
+   }
+
+   void
+   surface_read_rgba(struct st_surface *surface,
+                     unsigned x, unsigned y, unsigned w, unsigned h,
+                     float *rgba)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y, w, h);
+      if(transfer) {
+         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+   }
+
+   void
+   surface_write_rgba(struct st_surface *surface,
+                      unsigned x, unsigned y, unsigned w, unsigned h,
+                      const float *rgba)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_WRITE,
+                                          x, y, w, h);
+      if(transfer) {
+         pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+   }
+
+   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+   void
+   surface_read_rgba8(struct st_surface *surface,
+                      unsigned x, unsigned y, unsigned w, unsigned h,
+                      char **STRING, int *LENGTH)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      float *rgba;
+      unsigned char *rgba8;
+      unsigned i, j, k;
+
+      *LENGTH = 0;
+      *STRING = NULL;
+
+      if (!surface)
+         return;
+
+      *LENGTH = h*w*4;
+      *STRING = (char *) malloc(*LENGTH);
+      if(!*STRING)
+         return;
+
+      rgba = malloc(h*w*4*sizeof(float));
+      if(!rgba)
+         return;
+
+      rgba8 = (unsigned char *) *STRING;
+
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y,
+                                          w, h);
+      if(transfer) {
+         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
+         for(j = 0; j < h; ++j) {
+            for(i = 0; i < w; ++i)
+               for(k = 0; k <4; ++k)
+                  rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
+         }
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+
+      free(rgba);
+   }
+
+   void
+   surface_read_z(struct st_surface *surface,
+                  unsigned x, unsigned y, unsigned w, unsigned h,
+                  unsigned *z)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y, w, h);
+      if(transfer) {
+         pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+   }
+
+   void
+   surface_write_z(struct st_surface *surface,
+                   unsigned x, unsigned y, unsigned w, unsigned h,
+                   const unsigned *z)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_WRITE,
+                                          x, y, w, h);
+      if(transfer) {
+         pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
+         pipe->tex_transfer_destroy(pipe, transfer);
+      }
+   }
+
+   void
+   surface_sample_rgba(struct st_surface *surface,
+                       float *rgba)
+   {
+      st_sample_surface($self->pipe, surface, rgba);
+   }
+
+   unsigned
+   surface_compare_rgba(struct st_surface *surface,
+                        unsigned x, unsigned y, unsigned w, unsigned h,
+                        const float *rgba, float tol = 0.0)
+   {
+      struct pipe_context *pipe = $self->pipe;
+      struct pipe_transfer *transfer;
+      float *rgba2;
+      const float *p1;
+      const float *p2;
+      unsigned i, j, n;
+
+      rgba2 = MALLOC(h*w*4*sizeof(float));
+      if(!rgba2)
+         return ~0;
+
+      transfer = pipe->get_tex_transfer(pipe,
+                                          surface->texture,
+                                          surface->face,
+                                          surface->level,
+                                          surface->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y, w, h);
+      if(!transfer) {
+         FREE(rgba2);
+         return ~0;
+      }
+
+      pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
+      pipe->tex_transfer_destroy(pipe, transfer);
+
+      p1 = rgba;
+      p2 = rgba2;
+      n = 0;
+      for(i = h*w; i; --i) {
+         unsigned differs = 0;
+         for(j = 4; j; --j) {
+            float delta = *p2++ - *p1++;
+            if (delta < -tol || delta > tol)
+                differs = 1;
+         }
+         n += differs;
+      }
+
+      FREE(rgba2);
+
+      return n;
    }
 
 };
index 2dd9e5050ea9fadfe222abbc83bfc008636fb24e..923a6285289cd6adc9b6a935434175804ff0ee9c 100644 (file)
@@ -124,232 +124,6 @@ struct st_surface
       FREE($self);
    }
    
-   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
-   void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH)
-   {
-      struct pipe_texture *texture = $self->texture;
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      unsigned stride;
-
-      stride = util_format_get_stride(texture->format, w);
-      *LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
-      *STRING = (char *) malloc(*LENGTH);
-      if(!*STRING)
-         return;
-
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_READ,
-                                          x, y, w, h);
-      if(transfer) {
-         pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-   }
-
-   %cstring_input_binary(const char *STRING, unsigned LENGTH);
-   void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0)
-   {
-      struct pipe_texture *texture = $self->texture;
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-     
-      if(stride == 0)
-         stride = util_format_get_stride(texture->format, w);
-      
-      if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
-         SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
-         
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_WRITE,
-                                          x, y, w, h);
-      if(!transfer)
-         SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
-         
-      pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
-      pipe->tex_transfer_destroy(pipe, transfer);
-
-   fail:
-      return;
-   }
-
-   void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) 
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_READ,
-                                          x, y, w, h);
-      if(transfer) {
-         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-   }
-
-   void
-      put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba)
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_WRITE,
-                                          x, y, w, h);
-      if(transfer) {
-         pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-   }
-
-   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
-   void
-   get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) 
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      float *rgba;
-      unsigned char *rgba8;
-      unsigned i, j, k;
-
-      *LENGTH = 0;
-      *STRING = NULL;
-      
-      if (!$self)
-         return;
-
-      *LENGTH = h*w*4;
-      *STRING = (char *) malloc(*LENGTH);
-      if(!*STRING)
-         return;
-      
-      rgba = malloc(h*w*4*sizeof(float));
-      if(!rgba)
-         return;
-      
-      rgba8 = (unsigned char *) *STRING;
-
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_READ,
-                                          x, y,
-                                          w, h);
-      if(transfer) {
-         pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
-         for(j = 0; j < h; ++j) {
-            for(i = 0; i < w; ++i)
-               for(k = 0; k <4; ++k)
-                  rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
-         }
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-      
-      free(rgba);
-   }
-
-   void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z)
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_READ,
-                                          x, y, w, h);
-      if(transfer) {
-         pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-   }
-
-   void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z)
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_WRITE,
-                                          x, y, w, h);
-      if(transfer) {
-         pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
-         pipe->tex_transfer_destroy(pipe, transfer);
-      }
-   }
-   
-/*
-   void
-   sample_rgba(float *rgba) {
-      st_sample_surface($self, rgba);
-   }
-*/
-   
-   unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) 
-   {
-      struct pipe_context *pipe = ctx->pipe;
-      struct pipe_transfer *transfer;
-      float *rgba2;
-      const float *p1;
-      const float *p2;
-      unsigned i, j, n;
-      
-      rgba2 = MALLOC(h*w*4*sizeof(float));
-      if(!rgba2)
-         return ~0;
-
-      transfer = pipe->get_tex_transfer(pipe,
-                                          $self->texture,
-                                          $self->face,
-                                          $self->level,
-                                          $self->zslice,
-                                          PIPE_TRANSFER_READ,
-                                          x, y, w, h);
-      if(!transfer) {
-         FREE(rgba2);
-         return ~0;
-      }
-
-      pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
-      pipe->tex_transfer_destroy(pipe, transfer);
-
-      p1 = rgba;
-      p2 = rgba2;
-      n = 0;
-      for(i = h*w; i; --i) {
-         unsigned differs = 0;
-         for(j = 4; j; --j) {
-            float delta = *p2++ - *p1++;
-            if (delta < -tol || delta > tol)
-                differs = 1;
-         }
-         n += differs;
-      }
-      
-      FREE(rgba2);
-      
-      return n;
-   }
 
 };
 
index f9622533fbc5590ffefcfdf308fa21ddcb51aa59..e2c1e0601747d25ba934afda5a28c3c74c76882d 100644 (file)
@@ -521,12 +521,13 @@ st_sample_pixel_block(enum pipe_format format,
    }
 }
 
-#if 0
+
 void
-st_sample_surface(struct st_surface *surface, float *rgba) 
+st_sample_surface(struct pipe_context *pipe,
+                  struct st_surface *surface,
+                  float *rgba)
 {
    struct pipe_texture *texture = surface->texture;
-   struct pipe_screen *screen = texture->screen;
    unsigned width = u_minify(texture->width0, surface->level);
    unsigned height = u_minify(texture->height0, surface->level);
    uint rgba_stride = width * 4;
@@ -534,18 +535,18 @@ st_sample_surface(struct st_surface *surface, float *rgba)
    void *raw;
 
    transfer = pipe->get_tex_transfer(pipe,
-                                       surface->texture,
-                                       surface->face,
-                                       surface->level,
-                                       surface->zslice,
-                                       PIPE_TRANSFER_WRITE,
-                                       0, 0,
-                                       width,
-                                       height);
+                                     surface->texture,
+                                     surface->face,
+                                     surface->level,
+                                     surface->zslice,
+                                     PIPE_TRANSFER_WRITE,
+                                     0, 0,
+                                     width,
+                                     height);
    if (!transfer)
       return;
 
-   raw = screen->transfer_map(screen, transfer);
+   raw = pipe->transfer_map(pipe, transfer);
    if (raw) {
       enum pipe_format format = texture->format;
       uint x, y;
@@ -567,9 +568,8 @@ st_sample_surface(struct st_surface *surface, float *rgba)
          }
       }
 
-      screen->transfer_unmap(screen, transfer);
+      pipe->transfer_unmap(pipe, transfer);
    }
    
-   screen->tex_transfer_destroy(transfer);
+   pipe->tex_transfer_destroy(pipe, transfer);
 }
-#endif
index 888114d3021d899c76f564fb92f9cc26442dbedc..6fb8417add8895c1738314548c34e23ae8827129 100644 (file)
@@ -32,6 +32,9 @@
 
 #include "pipe/p_format.h"
 
+struct pipe_context;
+struct st_surface;
+
 
 void 
 st_sample_pixel_block(enum pipe_format format,
@@ -40,7 +43,9 @@ st_sample_pixel_block(enum pipe_format format,
                       unsigned w, unsigned h);
 
 void
-st_sample_surface(struct st_surface *surface, float *rgba);
+st_sample_surface(struct pipe_context *pipe,
+                  struct st_surface *surface,
+                  float *rgba);
 
 
 #endif /* ST_SAMPLE_H_ */