summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-11-21 18:58:47 +0800
committerChia-I Wu <[email protected]>2010-11-21 19:32:22 +0800
commitb8f6cb380951463f86e6f9e7bb3a18a87fe2f53e (patch)
tree1630c86b6dee79a763e2d87aff52470ba3c4afef /src/gallium
parente8bbaff22e75953b1c8a259753dbd8658998305e (diff)
st/vega: Fix vgReadPixels with a subrectangle.
Fix a crash when the subrectangle is not inside the fb. Fix wrong pipe transfer when sx > 0 or sy + height != fb->height. This fixes "readpixels" demo.
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/state_trackers/vega/api_images.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c
index 7054d9bb7ed..e9f038c5f92 100644
--- a/src/gallium/state_trackers/vega/api_images.c
+++ b/src/gallium/state_trackers/vega/api_images.c
@@ -37,6 +37,7 @@
#include "pipe/p_screen.h"
#include "util/u_inlines.h"
#include "util/u_tile.h"
+#include "util/u_math.h"
static INLINE VGboolean supported_image_format(VGImageFormat format)
{
@@ -402,7 +403,6 @@ void vegaReadPixels(void * data, VGint dataStride,
VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4];
VGfloat *df = (VGfloat*)temp;
- VGint y = (fb->height - sy) - 1, yStep = -1;
VGint i;
VGubyte *dst = (VGubyte *)data;
VGint xoffset = 0, yoffset = 0;
@@ -430,18 +430,26 @@ void vegaReadPixels(void * data, VGint dataStride,
}
if (sy < 0) {
yoffset = -sy;
+ yoffset *= dataStride;
height += sy;
sy = 0;
- y = (fb->height - sy) - 1;
- yoffset *= dataStride;
+ }
+
+ if (sx + width > fb->width || sy + height > fb->height) {
+ width = fb->width - sx;
+ height = fb->height - sy;
+ /* nothing to read */
+ if (width <= 0 || height <= 0)
+ return;
}
{
+ VGint y = (fb->height - sy) - 1, yStep = -1;
struct pipe_transfer *transfer;
transfer = pipe_get_transfer(pipe, strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ,
- 0, 0, width, height);
+ 0, 0, sx + width, fb->height - sy);
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {