File indexing completed on 2024-05-12 05:30:32

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "generic_scene_opengl_test.h"
0010 #include "compositor.h"
0011 #include "core/renderbackend.h"
0012 #include "cursor.h"
0013 #include "effect/effectloader.h"
0014 #include "scene/workspacescene.h"
0015 #include "wayland_server.h"
0016 #include "window.h"
0017 
0018 #include <KConfigGroup>
0019 #include <QSignalSpy>
0020 
0021 using namespace KWin;
0022 static const QString s_socketName = QStringLiteral("wayland_test_kwin_scene_opengl-0");
0023 
0024 GenericSceneOpenGLTest::GenericSceneOpenGLTest(const QByteArray &envVariable)
0025     : QObject()
0026     , m_envVariable(envVariable)
0027 {
0028 }
0029 
0030 GenericSceneOpenGLTest::~GenericSceneOpenGLTest()
0031 {
0032 }
0033 
0034 void GenericSceneOpenGLTest::cleanup()
0035 {
0036     Test::destroyWaylandConnection();
0037 }
0038 
0039 void GenericSceneOpenGLTest::initTestCase()
0040 {
0041     if (!Test::renderNodeAvailable()) {
0042         QSKIP("no render node available");
0043         return;
0044     }
0045     qRegisterMetaType<KWin::Window *>();
0046     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0047     QVERIFY(waylandServer()->init(s_socketName));
0048     Test::setOutputConfig({
0049         QRect(0, 0, 1280, 1024),
0050         QRect(1280, 0, 1280, 1024),
0051     });
0052 
0053     // disable all effects - we don't want to have it interact with the rendering
0054     auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
0055     KConfigGroup plugins(config, QStringLiteral("Plugins"));
0056     const auto builtinNames = EffectLoader().listOfKnownEffects();
0057     for (QString name : builtinNames) {
0058         plugins.writeEntry(name + QStringLiteral("Enabled"), false);
0059     }
0060 
0061     config->sync();
0062     kwinApp()->setConfig(config);
0063 
0064     qputenv("XCURSOR_THEME", QByteArrayLiteral("DMZ-White"));
0065     qputenv("XCURSOR_SIZE", QByteArrayLiteral("24"));
0066     qputenv("KWIN_COMPOSE", m_envVariable);
0067 
0068     kwinApp()->start();
0069     QVERIFY(applicationStartedSpy.wait());
0070     QVERIFY(Compositor::self());
0071 
0072     QCOMPARE(Compositor::self()->backend()->compositingType(), KWin::OpenGLCompositing);
0073 }
0074 
0075 void GenericSceneOpenGLTest::testRestart()
0076 {
0077     // simple restart of the OpenGL compositor without any windows being shown
0078     QSignalSpy sceneCreatedSpy(KWin::Compositor::self(), &Compositor::sceneCreated);
0079     KWin::Compositor::self()->reinitialize();
0080     if (sceneCreatedSpy.isEmpty()) {
0081         QVERIFY(sceneCreatedSpy.wait());
0082     }
0083     QCOMPARE(sceneCreatedSpy.count(), 1);
0084     QCOMPARE(Compositor::self()->backend()->compositingType(), KWin::OpenGLCompositing);
0085 
0086     // trigger a repaint
0087     KWin::Compositor::self()->scene()->addRepaintFull();
0088     // and wait 100 msec to ensure it's rendered
0089     // TODO: introduce frameRendered signal in SceneOpenGL
0090     QTest::qWait(100);
0091 }
0092 
0093 #include "moc_generic_scene_opengl_test.cpp"