[Mesa-dev] [PATCH v2 2/2] egl/drm: Fix misused x and y offsets on swrast_get_image() (v2)

Gwan-gyeong Mun elongbug at gmail.com
Wed Jul 19 10:25:28 UTC 2017


It fixes misused x and y variables on the calculation of the memory copy regions.
And it adds limits of the height and the width on the copy region.

v2: Polish the variable name and fix the calculation of the stride. (Eric Engestrom)

Fixes: 8430af5ebe1ee8119e14 "Add support for swrast to the DRM EGL platform"
Signed-off-by: Mun Gwan-gyeong <elongbug at gmail.com>
---
 src/egl/drivers/dri2/platform_drm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 00180deaf8..7a538c0c80 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -603,20 +603,41 @@ swrast_get_image(__DRIdrawable *driDrawable,
    struct dri2_egl_surface *dri2_surf = loaderPrivate;
    int internal_stride, stride;
    struct gbm_dri_bo *bo;
+   int bpp;
+   int x_bytes, width_bytes;
+   char *src, *dst;
 
    if (get_swrast_front_bo(dri2_surf) < 0)
       return;
 
    bo = gbm_dri_bo(dri2_surf->current->bo);
-   if (gbm_dri_bo_map_dumb(bo) == NULL)
+
+   bpp = get_format_bpp(bo->base.format);
+   if (bpp == 0)
       return;
 
+   x_bytes = x * bpp;
+   width_bytes = width * bpp;
+
    internal_stride = bo->base.stride;
-   stride = width * 4;
+   stride = width_bytes;
+
+   if (gbm_dri_bo_map_dumb(bo) == NULL)
+      return;
+
+   if (height > dri2_surf->base.Height - y)
+      height = dri2_surf->base.Height - y;
+
+   if (width_bytes > internal_stride - x_bytes)
+      width_bytes = internal_stride - x_bytes;
+
+   dst = data;
+   src = bo->map + x_bytes + (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, width_bytes);
+      dst += stride;
+      src += internal_stride;
    }
 
    gbm_dri_bo_unmap_dumb(bo);
-- 
2.13.3



More information about the mesa-dev mailing list