From: giwoong.kim Date: Wed, 17 Apr 2013 04:30:47 +0000 (+0900) Subject: screenshot: optimize a framebuffer copying X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1001 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ed0a6f9d49ea9fad1b72d5fd52a9abb0b9f4660;p=sdk%2Femulator%2Fqemu.git screenshot: optimize a framebuffer copying optimize a framebuffer copying in screenshot window Signed-off-by: GiWoong Kim --- 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 149137ca02..632b55b49d 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 @@ -138,7 +138,7 @@ public class EmulatorSdlSkin extends EmulatorSkin { } try { - screenShotDialog = new SdlScreenShotWindow(shell, communicator, this, config, + screenShotDialog = new SdlScreenShotWindow(shell, this, config, imageRegistry.getIcon(IconName.SCREENSHOT)); screenShotDialog.open(); 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 dc33f41324..3b15aa3d09 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 @@ -50,14 +50,14 @@ import org.tizen.emulator.skin.screenshot.ShmScreenShotWindow; import org.tizen.emulator.skin.util.SkinUtil; public class EmulatorShmSkin extends EmulatorSkin { - private Logger logger = SkinLogger.getSkinLogger( - EmulatorShmSkin.class).getLogger(); - public static final int RED_MASK = 0x00FF0000; public static final int GREEN_MASK = 0x0000FF00; public static final int BLUE_MASK = 0x000000FF; public static final int COLOR_DEPTH = 24; /* no need to Alpha channel */ + private Logger logger = SkinLogger.getSkinLogger( + EmulatorShmSkin.class).getLogger(); + /* define JNI functions */ public native int shmget(int shmkey, int size); public native int shmdt(); @@ -332,7 +332,7 @@ public class EmulatorShmSkin extends EmulatorSkin { } try { - screenShotDialog = new ShmScreenShotWindow(shell, communicator, this, config, + screenShotDialog = new ShmScreenShotWindow(shell, this, config, imageRegistry.getIcon(IconName.SCREENSHOT)); screenShotDialog.open(); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java index 5c62469d67..67bcbf04c8 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java @@ -1,7 +1,7 @@ /** * Capture a screenshot of the Emulator framebuffer * - * 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 @@ -11,7 +11,7 @@ * 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. + * 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 @@ -67,7 +67,6 @@ import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.tizen.emulator.skin.EmulatorSkin; import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo; -import org.tizen.emulator.skin.comm.sock.SocketCommunicator; import org.tizen.emulator.skin.config.EmulatorConfig; import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants; import org.tizen.emulator.skin.exception.ScreenShotException; @@ -80,29 +79,22 @@ import org.tizen.emulator.skin.util.StringUtil; import org.tizen.emulator.skin.util.SwtUtil; public class ScreenShotDialog { - public final static String DEFAULT_FILE_EXTENSION = "png"; - - public static final int RED_MASK = 0x0000FF00; - public static final int GREEN_MASK = 0x00FF0000; - public static final int BLUE_MASK = 0xFF000000; - public static final int COLOR_DEPTH = 32; - public static final int CANVAS_MARGIN = 30; public static final int TOOLITEM_COOLTIME = 200; - private Logger logger = + private static Logger logger = SkinLogger.getSkinLogger(ScreenShotDialog.class).getLogger(); - protected PaletteData paletteData; - protected PaletteData paletteData2; + protected PaletteData paletteData_ARGB; + protected PaletteData paletteData_BGRA; + protected PaletteData paletteData_RGBA; protected Image image; protected Canvas imageCanvas; private Shell shell; private ScrolledComposite scrollComposite; private Label label; - protected SocketCommunicator communicator; protected EmulatorSkin emulatorSkin; protected EmulatorConfig config; @@ -113,31 +105,34 @@ public class ScreenShotDialog { private ToolItem increaseScaleItem; private ToolItem decreaseScaleItem; private double scaleLevel; + /** * @brief constructor * @param Image icon : screenshot window icon resource */ public ScreenShotDialog(Shell parent, - SocketCommunicator communicator, final EmulatorSkin emulatorSkin, - EmulatorConfig config, Image icon) throws ScreenShotException { - - this.communicator = communicator; + final EmulatorSkin emulatorSkin, EmulatorConfig config, + Image icon) throws ScreenShotException { this.emulatorSkin = emulatorSkin; this.config = config; this.scaleLevel = 100d; - shell = new Shell(Display.getDefault(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX); + shell = new Shell(Display.getDefault(), + SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX); shell.setText("Screen Shot - " + SkinUtil.makeEmulatorName(config)); - if(!SwtUtil.isMacPlatform()) { - if (icon != null) { - shell.setImage(icon); - } - } - shell.addListener( SWT.Close, new Listener() { + + /* To prevent the icon switching on Mac */ + if (!SwtUtil.isMacPlatform()) { + if (icon != null) { + shell.setImage(icon); + } + } + + shell.addListener(SWT.Close, new Listener() { @Override - public void handleEvent( Event event ) { - if ( null != image ) { - if ( !reserveImage ) { + public void handleEvent(Event event) { + if (null != image) { + if (!reserveImage) { image.dispose(); } } @@ -151,9 +146,9 @@ public class ScreenShotDialog { gridLayout.marginHeight = 0; gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; - shell.setLayout( gridLayout ); + shell.setLayout(gridLayout); - makeMenuBar( shell ); + makeMenuBar(shell); scrollComposite = new ScrolledComposite( shell, SWT.V_SCROLL | SWT.H_SCROLL ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); @@ -176,17 +171,23 @@ public class ScreenShotDialog { //e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN ); Rectangle r = image.getBounds(); //logger.info("r.width: " +r.width +", r.height " + r.height); + e.gc.drawImage(image, 0, 0, r.width, r.height, - CANVAS_MARGIN, CANVAS_MARGIN, (int)(r.width * scaleLevel * 1/100), (int)(r.height * scaleLevel * 1/100)); + CANVAS_MARGIN, CANVAS_MARGIN, + (int)(r.width * scaleLevel / 100), + (int)(r.height * scaleLevel / 100)); } - } } ); - paletteData = new PaletteData(RED_MASK, GREEN_MASK, BLUE_MASK); - paletteData2 = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); + paletteData_ARGB = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); + + /* for Endian */ + paletteData_BGRA = new PaletteData(0x0000FF00, 0x00FF0000, 0xFF000000); + /* for clipboard on Windows */ + paletteData_RGBA = new PaletteData(0xFF000000, 0x00FF0000, 0x0000FF00); - scrollComposite.setContent( imageCanvas ); + scrollComposite.setContent(imageCanvas); try { clickShutter(); @@ -196,13 +197,15 @@ public class ScreenShotDialog { } throw e; } - + shell.pack(); - - label = new Label(shell, SWT.NORMAL ); - label.setText(" Resolution : " + config.getArgInt(ArgsConstants.RESOLUTION_WIDTH) + - "x" + config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT) + " " + scaleLevel + "%"); - + + label = new Label(shell, SWT.NORMAL); + label.setText(" Resolution : " + + config.getArgInt(ArgsConstants.RESOLUTION_WIDTH) + "x" + + config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT) + " " + + scaleLevel + "%"); + // imageCanvas.addMouseMoveListener(new MouseMoveListener() { // public void mouseMove(MouseEvent e) { // Rectangle rectangle = imageCanvas.getBounds(); @@ -277,8 +280,9 @@ public class ScreenShotDialog { } protected void capture() throws ScreenShotException { + /* abstract */ } - + private double getScaleLevel() { return scaleLevel; } @@ -411,12 +415,13 @@ public class ScreenShotDialog { return rotationInfo; } - private void makeMenuBar( final Shell shell ) { - - ToolBar toolBar = new ToolBar( shell, SWT.HORIZONTAL ); - GridData gridData = new GridData( GridData.FILL_HORIZONTAL, GridData.CENTER, true, false ); - toolBar.setLayoutData( gridData ); + private void makeMenuBar(final Shell shell) { + ToolBar toolBar = new ToolBar(shell, SWT.HORIZONTAL); + GridData gridData = new GridData( + GridData.FILL_HORIZONTAL, GridData.CENTER, true, false); + toolBar.setLayoutData(gridData); + /* save */ ToolItem saveItem = new ToolItem( toolBar, SWT.FLAT ); saveItem.setImage( ImageRegistry.getInstance().getIcon( IconName.SAVE_SCREEN_SHOT ) ); saveItem.setToolTipText( "Save to file" ); @@ -455,6 +460,7 @@ public class ScreenShotDialog { } ); + /* copy to clipboard */ copyItem = new ToolItem( toolBar, SWT.FLAT ); copyItem.setImage( ImageRegistry.getInstance().getIcon( IconName.COPY_SCREEN_SHOT ) ); copyItem.setToolTipText( "Copy to clipboard" ); @@ -462,9 +468,9 @@ public class ScreenShotDialog { copyItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent e ) { - - if ( null == image || image.isDisposed() ) { - SkinUtil.openMessage( shell, null, "Fail to copy to clipboard.", SWT.ICON_ERROR, config ); + if (null == image || image.isDisposed()) { + SkinUtil.openMessage(shell, null, + "Fail to copy to clipboard.", SWT.ICON_ERROR, config); return; } @@ -481,15 +487,14 @@ public class ScreenShotDialog { }); ImageLoader loader = new ImageLoader(); - ImageData data = null; - if ( SwtUtil.isWindowsPlatform() ) { - // change RGB mask + if (SwtUtil.isWindowsPlatform()) { + /* change RGB mask */ ImageData imageData = image.getImageData(); - PaletteData paletteData = new PaletteData( BLUE_MASK, GREEN_MASK, RED_MASK ); - data = new ImageData( imageData.width, imageData.height, imageData.depth, paletteData, - imageData.bytesPerLine, imageData.data ); + data = new ImageData(imageData.width, imageData.height, + imageData.depth, paletteData_RGBA, + imageData.bytesPerLine, imageData.data); } else { data = image.getImageData(); } @@ -511,6 +516,7 @@ public class ScreenShotDialog { } ); + /* refresh */ refreshItem = new ToolItem( toolBar, SWT.FLAT ); refreshItem.setImage( ImageRegistry.getInstance().getIcon( IconName.REFRESH_SCREEN_SHOT ) ); refreshItem.setToolTipText( "Refresh image" ); @@ -554,6 +560,7 @@ public class ScreenShotDialog { } ); + /* zoom in */ increaseScaleItem = new ToolItem(toolBar, SWT.FLAT); increaseScaleItem.setImage(ImageRegistry.getInstance().getIcon(IconName.INCREASE_SCALE)); increaseScaleItem.setToolTipText("Increase view size"); @@ -562,7 +569,7 @@ public class ScreenShotDialog { @Override public void widgetSelected(SelectionEvent e) { double level = getScaleLevel(); - Point dialogSize = shell.getSize(); + Point dialogSize = shell.getSize(); upScaleLevel(); @@ -588,6 +595,7 @@ public class ScreenShotDialog { } ); + /* zoom out */ decreaseScaleItem = new ToolItem(toolBar, SWT.FLAT); decreaseScaleItem.setImage(ImageRegistry.getInstance().getIcon(IconName.DECREASE_SCALE)); decreaseScaleItem.setToolTipText("Decrease view size"); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java index 7cbc728530..f88a49b81f 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java @@ -1,7 +1,7 @@ /** * Capture a screenshot of the Emulator framebuffer * - * 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 @@ -10,7 +10,7 @@ * 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. + * 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 @@ -37,7 +37,6 @@ import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorSdlSkin; import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo; import org.tizen.emulator.skin.comm.ICommunicator.SendCommand; -import org.tizen.emulator.skin.comm.sock.SocketCommunicator; import org.tizen.emulator.skin.comm.sock.SocketCommunicator.DataTranfer; import org.tizen.emulator.skin.config.EmulatorConfig; import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants; @@ -45,7 +44,7 @@ import org.tizen.emulator.skin.exception.ScreenShotException; import org.tizen.emulator.skin.log.SkinLogger; public class SdlScreenShotWindow extends ScreenShotDialog { - private Logger logger = SkinLogger.getSkinLogger( + private static Logger logger = SkinLogger.getSkinLogger( SdlScreenShotWindow.class).getLogger(); /** @@ -53,21 +52,24 @@ public class SdlScreenShotWindow extends ScreenShotDialog { * @param Image icon : screenshot window icon resource */ public SdlScreenShotWindow(Shell parent, - SocketCommunicator communicator, EmulatorSdlSkin emulatorSkin, - EmulatorConfig config, Image icon) throws ScreenShotException { - super(parent, communicator, emulatorSkin, config, icon); + EmulatorSdlSkin emulatorSkin, EmulatorConfig config, + Image icon) throws ScreenShotException { + super(parent, emulatorSkin, config, icon); } protected void capture() throws ScreenShotException { - DataTranfer dataTranfer = communicator.sendDataToQEMU( + logger.info("screenshot capture"); + + DataTranfer dataTranfer = emulatorSkin.communicator.sendDataToQEMU( SendCommand.SCREEN_SHOT, null, true); - byte[] receivedData = communicator.getReceivedData(dataTranfer); + byte[] receivedData = + emulatorSkin.communicator.getReceivedData(dataTranfer); if (null != receivedData) { int width = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH); int height = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT); ImageData imageData = new ImageData( - width, height, COLOR_DEPTH, paletteData, 1, receivedData); + width, height, 32, paletteData_BGRA, 1, receivedData); RotationInfo rotation = getCurrentRotation(); imageData = rotateImageData(imageData, rotation); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java index 4558d2840b..7fa310e424 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java @@ -1,7 +1,7 @@ /** * Capture a screenshot of the Emulator framebuffer * - * 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 @@ -10,7 +10,7 @@ * 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. + * 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 @@ -28,41 +28,48 @@ package org.tizen.emulator.skin.screenshot; +import java.util.logging.Logger; + import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorShmSkin; import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo; -import org.tizen.emulator.skin.comm.sock.SocketCommunicator; import org.tizen.emulator.skin.config.EmulatorConfig; import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants; import org.tizen.emulator.skin.exception.ScreenShotException; +import org.tizen.emulator.skin.log.SkinLogger; public class ShmScreenShotWindow extends ScreenShotDialog { + private static Logger logger = SkinLogger.getSkinLogger( + ShmScreenShotWindow.class).getLogger(); /** * @brief constructor * @param Image icon : screenshot window icon resource */ public ShmScreenShotWindow(Shell parent, - SocketCommunicator communicator, EmulatorShmSkin emulatorSkin, - EmulatorConfig config, Image icon) throws ScreenShotException { - super(parent, communicator, emulatorSkin, config, icon); + EmulatorShmSkin emulatorSkin, EmulatorConfig config, + Image icon) throws ScreenShotException { + super(parent, emulatorSkin, config, icon); } protected void capture() throws ScreenShotException { + logger.info("screenshot capture"); + int width = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH); int height = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT); - int[] array = new int[width * height]; - int result = ((EmulatorShmSkin)emulatorSkin).getPixels(array); /* from shared memory */ + int[] arrayFramebuffer = new int[width * height]; + int result = + ((EmulatorShmSkin) emulatorSkin).getPixels(arrayFramebuffer); //logger.info("getPixels native function returned " + result); - ImageData imageData = new ImageData(width, height, COLOR_DEPTH, paletteData2); - for (int i = 0; i < height; i++) { - imageData.setPixels(0, i, width, array, i * width); - } + ImageData imageData = new ImageData(width, height, 24, paletteData_ARGB); + /* from shared memory */ + imageData.setPixels(0, 0, + width * height, arrayFramebuffer, 0); RotationInfo rotation = getCurrentRotation(); imageData = rotateImageData(imageData, rotation);