diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-09-23 06:31:23 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-09-23 13:10:41 (GMT) |
commit | 7dcf984f85a3a75ce4c078cc931bd9d2304bc235 (patch) | |
tree | d18699427b8ffe5843e82c3057c70b9db53d136d /src/openvg | |
parent | 48d0f84958fdc2dcffab75f33842a9dbc3d4d7b1 (diff) | |
download | Qt-7dcf984f85a3a75ce4c078cc931bd9d2304bc235.zip Qt-7dcf984f85a3a75ce4c078cc931bd9d2304bc235.tar.gz Qt-7dcf984f85a3a75ce4c078cc931bd9d2304bc235.tar.bz2 |
Modify functions for native pixmap data conversion on Symbian.
We need a way to support converion to and from multiple native pixmap
types from multiple pixmap backends. Instead of adding more virtual
functions to QPixmapData, make the existing one more generic but pass
an opaque pointer and a type and do some internal casting.
Currently this function is Symbian only, but could easily be extended
to work on other platforms.
Reviewed-by: Aleksandar Babic
Reviewed-by: Jani Hautakangas
Diffstat (limited to 'src/openvg')
-rw-r--r-- | src/openvg/qpixmapdata_vg.cpp | 266 | ||||
-rw-r--r-- | src/openvg/qpixmapdata_vg_p.h | 4 |
2 files changed, 141 insertions, 129 deletions
diff --git a/src/openvg/qpixmapdata_vg.cpp b/src/openvg/qpixmapdata_vg.cpp index 53975d7..38a89e6 100644 --- a/src/openvg/qpixmapdata_vg.cpp +++ b/src/openvg/qpixmapdata_vg.cpp @@ -381,167 +381,179 @@ void QVGPixmapData::cleanup() source = QImage(); } -void QVGPixmapData::fromRSgImage(RSgImage* sgImage) +void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) { - Q_UNUSED(sgImage); #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) - // when "0" used as argument then - // default display, context are used - if (!context) - context = qt_vg_create_context(0); + if (type == QPixmapData::SgImage && pixmap) { + RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); + // when "0" used as argument then + // default display, context are used + if (!context) + context = qt_vg_create_context(0); - if (vgImage != VG_INVALID_HANDLE) { - vgDestroyImage(vgImage); - vgImage = VG_INVALID_HANDLE; - } - if (vgImageOpacity != VG_INVALID_HANDLE) { - vgDestroyImage(vgImageOpacity); - vgImageOpacity = VG_INVALID_HANDLE; - } + if (vgImage != VG_INVALID_HANDLE) { + vgDestroyImage(vgImage); + vgImage = VG_INVALID_HANDLE; + } + if (vgImageOpacity != VG_INVALID_HANDLE) { + vgDestroyImage(vgImageOpacity); + vgImageOpacity = VG_INVALID_HANDLE; + } - TInt err = 0; + TInt err = 0; - err = SgDriver::Open(); - if(err != KErrNone) { - cleanup(); - return; - } + err = SgDriver::Open(); + if(err != KErrNone) { + cleanup(); + return; + } - if(sgImage->IsNull()) { - cleanup(); - SgDriver::Close(); - return; - } + if(sgImage->IsNull()) { + cleanup(); + SgDriver::Close(); + return; + } - TSgImageInfo sgImageInfo; - err = sgImage->GetInfo(sgImageInfo); - if(err != KErrNone) { - cleanup(); - SgDriver::Close(); - return; - } + TSgImageInfo sgImageInfo; + err = sgImage->GetInfo(sgImageInfo); + if(err != KErrNone) { + cleanup(); + SgDriver::Close(); + return; + } - pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); - pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); - pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); + pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); + pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); + pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); - if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { - cleanup(); - SgDriver::Close(); - return; - } + if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { + cleanup(); + SgDriver::Close(); + return; + } - const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; - EGLImageKHR eglImage = eglCreateImageKHR(context->display(), - EGL_NO_CONTEXT, - EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer)sgImage, - (EGLint*)KEglImageAttribs); + const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; + EGLImageKHR eglImage = eglCreateImageKHR(context->display(), + EGL_NO_CONTEXT, + EGL_NATIVE_PIXMAP_KHR, + (EGLClientBuffer)sgImage, + (EGLint*)KEglImageAttribs); + + if(eglGetError() != EGL_SUCCESS) { + cleanup(); + SgDriver::Close(); + return; + } - if(eglGetError() != EGL_SUCCESS) { - cleanup(); - SgDriver::Close(); - return; - } + vgImage = vgCreateEGLImageTargetKHR(eglImage); + if(vgGetError() != VG_NO_ERROR) { + cleanup(); + eglDestroyImageKHR(context->display(), eglImage); + SgDriver::Close(); + return; + } - vgImage = vgCreateEGLImageTargetKHR(eglImage); - if(vgGetError() != VG_NO_ERROR) { - cleanup(); + w = sgImageInfo.iSizeInPixels.iWidth; + h = sgImageInfo.iSizeInPixels.iHeight; + d = 32; // We always use ARGB_Premultiplied for VG pixmaps. + is_null = (w <= 0 || h <= 0); + source = QImage(); + recreate = false; + setSerialNumber(++qt_vg_pixmap_serial); + // release stuff eglDestroyImageKHR(context->display(), eglImage); SgDriver::Close(); - return; - } + } else if (type == QPixmapData::FbsBitmap) { - w = sgImageInfo.iSizeInPixels.iWidth; - h = sgImageInfo.iSizeInPixels.iHeight; - d = 32; // We always use ARGB_Premultiplied for VG pixmaps. - is_null = (w <= 0 || h <= 0); - source = QImage(); - recreate = false; - setSerialNumber(++qt_vg_pixmap_serial); - // release stuff - eglDestroyImageKHR(context->display(), eglImage); - SgDriver::Close(); + } #else + Q_UNUSED(pixmap); + Q_UNUSED(type); #endif } -RSgImage* QVGPixmapData::toRSgImage() +void* QVGPixmapData::toNativeType(NativeType type) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) - toVGImage(); - - if(!isValid() || vgImage == VG_INVALID_HANDLE) - return 0; - - TInt err = 0; + if (type == QPixmapData::SgImage) { + toVGImage(); + + if(!isValid() || vgImage == VG_INVALID_HANDLE) + return 0; + + TInt err = 0; + + err = SgDriver::Open(); + if(err != KErrNone) + return 0; + + TSgImageInfo sgInfo; + sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; + sgInfo.iSizeInPixels.SetSize(w, h); + sgInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget; + sgInfo.iShareable = ETrue; + sgInfo.iCpuAccess = ESgCpuAccessNone; + sgInfo.iScreenId = KSgScreenIdMain; //KSgScreenIdAny; + sgInfo.iUserAttributes = NULL; + sgInfo.iUserAttributeCount = 0; + + RSgImage *sgImage = q_check_ptr(new RSgImage()); + err = sgImage->Create(sgInfo, NULL, NULL); + if(err != KErrNone) { + SgDriver::Close(); + return 0; + } - err = SgDriver::Open(); - if(err != KErrNone) - return 0; + pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); + pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); + pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); - TSgImageInfo sgInfo; - sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; - sgInfo.iSizeInPixels.SetSize(w, h); - sgInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget; - sgInfo.iShareable = ETrue; - sgInfo.iCpuAccess = ESgCpuAccessNone; - sgInfo.iScreenId = KSgScreenIdMain; //KSgScreenIdAny; - sgInfo.iUserAttributes = NULL; - sgInfo.iUserAttributeCount = 0; - - RSgImage *sgImage = q_check_ptr(new RSgImage()); - err = sgImage->Create(sgInfo, NULL, NULL); - if(err != KErrNone) { - SgDriver::Close(); - return 0; - } + if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { + SgDriver::Close(); + return 0; + } - pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); - pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); - pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); + const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; + EGLImageKHR eglImage = eglCreateImageKHR(context->display(), + EGL_NO_CONTEXT, + EGL_NATIVE_PIXMAP_KHR, + (EGLClientBuffer)sgImage, + (EGLint*)KEglImageAttribs); + if(eglGetError() != EGL_SUCCESS) { + sgImage->Close(); + SgDriver::Close(); + return 0; + } - if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { - SgDriver::Close(); - return 0; - } + VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); + if(vgGetError() != VG_NO_ERROR) { + eglDestroyImageKHR(context->display(), eglImage); + sgImage->Close(); + SgDriver::Close(); + return 0; + } - const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; - EGLImageKHR eglImage = eglCreateImageKHR(context->display(), - EGL_NO_CONTEXT, - EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer)sgImage, - (EGLint*)KEglImageAttribs); - if(eglGetError() != EGL_SUCCESS) { - sgImage->Close(); - SgDriver::Close(); - return 0; - } + vgCopyImage(dstVgImage, 0, 0, + vgImage, 0, 0, + w, h, VG_FALSE); - VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); - if(vgGetError() != VG_NO_ERROR) { + if(vgGetError() != VG_NO_ERROR) { + sgImage->Close(); + sgImage = 0; + } + // release stuff + vgDestroyImage(dstVgImage); eglDestroyImageKHR(context->display(), eglImage); - sgImage->Close(); SgDriver::Close(); + return reinterpret_cast<void*>(sgImage); + } else if (type == QPixmapData::FbsBitmap) { return 0; } - - vgCopyImage(dstVgImage, 0, 0, - vgImage, 0, 0, - w, h, VG_FALSE); - - if(vgGetError() != VG_NO_ERROR) { - sgImage->Close(); - sgImage = 0; - } - // release stuff - vgDestroyImage(dstVgImage); - eglDestroyImageKHR(context->display(), eglImage); - SgDriver::Close(); - return sgImage; #else + Q_UNUSED(type); return 0; #endif } #endif //Q_OS_SYMBIAN + QT_END_NAMESPACE diff --git a/src/openvg/qpixmapdata_vg_p.h b/src/openvg/qpixmapdata_vg_p.h index 122f596..99115df 100644 --- a/src/openvg/qpixmapdata_vg_p.h +++ b/src/openvg/qpixmapdata_vg_p.h @@ -95,8 +95,8 @@ public: QSize size() const { return QSize(w, h); } #if defined(Q_OS_SYMBIAN) - RSgImage* toRSgImage(); - void fromRSgImage(RSgImage* sgImage); + void* toNativeType(NativeType type); + void fromNativeType(void* pixmap, NativeType type); #endif protected: |