Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qmeegoruntime.h"
43
44#include "qmeegoswitchevent.h"
45
46#include <QtGui/QApplication>
47#include <QtGui/QWidget>
48
49#include <private/qlibrary_p.h>
50#include <private/qfactoryloader_p.h>
51#include <private/qgraphicssystemplugin_p.h>
52#include <stdio.h>
53
54#define ENSURE_INITIALIZED {if (!initialized) initialize();}
55
56bool QMeeGoRuntime::initialized = false;
57bool QMeeGoRuntime::switchEventsEnabled = false;
58
59typedef int (*QMeeGoImageToEglSharedImageFunc) (const QImage&);
60typedef QPixmapData* (*QMeeGoPixmapDataFromEglSharedImageFunc) (Qt::HANDLE handle, const QImage&);
61typedef QPixmapData* (*QMeeGoPixmapDataWithGLTextureFunc) (int w, int h);
62typedef bool (*QMeeGoDestroyEGLSharedImageFunc) (Qt::HANDLE handle);
63typedef void (*QMeeGoUpdateEglSharedImagePixmapFunc) (QPixmap*);
64typedef void (*QMeeGoSetSurfaceFixedSizeFunc) (int w, int h);
65typedef void (*QMeeGoSetSurfaceScalingFunc) (int x, int y, int w, int h);
66typedef void (*QMeeGoSetTranslucentFunc) (bool translucent);
67typedef QPixmapData* (*QMeeGoPixmapDataWithNewLiveTextureFunc) (int w, int h, QImage::Format format);
68typedef QPixmapData* (*QMeeGoPixmapDataFromLiveTextureHandleFunc) (Qt::HANDLE h);
69typedef QImage* (*QMeeGoLiveTextureLockFunc) (QPixmap*, void* fenceSync);
70typedef bool (*QMeeGoLiveTextureReleaseFunc) (QPixmap*, QImage *i);
71typedef Qt::HANDLE (*QMeeGoLiveTextureGetHandleFunc) (QPixmap*);
72typedef void* (*QMeeGoCreateFenceSyncFunc) (void);
73typedef void (*QMeeGoDestroyFenceSyncFunc) (void *fs);
74typedef void (*QMeeGoInvalidateLiveSurfacesFunc) (void);
75typedef void (*QMeeGoSwitchToRasterFunc) (void);
76typedef void (*QMeeGoSwitchToMeeGoFunc) (void);
77typedef void (*QMeeGoRegisterSwitchCallbackFunc) (void (*callback)(int type, const char *name));
78typedef void (*QMeeGoSetSwitchPolicyFunc) (int policy);
79
80static QMeeGoImageToEglSharedImageFunc qt_meego_image_to_egl_shared_image = NULL;
81static QMeeGoPixmapDataFromEglSharedImageFunc qt_meego_pixmapdata_from_egl_shared_image = NULL;
82static QMeeGoPixmapDataWithGLTextureFunc qt_meego_pixmapdata_with_gl_texture = NULL;
83static QMeeGoDestroyEGLSharedImageFunc qt_meego_destroy_egl_shared_image = NULL;
84static QMeeGoUpdateEglSharedImagePixmapFunc qt_meego_update_egl_shared_image_pixmap = NULL;
85static QMeeGoSetSurfaceFixedSizeFunc qt_meego_set_surface_fixed_size = NULL;
86static QMeeGoSetSurfaceScalingFunc qt_meego_set_surface_scaling = NULL;
87static QMeeGoSetTranslucentFunc qt_meego_set_translucent = NULL;
88static QMeeGoPixmapDataWithNewLiveTextureFunc qt_meego_pixmapdata_with_new_live_texture = NULL;
89static QMeeGoPixmapDataFromLiveTextureHandleFunc qt_meego_pixmapdata_from_live_texture_handle = NULL;
90static QMeeGoLiveTextureLockFunc qt_meego_live_texture_lock = NULL;
91static QMeeGoLiveTextureReleaseFunc qt_meego_live_texture_release = NULL;
92static QMeeGoLiveTextureGetHandleFunc qt_meego_live_texture_get_handle = NULL;
93static QMeeGoCreateFenceSyncFunc qt_meego_create_fence_sync = NULL;
94static QMeeGoDestroyFenceSyncFunc qt_meego_destroy_fence_sync = NULL;
95static QMeeGoInvalidateLiveSurfacesFunc qt_meego_invalidate_live_surfaces = NULL;
96static QMeeGoSwitchToRasterFunc qt_meego_switch_to_raster = NULL;
97static QMeeGoSwitchToMeeGoFunc qt_meego_switch_to_meego = NULL;
98static QMeeGoRegisterSwitchCallbackFunc qt_meego_register_switch_callback = NULL;
99static QMeeGoSetSwitchPolicyFunc qt_meego_set_switch_policy = NULL;
100
101extern "C" void handleSwitch(int type, const char *name)
102{
103 QMeeGoSwitchEvent switchEvent((QLatin1String(name)), QMeeGoSwitchEvent::State(type));
104 foreach (QWidget *widget, QApplication::topLevelWidgets())
105 QCoreApplication::sendEvent(widget, &switchEvent);
106}
107
108void QMeeGoRuntime::initialize()
109{
110 QFactoryLoader loader(QGraphicsSystemFactoryInterface_iid, QLatin1String("/graphicssystems"), Qt::CaseInsensitive);
111
112 QLibraryPrivate *libraryPrivate = loader.library(QLatin1String("meego"));
113 Q_ASSERT(libraryPrivate);
114
115 QLibrary library(libraryPrivate->fileName, libraryPrivate->fullVersion);
116 library.setLoadHints(QLibrary::ImprovedSearchHeuristics);
117 bool success = library.load();
118
119 if (success) {
120 qt_meego_image_to_egl_shared_image = (QMeeGoImageToEglSharedImageFunc) library.resolve("qt_meego_image_to_egl_shared_image");
121 qt_meego_pixmapdata_from_egl_shared_image = (QMeeGoPixmapDataFromEglSharedImageFunc) library.resolve("qt_meego_pixmapdata_from_egl_shared_image");
122 qt_meego_pixmapdata_with_gl_texture = (QMeeGoPixmapDataWithGLTextureFunc) library.resolve("qt_meego_pixmapdata_with_gl_texture");
123 qt_meego_destroy_egl_shared_image = (QMeeGoDestroyEGLSharedImageFunc) library.resolve("qt_meego_destroy_egl_shared_image");
124 qt_meego_update_egl_shared_image_pixmap = (QMeeGoUpdateEglSharedImagePixmapFunc) library.resolve("qt_meego_update_egl_shared_image_pixmap");
125 qt_meego_set_surface_fixed_size = (QMeeGoSetSurfaceFixedSizeFunc) library.resolve("qt_meego_set_surface_fixed_size");
126 qt_meego_set_surface_scaling = (QMeeGoSetSurfaceScalingFunc) library.resolve("qt_meego_set_surface_scaling");
127 qt_meego_set_translucent = (QMeeGoSetTranslucentFunc) library.resolve("qt_meego_set_translucent");
128 qt_meego_pixmapdata_with_new_live_texture = (QMeeGoPixmapDataWithNewLiveTextureFunc) library.resolve("qt_meego_pixmapdata_with_new_live_texture");
129 qt_meego_pixmapdata_from_live_texture_handle = (QMeeGoPixmapDataFromLiveTextureHandleFunc) library.resolve("qt_meego_pixmapdata_from_live_texture_handle");
130 qt_meego_live_texture_lock = (QMeeGoLiveTextureLockFunc) library.resolve("qt_meego_live_texture_lock");
131 qt_meego_live_texture_release = (QMeeGoLiveTextureReleaseFunc) library.resolve("qt_meego_live_texture_release");
132 qt_meego_live_texture_get_handle = (QMeeGoLiveTextureGetHandleFunc) library.resolve("qt_meego_live_texture_get_handle");
133 qt_meego_create_fence_sync = (QMeeGoCreateFenceSyncFunc) library.resolve("qt_meego_create_fence_sync");
134 qt_meego_destroy_fence_sync = (QMeeGoDestroyFenceSyncFunc) library.resolve("qt_meego_destroy_fence_sync");
135 qt_meego_invalidate_live_surfaces = (QMeeGoInvalidateLiveSurfacesFunc) library.resolve("qt_meego_invalidate_live_surfaces");
136 qt_meego_switch_to_raster = (QMeeGoSwitchToRasterFunc) library.resolve("qt_meego_switch_to_raster");
137 qt_meego_switch_to_meego = (QMeeGoSwitchToMeeGoFunc) library.resolve("qt_meego_switch_to_meego");
138 qt_meego_register_switch_callback = (QMeeGoRegisterSwitchCallbackFunc) library.resolve("qt_meego_register_switch_callback");
139 qt_meego_set_switch_policy = (QMeeGoSetSwitchPolicyFunc) library.resolve("qt_meego_set_switch_policy");
140
141 if (qt_meego_image_to_egl_shared_image && qt_meego_pixmapdata_from_egl_shared_image &&
142 qt_meego_pixmapdata_with_gl_texture && qt_meego_destroy_egl_shared_image && qt_meego_update_egl_shared_image_pixmap &&
143 qt_meego_set_surface_fixed_size && qt_meego_set_surface_scaling && qt_meego_set_translucent &&
144 qt_meego_pixmapdata_with_new_live_texture && qt_meego_pixmapdata_from_live_texture_handle &&
145 qt_meego_live_texture_lock && qt_meego_live_texture_release && qt_meego_live_texture_get_handle &&
146 qt_meego_create_fence_sync && qt_meego_destroy_fence_sync && qt_meego_invalidate_live_surfaces &&
147 qt_meego_switch_to_raster && qt_meego_switch_to_meego && qt_meego_register_switch_callback &&
148 qt_meego_set_switch_policy)
149 {
150 qDebug("Successfully resolved MeeGo graphics system: %s %s\n", qPrintable(libraryPrivate->fileName), qPrintable(libraryPrivate->fullVersion));
151 } else {
152 Q_ASSERT(false);
153 }
154 } else {
155 Q_ASSERT(false);
156 }
157
158 initialized = true;
159}
160
161Qt::HANDLE QMeeGoRuntime::imageToEGLSharedImage(const QImage &image)
162{
163 ENSURE_INITIALIZED;
164 Q_ASSERT(qt_meego_image_to_egl_shared_image);
165 return qt_meego_image_to_egl_shared_image(image);
166}
167
168QPixmapData* QMeeGoRuntime::pixmapDataFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage)
169{
170 ENSURE_INITIALIZED;
171 Q_ASSERT(qt_meego_pixmapdata_from_egl_shared_image);
172 return qt_meego_pixmapdata_from_egl_shared_image(handle, softImage);
173}
174
175QPixmapData* QMeeGoRuntime::pixmapDataWithGLTexture(int w, int h)
176{
177 ENSURE_INITIALIZED;
178 Q_ASSERT(qt_meego_pixmapdata_with_gl_texture);
179 return qt_meego_pixmapdata_with_gl_texture(w, h);
180}
181
182bool QMeeGoRuntime::destroyEGLSharedImage(Qt::HANDLE handle)
183{
184 ENSURE_INITIALIZED;
185 Q_ASSERT(qt_meego_destroy_egl_shared_image);
186 return qt_meego_destroy_egl_shared_image(handle);
187}
188
189void QMeeGoRuntime::updateEGLSharedImagePixmap(QPixmap *p)
190{
191 ENSURE_INITIALIZED;
192 Q_ASSERT(qt_meego_update_egl_shared_image_pixmap);
193 return qt_meego_update_egl_shared_image_pixmap(p);
194}
195
196void QMeeGoRuntime::setSurfaceFixedSize(int w, int h)
197{
198 ENSURE_INITIALIZED;
199 Q_ASSERT(qt_meego_set_surface_fixed_size);
200 qt_meego_set_surface_fixed_size(w, h);
201}
202
203void QMeeGoRuntime::setSurfaceScaling(int x, int y, int w, int h)
204{
205 ENSURE_INITIALIZED;
206 Q_ASSERT(qt_meego_set_surface_scaling);
207 qt_meego_set_surface_scaling(x, y, w, h);
208}
209
210void QMeeGoRuntime::setTranslucent(bool translucent)
211{
212 ENSURE_INITIALIZED;
213 Q_ASSERT(qt_meego_set_translucent);
214 qt_meego_set_translucent(translucent);
215}
216
217QPixmapData* QMeeGoRuntime::pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format)
218{
219 ENSURE_INITIALIZED;
220 Q_ASSERT(qt_meego_pixmapdata_with_new_live_texture);
221 return qt_meego_pixmapdata_with_new_live_texture(w, h, format);
222}
223
224QPixmapData* QMeeGoRuntime::pixmapDataFromLiveTextureHandle(Qt::HANDLE h)
225{
226 ENSURE_INITIALIZED;
227 Q_ASSERT(qt_meego_pixmapdata_from_live_texture_handle);
228 return qt_meego_pixmapdata_from_live_texture_handle(h);
229}
230
231QImage* QMeeGoRuntime::lockLiveTexture(QPixmap *p, void* fenceSync)
232{
233 ENSURE_INITIALIZED;
234 Q_ASSERT(qt_meego_live_texture_lock);
235 return qt_meego_live_texture_lock(p, fenceSync);
236}
237
238bool QMeeGoRuntime::releaseLiveTexture(QPixmap *p, QImage *i)
239{
240 ENSURE_INITIALIZED;
241 Q_ASSERT(qt_meego_live_texture_release);
242 return qt_meego_live_texture_release(p, i);
243}
244
245Qt::HANDLE QMeeGoRuntime::getLiveTextureHandle(QPixmap *pixmap)
246{
247 ENSURE_INITIALIZED;
248 Q_ASSERT(qt_meego_live_texture_get_handle);
249 return qt_meego_live_texture_get_handle(pixmap);
250}
251
252void* QMeeGoRuntime::createFenceSync()
253{
254 ENSURE_INITIALIZED;
255 Q_ASSERT(qt_meego_create_fence_sync);
256 return qt_meego_create_fence_sync();
257}
258
259void QMeeGoRuntime::destroyFenceSync(void *fs)
260{
261 ENSURE_INITIALIZED;
262 Q_ASSERT(qt_meego_destroy_fence_sync);
263 qt_meego_destroy_fence_sync(fs);
264}
265
266void QMeeGoRuntime::invalidateLiveSurfaces()
267{
268 ENSURE_INITIALIZED;
269 Q_ASSERT(qt_meego_invalidate_live_surfaces);
270 qt_meego_invalidate_live_surfaces();
271}
272
273void QMeeGoRuntime::switchToRaster()
274{
275 ENSURE_INITIALIZED;
276 Q_ASSERT(qt_meego_switch_to_raster);
277 qt_meego_switch_to_raster();
278}
279
280void QMeeGoRuntime::switchToMeeGo()
281{
282 ENSURE_INITIALIZED;
283 Q_ASSERT(qt_meego_switch_to_meego);
284 qt_meego_switch_to_meego();
285}
286
287void QMeeGoRuntime::enableSwitchEvents()
288{
289 ENSURE_INITIALIZED;
290 if (!switchEventsEnabled) {
291 Q_ASSERT(qt_meego_register_switch_callback);
292 qt_meego_register_switch_callback(handleSwitch);
293 switchEventsEnabled = true;
294 }
295}
296
297void QMeeGoRuntime::setSwitchPolicy(QMeeGoGraphicsSystemHelper::SwitchPolicy policy)
298{
299 ENSURE_INITIALIZED;
300 Q_ASSERT(qt_meego_set_switch_policy);
301 qt_meego_set_switch_policy(int(policy));
302}
303

Warning: That file was not part of the compilation database. It may have many parsing errors.