plugins: add effect that shows when compositing is active

It just shows "Compositing" in the corner and doesn't block direct scanout.
When direct scanout is active, the "Compositing" text isn't visible anymore.

This is useful for debugging performance or power draw issues.
This commit is contained in:
Xaver Hugl 2024-08-02 00:03:18 +02:00
parent 1d9d809dfd
commit 20dc8f1684
7 changed files with 152 additions and 0 deletions

View file

@ -91,6 +91,7 @@ add_subdirectory(screentransform)
add_subdirectory(sessionquit)
add_subdirectory(shakecursor)
add_subdirectory(sheet)
add_subdirectory(showcompositing)
add_subdirectory(showfps)
add_subdirectory(showpaint)
add_subdirectory(slide)

View file

@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
# SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com>
#
# SPDX-License-Identifier: BSD-3-Clause
set(showcompositing_SOURCES
main.cpp
showcompositing.cpp
)
kwin_add_builtin_effect(showcompositing ${showcompositing_SOURCES})
target_link_libraries(showcompositing PRIVATE
kwin
KF6::I18n
Qt::Quick
)
install(DIRECTORY qml DESTINATION ${KDE_INSTALL_DATADIR}/kwin/effects/showcompositing)

View file

@ -0,0 +1,18 @@
/*
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "showcompositing.h"
namespace KWin
{
KWIN_EFFECT_FACTORY_SUPPORTED(ShowCompositingEffect,
"metadata.json.stripped",
return ShowCompositingEffect::supported();)
} // namespace KWin
#include "main.moc"

View file

@ -0,0 +1,9 @@
{
"KPlugin": {
"Category": "Tools",
"Description": "Display if compositing is active",
"EnabledByDefault": false,
"License": "GPL",
"Name": "Show Compositing"
}
}

View file

@ -0,0 +1,15 @@
/*
SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick
Text {
color: Qt.rgba(1.0, 0.0, 0.0, 1.0)
text: i18nc("@label", "Compositing")
fontSizeMode: Text.Fit
font.pointSize: 100
}

View file

@ -0,0 +1,55 @@
/*
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "showcompositing.h"
#include "core/output.h"
#include "core/renderviewport.h"
#include "effect/effecthandler.h"
namespace KWin
{
ShowCompositingEffect::ShowCompositingEffect()
{
}
ShowCompositingEffect::~ShowCompositingEffect() = default;
void ShowCompositingEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
effects->prePaintScreen(data, presentTime);
if (!m_scene) {
m_scene = std::make_unique<OffscreenQuickScene>();
m_scene->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/effects/showcompositing/qml/main.qml"))));
}
}
void ShowCompositingEffect::paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen)
{
effects->paintScreen(renderTarget, viewport, mask, region, screen);
const auto rect = viewport.renderRect();
m_scene->setGeometry(QRect(rect.x() + rect.width() - 300, 0, 300, 150));
effects->renderOffscreenQuickView(renderTarget, viewport, m_scene.get());
}
bool ShowCompositingEffect::supported()
{
return effects->isOpenGLCompositing();
}
bool ShowCompositingEffect::blocksDirectScanout() const
{
// this is intentionally wrong, as we want direct scanout to change the image
// with this effect
return false;
}
} // namespace KWin
#include "moc_showcompositing.cpp"

View file

@ -0,0 +1,35 @@
/*
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
SPDX-FileCopyrightText: 2024 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "effect/effect.h"
#include "effect/offscreenquickview.h"
namespace KWin
{
class ShowCompositingEffect : public Effect
{
Q_OBJECT
public:
ShowCompositingEffect();
~ShowCompositingEffect() override;
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override;
bool blocksDirectScanout() const override;
static bool supported();
private:
std::unique_ptr<OffscreenQuickScene> m_scene;
};
} // namespace KWin