Qt 4.8
qmeegographicssystem.cpp
Go to the documentation of this file.
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 <QDebug>
43 #include <private/qpixmap_raster_p.h>
44 #include <private/qwindowsurface_gl_p.h>
45 #include <private/qwindowsurface_raster_p.h>
46 #include <private/qegl_p.h>
47 #include <private/qglextensions_p.h>
48 #include <private/qgl_p.h>
49 #include <private/qimagepixmapcleanuphooks_p.h>
50 #include <private/qapplication_p.h>
51 #include <private/qgraphicssystem_runtime_p.h>
52 #include <private/qimage_p.h>
53 #include <private/qeglproperties_p.h>
54 #include <private/qeglcontext_p.h>
55 #include <private/qpixmap_x11_p.h>
56 
57 #include "qmeegopixmapdata.h"
58 #include "qmeegolivepixmapdata.h"
59 #include "qmeegographicssystem.h"
60 #include "qmeegoextensions.h"
61 
62 #include <QTimer>
63 
65 
67 
69 
71 
73 {
74  qDebug("Using the meego graphics system");
75 }
76 
78 {
79  qDebug("Meego graphics system destroyed");
81 }
82 
84 {
85  Q_OBJECT
86 public:
88 
89  void addWidget(QWidget *widget);
90  bool eventFilter(QObject *, QEvent *);
91 
92  void handleMapNotify();
93 
94 private slots:
95  void removeWidget(QObject *object);
96  void switchToRaster();
97  void switchToMeeGo();
98 
99 private:
100  int visibleWidgets() const;
101 
102 private:
104 };
105 
106 typedef bool(*QX11FilterFunction)(XEvent *event);
108 
109 static bool x11EventFilter(XEvent *event);
110 
112 {
114 }
115 
117 {
118  if (widget != qt_gl_share_widget() && !m_widgets.contains(widget)) {
119  widget->installEventFilter(this);
120  connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(removeWidget(QObject *)));
121  m_widgets << widget;
122  }
123 }
124 
126 {
129 }
130 
132 {
133  m_widgets.removeOne(static_cast<QWidget *>(object));
136 }
137 
139 {
141 }
142 
144 {
146 }
147 
149 {
150  int count = 0;
151  for (int i = 0; i < m_widgets.size(); ++i)
152  count += m_widgets.at(i)->isVisible() && !(m_widgets.at(i)->windowState() & Qt::WindowMinimized);
153  return count;
154 }
155 
157 {
158  if (event->type() == QEvent::WindowStateChange
160  {
161  QWindowStateChangeEvent *change = static_cast<QWindowStateChangeEvent *>(event);
162  QWidget *widget = static_cast<QWidget *>(object);
163 
164  Qt::WindowStates current = widget->windowState();
165  Qt::WindowStates old = change->oldState();
166 
167  // did minimized flag change?
168  if ((current ^ old) & Qt::WindowMinimized) {
169  if (current & Qt::WindowMinimized) {
170  if (visibleWidgets() == 0)
172  } else {
173  if (visibleWidgets() > 0)
175  }
176  }
177  } else if (event->type() == QEvent::Show
178  && QMeeGoGraphicsSystem::switchPolicy == QMeeGoGraphicsSystem::AutomaticSwitch) {
179  if (visibleWidgets() > 0)
181  } else if (event->type() == QEvent::Hide
182  && QMeeGoGraphicsSystem::switchPolicy == QMeeGoGraphicsSystem::AutomaticSwitch) {
183  if (visibleWidgets() == 0)
185  }
186 
187  // resume processing of event
188  return false;
189 }
190 
192 
194 {
195  if (event->type == MapNotify)
196  switch_handler()->handleMapNotify();
197  return false;
198 }
199 
201 {
202  QGLWidget *shareWidget = qt_gl_share_widget();
203 
204  if (!shareWidget)
205  return new QRasterWindowSurface(widget);
206 
207  QGLShareContextScope ctx(shareWidget->context());
208 
210  switch_handler()->addWidget(widget);
211 
213  QWindowSurface *surface = new QGLWindowSurface(widget);
214  return surface;
215 }
216 
218 {
219  return new QRasterPixmapData(type);
220 }
221 
223 {
224  // If the pixmap is a raster type...
225  // and if the pixmap pointer matches our mapping...
226  // create a shared image instead with the given handle.
227 
228  if (!origin->isNull() && origin->classId() == QPixmapData::RasterClass) {
229  QRasterPixmapData *rasterClass = static_cast <QRasterPixmapData *> (origin);
230  void *rawResource = static_cast <void *> (rasterClass->buffer()->data_ptr()->data);
231 
232  if (QMeeGoPixmapData::sharedImagesMap.contains(rawResource))
233  return new QMeeGoPixmapData();
234  }
235 
236  return new QRasterPixmapData(origin->pixelType());
237 }
238 
240 {
242  if (name == "runtime") {
244  QRuntimePixmapData *rt = new QRuntimePixmapData(rsystem, pmd->pixelType());;
245  rt->m_data = pmd;
246  rt->readBackInfo();
247  rsystem->m_pixmapDatas << rt;
248  return rt;
249  } else
250  return pmd;
251 }
252 
253 void QMeeGoGraphicsSystem::setSurfaceFixedSize(int /*width*/, int /*height*/)
254 {
256  qWarning("Trying to set surface fixed size but surface already created!");
257  return;
258  }
259 
260 #ifdef QT_WAS_PATCHED
262  properties->setValue(EGL_FIXED_WIDTH_NOK, width);
263  properties->setValue(EGL_FIXED_HEIGHT_NOK, height);
265 #endif
266 }
267 
268 void QMeeGoGraphicsSystem::setSurfaceScaling(int x, int y, int width, int height)
269 {
272 }
273 
275 {
277  qWarning("Trying to set translucency but surface already created!");
278  return;
279  }
280 
284 }
285 
287 {
288  if (softImage.format() != QImage::Format_ARGB32_Premultiplied &&
289  softImage.format() != QImage::Format_RGB32) {
290  qFatal("For egl shared images, the soft image has to be ARGB32_Premultiplied or RGB32");
291  return NULL;
292  }
293 
296  pmd->fromEGLSharedImage(handle, softImage);
298  } else {
300  pmd->fromImage(softImage, Qt::NoFormatConversion);
301 
302  // Make sure that the image was not converted in any way
303  if (pmd->buffer()->data_ptr()->data !=
304  const_cast<QImage &>(softImage).data_ptr()->data)
305  qFatal("Iternal misalignment of raster data detected. Prolly a QImage copy fail.");
306 
307  QMeeGoPixmapData::registerSharedImage(handle, softImage);
309  }
310 }
311 
313 {
314  QMeeGoPixmapData *pmd = (QMeeGoPixmapData *) pixmap->pixmapData();
315 
316  // Basic sanity check to make sure this is really a QMeeGoPixmapData...
317  if (pmd->classId() != QPixmapData::OpenGLClass)
318  qFatal("Trying to updated EGLSharedImage pixmap but it's not really a shared image pixmap!");
319 
320  pmd->updateFromSoftImage();
321 }
322 
324 {
326  pmd->resize(w, h);
328 }
329 
331 {
332  return runningGraphicsSystemName() == "meego";
333 }
334 
336 {
337  return new QMeeGoLivePixmapData(w, h, format);
338 }
339 
341 {
342  return new QMeeGoLivePixmapData(handle);
343 }
344 
346 {
347  QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
348  return pixmapData->lock(fenceSync);
349 }
350 
352 {
353  QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
354  return pixmapData->release(image);
355 }
356 
358 {
359  QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data());
360  return pixmapData->handle();
361 }
362 
364 {
368 }
369 
371 {
375 }
376 
378 {
380  qWarning("Querying graphics system but application not running yet!");
381  return QString();
382  }
383 
385  if (name == QLatin1String("runtime")) {
387  name = rsystem->graphicsSystemName();
388  }
389 
390  return name;
391 }
392 
394 {
395  if (switchPolicy == NoSwitch || meeGoRunning())
396  return;
397 
398  if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime"))
399  qWarning("Can't switch to meego - switching only supported with 'runtime' graphics system.");
400  else {
401  triggerSwitchCallbacks(0, "meego");
402 
403  QApplication *app = static_cast<QApplication *>(QCoreApplication::instance());
404  app->setGraphicsSystem(QLatin1String("meego"));
405 
406  triggerSwitchCallbacks(1, "meego");
407  }
408 }
409 
411 {
413  return;
414 
415  if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime"))
416  qWarning("Can't switch to raster - switching only supported with 'runtime' graphics system.");
417  else {
418  triggerSwitchCallbacks(0, "raster");
419 
420  QApplication *app = static_cast<QApplication *>(QCoreApplication::instance());
421  app->setGraphicsSystem(QLatin1String("raster"));
422 
424 
425  triggerSwitchCallbacks(1, "raster");
426  }
427 }
428 
430 {
432 }
433 
435 {
436  for (int i = 0; i < switchCallbacks.size(); ++i)
438 }
439 
440 /* C API */
441 
443 {
445 }
446 
448 {
449  return QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(handle, softImage);
450 }
451 
453 {
455 }
456 
458 {
460 }
461 
462 void qt_meego_set_surface_fixed_size(int width, int height)
463 {
465 }
466 
467 void qt_meego_set_surface_scaling(int x, int y, int width, int height)
468 {
469  QMeeGoGraphicsSystem::setSurfaceScaling(x, y, width, height);
470 }
471 
472 void qt_meego_set_translucent(bool translucent)
473 {
475 }
476 
478 {
480 }
481 
483 {
485 }
486 
488 {
490 }
491 
492 QImage* qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync)
493 {
494  return QMeeGoGraphicsSystem::lockLiveTexture(pixmap, fenceSync);
495 }
496 
498 {
499  return QMeeGoGraphicsSystem::releaseLiveTexture(pixmap, image);
500 }
501 
503 {
505 }
506 
508 {
510 }
511 
513 {
515 }
516 
518 {
520 }
521 
523 {
525 }
526 
528 {
530 }
531 
533 {
535 }
536 
538 {
540 }
541 
542 #include "qmeegographicssystem.moc"
static bool eglSetSurfaceScalingNOK(EGLDisplay dpy, EGLSurface surface, int x, int y, int width, int height)
static void triggerSwitchCallbacks(int type, const char *name)
static void registerSharedImage(Qt::HANDLE handle, const QImage &si)
Qt::WindowStates oldState() const
Returns the state of the window before the change.
Definition: qevent.h:712
DataPtr & data_ptr()
Definition: qpixmap.h:297
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
Format
The following image formats are available in Qt.
Definition: qimage.h:91
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
bool(* QX11FilterFunction)(XEvent *event)
bool qt_meego_live_texture_release(QPixmap *pixmap, QImage *image)
int type
Definition: qmetatype.cpp:239
void setSamples(int numSamples)
Set the preferred number of samples per pixel when multisampling is enabled to numSamples.
Definition: qgl.cpp:836
static void updateEGLSharedImagePixmap(QPixmap *pixmap)
EventRef event
QPointer< QWidget > widget
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
void * qt_meego_create_fence_sync(void)
static QImage * lockLiveTexture(QPixmap *pixmap, void *fenceSync)
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
Q_OPENGL_EXPORT QGLWidget * qt_gl_share_widget()
static QPixmapData * pixmapDataFromLiveTextureHandle(Qt::HANDLE handle)
#define SLOT(a)
Definition: qobjectdefs.h:226
static void setExtraWindowSurfaceCreationProps(QEglProperties *props)
Definition: qgl_egl.cpp:352
void qt_meego_set_switch_policy(int policy)
static bool x11EventFilter(XEvent *event)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
const QGLContext * context() const
Returns the context of this widget.
Definition: qgl.cpp:5303
static void registerSwitchCallback(QMeeGoSwitchCallback callback)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QApplicationPrivate * instance()
void qt_meego_destroy_fence_sync(void *fs)
static bool releaseLiveTexture(QPixmap *pixmap, QImage *image)
void setAlpha(bool enable)
If enable is true enables the alpha buffer; otherwise disables the alpha buffer.
Definition: qgl.cpp:664
static void setSurfaceFixedSize(int width, int height)
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
Definition: qgl.cpp:812
The QString class provides a Unicode character string.
Definition: qstring.h:83
void qt_meego_invalidate_live_surfaces(void)
bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
void setValue(int name, int value)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual QPixmapData * createPixmapData(QPixmapData::PixelType) const
QPixmapData * qt_meego_pixmapdata_with_gl_texture(int w, int h)
QImage * lock(EGLSyncKHR fenceSync)
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
static SwitchPolicy switchPolicy
int qt_meego_image_to_egl_shared_image(const QImage &image)
union _XEvent XEvent
Definition: qwindowdefs.h:116
Q_CORE_EXPORT void qDebug(const char *,...)
PixelType pixelType() const
void qt_meego_set_surface_fixed_size(int width, int height)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static bool destroyEGLSharedImage(Qt::HANDLE h)
QImage * qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync)
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static QHash< Qt::HANDLE, QPixmap * > liveTexturePixmaps
void qt_meego_set_surface_scaling(int x, int y, int width, int height)
static void setSurfaceScaling(int x, int y, int width, int height)
void qt_meego_update_egl_shared_image_pixmap(QPixmap *pixmap)
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void resize(int width, int height)
void(* QMeeGoSwitchCallback)(int type, const char *name)
static QGLFormat surfaceFormat
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QHash< void *, QMeeGoImageInfo * > sharedImagesMap
void qt_meego_switch_to_meego(void)
ClassId classId() const
void * HANDLE
Definition: qnamespace.h:1671
static void setGraphicsSystem(const QString &)
Sets the default graphics backend to system, which will be used for on-screen widgets and QPixmaps...
Q_GUI_EXPORT void qt_installX11EventFilter(QX11FilterFunction func)
static void destroyFenceSync(void *fenceSync)
QPixmapData * qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle)
static QString graphics_system_name
static EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QWindowSurface class provides the drawing area for top-level windows.
DataPtr & data_ptr()
Definition: qimage.h:346
#define EGL_SYNC_FENCE_KHR
static QPixmapData * pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format)
QList< QRuntimePixmapData * > m_pixmapDatas
Q_CORE_EXPORT void qFatal(const char *,...)
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
void qt_destroy_gl_share_widget()
The QWindowStateChangeEvent class provides the window state before a window state change...
Definition: qevent.h:705
static QEglContext * currentContext(QEgl::API api)
Definition: qegl.cpp:799
static Qt::HANDLE imageToEGLSharedImage(const QImage &image)
static void ensureInitialized()
QPixmapData * qt_meego_pixmapdata_with_new_live_texture(int w, int h, QImage::Format format)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static bool eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
void qt_meego_register_switch_callback(QMeeGoSwitchCallback callback)
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
#define ctx
Definition: qgl.cpp:6094
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QGraphicsSystem * graphics_system
uchar * data
Definition: qimage_p.h:81
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool qt_meego_destroy_egl_shared_image(Qt::HANDLE handle)
virtual void fromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage)
void qt_meego_switch_to_raster(void)
QPixmapData * qt_meego_pixmapdata_from_egl_shared_image(Qt::HANDLE handle, const QImage &softImage)
static void setTranslucent(bool translucent)
bool isNull() const
#define EGL_FIXED_HEIGHT_NOK
Qt::HANDLE qt_meego_live_texture_get_handle(QPixmap *pixmap)
static QList< QMeeGoSwitchCallback > switchCallbacks
static QString runningGraphicsSystemName()
#define slots
Definition: qobjectdefs.h:68
#define EGL_FIXED_WIDTH_NOK
void qt_meego_set_translucent(bool translucent)
virtual void updateFromSoftImage()
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
virtual QWindowSurface * createWindowSurface(QWidget *widget) const
static QPixmapData * pixmapDataWithGLTexture(int w, int h)
static Qt::HANDLE getLiveTextureHandle(QPixmap *pixmap)
static QPixmapData * pixmapDataFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage)
static QPixmapData * wrapPixmapData(QPixmapData *pmd)
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277