| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the plugins of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #define ENSURE_RUNNING_MEEGO {if (! QMeeGoGraphicsSystemHelper::isRunningMeeGo()) { qFatal("Using meego functionality but not running meego graphics system!"); }} | 
|---|
| 43 |  | 
|---|
| 44 | #include "qmeegographicssystemhelper.h" | 
|---|
| 45 | #include <private/qapplication_p.h> | 
|---|
| 46 | #include <private/qgraphicssystem_runtime_p.h> | 
|---|
| 47 | #include <private/qpixmap_raster_p.h> | 
|---|
| 48 | #include <private/qwindowsurface_gl_p.h> | 
|---|
| 49 | #include "qmeegoruntime.h" | 
|---|
| 50 | #include "qmeegoswitchevent.h" | 
|---|
| 51 |  | 
|---|
| 52 | QString QMeeGoGraphicsSystemHelper::runningGraphicsSystemName() | 
|---|
| 53 | { | 
|---|
| 54 | if (! QApplicationPrivate::instance()) { | 
|---|
| 55 | qWarning("Querying graphics system but application not running yet!"); | 
|---|
| 56 | return QString(); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | QString name = QApplicationPrivate::instance()->graphics_system_name; | 
|---|
| 60 | if (name == QLatin1String("runtime")) { | 
|---|
| 61 | QRuntimeGraphicsSystem *rsystem = (QRuntimeGraphicsSystem *) QApplicationPrivate::instance()->graphics_system; | 
|---|
| 62 | name = rsystem->graphicsSystemName(); | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | return name; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | bool QMeeGoGraphicsSystemHelper::isRunningMeeGo() | 
|---|
| 69 | { | 
|---|
| 70 | return (runningGraphicsSystemName() == QLatin1String("meego")); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | bool QMeeGoGraphicsSystemHelper::isRunningRuntime() | 
|---|
| 74 | { | 
|---|
| 75 | return (QApplicationPrivate::instance()->graphics_system_name == QLatin1String("runtime")); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | void QMeeGoGraphicsSystemHelper::switchToMeeGo() | 
|---|
| 79 | { | 
|---|
| 80 | if (isRunningMeeGo()) | 
|---|
| 81 | return; | 
|---|
| 82 |  | 
|---|
| 83 | if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime")) | 
|---|
| 84 | qWarning("Can't switch to meego - switching only supported with 'runtime' graphics system."); | 
|---|
| 85 | else { | 
|---|
| 86 | QMeeGoSwitchEvent willSwitchEvent(QLatin1String("meego"), QMeeGoSwitchEvent::WillSwitch); | 
|---|
| 87 | foreach (QWidget *widget, QApplication::topLevelWidgets()) | 
|---|
| 88 | QCoreApplication::sendEvent(widget, &willSwitchEvent); | 
|---|
| 89 |  | 
|---|
| 90 | QApplication *app = static_cast<QApplication *>(QCoreApplication::instance()); | 
|---|
| 91 | app->setGraphicsSystem(QLatin1String("meego")); | 
|---|
| 92 |  | 
|---|
| 93 | QMeeGoSwitchEvent didSwitchEvent(QLatin1String("meego"), QMeeGoSwitchEvent::DidSwitch); | 
|---|
| 94 | foreach (QWidget *widget, QApplication::topLevelWidgets()) | 
|---|
| 95 | QCoreApplication::sendEvent(widget, &didSwitchEvent); | 
|---|
| 96 | } | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | void QMeeGoGraphicsSystemHelper::switchToRaster() | 
|---|
| 100 | { | 
|---|
| 101 | if (runningGraphicsSystemName() == QLatin1String("raster")) | 
|---|
| 102 | return; | 
|---|
| 103 |  | 
|---|
| 104 | if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime")) | 
|---|
| 105 | qWarning("Can't switch to raster - switching only supported with 'runtime' graphics system."); | 
|---|
| 106 | else { | 
|---|
| 107 | QMeeGoSwitchEvent willSwitchEvent(QLatin1String("raster"), QMeeGoSwitchEvent::WillSwitch); | 
|---|
| 108 | foreach (QWidget *widget, QApplication::topLevelWidgets()) | 
|---|
| 109 | QCoreApplication::sendEvent(widget, &willSwitchEvent); | 
|---|
| 110 |  | 
|---|
| 111 | QApplication *app = static_cast<QApplication *>(QCoreApplication::instance()); | 
|---|
| 112 | app->setGraphicsSystem(QLatin1String("raster")); | 
|---|
| 113 |  | 
|---|
| 114 | QMeeGoSwitchEvent didSwitchEvent(QLatin1String("raster"), QMeeGoSwitchEvent::DidSwitch); | 
|---|
| 115 | foreach (QWidget *widget, QApplication::topLevelWidgets()) | 
|---|
| 116 | QCoreApplication::sendEvent(widget, &didSwitchEvent); | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | Qt::HANDLE QMeeGoGraphicsSystemHelper::imageToEGLSharedImage(const QImage &image) | 
|---|
| 121 | { | 
|---|
| 122 | ENSURE_RUNNING_MEEGO; | 
|---|
| 123 | return QMeeGoRuntime::imageToEGLSharedImage(image); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | QPixmap QMeeGoGraphicsSystemHelper::pixmapFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage) | 
|---|
| 127 | { | 
|---|
| 128 | // This function is supported when not running meego too. A raster-backed | 
|---|
| 129 | // pixmap will be created... but when you switch back to 'meego', it'll | 
|---|
| 130 | // be replaced with a EGL shared image backing. | 
|---|
| 131 | return QPixmap(QMeeGoRuntime::pixmapDataFromEGLSharedImage(handle, softImage)); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | QPixmap QMeeGoGraphicsSystemHelper::pixmapWithGLTexture(int w, int h) | 
|---|
| 135 | { | 
|---|
| 136 | ENSURE_RUNNING_MEEGO; | 
|---|
| 137 | return QPixmap(QMeeGoRuntime::pixmapDataWithGLTexture(w, h)); | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | bool QMeeGoGraphicsSystemHelper::destroyEGLSharedImage(Qt::HANDLE handle) | 
|---|
| 141 | { | 
|---|
| 142 | ENSURE_RUNNING_MEEGO; | 
|---|
| 143 | return QMeeGoRuntime::destroyEGLSharedImage(handle); | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | void QMeeGoGraphicsSystemHelper::updateEGLSharedImagePixmap(QPixmap *p) | 
|---|
| 147 | { | 
|---|
| 148 | ENSURE_RUNNING_MEEGO; | 
|---|
| 149 | return QMeeGoRuntime::updateEGLSharedImagePixmap(p); | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | void QMeeGoGraphicsSystemHelper::setTranslucent(bool translucent) | 
|---|
| 153 | { | 
|---|
| 154 | ENSURE_RUNNING_MEEGO; | 
|---|
| 155 | QMeeGoRuntime::setTranslucent(translucent); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | void QMeeGoGraphicsSystemHelper::setSwapBehavior(SwapMode mode) | 
|---|
| 159 | { | 
|---|
| 160 | ENSURE_RUNNING_MEEGO; | 
|---|
| 161 |  | 
|---|
| 162 | if (mode == AutomaticSwap) | 
|---|
| 163 | QGLWindowSurface::swapBehavior = QGLWindowSurface::AutomaticSwap; | 
|---|
| 164 | else if (mode == AlwaysFullSwap) | 
|---|
| 165 | QGLWindowSurface::swapBehavior = QGLWindowSurface::AlwaysFullSwap; | 
|---|
| 166 | else if (mode == AlwaysPartialSwap) | 
|---|
| 167 | QGLWindowSurface::swapBehavior = QGLWindowSurface::AlwaysPartialSwap; | 
|---|
| 168 | else if (mode == KillSwap) | 
|---|
| 169 | QGLWindowSurface::swapBehavior = QGLWindowSurface::KillSwap; | 
|---|
| 170 | } | 
|---|