diff options
author | A-Team <ateam@pad.test.qt.nokia.com> | 2010-10-22 22:00:11 (GMT) |
---|---|---|
committer | A-Team <ateam@pad.test.qt.nokia.com> | 2010-10-22 22:00:11 (GMT) |
commit | 0787890a9a06a0f05c78c7e4d85655fdc1fc9398 (patch) | |
tree | 824906aa3899243d46e2590a86ccd114259712a5 /src/plugins/graphicssystems/meego/qmeegographicssystem.cpp | |
parent | 215f46d0a61a2f48d1ccbbc52c3b161fa36c84ec (diff) | |
parent | db14623485396fd69839e519184b794775b65b01 (diff) | |
download | Qt-0787890a9a06a0f05c78c7e4d85655fdc1fc9398.zip Qt-0787890a9a06a0f05c78c7e4d85655fdc1fc9398.tar.gz Qt-0787890a9a06a0f05c78c7e4d85655fdc1fc9398.tar.bz2 |
Merge branch '4.7-upstream' into 4.7-doc
Diffstat (limited to 'src/plugins/graphicssystems/meego/qmeegographicssystem.cpp')
-rw-r--r-- | src/plugins/graphicssystems/meego/qmeegographicssystem.cpp | 218 |
1 files changed, 31 insertions, 187 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp index 772db44..96fbd6c 100644 --- a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp +++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp @@ -54,6 +54,7 @@ #include <private/qpixmap_x11_p.h> #include "qmeegopixmapdata.h" +#include "qmeegolivepixmapdata.h" #include "qmeegographicssystem.h" #include "qmeegoextensions.h" @@ -174,22 +175,6 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(Qt::HANDLE handl } } -QPixmapData *QMeeGoGraphicsSystem::pixmapDataFromEGLImage(Qt::HANDLE handle) -{ - if (QMeeGoGraphicsSystem::meeGoRunning()) { - QMeeGoPixmapData *pmd = new QMeeGoPixmapData; - pmd->fromEGLImage(handle); - - // FIXME Ok. This is a bit BAD BAD BAD. We're abusing here the fact that we KNOW - // that this function is used for the live pixmap... - pmd->texture()->options &= ~QGLContext::InvertedYBindOption; - return QMeeGoGraphicsSystem::wrapPixmapData(pmd); - } else { - qFatal("Can't create from EGL image when not running meego graphics system!"); - return NULL; - } -} - void QMeeGoGraphicsSystem::updateEGLSharedImagePixmap(QPixmap *pixmap) { QMeeGoPixmapData *pmd = (QMeeGoPixmapData *) pixmap->pixmapData(); @@ -208,117 +193,6 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataWithGLTexture(int w, int h) return QMeeGoGraphicsSystem::wrapPixmapData(pmd); } -Qt::HANDLE QMeeGoGraphicsSystem::createLiveTexture(int w, int h, QImage::Format format) -{ - // No need to wrap the QPixmapData here. This QPixmap(Data) is a - // internal implementation and we don't migrate it between - // graphics system switching. - - // We use a bit ugly way of enforcing a color format on the X pixmap -- we create - // a local QImage and fromImage from there. This is quite redundant (extra overhead of creating - // the useless image only to delete it) but shouldn't be too bad for now... you're not expected - // to call createLiveTexture too often anyways. Would be great if QX11PixmapData had a way to - // force the X format upon creation or resize. - - QImage image(w, h, format); - QX11PixmapData *pmd = new QX11PixmapData(QPixmapData::PixmapType); - pmd->fromImage(image, Qt::NoOpaqueDetection); - QPixmap *p = new QPixmap(pmd); - - liveTexturePixmaps.insert(p->handle(), p); - return p->handle(); -} - -void QMeeGoGraphicsSystem::destroyLiveTexture(Qt::HANDLE h) -{ - if (liveTexturePixmaps.contains(h)) { - QPixmap *p = liveTexturePixmaps.value(h); - delete p; - liveTexturePixmaps.remove(h); - } else - qWarning("Trying to destroy live texture %ld which was not found!", h); -} - -bool QMeeGoGraphicsSystem::lockLiveTexture(Qt::HANDLE h) -{ - if (! liveTexturePixmaps.contains(h)) { - qWarning("Trying to lock live texture %ld which was not found!", h); - return false; - } - - EGLint attribs[] = { - EGL_MAP_PRESERVE_PIXELS_KHR, EGL_TRUE, - EGL_LOCK_USAGE_HINT_KHR, EGL_READ_SURFACE_BIT_KHR | EGL_WRITE_SURFACE_BIT_KHR, - EGL_NONE - }; - - QGLShareContextScope ctx(qt_gl_share_widget()->context()); - EGLSurface surface = getSurfaceForLiveTexturePixmap(liveTexturePixmaps.value(h)); - return QMeeGoExtensions::eglLockSurfaceKHR(QEgl::display(), surface, attribs); -} - -bool QMeeGoGraphicsSystem::unlockLiveTexture(Qt::HANDLE h) -{ - if (! liveTexturePixmaps.contains(h)) { - qWarning("Trying to lock live texture %ld which was not found!", h); - return false; - } - - QGLShareContextScope ctx(qt_gl_share_widget()->context()); - QMeeGoExtensions::ensureInitialized(); - - EGLSurface surface = getSurfaceForLiveTexturePixmap(liveTexturePixmaps.value(h)); - if (QMeeGoExtensions::eglUnlockSurfaceKHR(QEgl::display(), surface)) { - glFinish(); - return true; - } else { - return false; - } -} - -void QMeeGoGraphicsSystem::queryLiveTexture(Qt::HANDLE h, void **data, int *pitch, QImage::Format *f) -{ - // FIXME Only allow this on locked surfaces - if (! liveTexturePixmaps.contains(h)) { - qWarning("Trying to query live texture %ld which was not found!", h); - return; - } - - QGLShareContextScope ctx(qt_gl_share_widget()->context()); - QMeeGoExtensions::ensureInitialized(); - - EGLSurface surface = getSurfaceForLiveTexturePixmap(liveTexturePixmaps.value(h)); - eglQuerySurface(QEgl::display(), surface, EGL_BITMAP_POINTER_KHR, (EGLint*) data); - eglQuerySurface(QEgl::display(), surface, EGL_BITMAP_PITCH_KHR, (EGLint*) pitch); - - // Ok, here we know we just support those two formats. Real solution would be: - // in liveTexturePixmaps store a small structure containing the pixmap and the - // original Qt format. - if (liveTexturePixmaps.value(h)->depth() > 16) - *f = QImage::Format_ARGB32_Premultiplied; - else - *f = QImage::Format_RGB16; -} - -Qt::HANDLE QMeeGoGraphicsSystem::liveTextureToEGLImage(Qt::HANDLE h) -{ - QGLShareContextScope ctx(qt_gl_share_widget()->context()); - QMeeGoExtensions::ensureInitialized(); - - EGLint attribs[] = { - EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, - EGL_NONE - }; - - EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer) h, attribs); - - if (eglImage == EGL_NO_IMAGE_KHR) - qWarning("eglCreateImageKHR failed!"); - - return (Qt::HANDLE) eglImage; -} - bool QMeeGoGraphicsSystem::meeGoRunning() { if (! QApplicationPrivate::instance()) { @@ -335,52 +209,32 @@ bool QMeeGoGraphicsSystem::meeGoRunning() return (name == "meego"); } -void QMeeGoGraphicsSystem::destroySurfaceForLiveTexturePixmap(QPixmapData* pmd) +QPixmapData* QMeeGoGraphicsSystem::pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format) { - Q_ASSERT(pmd->classId() == QPixmapData::X11Class); - QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd); - if (pixmapData->gl_surface) { - eglDestroySurface(QEgl::display(), (EGLSurface)pixmapData->gl_surface); - pixmapData->gl_surface = 0; - } + return new QMeeGoLivePixmapData(w, h, format); } -EGLSurface QMeeGoGraphicsSystem::getSurfaceForLiveTexturePixmap(QPixmap *pixmap) +QPixmapData* QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(Qt::HANDLE handle) { - // This code is a crative remix of the stuff that can be found in the - // Qt's TFP implementation in /src/opengl/qgl_x11egl.cpp ::bindiTextureFromNativePixmap - QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pixmap->data_ptr().data()); - Q_ASSERT(pixmapData->classId() == QPixmapData::X11Class); - bool hasAlpha = pixmapData->hasAlphaChannel(); - - if (pixmapData->gl_surface && - hasAlpha == (pixmapData->flags & QX11PixmapData::GlSurfaceCreatedWithAlpha)) - return pixmapData->gl_surface; - - // Check to see if the surface is still valid - if (pixmapData->gl_surface && - hasAlpha != ((pixmapData->flags & QX11PixmapData::GlSurfaceCreatedWithAlpha) > 0)) { - // Surface is invalid! - QMeeGoGraphicsSystem::destroySurfaceForLiveTexturePixmap(pixmapData); - } + return new QMeeGoLivePixmapData(handle); +} - if (pixmapData->gl_surface == 0) { - EGLConfig config = QEgl::defaultConfig(QInternal::Pixmap, - QEgl::OpenGL, - hasAlpha ? QEgl::Translucent : QEgl::NoOptions); +QImage* QMeeGoGraphicsSystem::lockLiveTexture(QPixmap* pixmap) +{ + QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data()); + return pixmapData->lock(); +} - pixmapData->gl_surface = (void*)QEgl::createSurface(pixmap, config); - - if (hasAlpha) - pixmapData->flags |= QX11PixmapData::GlSurfaceCreatedWithAlpha; - else - pixmapData->flags &= ~QX11PixmapData::GlSurfaceCreatedWithAlpha; - - if (pixmapData->gl_surface == (void*)EGL_NO_SURFACE) - return NULL; - } +bool QMeeGoGraphicsSystem::releaseLiveTexture(QPixmap *pixmap, QImage *image) +{ + QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data()); + return pixmapData->release(image); +} - return pixmapData->gl_surface; +Qt::HANDLE QMeeGoGraphicsSystem::getLiveTextureHandle(QPixmap *pixmap) +{ + QMeeGoLivePixmapData *pixmapData = static_cast<QMeeGoLivePixmapData*>(pixmap->data_ptr().data()); + return pixmapData->handle(); } /* C API */ @@ -395,11 +249,6 @@ QPixmapData* qt_meego_pixmapdata_from_egl_shared_image(Qt::HANDLE handle, const return QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(handle, softImage); } -QPixmapData* qt_meego_pixmapdata_from_egl_image(Qt::HANDLE handle) -{ - return QMeeGoGraphicsSystem::pixmapDataFromEGLImage(handle); -} - QPixmapData* qt_meego_pixmapdata_with_gl_texture(int w, int h) { return QMeeGoGraphicsSystem::pixmapDataWithGLTexture(w, h); @@ -430,32 +279,27 @@ void qt_meego_update_egl_shared_image_pixmap(QPixmap *pixmap) QMeeGoGraphicsSystem::updateEGLSharedImagePixmap(pixmap); } -Qt::HANDLE qt_meego_live_texture_create(int w, int h, QImage::Format format) +QPixmapData* qt_meego_pixmapdata_with_new_live_texture(int w, int h, QImage::Format format) { - return QMeeGoGraphicsSystem::createLiveTexture(w, h, format); + return QMeeGoGraphicsSystem::pixmapDataWithNewLiveTexture(w, h, format); } -void qt_meego_live_texture_destroy(Qt::HANDLE h) +QPixmapData* qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle) { - QMeeGoGraphicsSystem::destroyLiveTexture(h); + return QMeeGoGraphicsSystem::pixmapDataFromLiveTextureHandle(handle); } -bool qt_meego_live_texture_lock(Qt::HANDLE h) +QImage* qt_meego_live_texture_lock(QPixmap *pixmap) { - return QMeeGoGraphicsSystem::lockLiveTexture(h); + return QMeeGoGraphicsSystem::lockLiveTexture(pixmap); } -bool qt_meego_live_texture_unlock(Qt::HANDLE h) +bool qt_meego_live_texture_release(QPixmap *pixmap, QImage *image) { - return QMeeGoGraphicsSystem::unlockLiveTexture(h); + return QMeeGoGraphicsSystem::releaseLiveTexture(pixmap, image); } -void qt_meego_live_texture_query(Qt::HANDLE h, void **data, int *pitch, QImage::Format *f) +Qt::HANDLE qt_meego_live_texture_get_handle(QPixmap *pixmap) { - return QMeeGoGraphicsSystem::queryLiveTexture(h, data, pitch, f); -} - -Qt::HANDLE qt_meego_live_texture_to_egl_image(Qt::HANDLE h) -{ - return QMeeGoGraphicsSystem::liveTextureToEGLImage(h); -} + return QMeeGoGraphicsSystem::getLiveTextureHandle(pixmap); +}
\ No newline at end of file |