From: giwoong.kim Date: Wed, 17 Oct 2012 14:04:51 +0000 (+0900) Subject: ScreenShot: make an inheritance of screen shot window X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1409^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd45e3de0731dd46d9c53ff4d35d4588fe02a2a3;p=sdk%2Femulator%2Fqemu.git ScreenShot: make an inheritance of screen shot window 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 --- 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 edefcd79db..413be9146e 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 @@ -28,10 +28,22 @@ 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; + } + } + } 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 1019bd83ab..021ad746bf 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 @@ -28,6 +28,10 @@ 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; + } + } } 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 5019f0372c..646dc12575 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 @@ -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(); } } ); 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 06a43ae453..8a2533a500 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 @@ -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 index 0000000000..24bfc4c0db --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/SdlScreenShotWindow.java @@ -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 + * YeongKyoon Lee + * + * 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 index 0000000000..4912098434 --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ShmScreenShotWindow.java @@ -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 + * YeongKyoon Lee + * + * 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