kwin/autotests/integration/buffer_size_change_test.cpp
Vlad Zahorodnii b8a70e62d5 Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.

This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.

With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.

On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.

The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.

Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2021-01-06 16:59:29 +00:00

116 lines
3.5 KiB
C++

/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "generic_scene_opengl_test.h"
#include "abstract_client.h"
#include "composite.h"
#include "scene.h"
#include "wayland_server.h"
#include <KWayland/Client/xdgshell.h>
#include <KWayland/Client/subsurface.h>
#include <KWayland/Client/surface.h>
namespace KWin
{
static const QString s_socketName = QStringLiteral("wayland_test_buffer_size_change-0");
class BufferSizeChangeTest : public GenericSceneOpenGLTest
{
Q_OBJECT
public:
BufferSizeChangeTest() : GenericSceneOpenGLTest(QByteArrayLiteral("O2")) {}
private Q_SLOTS:
void init();
void testShmBufferSizeChange();
void testShmBufferSizeChangeOnSubSurface();
};
void BufferSizeChangeTest::init()
{
QVERIFY(Test::setupWaylandConnection());
}
void BufferSizeChangeTest::testShmBufferSizeChange()
{
// This test verifies that an SHM buffer size change is handled correctly
using namespace KWayland::Client;
QScopedPointer<Surface> surface(Test::createSurface());
QVERIFY(!surface.isNull());
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data()));
QVERIFY(!shellSurface.isNull());
// set buffer size
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(client);
// add a first repaint
QSignalSpy frameRenderedSpy(Compositor::self()->scene(), &Scene::frameRendered);
QVERIFY(frameRenderedSpy.isValid());
Compositor::self()->addRepaintFull();
QVERIFY(frameRenderedSpy.wait());
// now change buffer size
Test::render(surface.data(), QSize(30, 10), Qt::red);
QSignalSpy damagedSpy(client, &AbstractClient::damaged);
QVERIFY(damagedSpy.isValid());
QVERIFY(damagedSpy.wait());
KWin::Compositor::self()->addRepaintFull();
QVERIFY(frameRenderedSpy.wait());
}
void BufferSizeChangeTest::testShmBufferSizeChangeOnSubSurface()
{
using namespace KWayland::Client;
// setup parent surface
QScopedPointer<Surface> parentSurface(Test::createSurface());
QVERIFY(!parentSurface.isNull());
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(parentSurface.data()));
QVERIFY(!shellSurface.isNull());
// setup sub surface
QScopedPointer<Surface> surface(Test::createSurface());
QVERIFY(!surface.isNull());
QScopedPointer<SubSurface> subSurface(Test::createSubSurface(surface.data(), parentSurface.data()));
QVERIFY(!subSurface.isNull());
// set buffer sizes
Test::render(surface.data(), QSize(30, 10), Qt::red);
AbstractClient *parent = Test::renderAndWaitForShown(parentSurface.data(), QSize(100, 50), Qt::blue);
QVERIFY(parent);
// add a first repaint
QSignalSpy frameRenderedSpy(Compositor::self()->scene(), &Scene::frameRendered);
QVERIFY(frameRenderedSpy.isValid());
Compositor::self()->addRepaintFull();
QVERIFY(frameRenderedSpy.wait());
// change buffer size of sub surface
QSignalSpy damagedParentSpy(parent, &AbstractClient::damaged);
QVERIFY(damagedParentSpy.isValid());
Test::render(surface.data(), QSize(20, 10), Qt::red);
parentSurface->commit(Surface::CommitFlag::None);
QVERIFY(damagedParentSpy.wait());
// add a second repaint
KWin::Compositor::self()->addRepaintFull();
QVERIFY(frameRenderedSpy.wait());
}
}
WAYLANDTEST_MAIN(KWin::BufferSizeChangeTest)
#include "buffer_size_change_test.moc"