File indexing completed on 2024-05-05 17:35:46

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 "composite.h"
0011 #include "core/outputbackend.h"
0012 #include "core/renderbackend.h"
0013 #include "cursor.h"
0014 #include "effectloader.h"
0015 #include "scene/workspacescene.h"
0016 #include "wayland_server.h"
0017 #include "window.h"
0018 
0019 #include <KConfigGroup>
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     qRegisterMetaType<KWin::Window *>();
0042     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0043     QVERIFY(waylandServer()->init(s_socketName));
0044     QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
0045 
0046     // disable all effects - we don't want to have it interact with the rendering
0047     auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
0048     KConfigGroup plugins(config, QStringLiteral("Plugins"));
0049     const auto builtinNames = EffectLoader().listOfKnownEffects();
0050     for (QString name : builtinNames) {
0051         plugins.writeEntry(name + QStringLiteral("Enabled"), false);
0052     }
0053 
0054     config->sync();
0055     kwinApp()->setConfig(config);
0056 
0057     qputenv("XCURSOR_THEME", QByteArrayLiteral("DMZ-White"));
0058     qputenv("XCURSOR_SIZE", QByteArrayLiteral("24"));
0059     qputenv("KWIN_COMPOSE", m_envVariable);
0060 
0061     kwinApp()->start();
0062     QVERIFY(applicationStartedSpy.wait());
0063     QVERIFY(Compositor::self());
0064 
0065     QCOMPARE(Compositor::self()->backend()->compositingType(), KWin::OpenGLCompositing);
0066 }
0067 
0068 void GenericSceneOpenGLTest::testRestart()
0069 {
0070     // simple restart of the OpenGL compositor without any windows being shown
0071     QSignalSpy sceneCreatedSpy(KWin::Compositor::self(), &Compositor::sceneCreated);
0072     KWin::Compositor::self()->reinitialize();
0073     if (sceneCreatedSpy.isEmpty()) {
0074         QVERIFY(sceneCreatedSpy.wait());
0075     }
0076     QCOMPARE(sceneCreatedSpy.count(), 1);
0077     QCOMPARE(Compositor::self()->backend()->compositingType(), KWin::OpenGLCompositing);
0078 
0079     // trigger a repaint
0080     KWin::Compositor::self()->scene()->addRepaintFull();
0081     // and wait 100 msec to ensure it's rendered
0082     // TODO: introduce frameRendered signal in SceneOpenGL
0083     QTest::qWait(100);
0084 }