summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <jrfonseca@tungstengraphics.com>2008-11-20 01:01:48 +0900
committerJosé Fonseca <jrfonseca@tungstengraphics.com>2008-11-20 01:01:48 +0900
commit2f153b5487459f04941bbbf35fd531adbf7535a2 (patch)
treec6cffaf15f3e3ffe5e5e54d8c9ce436f62431880 /src
parent8a9e06257f3a145cddc5e44f841e2f2e81a2cafb (diff)
python: Allow to read from buffers.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/state_trackers/python/gallium.i2
-rw-r--r--src/gallium/state_trackers/python/p_texture.i30
2 files changed, 31 insertions, 1 deletions
diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i
index 68d2db3325..f4c4b36ea7 100644
--- a/src/gallium/state_trackers/python/gallium.i
+++ b/src/gallium/state_trackers/python/gallium.i
@@ -57,6 +57,8 @@
%include "typemaps.i"
+%include "cstring.i"
+
%include "carrays.i"
%array_class(unsigned char, ByteArray);
%array_class(int, IntArray);
diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i
index 33fb3743cc..08ba0ebe4d 100644
--- a/src/gallium/state_trackers/python/p_texture.i
+++ b/src/gallium/state_trackers/python/p_texture.i
@@ -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;