From ad1b5495a2a437d21435a9c321c9abf612cd210e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 1 Mar 2012 18:06:29 +0100 Subject: Fixed Windows performance regression introduced by ac2818bef95f134. Only create a temporary DC if we're not on the main thread. Task-number: QTBUG-24602 Change-Id: I36dad4c197c7cc1e019b19d42c81526fc8cfdcf4 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qwidget_win.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 3fdc00c834..8a400cded2 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -49,6 +49,7 @@ #include "qlayout.h" #include "qpainter.h" #include "qstack.h" +#include "qthread.h" #include "qt_windows.h" #include "qwidget.h" #include "qwidget_p.h" @@ -1636,6 +1637,8 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r) } } +extern Q_GUI_EXPORT HDC qt_win_display_dc(); + int QWidget::metric(PaintDeviceMetric m) const { Q_D(const QWidget); @@ -1645,7 +1648,8 @@ int QWidget::metric(PaintDeviceMetric m) const } else if (m == PdmHeight) { val = data->crect.height(); } else { - HDC gdc = GetDC(0); + bool ownDC = QThread::currentThread() != qApp->thread(); + HDC gdc = ownDC ? GetDC(0) : qt_win_display_dc(); switch (m) { case PdmDpiX: case PdmPhysicalDpiX: @@ -1696,7 +1700,8 @@ int QWidget::metric(PaintDeviceMetric m) const val = 0; qWarning("QWidget::metric: Invalid metric command"); } - ReleaseDC(0, gdc); + if (ownDC) + ReleaseDC(0, gdc); } return val; } -- cgit v1.2.3