diff options
author | Michael Dominic K <mdk@codethink.co.uk> | 2010-10-21 10:28:14 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2010-10-21 12:59:55 (GMT) |
commit | 416974d8be2fede8679a56e989ef6ec3e6404aaa (patch) | |
tree | f3ca846797b5d74e17aa5eaec657a26c12c20395 /tools | |
parent | 9624d70e5588bb1f6b0c894288c8ec3d4b3246c6 (diff) | |
download | Qt-416974d8be2fede8679a56e989ef6ec3e6404aaa.zip Qt-416974d8be2fede8679a56e989ef6ec3e6404aaa.tar.gz Qt-416974d8be2fede8679a56e989ef6ec3e6404aaa.tar.bz2 |
Major refactoring: creating a new QPixmapData subclass for live textures.
Moving code from qmeegopixmapdata there.
Merge-request: 2494
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'tools')
7 files changed, 60 insertions, 112 deletions
diff --git a/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro b/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro index 4d69fac..7412fc3 100644 --- a/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro +++ b/tools/qmeegographicssystemhelper/qmeegographicssystemhelper.pro @@ -7,4 +7,4 @@ 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 +SOURCES = qmeegographicssystemhelper.cpp qmeegooverlaywidget.cpp qmeegoruntime.cpp qmeegolivepixmap.cpp qmeegographicssystemhelper.h qmeegooverlaywidget.h qmeegolivepixmap.h qmeegoruntime.h qmeegolivepixmap_p.h diff --git a/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp b/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp index 5e36631..d43efe2 100644 --- a/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp +++ b/tools/qmeegographicssystemhelper/qmeegolivepixmap.cpp @@ -40,15 +40,12 @@ ****************************************************************************/ #include "qmeegolivepixmap.h" -#include <private/qimage_p.h> -#include <private/qpixmap_raster_p.h> #include "qmeegolivepixmap_p.h" #include "qmeegoruntime.h" -#include <QSharedMemory> /* QMeeGoLivePixmapPrivate */ -QMeeGoLivePixmapPrivate::QMeeGoLivePixmapPrivate(Qt::HANDLE h) : handle(h) +QMeeGoLivePixmapPrivate::QMeeGoLivePixmapPrivate() { } @@ -60,7 +57,7 @@ QMeeGoLivePixmapPrivate::~QMeeGoLivePixmapPrivate() QMeeGoLivePixmap* QMeeGoLivePixmap::livePixmapWithSize(int w, int h, Format format) { - QImage::Format qtFormat; + QImage::Format qtFormat; if (format == Format_RGB16) qtFormat = QImage::Format_RGB16; else if (format == Format_ARGB32_Premultiplied) @@ -69,17 +66,17 @@ QMeeGoLivePixmap* QMeeGoLivePixmap::livePixmapWithSize(int w, int h, Format form qWarning("Unsupported live pixmap format!"); return 0; } - - Qt::HANDLE liveTextureHandle = QMeeGoRuntime::createLiveTexture(w, h, qtFormat); - if (! liveTextureHandle) { + + QPixmapData *pmd = QMeeGoRuntime::pixmapDataWithNewLiveTexture(w, h, qtFormat); + if (! pmd) { qWarning("Failed to create a live texture with given size!"); return NULL; } - return QMeeGoLivePixmap::fromHandle(liveTextureHandle); + return new QMeeGoLivePixmap(pmd); } -QMeeGoLivePixmap::QMeeGoLivePixmap(QPixmapData *p, Qt::HANDLE h) : QPixmap(p), d_ptr(new QMeeGoLivePixmapPrivate(h)) +QMeeGoLivePixmap::QMeeGoLivePixmap(QPixmapData *p) : QPixmap(p), d_ptr(new QMeeGoLivePixmapPrivate()) { Q_D(QMeeGoLivePixmap); d->q_ptr = this; @@ -87,25 +84,18 @@ QMeeGoLivePixmap::QMeeGoLivePixmap(QPixmapData *p, Qt::HANDLE h) : QPixmap(p), d QMeeGoLivePixmap* QMeeGoLivePixmap::fromHandle(Qt::HANDLE liveTextureHandle) { - Qt::HANDLE eglImage = QMeeGoRuntime::liveTextureToEGLImage(liveTextureHandle); - if (! eglImage) { - qWarning("Failed to bind the live texture as an egl image!"); - return NULL; - } - - QPixmapData *pmd = QMeeGoRuntime::pixmapDataFromEGLImage(eglImage); + QPixmapData *pmd = QMeeGoRuntime::pixmapDataFromLiveTextureHandle(liveTextureHandle); if (! pmd) { - qWarning("Failed to allocate a pixmap data from a given live texture egl image!"); + qWarning("Failed to create a live texture from given handle!"); return NULL; } - - return new QMeeGoLivePixmap(pmd, liveTextureHandle); + + return new QMeeGoLivePixmap(pmd); } Qt::HANDLE QMeeGoLivePixmap::handle() { - Q_D(QMeeGoLivePixmap); - return d->handle; + return QMeeGoRuntime::getLiveTextureHandle(this); } QMeeGoLivePixmap::~QMeeGoLivePixmap() @@ -114,30 +104,11 @@ QMeeGoLivePixmap::~QMeeGoLivePixmap() QImage* QMeeGoLivePixmap::lock() { - Q_D(QMeeGoLivePixmap); + return QMeeGoRuntime::lockLiveTexture(this); - void *data = NULL; - int pitch = 0; - QImage::Format format; - - if (! QMeeGoRuntime::lockLiveTexture(d->handle)) { - qWarning("Failed to lock a live texture!"); - return new QImage(); - } - - QMeeGoRuntime::queryLiveTexture(d->handle, &data, &pitch, &format); - if (data == NULL || pitch == 0) { - qWarning("Failed to query the live texture!"); - return new QImage(); - } - - return new QImage((uchar *) data, width(), height(), format); } - + void QMeeGoLivePixmap::release(QImage *img) { - Q_D(QMeeGoLivePixmap); - // FIXME Make sure we're locked! - QMeeGoRuntime::unlockLiveTexture(d->handle); - delete img; + QMeeGoRuntime::releaseLiveTexture(this, img); } diff --git a/tools/qmeegographicssystemhelper/qmeegolivepixmap.h b/tools/qmeegographicssystemhelper/qmeegolivepixmap.h index 12fe994..7be2c4b 100644 --- a/tools/qmeegographicssystemhelper/qmeegolivepixmap.h +++ b/tools/qmeegographicssystemhelper/qmeegolivepixmap.h @@ -52,7 +52,7 @@ class QImage; /*! */ -class QMeeGoLivePixmap : public QPixmap +class Q_DECL_EXPORT QMeeGoLivePixmap : public QPixmap { public: enum Format { @@ -96,7 +96,7 @@ public: virtual ~QMeeGoLivePixmap(); private: - QMeeGoLivePixmap(QPixmapData *p, Qt::HANDLE h); + QMeeGoLivePixmap(QPixmapData *p); Q_DISABLE_COPY(QMeeGoLivePixmap) Q_DECLARE_PRIVATE(QMeeGoLivePixmap) diff --git a/tools/qmeegographicssystemhelper/qmeegolivepixmap_p.h b/tools/qmeegographicssystemhelper/qmeegolivepixmap_p.h index 22347d6..78d9553 100644 --- a/tools/qmeegographicssystemhelper/qmeegolivepixmap_p.h +++ b/tools/qmeegographicssystemhelper/qmeegolivepixmap_p.h @@ -48,11 +48,9 @@ class QMeeGoLivePixmapPrivate { public: Q_DECLARE_PUBLIC(QMeeGoLivePixmap); - QMeeGoLivePixmapPrivate(Qt::HANDLE handle); + QMeeGoLivePixmapPrivate(); virtual ~QMeeGoLivePixmapPrivate(); - - Qt::HANDLE handle; - + QMeeGoLivePixmap *q_ptr; }; diff --git a/tools/qmeegographicssystemhelper/qmeegooverlaywidget.h b/tools/qmeegographicssystemhelper/qmeegooverlaywidget.h index c2c08b4..e67f59b 100644 --- a/tools/qmeegographicssystemhelper/qmeegooverlaywidget.h +++ b/tools/qmeegographicssystemhelper/qmeegooverlaywidget.h @@ -48,7 +48,7 @@ /*! */ -class QMeeGoOverlayWidget : public QWidget +class Q_DECL_EXPORT QMeeGoOverlayWidget : public QWidget { public: //! Constructs a new scaling widget. diff --git a/tools/qmeegographicssystemhelper/qmeegoruntime.cpp b/tools/qmeegographicssystemhelper/qmeegoruntime.cpp index 215dffc..ac627e5 100644 --- a/tools/qmeegographicssystemhelper/qmeegoruntime.cpp +++ b/tools/qmeegographicssystemhelper/qmeegoruntime.cpp @@ -44,6 +44,7 @@ #include <private/qlibrary_p.h> #include <private/qfactoryloader_p.h> #include <private/qgraphicssystemplugin_p.h> +#include <stdio.h> #define ENSURE_INITIALIZED {if (!initialized) initialize();} @@ -51,36 +52,31 @@ bool QMeeGoRuntime::initialized = false; typedef int (*QMeeGoImageToEglSharedImageFunc) (const QImage&); typedef QPixmapData* (*QMeeGoPixmapDataFromEglSharedImageFunc) (Qt::HANDLE handle, const QImage&); -typedef QPixmapData* (*QMeeGoPixmapDataFromEglImageFunc) (Qt::HANDLE handle); typedef QPixmapData* (*QMeeGoPixmapDataWithGLTextureFunc) (int w, int h); typedef bool (*QMeeGoDestroyEGLSharedImageFunc) (Qt::HANDLE handle); typedef void (*QMeeGoUpdateEglSharedImagePixmapFunc) (QPixmap*); typedef void (*QMeeGoSetSurfaceFixedSizeFunc) (int w, int h); typedef void (*QMeeGoSetSurfaceScalingFunc) (int x, int y, int w, int h); typedef void (*QMeeGoSetTranslucentFunc) (bool translucent); -typedef Qt::HANDLE (*QMeeGoLiveTextureCreateFunc) (int w, int h, QImage::Format format); -typedef bool (*QMeeGoLiveTextureLockFunc) (Qt::HANDLE h); -typedef bool (*QMeeGoLiveTextureUnlockFunc) (Qt::HANDLE h); -typedef void (*QMeeGoLiveTextureDestroyFunc) (Qt::HANDLE h); -typedef void (*QMeeGoLiveTextureQueryFunc) (Qt::HANDLE h, void **data, int *pitch, QImage::Format *format); -typedef Qt::HANDLE (*QMeeGoLiveTextureToEglImageFunc) (Qt::HANDLE h); +typedef QPixmapData* (*QMeeGoPixmapDataWithNewLiveTextureFunc) (int w, int h, QImage::Format format); +typedef QPixmapData* (*QMeeGoPixmapDataFromLiveTextureHandleFunc) (Qt::HANDLE h); +typedef QImage* (*QMeeGoLiveTextureLockFunc) (QPixmap*); +typedef bool (*QMeeGoLiveTextureReleaseFunc) (QPixmap*, QImage *i); +typedef Qt::HANDLE (*QMeeGoLiveTextureGetHandleFunc) (QPixmap*); static QMeeGoImageToEglSharedImageFunc qt_meego_image_to_egl_shared_image = NULL; static QMeeGoPixmapDataFromEglSharedImageFunc qt_meego_pixmapdata_from_egl_shared_image = NULL; -static QMeeGoPixmapDataFromEglImageFunc qt_meego_pixmapdata_from_egl_image = NULL; static QMeeGoPixmapDataWithGLTextureFunc qt_meego_pixmapdata_with_gl_texture = NULL; static QMeeGoDestroyEGLSharedImageFunc qt_meego_destroy_egl_shared_image = NULL; static QMeeGoUpdateEglSharedImagePixmapFunc qt_meego_update_egl_shared_image_pixmap = NULL; static QMeeGoSetSurfaceFixedSizeFunc qt_meego_set_surface_fixed_size = NULL; static QMeeGoSetSurfaceScalingFunc qt_meego_set_surface_scaling = NULL; static QMeeGoSetTranslucentFunc qt_meego_set_translucent = NULL; -static QMeeGoLiveTextureCreateFunc qt_meego_live_texture_create = NULL; +static QMeeGoPixmapDataWithNewLiveTextureFunc qt_meego_pixmapdata_with_new_live_texture = NULL; +static QMeeGoPixmapDataFromLiveTextureHandleFunc qt_meego_pixmapdata_from_live_texture_handle = NULL; static QMeeGoLiveTextureLockFunc qt_meego_live_texture_lock = NULL; -static QMeeGoLiveTextureUnlockFunc qt_meego_live_texture_unlock = NULL; -static QMeeGoLiveTextureDestroyFunc qt_meego_live_texture_destroy = NULL; -static QMeeGoLiveTextureQueryFunc qt_meego_live_texture_query = NULL; -static QMeeGoLiveTextureToEglImageFunc qt_meego_live_texture_to_egl_image = NULL; - +static QMeeGoLiveTextureReleaseFunc qt_meego_live_texture_release = NULL; +static QMeeGoLiveTextureGetHandleFunc qt_meego_live_texture_get_handle = NULL; void QMeeGoRuntime::initialize() { @@ -96,27 +92,27 @@ void QMeeGoRuntime::initialize() if (success) { qt_meego_image_to_egl_shared_image = (QMeeGoImageToEglSharedImageFunc) library.resolve("qt_meego_image_to_egl_shared_image"); qt_meego_pixmapdata_from_egl_shared_image = (QMeeGoPixmapDataFromEglSharedImageFunc) library.resolve("qt_meego_pixmapdata_from_egl_shared_image"); - qt_meego_pixmapdata_from_egl_image = (QMeeGoPixmapDataFromEglImageFunc) library.resolve("qt_meego_pixmapdata_from_egl_image"); qt_meego_pixmapdata_with_gl_texture = (QMeeGoPixmapDataWithGLTextureFunc) library.resolve("qt_meego_pixmapdata_with_gl_texture"); qt_meego_destroy_egl_shared_image = (QMeeGoDestroyEGLSharedImageFunc) library.resolve("qt_meego_destroy_egl_shared_image"); qt_meego_update_egl_shared_image_pixmap = (QMeeGoUpdateEglSharedImagePixmapFunc) library.resolve("qt_meego_update_egl_shared_image_pixmap"); qt_meego_set_surface_fixed_size = (QMeeGoSetSurfaceFixedSizeFunc) library.resolve("qt_meego_set_surface_fixed_size"); qt_meego_set_surface_scaling = (QMeeGoSetSurfaceScalingFunc) library.resolve("qt_meego_set_surface_scaling"); qt_meego_set_translucent = (QMeeGoSetTranslucentFunc) library.resolve("qt_meego_set_translucent"); - qt_meego_live_texture_create = (QMeeGoLiveTextureCreateFunc) library.resolve("qt_meego_live_texture_create"); + qt_meego_pixmapdata_with_new_live_texture = (QMeeGoPixmapDataWithNewLiveTextureFunc) library.resolve("qt_meego_pixmapdata_with_new_live_texture"); + qt_meego_pixmapdata_from_live_texture_handle = (QMeeGoPixmapDataFromLiveTextureHandleFunc) library.resolve("qt_meego_pixmapdata_from_live_texture_handle"); qt_meego_live_texture_lock = (QMeeGoLiveTextureLockFunc) library.resolve("qt_meego_live_texture_lock"); - qt_meego_live_texture_unlock = (QMeeGoLiveTextureUnlockFunc) library.resolve("qt_meego_live_texture_unlock"); - qt_meego_live_texture_destroy = (QMeeGoLiveTextureDestroyFunc) library.resolve("qt_meego_live_texture_destroy"); - qt_meego_live_texture_query = (QMeeGoLiveTextureQueryFunc) library.resolve("qt_meego_live_texture_query"); - qt_meego_live_texture_to_egl_image = (QMeeGoLiveTextureToEglImageFunc) library.resolve("qt_meego_live_texture_to_egl_image"); + 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"); - if (qt_meego_image_to_egl_shared_image && qt_meego_pixmapdata_from_egl_shared_image && qt_meego_pixmapdata_from_egl_image && + 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_live_texture_create && qt_meego_live_texture_lock && qt_meego_live_texture_unlock && - qt_meego_live_texture_destroy && qt_meego_live_texture_query && qt_meego_live_texture_to_egl_image) + 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) { qDebug("Successfully resolved MeeGo graphics system: %s %s\n", qPrintable(libraryPrivate->fileName), qPrintable(libraryPrivate->fullVersion)); + } else { + Q_ASSERT(false); } } else { Q_ASSERT(false); @@ -139,13 +135,6 @@ QPixmapData* QMeeGoRuntime::pixmapDataFromEGLSharedImage(Qt::HANDLE handle, cons return qt_meego_pixmapdata_from_egl_shared_image(handle, softImage); } -QPixmapData* QMeeGoRuntime::pixmapDataFromEGLImage(Qt::HANDLE handle) -{ - ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_pixmapdata_from_egl_image); - return qt_meego_pixmapdata_from_egl_image(handle); -} - QPixmapData* QMeeGoRuntime::pixmapDataWithGLTexture(int w, int h) { ENSURE_INITIALIZED; @@ -188,45 +177,37 @@ void QMeeGoRuntime::setTranslucent(bool translucent) qt_meego_set_translucent(translucent); } -Qt::HANDLE QMeeGoRuntime::createLiveTexture(int w, int h, QImage::Format format) -{ - ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_create); - return qt_meego_live_texture_create(w, h, format); -} - -bool QMeeGoRuntime::lockLiveTexture(Qt::HANDLE h) +QPixmapData* QMeeGoRuntime::pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format) { ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_lock); - return qt_meego_live_texture_lock(h); + Q_ASSERT(qt_meego_pixmapdata_with_new_live_texture); + return qt_meego_pixmapdata_with_new_live_texture(w, h, format); } -bool QMeeGoRuntime::unlockLiveTexture(Qt::HANDLE h) +QPixmapData* QMeeGoRuntime::pixmapDataFromLiveTextureHandle(Qt::HANDLE h) { ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_unlock); - return qt_meego_live_texture_unlock(h); + Q_ASSERT(qt_meego_pixmapdata_from_live_texture_handle); + return qt_meego_pixmapdata_from_live_texture_handle(h); } -void QMeeGoRuntime::destroyLiveTexture(Qt::HANDLE h) +QImage* QMeeGoRuntime::lockLiveTexture(QPixmap *p) { ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_destroy); - qt_meego_live_texture_destroy(h); + Q_ASSERT(qt_meego_live_texture_lock); + return qt_meego_live_texture_lock(p); } -void QMeeGoRuntime::queryLiveTexture(Qt::HANDLE h, void **data, int *pitch, QImage::Format *format) +bool QMeeGoRuntime::releaseLiveTexture(QPixmap *p, QImage *i) { ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_query); - qt_meego_live_texture_query(h, data, pitch, format); + Q_ASSERT(qt_meego_live_texture_release); + return qt_meego_live_texture_release(p, i); } -Qt::HANDLE QMeeGoRuntime::liveTextureToEGLImage(Qt::HANDLE handle) +Qt::HANDLE QMeeGoRuntime::getLiveTextureHandle(QPixmap *pixmap) { ENSURE_INITIALIZED; - Q_ASSERT(qt_meego_live_texture_to_egl_image); - return qt_meego_live_texture_to_egl_image(handle); + Q_ASSERT(qt_meego_live_texture_get_handle); + return qt_meego_live_texture_get_handle(pixmap); } - diff --git a/tools/qmeegographicssystemhelper/qmeegoruntime.h b/tools/qmeegographicssystemhelper/qmeegoruntime.h index 9f2d505..6b34836 100644 --- a/tools/qmeegographicssystemhelper/qmeegoruntime.h +++ b/tools/qmeegographicssystemhelper/qmeegoruntime.h @@ -49,19 +49,17 @@ public: static Qt::HANDLE imageToEGLSharedImage(const QImage &image); static QPixmapData* pixmapDataFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage); - static QPixmapData* pixmapDataFromEGLImage(Qt::HANDLE handle); static QPixmapData* pixmapDataWithGLTexture(int w, int h); static bool destroyEGLSharedImage(Qt::HANDLE handle); static void updateEGLSharedImagePixmap(QPixmap *p); static void setSurfaceFixedSize(int w, int h); static void setSurfaceScaling(int x, int y, int w, int h); static void setTranslucent(bool translucent); - static Qt::HANDLE createLiveTexture(int w, int h, QImage::Format format); - static bool lockLiveTexture(Qt::HANDLE h); - static bool unlockLiveTexture(Qt::HANDLE h); - static void destroyLiveTexture(Qt::HANDLE h); - static void queryLiveTexture(Qt::HANDLE h, void **data, int *pitch, QImage::Format *format); - static Qt::HANDLE liveTextureToEGLImage(Qt::HANDLE); + static QPixmapData* pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format); + static QPixmapData* pixmapDataFromLiveTextureHandle(Qt::HANDLE h); + static QImage* lockLiveTexture(QPixmap *pixmap); + static bool releaseLiveTexture(QPixmap *pixmap, QImage *image); + static Qt::HANDLE getLiveTextureHandle(QPixmap *pixmap); private: static bool initialized; |