From 31091808814de383aeec453933d2b29ce4eefb6f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 5 May 2014 15:54:10 +0200 Subject: Avoid showing warnings from drawPixmap when using a QGLWidget QGLWidget has a paint device type of Widget, yet drawing on it from outside the gui thread is fine as long as ThreadedOpenGL is supported. It has probably been overlooked that the device type OpenGL applies to QGLFramebufferObject and such but not QGLWidget. This will fix the problem of flooding the output with warnings in the tst_qglthreads autotest and potentially elsewhere too. Task-number: QTBUG-38771 Change-Id: Ie014a2610a0db41b31c30c404e286d4997aecdc3 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Gunnar Sletta --- src/gui/painting/qpainter.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index fe5fc051df..3f387d575b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -147,8 +147,9 @@ static inline uint line_emulation(uint emulation) } #ifndef QT_NO_DEBUG -static bool qt_painter_thread_test(int devType, const char *what) +static bool qt_painter_thread_test(int devType, int engineType, const char *what) { + const QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration(); switch (devType) { case QInternal::Image: case QInternal::Printer: @@ -157,8 +158,13 @@ static bool qt_painter_thread_test(int devType, const char *what) break; default: if (QThread::currentThread() != qApp->thread() - && (devType!=QInternal::Pixmap || !QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) - && (devType!=QInternal::OpenGL || !QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))) { + // pixmaps cannot be targets unless threaded pixmaps are supported + && (devType != QInternal::Pixmap || !platformIntegration->hasCapability(QPlatformIntegration::ThreadedPixmaps)) + // framebuffer objects and such cannot be targets unless threaded GL is supported + && (devType != QInternal::OpenGL || !platformIntegration->hasCapability(QPlatformIntegration::ThreadedOpenGL)) + // widgets cannot be targets except for QGLWidget + && (devType != QInternal::Widget || !platformIntegration->hasCapability(QPlatformIntegration::ThreadedOpenGL) + || (engineType != QPaintEngine::OpenGL && engineType != QPaintEngine::OpenGL2))) { qWarning("QPainter: It is not safe to use %s outside the GUI thread", what); return false; } @@ -5054,7 +5060,7 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) return; #ifndef QT_NO_DEBUG - qt_painter_thread_test(d->device->devType(), "drawPixmap()"); + qt_painter_thread_test(d->device->devType(), d->engine->type(), "drawPixmap()"); #endif if (d->extended) { @@ -5125,7 +5131,7 @@ void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) if (!d->engine || pm.isNull()) return; #ifndef QT_NO_DEBUG - qt_painter_thread_test(d->device->devType(), "drawPixmap()"); + qt_painter_thread_test(d->device->devType(), d->engine->type(), "drawPixmap()"); #endif qreal x = r.x(); @@ -6610,7 +6616,7 @@ void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPo return; #ifndef QT_NO_DEBUG - qt_painter_thread_test(d->device->devType(), "drawTiledPixmap()"); + qt_painter_thread_test(d->device->devType(), d->engine->type(), "drawTiledPixmap()"); #endif qreal sw = pixmap.width(); -- cgit v1.2.3