diff options
14 files changed, 428 insertions, 48 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegoextensions.cpp b/src/plugins/graphicssystems/meego/qmeegoextensions.cpp index 611c962..dff80a4 100644 --- a/src/plugins/graphicssystems/meego/qmeegoextensions.cpp +++ b/src/plugins/graphicssystems/meego/qmeegoextensions.cpp @@ -47,6 +47,7 @@ bool QMeeGoExtensions::initialized = false; bool QMeeGoExtensions::hasImageShared = false; bool QMeeGoExtensions::hasSurfaceScaling = false; bool QMeeGoExtensions::hasLockSurface = false; +bool QMeeGoExtensions::hasFenceSync = false; /* Extension funcs */ @@ -54,8 +55,12 @@ typedef EGLBoolean (EGLAPIENTRY *eglQueryImageNOKFunc)(EGLDisplay, EGLImageKHR, typedef EGLNativeSharedImageTypeNOK (EGLAPIENTRY *eglCreateSharedImageNOKFunc)(EGLDisplay, EGLImageKHR, EGLint*); typedef EGLBoolean (EGLAPIENTRY *eglDestroySharedImageNOKFunc)(EGLDisplay, EGLNativeSharedImageTypeNOK); typedef EGLBoolean (EGLAPIENTRY *eglSetSurfaceScalingNOKFunc)(EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); -typedef EGLBoolean (EGLAPIENTRY *eglLockSurfaceKHRFunc)(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); -typedef EGLBoolean (EGLAPIENTRY *eglUnlockSurfaceKHRFunc)(EGLDisplay display, EGLSurface surface); +typedef EGLBoolean (EGLAPIENTRY *eglLockSurfaceKHRFunc)(EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglUnlockSurfaceKHRFunc)(EGLDisplay, EGLSurface); +typedef EGLSyncKHR (EGLAPIENTRY *eglCreateSyncKHRFunc)(EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglDestroySyncKHRFunc)(EGLDisplay, EGLSyncKHR); +typedef EGLint (EGLAPIENTRY *eglClientWaitSyncKHRFunc)(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR); +typedef EGLBoolean (EGLAPIENTRY *eglGetSyncAttribKHRFunc)(EGLDisplay, EGLSyncKHR, EGLint, EGLint*); static eglQueryImageNOKFunc _eglQueryImageNOK = 0; static eglCreateSharedImageNOKFunc _eglCreateSharedImageNOK = 0; @@ -63,6 +68,10 @@ static eglDestroySharedImageNOKFunc _eglDestroySharedImageNOK = 0; static eglSetSurfaceScalingNOKFunc _eglSetSurfaceScalingNOK = 0; static eglLockSurfaceKHRFunc _eglLockSurfaceKHR = 0; static eglUnlockSurfaceKHRFunc _eglUnlockSurfaceKHR = 0; +static eglCreateSyncKHRFunc _eglCreateSyncKHR = 0; +static eglDestroySyncKHRFunc _eglDestroySyncKHR = 0; +static eglClientWaitSyncKHRFunc _eglClientWaitSyncKHR = 0; +static eglGetSyncAttribKHRFunc _eglGetSyncAttribKHR = 0; /* Public */ @@ -76,15 +85,15 @@ void QMeeGoExtensions::ensureInitialized() EGLNativeSharedImageTypeNOK QMeeGoExtensions::eglCreateSharedImageNOK(EGLDisplay dpy, EGLImageKHR image, EGLint *props) { - if (! hasImageShared) + if (!hasImageShared) qFatal("EGL_NOK_image_shared not found but trying to use capability!"); - + return _eglCreateSharedImageNOK(dpy, image, props); } bool QMeeGoExtensions::eglQueryImageNOK(EGLDisplay dpy, EGLImageKHR image, EGLint prop, EGLint *v) { - if (! hasImageShared) + if (!hasImageShared) qFatal("EGL_NOK_image_shared not found but trying to use capability!"); return _eglQueryImageNOK(dpy, image, prop, v); @@ -92,7 +101,7 @@ bool QMeeGoExtensions::eglQueryImageNOK(EGLDisplay dpy, EGLImageKHR image, EGLin bool QMeeGoExtensions::eglDestroySharedImageNOK(EGLDisplay dpy, EGLNativeSharedImageTypeNOK img) { - if (! hasImageShared) + if (!hasImageShared) qFatal("EGL_NOK_image_shared not found but trying to use capability!"); return _eglDestroySharedImageNOK(dpy, img); @@ -100,7 +109,7 @@ bool QMeeGoExtensions::eglDestroySharedImageNOK(EGLDisplay dpy, EGLNativeSharedI bool QMeeGoExtensions::eglSetSurfaceScalingNOK(EGLDisplay dpy, EGLSurface surface, int x, int y, int width, int height) { - if (! hasSurfaceScaling) + if (!hasSurfaceScaling) qFatal("EGL_NOK_surface_scaling not found but trying to use capability!"); return _eglSetSurfaceScalingNOK(dpy, surface, x, y, width, height); @@ -108,7 +117,7 @@ bool QMeeGoExtensions::eglSetSurfaceScalingNOK(EGLDisplay dpy, EGLSurface surfac bool QMeeGoExtensions::eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) { - if (! hasLockSurface) + if (!hasLockSurface) qFatal("EGL_KHR_lock_surface2 not found but trying to use capability!"); return _eglLockSurfaceKHR(display, surface, attrib_list); @@ -116,19 +125,51 @@ bool QMeeGoExtensions::eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, bool QMeeGoExtensions::eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) { - if (! hasLockSurface) + if (!hasLockSurface) qFatal("EGL_KHR_lock_surface2 not found but trying to use capability!"); return _eglUnlockSurfaceKHR(display, surface); } +EGLSyncKHR QMeeGoExtensions::eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + if (!hasFenceSync) + qFatal("EGL_KHR_fence_sync not found but trying to use capability!"); + + return _eglCreateSyncKHR(dpy, type, attrib_list); +} + +bool QMeeGoExtensions::eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + if (!hasFenceSync) + qFatal("EGL_KHR_fence_sync not found but trying to use capability!"); + + return _eglDestroySyncKHR(dpy, sync); +} + +EGLint QMeeGoExtensions::eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + if (!hasFenceSync) + qFatal("EGL_KHR_fence_sync not found but trying to use capability!"); + + return _eglClientWaitSyncKHR(dpy, sync, flags, timeout); +} + +EGLBoolean QMeeGoExtensions::eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + if (!hasFenceSync) + qFatal("EGL_KHR_fence_sync not found but trying to use capability!"); + + return _eglGetSyncAttribKHR(dpy, sync, attribute, value); +} + /* Private */ void QMeeGoExtensions::initialize() { QGLContext *ctx = (QGLContext *) QGLContext::currentContext(); qt_resolve_eglimage_gl_extensions(ctx); - + if (QEgl::hasExtension("EGL_NOK_image_shared")) { qDebug("MeegoGraphics: found EGL_NOK_image_shared"); _eglQueryImageNOK = (eglQueryImageNOKFunc) eglGetProcAddress("eglQueryImageNOK"); @@ -136,15 +177,15 @@ void QMeeGoExtensions::initialize() _eglDestroySharedImageNOK = (eglDestroySharedImageNOKFunc) eglGetProcAddress("eglDestroySharedImageNOK"); _eglLockSurfaceKHR = (eglLockSurfaceKHRFunc) eglGetProcAddress("eglLockSurfaceKHR"); _eglUnlockSurfaceKHR = (eglUnlockSurfaceKHRFunc) eglGetProcAddress("eglUnlockSurfaceKHR"); - + Q_ASSERT(_eglQueryImageNOK && _eglCreateSharedImageNOK && _eglDestroySharedImageNOK); hasImageShared = true; } - + if (QEgl::hasExtension("EGL_NOK_surface_scaling")) { qDebug("MeegoGraphics: found EGL_NOK_surface_scaling"); _eglSetSurfaceScalingNOK = (eglSetSurfaceScalingNOKFunc) eglGetProcAddress("eglSetSurfaceScalingNOK"); - + Q_ASSERT(_eglSetSurfaceScalingNOK); hasSurfaceScaling = true; } @@ -153,9 +194,20 @@ void QMeeGoExtensions::initialize() qDebug("MeegoGraphics: found EGL_KHR_lock_surface2"); _eglLockSurfaceKHR = (eglLockSurfaceKHRFunc) eglGetProcAddress("eglLockSurfaceKHR"); _eglUnlockSurfaceKHR = (eglUnlockSurfaceKHRFunc) eglGetProcAddress("eglUnlockSurfaceKHR"); - + Q_ASSERT(_eglLockSurfaceKHR && _eglUnlockSurfaceKHR); hasLockSurface = true; } + + if (QEgl::hasExtension("EGL_KHR_fence_sync")) { + qDebug("MeegoGraphics: found EGL_KHR_fence_sync"); + _eglCreateSyncKHR = (eglCreateSyncKHRFunc) eglGetProcAddress("eglCreateSyncKHR"); + _eglDestroySyncKHR = (eglDestroySyncKHRFunc) eglGetProcAddress("eglDestroySyncKHR"); + _eglClientWaitSyncKHR = (eglClientWaitSyncKHRFunc) eglGetProcAddress("eglClientWaitSyncKHR"); + _eglGetSyncAttribKHR = (eglGetSyncAttribKHRFunc) eglGetProcAddress("eglGetSyncAttribKHR"); + + Q_ASSERT(_eglCreateSyncKHR && _eglDestroySyncKHR && _eglClientWaitSyncKHR && _eglGetSyncAttribKHR); + hasFenceSync = true; + } } diff --git a/src/plugins/graphicssystems/meego/qmeegoextensions.h b/src/plugins/graphicssystems/meego/qmeegoextensions.h index 9e78caf..49a1e30 100644 --- a/src/plugins/graphicssystems/meego/qmeegoextensions.h +++ b/src/plugins/graphicssystems/meego/qmeegoextensions.h @@ -77,6 +77,23 @@ typedef void* EGLNativeSharedImageTypeNOK; #define EGL_WRITE_SURFACE_BIT_KHR 0x0002 #endif +#ifndef EGL_SYNC_FENCE_KHR +#define EGL_SYNC_FENCE_KHR 0x30F9 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +typedef void* EGLSyncKHR; +typedef khronos_utime_nanoseconds_t EGLTimeKHR; +#endif + /* Class */ class QMeeGoExtensions @@ -90,6 +107,10 @@ public: static bool eglSetSurfaceScalingNOK(EGLDisplay dpy, EGLSurface surface, int x, int y, int width, int height); static bool eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); static bool eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface); + static EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); + static bool eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync); + static EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); + static EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); private: static void initialize(); @@ -98,6 +119,7 @@ private: static bool hasImageShared; static bool hasSurfaceScaling; static bool hasLockSurface; + static bool hasFenceSync; }; #endif diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp index 67d760c..063af13 100644 --- a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp +++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp @@ -82,12 +82,12 @@ QWindowSurface* QMeeGoGraphicsSystem::createWindowSurface(QWidget *widget) const QPixmapData *QMeeGoGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const { - // Long story short: without this it's possible to hit an - // uninitialized paintDevice due to a Qt bug too complex to even - // explain here... not to mention fix without going crazy. + // Long story short: without this it's possible to hit an + // unitialized paintDevice due to a Qt bug too complex to even + // explain here... not to mention fix without going crazy. // MDK QGLShareContextScope ctx(qt_gl_share_widget()->context()); - + return new QRasterPixmapData(type); } @@ -103,8 +103,8 @@ QPixmapData *QMeeGoGraphicsSystem::createPixmapData(QPixmapData *origin) if (QMeeGoPixmapData::sharedImagesMap.contains(rawResource)) return new QMeeGoPixmapData(); - } - + } + return new QRasterPixmapData(origin->pixelType()); } @@ -155,7 +155,7 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(Qt::HANDLE handl qFatal("For egl shared images, the soft image has to be ARGB32_Premultiplied or RGB32"); return NULL; } - + if (QMeeGoGraphicsSystem::meeGoRunning()) { QMeeGoPixmapData *pmd = new QMeeGoPixmapData; pmd->fromEGLSharedImage(handle, softImage); @@ -177,9 +177,9 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(Qt::HANDLE handl void QMeeGoGraphicsSystem::updateEGLSharedImagePixmap(QPixmap *pixmap) { QMeeGoPixmapData *pmd = (QMeeGoPixmapData *) pixmap->pixmapData(); - + // Basic sanity check to make sure this is really a QMeeGoPixmapData... - if (pmd->classId() != QPixmapData::OpenGLClass) + if (pmd->classId() != QPixmapData::OpenGLClass) qFatal("Trying to updated EGLSharedImage pixmap but it's not really a shared image pixmap!"); pmd->updateFromSoftImage(); @@ -218,10 +218,10 @@ QPixmapData* QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(Qt::HANDLE ha return new QMeeGoLivePixmapData(handle); } -QImage* QMeeGoGraphicsSystem::lockLiveTexture(QPixmap* pixmap) +QImage* QMeeGoGraphicsSystem::lockLiveTexture(QPixmap* pixmap, void* fenceSync) { QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data()); - return pixmapData->lock(); + return pixmapData->lock(fenceSync); } bool QMeeGoGraphicsSystem::releaseLiveTexture(QPixmap *pixmap, QImage *image) @@ -236,6 +236,20 @@ Qt::HANDLE QMeeGoGraphicsSystem::getLiveTextureHandle(QPixmap *pixmap) return pixmapData->handle(); } +void* QMeeGoGraphicsSystem::createFenceSync() +{ + QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QMeeGoExtensions::ensureInitialized(); + return QMeeGoExtensions::eglCreateSyncKHR(QEgl::display(), EGL_SYNC_FENCE_KHR, NULL); +} + +void QMeeGoGraphicsSystem::destroyFenceSync(void *fenceSync) +{ + QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QMeeGoExtensions::ensureInitialized(); + QMeeGoExtensions::eglDestroySyncKHR(QEgl::display(), fenceSync); +} + /* C API */ int qt_meego_image_to_egl_shared_image(const QImage &image) @@ -288,9 +302,9 @@ QPixmapData* qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle) return QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(handle); } -QImage* qt_meego_live_texture_lock(QPixmap *pixmap) +QImage* qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync) { - return QMeeGoGraphicsSystem::lockLiveTexture(pixmap); + return QMeeGoGraphicsSystem::lockLiveTexture(pixmap, fenceSync); } bool qt_meego_live_texture_release(QPixmap *pixmap, QImage *image) @@ -302,3 +316,13 @@ Qt::HANDLE qt_meego_live_texture_get_handle(QPixmap *pixmap) { return QMeeGoGraphicsSystem::getLiveTextureHandle(pixmap); } + +void* qt_meego_create_fence_sync(void) +{ + return QMeeGoGraphicsSystem::createFenceSync(); +} + +void qt_meego_destroy_fence_sync(void* fs) +{ + return QMeeGoGraphicsSystem::destroyFenceSync(fs); +} diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.h b/src/plugins/graphicssystems/meego/qmeegographicssystem.h index 2697f0f..1e50f00 100644 --- a/src/plugins/graphicssystems/meego/qmeegographicssystem.h +++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.h @@ -69,10 +69,13 @@ public: static QPixmapData *pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format); static QPixmapData *pixmapDataFromLiveTextureHandle(Qt::HANDLE handle); - static QImage *lockLiveTexture(QPixmap* pixmap); + static QImage *lockLiveTexture(QPixmap* pixmap, void* fenceSync); static bool releaseLiveTexture(QPixmap *pixmap, QImage *image); static Qt::HANDLE getLiveTextureHandle(QPixmap *pixmap); + static void* createFenceSync(); + static void destroyFenceSync(void* fenceSync); + private: static bool meeGoRunning(); static EGLSurface getSurfaceForLiveTexturePixmap(QPixmap *pixmap); @@ -95,9 +98,11 @@ extern "C" { Q_DECL_EXPORT void qt_meego_set_translucent(bool translucent); Q_DECL_EXPORT QPixmapData* qt_meego_pixmapdata_with_new_live_texture(int w, int h, QImage::Format format); Q_DECL_EXPORT QPixmapData* qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle); - Q_DECL_EXPORT QImage* qt_meego_live_texture_lock(QPixmap *pixmap); + Q_DECL_EXPORT QImage* qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync); Q_DECL_EXPORT bool qt_meego_live_texture_release(QPixmap *pixmap, QImage *image); Q_DECL_EXPORT Qt::HANDLE qt_meego_live_texture_get_handle(QPixmap *pixmap); + Q_DECL_EXPORT void* qt_meego_create_fence_sync(void); + Q_DECL_EXPORT void qt_meego_destroy_fence_sync(void* fs); } #endif diff --git a/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.cpp b/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.cpp index 405b765..16096c9 100644 --- a/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.cpp +++ b/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qmeegolivepixmapdata.h" -#include "qmeegoextensions.h" #include "qmeegorasterpixmapdata.h" #include <private/qimage_p.h> #include <private/qwindowsurface_gl_p.h> @@ -171,11 +170,18 @@ QPixmapData *QMeeGoLivePixmapData::createCompatiblePixmapData() const return new QMeeGoRasterPixmapData(pixelType()); } -QImage* QMeeGoLivePixmapData::lock() +QImage* QMeeGoLivePixmapData::lock(EGLSyncKHR fenceSync) { QGLShareContextScope ctx(qt_gl_share_widget()->context()); QMeeGoExtensions::ensureInitialized(); + if (fenceSync) { + QMeeGoExtensions::eglClientWaitSyncKHR(QEgl::display(), + fenceSync, + EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, + EGL_FOREVER_KHR); + } + void *data = 0; int pitch = 0; EGLSurface surface = 0; @@ -214,7 +220,6 @@ bool QMeeGoLivePixmapData::release(QImage* /*img*/) if (QMeeGoExtensions::eglUnlockSurfaceKHR(QEgl::display(), getSurfaceForBackingPixmap())) { lockedImage = QImage(); - glFinish(); return true; } else { lockedImage = QImage(); @@ -229,7 +234,7 @@ Qt::HANDLE QMeeGoLivePixmapData::handle() bool QMeeGoLivePixmapData::scroll(int dx, int dy, const QRect &rect) { - lock(); + lock(NULL); if (!lockedImage.isNull()) qt_scrollRectInImage(lockedImage, rect, QPoint(dx, dy)); diff --git a/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.h b/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.h index 1d647f0..2c6854e 100644 --- a/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.h +++ b/src/plugins/graphicssystems/meego/qmeegolivepixmapdata.h @@ -43,6 +43,7 @@ #define MLIVEPIXMAPDATA_H #include <private/qpixmapdata_gl_p.h> +#include "qmeegoextensions.h" class QMeeGoLivePixmapData : public QGLPixmapData { @@ -50,16 +51,16 @@ public: QMeeGoLivePixmapData(int w, int h, QImage::Format format); QMeeGoLivePixmapData(Qt::HANDLE h); ~QMeeGoLivePixmapData(); - + QPixmapData *createCompatiblePixmapData() const; bool scroll(int dx, int dy, const QRect &rect); void initializeThroughEGLImage(); - - QImage* lock(); + + QImage* lock(EGLSyncKHR fenceSync); bool release(QImage *img); Qt::HANDLE handle(); - + EGLSurface getSurfaceForBackingPixmap(); void destroySurfaceForPixmapData(QPixmapData* pmd); diff --git a/tools/qmeegographicssystemhelper/qmeegofencesync.cpp b/tools/qmeegographicssystemhelper/qmeegofencesync.cpp new file mode 100644 index 0000000..499e102 --- /dev/null +++ b/tools/qmeegographicssystemhelper/qmeegofencesync.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmeegofencesync.h" +#include "qmeegofencesync_p.h" +#include "qmeegoruntime.h" + +/* QMeeGoFenceSyncPrivate */ + +QMeeGoFenceSyncPrivate::QMeeGoFenceSyncPrivate() : syncObject(NULL) +{ +} + +QMeeGoFenceSyncPrivate::~QMeeGoFenceSyncPrivate() +{ + if (syncObject) { + QMeeGoRuntime::destroyFenceSync(syncObject); + syncObject = NULL; + } +} + +/* QMeeGoFenceSync */ + +QMeeGoFenceSync::QMeeGoFenceSync(QWidget *parent) : QObject(parent), d_ptr(new QMeeGoFenceSyncPrivate()) +{ + Q_D(QMeeGoFenceSync); + d->q_ptr = this; +} + +QMeeGoFenceSync::~QMeeGoFenceSync() +{ +} + +void QMeeGoFenceSync::setSyncPoint() +{ + Q_D(QMeeGoFenceSync); + if (d->syncObject) + QMeeGoRuntime::destroyFenceSync(d->syncObject); + + d->syncObject = QMeeGoRuntime::createFenceSync(); +} diff --git a/tools/qmeegographicssystemhelper/qmeegofencesync.h b/tools/qmeegographicssystemhelper/qmeegofencesync.h new file mode 100644 index 0000000..2d3f5c5 --- /dev/null +++ b/tools/qmeegographicssystemhelper/qmeegofencesync.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEEGOFENCESYNC_H +#define QMEEGOFENCESYNC_H + +#include <QWidget> + +class QMeeGoFenceSyncPrivate; + +//! A synchronization helper for GL pipeline. +/*! + Fence syncs provide a mechanism for synchronizing access to certain GL primitives + and make it possible for the application developer to be sure that a certain point + in the GL processing pipeline has been already executed before continuing operation. + + Currently fence syncs are only useful in conjunction with QMeeGoLivePixmaps. + \code + ... + // In your paint/expose event: + QImage *image = livePixmap->lock(&someGlobalFenceSync); + // Modify the image... + livePixmap->release(image); + + painter->drawPixmap(0, 0, *livePixmap); + someGlobalFenceSync.setSyncPoint(); + ... + \endcode + + Assuming the paint/expose events come repeatedly, the lock operation + will block till the previous event completed painting the livePixmap. +*/ + +class Q_DECL_EXPORT QMeeGoFenceSync : public QObject +{ +public: + //! Constructs a new fence sync. + /*! + The fence sync is created without a sync point. You need to set the sync point manually. + */ + QMeeGoFenceSync(QWidget *parent = 0); + + //! Destructor for the fence sync. + virtual ~QMeeGoFenceSync(); + + //! Sets the fence sync. + /*! + The fence sync synchronization point should be set after all drawing has been scheduled. + Setting a synchronization point always overrides the previous point -- whetver is was + used (waited upon) or not. + */ + void setSyncPoint(); + +private: + Q_DISABLE_COPY(QMeeGoFenceSync) + Q_DECLARE_PRIVATE(QMeeGoFenceSync) + +protected: + QScopedPointer<QMeeGoFenceSyncPrivate> d_ptr; //! Private bits. + friend class QMeeGoLivePixmap; +}; + +#endif diff --git a/tools/qmeegographicssystemhelper/qmeegofencesync_p.h b/tools/qmeegographicssystemhelper/qmeegofencesync_p.h new file mode 100644 index 0000000..8a5d26e --- /dev/null +++ b/tools/qmeegographicssystemhelper/qmeegofencesync_p.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmeegofencesync.h" + +#ifndef QMEEGOFENCESYNC_P_H +#define QMEEGOFENCESYNC_P_H + +class QMeeGoFenceSyncPrivate +{ +public: + Q_DECLARE_PUBLIC(QMeeGoFenceSync); + QMeeGoFenceSyncPrivate(); + + virtual ~QMeeGoFenceSyncPrivate(); + + void* syncObject; + + QMeeGoFenceSync *q_ptr; +}; + +#endif diff --git a/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro b/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro index 7412fc3..161a31b 100644 --- a/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro +++ b/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro @@ -6,5 +6,5 @@ include(../../src/qbase.pri) QT += gui INCLUDEPATH += '../../src/plugins/graphicssystems/meego' -HEADERS = qmeegographicssystemhelper.h qmeegooverlaywidget.h qmeegolivepixmap.h qmeegoruntime.h qmeegolivepixmap_p.h -SOURCES = qmeegographicssystemhelper.cpp qmeegooverlaywidget.cpp qmeegoruntime.cpp qmeegolivepixmap.cpp qmeegographicssystemhelper.h qmeegooverlaywidget.h qmeegolivepixmap.h qmeegoruntime.h qmeegolivepixmap_p.h +HEADERS = qmeegographicssystemhelper.h qmeegooverlaywidget.h qmeegolivepixmap.h qmeegoruntime.h qmeegolivepixmap_p.h qmeegofencesync.h qmeegofencesync_p.h +SOURCES = qmeegographicssystemhelper.cpp qmeegooverlaywidget.cpp qmeegoruntime.cpp qmeegolivepixmap.cpp qmeegographicssystemhelper.h qmeegooverlaywidget.h qmeegolivepixmap.h qmeegoruntime.h qmeegolivepixmap_p.h qmeegofencesync.h qmeegofencesync_p.h qmeegofencesync.cpp diff --git a/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp b/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp index d43efe2..9700581f 100644 --- a/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp +++ b/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp @@ -41,6 +41,7 @@ #include "qmeegolivepixmap.h" #include "qmeegolivepixmap_p.h" +#include "qmeegofencesync_p.h" #include "qmeegoruntime.h" /* QMeeGoLivePixmapPrivate */ @@ -102,10 +103,12 @@ QMeeGoLivePixmap::~QMeeGoLivePixmap() { } -QImage* QMeeGoLivePixmap::lock() +QImage* QMeeGoLivePixmap::lock(QMeeGoFenceSync *fenceSync) { - return QMeeGoRuntime::lockLiveTexture(this); - + if (fenceSync) + return QMeeGoRuntime::lockLiveTexture(this, fenceSync->d_func()->syncObject); + else + return QMeeGoRuntime::lockLiveTexture(this, NULL); } void QMeeGoLivePixmap::release(QImage *img) diff --git a/tools/qmeegographicssystemhelper/qmeegolivepixmap.h b/tools/qmeegographicssystemhelper/qmeegolivepixmap.h index 7be2c4b..51b5976 100644 --- a/tools/qmeegographicssystemhelper/qmeegolivepixmap.h +++ b/tools/qmeegographicssystemhelper/qmeegolivepixmap.h @@ -43,6 +43,7 @@ #define QMEEGOLIVEPIXMAP_H #include <QPixmap> +#include "qmeegofencesync.h" class QMeeGoLivePixmapPrivate; class QSharedMemory; @@ -82,8 +83,12 @@ public: //! Locks the access to the pixmap. /*! The returned image can be used for direct access. + You can optionally specify a fence sync to wait upon before unlocking. When + you specify a fence sync, you can be sure that this function will return only + when the previsouly set QMeeGoFenceSync synchronization point has been executed/passed + by the GL processing pipeline. */ - QImage* lock(); + QImage* lock(QMeeGoFenceSync *fenceSync = NULL); //! Unlocks the access to the pixmap. /*! diff --git a/tools/qmeegographicssystemhelper/qmeegoruntime.cpp b/tools/qmeegographicssystemhelper/qmeegoruntime.cpp index ac627e5..2d3ee3c 100644 --- a/tools/qmeegographicssystemhelper/qmeegoruntime.cpp +++ b/tools/qmeegographicssystemhelper/qmeegoruntime.cpp @@ -60,9 +60,11 @@ typedef void (*QMeeGoSetSurfaceScalingFunc) (int x, int y, int w, int h); typedef void (*QMeeGoSetTranslucentFunc) (bool translucent); typedef QPixmapData* (*QMeeGoPixmapDataWithNewLiveTextureFunc) (int w, int h, QImage::Format format); typedef QPixmapData* (*QMeeGoPixmapDataFromLiveTextureHandleFunc) (Qt::HANDLE h); -typedef QImage* (*QMeeGoLiveTextureLockFunc) (QPixmap*); +typedef QImage* (*QMeeGoLiveTextureLockFunc) (QPixmap*, void* fenceSync); typedef bool (*QMeeGoLiveTextureReleaseFunc) (QPixmap*, QImage *i); typedef Qt::HANDLE (*QMeeGoLiveTextureGetHandleFunc) (QPixmap*); +typedef void* (*QMeeGoCreateFenceSyncFunc) (void); +typedef void (*QMeeGoDestroyFenceSyncFunc) (void *fs); static QMeeGoImageToEglSharedImageFunc qt_meego_image_to_egl_shared_image = NULL; static QMeeGoPixmapDataFromEglSharedImageFunc qt_meego_pixmapdata_from_egl_shared_image = NULL; @@ -77,6 +79,8 @@ static QMeeGoPixmapDataFromLiveTextureHandleFunc qt_meego_pixmapdata_from_live_t static QMeeGoLiveTextureLockFunc qt_meego_live_texture_lock = NULL; static QMeeGoLiveTextureReleaseFunc qt_meego_live_texture_release = NULL; static QMeeGoLiveTextureGetHandleFunc qt_meego_live_texture_get_handle = NULL; +static QMeeGoCreateFenceSyncFunc qt_meego_create_fence_sync = NULL; +static QMeeGoDestroyFenceSyncFunc qt_meego_destroy_fence_sync = NULL; void QMeeGoRuntime::initialize() { @@ -103,12 +107,15 @@ void QMeeGoRuntime::initialize() qt_meego_live_texture_lock = (QMeeGoLiveTextureLockFunc) library.resolve("qt_meego_live_texture_lock"); qt_meego_live_texture_release = (QMeeGoLiveTextureReleaseFunc) library.resolve("qt_meego_live_texture_release"); qt_meego_live_texture_get_handle = (QMeeGoLiveTextureGetHandleFunc) library.resolve("qt_meego_live_texture_get_handle"); + qt_meego_create_fence_sync = (QMeeGoCreateFenceSyncFunc) library.resolve("qt_meego_create_fence_sync"); + qt_meego_destroy_fence_sync = (QMeeGoDestroyFenceSyncFunc) library.resolve("qt_meego_destroy_fence_sync"); if (qt_meego_image_to_egl_shared_image && qt_meego_pixmapdata_from_egl_shared_image && qt_meego_pixmapdata_with_gl_texture && qt_meego_destroy_egl_shared_image && qt_meego_update_egl_shared_image_pixmap && qt_meego_set_surface_fixed_size && qt_meego_set_surface_scaling && qt_meego_set_translucent && qt_meego_pixmapdata_with_new_live_texture && qt_meego_pixmapdata_from_live_texture_handle && - qt_meego_live_texture_lock && qt_meego_live_texture_release && qt_meego_live_texture_get_handle) + qt_meego_live_texture_lock && qt_meego_live_texture_release && qt_meego_live_texture_get_handle && + qt_meego_create_fence_sync && qt_meego_destroy_fence_sync) { qDebug("Successfully resolved MeeGo graphics system: %s %s\n", qPrintable(libraryPrivate->fileName), qPrintable(libraryPrivate->fullVersion)); } else { @@ -191,11 +198,11 @@ QPixmapData* QMeeGoRuntime::pixmapDataFromLiveTextureHandle(Qt::HANDLE h) return qt_meego_pixmapdata_from_live_texture_handle(h); } -QImage* QMeeGoRuntime::lockLiveTexture(QPixmap *p) +QImage* QMeeGoRuntime::lockLiveTexture(QPixmap *p, void* fenceSync) { ENSURE_INITIALIZED; Q_ASSERT(qt_meego_live_texture_lock); - return qt_meego_live_texture_lock(p); + return qt_meego_live_texture_lock(p, fenceSync); } bool QMeeGoRuntime::releaseLiveTexture(QPixmap *p, QImage *i) @@ -211,3 +218,17 @@ Qt::HANDLE QMeeGoRuntime::getLiveTextureHandle(QPixmap *pixmap) Q_ASSERT(qt_meego_live_texture_get_handle); return qt_meego_live_texture_get_handle(pixmap); } + +void* QMeeGoRuntime::createFenceSync() +{ + ENSURE_INITIALIZED; + Q_ASSERT(qt_meego_create_fence_sync); + return qt_meego_create_fence_sync(); +} + +void QMeeGoRuntime::destroyFenceSync(void *fs) +{ + ENSURE_INITIALIZED; + Q_ASSERT(qt_meego_destroy_fence_sync); + qt_meego_destroy_fence_sync(fs); +} diff --git a/tools/qmeegographicssystemhelper/qmeegoruntime.h b/tools/qmeegographicssystemhelper/qmeegoruntime.h index 6b34836..be6ff6b 100644 --- a/tools/qmeegographicssystemhelper/qmeegoruntime.h +++ b/tools/qmeegographicssystemhelper/qmeegoruntime.h @@ -57,9 +57,11 @@ public: static void setTranslucent(bool translucent); static QPixmapData* pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format); static QPixmapData* pixmapDataFromLiveTextureHandle(Qt::HANDLE h); - static QImage* lockLiveTexture(QPixmap *pixmap); + static QImage* lockLiveTexture(QPixmap *pixmap, void *fenceSync); static bool releaseLiveTexture(QPixmap *pixmap, QImage *image); static Qt::HANDLE getLiveTextureHandle(QPixmap *pixmap); + static void* createFenceSync(); + static void destroyFenceSync(void *fs); private: static bool initialized; |