From: GiWoong Kim Date: Thu, 17 Oct 2013 09:07:20 +0000 (+0900) Subject: skin: function call re-ordering in arrangeSkin() & etc X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~687 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7001337d71eac62979019086c9e7c556e0e8b8e0;p=sdk%2Femulator%2Fqemu.git skin: function call re-ordering in arrangeSkin() & etc Change-Id: Ib3f26f7ca8b7759fc5998b67ed07d38ac41cb05c Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java index c7c2e1e07f..58cff1f518 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java @@ -123,10 +123,10 @@ public class SpecialKeyWindow extends SkinWindow { /* get keywindow image */ //TODO: null - keyWindowImage = imageRegistry.getKeyWindowImage( + this.keyWindowImage = imageRegistry.getKeyWindowImage( EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_NORMAL); - keyWindowPressedImage = imageRegistry.getKeyWindowImage( + this.keyWindowPressedImage = imageRegistry.getKeyWindowImage( EmulatorConfig.DEFAULT_WINDOW_ROTATION, SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); @@ -136,7 +136,7 @@ public class SpecialKeyWindow extends SkinWindow { keyWindowImage.getImageData().height); /* custom window shape */ - SkinUtil.trimShell(shell, keyWindowImage); + shell.setRegion(SkinUtil.getTrimmingRegion(keyWindowImage)); addKeyWindowListener(); } 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 73c6e6b6fb..f524d31489 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 @@ -44,6 +44,7 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; 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.EmulatorSkin; import org.tizen.emulator.skin.EmulatorSkinState; @@ -143,7 +144,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { /* This string must match the definition of Emulator-Manager */ String emulatorName = SkinUtil.makeEmulatorName(config); - shell.setText("Emulator - " + emulatorName); + shell.setText(SkinUtil.EMULATOR_PREFIX + " - " + emulatorName); displayCanvas.setBackground( shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); @@ -217,8 +218,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { skin.getKeyWindowKeeper().openKeyWindow( SWT.RIGHT | SWT.CENTER, false); } else { - skin.getKeyWindowKeeper().openKeyWindow( - dockValue, false); + skin.getKeyWindowKeeper().openKeyWindow(dockValue, false); } } }); @@ -227,13 +227,13 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { @Override public void arrangeSkin(int scale, short rotationId) { - currentState.setCurrentScale(scale); - currentState.setCurrentRotationId(rotationId); + //TODO: eject the calculation from UI thread - /* arrange the display */ - Rectangle displayBounds = adjustLcdGeometry(displayCanvas, + /* calculate display bounds */ + Rectangle displayBounds = adjustDisplayGeometry(displayCanvas, currentState.getCurrentResolutionWidth(), - currentState.getCurrentResolutionHeight(), scale, rotationId); + currentState.getCurrentResolutionHeight(), + scale, rotationId); if (displayBounds == null) { logger.severe("Failed to read display information for skin."); @@ -245,23 +245,31 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } logger.info("display bounds : " + displayBounds); + /* make general skin */ + Image generalSkin = + frameMaker.getPatchedImage(displayBounds.width, displayBounds.height); + + /* make window region */ + Region region = getTrimmingRegion(shell.getDisplay(), generalSkin); + + /* update the skin state information */ + currentState.setCurrentScale(scale); + currentState.setCurrentRotationId(rotationId); currentState.setDisplayBounds(displayBounds); - displayCanvas.setBounds(displayBounds); - /* arrange the skin image */ Image tempImage = null; - if (currentState.getCurrentImage() != null) { tempImage = currentState.getCurrentImage(); } - - currentState.setCurrentImage( - frameMaker.getPatchedImage(displayBounds.width, displayBounds.height)); + currentState.setCurrentImage(generalSkin); if (tempImage != null) { tempImage.dispose(); } + /* arrange the display */ + displayCanvas.setBounds(displayBounds); + /* arrange the toggle button of key window */ toggleButton.setBounds(displayBounds.x + displayBounds.width + 4, displayBounds.y + ((displayBounds.height - toggleButton.getImageSize().y) / 2), @@ -280,22 +288,21 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } /* arrange the pair tag */ - int rotationType = currentState.getCurrentRotationId(); - if (rotationType == RotationInfo.PORTRAIT.id()) { + if (rotationId == RotationInfo.PORTRAIT.id()) { skin.pairTag.setBounds( PAIR_TAG_POSITION_X, PAIR_TAG_POSITION_Y, skin.pairTag.getWidth(), skin.pairTag.getHeight()); - } else if (rotationType == RotationInfo.LANDSCAPE.id()) { + } else if (rotationId == RotationInfo.LANDSCAPE.id()) { skin.pairTag.setBounds( PAIR_TAG_POSITION_Y, shell.getSize().y - PAIR_TAG_POSITION_X - skin.pairTag.getHeight(), skin.pairTag.getWidth(), skin.pairTag.getHeight()); - } else if (rotationType == RotationInfo.REVERSE_PORTRAIT.id()) { + } else if (rotationId == RotationInfo.REVERSE_PORTRAIT.id()) { skin.pairTag.setBounds( shell.getSize().x - PAIR_TAG_POSITION_X - skin.pairTag.getWidth(), shell.getSize().y - PAIR_TAG_POSITION_Y - skin.pairTag.getHeight(), skin.pairTag.getWidth(), skin.pairTag.getHeight()); - } else if (rotationType == RotationInfo.REVERSE_LANDSCAPE.id()) { + } else if (rotationId == RotationInfo.REVERSE_LANDSCAPE.id()) { skin.pairTag.setBounds( shell.getSize().x - PAIR_TAG_POSITION_Y - skin.pairTag.getWidth(), PAIR_TAG_POSITION_X, @@ -303,51 +310,53 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } /* custom window shape */ - trimPatchedShell(shell, currentState.getCurrentImage()); + if (region != null) { + shell.setRegion(region); + } currentState.setNeedToUpdateDisplay(true); shell.redraw(); } @Override - public Rectangle adjustLcdGeometry( + public Rectangle adjustDisplayGeometry( Canvas displayCanvas, int resolutionW, int resolutionH, int scale, short rotationId) { - Rectangle lcdBounds = new Rectangle( + Rectangle displayBounds = new Rectangle( frameMaker.getPatchWidth(), frameMaker.getPatchHeight(), 0, 0); float convertedScale = SkinUtil.convertScale(scale); RotationInfo rotation = RotationInfo.getValue(rotationId); - /* resoultion, that is lcd size in general skin mode */ + /* resoultion, that is display size in general skin mode */ if (RotationInfo.LANDSCAPE == rotation || RotationInfo.REVERSE_LANDSCAPE == rotation) { - lcdBounds.width = (int)(resolutionH * convertedScale); - lcdBounds.height = (int)(resolutionW * convertedScale); + displayBounds.width = (int)(resolutionH * convertedScale); + displayBounds.height = (int)(resolutionW * convertedScale); } else { - lcdBounds.width = (int)(resolutionW * convertedScale); - lcdBounds.height = (int)(resolutionH * convertedScale); + displayBounds.width = (int)(resolutionW * convertedScale); + displayBounds.height = (int)(resolutionH * convertedScale); } - return lcdBounds; + return displayBounds; } - public static void trimPatchedShell(Shell shell, Image image) { + public static Region getTrimmingRegion(Display display, Image image) { if (null == image) { - return; + return null; } - ImageData imageData = image.getImageData(); + ImageData imageData = image.getImageData(); int width = imageData.width; int height = imageData.height; Region region = new Region(); region.add(new Rectangle(0, 0, width, height)); - int r = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getRed(); - int g = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getGreen(); - int b = shell.getDisplay().getSystemColor(SWT.COLOR_MAGENTA).getBlue(); + int r = display.getSystemColor(SWT.COLOR_MAGENTA).getRed(); + int g = display.getSystemColor(SWT.COLOR_MAGENTA).getGreen(); + int b = display.getSystemColor(SWT.COLOR_MAGENTA).getBlue(); int colorKey = 0; if (SwtUtil.isWindowsPlatform()) { @@ -356,8 +365,9 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { colorKey = r << 16 | g << 8 | b; } + int j = 0; for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { + for (j = 0; j < height; j++) { int colorPixel = imageData.getPixel(i, j); if (colorPixel == colorKey /* magenta */) { region.subtract(i, j, 1, 1); @@ -365,7 +375,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { } } - shell.setRegion(region); + return region; } public void addGeneralPurposeListener(final Shell shell) { 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 34aee84730..eed873e464 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 @@ -1,7 +1,7 @@ /** - * + * Skin Composer Interface * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim @@ -39,8 +39,8 @@ public interface ISkinComposer { public abstract void arrangeSkin(int scale, short rotationId); - public abstract Rectangle adjustLcdGeometry( - Canvas lcdCanvas, int resolutionW, int resolutionH, + public abstract Rectangle adjustDisplayGeometry( + Canvas displayCanvas, int resolutionW, int resolutionH, int scale, short rotationId); public abstract void composerFinalize(); 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 74dee615ef..78ea4ea583 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 @@ -45,6 +45,7 @@ import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; 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.EmulatorSkin; @@ -134,7 +135,7 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { /* This string must match the definition of Emulator-Manager */ String emulatorName = SkinUtil.makeEmulatorName(config); - shell.setText("Emulator - " + emulatorName); + shell.setText(SkinUtil.EMULATOR_PREFIX + " - " + emulatorName); lcdCanvas.setBackground( shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); @@ -185,15 +186,14 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { @Override public void arrangeSkin(int scale, short rotationId) { - currentState.setCurrentScale(scale); - currentState.setCurrentRotationId(rotationId); + //TODO: eject the calculation from UI thread - /* arrange the display */ - Rectangle lcdBounds = adjustLcdGeometry(lcdCanvas, + /* calculate display bounds */ + Rectangle displayBounds = adjustDisplayGeometry(lcdCanvas, currentState.getCurrentResolutionWidth(), currentState.getCurrentResolutionHeight(), scale, rotationId); - if (lcdBounds == null) { + if (displayBounds == null) { logger.severe("Failed to read display information for skin."); SkinUtil.openMessage(shell, null, "Failed to read display information for skin.\n" + @@ -201,11 +201,27 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { SWT.ICON_ERROR, config); System.exit(-1); } - logger.info("display bounds : " + lcdBounds); + logger.info("display bounds : " + displayBounds); + + /* make profile skin */ + Image originSkin = imageRegistry.getSkinImage( + rotationId, SkinImageType.PROFILE_IMAGE_TYPE_NORMAL); + Image profileSkin = SkinUtil.createScaledImage( + shell.getDisplay(), originSkin, rotationId, scale); + + Image originSkinKeyPressed = imageRegistry.getSkinImage( + rotationId, SkinImageType.PROFILE_IMAGE_TYPE_PRESSED); + Image profileSkinKeyPressed = SkinUtil.createScaledImage( + shell.getDisplay(), originSkinKeyPressed, rotationId, scale); - currentState.setDisplayBounds(lcdBounds); + /* make window region */ + Region region = SkinUtil.getTrimmingRegion(profileSkin); + + /* update the skin state information */ + currentState.setCurrentScale(scale); + currentState.setCurrentRotationId(rotationId); + currentState.setDisplayBounds(displayBounds); - /* arrange the skin image */ Image tempImage = null; Image tempKeyPressedImage = null; @@ -216,14 +232,8 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { tempKeyPressedImage = currentState.getCurrentKeyPressedImage(); } - currentState.setCurrentImage(SkinUtil.createScaledImage( - shell.getDisplay(), imageRegistry, - SkinImageType.PROFILE_IMAGE_TYPE_NORMAL, - rotationId, scale)); - currentState.setCurrentKeyPressedImage(SkinUtil.createScaledImage( - shell.getDisplay(), imageRegistry, - SkinImageType.PROFILE_IMAGE_TYPE_PRESSED, - rotationId, scale)); + currentState.setCurrentImage(profileSkin); + currentState.setCurrentKeyPressedImage(profileSkinKeyPressed); if (tempImage != null) { tempImage.dispose(); @@ -232,14 +242,15 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { tempKeyPressedImage.dispose(); } + /* arrange the display */ if (SwtUtil.isMacPlatform() == true) { lcdCanvas.setBounds(currentState.getDisplayBounds()); } /* arrange the progress bar */ if (skin.bootingProgress != null) { - skin.bootingProgress.setBounds(lcdBounds.x, - lcdBounds.y + lcdBounds.height + 1, lcdBounds.width, 2); + skin.bootingProgress.setBounds(displayBounds.x, + displayBounds.y + displayBounds.height + 1, displayBounds.width, 2); } /* set window size */ @@ -249,27 +260,29 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { } /* custom window shape */ - SkinUtil.trimShell(shell, currentState.getCurrentImage()); + if (region != null) { + shell.setRegion(region); + } currentState.setNeedToUpdateDisplay(true); shell.redraw(); } @Override - public Rectangle adjustLcdGeometry( - Canvas lcdCanvas, int resolutionW, int resolutionH, + public Rectangle adjustDisplayGeometry( + Canvas displayCanvas, int resolutionW, int resolutionH, int scale, short rotationId) { - Rectangle lcdBounds = new Rectangle(0, 0, 0, 0); + Rectangle displayBounds = new Rectangle(0, 0, 0, 0); float convertedScale = SkinUtil.convertScale(scale); RotationType rotation = SkinRotation.getRotation(rotationId); - DisplayType lcd = rotation.getDisplay(); /* from dbi */ - if (lcd == null) { + DisplayType display = rotation.getDisplay(); /* from dbi */ + if (display == null) { return null; } - RegionType region = lcd.getRegion(); + RegionType region = display.getRegion(); if (region == null) { return null; } @@ -279,12 +292,12 @@ public class ProfileSpecificSkinComposer implements ISkinComposer { Integer width = region.getWidth(); Integer height = region.getHeight(); - lcdBounds.x = (int) (left * convertedScale); - lcdBounds.y = (int) (top * convertedScale); - lcdBounds.width = (int) (width * convertedScale); - lcdBounds.height = (int) (height * convertedScale); + displayBounds.x = (int) (left * convertedScale); + displayBounds.y = (int) (top * convertedScale); + displayBounds.width = (int) (width * convertedScale); + displayBounds.height = (int) (height * convertedScale); - return lcdBounds; + return displayBounds; } public void addProfileSpecificListener(final Shell shell) { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java deleted file mode 100644 index d66c0a4d51..0000000000 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/KeyWindowRotation.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * - * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * GiWoong Kim - * YeongKyoon Lee - * HyunJun Son - * Hyunjin Lee rotationMap; - private static Map angleMap; - - private KeyWindowRotation(){} - - static { - rotationMap = new LinkedHashMap(); - angleMap = new HashMap(); - } - - public static void clear() { - if (!rotationMap.isEmpty()) - rotationMap.clear(); - if (!angleMap.isEmpty()) - angleMap.clear(); - } - - public static void put(RotationType rotation ) { - - if ( RotationInfo.PORTRAIT.value().equalsIgnoreCase( rotation.getName().value() ) ) { - rotationMap.put( RotationInfo.PORTRAIT.id(), rotation ); - angleMap.put( RotationInfo.PORTRAIT.id(), RotationInfo.PORTRAIT ); - } else if ( RotationInfo.LANDSCAPE.value().equalsIgnoreCase( rotation.getName().value() ) ) { - rotationMap.put( RotationInfo.LANDSCAPE.id(), rotation ); - angleMap.put( RotationInfo.LANDSCAPE.id(), RotationInfo.LANDSCAPE ); - } else if ( RotationInfo.REVERSE_PORTRAIT.value().equalsIgnoreCase( rotation.getName().value() ) ) { - rotationMap.put( RotationInfo.REVERSE_PORTRAIT.id(), rotation ); - angleMap.put( RotationInfo.REVERSE_PORTRAIT.id(), RotationInfo.REVERSE_PORTRAIT ); - } else if ( RotationInfo.REVERSE_LANDSCAPE.value().equalsIgnoreCase( rotation.getName().value() ) ) { - rotationMap.put( RotationInfo.REVERSE_LANDSCAPE.id(), rotation ); - angleMap.put( RotationInfo.REVERSE_LANDSCAPE.id(), RotationInfo.REVERSE_LANDSCAPE ); - } - - } - - public static int getAngle( Short rotationId ) { - RotationInfo rotationInfo = angleMap.get(rotationId); - if( null != rotationInfo ) { - return rotationInfo.angle(); - }else { - return 0; - } - } - - public static RotationType getRotation( Short rotationId ) { - return rotationMap.get(rotationId); - } - - public static Iterator>getRotationIterator() { - return rotationMap.entrySet().iterator(); - } - -} diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java index 46f02fffe8..101dc639db 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java @@ -56,8 +56,6 @@ import org.tizen.emulator.skin.dbi.KeyMapListType; import org.tizen.emulator.skin.dbi.KeyMapType; import org.tizen.emulator.skin.dbi.RegionType; import org.tizen.emulator.skin.dbi.RotationType; -import org.tizen.emulator.skin.image.ProfileSkinImageRegistry; -import org.tizen.emulator.skin.image.ProfileSkinImageRegistry.SkinImageType; import org.tizen.emulator.skin.layout.HWKey; import org.tizen.emulator.skin.log.SkinLogger; @@ -73,7 +71,7 @@ public class SkinUtil { public static final int UNKNOWN_KEYCODE = -1; public static final int SCALE_CONVERTER = 100; - public static final String EMULATOR_PREFIX = "emulator"; + public static final String EMULATOR_PREFIX = "Emulator"; private static Logger logger = SkinLogger.getSkinLogger(SkinUtil.class).getLogger(); @@ -199,31 +197,28 @@ public class SkinUtil { return false; } - public static void trimShell(Shell shell, Image image) { - /* trim transparent pixels in image. - * especially, corner round areas. */ + public static Region getTrimmingRegion(Image image) { if (null == image) { - return; + return null; } ImageData imageData = image.getImageData(); - int width = imageData.width; int height = imageData.height; Region region = new Region(); region.add(new Rectangle(0, 0, width, height)); + int j = 0; for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - int alpha = imageData.getAlpha(i, j); - if (0 == alpha) { + for (j = 0; j < height; j++) { + if (0 == imageData.getAlpha(i, j)) { region.subtract(i, j, 1, 1); } } } - shell.setRegion(region); + return region; } public static void trimShell(Shell shell, Image image, @@ -233,7 +228,6 @@ public class SkinUtil { } ImageData imageData = image.getImageData(); - int right = left + width; int bottom = top + height; @@ -242,10 +236,10 @@ public class SkinUtil { return; } + int j = 0; for (int i = left; i < right; i++) { - for (int j = top; j < bottom; j++) { - int alpha = imageData.getAlpha(i, j); - if (0 == alpha) { + for (j = top; j < bottom; j++) { + if (0 == imageData.getAlpha(i, j)) { region.subtract(i, j, 1, 1); } else { region.add(i, j, 1, 1); @@ -282,9 +276,7 @@ public class SkinUtil { } public static Image createScaledImage(Display display, - ProfileSkinImageRegistry imageRegistry, SkinImageType type, - short rotationId, int scale) { - Image imageOrigin = imageRegistry.getSkinImage(rotationId, type); + Image imageOrigin, short rotationId, int scale) { if (imageOrigin == null) { return null; }