touch: multi-touch bounds checking on maru_shm 62/35262/3
authorGiWoong Kim <giwoong.kim@samsung.com>
Wed, 11 Feb 2015 08:27:00 +0000 (17:27 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 13 Feb 2015 05:46:00 +0000 (21:46 -0800)
Emulator need to consider the display mask while
multi-touch bounds checking

Change-Id: I83b97353fbe3f63d5c0fce00031d731f37ef9852
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/display/maru_finger.c
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java

index 556336ea739f97c5605cf30880368903410687c7..2087b2c31d53193eab955d425e787b4065f99afc 100644 (file)
@@ -300,17 +300,17 @@ FingerPoint *get_finger_point_search(int x, int y)
     int i;
     MultiTouchState *mts = get_emul_multi_touch_state();
     FingerPoint *finger = NULL;
-    int finger_region = (mts->finger_point_size / 2) +
+    int finger_area = (mts->finger_point_size / 2) +
         2 + (int)((1 - get_emul_win_scale()) * 4);
 
     for (i = mts->finger_cnt - 1; i >= 0; i--) {
         finger = get_finger_point_from_slot(i);
 
         if (finger != NULL) {
-            if (x >= (finger->x - finger_region) &&
-                x < (finger->x + finger_region) &&
-                y >= (finger->y - finger_region) &&
-                y < (finger->y + finger_region)) {
+            if (x >= (finger->x - finger_area) &&
+                x < (finger->x + finger_area) &&
+                y >= (finger->y - finger_area) &&
+                y < (finger->y + finger_area)) {
                     return finger;
             }
         }
@@ -346,7 +346,7 @@ void maru_finger_processing_1(
 
         if (mts->finger_cnt == 0)
         { /* first finger touch input */
-            INFO("multi-touch mode 1 processing");
+            INFO("multi-touch mode 1 processing\n");
 
             if (add_finger_point(origin_x, origin_y, x, y) == -1) {
                 return;
@@ -418,49 +418,43 @@ void maru_finger_processing_2(
                 /* bounds checking */
                 const int current_screen_w = get_emul_resolution_width();
                 const int current_screen_h = get_emul_resolution_height();
-                int temp_finger_x, temp_finger_y;
 
                 for (i = 0; i < get_emul_multi_touch_state()->finger_cnt; i++) {
                     finger = get_finger_point_from_slot(i);
-                    if (finger == NULL) {
-                        continue;
-                    }
-
-                    temp_finger_x = finger->x + distance_x;
-                    temp_finger_y = finger->y + distance_y;
-
-                    if (temp_finger_x >= current_screen_w || temp_finger_x < 0
-                        || temp_finger_y >= current_screen_h || temp_finger_y < 0) {
-                        TRACE("id %d finger is out of bounds : (%d, %d)\n",
-                            i + 1, temp_finger_x, temp_finger_y);
-                        return;
+                    if (finger != NULL) {
+                        if (finger->x + distance_x >= current_screen_w ||
+                            finger->x + distance_x < 0 ||
+                            finger->y + distance_y >= current_screen_h ||
+                            finger->y + distance_y < 0) {
+                            TRACE("id %d finger is out of bounds : (%d, %d)\n",
+                                i + 1, finger->x + distance_x, finger->y + distance_y);
+                            /* do nothing */
+                            return;
+                        }
                     }
                 }
 
                 /* move */
                 for (i = 0; i < get_emul_multi_touch_state()->finger_cnt; i++) {
                     finger = get_finger_point_from_slot(i);
-                    if (finger == NULL) {
-                        continue;
-                    }
-
-                    finger->origin_x += origin_distance_x;
-                    finger->origin_y += origin_distance_y;
-                    finger->x += distance_x;
-                    finger->y += distance_y;
-
-                    if (finger->id != 0) {
-                        virtio_touchscreen_event(finger->x, finger->y,
-                            i, QEMU_MOUSE_PRESSED);
-                        TRACE("id %d finger multi-touch dragging : (%d, %d)\n",
-                            i + 1, finger->x, finger->y);
-                    }
+                    if (finger != NULL) {
+                        finger->origin_x += origin_distance_x;
+                        finger->origin_y += origin_distance_y;
+                        finger->x += distance_x;
+                        finger->y += distance_y;
+
+                        if (finger->id != 0) {
+                            virtio_touchscreen_event(finger->x, finger->y,
+                                i, QEMU_MOUSE_PRESSED);
+                            TRACE("id %d finger multi-touch dragging : (%d, %d)\n",
+                                i + 1, finger->x, finger->y);
+                        }
 #ifdef CONFIG_WIN32
-                    Sleep(1);
+                        Sleep(1);
 #else
-                    usleep(1000);
+                        usleep(1000);
 #endif
-
+                    }
                 }
             }
 
@@ -469,7 +463,7 @@ void maru_finger_processing_2(
 
         if (mts->finger_cnt == 0)
         { /* first finger touch input */
-            INFO("multi-touch mode 2 processing");
+            INFO("multi-touch mode 2 processing\n");
 
             if (add_finger_point(origin_x, origin_y, x, y) == -1) {
                 return;
@@ -542,6 +536,7 @@ void maru_finger_processing_3(
                             (co_finger->y - distance_y) < 0) {
                             TRACE("id %d finger is out of bounds (%d, %d)\n",
                                 co_finger->id, co_finger->x - distance_x, co_finger->y - distance_y);
+                            /* do nothing */
                             return;
                         }
 
@@ -565,7 +560,7 @@ void maru_finger_processing_3(
 
         if (mts->finger_cnt == 0)
         { /* first finger touch input */
-            INFO("multi-touch mode 3 processing");
+            INFO("multi-touch mode 3 processing\n");
 
             if (add_finger_point(origin_x, origin_y, x, y) == -1) {
                 return;
index 1336edb42af8610b206b6c0d4d0b109fc0bc638d..5b748d65a70196623bc45bcb587130da569fc53d 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.Region;
 import org.eclipse.swt.widgets.Display;
 import org.tizen.emulator.skin.comm.ICommunicator.MouseButtonType;
 import org.tizen.emulator.skin.comm.ICommunicator.MouseEventType;
@@ -55,6 +56,10 @@ public class EmulatorFingers {
        private Logger logger =
                        SkinLogger.getSkinLogger(EmulatorFingers.class).getLogger();
 
+       private EmulatorShmSkin skin;
+       protected SocketCommunicator communicator;
+       private EmulatorSkinState currentState;
+
        private int multiTouchEnable;
        private int maxTouchPoint;
        protected int fingerCnt;
@@ -66,16 +71,13 @@ public class EmulatorFingers {
        protected int fingerPointSizeHalf;
        protected Image fingerPointImage;
 
-       protected SocketCommunicator communicator;
-       private EmulatorSkinState currentState;
-
        /**
         *  Constructor
         */
-       EmulatorFingers(int maximum, EmulatorSkinState currentState,
-                       SocketCommunicator communicator, PaletteData palette) {
-               this.currentState = currentState;
-               this.communicator = communicator;
+       EmulatorFingers(EmulatorShmSkin skin, PaletteData palette, int maximum) {
+               this.skin = skin;
+               this.currentState = skin.currentState;
+               this.communicator = skin.communicator;
 
                initMultiTouchState(maximum, palette);
        }
@@ -138,17 +140,17 @@ public class EmulatorFingers {
 
        public FingerPoint getFingerPointSearch(int x, int y) {
                FingerPoint finger = null;
-               int fingerRegion = fingerPointSize + 2;
-               //logger.info("x: "+x+ "y: "+ y + " fingerRegion: " + fingerRegion);
+               int fingerArea = (fingerPointSize / 2) +
+                               2 + ((100 - skin.currentState.getCurrentScale()) * 4 / 100);
 
                for (int i = fingerCnt - 1; i >= 0; i--) {
                        finger = getFingerPointFromSlot(i);
 
                        if (finger != null) {
-                               if (x >= (finger.x - fingerRegion) &&
-                                               x < (finger.x + fingerRegion) &&
-                                               y >= (finger.y - fingerRegion) &&
-                                               y < (finger.y + fingerRegion)) {
+                               if (x >= (finger.x - fingerArea) &&
+                                               x < (finger.x + fingerArea) &&
+                                               y >= (finger.y - fingerArea) &&
+                                               y < (finger.y + fingerArea)) {
                                        return finger;
                                }
                        }
@@ -362,22 +364,38 @@ public class EmulatorFingers {
                                        int i = 0;
 
                                        /* bounds checking */
-                                       final int currrntScreenW = currentState.getCurrentResolutionWidth();
-                                       final int currrntScreenH = currentState.getCurrentResolutionHeight();
-                                       int tempFingerX = 0, tempFingerY = 0;
-
-                                       for (i = 0; i < fingerCnt; i++) {
-                                               finger = getFingerPointFromSlot(i);
-                                               if (finger != null) {
-                                                       tempFingerX = finger.x + distanceX;
-                                                       tempFingerY = finger.y + distanceY;
-
-                                                       if (tempFingerX >= currrntScreenW || tempFingerX < 0 ||
-                                                                       tempFingerY >= currrntScreenH || tempFingerY < 0) {
-                                                               logger.info("id " + (i + 1) + " finger is out of bounds : ("
-                                                                       + tempFingerX + ", " + tempFingerY + ")");
-
-                                                               return;
+                                       Region maskRegion = skin.getDisplayCanvas().getRegion();
+                                       if (maskRegion == null) {
+                                               final int currrntScreenW = currentState.getCurrentResolutionWidth();
+                                               final int currrntScreenH = currentState.getCurrentResolutionHeight();
+
+                                               for (i = 0; i < fingerCnt; i++) {
+                                                       finger = getFingerPointFromSlot(i);
+                                                       if (finger != null) {
+                                                               if (finger.x + distanceX >= currrntScreenW ||
+                                                                               finger.x + distanceX < 0 ||
+                                                                               finger.y + distanceY >= currrntScreenH ||
+                                                                               finger.y + distanceY < 0) {
+                                                                       logger.info("id " + (i + 1) + " finger is out of bounds : (" +
+                                                                                       (finger.x + distanceX) + ", " +
+                                                                                       (finger.y + distanceY) + ")");
+                                                                       /* do nothing */
+                                                                       return;
+                                                               }
+                                                       }
+                                               }
+                                       } else {
+                                               for (i = 0; i < fingerCnt; i++) {
+                                                       finger = getFingerPointFromSlot(i);
+                                                       if (finger != null) {
+                                                               if (maskRegion.contains(finger.x + distanceX,
+                                                                               finger.y + distanceY) == false) {
+                                                                       logger.info("id " + (i + 1) + " finger is out of bounds : (" +
+                                                                                       (finger.x + distanceX) + ", " +
+                                                                                       (finger.y + distanceY) + ")");
+                                                                       /* do nothing */
+                                                                       return;
+                                                               }
                                                        }
                                                }
                                        }
@@ -496,16 +514,30 @@ public class EmulatorFingers {
                                                                (grabFingerID == 2) ? 0 : 1);
                                                if (coFinger != null) {
                                                        /* bounds checking */
-                                                       final int currrntScreenW = currentState.getCurrentResolutionWidth();
-                                                       final int currrntScreenH = currentState.getCurrentResolutionHeight();
-
-                                                       if (coFinger.x - distanceX >= currrntScreenW ||
-                                                                       coFinger.x - distanceX < 0 ||
-                                                                       coFinger.y - distanceY >= currrntScreenH ||
-                                                                       coFinger.y - distanceY < 0) {
-                                                               logger.info("id " + coFinger.id + " finger is out of bounds : ("
-                                                                       + (coFinger.x - distanceX) + ", " + (coFinger.y - distanceY) + ")");
-                                                               return;
+                                                       Region maskRegion = skin.getDisplayCanvas().getRegion();
+                                                       if (maskRegion == null) {
+                                                               final int currrntScreenW = currentState.getCurrentResolutionWidth();
+                                                               final int currrntScreenH = currentState.getCurrentResolutionHeight();
+
+                                                               if (coFinger.x - distanceX >= currrntScreenW ||
+                                                                               coFinger.x - distanceX < 0 ||
+                                                                               coFinger.y - distanceY >= currrntScreenH ||
+                                                                               coFinger.y - distanceY < 0) {
+                                                                       logger.info("id " + coFinger.id + " finger is out of bounds : (" +
+                                                                                       (coFinger.x - distanceX) + ", " +
+                                                                                       (coFinger.y - distanceY) + ")");
+                                                                       /* do nothing */
+                                                                       return;
+                                                               }
+                                                       } else {
+                                                               if (maskRegion.contains(coFinger.x - distanceX,
+                                                                               coFinger.y - distanceY) == false) {
+                                                                       logger.info("id " + coFinger.id + " finger is out of bounds : (" +
+                                                                                       (coFinger.x - distanceX) + ", " +
+                                                                                       (coFinger.y - distanceY) + ")");
+                                                                       /* do nothing */
+                                                                       return;
+                                                               }
                                                        }
 
                                                        /* move */
index b43ae81975a13553b3c7a52addf5c5ca500b4815..52ee75ffca965098546f6f72f09234a2534e4a6c 100644 (file)
@@ -245,8 +245,7 @@ public class EmulatorShmSkin extends EmulatorSkin {
        public StartData initSkin() {
                initLayout();
 
-               fingers = new EmulatorFingers(maxTouchPoint,
-                               currentState, communicator, palette);
+               fingers = new EmulatorFingers(this, palette, maxTouchPoint);
 
                /* multi-touch toggle key */
                if (SwtUtil.isMacPlatform() == true) {