ui: introduce new Qt5 UI console prototype 25/24625/7
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 16 Jul 2014 12:50:01 +0000 (21:50 +0900)
committerJinhyung Jo <jinhyung.jo@samsung.com>
Fri, 18 Jul 2014 04:23:46 +0000 (21:23 -0700)
It has limited capability for now.

Change-Id: I4f8c4e95ecbe0723594868fac985d4f1875fa957
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
.gitignore
include/sysemu/sysemu.h
include/ui/console.h
ui/Makefile.objs
ui/qt5.c [new file with mode: 0644]
ui/qt5_supplement.cpp [new file with mode: 0644]
ui/qt5_supplement.h [new file with mode: 0644]
vl.c

index a39c2e0c8a4353e8f2ca6b9206ae70d26cef8f32..262fa1a3821718c616aa0cbcb3a9d97d888a2da8 100644 (file)
@@ -129,6 +129,6 @@ tizen/src/skin/client/native_src/*.dynlib
 fsdev/virtfs-proxy-helper
 .cproject
 .project
-tizen/src/util/check-hax
-tizen/src/util/check-cam
-
+check-hax
+check-cam
+moc_*.cpp
index 0a44fcef0ed21474c7b1a1d4dc9f2d3c957a8a2c..767dcbe45c9eca2d031c00cd988b4b741f544e6d 100644 (file)
@@ -99,6 +99,7 @@ typedef enum DisplayType
     DT_NOGRAPHIC,
 #ifdef CONFIG_MARU
     DT_MARU,
+    DT_QT,
 #endif
     DT_NONE,
 } DisplayType;
index a95944f4af4810e5d37862733d73e42dde6ae330..080eac69a7c4c955daa42b74cae2c396767a5807 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef CONSOLE_H
 #define CONSOLE_H
 
+#ifndef __cplusplus
 #include "ui/qemu-pixman.h"
+#endif
 #include "qom/object.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/notify.h"
@@ -362,4 +364,7 @@ int index_from_key(const char *key);
 void early_gtk_display_init(void);
 void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover);
 
+/* qt5.c */
+void qt5_display_init(DisplayState *ds, int full_screen);
+
 #endif
index 6f2294efdaafca8fc32f840ae5778f5b4747518a..55bd9410415b2bd322805de1000eb5424470d802 100644 (file)
@@ -15,6 +15,16 @@ common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
 
+# by caramis
+common-obj-$(CONFIG_QT) += qt5.o
+common-obj-$(CONFIG_QT) += qt5_supplement.o moc_qt5_supplement.o
+
 $(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS)
 
 $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS)
