diff options
author | Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> | 2015-04-10 17:52:49 +0200 |
---|---|---|
committer | Pier Luigi Fiorini <pierluigi.fiorini@hawaiios.org> | 2016-10-03 15:15:58 +0000 |
commit | 7ee4be6af2c92c345539bb4950dd48d7a740847d (patch) | |
tree | 2acbcfb9fd0a2dbc995cb0d700e7e14ad4afd759 /tests | |
parent | 59c8598958959de943a0782093f020ae1c348edf (diff) | |
download | qtwayland-7ee4be6af2c92c345539bb4950dd48d7a740847d.tar.gz |
Add mode support to QWaylandOutput
Outputs usually have more than one mode, add an API to support them.
When sizeFollowsWindow is true, modes are replaced by one with the
window size and refresh rate. In that circumstance the mode changes
when the window is resized.
The sizeFollowsWindow property default value is no longer true.
The setGeometry() method is gone as it doesn't make sense now, the
setWidth() and setHeight() methods are now private slots to resize
the resolution as the window resizes (and sizeFollowsWindow is true).
Refresh rate is expressed in mHz rather than Hz just like the
Wayland protocol.
A compositor implementation may choose to add modes if it has access
to hardware information, it will call addMode() for each mode and
then invoke the setCurrentMode() method that sends the modes list
to the client. The preferred mode is indicated with a boolean
parameter to the addMode() method.
Change-Id: Iffed4784ccef695c276ebd800172957f4cff3324
Task-number: QTBUG-49814
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.cpp | 19 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.h | 8 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/tst_compositor.cpp | 58 |
3 files changed, 78 insertions, 7 deletions
diff --git a/tests/auto/compositor/compositor/mockclient.cpp b/tests/auto/compositor/compositor/mockclient.cpp index f2fbc5de..da1096fb 100644 --- a/tests/auto/compositor/compositor/mockclient.cpp +++ b/tests/auto/compositor/compositor/mockclient.cpp @@ -52,6 +52,7 @@ MockClient::MockClient() , wlshell(0) , xdgShell(nullptr) , iviApplication(nullptr) + , refreshRate(-1) , error(0 /* means no error according to spec */) , protocolError({0, 0, nullptr}) { @@ -102,10 +103,22 @@ void MockClient::outputGeometryEvent(void *data, wl_output *, resolve(data)->geometry.moveTopLeft(QPoint(x, y)); } -void MockClient::outputModeEvent(void *data, wl_output *, uint32_t, - int w, int h, int) +void MockClient::outputModeEvent(void *data, wl_output *, uint32_t flags, + int w, int h, int refreshRate) { - resolve(data)->geometry.setSize(QSize(w, h)); + QWaylandOutputMode mode(QSize(w, h), refreshRate); + + if (flags & WL_OUTPUT_MODE_CURRENT) { + resolve(data)->geometry.setSize(QSize(w, h)); + resolve(data)->resolution = QSize(w, h); + resolve(data)->refreshRate = refreshRate; + resolve(data)->currentMode = mode; + } + + if (flags & WL_OUTPUT_MODE_PREFERRED) + resolve(data)->preferredMode = mode; + + resolve(data)->modes.append(mode); } void MockClient::outputDone(void *, wl_output *) diff --git a/tests/auto/compositor/compositor/mockclient.h b/tests/auto/compositor/compositor/mockclient.h index ed9319af..1881393a 100644 --- a/tests/auto/compositor/compositor/mockclient.h +++ b/tests/auto/compositor/compositor/mockclient.h @@ -34,6 +34,7 @@ #include <QImage> #include <QRect> #include <QList> +#include <QWaylandOutputMode> class MockSeat; @@ -73,6 +74,11 @@ public: QList<MockSeat *> m_seats; QRect geometry; + QSize resolution; + int refreshRate; + QWaylandOutputMode currentMode; + QWaylandOutputMode preferredMode; + QList<QWaylandOutputMode> modes; int fd; int error; @@ -106,7 +112,7 @@ private: uint32_t flags, int width, int height, - int refresh); + int refreshRate); static void outputDone(void *data, wl_output *output); static void outputScale(void *data, wl_output *output, int factor); diff --git a/tests/auto/compositor/compositor/tst_compositor.cpp b/tests/auto/compositor/compositor/tst_compositor.cpp index 16aedd8e..393b9f5b 100644 --- a/tests/auto/compositor/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/compositor/tst_compositor.cpp @@ -35,6 +35,7 @@ #include "qwaylandbufferref.h" #include "qwaylandseat.h" +#include <QtGui/QScreen> #include <QtWaylandCompositor/QWaylandXdgShellV5> #include <QtWaylandCompositor/QWaylandIviApplication> #include <QtWaylandCompositor/QWaylandIviSurface> @@ -58,6 +59,8 @@ private slots: void singleClient(); void multipleClients(); void geometry(); + void modes(); + void sizeFollowsWindow(); void mapSurface(); void frameCallback(); @@ -202,12 +205,61 @@ void tst_WaylandCompositor::geometry() TestCompositor compositor; compositor.create(); - QRect geometry(0, 0, 4096, 3072); - compositor.defaultOutput()->setGeometry(geometry); + QWaylandOutputMode mode(QSize(4096, 3072), 60000); + compositor.defaultOutput()->setPosition(QPoint(1024, 0)); + compositor.defaultOutput()->addMode(mode, true); + compositor.defaultOutput()->setCurrentMode(mode); MockClient client; - QTRY_COMPARE(client.geometry, geometry); + QTRY_COMPARE(client.geometry, QRect(QPoint(1024, 0), QSize(4096, 3072))); + QTRY_COMPARE(client.resolution, QSize(4096, 3072)); + QTRY_COMPARE(client.refreshRate, 60000); +} + +void tst_WaylandCompositor::modes() +{ + TestCompositor compositor; + compositor.create(); + + // mode3 is current, mode4 is preferred + QWaylandOutputMode mode1(QSize(800, 600), 120000); + QWaylandOutputMode mode2(QSize(1024, 768), 100000); + QWaylandOutputMode mode3(QSize(1920, 1080), 60000); + QWaylandOutputMode mode4(QSize(2560, 1440), 59000); + compositor.defaultOutput()->addMode(mode1); + compositor.defaultOutput()->addMode(mode2, true); + compositor.defaultOutput()->addMode(mode3); + compositor.defaultOutput()->addMode(mode4, true); + compositor.defaultOutput()->setCurrentMode(mode3); + + MockClient client; + + QTRY_COMPARE(client.modes.size(), 4); + QTRY_COMPARE(client.currentMode, mode3); + QTRY_COMPARE(client.preferredMode, mode4); + QTRY_COMPARE(client.geometry, QRect(QPoint(0, 0), QSize(1920, 1080))); +} + +void tst_WaylandCompositor::sizeFollowsWindow() +{ + TestCompositor compositor; + + QWindow window; + window.resize(800, 600); + + auto output = new QWaylandOutput(&compositor, &window); + output->setSizeFollowsWindow(true); + + compositor.create(); + + QWaylandOutputMode mode(window.size(), qFloor(window.screen()->refreshRate() * 1000)); + + MockClient client; + + QTRY_COMPARE(client.modes.size(), 1); + QTRY_COMPARE(client.currentMode, mode); + QTRY_COMPARE(client.preferredMode, mode); } void tst_WaylandCompositor::mapSurface() |