From: GiWoong Kim Date: Sat, 27 Dec 2014 03:40:08 +0000 (+0900) Subject: display: added DisplayCavas class X-Git-Tag: TizenStudio_2.0_p3.0~350 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=368f1424b50b6cf58fce902d58b6aee5fd384a61;p=sdk%2Femulator%2Fqemu.git display: added DisplayCavas class Change-Id: I203fcaa9bc6b4436bbd8710b6638026cb5f2692c Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/DisplayCanvas.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/DisplayCanvas.java new file mode 100644 index 0000000..462fd09 --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/DisplayCanvas.java @@ -0,0 +1,61 @@ +/** + * Display + * + * Copyright (C) 2011 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * SangHo Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.emulator.skin; + +import java.util.logging.Logger; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.skin.log.SkinLogger; + +public class DisplayCanvas extends Canvas { + private Image maskImage; + + private static Logger logger = SkinLogger.getSkinLogger( + DisplayCanvas.class).getLogger(); + + /** + * Constructor + */ + public DisplayCanvas(Shell parent, int style) { + super(parent, style); + } + + public Image getMaskImage() { + return maskImage; + } + + public void setMaskImage(Image image) { + logger.info("set mask image : " + + image.getImageData().width + "x" + image.getImageData().height); + + maskImage = image; + } +} \ No newline at end of file diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java index 934231b..da978e8 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java @@ -99,9 +99,9 @@ public class EmulatorSdlSkin extends EmulatorSkin { /* org.eclipse.swt.widgets.Widget */ if (SwtUtil.isLinuxPlatform()) { try { - Field field = lcdCanvas.getClass().getField("embeddedHandle"); - windowHandleId = field.getLong(lcdCanvas); - logger.info("lcdCanvas.embeddedHandle:" + windowHandleId); + Field field = displayCanvas.getClass().getField("embeddedHandle"); + windowHandleId = field.getLong(displayCanvas); + logger.info("displayCanvas.embeddedHandle:" + windowHandleId); } catch (IllegalArgumentException e) { logger.log(Level.SEVERE, e.getMessage(), e); shutdown(); @@ -117,9 +117,9 @@ public class EmulatorSdlSkin extends EmulatorSkin { } } else if (SwtUtil.isWindowsPlatform()) { try { - Field field = lcdCanvas.getClass().getField("handle"); - windowHandleId = field.getLong(lcdCanvas); - logger.info("lcdCanvas.handle:" + windowHandleId); + Field field = displayCanvas.getClass().getField("handle"); + windowHandleId = field.getLong(displayCanvas); + logger.info("displayCanvas.handle:" + windowHandleId); } catch (IllegalArgumentException e) { logger.log(Level.SEVERE, e.getMessage(), e); shutdown(); 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 e7e4268..88b29e2 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 @@ -141,8 +141,8 @@ public class EmulatorShmSkin extends EmulatorSkin { this.runnable = new Runnable() { @Override public void run() { - if (lcdCanvas.isDisposed() == false) { - lcdCanvas.redraw(); + if (displayCanvas.isDisposed() == false) { + displayCanvas.redraw(); } } }; @@ -311,15 +311,15 @@ public class EmulatorShmSkin extends EmulatorSkin { currentState.getCurrentResolutionWidth(), currentState.getCurrentResolutionHeight()); - lcdCanvas.addPaintListener(new PaintListener() { + displayCanvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { /* e.gc.setAdvanced(true); if (!e.gc.getAdvanced()) { logger.info("Advanced graphics not supported"); } */ - final int screen_width = lcdCanvas.getSize().x; - final int screen_height = lcdCanvas.getSize().y; + final int screen_width = displayCanvas.getSize().x; + final int screen_height = displayCanvas.getSize().y; /* blank guide */ if (imageCover != null) { @@ -413,7 +413,7 @@ public class EmulatorShmSkin extends EmulatorSkin { public void run() { imageCover = image; - lcdCanvas.redraw(); + displayCanvas.redraw(); } }); } @@ -474,13 +474,13 @@ public class EmulatorShmSkin extends EmulatorSkin { finger.maruFingerProcessing1(eventType, e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } else if (finger.getMultiTouchEnable() == 2) { finger.maruFingerProcessing2(eventType, e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } @@ -510,14 +510,14 @@ public class EmulatorShmSkin extends EmulatorSkin { finger.maruFingerProcessing1(MouseEventType.RELEASE.value(), e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } else if (finger.getMultiTouchEnable() == 2) { logger.info("maruFingerProcessing 2"); finger.maruFingerProcessing2(MouseEventType.RELEASE.value(), e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } @@ -549,14 +549,14 @@ public class EmulatorShmSkin extends EmulatorSkin { finger.maruFingerProcessing1(MouseEventType.PRESS.value(), e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } else if (finger.getMultiTouchEnable() == 2) { logger.info("maruFingerProcessing 2"); finger.maruFingerProcessing2(MouseEventType.PRESS.value(), e.x, e.y, geometry[0], geometry[1]); - lcdCanvas.redraw(); + displayCanvas.redraw(); return; } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java old mode 100755 new mode 100644 index 0e36d65..ce19d61 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java @@ -65,7 +65,6 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.graphics.Transform; -import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -146,7 +145,7 @@ public class EmulatorSkin { public EmulatorConfig config; protected Shell shell; protected ImageRegistry imageRegistry; - protected Canvas lcdCanvas; + protected DisplayCanvas displayCanvas; private int displayCanvasStyle; public Transform displayTransform; public SkinInformation skinInfo; @@ -275,13 +274,13 @@ public class EmulatorSkin { skinComposer = new GeneralPurposeSkinComposer(config, this); } - lcdCanvas = skinComposer.compose(displayCanvasStyle); + displayCanvas = skinComposer.compose(displayCanvasStyle); /* */ //TODO: move if (config.getArgBoolean(ArgsConstants.INPUT_MOUSE, false) == true) { - prev_x = lcdCanvas.getSize().x / 2; - prev_y = lcdCanvas.getSize().y / 2; + prev_x = displayCanvas.getSize().x / 2; + prev_y = displayCanvas.getSize().y / 2; logger.info("prev_x : " + prev_x + " prev_y : " + prev_y); isDisplayOn = false; } @@ -293,7 +292,7 @@ public class EmulatorSkin { addMainWindowListeners(); addCanvasListeners(); - lcdCanvas.setFocus(); + displayCanvas.setFocus(); return 0; } @@ -326,6 +325,10 @@ public class EmulatorSkin { return shell; } + public DisplayCanvas getDisplayCanvas() { + return displayCanvas; + } + public EmulatorSkinState getEmulatorSkinState() { return currentState; } @@ -652,7 +655,7 @@ public class EmulatorSkin { public void mouseMove(MouseEvent e) { if (true == isDisplayDragging) { int eventType = MouseEventType.DRAG.value(); - Point canvasSize = lcdCanvas.getSize(); + Point canvasSize = displayCanvas.getSize(); if (e.x < 0) { e.x = 0; @@ -675,18 +678,18 @@ public class EmulatorSkin { } /* filtering for display mask */ - Region displayRegion = lcdCanvas.getRegion(); + Region displayRegion = displayCanvas.getRegion(); if (displayRegion != null && displayRegion.contains(e.x, e.y) == false) { logger.info("out of range touch event : " + e.x + ", " + e.y); - int angle = SkinUtil.getAngleFromVector(lcdCanvas, e.x, e.y); + int angle = SkinUtil.getAngleFromVector(displayCanvas, e.x, e.y); if (angle < 0) { angle += 360; } - final int displayCenterX = lcdCanvas.getSize().x / 2; - final int displayCenterY = lcdCanvas.getSize().y / 2; + final int displayCenterX = displayCanvas.getSize().x / 2; + final int displayCenterY = displayCanvas.getSize().y / 2; if (angle >= 45 && angle < 135) { /* down side */ do { @@ -729,7 +732,7 @@ public class EmulatorSkin { int diff_y = e.y - prev_y; int final_x = e.x; int final_y = e.y; - Point canvasSize = lcdCanvas.getSize(); + Point canvasSize = displayCanvas.getSize(); /* caculate maximum relative point */ if (final_x >= canvasSize.x) { @@ -763,7 +766,7 @@ public class EmulatorSkin { int eventType = MouseEventType.MOVE.value(); if (true == isDisplayDragging) { - Point canvasSize = lcdCanvas.getSize(); + Point canvasSize = displayCanvas.getSize(); eventType = MouseEventType.DRAG.value(); if (e.x < 0) { e.x = 0; @@ -932,18 +935,18 @@ public class EmulatorSkin { if (menu != null) { keyForceRelease(false); - lcdCanvas.setMenu(menu); + displayCanvas.setMenu(menu); menu.setVisible(true); e.doit = false; } else { - lcdCanvas.setMenu(null); + displayCanvas.setMenu(null); } } }; /* remove 'input method' menu item (avoid bug) */ - lcdCanvas.addMenuDetectListener(canvasMenuDetectListener); + displayCanvas.addMenuDetectListener(canvasMenuDetectListener); /* focus */ canvasFocusListener = new FocusListener() { @@ -961,7 +964,7 @@ public class EmulatorSkin { } }; - lcdCanvas.addFocusListener(canvasFocusListener); + displayCanvas.addFocusListener(canvasFocusListener); /* host mouse event */ if (config.getArgBoolean(ArgsConstants.INPUT_MOUSE, false) == true) { @@ -970,15 +973,15 @@ public class EmulatorSkin { canvasMouseListener = makeDisplayMouseClickListener(); canvasMouseWheelListener = makeDisplayMouseWheelListener(); - lcdCanvas.addMouseWheelListener(canvasMouseWheelListener); + displayCanvas.addMouseWheelListener(canvasMouseWheelListener); } else { /* mapping to virtual touch screen */ canvasMouseMoveListener = makeDisplayTouchMoveListener(); canvasMouseListener = makeDisplayTouchClickListener(); } - lcdCanvas.addMouseMoveListener(canvasMouseMoveListener); - lcdCanvas.addMouseListener(canvasMouseListener); + displayCanvas.addMouseMoveListener(canvasMouseMoveListener); + displayCanvas.addMouseListener(canvasMouseListener); /* host keyboard event */ canvasKeyListener = new KeyListener() { @@ -1173,7 +1176,7 @@ public class EmulatorSkin { } }; - lcdCanvas.addKeyListener(canvasKeyListener); + displayCanvas.addKeyListener(canvasKeyListener); } /* for display */ @@ -1290,27 +1293,27 @@ public class EmulatorSkin { private void removeCanvasListeners() { if (null != canvasMouseMoveListener) { - lcdCanvas.removeMouseMoveListener(canvasMouseMoveListener); + displayCanvas.removeMouseMoveListener(canvasMouseMoveListener); } if (null != canvasMouseListener) { - lcdCanvas.removeMouseListener(canvasMouseListener); + displayCanvas.removeMouseListener(canvasMouseListener); } if (null != canvasKeyListener) { - lcdCanvas.removeKeyListener(canvasKeyListener); + displayCanvas.removeKeyListener(canvasKeyListener); } if (null != canvasMenuDetectListener) { - lcdCanvas.removeMenuDetectListener(canvasMenuDetectListener); + displayCanvas.removeMenuDetectListener(canvasMenuDetectListener); } if (null != canvasFocusListener) { - lcdCanvas.removeFocusListener(canvasFocusListener); + displayCanvas.removeFocusListener(canvasFocusListener); } if (null != canvasMouseWheelListener) { - lcdCanvas.removeMouseWheelListener(canvasMouseWheelListener); + displayCanvas.removeMouseWheelListener(canvasMouseWheelListener); } } @@ -1333,24 +1336,22 @@ public class EmulatorSkin { displayTransform.dispose(); } - displayTransform = new Transform(lcdCanvas.getDisplay()); + displayTransform = new Transform(displayCanvas.getDisplay()); short rotationId = currentState.getCurrentRotationId(); displayTransform.rotate(SkinRotations.getAngle(rotationId)); if (rotationId == SkinRotations.LANDSCAPE_ID) { /* landscape */ - displayTransform.translate( - lcdCanvas.getSize().y * -1, 0); + displayTransform.translate(displayCanvas.getSize().y * -1, 0); } else if (rotationId == SkinRotations.REVERSE_PORTRAIT_ID) { /* reverse-portrait */ displayTransform.translate( - lcdCanvas.getSize().x * -1, - lcdCanvas.getSize().y * -1); + displayCanvas.getSize().x * -1, + displayCanvas.getSize().y * -1); } else if (rotationId == SkinRotations.REVERSE_LANDSCAPE_ID) { /* reverse-landscape */ - displayTransform.translate( - 0, lcdCanvas.getSize().x * -1); + displayTransform.translate(0, displayCanvas.getSize().x * -1); } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java index e48d5d8..67578d9 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java @@ -47,6 +47,7 @@ import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.skin.DisplayCanvas; import org.tizen.emulator.skin.EmulatorSkin; import org.tizen.emulator.skin.EmulatorSkinMain; import org.tizen.emulator.skin.config.EmulatorConfig; @@ -77,7 +78,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { private EmulatorConfig config; private EmulatorSkin skin; private Shell shell; - private Canvas displayCanvas; + private DisplayCanvas displayCanvas; private Color backgroundColor; private CustomButton toggleButton; private ColorTag pairTag; @@ -115,10 +116,10 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } @Override - public Canvas compose(int style) { + public DisplayCanvas compose(int style) { shell.setBackground(backgroundColor); - displayCanvas = new Canvas(shell, style); + displayCanvas = new DisplayCanvas(shell, style); int x = config.getValidWindowX(); int y = config.getValidWindowY(); @@ -133,7 +134,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } @Override - public void composeInternal(Canvas displayCanvas, + public void composeInternal(DisplayCanvas displayCanvas, final int x, final int y, int scale, short rotationId) { shell.setLocation(x, y); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java index 478d334..e126843 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java @@ -30,11 +30,12 @@ package org.tizen.emulator.skin.layout; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; +import org.tizen.emulator.skin.DisplayCanvas; public interface ISkinComposer { - public abstract Canvas compose(int style); + public abstract DisplayCanvas compose(int style); - public abstract void composeInternal(Canvas lcdCanvas, + public abstract void composeInternal(DisplayCanvas DisplayCanvas, int x, int y, int scale, short rotationId); public abstract void arrangeSkin(int scale, short rotationId); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java index 226e5b7..0b69aed 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ProfileSpecificSkinComposer.java @@ -48,6 +48,7 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.skin.DisplayCanvas; import org.tizen.emulator.skin.EmulatorSkin; import org.tizen.emulator.skin.EmulatorSkinMain; import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType; @@ -75,12 +76,12 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { private Logger logger = SkinLogger.getSkinLogger( ProfileSpecificSkinComposer.class).getLogger(); - private EmulatorConfig config; - private EmulatorSkin skin; - private Shell shell; - private Canvas lcdCanvas; - private EmulatorSkinState currentState; - private SocketCommunicator communicator; + protected EmulatorConfig config; + protected EmulatorSkin skin; + protected Shell shell; + protected DisplayCanvas displayCanvas; + protected EmulatorSkinState currentState; + protected SocketCommunicator communicator; private PaintListener shellPaintListener; private MouseTrackListener shellMouseTrackListener; @@ -107,23 +108,24 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { } @Override - public Canvas compose(int style) { - lcdCanvas = new Canvas(shell, style); + public DisplayCanvas compose(int style) { + displayCanvas = new DisplayCanvas(shell, style); + displayCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); int x = config.getValidWindowX(); int y = config.getValidWindowY(); int scale = currentState.getCurrentScale(); short rotationId = currentState.getCurrentRotationId(); - composeInternal(lcdCanvas, x, y, scale, rotationId); + composeInternal(displayCanvas, x, y, scale, rotationId); logger.info("resolution : " + currentState.getCurrentResolution() + ", scale : " + scale); - return lcdCanvas; + return displayCanvas; } @Override - public void composeInternal(Canvas lcdCanvas, + public void composeInternal(DisplayCanvas displayCanvas, int x, int y, int scale, short rotationId) { shell.setLocation(x, y); @@ -131,7 +133,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { String emulatorName = SkinUtil.makeEmulatorName(config); shell.setText(SkinUtil.EMULATOR_PREFIX + " - " + emulatorName); - lcdCanvas.setBackground( + displayCanvas.setBackground( shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); shell.setImage(skin.getImageRegistry().getIcon( @@ -181,7 +183,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { //TODO: eject the calculation from UI thread /* calculate display bounds */ - Rectangle displayBounds = adjustDisplayGeometry(lcdCanvas, + Rectangle displayBounds = adjustDisplayGeometry(displayCanvas, currentState.getCurrentResolutionWidth(), currentState.getCurrentResolutionHeight(), scale, rotationId); @@ -198,15 +200,17 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { Image mask = imageRegistry.getSkinImage(rotationId, SkinImageType.DISPLAY_MASK_IMAGE); if (mask != null) { + displayCanvas.setMaskImage(mask); + logger.info("display masking"); mask = SkinUtil.createScaledImage( shell.getDisplay(), mask, rotationId, scale); - lcdCanvas.setRegion(SkinUtil.getTrimmedRegion(mask)); + displayCanvas.setRegion(SkinUtil.getTrimmedRegion(mask)); mask.dispose(); } else { - lcdCanvas.setRegion(null); + displayCanvas.setRegion(null); } /* make profile skin */ @@ -250,7 +254,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { /* arrange the display */ if (SwtUtil.isMacPlatform() == true) { - lcdCanvas.setBounds(currentState.getDisplayBounds()); + displayCanvas.setBounds(currentState.getDisplayBounds()); } /* arrange the progress bar */ @@ -366,7 +370,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { logger.info("shell transform was changed"); if (SwtUtil.isMacPlatform() == false) { - lcdCanvas.setBounds(currentState.getDisplayBounds()); + displayCanvas.setBounds(currentState.getDisplayBounds()); } skin.setSuitableTransform();