VGImage QVGPixmapData::toVGImage() { if (!isValid() || failedToAlloc) return VG_INVALID_HANDLE; #if !defined(QT_NO_EGL) // Increase the reference count on the shared context. if (!context) context = qt_vg_create_context(0, QInternal::Pixmap); #endif if (recreate && prevSize != QSize(w, h)) destroyImages(); else if (recreate) cachedOpacity = -1.0f; // Force opacity image to be refreshed later. #if defined(Q_OS_SYMBIAN) if (recreate && nativeImageHandleProvider && !nativeImageHandle) { createFromNativeImageHandleProvider(); } #endif if (vgImage == VG_INVALID_HANDLE) { vgImage = QVGImagePool::instance()->createImageForPixmap (qt_vg_image_to_vg_format(source.format()), w, h, VG_IMAGE_QUALITY_FASTER, this); // Bail out if we run out of GPU memory - try again next time. if (vgImage == VG_INVALID_HANDLE) { failedToAlloc = true; return VG_INVALID_HANDLE; } inImagePool = true; } else if (inImagePool) { QVGImagePool::instance()->useImage(this); } if (!source.isNull() && recreate) { source.beginDataAccess(); vgImageSubData (vgImage, source.constBits(), source.bytesPerLine(), qt_vg_image_to_vg_format(source.format()), 0, 0, w, h); source.endDataAccess(true); } recreate = false; prevSize = QSize(w, h); return vgImage; }
void QVGPixmapData::ensureReadback(bool readOnly) const { if (vgImage != VG_INVALID_HANDLE && source.isNull()) { source = QVolatileImage(w, h, sourceFormat()); source.beginDataAccess(); vgGetImageSubData(vgImage, source.bits(), source.bytesPerLine(), qt_vg_image_to_vg_format(source.format()), 0, 0, w, h); source.endDataAccess(); if (readOnly) { recreate = false; } else { // Once we did a readback, the original VGImage must be destroyed // because it may be shared (e.g. created via SgImage) and a subsequent // upload of the image data may produce unexpected results. const_cast<QVGPixmapData *>(this)->destroyImages(); #if defined(Q_OS_SYMBIAN) // There is now an own copy of the data so drop the handle provider, // otherwise toVGImage() would request the handle again, which is wrong. nativeImageHandleProvider = 0; #endif recreate = true; } } }
QT_BEGIN_NAMESPACE // Turn off "direct to window" rendering if EGL cannot support it. #if !defined(EGL_RENDER_BUFFER) || !defined(EGL_SINGLE_BUFFER) #if defined(QVG_DIRECT_TO_WINDOW) #undef QVG_DIRECT_TO_WINDOW #endif #endif // Determine if preserved window contents should be used. #if !defined(EGL_SWAP_BEHAVIOR) || !defined(EGL_BUFFER_PRESERVED) #if !defined(QVG_NO_PRESERVED_SWAP) #define QVG_NO_PRESERVED_SWAP 1 #endif #endif VGImageFormat qt_vg_config_to_vg_format(QEglContext *context) { return qt_vg_image_to_vg_format (qt_vg_config_to_image_format(context)); }