From dcd5ff37950fc114fcab97159d3975bbbb7160c5 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Wed, 11 Feb 2015 17:28:27 +0900 Subject: [PATCH] touch: consider the scaling while touch bounds checking consider the scaling while touch bounds checking and optimization Change-Id: I8cd5acb7a77de2da58a8dce77e7813846244a5cd Signed-off-by: GiWoong Kim --- .../tizen/emulator/skin/EmulatorFingers.java | 78 ++++++++++--------- .../tizen/emulator/skin/EmulatorShmSkin.java | 76 ++++++------------ 2 files changed, 64 insertions(+), 90 deletions(-) diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java index 5b748d65a7..470a997dc7 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java @@ -38,7 +38,6 @@ 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; import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; @@ -56,7 +55,7 @@ public class EmulatorFingers { private Logger logger = SkinLogger.getSkinLogger(EmulatorFingers.class).getLogger(); - private EmulatorShmSkin skin; + private EmulatorSkin skin; protected SocketCommunicator communicator; private EmulatorSkinState currentState; @@ -74,10 +73,11 @@ public class EmulatorFingers { /** * Constructor */ - EmulatorFingers(EmulatorShmSkin skin, PaletteData palette, int maximum) { + EmulatorFingers(EmulatorSkin skin, PaletteData palette, int maximum) { this.skin = skin; this.currentState = skin.currentState; this.communicator = skin.communicator; + this.fingerPointImage = null; initMultiTouchState(maximum, palette); } @@ -85,14 +85,14 @@ public class EmulatorFingers { /* a finger */ static class FingerPoint { private int id; - private int originX; + private int originX; /* host position */ private int originY; - private int x; + private int x; /* guest position */ private int y; FingerPoint(int originX, int originY, int x, int y) { this.originX = originX; - this.originY = -originY; + this.originY = originY; this.x = x; this.y = y; } @@ -100,7 +100,7 @@ public class EmulatorFingers { FingerPoint(int id, int originX, int originY, int x, int y) { this.id = id; this.originX = originX; - this.originY = -originY; + this.originY = originY; this.x = x; this.y = y; } @@ -131,7 +131,7 @@ public class EmulatorFingers { } public FingerPoint getFingerPointFromSlot(int index) { - if (index < 0 || index > getMaxTouchPoint()) { + if (index < 0 || index >= getMaxTouchPoint()) { return null; } @@ -140,8 +140,8 @@ public class EmulatorFingers { public FingerPoint getFingerPointSearch(int x, int y) { FingerPoint finger = null; - int fingerArea = (fingerPointSize / 2) + - 2 + ((100 - skin.currentState.getCurrentScale()) * 4 / 100); + int fingerArea = fingerPointSizeHalf + 2 + + ((100 - skin.currentState.getCurrentScale()) * 4 / 100); for (int i = fingerCnt - 1; i >= 0; i--) { finger = getFingerPointFromSlot(i); @@ -172,32 +172,36 @@ public class EmulatorFingers { fingerCnt = 0; FingerPointList = new ArrayList(); - for (int i = 0; i <= getMaxTouchPoint(); i++) { + for (int i = 0; i < getMaxTouchPoint(); i++) { FingerPointList.add(new FingerPoint(-1, -1, -1, -1)); - } + } - this.fingerPointSize = FINGER_POINT_SIZE; - this.fingerPointSizeHalf = fingerPointSize / 2; + fingerPointSize = FINGER_POINT_SIZE; + fingerPointSizeHalf = fingerPointSize / 2; - Color pointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD); - Color pointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F); + if (palette != null) { + Color pointOutlineColor = new Color(skin.getShell().getDisplay(), + 0xDD, 0xDD, 0xDD); + Color pointColor = new Color(skin.getShell().getDisplay(), + 0x0F, 0x0F, 0x0F); - ImageData imageData = new ImageData( - fingerPointSize + 4, fingerPointSize + 4, 32, palette); - imageData.transparentPixel = 0; - this.fingerPointImage = new Image(Display.getCurrent(), imageData); + ImageData imageData = new ImageData( + fingerPointSize + 4, fingerPointSize + 4, 32, palette); + imageData.transparentPixel = 0; + fingerPointImage = new Image(skin.getShell().getDisplay(), imageData); - /* draw point image */ - GC gc = new GC(fingerPointImage); + /* draw point image */ + GC gc = new GC(fingerPointImage); - gc.setBackground(pointColor); - gc.fillOval(2, 2, fingerPointSize, fingerPointSize); - gc.setForeground(pointOutlineColor); - gc.drawOval(0, 0, fingerPointSize + 2, fingerPointSize + 2); + gc.setBackground(pointColor); + gc.fillOval(2, 2, fingerPointSize, fingerPointSize); + gc.setForeground(pointOutlineColor); + gc.drawOval(0, 0, fingerPointSize + 2, fingerPointSize + 2); - gc.dispose(); - pointOutlineColor.dispose(); - pointColor.dispose(); + gc.dispose(); + pointOutlineColor.dispose(); + pointColor.dispose(); + } } public void setMultiTouchEnable(int mode) { @@ -388,11 +392,11 @@ public class EmulatorFingers { for (i = 0; i < fingerCnt; i++) { finger = getFingerPointFromSlot(i); if (finger != null) { - if (maskRegion.contains(finger.x + distanceX, - finger.y + distanceY) == false) { + if (maskRegion.contains(finger.originX + originDistanceX, + finger.originY + originDistanceY) == false) { logger.info("id " + (i + 1) + " finger is out of bounds : (" + - (finger.x + distanceX) + ", " + - (finger.y + distanceY) + ")"); + (finger.originX + originDistanceX) + ", " + + (finger.originY + originDistanceY) + ")"); /* do nothing */ return; } @@ -530,11 +534,11 @@ public class EmulatorFingers { return; } } else { - if (maskRegion.contains(coFinger.x - distanceX, - coFinger.y - distanceY) == false) { + if (maskRegion.contains(coFinger.originX - originDistanceX, + coFinger.originY - originDistanceY) == false) { logger.info("id " + coFinger.id + " finger is out of bounds : (" + - (coFinger.x - distanceX) + ", " + - (coFinger.y - distanceY) + ")"); + (coFinger.originX - originDistanceX) + ", " + + (coFinger.originY - originDistanceY) + ")"); /* do nothing */ return; } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java index 52ee75ffca..774333cfb0 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java @@ -42,11 +42,9 @@ import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; -import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType; import org.tizen.emulator.skin.comm.ICommunicator.MouseButtonType; import org.tizen.emulator.skin.comm.ICommunicator.MouseEventType; import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; -import org.tizen.emulator.skin.comm.sock.data.KeyEventData; import org.tizen.emulator.skin.comm.sock.data.MouseEventData; import org.tizen.emulator.skin.comm.sock.data.StartData; import org.tizen.emulator.skin.config.EmulatorConfig; @@ -63,11 +61,7 @@ import org.tizen.emulator.skin.util.SwtUtil; public class EmulatorShmSkin extends EmulatorSkin { public static final String JNI_LIBRARY_FILE = "shared"; - public static final int DISPLAY_COLOR_DEPTH = 24; /* no need to Alpha channel */ - - /* touch values */ - protected static int pressingX = -1, pressingY = -1; - protected static int pressingOriginX = -1, pressingOriginY = -1; + public static final int DISPLAY_COLOR_DEPTH = 24; /* no need to get Alpha channel */ private static Logger logger = SkinLogger.getSkinLogger( EmulatorShmSkin.class).getLogger(); @@ -101,7 +95,10 @@ public class EmulatorShmSkin extends EmulatorSkin { private BufferPainter bufferPainter; private Image imageCover; - private int maxTouchPoint; + /* touch values */ + protected static int pressingX = -1, pressingY = -1; + protected static int pressingOriginX = -1, pressingOriginY = -1; + private EmulatorFingers fingers; private int multiTouchKey; private int multiTouchKeySub1; @@ -225,18 +222,16 @@ public class EmulatorShmSkin extends EmulatorSkin { /* ARGB */ this.palette = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); - - /* get MaxTouchPoint from startup argument */ - this.maxTouchPoint = config.getArgInt( - ArgsConstants.INPUT_TOUCH_MAXPOINT); } @Override protected void skinFinalize() { bufferPainter.stopRequest(); - /* remove multi-touch finger points */ - fingers.cleanupMultiTouchState(); + /* remove multi-touch points */ + if (fingers != null) { + fingers.cleanupMultiTouchState(); + } super.skinFinalize(); } @@ -245,8 +240,6 @@ public class EmulatorShmSkin extends EmulatorSkin { public StartData initSkin() { initLayout(); - fingers = new EmulatorFingers(this, palette, maxTouchPoint); - /* multi-touch toggle key */ if (SwtUtil.isMacPlatform() == true) { multiTouchKey = SWT.COMMAND; @@ -256,6 +249,9 @@ public class EmulatorShmSkin extends EmulatorSkin { multiTouchKeySub1 = SWT.SHIFT; multiTouchKeySub2 = SWT.ALT; + fingers = new EmulatorFingers(this, palette, + config.getArgInt(ArgsConstants.INPUT_TOUCH_MAXPOINT)); + initDisplay(); /* generate a start data */ @@ -471,7 +467,7 @@ public class EmulatorShmSkin extends EmulatorSkin { currentState.getCurrentScale(), currentState.getCurrentRotationId()); - /* multi-touch */ + /* filtering for multi-touch */ if (fingers.getMultiTouchEnable() == 1) { /* Ctrl or Shift */ fingers.maruFingerProcessing1(eventType, @@ -516,6 +512,7 @@ public class EmulatorShmSkin extends EmulatorSkin { pressingX = pressingY = -1; pressingOriginX = pressingOriginY = -1; + /* filtering for multi-touch */ if (fingers.getMultiTouchEnable() == 1) { fingers.maruFingerProcessing1(MouseEventType.RELEASE.value(), e.x, e.y, geometry[0], geometry[1]); @@ -559,6 +556,7 @@ public class EmulatorShmSkin extends EmulatorSkin { pressingOriginX = e.x; pressingOriginY = e.y; + /* filtering for multi-touch */ if (fingers.getMultiTouchEnable() == 1) { fingers.maruFingerProcessing1(MouseEventType.PRESS.value(), e.x, e.y, geometry[0], geometry[1]); @@ -592,9 +590,9 @@ public class EmulatorShmSkin extends EmulatorSkin { protected void keyReleasedDelivery(int keyCode, int stateMask, int keyLocation, boolean remove) { if (fingers.getMaxTouchPoint() > 1) { + /* multi-touch checking */ final int tempStateMask = stateMask & ~SWT.BUTTON1; - /* multi-touch checking */ if (keyCode == multiTouchKey || keyCode == multiTouchKeySub1) { if (tempStateMask == (multiTouchKeySub1 | multiTouchKey)) { fingers.setMultiTouchEnable(1); @@ -604,7 +602,7 @@ public class EmulatorShmSkin extends EmulatorSkin { logger.info("disable multi-touch"); } - updateDisplay(); + displayCanvas.redraw(); } else if (keyCode == multiTouchKeySub2) { if (tempStateMask == (multiTouchKey | multiTouchKeySub2)) { fingers.setMultiTouchEnable(1); @@ -614,18 +612,11 @@ public class EmulatorShmSkin extends EmulatorSkin { logger.info("disable multi-touch"); } - updateDisplay(); + displayCanvas.redraw(); } } - KeyEventData keyEventData = new KeyEventData( - KeyEventType.RELEASED.value(), keyCode, stateMask, keyLocation); - communicator.sendToQEMU( - SendCommand.SEND_KEYBOARD_KEY_EVENT, keyEventData, false); - - if (remove == true) { - removePressedKeyFromList(keyEventData); - } + super.keyReleasedDelivery(keyCode, stateMask, keyLocation, remove); } @Override @@ -643,7 +634,7 @@ public class EmulatorShmSkin extends EmulatorSkin { for ( ; i > 2; i--) { fingers.removeFingerPointFromSlot(i - 1); } - updateDisplay(); + displayCanvas.redraw(); fingers.setMultiTouchEnable(3); @@ -654,20 +645,6 @@ public class EmulatorShmSkin extends EmulatorSkin { { fingers.setMultiTouchEnable(2); - /* Before the Emulator starts multi-touch processing, - * add a first finger if user just switches on to the multi-touch mode - * while display dragging. */ - if (fingers.getFingerCnt() == 0 && pressingX != -1 && pressingY != -1 && - pressingOriginX != -1 && pressingOriginY != -1) { - fingers.addFingerPoint( - pressingOriginX, pressingOriginY, - pressingX, pressingY); - pressingX = pressingY = -1; - pressingOriginX = pressingOriginY = -1; - - updateDisplay(); - } - logger.info("enable multi-touch mode 2"); } else if (keyCode == multiTouchKeySub1 || keyCode == multiTouchKey) { fingers.setMultiTouchEnable(1); @@ -683,7 +660,7 @@ public class EmulatorShmSkin extends EmulatorSkin { pressingX = pressingY = -1; pressingOriginX = pressingOriginY = -1; - updateDisplay(); + displayCanvas.redraw(); } logger.info("enable multi-touch mode 1"); @@ -692,19 +669,12 @@ public class EmulatorShmSkin extends EmulatorSkin { fingers.clearFingerSlot(false); logger.info("disable multi-touch"); - updateDisplay(); + displayCanvas.redraw(); } } } - KeyEventData keyEventData = new KeyEventData( - KeyEventType.PRESSED.value(), keyCode, stateMask, keyLocation); - communicator.sendToQEMU( - SendCommand.SEND_KEYBOARD_KEY_EVENT, keyEventData, false); - - if (add == true) { - addPressedKeyToList(keyEventData); - } + super.keyPressedDelivery(keyCode, stateMask, keyLocation, add); } @Override -- 2.34.1