video: make up for rounding error by comparing if two values are close enough. 90/228690/3
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 12 Mar 2020 02:18:01 +0000 (11:18 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 26 Mar 2020 03:44:59 +0000 (03:44 +0000)
not sure that this error actually caused by rounding error of
e_util_transform, but anyway there was a failure converting 4 vertices
of evas_map to elements of rectangle and rotation.

And it turned out that was because of 1 pixel difference between two
vertices when it is compared to find out whether it's rectangle or not.

Change-Id: I1876b35f36fa76a10e00b5ef89c0a2c35a7edd18

src/bin/video/iface/e_video_hwc.c

index e8d26afab8bcdd18d84c144ece5725627060eda7..072593388122a7b345af94c02ff90e3b17978745 100644 (file)
@@ -1008,17 +1008,33 @@ normal:
  *   1. The given coordinates are not represented by rectangle.
  *   2. All angles except for 0, 90, 180, 270.
  */
+#ifdef IS_CLOSE
+#undef IS_CLOSE
+#endif
+#define IS_CLOSE(x, y)  (abs((x - y)) < 2)
+
 #ifdef IS_PORTRAIT_RECT
 #undef IS_PORTRAIT_RECT
 #endif
 #define IS_PORTRAIT_RECT(p) \
-   ((p[0].y == p[1].y) && (p[1].x == p[2].x) && (p[2].y == p[3].y) && (p[3].x == p[0].x))
+   (IS_CLOSE(p[0].y, p[1].y) && IS_CLOSE(p[1].x, p[2].x) && \
+    IS_CLOSE(p[2].y, p[3].y) && IS_CLOSE(p[3].x, p[0].x))
 
 #ifdef IS_LANDSCAPE_RECT
 #undef IS_LANDSCAPE_RECT
 #endif
 #define IS_LANDSCAPE_RECT(p) \
-   ((p[0].x == p[1].x) && (p[1].y == p[2].y) && (p[2].x == p[3].x) && (p[3].y == p[0].y))
+   (IS_CLOSE(p[0].x, p[1].x) && IS_CLOSE(p[1].y, p[2].y) && \
+    IS_CLOSE(p[2].x, p[3].x) && IS_CLOSE(p[3].y, p[0].y))
+
+#ifdef VERTICES_TO_RECT
+#undef VERTICES_TO_RECT
+#endif
+#define VERTICES_TO_RECT(r, vs)             \
+    r->x = MIN(vs[0].x, vs[2].x);           \
+    r->y = MIN(vs[0].y, vs[2].y);           \
+    r->w = MAX(vs[0].x, vs[2].x) - r->x;    \
+    r->h = MAX(vs[0].y, vs[2].y) - r->y
 
 static Eina_Bool
 _e_video_hwc_coords_to_rectangle_convert(Evas_Point p[4], Eina_Rectangle *rect, uint *transform)
@@ -1031,13 +1047,13 @@ _e_video_hwc_coords_to_rectangle_convert(Evas_Point p[4], Eina_Rectangle *rect,
         if ((p[0].x < p[2].x) && (p[0].y < p[2].y))
           {
              *transform = TDM_TRANSFORM_NORMAL;
-             EINA_RECTANGLE_SET(rect, p[0].x, p[0].y, p[2].x - p[0].x, p[2].y - p[0].y);
+             VERTICES_TO_RECT(rect, p);
              ret = EINA_TRUE;
           }
         else if ((p[0].x > p[2].x) && (p[0].y > p[2].y))
           {
              *transform = TDM_TRANSFORM_180;
-             EINA_RECTANGLE_SET(rect, p[2].x, p[2].y, p[0].x - p[2].x, p[0].y - p[2].y);
+             VERTICES_TO_RECT(rect, p);
              ret = EINA_TRUE;
           }
      }
@@ -1047,13 +1063,13 @@ _e_video_hwc_coords_to_rectangle_convert(Evas_Point p[4], Eina_Rectangle *rect,
         if ((p[0].x > p[2].x) && (p[0].y < p[2].y))
           {
              *transform = TDM_TRANSFORM_90;
-             EINA_RECTANGLE_SET(rect, p[2].x, p[0].y, p[0].x - p[2].x, p[2].y - p[0].y);
+             VERTICES_TO_RECT(rect, p);
              ret = EINA_TRUE;
           }
         else if ((p[0].x < p[2].x) && (p[0].y > p[2].y))
           {
              *transform = TDM_TRANSFORM_270;
-             EINA_RECTANGLE_SET(rect, p[0].x, p[2].y, p[2].x - p[0].x, p[0].y - p[2].y);
+             VERTICES_TO_RECT(rect, p);
              ret = EINA_TRUE;
           }
      }
@@ -1061,8 +1077,10 @@ _e_video_hwc_coords_to_rectangle_convert(Evas_Point p[4], Eina_Rectangle *rect,
    return ret;
 }
 
+#undef IS_CLOSE
 #undef IS_PORTRAIT_RECT
 #undef IS_LANDSCAPE_RECT
+#undef VERTICES_TO_RECT
 
 /**
  * Merge transform value of E_Comp_Wl_Buffer_Viewport with given transform.