screenshot: merge codes from tizen-mac
authormunkyu.im <munkyu.im@samsung.com>
Fri, 28 Sep 2012 07:51:45 +0000 (16:51 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Fri, 28 Sep 2012 07:51:45 +0000 (16:51 +0900)
screenshot was not working because of some codes were missing.

Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
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/util/SkinUtil.java

index f93b929edd912ca966e5a05acccc37470834efb0..593691543110858d10da577d03b7f0c0284be29a 100644 (file)
@@ -61,6 +61,7 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Canvas;
@@ -125,11 +126,17 @@ public class EmulatorSkin {
                }
 
        }
+       public native int getPixels(int[] array); 
 
        public static final String GTK_OS_CLASS = "org.eclipse.swt.internal.gtk.OS";
        public static final String WIN32_OS_CLASS = "org.eclipse.swt.internal.win32.OS";
        public static final String COCOA_OS_CLASS = "org.eclipse.swt.internal.cocoa.OS";
        
+       public final static int RED_MASK = 0x00FF0000;
+       public final static int GREEN_MASK = 0x0000FF00;
+       public final static int BLUE_MASK = 0x000000FF;
+       public final static int COLOR_DEPTH = 32;
+
        private Logger logger = SkinLogger.getSkinLogger( EmulatorSkin.class ).getLogger();
 
        protected EmulatorConfig config;
@@ -166,6 +173,7 @@ public class EmulatorSkin {
        private SocketCommunicator communicator;
        private long windowHandleId;
 
+       private PaletteData paletteData;
        private Listener shellCloseListener;
        private PaintListener shellPaintListener;
        private MouseTrackListener shellMouseTrackListener;
@@ -191,6 +199,7 @@ public class EmulatorSkin {
                this.config = config;
                this.isDefaultHoverColor = true;
                this.isOnTop = isOnTop;
+               this.paletteData = new PaletteData(RED_MASK, GREEN_MASK, BLUE_MASK);
                
                int style = SWT.NO_TRIM;
                this.shell = new Shell( Display.getDefault(), style );
@@ -200,6 +209,9 @@ public class EmulatorSkin {
        public void setCommunicator( SocketCommunicator communicator ) {
                this.communicator = communicator;
        }
+       public PaletteData getPalette() {
+               return paletteData;
+       }
 
        public long compose() {
 
@@ -1797,13 +1809,12 @@ public class EmulatorSkin {
 
                                ProcessBuilder procSdb = new ProcessBuilder();
 
-                               if (SwtUtil.isLinuxPlatform()) {
-                                       procSdb.command("/usr/bin/gnome-terminal", "--disable-factory",
-                                                       "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath,
-                                                       "-s", "emulator-"       + portSdb, "shell");
-                               } else if (SwtUtil.isWindowsPlatform()) {
-                                       procSdb.command("cmd.exe", "/c", "start", sdbPath, "sdb",
-                                                       "-s", "emulator-" + portSdb, "shell");
+                               if ( SwtUtil.isLinuxPlatform() ) {
+                                       procSdb.command( "/usr/bin/gnome-terminal", "--disable-factory",
+                                                       "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath, "-s", "emulator-"
+                                                                       + portSdb, "shell" );
+                               } else if ( SwtUtil.isWindowsPlatform() ) {
+                                       procSdb.command( "cmd.exe", "/c", "start", sdbPath, "-s", "emulator-" + portSdb, "shell" );
                                }
                                logger.log( Level.INFO, procSdb.command().toString() );
 
index 06a43ae4539d0a327dec87868f4075be9eb0a6f5..98f0543f06bcaf8fdff6c0beb81fd2bce3dc3123 100644 (file)
@@ -51,7 +51,6 @@ import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.graphics.PaletteData;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.GridData;
@@ -67,9 +66,7 @@ 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.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;
@@ -78,24 +75,17 @@ import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.IOUtil;
 import org.tizen.emulator.skin.util.SkinUtil;
-import org.tizen.emulator.skin.util.StringUtil;
 import org.tizen.emulator.skin.util.SwtUtil;
+import org.tizen.emulator.skin.util.StringUtil;
 
 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;
+       public final static int CANVAS_MARGIN = 30;
+       public final static int TOOLITEM_COOLTIME = 200;
 
        private Logger logger = SkinLogger.getSkinLogger( ScreenShotDialog.class ).getLogger();
 
-       private PaletteData paletteData;
        private Image image;
        private Canvas imageCanvas;
        private Shell shell;
@@ -170,7 +160,7 @@ public class ScreenShotDialog {
                                if ( null != image && !image.isDisposed() ) {
                                        //e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
                                        Rectangle r = image.getBounds();
-                                       //logger.info("r.width: " +r.width +", r.height " + r.height);
+                                       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));
                                }
@@ -178,8 +168,6 @@ public class ScreenShotDialog {
                        }
                } );
 
-               paletteData = new PaletteData( RED_MASK, GREEN_MASK, BLUE_MASK );
-
                scrollComposite.setContent( imageCanvas );
 
                try {
@@ -272,7 +260,7 @@ public class ScreenShotDialog {
 
        private void capture() throws ScreenShotException {
 
-               DataTranfer dataTranfer = communicator.sendToQEMU( SendCommand.SCREEN_SHOT, null, true );
+               /* DataTranfer dataTranfer = communicator.sendToQEMU( SendCommand.SCREEN_SHOT, null, true );
                byte[] receivedData = communicator.getReceivedData( dataTranfer );
 
                if ( null != receivedData ) {
@@ -294,10 +282,30 @@ public class ScreenShotDialog {
                        
                } else {
                        throw new ScreenShotException( "Fail to get image data." );
+               }*/
+
+               int width = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH);
+               int height = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
+
+               int[] array = new int[width * height];
+               int result = emulatorSkin.getPixels(array); //from shared memory
+               //logger.info("getPixels navtive function returned " + result);
+
+               ImageData imageData = new ImageData(width, height, EmulatorSkin.COLOR_DEPTH, emulatorSkin.getPalette());
+               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();
        }
-       
+
        private double getScaleLevel() {
                return scaleLevel;
        }
@@ -502,8 +510,7 @@ public class ScreenShotDialog {
                                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,
+                                       data = new ImageData( imageData.width, imageData.height, imageData.depth, emulatorSkin.getPalette(),
                                                        imageData.bytesPerLine, imageData.data );
                                } else {
                                        data = image.getImageData();
@@ -738,4 +745,4 @@ public class ScreenShotDialog {
                return shell;
        }
 
-}
\ No newline at end of file
+}
index 859b0b12663364bcab77485bcaaa9294bc5064be..00c5feb548f3ce1a50c335ff59550dc2b4a2e9a8 100644 (file)
@@ -72,7 +72,7 @@ public class SkinUtil {
                String vmPath = config.getArg( ArgsConstants.VM_PATH );
 
                String regex = "";
-               if ( SwtUtil.isWindowsPlatform() ) {
+               if (SwtUtil.isWindowsPlatform()) {
                        regex = "\\" + File.separator;
                } else {
                        regex = File.separator;