From e35d066b6156550986944528f4bfce32ad6d1363 Mon Sep 17 00:00:00 2001 From: Son Hyunjun Date: Mon, 2 Apr 2012 17:25:44 +0900 Subject: [PATCH] [Title] increate java booting performance [Type] Feature [Module] Skin [Priority] Minor [CQ#] [Redmine#] [Problem] all of the skin image loading takes a long time in booting sequence. [Cause] [Solution] lazy loading Change-Id: I7ebec0e1949e9154c8d9df68724acbfee082d371 --- .../org/tizen/emulator/skin/EmulatorSkin.java | 14 +- .../emulator/skin/image/ImageRegistry.java | 172 +++++++++++------- .../tizen/emulator/skin/util/SkinUtil.java | 8 + 3 files changed, 121 insertions(+), 73 deletions(-) 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 index 13bcbcb6a7..1f001fc711 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java @@ -229,6 +229,12 @@ public class EmulatorSkin { arrangeSkin( lcdWidth, lcdHeight, scale, rotationId ); + if ( null == currentImage ) { + logger.severe( "Fail to load initial skin image file. Kill this skin process!!!" ); + SkinUtil.openMessage( shell, null, "Fail to load Skin image file.", SWT.ICON_ERROR, config ); + System.exit( -1 ); + } + seteHoverColor(); setMenu(); @@ -400,9 +406,11 @@ public class EmulatorSkin { SkinUtil.trimShell( shell, currentImage ); SkinUtil.adjustLcdGeometry( lcdCanvas, scale, rotationId ); - ImageData imageData = currentImage.getImageData(); - shell.setMinimumSize( imageData.width, imageData.height ); - shell.setSize( imageData.width, imageData.height ); + if( null != currentImage ) { + ImageData imageData = currentImage.getImageData(); + shell.setMinimumSize( imageData.width, imageData.height ); + shell.setSize( imageData.width, imageData.height ); + } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java index 8bfc31143e..dedc5a07b6 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java @@ -36,7 +36,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.logging.Logger; import org.eclipse.swt.graphics.Image; @@ -105,35 +104,37 @@ public class ImageRegistry { private int resolutionWidth; private int resolutionHeight; private EmulatorUI dbiContents; - + private Map skinImageMap; private Map iconMap; + private String argSkinPath; + private static ImageRegistry instance; private static boolean isInitialized; - + private ImageRegistry() { } - + public static ImageRegistry getInstance() { - if( null == instance ) { + if ( null == instance ) { instance = new ImageRegistry(); } return instance; } - - public void initialize( EmulatorConfig config ) { - - if( isInitialized ) { + + public void initialize( EmulatorConfig config ) { + + if ( isInitialized ) { return; } isInitialized = true; - + this.display = Display.getDefault(); int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) ); int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) ); - String skinPath = (String) config.getArg( ArgsConstants.SKIN_PATH ); + this.argSkinPath = (String) config.getArg( ArgsConstants.SKIN_PATH ); this.resolutionWidth = lcdWidth; this.resolutionHeight = lcdHeight; @@ -141,111 +142,142 @@ public class ImageRegistry { this.skinImageMap = new HashMap(); this.iconMap = new HashMap(); - init( skinPath ); + init( this.argSkinPath ); } - + public static String getSkinPath( String argSkinPath, int lcdWidth, int lcdHeight ) { - String skinPath = ".." + File.separator + SKIN_FOLDER + File.separator + - IMAGE_FOLDER_PREFIX + lcdWidth + "x" + lcdHeight; + String skinPath = ".." + File.separator + SKIN_FOLDER + File.separator + IMAGE_FOLDER_PREFIX + lcdWidth + "x" + + lcdHeight; - if (argSkinPath == null) { + if ( argSkinPath == null ) { return skinPath; } - File f = new File(argSkinPath); - if (f.isDirectory() == false) { + File f = new File( argSkinPath ); + if ( f.isDirectory() == false ) { return skinPath; } return argSkinPath; } - private void init(String argSkinPath) { + private void init( String argSkinPath ) { - String skinPath = getSkinPath( argSkinPath, resolutionWidth, resolutionHeight ); - RotationsType rotations = dbiContents.getRotations(); - - if( null == rotations ) { + + if ( null == rotations ) { logger.severe( "Fail to loading rotations element from dbi." ); return; } - + List rotationList = rotations.getRotation(); for ( RotationType rotation : rotationList ) { SkinRotation.put( rotation ); } - for ( RotationType rotation : rotationList ) { + } - ImageListType imageList = rotation.getImageList(); - String mainImage = imageList.getMainImage(); - String keyPressedImage = imageList.getKeyPressedImage(); + public ImageData getSkinImageData( Short id, ImageType imageType ) { + + Image image = skinImageMap.get( makeKey( id, imageType ) ); - Iterator> rotationIterator = SkinRotation.getRotationIterator(); + if ( null != image ) { - while ( rotationIterator.hasNext() ) { + return image.getImageData(); - Entry entry = rotationIterator.next(); + } else { - if ( entry.getValue().getName().value().equals( rotation.getName().value() ) ) { + RotationsType rotations = dbiContents.getRotations(); - String mainKey = makeKey( entry.getKey(), ImageType.IMG_TYPE_MAIN ); + if ( null == rotations ) { + logger.severe( "Fail to loading rotations element from dbi." ); + return null; + } + + String skinPath = getSkinPath( argSkinPath, resolutionWidth, resolutionHeight ); + + RotationType targetRotation = SkinRotation.getRotation( id ); + + List rotationList = rotations.getRotation(); + + for ( RotationType rotation : rotationList ) { + + ImageListType imageList = rotation.getImageList(); + String mainImage = imageList.getMainImage(); + String keyPressedImage = imageList.getKeyPressedImage(); + + if ( targetRotation.getName().value().equals( rotation.getName().value() ) ) { + + String mainKey = makeKey( id, ImageType.IMG_TYPE_MAIN ); skinImageMap.put( mainKey, new Image( display, skinPath + File.separator + mainImage ) ); - String pressedKey = makeKey( entry.getKey(), ImageType.IMG_TYPE_PRESSED ); + String pressedKey = makeKey( id, ImageType.IMG_TYPE_PRESSED ); skinImageMap.put( pressedKey, new Image( display, skinPath + File.separator + keyPressedImage ) ); + break; + } + } - } - - ClassLoader classLoader = this.getClass().getClassLoader(); - IconName[] values = IconName.values(); - - for ( IconName iconName : values ) { - - String name = iconName.getName(); - - String iconPath = ICON_FOLDER + "/" + name; - - InputStream is = null; - try { - is = classLoader.getResourceAsStream( iconPath ); - if( null != is ) { - logger.fine( "load icon:" + iconPath ); - iconMap.put( name, new Image( display, is ) ); - }else { - logger.severe( "missing icon:" + iconPath ); - } - } finally { - IOUtil.close( is ); + Image registeredImage = skinImageMap.get( makeKey( id, imageType ) ); + + if ( null != registeredImage ) { + return registeredImage.getImageData(); + } else { + return null; } - - } - } - - public ImageData getSkinImageData( Short id, ImageType imageType ) { - Image image = skinImageMap.get( makeKey(id, imageType) ); - if( null != image ) { - return image.getImageData(); - }else { - return null; } } - + private String makeKey( Short id, ImageType imageType ) { return id + ":" + imageType.ordinal(); } - + public Image getIcon( IconName name ) { - return iconMap.get( name.getName() ); + + if ( 0 != iconMap.size() ) { + + Image image = iconMap.get( name.getName() ); + return image; + + } else { + + // load all of the icons at once. + + ClassLoader classLoader = this.getClass().getClassLoader(); + IconName[] values = IconName.values(); + + for ( IconName iconName : values ) { + + String icoNname = iconName.getName(); + + String iconPath = ICON_FOLDER + "/" + icoNname; + + InputStream is = null; + try { + is = classLoader.getResourceAsStream( iconPath ); + if ( null != is ) { + logger.fine( "load icon:" + iconPath ); + iconMap.put( icoNname, new Image( display, is ) ); + } else { + logger.severe( "missing icon:" + iconPath ); + } + } finally { + IOUtil.close( is ); + } + + } + + return iconMap.get( name.getName() ); + + } + } - + public void dispose() { Collection images = skinImageMap.values(); 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 c91d7d9662..76cc6dcdc3 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 @@ -219,6 +219,10 @@ public class SkinUtil { // trim transparent pixels in image. especially, corner round areas. + if ( null == image ) { + return; + } + ImageData imageData = image.getImageData(); int width = imageData.width; @@ -271,6 +275,10 @@ public class SkinUtil { ImageData originalImageData = imageRegistry.getSkinImageData( rotationId, type ); + if ( null == originalImageData ) { + return null; + } + ImageData imageData = (ImageData) originalImageData.clone(); float convertedScale = convertScale( scale ); -- 2.34.1