diff --git a/src/gui/kernel/qwidget_qpa.cpp b/src/gui/kernel/qwidget_qpa.cpp index 001810e0f4..960073c054 100644 --- a/src/gui/kernel/qwidget_qpa.cpp +++ b/src/gui/kernel/qwidget_qpa.cpp @@ -731,12 +731,19 @@ QPlatformWindowFormat QWidget::platformWindowFormat() const { Q_D(const QWidget); + QPlatformWindowFormat format; + QTLWExtra *extra = d->maybeTopData(); if (extra){ - return extra->platformWindowFormat; + format = extra->platformWindowFormat; } else { - return QPlatformWindowFormat::defaultFormat(); + format = QPlatformWindowFormat::defaultFormat(); } + + if (testAttribute(Qt::WA_TranslucentBackground)) + format.setAlpha(true); + + return format; } void QWidgetPrivate::createSysExtra() diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index 994344c6eb..9da650f98d 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -150,6 +150,8 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) if (shareContext) { winFormat.setSharedContext(shareContext->d_func()->platformContext); } + if (widget->testAttribute(Qt::WA_TranslucentBackground)) + winFormat.setAlpha(true); winFormat.setWindowApi(QPlatformWindowFormat::OpenGL); winFormat.setWindowSurface(false); widget->setPlatformWindowFormat(winFormat); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 49b3dc2dae..ff5744678d 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -542,19 +542,27 @@ void QGLWindowSurface::beginPaint(const QRegion &) d_ptr->did_paint = true; updateGeometry(); - if (!context()) - return; - int clearFlags = 0; - if (context()->d_func()->workaround_needsFullClearOnEveryFrame) + QGLContext *ctx = reinterpret_cast(window()->d_func()->extraData()->glContext); + + if (!ctx) + return; + + if (ctx->d_func()->workaround_needsFullClearOnEveryFrame) clearFlags = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; - else if (context()->format().alpha()) + else if (ctx->format().alpha()) clearFlags = GL_COLOR_BUFFER_BIT; if (clearFlags) { + if (d_ptr->fbo) + d_ptr->fbo->bind(); + glClearColor(0.0, 0.0, 0.0, 0.0); glClear(clearFlags); + + if (d_ptr->fbo) + d_ptr->fbo->release(); } } diff --git a/src/plugins/platforms/glxconvenience/glxconvenience.pri b/src/plugins/platforms/glxconvenience/glxconvenience.pri index d6c992229e..b4d43a30b5 100644 --- a/src/plugins/platforms/glxconvenience/glxconvenience.pri +++ b/src/plugins/platforms/glxconvenience/glxconvenience.pri @@ -5,3 +5,11 @@ HEADERS += \ SOURCES += \ $$PWD/qglxconvenience.cpp + +CONFIG += xrender + +xrender { + LIBS += -lXrender +} else { + DEFINES += QT_NO_XRENDER +} diff --git a/src/plugins/platforms/glxconvenience/qglxconvenience.cpp b/src/plugins/platforms/glxconvenience/qglxconvenience.cpp index 7cee3e2ea1..eb0f6a6604 100644 --- a/src/plugins/platforms/glxconvenience/qglxconvenience.cpp +++ b/src/plugins/platforms/glxconvenience/qglxconvenience.cpp @@ -43,6 +43,10 @@ #include +#ifndef QT_NO_XRENDER +#include +#endif + enum { XFocusOut = FocusOut, XFocusIn = FocusIn, @@ -84,14 +88,15 @@ QVector qglx_buildSpec(const QPlatformWindowFormat &format, int drawableBit spec[i++] = GLX_ALPHA_SIZE; spec[i++] = (format.alphaBufferSize() == -1) ? 1 : format.alphaBufferSize(); } - spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); - spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); - spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + if (format.accum()) { + spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); - if (format.alpha()) { - spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + if (format.alpha()) { + spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + } } - } else { spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_COLOR_INDEX_BIT; //I'm really not sure if this works.... spec[i++] = GLX_BUFFER_SIZE; spec[i++] = 8; @@ -136,8 +141,17 @@ GLXFBConfig qglx_findConfig(Display *display, int screen , const QPlatformWindow if (reducedFormat.alpha()) { int alphaSize; glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize); - if (alphaSize > 0) - break; + if (alphaSize > 0) { + XVisualInfo *visual = glXGetVisualFromFBConfig(display, chosenConfig); +#if !defined(QT_NO_XRENDER) + XRenderPictFormat *pictFormat = XRenderFindVisualFormat(display, visual->visual); + if (pictFormat->direct.alphaMask > 0) + break; +#else + if (visual->depth == 32) + break; +#endif + } } else { break; // Just choose the first in the list if there's no alpha requested } diff --git a/src/plugins/platforms/minimal/qminimalintegration.cpp b/src/plugins/platforms/minimal/qminimalintegration.cpp index 3a545e4e5c..44a4eb6adc 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.cpp +++ b/src/plugins/platforms/minimal/qminimalintegration.cpp @@ -50,8 +50,8 @@ QMinimalIntegration::QMinimalIntegration() QMinimalScreen *mPrimaryScreen = new QMinimalScreen(); mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); - mPrimaryScreen->mDepth = 16; - mPrimaryScreen->mFormat = QImage::Format_RGB16; + mPrimaryScreen->mDepth = 32; + mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; mScreens.append(mPrimaryScreen); } diff --git a/src/plugins/platforms/minimal/qminimalintegration.h b/src/plugins/platforms/minimal/qminimalintegration.h index 5f93443b8c..993d364c1b 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.h +++ b/src/plugins/platforms/minimal/qminimalintegration.h @@ -51,7 +51,7 @@ class QMinimalScreen : public QPlatformScreen { public: QMinimalScreen() - : mDepth(16), mFormat(QImage::Format_RGB16) {} + : mDepth(32), mFormat(QImage::Format_ARGB32_Premultiplied) {} QRect geometry() const { return mGeometry; } int depth() const { return mDepth; } diff --git a/src/plugins/platforms/wayland/gl_integration/xcomposite_glx/qwaylandxcompositeglxcontext.cpp b/src/plugins/platforms/wayland/gl_integration/xcomposite_glx/qwaylandxcompositeglxcontext.cpp index caf51170a6..baf0fa3432 100644 --- a/src/plugins/platforms/wayland/gl_integration/xcomposite_glx/qwaylandxcompositeglxcontext.cpp +++ b/src/plugins/platforms/wayland/gl_integration/xcomposite_glx/qwaylandxcompositeglxcontext.cpp @@ -132,10 +132,12 @@ void QWaylandXCompositeGLXContext::geometryChanged() Colormap cmap = XCreateColormap(mGlxIntegration->xDisplay(),mGlxIntegration->rootWindow(),visualInfo->visual,AllocNone); XSetWindowAttributes a; + a.background_pixel = WhitePixel(mGlxIntegration->xDisplay(), mGlxIntegration->screen()); + a.border_pixel = BlackPixel(mGlxIntegration->xDisplay(), mGlxIntegration->screen()); a.colormap = cmap; mXWindow = XCreateWindow(mGlxIntegration->xDisplay(), mGlxIntegration->rootWindow(),0, 0, size.width(), size.height(), 0, visualInfo->depth, InputOutput, visualInfo->visual, - CWColormap, &a); + CWBackPixel|CWBorderPixel|CWColormap, &a); XCompositeRedirectWindow(mGlxIntegration->xDisplay(), mXWindow, CompositeRedirectManual); XMapWindow(mGlxIntegration->xDisplay(), mXWindow); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 0456638ab9..0dd29eb8b2 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -113,7 +113,8 @@ QXcbWindow::QXcbWindow(QWidget *tlw) #if defined(XCB_USE_GLX) || defined(XCB_USE_EGL) if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL - && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) + && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL) + || tlw->platformWindowFormat().alpha()) { #if defined(XCB_USE_GLX) XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), tlw->platformWindowFormat()); @@ -131,13 +132,17 @@ QXcbWindow::QXcbWindow(QWidget *tlw) visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount); #endif //XCB_USE_GLX if (visualInfo) { + m_depth = visualInfo->depth; + m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), m_screen->root(), visualInfo->visual, AllocNone); XSetWindowAttributes a; + a.background_pixel = WhitePixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber()); + a.border_pixel = BlackPixel(DISPLAY_FROM_XCB(this), m_screen->screenNumber()); a.colormap = cmap; m_window = XCreateWindow(DISPLAY_FROM_XCB(this), m_screen->root(), tlw->x(), tlw->y(), tlw->width(), tlw->height(), 0, visualInfo->depth, InputOutput, visualInfo->visual, - CWColormap, &a); + CWBackPixel|CWBorderPixel|CWColormap, &a); printf("created GL window: %d\n", m_window); } else { @@ -147,6 +152,8 @@ QXcbWindow::QXcbWindow(QWidget *tlw) #endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL) { m_window = xcb_generate_id(xcb_connection()); + m_depth = m_screen->screen()->root_depth; + m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; Q_XCB_CALL(xcb_create_window(xcb_connection(), XCB_COPY_FROM_PARENT, // depth -- same as root diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index e049837253..20b464061a 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -74,6 +75,8 @@ public: QPlatformGLContext *glContext() const; xcb_window_t window() const { return m_window; } + uint depth() const { return m_depth; } + QImage::Format format() const { return m_format; } void handleExposeEvent(const xcb_expose_event_t *event); void handleClientMessageEvent(const xcb_client_message_event_t *event); @@ -99,6 +102,9 @@ private: xcb_window_t m_window; QPlatformGLContext *m_context; + uint m_depth; + QImage::Format m_format; + xcb_sync_int64_t m_syncValue; xcb_sync_counter_t m_syncCounter; diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp index 718f09383c..88a54dc316 100644 --- a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp +++ b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp @@ -54,11 +54,12 @@ #include #include +#include class QXcbShmImage : public QXcbObject { public: - QXcbShmImage(QXcbScreen *connection, const QSize &size); + QXcbShmImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); ~QXcbShmImage() { destroy(); } QImage *image() { return &m_qimage; } @@ -81,7 +82,7 @@ private: QRegion m_dirty; }; -QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size) +QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) : QXcbObject(screen->connection()) , m_gc(0) , m_gc_window(0) @@ -91,7 +92,7 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size) size.width(), size.height(), XCB_IMAGE_FORMAT_Z_PIXMAP, - screen->depth(), + depth, 0, ~0, 0); @@ -111,7 +112,7 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size) if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1) qWarning() << "QXcbWindowSurface: Error while marking the shared memory segment to be destroyed"; - m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, screen->format()); + m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); } void QXcbShmImage::destroy() @@ -189,6 +190,16 @@ QPaintDevice *QXcbWindowSurface::paintDevice() void QXcbWindowSurface::beginPaint(const QRegion ®ion) { m_image->preparePaint(region); + + if (m_image->image()->hasAlphaChannel()) { + QPainter p(m_image->image()); + p.setCompositionMode(QPainter::CompositionMode_Source); + const QVector rects = region.rects(); + const QColor blank = Qt::transparent; + for (QVector::const_iterator it = rects.begin(); it != rects.end(); ++it) { + p.fillRect(*it, blank); + } + } } void QXcbWindowSurface::endPaint(const QRegion &) @@ -232,9 +243,10 @@ void QXcbWindowSurface::resize(const QSize &size) QWindowSurface::resize(size); QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWidget(window())); + QXcbWindow* win = static_cast(window()->platformWindow()); delete m_image; - m_image = new QXcbShmImage(screen, size); + m_image = new QXcbShmImage(screen, size, win->depth(), win->format()); Q_XCB_NOOP(connection()); m_syncingResize = true; diff --git a/src/plugins/platforms/xlib/qxlibintegration.cpp b/src/plugins/platforms/xlib/qxlibintegration.cpp index 78f907abd2..b0c8bc9560 100644 --- a/src/plugins/platforms/xlib/qxlibintegration.cpp +++ b/src/plugins/platforms/xlib/qxlibintegration.cpp @@ -150,7 +150,7 @@ bool QXlibIntegration::hasOpenGL() const { #if !defined(QT_NO_OPENGL) #if !defined(QT_OPENGL_ES_2) - QXlibScreen *screen = static_cast(mScreens.at(0)); + QXlibScreen *screen = static_cast(mScreens.at(0)); return glXQueryExtension(screen->display()->nativeDisplay(), 0, 0) != 0; #else static bool eglHasbeenInitialized = false; diff --git a/src/plugins/platforms/xlib/qxlibscreen.cpp b/src/plugins/platforms/xlib/qxlibscreen.cpp index 7c8a367373..920116a614 100644 --- a/src/plugins/platforms/xlib/qxlibscreen.cpp +++ b/src/plugins/platforms/xlib/qxlibscreen.cpp @@ -41,6 +41,8 @@ #include "qxlibscreen.h" +#include + #include "qxlibcursor.h" #include "qxlibwindow.h" #include "qxlibkeyboard.h" @@ -54,8 +56,6 @@ #include -#include - QT_BEGIN_NAMESPACE static int (*original_x_errhandler)(Display *dpy, XErrorEvent *); @@ -201,7 +201,7 @@ QXlibScreen::QXlibScreen() #ifndef DONT_USE_MIT_SHM - Status MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); + int MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); Q_ASSERT(MIT_SHM_extension_supported == True); #endif original_x_errhandler = XSetErrorHandler(qt_x_errhandler); diff --git a/src/plugins/platforms/xlib/qxlibstatic.cpp b/src/plugins/platforms/xlib/qxlibstatic.cpp index 61177812d5..7b562ea50d 100644 --- a/src/plugins/platforms/xlib/qxlibstatic.cpp +++ b/src/plugins/platforms/xlib/qxlibstatic.cpp @@ -51,10 +51,6 @@ #include -#ifndef QT_NO_XFIXES -#include -#endif // QT_NO_XFIXES - static const char * x11_atomnames = { // window-manager <-> client protocols "WM_PROTOCOLS\0" diff --git a/src/plugins/platforms/xlib/qxlibstatic.h b/src/plugins/platforms/xlib/qxlibstatic.h index 8517de0bc2..fec2a16cdf 100644 --- a/src/plugins/platforms/xlib/qxlibstatic.h +++ b/src/plugins/platforms/xlib/qxlibstatic.h @@ -135,6 +135,7 @@ typedef char *XPointer; #endif #ifndef QT_NO_XFIXES +#include typedef Bool (*PtrXFixesQueryExtension)(Display *, int *, int *); typedef Status (*PtrXFixesQueryVersion)(Display *, int *, int *); typedef void (*PtrXFixesSetCursorName)(Display *dpy, Cursor cursor, const char *name); diff --git a/src/plugins/platforms/xlib/qxlibwindow.cpp b/src/plugins/platforms/xlib/qxlibwindow.cpp index 9a05fc620d..50ea7b58e4 100644 --- a/src/plugins/platforms/xlib/qxlibwindow.cpp +++ b/src/plugins/platforms/xlib/qxlibwindow.cpp @@ -47,14 +47,6 @@ #include "qxlibstatic.h" #include "qxlibdisplay.h" -#include -#include -#include -#include - -#include -#include - #if !defined(QT_NO_OPENGL) #if !defined(QT_OPENGL_ES_2) #include "qglxintegration.h" @@ -66,6 +58,15 @@ #endif //QT_OPENGL_ES_2 #endif //QT_NO_OPENGL + +#include +#include +#include +#include + +#include +#include + //#define MYX11_DEBUG QT_BEGIN_NAMESPACE @@ -80,9 +81,10 @@ QXlibWindow::QXlibWindow(QWidget *window) int w = window->width(); int h = window->height(); - if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL - && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL) ) { #if !defined(QT_NO_OPENGL) + if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL + && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL) + || window->platformWindowFormat().alpha()) { #if !defined(QT_OPENGL_ES_2) XVisualInfo *visualInfo = qglx_findVisualInfo(mScreen->display()->nativeDisplay(),mScreen->xScreenNumber(),window->platformWindowFormat()); #else @@ -101,18 +103,28 @@ QXlibWindow::QXlibWindow(QWidget *window) visualInfo = XGetVisualInfo(mScreen->display()->nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount); #endif //!defined(QT_OPENGL_ES_2) if (visualInfo) { - Colormap cmap = XCreateColormap(mScreen->display()->nativeDisplay(),mScreen->rootWindow(),visualInfo->visual,AllocNone); + mDepth = visualInfo->depth; + mFormat = (mDepth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; + mVisual = visualInfo->visual; + Colormap cmap = XCreateColormap(mScreen->display()->nativeDisplay(), mScreen->rootWindow(), visualInfo->visual, AllocNone); XSetWindowAttributes a; + a.background_pixel = WhitePixel(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber()); + a.border_pixel = BlackPixel(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber()); a.colormap = cmap; x_window = XCreateWindow(mScreen->display()->nativeDisplay(), mScreen->rootWindow(),x, y, w, h, 0, visualInfo->depth, InputOutput, visualInfo->visual, - CWColormap, &a); + CWBackPixel|CWBorderPixel|CWColormap, &a); } else { qFatal("no window!"); } + } else #endif //!defined(QT_NO_OPENGL) - } else { + { + mDepth = mScreen->depth(); + mFormat = (mDepth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; + mVisual = mScreen->defaultVisual(); + x_window = XCreateSimpleWindow(mScreen->display()->nativeDisplay(), mScreen->rootWindow(), x, y, w, h, 0 /*border_width*/, mScreen->blackPixel(), mScreen->whitePixel()); diff --git a/src/plugins/platforms/xlib/qxlibwindow.h b/src/plugins/platforms/xlib/qxlibwindow.h index 08694a5026..2d11224c23 100644 --- a/src/plugins/platforms/xlib/qxlibwindow.h +++ b/src/plugins/platforms/xlib/qxlibwindow.h @@ -122,6 +122,10 @@ public: Window xWindow() const; GC graphicsContext() const; + inline uint depth() const { return mDepth; } + QImage::Format format() const { return mFormat; } + Visual* visual() const { return mVisual; } + protected: QVector getNetWmState() const; void setMWMHints(const QXlibMWMHints &mwmhints); @@ -135,6 +139,10 @@ private: Window x_window; GC gc; + uint mDepth; + QImage::Format mFormat; + Visual* mVisual; + GC createGC(); QPlatformGLContext *mGLContext; diff --git a/src/plugins/platforms/xlib/qxlibwindowsurface.cpp b/src/plugins/platforms/xlib/qxlibwindowsurface.cpp index 513f10dc6a..a917f452e8 100644 --- a/src/plugins/platforms/xlib/qxlibwindowsurface.cpp +++ b/src/plugins/platforms/xlib/qxlibwindowsurface.cpp @@ -49,6 +49,8 @@ #include "qxlibscreen.h" #include "qxlibdisplay.h" +#include "qpainter.h" + # include # include # include @@ -80,20 +82,19 @@ void QXlibShmImageInfo::destroy() void QXlibWindowSurface::resizeShmImage(int width, int height) { + QXlibScreen *screen = QXlibScreen::testLiteScreenForWidget(window()); + QXlibWindow *win = static_cast(window()->platformWindow()); #ifdef DONT_USE_MIT_SHM - shm_img = QImage(width, height, QImage::Format_RGB32); + shm_img = QImage(width, height, win->format()); #else - QXlibScreen *screen = QXlibScreen::testLiteScreenForWidget(window()); if (image_info) image_info->destroy(); else image_info = new QXlibShmImageInfo(screen->display()->nativeDisplay()); - Visual *visual = screen->defaultVisual(); - - XImage *image = XShmCreateImage (screen->display()->nativeDisplay(), visual, 24, ZPixmap, 0, + XImage *image = XShmCreateImage (screen->display()->nativeDisplay(), win->visual(), win->depth(), ZPixmap, 0, &image_info->shminfo, width, height); @@ -109,7 +110,7 @@ void QXlibWindowSurface::resizeShmImage(int width, int height) Q_ASSERT(shm_attach_status == True); - shm_img = QImage( (uchar*) image->data, image->width, image->height, image->bytes_per_line, QImage::Format_RGB32 ); + shm_img = QImage( (uchar*) image->data, image->width, image->height, image->bytes_per_line, win->format() ); #endif painted = false; } @@ -160,11 +161,11 @@ void QXlibWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPo #ifdef DONT_USE_MIT_SHM // just convert the image every time... if (!shm_img.isNull()) { - Visual *visual = DefaultVisual(screen->display(), screen->xScreenNumber()); + QXlibWindow *win = static_cast(window()->platformWindow()); QImage image = shm_img; //img.convertToFormat( - XImage *xi = XCreateImage(screen->display(), visual, 24, ZPixmap, + XImage *xi = XCreateImage(screen->display(), win->visual(), win->depth(), ZPixmap, 0, (char *) image.scanLine(0), image.width(), image.height(), 32, image.bytesPerLine()); @@ -214,6 +215,16 @@ void QXlibWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); resizeBuffer(size()); + + if (shm_img.hasAlphaChannel()) { + QPainter p(&shm_img); + p.setCompositionMode(QPainter::CompositionMode_Source); + const QVector rects = region.rects(); + const QColor blank = Qt::transparent; + for (QVector::const_iterator it = rects.begin(); it != rects.end(); ++it) { + p.fillRect(*it, blank); + } + } } void QXlibWindowSurface::endPaint(const QRegion ®ion)