screenshot: optimize a framebuffer copying
authorgiwoong.kim <giwoong.kim@samsung.com>
Wed, 17 Apr 2013 04:30:47 +0000 (13:30 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Wed, 17 Apr 2013 07:45:07 +0000 (16:45 +0900)
optimize a framebuffer copying in screenshot window

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java

index 149137ca02da385726dc3f4f56cb539f7ebb4184..632b55b49d02ea6cd8111ec009607318ea97a454 100644 (file)
@@ -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();
 
index dc33f413240e2e176949df280333249883cebd02..3b15aa3d0977cf7caa9e5e416d5a40151b1d1c54 100644 (file)
@@ -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();
 
index 5c62469d670380d7ac7f03b9ded030a37d327d62..67bcbf04c89c32ae85698a3c9e77f984135a3ada 100644 (file)
@@ -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 <giwoong.kim@samsung.com>
@@ -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");
index 7cbc72853098ac490f13717c921d828757872d6a..f88a49b81f2f59a1d728d6a0180efcf5c32d8341 100644 (file)
@@ -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 <giwoong.kim@samsung.com>
@@ -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);
index 4558d2840bdf269b807a69e731429a8808549874..7fa310e424987aeb9e15d347611917accdc31e07 100644 (file)
@@ -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 <giwoong.kim@samsung.com>
@@ -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
 
 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);