ScreenShot: make an inheritance of screen shot window
authorgiwoong.kim <giwoong.kim@samsung.com>
Wed, 17 Oct 2012 14:04:51 +0000 (23:04 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Wed, 17 Oct 2012 14:04:51 +0000 (23:04 +0900)
The screen shot's framebuffer is received from qemu on Linux/Windows.
But on Mac, it is received from shared memory.

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/EmulatorSkin.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 [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java [new file with mode: 0644]

index edefcd79db01517b3452a5bbe82660df763971a1..413be9146ec988d57c43968e86cffbae7a689afd 100644 (file)
 
 package org.tizen.emulator.skin;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
 import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.exception.ScreenShotException;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.mode.SkinMode;
+import org.tizen.emulator.skin.screenshot.SdlScreenShotWindow;
+import org.tizen.emulator.skin.util.SkinUtil;
 
 public class EmulatorSdlSkin extends EmulatorSkin {
+       private Logger logger = SkinLogger.getSkinLogger(
+                       EmulatorSdlSkin.class).getLogger();
+
        /**
         *  Constructor
         */
@@ -39,4 +51,30 @@ public class EmulatorSdlSkin extends EmulatorSkin {
                super(config, mode, isOnTop);
        }
 
+       protected void openScreenShotWindow() {
+               if (screenShotDialog != null) {
+                       return;
+               }
+
+               try {
+                       screenShotDialog = new SdlScreenShotWindow(shell, communicator, this, config,
+                                       imageRegistry.getIcon(IconName.SCREENSHOT));
+                       screenShotDialog.open();
+
+               } catch (ScreenShotException ex) {
+                       logger.log(Level.SEVERE, ex.getMessage(), ex);
+                       SkinUtil.openMessage(shell, null,
+                                       "Fail to create a screen shot.", SWT.ICON_ERROR, config);
+
+               } catch (Exception ex) {
+                       // defense exception handling.
+                       logger.log(Level.SEVERE, ex.getMessage(), ex);
+                       String errorMessage = "Internal Error.\n[" + ex.getMessage() + "]";
+                       SkinUtil.openMessage(shell, null, errorMessage, SWT.ICON_ERROR, config);
+
+               } finally {
+                       screenShotDialog = null;
+               }
+       }
+
 }
index 1019bd83ab93bed6f2fff3da6be899d966e2faf2..021ad746bf13d3ed0ae1b53ee94dd513049f9baa 100644 (file)
 
 package org.tizen.emulator.skin;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
 import org.eclipse.swt.graphics.Image;
@@ -36,9 +40,17 @@ import org.eclipse.swt.graphics.PaletteData;
 import org.eclipse.swt.graphics.Transform;
 import org.eclipse.swt.widgets.Display;
 import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.exception.ScreenShotException;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.mode.SkinMode;
+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;
@@ -179,4 +191,30 @@ public class EmulatorShmSkin extends EmulatorSkin {
 
                return ret;
        }
+
+       protected void openScreenShotWindow() {
+               if (screenShotDialog != null) {
+                       return;
+               }
+
+               try {
+                       screenShotDialog = new ShmScreenShotWindow(shell, communicator, this, config,
+                                       imageRegistry.getIcon(IconName.SCREENSHOT));
+                       screenShotDialog.open();
+
+               } catch (ScreenShotException ex) {
+                       logger.log(Level.SEVERE, ex.getMessage(), ex);
+                       SkinUtil.openMessage(shell, null,
+                                       "Fail to create a screen shot.", SWT.ICON_ERROR, config);
+
+               } catch (Exception ex) {
+                       // defense exception handling.
+                       logger.log(Level.SEVERE, ex.getMessage(), ex);
+                       String errorMessage = "Internal Error.\n[" + ex.getMessage() + "]";
+                       SkinUtil.openMessage(shell, null, errorMessage, SWT.ICON_ERROR, config);
+
+               } finally {
+                       screenShotDialog = null;
+               }
+       }
 }
index 5019f0372cfe8d9af9bd50b8b889dc97cb6a539f..646dc1257558553c400c40e9ed337c8f284fe16a 100644 (file)
@@ -137,8 +137,8 @@ public class EmulatorSkin {
        private Logger logger = SkinLogger.getSkinLogger( EmulatorSkin.class ).getLogger();
 
        protected EmulatorConfig config;
-       private Shell shell;
-       private ImageRegistry imageRegistry;
+       protected Shell shell;
+       protected ImageRegistry imageRegistry;
        protected Canvas lcdCanvas;
        private SkinMode skinMode;
        private Image currentImage;
@@ -162,13 +162,12 @@ public class EmulatorSkin {
        private boolean isShutdownRequested;
        private boolean isAboutToReopen;
        private boolean isOnTop;
-       private boolean isScreenShotOpened;
        private boolean isOnUsbKbd;
 
-       private ScreenShotDialog screenShotDialog;
+       protected ScreenShotDialog screenShotDialog;
        private Menu contextMenu;
 
-       private SocketCommunicator communicator;
+       protected SocketCommunicator communicator;
        private long windowHandleId;
 
        private Listener shellCloseListener;
@@ -410,14 +409,14 @@ public class EmulatorSkin {
                this.shell.open();
 
                // logic only for reopen case ///////
-               if ( isScreenShotOpened && ( null != screenShotDialog ) ) {
-                       try {
-                               screenShotDialog.setReserveImage( false );
-                               screenShotDialog.open();
-                       } finally {
-                               isScreenShotOpened = false;
-                       }
-               }
+//             if ( isScreenShotOpened && ( null != screenShotDialog ) ) {
+//                     try {
+//                             screenShotDialog.setReserveImage( false );
+//                             screenShotDialog.open();
+//                     } finally {
+//                             isScreenShotOpened = false;
+//                     }
+//             }
                // ///////////////////////////////////
 
                while ( !shell.isDisposed() ) {
@@ -492,11 +491,12 @@ public class EmulatorSkin {
 
                                        if ( !isAboutToReopen ) {
 
-                                               if ( isScreenShotOpened && ( null != screenShotDialog ) ) {
+                                               if (null != screenShotDialog) {
                                                        Shell scShell = screenShotDialog.getShell();
                                                        if ( !scShell.isDisposed() ) {
                                                                scShell.close();
                                                        }
+                                                       screenShotDialog = null;
                                                }
 
                                                // save config only for emulator close
@@ -1779,6 +1779,10 @@ public class EmulatorSkin {
                return true;
        }
 
+       protected void openScreenShotWindow() {
+               //TODO:
+       }
+
        private void addMenuItems( final Shell shell, final Menu menu ) {
 
                /* Emulator detail info menu */
@@ -2115,35 +2119,7 @@ public class EmulatorSkin {
 
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
-
-                               if ( isScreenShotOpened ) {
-                                       return;
-                               }
-
-                               try {
-
-                                       isScreenShotOpened = true;
-
-                                       screenShotDialog = new ScreenShotDialog( shell, communicator, EmulatorSkin.this, config,
-                                                       imageRegistry.getIcon(IconName.SCREENSHOT) );
-                                       screenShotDialog.open();
-
-                               } catch ( ScreenShotException ex ) {
-
-                                       logger.log( Level.SEVERE, ex.getMessage(), ex );
-                                       SkinUtil.openMessage( shell, null, "Fail to create a screen shot.", SWT.ICON_ERROR, config );
-
-                               } catch ( Exception ex ) {
-
-                                       // defense exception handling.
-                                       logger.log( Level.SEVERE, ex.getMessage(), ex );
-                                       String errorMessage = "Internal Error.\n[" + ex.getMessage() + "]";
-                                       SkinUtil.openMessage( shell, null, errorMessage, SWT.ICON_ERROR, config );
-
-                               } finally {
-                                       isScreenShotOpened = false;
-                               }
-
+                               openScreenShotWindow();
                        }
                } );
 
index 06a43ae4539d0a327dec87868f4075be9eb0a6f5..8a2533a5003327e5d2059b6e6b92435398bc41a4 100644 (file)
@@ -95,16 +95,16 @@ public class ScreenShotDialog {
 
        private Logger logger = SkinLogger.getSkinLogger( ScreenShotDialog.class ).getLogger();
 
-       private PaletteData paletteData;
-       private Image image;
-       private Canvas imageCanvas;
+       protected PaletteData paletteData;
+       protected Image image;
+       protected Canvas imageCanvas;
        private Shell shell;
        private ScrolledComposite scrollComposite;
        private Label label;
 
-       private SocketCommunicator communicator;
+       protected SocketCommunicator communicator;
        private EmulatorSkin emulatorSkin;
-       private EmulatorConfig config;
+       protected EmulatorConfig config;
 
        private RotationInfo currentRotation;
        private boolean reserveImage;
@@ -270,32 +270,7 @@ public class ScreenShotDialog {
                arrageImageLayout();
        }
 
-       private void capture() throws ScreenShotException {
-
-               DataTranfer dataTranfer = communicator.sendToQEMU( SendCommand.SCREEN_SHOT, null, true );
-               byte[] receivedData = communicator.getReceivedData( dataTranfer );
-
-               if ( null != receivedData ) {
-
-                       if ( null != this.image ) {
-                               this.image.dispose();
-                       }
-
-                       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 );
-                       
-                       RotationInfo rotation = getCurrentRotation();
-                       imageData = rotateImageData( imageData, rotation );
-
-                this.image = new Image( Display.getDefault(), imageData );
-                
-                imageCanvas.redraw();
-                       
-               } else {
-                       throw new ScreenShotException( "Fail to get image data." );
-               }
-
+       protected void capture() throws ScreenShotException {
        }
        
        private double getScaleLevel() {
@@ -352,7 +327,7 @@ public class ScreenShotDialog {
        }
        
 
-       private ImageData rotateImageData( ImageData srcData, RotationInfo rotation ) {
+       protected ImageData rotateImageData( ImageData srcData, RotationInfo rotation ) {
 
                int direction = SWT.NONE;
 
@@ -420,7 +395,7 @@ public class ScreenShotDialog {
 
        }
 
-       private RotationInfo getCurrentRotation() {
+       protected RotationInfo getCurrentRotation() {
                short currentRotationId = emulatorSkin.getCurrentRotationId();
                RotationInfo rotationInfo = RotationInfo.getValue( currentRotationId );
                return rotationInfo;
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
new file mode 100644 (file)
index 0000000..24bfc4c
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * Capture a screenshot of the Emulator framebuffer
+ *
+ * Copyright ( C ) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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.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.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;
+import org.tizen.emulator.skin.exception.ScreenShotException;
+import org.tizen.emulator.skin.log.SkinLogger;
+
+public class SdlScreenShotWindow extends ScreenShotDialog {
+       private Logger logger = SkinLogger.getSkinLogger(
+                       SdlScreenShotWindow.class).getLogger();
+
+       /**
+        * @brief constructor
+        * @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);
+       }
+       
+       protected void capture() throws ScreenShotException {
+               DataTranfer dataTranfer = communicator.sendToQEMU( SendCommand.SCREEN_SHOT, null, true );
+               byte[] receivedData = communicator.getReceivedData( dataTranfer );
+
+               if ( null != receivedData ) {
+
+                       if ( null != this.image ) {
+                               this.image.dispose();
+                       }
+
+                       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 );
+                       
+                       RotationInfo rotation = getCurrentRotation();
+                       imageData = rotateImageData( imageData, rotation );
+
+                this.image = new Image( Display.getDefault(), imageData );
+                
+                imageCanvas.redraw();
+                       
+               } else {
+                       throw new ScreenShotException( "Fail to get image data." );
+               }
+       }
+}
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..4912098
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * Capture a screenshot of the Emulator framebuffer
+ *
+ * Copyright ( C ) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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.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 Logger logger = SkinLogger.getSkinLogger(
+                       ShmScreenShotWindow.class).getLogger();
+       
+       private EmulatorShmSkin emulatorSkin;
+
+       /**
+        * @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);
+               
+               this.emulatorSkin = emulatorSkin;
+       }
+       
+       protected void capture() throws ScreenShotException {
+               int width = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH);
+               int height = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
+
+               int[] array = new int[width * height];
+               //TODO:
+               //int result = emulatorSkin.getPixels(array); //from shared memory
+               //logger.info("getPixels navtive function returned " + result);
+
+               ImageData imageData = new ImageData(width, height, COLOR_DEPTH, paletteData);
+               for (int i = 0; i < height; i++) {
+                       imageData.setPixels(0, i, width, array, i * width);
+                }
+
+               RotationInfo rotation = getCurrentRotation();
+               imageData = rotateImageData(imageData, rotation);
+
+               if (image != null) {
+                       image.dispose();
+               }
+               image = new Image(Display.getDefault(), imageData);
+               imageCanvas.redraw();
+       }
+}
\ No newline at end of file