[Mesa-dev] [PATCH 2/2] egl/drm: Fix misused x and y offsets on swrast_get_image()
Gwan-gyeong Mun
elongbug at gmail.com
Mon Jul 17 18:11:51 UTC 2017
It fixes misused x and y offsets on the calculation of the memory copy regions.
And it adds limits of the height and the width on the copy region.
Signed-off-by: Mun Gwan-gyeong <elongbug at gmail.com>
---
src/egl/drivers/dri2/platform_drm.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 36e9c74a56..d2fefad83b 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -575,6 +575,9 @@ swrast_get_image(__DRIdrawable *driDrawable,
struct dri2_egl_surface *dri2_surf = loaderPrivate;
int internal_stride, stride;
struct gbm_dri_bo *bo;
+ int x_offset = x * 4;
+ int copy_width = width * 4;
+ char *src, *dst;
if (get_swrast_front_bo(dri2_surf) < 0)
return;
@@ -584,11 +587,21 @@ swrast_get_image(__DRIdrawable *driDrawable,
return;
internal_stride = bo->base.stride;
- stride = width * 4;
+ stride = copy_width;
+
+ if (height > dri2_surf->base.Height - y)
+ height = dri2_surf->base.Height - y;
+
+ if (copy_width > internal_stride - x_offset)
+ copy_width = internal_stride - x_offset;
+
+ dst = data;
+ src = bo->map + x_offset + (y * internal_stride);
for (int i = 0; i < height; i++) {
- memcpy(data + i * stride,
- bo->map + (x + i) * internal_stride + y, stride);
+ memcpy(dst, src, copy_width);
+ dst += stride;
+ src += internal_stride;
}
gbm_dri_bo_unmap_dumb(bo);
--
2.13.3
More information about the mesa-dev
mailing list