| 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 | #ifndef QMEEGOGRAPHICSSYSTEMHELPER_H | 
|---|
| 43 | #define QMEEGOGRAPHICSSYSTEMHELPER_H | 
|---|
| 44 |  | 
|---|
| 45 | #include <QPixmap> | 
|---|
| 46 | #include <QImage> | 
|---|
| 47 | #include "qmeegolivepixmap.h" | 
|---|
| 48 |  | 
|---|
| 49 | class QLibrary; | 
|---|
| 50 |  | 
|---|
| 51 | //! The base class for accressing special meego graphics system features. | 
|---|
| 52 | /*! | 
|---|
| 53 | This class is a helper class with static-only methods for accessing various | 
|---|
| 54 | meego graphics system functionalities. The way it works is that the helper | 
|---|
| 55 | dynamically calls-in to the loaded graphicssystem plugin... therefore, you're | 
|---|
| 56 | expected to make sure that you're indeed running with 'meego' before using any | 
|---|
| 57 | of the specialized methods. | 
|---|
| 58 |  | 
|---|
| 59 | In example: | 
|---|
| 60 |  | 
|---|
| 61 | \code | 
|---|
| 62 | QPixmap p; | 
|---|
| 63 | if (QMeeGoGraphicsSystemHelper::isRunningMeeGo()) { | 
|---|
| 64 | p = QMeeGoGraphicsSystemHelper::pixmapWithGLTexture(64, 64); | 
|---|
| 65 | } else { | 
|---|
| 66 | p = QPixmap(64, 64); | 
|---|
| 67 | } | 
|---|
| 68 | \endcode | 
|---|
| 69 |  | 
|---|
| 70 | Calling any of the meego-specific features while not running meego might | 
|---|
| 71 | give unpredictable results. The only functions safe to call at all times are: | 
|---|
| 72 |  | 
|---|
| 73 | \code | 
|---|
| 74 | QMeeGoGraphicsSystemHelper::isRunningMeeGo(); | 
|---|
| 75 | QMeeGoGraphicsSystemHelper::runningGraphicsSystemName(); | 
|---|
| 76 | QMeeGoGraphicsSystemHelper::switchToMeeGo(); | 
|---|
| 77 | QMeeGoGraphicsSystemHelper::switchToRaster(); | 
|---|
| 78 | \endcode | 
|---|
| 79 | */ | 
|---|
| 80 |  | 
|---|
| 81 | class Q_DECL_EXPORT QMeeGoGraphicsSystemHelper | 
|---|
| 82 | { | 
|---|
| 83 | public: | 
|---|
| 84 | //! Returns true if running meego. | 
|---|
| 85 | /*! | 
|---|
| 86 | Returns true if the currently active (running) system is 'meego' with OpenGL. | 
|---|
| 87 | This returns both true if the app was started with 'meego' or was started with | 
|---|
| 88 | 'runtime' graphics system and the currently active system through the runtime | 
|---|
| 89 | switching is 'meego'. | 
|---|
| 90 | */ | 
|---|
| 91 | static bool isRunningMeeGo(); | 
|---|
| 92 |  | 
|---|
| 93 | //! Returns true if running with a 'runtime' graphicssystem. | 
|---|
| 94 | /*! | 
|---|
| 95 | This function can be used in combination with ::runningGraphicsSystemName to figure out | 
|---|
| 96 | the existing situation. | 
|---|
| 97 | */ | 
|---|
| 98 | static bool isRunningRuntime(); | 
|---|
| 99 |  | 
|---|
| 100 | //! Switches to meego graphics system. | 
|---|
| 101 | /*! | 
|---|
| 102 | When running with the 'runtime' graphics system, sets the currently active | 
|---|
| 103 | system to 'meego'. The window surface and all the resources are automatically | 
|---|
| 104 | migrated to OpenGL. Will fail if the active graphics system is not 'runtime'. | 
|---|
| 105 | Calling this function will emit QMeeGoSwitchEvent to the top level widgets. | 
|---|
| 106 | Two events will be emitted for each switch -- one before the switch (QMeeGoSwitchEvent::WillSwitch) | 
|---|
| 107 | and one after the switch (QMeeGoSwitchEvent::DidSwitch). | 
|---|
| 108 | */ | 
|---|
| 109 | static void switchToMeeGo(); | 
|---|
| 110 |  | 
|---|
| 111 | //! Switches to raster graphics system | 
|---|
| 112 | /*! | 
|---|
| 113 | When running with the 'runtime' graphics system, sets the currently active | 
|---|
| 114 | system to 'raster'. The window surface and the graphics resources (including the | 
|---|
| 115 | EGL shared image resources) are automatically migrated back to the CPU. All OpenGL | 
|---|
| 116 | resources (surface, context, cache, font cache) are automaticall anihilated. | 
|---|
| 117 | Calling this function will emit QMeeGoSwitchEvent to the top level widgets. | 
|---|
| 118 | Two events will be emitted for each switch -- one before the switch (QMeeGoSwitchEvent::WillSwitch) | 
|---|
| 119 | and one after the switch (QMeeGoSwitchEvent::DidSwitch). | 
|---|
| 120 | */ | 
|---|
| 121 | static void switchToRaster(); | 
|---|
| 122 |  | 
|---|
| 123 | //! Returns the name of the active graphics system | 
|---|
| 124 | /*! | 
|---|
| 125 | Returns the name of the currently active system. If running with 'runtime' graphics | 
|---|
| 126 | system, returns the name of the active system inside the runtime graphics system | 
|---|
| 127 | */ | 
|---|
| 128 | static QString runningGraphicsSystemName(); | 
|---|
| 129 |  | 
|---|
| 130 | //! Creates a new EGL shared image. | 
|---|
| 131 | /*! | 
|---|
| 132 | Creates a new EGL shared image from the given image. The EGL shared image wraps | 
|---|
| 133 | a GL texture in the native format and can be easily accessed from other processes. | 
|---|
| 134 | */ | 
|---|
| 135 | static Qt::HANDLE imageToEGLSharedImage(const QImage &image); | 
|---|
| 136 |  | 
|---|
| 137 | //! Creates a QPixmap from an EGL shared image | 
|---|
| 138 | /*! | 
|---|
| 139 | Creates a new QPixmap from the given EGL shared image handle. The QPixmap can be | 
|---|
| 140 | used for painting like any other pixmap. The softImage should point to an alternative, | 
|---|
| 141 | software version of the graphical resource -- ie. obtained from theme daemon. The | 
|---|
| 142 | softImage can be allocated on a QSharedMemory slice for easy sharing across processes | 
|---|
| 143 | too. When the application is migrated ToRaster, this softImage will replace the | 
|---|
| 144 | contents of the sharedImage. | 
|---|
| 145 |  | 
|---|
| 146 | It's ok to call this function too when not running 'meego' graphics system. In this | 
|---|
| 147 | case it'll create a QPixmap backed with a raster data (from softImage)... but when | 
|---|
| 148 | the system is switched back to 'meego', the QPixmap will be migrated to a EGL-shared image | 
|---|
| 149 | backed storage (handle). | 
|---|
| 150 | */ | 
|---|
| 151 | static QPixmap pixmapFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage); | 
|---|
| 152 |  | 
|---|
| 153 | //! Destroys an EGL shared image. | 
|---|
| 154 | /*! | 
|---|
| 155 | Destroys an EGLSharedImage previously created with an ::imageToEGLSharedImage call. | 
|---|
| 156 | Returns true if the image was found and the destruction was successful. Notice that | 
|---|
| 157 | this destroys the image for all processes using it. | 
|---|
| 158 | */ | 
|---|
| 159 | static bool destroyEGLSharedImage(Qt::HANDLE handle); | 
|---|
| 160 |  | 
|---|
| 161 | //! Updates the QPixmap backed with an EGLShared image. | 
|---|
| 162 | /*! | 
|---|
| 163 | This function re-reads the softImage that was specified when creating the pixmap with | 
|---|
| 164 | ::pixmapFromEGLSharedImage and updates the EGL Shared image contents. It can be used | 
|---|
| 165 | to share cross-proccess mutable EGLShared images. | 
|---|
| 166 | */ | 
|---|
| 167 | static void updateEGLSharedImagePixmap(QPixmap *p); | 
|---|
| 168 |  | 
|---|
| 169 | //! Create a new QPixmap with a GL texture. | 
|---|
| 170 | /*! | 
|---|
| 171 | Creates a new QPixmap which is backed by an OpenGL local texture. Drawing to this | 
|---|
| 172 | QPixmap will be accelerated by hardware -- unlike the normal (new QPixmap()) pixmaps, | 
|---|
| 173 | which are backed by a software engine and only migrated to GPU when used. Migrating those | 
|---|
| 174 | GL-backed pixmaps when going ToRaster is expsensive (they need to be downloaded from | 
|---|
| 175 | GPU to CPU) so use wisely. | 
|---|
| 176 | */ | 
|---|
| 177 | static QPixmap pixmapWithGLTexture(int w, int h); | 
|---|
| 178 |  | 
|---|
| 179 | //! Sets translucency (alpha) on the base window surface. | 
|---|
| 180 | /*! | 
|---|
| 181 | This function needs to be called *before* any widget/content is created. | 
|---|
| 182 | When called with true, the base window surface will be translucent and initialized | 
|---|
| 183 | with QGLFormat.alpha == true. | 
|---|
| 184 |  | 
|---|
| 185 | This function is *deprecated*. Set Qt::WA_TranslucentBackground attribute | 
|---|
| 186 | on the top-level widget *before* you show it instead. | 
|---|
| 187 | */ | 
|---|
| 188 | static void setTranslucent(bool translucent); | 
|---|
| 189 |  | 
|---|
| 190 | //! Used to specify the mode for swapping buffers in double-buffered GL rendering. | 
|---|
| 191 | enum SwapMode { | 
|---|
| 192 | AutomaticSwap,      /**< Automatically choose netween full and partial updates (25% threshold) */ | 
|---|
| 193 | AlwaysFullSwap,     /**< Always do a full swap even if partial updates support present */ | 
|---|
| 194 | AlwaysPartialSwap,  /**< Always do a partial swap (if support present) no matter what threshold */ | 
|---|
| 195 | KillSwap            /**< Do not perform buffer swapping at all (no picture) */ | 
|---|
| 196 | }; | 
|---|
| 197 |  | 
|---|
| 198 | //! Sets the buffer swapping mode. | 
|---|
| 199 | /*! | 
|---|
| 200 | This can be only called when running with the meego graphics system. | 
|---|
| 201 | The KillSwap mode can be specififed to effectively block painting. | 
|---|
| 202 |  | 
|---|
| 203 | This functionality should be used only by applications counting on a specific behavior. | 
|---|
| 204 | Most applications should use the default automatic behavior. | 
|---|
| 205 | */ | 
|---|
| 206 | static void setSwapBehavior(SwapMode mode); | 
|---|
| 207 | }; | 
|---|
| 208 |  | 
|---|
| 209 | #endif | 
|---|