From 174061f9f32ac76c6b8a6d155d772e37708d8cfc Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 31 Jul 2019 10:23:39 +0200 Subject: QHighDPI: Fix broken scaling of QPoint(F) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some reason, the overload resolution of the High DPI scale() functions introduced by b6ded193ee64ffe67df6d22e7a23aa1ea9e02ec7 chose the wrong overloads for QPointF and/or QPoint; it fell back to the generic template intended for qreal, QSize, etc, ignoring the origin. Remove the template and spell out all overloads. Fixes: QTBUG-77255 Change-Id: I5661f16f7326f65156f646f430f5a0c71d5302d2 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/kernel.pro | 3 + .../gui/kernel/qhighdpiscaling/qhighdpiscaling.pro | 6 ++ .../kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp | 77 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro create mode 100644 tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index fbd3b1b371..42135dae24 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -11,6 +11,7 @@ SUBDIRS=\ qguimetatype \ qguitimer \ qguivariant \ + qhighdpiscaling \ qinputmethod \ qkeyevent \ qkeysequence \ @@ -35,6 +36,8 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop !qtHaveModule(network): SUBDIRS -= \ qguieventloop +!qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling + !qtConfig(opengl): SUBDIRS -= qopenglwindow android|uikit: SUBDIRS -= qclipboard diff --git a/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro b/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro new file mode 100644 index 0000000000..6cd7bb01f5 --- /dev/null +++ b/tests/auto/gui/kernel/qhighdpiscaling/qhighdpiscaling.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qhighdpiscaling + +QT += core-private gui-private testlib + +SOURCES += tst_qhighdpiscaling.cpp diff --git a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp new file mode 100644 index 0000000000..969b2351ec --- /dev/null +++ b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +class tst_QHighDpiScaling: public QObject +{ + Q_OBJECT + +private slots: + void scale(); +}; + +// Emulate the case of a High DPI secondary screen +class MyPlatformScreen : public QPlatformScreen +{ +public: + QRect geometry() const override { return QRect(3840, 0, 3840, 1920); } + QRect availableGeometry() const override { return geometry(); } + + int depth() const override { return 32; } + QImage::Format format() const override { return QImage::Format_ARGB32_Premultiplied; } +}; + +// QTBUG-77255: Test some scaling overloads +void tst_QHighDpiScaling::scale() +{ + QHighDpiScaling::setGlobalFactor(2); + QScopedPointer screen(new MyPlatformScreen); + + qreal nativeValue = 10; + const qreal value = QHighDpi::fromNativePixels(nativeValue, screen.data()); + QCOMPARE(value, qreal(5)); + QCOMPARE(QHighDpi::toNativePixels(value, screen.data()), nativeValue); + + // 10, 10 within screen should translate to 5,5 with origin preserved + const QPoint nativePoint = screen->geometry().topLeft() + QPoint(10, 10); + const QPoint point = QHighDpi::fromNativePixels(nativePoint, screen.data()); + QCOMPARE(point, QPoint(3845, 5)); + QCOMPARE(QHighDpi::toNativePixels(point, screen.data()), nativePoint); + + const QPointF nativePointF(nativePoint); + const QPointF pointF = QHighDpi::fromNativePixels(nativePointF, screen.data()); + QCOMPARE(pointF, QPointF(3845, 5)); + QCOMPARE(QHighDpi::toNativePixels(pointF, screen.data()), nativePointF); +} + +#include "tst_qhighdpiscaling.moc" +QTEST_MAIN(tst_QHighDpiScaling); -- cgit v1.2.3 From 5d7f1133205d14002463456c26a97f8ba17d69b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 7 Aug 2019 13:15:51 +0200 Subject: Add nullptr guard to QHighDScaling::scaleAndOrigin(QPlatformScreen *) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit b6ded193 added an unconditional dereference of the platformScreen pointer, for calls where nativePostion is non-nullptr. Change-Id: I4a6fbbd0337f91d4fcb76c17b4dc60e1b9ad10ed Reviewed-by: Tor Arne Vestbø --- .../gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp index 969b2351ec..ec80c2d02c 100644 --- a/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp +++ b/tests/auto/gui/kernel/qhighdpiscaling/tst_qhighdpiscaling.cpp @@ -36,6 +36,7 @@ class tst_QHighDpiScaling: public QObject Q_OBJECT private slots: + void factor(); void scale(); }; @@ -50,6 +51,23 @@ public: QImage::Format format() const override { return QImage::Format_ARGB32_Premultiplied; } }; +void tst_QHighDpiScaling::factor() +{ + QHighDpiScaling::setGlobalFactor(2); + + // Verfy that QHighDpiScaling::factor() does not crash on nullptr contexts. + QPoint fakeNativePosition = QPoint(5, 5); + QPlatformScreen *screenContext = nullptr; + QVERIFY(QHighDpiScaling::factor(screenContext) >= 0); + QVERIFY(QHighDpiScaling::factor(screenContext, &fakeNativePosition) >= 0); + QPlatformScreen *platformScreenContext = nullptr; + QVERIFY(QHighDpiScaling::factor(platformScreenContext) >= 0); + QVERIFY(QHighDpiScaling::factor(platformScreenContext, &fakeNativePosition) >= 0); + QWindow *windowContext = nullptr; + QVERIFY(QHighDpiScaling::factor(windowContext) >= 0); + QVERIFY(QHighDpiScaling::factor(windowContext, &fakeNativePosition) >= 0); +} + // QTBUG-77255: Test some scaling overloads void tst_QHighDpiScaling::scale() { -- cgit v1.2.3 From 662fec6f0db32fb58b91357aa11c9d3be94f0c55 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Fri, 9 Aug 2019 11:04:27 +0200 Subject: Update for failures only on dev branch. Use general platform names This patch was generated with tooling from patchset 31 of https://codereview.qt-project.org/c/qt/qtqa/+/267034 in interactive mode. General platform names were chosen if greater than 60% of the currently active platforms of a given type in COIN recently failed. Change-Id: Ia4bde7f0ec422bbb727dc9d7151295159094f146 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/gui/kernel/qguitimer/BLACKLIST | 8 -------- tests/auto/gui/kernel/qwindow/BLACKLIST | 15 +++------------ 2 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 tests/auto/gui/kernel/qguitimer/BLACKLIST (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/qguitimer/BLACKLIST b/tests/auto/gui/kernel/qguitimer/BLACKLIST deleted file mode 100644 index 6ab715b922..0000000000 --- a/tests/auto/gui/kernel/qguitimer/BLACKLIST +++ /dev/null @@ -1,8 +0,0 @@ -[basic_chrono] -osx-10.13 -[remainingTime] -osx-10.12 -windows-10 msvc-2015 -osx-10.14 -osx-10.13 - diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index 1bb3917948..27463adf99 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -1,7 +1,5 @@ [positioning] opensuse-leap -ubuntu-16.04 -opensuse-42.3 [positioning:default] linux osx-10.12 ci @@ -9,24 +7,17 @@ winrt [positioning:fake] osx-10.12 ci [modalWithChildWindow] -ubuntu-16.04 -opensuse-leap # QTBUG-66851 # QTBUG-69160 -opensuse-42.3 +opensuse-leap [setVisible] # QTBUG-69154 android [modalWindowEnterEventOnHide_QTBUG35109] -ubuntu-16.04 -osx-10.11 -osx-10.13 -osx-10.14 -osx-10.12 +osx [spuriousMouseMove] # QTBUG-69162 -windows-10 msvc-2015 -windows-10 msvc-2017 +windows-10 [testInputEvents] rhel-7.4 [exposeEventOnShrink_QTBUG54040] -- cgit v1.2.3 From d55712153a357cc5cc975bf599470619b7c77faa Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 21 Aug 2019 18:53:41 +0300 Subject: tst_NoQtEventLoop: destroy hidden windows Otherwise, we get a warning: QWARN : tst_NoQtEventLoop::consumeSocketEvents() QWindowsContext::windowsProc: No Qt Window found for event 0x2a3 (WM_MOUSELEAVE), hwnd=0x0x9b80646. in the event loop which is running by another test. So, add missing 'delete' call. Change-Id: Ib9b24155bdd6e78062a5234c317c9f878906e413 Reviewed-by: Friedemann Kleint --- tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp index 4fca9a07fc..19c5c8a4a0 100644 --- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -258,8 +258,8 @@ void tst_NoQtEventLoop::consumeMouseEvents() ::SetWindowPos(mainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - Window *childWindow = new Window; - childWindow->setParent(QWindow::fromWinId((WId)mainWnd)); + QWindow *mainWindow = QWindow::fromWinId(reinterpret_cast(mainWnd)); + Window *childWindow = new Window(mainWindow); childWindow->setGeometry(margin, topVerticalMargin, width - 2 * margin, height - margin - topVerticalMargin); childWindow->show(); @@ -276,6 +276,7 @@ void tst_NoQtEventLoop::consumeMouseEvents() if (g_exit) break; } + delete mainWindow; QCOMPARE(testThread->passed(), true); -- cgit v1.2.3 From 81408c0e76616b127c46779dc14bbcf084a3d87b Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Mon, 19 Aug 2019 14:20:11 +0300 Subject: QEventDispatcherWin32: avoid livelock in a foreign event loop According to Windows docs, GetMessage() function retrieves the messages from the input queue in defined order, where posted messages are processed ahead of input messages, even if they were posted later. Therefore, if the application produces a posted event permanently, as a result of processing that event, user input messages may be blocked due to hard CPU usage by the application. It's not a problem, if an internal Qt event loop is running. By calling sendPostedEvents() on the beginning of processEvents(), we are sending posted events only once per iteration. However, during execution of the foreign loop, we should artificially lower the priority of the WM_QT_SENDPOSTEDEVENTS message in order to enable delivery of other input messages. To solve the problem, it is proposed to postpone the WM_QT_SENDPOSTEDEVENTS message until the message queue becomes empty, as it works for the internal loop. Task-number: QTBUG-77464 Change-Id: I8dedb6837c6fc41aa6f497e67ab2352c2b4f3772 Reviewed-by: Laszlo Agocs --- .../gui/kernel/noqteventloop/tst_noqteventloop.cpp | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp index 19c5c8a4a0..3d1876f00f 100644 --- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -49,7 +50,7 @@ class tst_NoQtEventLoop : public QObject private slots: void consumeMouseEvents(); void consumeSocketEvents(); - + void deliverEventsInLivelock(); }; class Window : public QRasterWindow @@ -312,6 +313,34 @@ void tst_NoQtEventLoop::consumeSocketEvents() QVERIFY(server.hasPendingConnections()); } +void tst_NoQtEventLoop::deliverEventsInLivelock() +{ + int argc = 1; + char *argv[] = { const_cast("test"), 0 }; + QGuiApplication app(argc, argv); + + QTimer livelockTimer; + livelockTimer.start(0); + QTimer::singleShot(100, Qt::CoarseTimer, &livelockTimer, &QTimer::stop); + + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + + // Exec own message loop + MSG msg; + forever { + if (elapsedTimer.hasExpired(3000) || !livelockTimer.isActive()) + break; + + if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + } + + QVERIFY(!livelockTimer.isActive()); +} + #include QTEST_APPLESS_MAIN(tst_NoQtEventLoop) -- cgit v1.2.3