summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/python/p_texture.i
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-02-20 16:50:02 +0000
committerJosé Fonseca <jfonseca@vmware.com>2009-02-20 16:50:02 +0000
commit60e35ebf1476c31eb5d7c207ab8e9db77fcad896 (patch)
tree74784001b694ae1268670932523369707c4f69d2 /src/gallium/state_trackers/python/p_texture.i
parent77388559886dd84c69aaffc9a385ad87c410afa9 (diff)
python: More efficient blits from surfaces.
C code instead of interpreted python code.
Diffstat (limited to 'src/gallium/state_trackers/python/p_texture.i')
-rw-r--r--src/gallium/state_trackers/python/p_texture.i44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i
index 08ba0ebe4d..9396522961 100644
--- a/src/gallium/state_trackers/python/p_texture.i
+++ b/src/gallium/state_trackers/python/p_texture.i
@@ -121,6 +121,50 @@
pipe_put_tile_rgba($self, x, y, w, h, rgba);
}
+ %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+ void
+ get_tile_rgba8(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH)
+ {
+ unsigned surface_usage;
+ 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(w*4*sizeof(float));
+ if(!rgba)
+ return;
+
+ rgba8 = (unsigned char *) *STRING;
+
+ /* XXX: force mappable surface */
+ surface_usage = $self->usage;
+ $self->usage |= PIPE_BUFFER_USAGE_CPU_READ;
+
+ for(j = 0; j < h; ++j) {
+ pipe_get_tile_rgba($self,
+ x, y + j, w, 1,
+ rgba);
+ for(i = 0; i < w; ++i)
+ for(k = 0; k <4; ++k)
+ rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[i*4 + k]);
+ }
+
+ $self->usage = surface_usage;
+
+ free(rgba);
+ }
+
void
get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) {
pipe_get_tile_z($self, x, y, w, h, z);