python: Allow to read from buffers.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 19 Nov 2008 16:01:48 +0000 (01:01 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 19 Nov 2008 16:01:48 +0000 (01:01 +0900)
src/gallium/state_trackers/python/gallium.i
src/gallium/state_trackers/python/p_texture.i

index 68d2db3325a8d9c7e26b5e6c7008162593400515..f4c4b36ea7d5d18da84b78dabe8c3a2d07a8843c 100644 (file)
@@ -57,6 +57,8 @@
 
 %include "typemaps.i"
 
+%include "cstring.i"
+
 %include "carrays.i"
 %array_class(unsigned char, ByteArray);
 %array_class(int, IntArray);
index 33fb3743cce9366f6e0a7485a53a826c90974343..08ba0ebe4d0b566f93474eabedaf70e7dd9b88cb 100644 (file)
@@ -179,7 +179,35 @@ struct st_buffer {
       st_buffer_destroy($self);
    }
    
-   void write( const char *STRING, unsigned LENGTH, unsigned offset = 0) {
+   unsigned __len__(void) 
+   {
+      assert($self->buffer->refcount);
+      return $self->buffer->size;
+   }
+   
+   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+   void read(char **STRING, int *LENGTH)
+   {
+      struct pipe_screen *screen = $self->st_dev->screen;
+      const char *map;
+      
+      assert($self->buffer->refcount);
+      
+      *LENGTH = $self->buffer->size;
+      *STRING = (char *) malloc($self->buffer->size);
+      if(!*STRING)
+         return;
+      
+      map = pipe_buffer_map(screen, $self->buffer, PIPE_BUFFER_USAGE_CPU_READ);
+      if(map) {
+         memcpy(*STRING, map, $self->buffer->size);
+         pipe_buffer_unmap(screen, $self->buffer);
+      }
+   }
+   
+   %cstring_input_binary(const char *STRING, unsigned LENGTH);
+   void write(const char *STRING, unsigned LENGTH, unsigned offset = 0) 
+   {
       struct pipe_screen *screen = $self->st_dev->screen;
       char *map;