cp -pP sdbscript $(EMUL_DIR)/bin
endif
-# use shared memory to display LCD
+# use shared memory for display framebuffer
ifdef CONFIG_USE_SHM
ifdef CONFIG_LINUX
cp -pP skin/client/native_src/libshared.so $(EMUL_DIR)/bin
endif
endif
+# use GTK for CopyToClipboard on Ubuntu 12.04 64bit
+ifdef CONFIG_LINUX
+ cp -pP skin/client/native_src/libclipboard.so $(EMUL_DIR)/bin
+endif
+
# change loading path of dynamic shared libraries on MAC OS X
ifdef CONFIG_DARWIN
install_name_tool -change /opt/local/lib/libgthread-2.0.*.dylib @loader_path/libgthread-2.0.0.dylib $(EMUL_DIR)/bin/qemu-img
cp -pP sdbscript $(DIBS_COMMON_DIR)/bin
endif
-# use shared memory to display LCD
+# use shared memory for display framebuffer
ifdef CONFIG_USE_SHM
ifdef CONFIG_LINUX
cp -pP skin/client/native_src/libshared.so $(DIBS_COMMON_DIR)/bin
endif
endif
+# use GTK for CopyToClipboard on Ubuntu 12.04 64bit
+ifdef CONFIG_LINUX
+ cp -pP skin/client/native_src/libclipboard.so $(EMUL_DIR)/bin
+endif
+
# change loading path of dynamic shared libraries on MAC OS X
ifdef CONFIG_DARWIN
install_name_tool -change /opt/local/lib/libgthread-2.0.*.dylib @loader_path/libgthread-2.0.0.dylib $(DIBS_COMMON_DIR)/bin/qemu-img
<?xml version="1.0" standalone="yes"?>
<project name="emulator-skin" basedir="." default="make-jar">
-
<condition property="isWindows">
<os family="windows" />
</condition>
<arg line="-o" />
<arg line="libshared.so" />
</exec>
+
+ <exec dir="native_src" executable="./check-gtk.sh" outputproperty="gtkabi" failifexecutionfails="false" />
+ <echo message="gtkversion : ${gtkabi}" />
+
+ <javah classpath="build;lib/swt.jar" destdir="native_src">
+ <class name="org.tizen.emulator.skin.screenshot.ScreenShotDialog" />
+ </javah>
+ <exec executable="pkg-config" outputproperty="gtk" failifexecutionfails="false">
+ <arg line="--cflags" />
+ <arg line="--libs" />
+ <arg line="${gtkabi}" />
+ </exec>
+ <exec dir="native_src" executable="gcc" failifexecutionfails="false">
+ <arg line="-c" />
+ <arg line="-fPIC" />
+ <arg line="clipboard.c" />
+ <arg line="-o" />
+ <arg line="clipboard.o" />
+ <arg line="-I${env.JAVA_JNI_H_INCLUDE_PATH}" />
+ <arg line="-I${env.JAVA_JNI_H_INCLUDE_PATH}/linux" />
+ <arg line="${gtk}" />
+ </exec>
+ <exec dir="native_src" executable="gcc" failifexecutionfails="false">
+ <arg line="clipboard.o" />
+ <arg line="-shared" />
+ <arg line="-o" />
+ <arg line="libclipboard.so" />
+ </exec>
+
<delete>
<fileset dir="native_src" includes="**/*.h" />
</delete>
--- /dev/null
+#!/bin/bash
+
+GTK3="gtk+-3.0"
+GTK2="gtk+-2.0"
+
+pkg-config --exists $GTK3
+if [ "$?" = "0" ]
+then
+ echo $GTK3
+else
+ echo $GTK2
+fi
--- /dev/null
+/**
+ * Copy framebuffer to clipboard by JNI
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SangHo Park <sangho1206.park@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
+ *
+ */
+
+#include <jni.h>
+#include <stdio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include "org_tizen_emulator_skin_screenshot_ScreenShotDialog.h"
+
+JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_screenshot_ScreenShotDialog_copyToClipboard
+ (JNIEnv *env, jobject obj, jint width, jint height, jbyteArray pixels)
+{
+ int len = (*env)->GetArrayLength(env, pixels);
+ if (len <= 0) {
+ fprintf(stderr, "clipboard.c: failed to get length\n");
+ fflush(stderr);
+ return -1;
+ }
+
+ fprintf(stdout, "clipboard.c: copy to clipboard (%dx%d:%d)\n", width, height, len);
+ fflush(stdout);
+
+ GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+ if (clipboard == NULL) {
+ fprintf(stderr, "clipboard.c: failed to get clipboard\n");
+ fflush(stderr);
+ return -1;
+ }
+
+ char *data = (char *)g_malloc(len);
+ if (data == NULL) {
+ fprintf(stderr, "clipboard.c: failed to g_malloc\n");
+ fflush(stderr);
+ return -1;
+ }
+ (*env)->GetByteArrayRegion(env, pixels, 0, len, data);
+
+ GdkPixbuf *image = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, FALSE, 8,
+ width, height, width * 3, NULL, NULL);
+ if (image == NULL) {
+ fprintf(stderr, "clipboard.c: failed to get pixbuf\n");
+ fflush(stderr);
+
+ g_free(data);
+ return -1;
+ }
+
+ gtk_clipboard_set_image(clipboard, image);
+
+ g_object_unref(image);
+
+ return 0;
+}
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.ImageTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.tizen.emulator.skin.util.SwtUtil;
public class ScreenShotDialog {
+ public static final String JNI_LIBRARY_FILE = "clipboard";
private final static String DETAIL_SCREENSHOT_WINDOW_TITLE = "Screen Shot";
private final static String DEFAULT_FILE_EXTENSION = "png";
private static Logger logger =
SkinLogger.getSkinLogger(ScreenShotDialog.class).getLogger();
+ static {
+ /* load JNI library file */
+ try {
+ if (SwtUtil.isLinuxPlatform() == true &&
+ SwtUtil.is64bitPlatform() == true) {
+ System.loadLibrary(JNI_LIBRARY_FILE);
+ }
+ } catch (UnsatisfiedLinkError e) {
+ logger.severe("Failed to load a " + JNI_LIBRARY_FILE + " file.\n" + e);
+
+ Shell temp = new Shell(Display.getDefault());
+ MessageBox messageBox = new MessageBox(temp, SWT.ICON_ERROR);
+ messageBox.setText("Emulator");
+ messageBox.setMessage(
+ "Failed to load a JNI library file from "
+ + System.getProperty("java.library.path") + ".\n\n" + e);
+ messageBox.open();
+ temp.dispose();
+ }
+ }
+
+ /* define JNI function */
+ public native int copyToClipboard(int width, int height, byte buf[]);
+
protected EmulatorSkin skin;
protected EmulatorConfig config;
private Shell shell;
saveItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
+ logger.info("Save menu is selected");
+
FileDialog fileDialog = new FileDialog(parent, SWT.SAVE);
fileDialog.setText("Save Image");
copyItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
+ logger.info("CopyToClipboard menu is selected");
+
if (null == imageShot || imageShot.isDisposed()) {
SkinUtil.openMessage(parent, null,
"Fail to copy to clipboard.", SWT.ICON_ERROR, config);
ImageData pngData = new ImageData(
new ByteArrayInputStream(bao.toByteArray()));
- Object[] imageObject = new Object[] { pngData };
- Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };
- Clipboard clipboard = new Clipboard(parent.getDisplay());
- clipboard.setContents(imageObject, transfer);
+ if (SwtUtil.isLinuxPlatform() == true &&
+ SwtUtil.is64bitPlatform() == true) {
+ /* use JNI for Ubuntu 12.04 64bit */
+ int result = copyToClipboard(
+ pngData.width, pngData.height, pngData.data);
+ if (result < 0) {
+ DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD);
+ }
+ } else {
+ Object[] imageObject = new Object[] { pngData };
+
+ Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };
+ Clipboard clipboard = new Clipboard(parent.getDisplay());
+ clipboard.setContents(imageObject, transfer);
+
+ clipboard.dispose();
+ }
}
});
refreshItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
+ logger.info("Refresh menu is selected");
+
refreshItem.setEnabled(false);
parent.getDisplay().asyncExec(new Runnable() {
public static boolean isMacPlatform() {
return "cocoa".equalsIgnoreCase(SWT.getPlatform());
}
+
+ public static boolean is64bitPlatform() {
+ /* internal/Library.java::arch() */
+ String osArch = System.getProperty("os.arch"); /* $NON-NLS-1$ */
+
+ if (osArch.equals("amd64") || osArch.equals("x86_64") ||
+ osArch.equals("IA64W") || osArch.equals("ia64")) {
+ /* $NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ */
+ return true;
+ }
+
+ return false;
+ }
}