source: trunk/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 11.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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 [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QDebug>
43#include <private/qpixmap_raster_p.h>
44#include <private/qwindowsurface_gl_p.h>
45#include <private/qegl_p.h>
46#include <private/qglextensions_p.h>
47#include <private/qgl_p.h>
48#include <private/qimagepixmapcleanuphooks_p.h>
49#include <private/qapplication_p.h>
50#include <private/qgraphicssystem_runtime_p.h>
51#include <private/qimage_p.h>
52#include <private/qeglproperties_p.h>
53#include <private/qeglcontext_p.h>
54#include <private/qpixmap_x11_p.h>
55
56#include "qmeegopixmapdata.h"
57#include "qmeegolivepixmapdata.h"
58#include "qmeegographicssystem.h"
59#include "qmeegoextensions.h"
60
61bool QMeeGoGraphicsSystem::surfaceWasCreated = false;
62
63QHash <Qt::HANDLE, QPixmap*> QMeeGoGraphicsSystem::liveTexturePixmaps;
64
65QMeeGoGraphicsSystem::QMeeGoGraphicsSystem()
66{
67 qDebug("Using the meego graphics system");
68}
69
70QMeeGoGraphicsSystem::~QMeeGoGraphicsSystem()
71{
72 qDebug("Meego graphics system destroyed");
73 qt_destroy_gl_share_widget();
74}
75
76QWindowSurface* QMeeGoGraphicsSystem::createWindowSurface(QWidget *widget) const
77{
78 QGLShareContextScope ctx(qt_gl_share_widget()->context());
79
80 QMeeGoGraphicsSystem::surfaceWasCreated = true;
81 QWindowSurface *surface = new QGLWindowSurface(widget);
82 return surface;
83}
84
85QPixmapData *QMeeGoGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const
86{
87 return new QRasterPixmapData(type);
88}
89
90QPixmapData *QMeeGoGraphicsSystem::createPixmapData(QPixmapData *origin)
91{
92 // If the pixmap is a raster type...
93 // and if the pixmap pointer matches our mapping...
94 // create a shared image instead with the given handle.
95
96 if (origin->classId() == QPixmapData::RasterClass) {
97 QRasterPixmapData *rasterClass = static_cast <QRasterPixmapData *> (origin);
98 void *rawResource = static_cast <void *> (rasterClass->buffer()->data_ptr()->data);
99
100 if (QMeeGoPixmapData::sharedImagesMap.contains(rawResource))
101 return new QMeeGoPixmapData();
102 }
103
104 return new QRasterPixmapData(origin->pixelType());
105}
106
107QPixmapData* QMeeGoGraphicsSystem::wrapPixmapData(QPixmapData *pmd)
108{
109 QString name = QApplicationPrivate::instance()->graphics_system_name;
110 if (name == "runtime") {
111 QRuntimeGraphicsSystem *rsystem = (QRuntimeGraphicsSystem *) QApplicationPrivate::instance()->graphics_system;
112 QRuntimePixmapData *rt = new QRuntimePixmapData(rsystem, pmd->pixelType());;
113 rt->m_data = pmd;
114 rt->readBackInfo();
115 rsystem->m_pixmapDatas << rt;
116 return rt;
117 } else
118 return pmd;
119}
120
121void QMeeGoGraphicsSystem::setSurfaceFixedSize(int /*width*/, int /*height*/)
122{
123 if (QMeeGoGraphicsSystem::surfaceWasCreated) {
124 qWarning("Trying to set surface fixed size but surface already created!");
125 return;
126 }
127
128#ifdef QT_WAS_PATCHED
129 QEglProperties *properties = new QEglProperties();
130 properties->setValue(EGL_FIXED_WIDTH_NOK, width);
131 properties->setValue(EGL_FIXED_HEIGHT_NOK, height);
132 QGLContextPrivate::setExtraWindowSurfaceCreationProps(properties);
133#endif
134}
135
136void QMeeGoGraphicsSystem::setSurfaceScaling(int x, int y, int width, int height)
137{
138 QMeeGoExtensions::ensureInitialized();
139 QMeeGoExtensions::eglSetSurfaceScalingNOK(QEgl::display(), QEglContext::currentContext(QEgl::OpenGL)->currentSurface, x, y, width, height);
140}
141
142void QMeeGoGraphicsSystem::setTranslucent(bool translucent)
143{
144 if (QMeeGoGraphicsSystem::surfaceWasCreated) {
145 qWarning("Trying to set translucency but surface already created!");
146 return;
147 }
148
149 QGLWindowSurface::surfaceFormat.setSampleBuffers(false);
150 QGLWindowSurface::surfaceFormat.setSamples(0);
151 QGLWindowSurface::surfaceFormat.setAlpha(translucent);
152}
153
154QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage)
155{
156 if (softImage.format() != QImage::Format_ARGB32_Premultiplied &&
157 softImage.format() != QImage::Format_RGB32) {
158 qFatal("For egl shared images, the soft image has to be ARGB32_Premultiplied or RGB32");
159 return NULL;
160 }
161
162 if (QMeeGoGraphicsSystem::meeGoRunning()) {
163 QMeeGoPixmapData *pmd = new QMeeGoPixmapData;
164 pmd->fromEGLSharedImage(handle, softImage);
165 return QMeeGoGraphicsSystem::wrapPixmapData(pmd);
166 } else {
167 QRasterPixmapData *pmd = new QRasterPixmapData(QPixmapData::PixmapType);
168 pmd->fromImage(softImage, Qt::NoOpaqueDetection);
169
170 // Make sure that the image was not converted in any way
171 if (pmd->buffer()->data_ptr()->data !=
172 const_cast<QImage &>(softImage).data_ptr()->data)
173 qFatal("Iternal misalignment of raster data detected. Prolly a QImage copy fail.");
174
175 QMeeGoPixmapData::registerSharedImage(handle, softImage);
176 return QMeeGoGraphicsSystem::wrapPixmapData(pmd);
177 }
178}
179
180void QMeeGoGraphicsSystem::updateEGLSharedImagePixmap(QPixmap *pixmap)
181{
182 QMeeGoPixmapData *pmd = (QMeeGoPixmapData *) pixmap->pixmapData();
183
184 // Basic sanity check to make sure this is really a QMeeGoPixmapData...
185 if (pmd->classId() != QPixmapData::OpenGLClass)
186 qFatal("Trying to updated EGLSharedImage pixmap but it's not really a shared image pixmap!");
187
188 pmd->updateFromSoftImage();
189}
190
191QPixmapData *QMeeGoGraphicsSystem::pixmapDataWithGLTexture(int w, int h)
192{
193 QGLPixmapData *pmd = new QGLPixmapData(QPixmapData::PixmapType);
194 pmd->resize(w, h);
195 return QMeeGoGraphicsSystem::wrapPixmapData(pmd);
196}
197
198bool QMeeGoGraphicsSystem::meeGoRunning()
199{
200 if (! QApplicationPrivate::instance()) {
201 qWarning("Application not running just yet... hard to know what system running!");
202 return false;
203 }
204
205 QString name = QApplicationPrivate::instance()->graphics_system_name;
206 if (name == "runtime") {
207 QRuntimeGraphicsSystem *rsystem = (QRuntimeGraphicsSystem *) QApplicationPrivate::instance()->graphics_system;
208 name = rsystem->graphicsSystemName();
209 }
210
211 return (name == "meego");
212}
213
214QPixmapData* QMeeGoGraphicsSystem::pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format)
215{
216 return new QMeeGoLivePixmapData(w, h, format);
217}
218
219QPixmapData* QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(Qt::HANDLE handle)
220{
221 return new QMeeGoLivePixmapData(handle);
222}
223
224QImage* QMeeGoGraphicsSystem::lockLiveTexture(QPixmap* pixmap, void* fenceSync)
225{
226 QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
227 return pixmapData->lock(fenceSync);
228}
229
230bool QMeeGoGraphicsSystem::releaseLiveTexture(QPixmap *pixmap, QImage *image)
231{
232 QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
233 return pixmapData->release(image);
234}
235
236Qt::HANDLE QMeeGoGraphicsSystem::getLiveTextureHandle(QPixmap *pixmap)
237{
238 QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
239 return pixmapData->handle();
240}
241
242void* QMeeGoGraphicsSystem::createFenceSync()
243{
244 QGLShareContextScope ctx(qt_gl_share_widget()->context());
245 QMeeGoExtensions::ensureInitialized();
246 return QMeeGoExtensions::eglCreateSyncKHR(QEgl::display(), EGL_SYNC_FENCE_KHR, NULL);
247}
248
249void QMeeGoGraphicsSystem::destroyFenceSync(void *fenceSync)
250{
251 QGLShareContextScope ctx(qt_gl_share_widget()->context());
252 QMeeGoExtensions::ensureInitialized();
253 QMeeGoExtensions::eglDestroySyncKHR(QEgl::display(), fenceSync);
254}
255
256/* C API */
257
258int qt_meego_image_to_egl_shared_image(const QImage &image)
259{
260 return QMeeGoPixmapData::imageToEGLSharedImage(image);
261}
262
263QPixmapData* qt_meego_pixmapdata_from_egl_shared_image(Qt::HANDLE handle, const QImage &softImage)
264{
265 return QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(handle, softImage);
266}
267
268QPixmapData* qt_meego_pixmapdata_with_gl_texture(int w, int h)
269{
270 return QMeeGoGraphicsSystem::pixmapDataWithGLTexture(w, h);
271}
272
273bool qt_meego_destroy_egl_shared_image(Qt::HANDLE handle)
274{
275 return QMeeGoPixmapData::destroyEGLSharedImage(handle);
276}
277
278void qt_meego_set_surface_fixed_size(int width, int height)
279{
280 QMeeGoGraphicsSystem::setSurfaceFixedSize(width, height);
281}
282
283void qt_meego_set_surface_scaling(int x, int y, int width, int height)
284{
285 QMeeGoGraphicsSystem::setSurfaceScaling(x, y, width, height);
286}
287
288void qt_meego_set_translucent(bool translucent)
289{
290 QMeeGoGraphicsSystem::setTranslucent(translucent);
291}
292
293void qt_meego_update_egl_shared_image_pixmap(QPixmap *pixmap)
294{
295 QMeeGoGraphicsSystem::updateEGLSharedImagePixmap(pixmap);
296}
297
298QPixmapData* qt_meego_pixmapdata_with_new_live_texture(int w, int h, QImage::Format format)
299{
300 return QMeeGoGraphicsSystem::pixmapDataWithNewLiveTexture(w, h, format);
301}
302
303QPixmapData* qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle)
304{
305 return QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(handle);
306}
307
308QImage* qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync)
309{
310 return QMeeGoGraphicsSystem::lockLiveTexture(pixmap, fenceSync);
311}
312
313bool qt_meego_live_texture_release(QPixmap *pixmap, QImage *image)
314{
315 return QMeeGoGraphicsSystem::releaseLiveTexture(pixmap, image);
316}
317
318Qt::HANDLE qt_meego_live_texture_get_handle(QPixmap *pixmap)
319{
320 return QMeeGoGraphicsSystem::getLiveTextureHandle(pixmap);
321}
322
323void* qt_meego_create_fence_sync(void)
324{
325 return QMeeGoGraphicsSystem::createFenceSync();
326}
327
328void qt_meego_destroy_fence_sync(void* fs)
329{
330 return QMeeGoGraphicsSystem::destroyFenceSync(fs);
331}
Note: See TracBrowser for help on using the repository browser.