From: Brian Date: Mon, 13 Aug 2007 19:56:54 +0000 (-0600) Subject: fill in the get_tile() function so ReadPixels can work X-Git-Tag: 062012170305~17580^2~390^2~4344 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21b9b8b74ec0975296d22493254875c0deb7b6da;p=profile%2Fivi%2Fmesa.git fill in the get_tile() function so ReadPixels can work --- diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index a67784b..cc0a870 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,6 +29,7 @@ #include "i915_state.h" #include "pipe/p_defines.h" #include "main/imports.h" +#include "main/macros.h" struct i915_surface @@ -38,13 +39,45 @@ struct i915_surface }; +/** + * Note: this is exactly like a8r8g8b8_get_tile() in sp_surface.c + * Share it someday. + */ static void i915_get_tile(struct pipe_surface *ps, GLuint x, GLuint y, GLuint w, GLuint h, GLfloat *p) { - /* any need to get tiles from i915 surfaces? */ - /* Yes, for glReadPixels (for a while at least). */ - assert(0); + const GLuint *src + = ((const GLuint *) (ps->region->map + ps->offset)) + + y * ps->region->pitch + x; + GLuint i, j; + GLuint w0 = w; + + assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); + +#if 0 + assert(x + w <= ps->width); + assert(y + h <= ps->height); +#else + /* temp clipping hack */ + if (x + w > ps->width) + w = ps->width - x; + if (y + h > ps->height) + h = ps->height -y; +#endif + for (i = 0; i < h; i++) { + GLfloat *pRow = p; + for (j = 0; j < w; j++) { + const GLuint pixel = src[j]; + pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); + pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); + pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); + pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } }