box: Remove duplicate transform calculation 58/294258/1
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 15 Jun 2023 01:54:51 +0000 (10:54 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Thu, 15 Jun 2023 06:48:44 +0000 (15:48 +0900)
Change-Id: I20a78ff303061e0bb1a3a42dbc35f0ee4f685687

src/util/box.c

index b47041d..e300a5d 100644 (file)
@@ -1,5 +1,50 @@
 #include "libds/util/box.h"
 
+#define BOX_TRANSFORM(dest, src, transform, width, height) \
+    do { \
+        if (transform % 2 == 0) { \
+            dest->width = src.width; \
+            dest->height = src.height; \
+        } else { \
+            dest->width = src.height; \
+            dest->height = src.width; \
+        } \
+        switch (transform) { \
+        case WL_OUTPUT_TRANSFORM_NORMAL: \
+            dest->x = src.x; \
+            dest->y = src.y; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_90: \
+            dest->x = height - src.y - src.height; \
+            dest->y = src.x; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_180: \
+            dest->x = width - src.x - src.width; \
+            dest->y = height - src.y - src.height; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_270: \
+            dest->x = src.y; \
+            dest->y = width - src.x - src.width; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_FLIPPED: \
+            dest->x = width - src.x - src.width; \
+            dest->y = src.y; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_FLIPPED_90: \
+            dest->x = src.y; \
+            dest->y = src.x; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_FLIPPED_180: \
+            dest->x = src.x; \
+            dest->y = height - src.y - src.height; \
+            break; \
+        case WL_OUTPUT_TRANSFORM_FLIPPED_270: \
+            dest->x = height - src.y - src.height; \
+            dest->y = width - src.x - src.width; \
+            break; \
+        } \
+    } while (0)
+
 WL_EXPORT bool
 ds_box_closest_point(const struct ds_box *box, double x, double y,
                double *dest_x, double *dest_y)
@@ -79,48 +124,7 @@ ds_box_transform(struct ds_box *dest, const struct ds_box *box,
                enum wl_output_transform transform, int width, int height) {
        struct ds_box src = *box;
 
-       if (transform % 2 == 0) {
-               dest->width = src.width;
-               dest->height = src.height;
-       } else {
-               dest->width = src.height;
-               dest->height = src.width;
-       }
-
-       switch (transform) {
-       case WL_OUTPUT_TRANSFORM_NORMAL:
-               dest->x = src.x;
-               dest->y = src.y;
-               break;
-       case WL_OUTPUT_TRANSFORM_90:
-               dest->x = height - src.y - src.height;
-               dest->y = src.x;
-               break;
-       case WL_OUTPUT_TRANSFORM_180:
-               dest->x = width - src.x - src.width;
-               dest->y = height - src.y - src.height;
-               break;
-       case WL_OUTPUT_TRANSFORM_270:
-               dest->x = src.y;
-               dest->y = width - src.x - src.width;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED:
-               dest->x = width - src.x - src.width;
-               dest->y = src.y;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-               dest->x = src.y;
-               dest->y = src.x;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-               dest->x = src.x;
-               dest->y = height - src.y - src.height;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-               dest->x = height - src.y - src.height;
-               dest->y = width - src.x - src.width;
-               break;
-       }
+    BOX_TRANSFORM(dest, src, transform, width, height);
 }
 
 WL_EXPORT bool
@@ -135,46 +139,5 @@ ds_fbox_transform(struct ds_fbox *dest, const struct ds_fbox *box,
 {
        struct ds_fbox src = *box;
 
-       if (transform % 2 == 0) {
-               dest->width = src.width;
-               dest->height = src.height;
-       } else {
-               dest->width = src.height;
-               dest->height = src.width;
-       }
-
-       switch (transform) {
-       case WL_OUTPUT_TRANSFORM_NORMAL:
-               dest->x = src.x;
-               dest->y = src.y;
-               break;
-       case WL_OUTPUT_TRANSFORM_90:
-               dest->x = height - src.y - src.height;
-               dest->y = src.x;
-               break;
-       case WL_OUTPUT_TRANSFORM_180:
-               dest->x = width - src.x - src.width;
-               dest->y = height - src.y - src.height;
-               break;
-       case WL_OUTPUT_TRANSFORM_270:
-               dest->x = src.y;
-               dest->y = width - src.x - src.width;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED:
-               dest->x = width - src.x - src.width;
-               dest->y = src.y;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-               dest->x = src.y;
-               dest->y = src.x;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-               dest->x = src.x;
-               dest->y = height - src.y - src.height;
-               break;
-       case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-               dest->x = height - src.y - src.height;
-               dest->y = width - src.x - src.width;
-               break;
-       }
+    BOX_TRANSFORM(dest, src, transform, width, height);
 }