summaryrefslogtreecommitdiffstats
path: root/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp')
-rw-r--r--src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp
index 84fc593..5473d09 100644
--- a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp
+++ b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp
@@ -51,6 +51,24 @@ static EGLint preserved_image_attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, E
QHash <void*, QMeeGoImageInfo*> QMeeGoPixmapData::sharedImagesMap;
+// This helper method converts (in place) a QImage::Format_ARGB4444_Premultiplied to
+// GL-friendly Format_RGBA4444_Premultiplied. Just swaps the bits around really.
+static void qARGBA4ToRGBA4(QImage *image)
+{
+ unsigned char *raw = static_cast <unsigned char *> (image->data_ptr()->data);
+ // FIXME image.bytesPerLine() is broken. Returns 512 for 128x128 image while it should
+ // return 256
+ int bytesPerLine = image->width() * 2;
+
+ for (int y = 0; y < image->height(); y++) {
+ for (int x = 0; x < image->width(); x++) {
+ unsigned short *target = (unsigned short *) (raw + (y * bytesPerLine + (x * 2)));
+ // FIXME Oh yeah, that's broken with endianness.
+ *target = (*target << 4) | (* target >> 12);
+ }
+ }
+}
+
/* Public */
QMeeGoPixmapData::QMeeGoPixmapData() : QGLPixmapData(QPixmapData::PixmapType)
@@ -108,8 +126,6 @@ void QMeeGoPixmapData::fromEGLImage(Qt::HANDLE handle)
QMeeGoExtensions::eglQueryImageNOK(QEgl::display(), (EGLImageKHR) handle, EGL_HEIGHT, &newHeight);
if (textureIsBound) {
- // FIXME Remove this ugly hasAlphaChannel check when Qt lands the NoOpaqueCheck flag fix
- // for QGLPixmapData.
fromTexture(newTextureId, newWidth, newHeight, true);
} else {
qWarning("Failed to create a texture from an egl image!");
@@ -152,10 +168,9 @@ void QMeeGoPixmapData::fromEGLSharedImage(Qt::HANDLE handle, const QImage &si)
}
if (textureIsBound) {
- // FIXME Remove this ugly hasAlphaChannel check when Qt lands the NoOpaqueCheck flag fix
- // for QGLPixmapData.
fromTexture(newTextureId, newWidth, newHeight,
(si.hasAlphaChannel() && const_cast<QImage &>(si).data_ptr()->checkForAlphaPixels()));
+ texture()->options &= ~QGLContext::InvertedYBindOption;
softImage = si;
QMeeGoPixmapData::registerSharedImage(handle, softImage);
} else {
@@ -171,15 +186,31 @@ Qt::HANDLE QMeeGoPixmapData::imageToEGLSharedImage(const QImage &image)
QMeeGoExtensions::ensureInitialized();
glFinish();
- QGLPixmapData pixmapData(QPixmapData::PixmapType);
- pixmapData.fromImage(image, 0);
- GLuint textureId = pixmapData.bind();
+
+ GLuint textureId;
+
+ glGenTextures(1, &textureId);
+ glBindTexture(GL_TEXTURE_2D, textureId);
+ if (image.hasAlphaChannel() && (image.hasAlphaChannel() && const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels())) {
+ QImage convertedImage = image.convertToFormat(QImage::Format_ARGB4444_Premultiplied, Qt::DiffuseAlphaDither | Qt::DiffuseDither | Qt::PreferDither);
+ qARGBA4ToRGBA4(&convertedImage);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, convertedImage.bits());
+ } else {
+ QImage convertedImage = image.convertToFormat(QImage::Format_RGB16, Qt::DiffuseAlphaDither | Qt::DiffuseDither | Qt::PreferDither);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, convertedImage.bits());
+ }
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFinish();
+
+ glBindTexture(GL_TEXTURE_2D, textureId);
EGLImageKHR eglimage = QEgl::eglCreateImageKHR(QEgl::display(), QEglContext::currentContext(QEgl::OpenGL)->context(),
EGL_GL_TEXTURE_2D_KHR,
(EGLClientBuffer) textureId,
preserved_image_attribs);
+ glDeleteTextures(1, &textureId);
glFinish();
if (eglimage) {
@@ -195,6 +226,7 @@ Qt::HANDLE QMeeGoPixmapData::imageToEGLSharedImage(const QImage &image)
void QMeeGoPixmapData::updateFromSoftImage()
{
+ // FIXME That's broken with recent 16bit textures changes.
m_dirty = true;
m_source = softImage;
ensureCreated();