egl: Fix missing clamping in eglSetDamageRegionKHR
authorHarish Krupo <harish.krupo.kps@intel.com>
Sun, 8 Jul 2018 07:23:00 +0000 (12:53 +0530)
committerEric Engestrom <eric.engestrom@intel.com>
Tue, 24 Jul 2018 13:46:21 +0000 (14:46 +0100)
Clamp the x and y co-ordinates of the rectangles.

v2: Clamp width/height after converting to co-ordinates
    (Ilia Merkin)

Signed-off-by: Harish Krupo <harish.krupo.kps@intel.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
src/egl/main/eglapi.c

index c1103491191065e973593068d7218392e8a895e6..deb479b6d56e636c3c0e2abdb5883141ab36252f 100644 (file)
@@ -1320,9 +1320,7 @@ eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface,
 }
 
 /**
- * If the width of the passed rect is greater than the surface's
- * width then it is clamped to the width of the surface. Same with
- * height.
+ * Clamp the rectangles so that they lie within the surface.
  */
 
 static void
@@ -1334,17 +1332,16 @@ _eglSetDamageRegionKHRClampRects(_EGLDisplay* disp, _EGLSurface* surf,
    EGLint surf_width = surf->Width;
 
    for (i = 0; i < (4 * n_rects); i += 4) {
-      EGLint x, y, rect_width, rect_height;
-      x = rects[i];
-      y = rects[i + 1];
-      rect_width = rects[i + 2];
-      rect_height = rects[i + 3];
-
-      if (rect_width > surf_width - x)
-         rects[i + 2] = surf_width - x;
-
-      if (rect_height > surf_height - y)
-         rects[i + 3] = surf_height - y;
+      EGLint x1, y1, x2, y2;
+      x1 = rects[i];
+      y1 = rects[i + 1];
+      x2 = rects[i + 2] + x1;
+      y2 = rects[i + 3] + y1;
+
+      rects[i] = CLAMP(x1, 0, surf_width);
+      rects[i + 1] = CLAMP(y1, 0, surf_height);
+      rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i];
+      rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1];
    }
 }