+
+$(obj)/qt5_supplement.o: QEMU_CFLAGS += $(QT_CFLAGS)
+$(obj)/moc_qt5_supplement.o: $(obj)/moc_qt5_supplement.cpp
+$(obj)/moc_qt5_supplement.cpp: $(obj)/qt5_supplement.h
+       moc $< -o $@
+$(obj)/moc_qt5_supplement.o: QEMU_CFLAGS += $(QT_CFLAGS)
diff --git a/ui/qt5.c b/ui/qt5.c
new file mode 100644 (file)
index 0000000..2a01abb
--- /dev/null
+++ b/ui/qt5.c
@@ -0,0 +1,120 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@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 "ui/console.h"
+#include "qt5_supplement.h"
+
+//static Notifier mouse_mode_notifier;
+static int qt5_num_outputs;
+
+static struct qt5_state {
+    DisplayChangeListener dcl;
+    DisplaySurface *surface;
+
+    int idx;
+} *qt5_console;
+
+static void qt5_update(DisplayChangeListener *dcl,
+                       int x, int y, int w, int h)
+{
+    DisplaySurface *surf = qemu_console_surface(dcl->con);
+
+    if (!surf) {
+        return;
+    }
+
+    qt5_update_internal(surface_data(surf), surface_width(surf), surface_height(surf));
+}
+
+static void qt5_switch(DisplayChangeListener *dcl,
+                       DisplaySurface *new_surface)
+{
+//    fprintf(stdout, "##### qt5_switch\n");
+}
+
+static void qt5_refresh(DisplayChangeListener *dcl)
+{
+    graphic_hw_update(dcl->con);
+    qt5_refresh_internal();
+}
+
+static void qt5_mouse_warp(DisplayChangeListener *dcl,
+                           int x, int y, int on)
+{
+}
+
+static void qt5_mouse_define(DisplayChangeListener *dcl,
+                             QEMUCursor *c)
+{
+}
+
+static const DisplayChangeListenerOps dcl_ops = {
+    .dpy_name          = "qt5",
+    .dpy_gfx_update    = qt5_update,
+    .dpy_gfx_switch    = qt5_switch,
+    .dpy_refresh       = qt5_refresh,
+    .dpy_mouse_set     = qt5_mouse_warp,
+    .dpy_cursor_define = qt5_mouse_define,
+};
+
+void qt5_display_init(DisplayState *ds, int full_screen)
+{
+    int i;
+
+    // prepare gui
+    qt5_prepare();
+
+    for (i = 0;; i++) {
+        QemuConsole *con = qemu_console_lookup_by_index(i);
+        if (!con || !qemu_console_is_graphic(con)) {
+            break;
+        }
+    }
+    qt5_num_outputs = i;
+    qt5_console = g_new0(struct qt5_state, qt5_num_outputs);
+    for (i = 0; i < qt5_num_outputs; i++) {
+        QemuConsole *con = qemu_console_lookup_by_index(i);
+        qt5_console[i].dcl.ops = &dcl_ops;
+        qt5_console[i].dcl.con = con;
+        register_displaychangelistener(&qt5_console[i].dcl);
+        qt5_console[i].idx = i;
+    }
+
+    // TODO: show icon
+
+    if (full_screen) {
+        // TODO
+    }
+
+    /* TODO
+    mouse_mode_notifier.notify = qt2_mouse_mode_change;
+    qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier);
+    */
+
+    // TODO: cursor control
+}
diff --git a/ui/qt5_supplement.cpp b/ui/qt5_supplement.cpp
new file mode 100644 (file)
index 0000000..e72ea75
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@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 <QApplication>
+#include "qt5_supplement.h"
+
+//using namespace std;
+
+static QApplication *app;
+
+QT5Console::QT5Console()
+{
+    label = new QLabel();
+    label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    label->setAlignment(Qt::AlignCenter);
+    label->setFixedSize(720 / 2, 1280 / 2);
+
+    layout = new QVBoxLayout();
+    layout->addWidget(label);
+    layout->setContentsMargins( 0, 0, 0, 0);
+    setLayout(layout);
+
+    setWindowTitle(tr("Emulator with Qt5"));
+}
+
+QLabel *QT5Console::getLabel()
+{
+    return label;
+}
+
+static int argc = 0;
+static char *argv[0];
+static QT5Console *console;
+
+void qt5_prepare(void)
+{
+    app = new QApplication(argc, argv);
+    console = new QT5Console();
+    console->show();
+}
+
+int qt5_get_win_id(void)
+{
+    return console->winId();
+}
+
+void qt5_update_internal(void *data, int width, int height)
+{
+    QPixmap pixmap = QPixmap();
+    QLabel *label = console->getLabel();
+
+    QImage image = QImage((uchar *)data, width, height, QImage::Format_ARGB32);
+    pixmap.convertFromImage(image);
+
+    label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio,
+                Qt::SmoothTransformation));
+}
+
+void qt5_switch_internal(void)
+{
+}
+
+void qt5_refresh_internal(void)
+{
+    app->processEvents();
+}
+
+void qt5_mouse_warp(void)
+{
+}
+
+void sdl_mouse_define(void)
+{
+}
diff --git a/ui/qt5_supplement.h b/ui/qt5_supplement.h
new file mode 100644 (file)
index 0000000..cd6e152
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@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
+ *
+ */
+
+#ifndef __QT5_INTERNAL_H__
+#define __QT5_INTERNAL_H__
+
+#ifdef __cplusplus
+#include <QtWidgets>
+
+class QT5Console : public QWidget
+{
+    Q_OBJECT
+
+public:
+    QT5Console();
+    QLabel *getLabel();
+
+protected:
+
+private:
+    QLabel *label;
+    QLayout *layout;
+};
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void qt5_prepare(void);
+int qt5_get_win_id(void);
+
+void qt5_update_internal(void *data, int width, int height);
+void qt5_switch_internal(void);
+void qt5_refresh_internal(void);
+void qt5_mouse_warp_internal(void);
+void sdl_mouse_define_internal(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __QT5_INTERNAL_H__
diff --git a/vl.c b/vl.c
index 3da782a66a97871836db45be71f685be7cc7ee1e..5ffb66ab7f758f6b7b923d0b9bf0ef4e40aaf102 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2352,6 +2352,8 @@ static DisplayType select_display(const char *p)
         fprintf(stderr, "GTK support is disabled\n");
         exit(1);
 #endif
+    } else if (strstart(p, "qt", &opts)) {
+        display = DT_QT;
     } else if (strstart(p, "none", &opts)) {
         display = DT_NONE;
     } else {
@@ -2985,8 +2987,6 @@ out:
 }
 
 #ifdef CONFIG_MARU
-int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
-
 // W/A for preserve larger continuous heap for RAM.
 extern void *preallocated_ram_ptr;
 extern int preallocated_ram_size;
@@ -4242,7 +4242,11 @@ int main(int argc, char **argv, char **envp)
 
     if (display_type == DT_DEFAULT && !display_remote) {
 #if defined(CONFIG_MARU)
+#if defined(CONFIG_SDL)
         display_type = DT_MARU;
+#elif defined(CONFIG_QT)
+        display_type = DT_QT;
+#endif
 #elif defined(CONFIG_GTK)
         display_type = DT_GTK;
 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
@@ -4593,6 +4597,11 @@ int main(int argc, char **argv, char **envp)
         start_skin();
         break;
 #endif
+#if defined(CONFIG_QT)
+    case DT_QT:
+        qt5_display_init(ds, full_screen);
+        break;
+#endif
 #endif
 #if defined(CONFIG_SDL)
     case DT_SDL: