Simplify software cursor implementation
With RenderTarget, CursorView and CursorDelegate can be merged.
This commit is contained in:
parent
bfb60e3610
commit
bd689ef76c
10 changed files with 57 additions and 119 deletions
|
@ -36,9 +36,8 @@ target_sources(kwin PRIVATE
|
|||
client_machine.cpp
|
||||
composite.cpp
|
||||
cursor.cpp
|
||||
cursorview.cpp
|
||||
cursorview_opengl.cpp
|
||||
cursorview_qpainter.cpp
|
||||
cursordelegate_opengl.cpp
|
||||
cursordelegate_qpainter.cpp
|
||||
dbusinterface.cpp
|
||||
debug_console.cpp
|
||||
decorationitem.cpp
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <config-kwin.h>
|
||||
|
||||
#include "abstract_output.h"
|
||||
#include "cursorview_opengl.h"
|
||||
#include "cursorview_qpainter.h"
|
||||
#include "cursordelegate_opengl.h"
|
||||
#include "cursordelegate_qpainter.h"
|
||||
#include "dbusinterface.h"
|
||||
#include "decorations/decoratedclient.h"
|
||||
#include "deleted.h"
|
||||
|
@ -203,7 +203,6 @@ bool Compositor::attemptOpenGLCompositing()
|
|||
|
||||
m_backend = backend.take();
|
||||
m_scene = scene.take();
|
||||
m_cursorView = new OpenGLCursorView();
|
||||
|
||||
// set strict binding
|
||||
if (options->isGlStrictBindingFollowsDriver()) {
|
||||
|
@ -228,7 +227,6 @@ bool Compositor::attemptQPainterCompositing()
|
|||
|
||||
m_backend = backend.take();
|
||||
m_scene = scene.take();
|
||||
m_cursorView = new QPainterCursorView();
|
||||
|
||||
qCDebug(KWIN_CORE) << "QPainter compositing has been successfully initialized";
|
||||
return true;
|
||||
|
@ -441,7 +439,11 @@ void Compositor::addOutput(AbstractOutput *output)
|
|||
|
||||
auto cursorLayer = new RenderLayer(output->renderLoop());
|
||||
cursorLayer->setVisible(false);
|
||||
cursorLayer->setDelegate(new CursorDelegate(m_cursorView));
|
||||
if (m_backend->compositingType() == OpenGLCompositing) {
|
||||
cursorLayer->setDelegate(new CursorDelegateOpenGL());
|
||||
} else {
|
||||
cursorLayer->setDelegate(new CursorDelegateQPainter());
|
||||
}
|
||||
cursorLayer->setParent(workspaceLayer);
|
||||
cursorLayer->setSuperlayer(workspaceLayer);
|
||||
|
||||
|
@ -551,9 +553,6 @@ void Compositor::stop()
|
|||
delete m_scene;
|
||||
m_scene = nullptr;
|
||||
|
||||
delete m_cursorView;
|
||||
m_cursorView = nullptr;
|
||||
|
||||
delete m_backend;
|
||||
m_backend = nullptr;
|
||||
|
||||
|
|
|
@ -153,7 +153,6 @@ private:
|
|||
QList<xcb_atom_t> m_unusedSupportProperties;
|
||||
QTimer m_unusedSupportPropertyTimer;
|
||||
Scene *m_scene = nullptr;
|
||||
CursorView *m_cursorView = nullptr;
|
||||
RenderBackend *m_backend = nullptr;
|
||||
QHash<RenderLoop *, RenderLayer *> m_superlayers;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "cursorview_opengl.h"
|
||||
#include "cursordelegate_opengl.h"
|
||||
#include "cursor.h"
|
||||
#include "kwingltexture.h"
|
||||
#include "kwinglutils.h"
|
||||
|
@ -14,17 +14,21 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
OpenGLCursorView::OpenGLCursorView(QObject *parent)
|
||||
: CursorView(parent)
|
||||
CursorDelegateOpenGL::CursorDelegateOpenGL(QObject *parent)
|
||||
: RenderLayerDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
OpenGLCursorView::~OpenGLCursorView()
|
||||
CursorDelegateOpenGL::~CursorDelegateOpenGL()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLCursorView::paint(RenderLayer *renderLayer, RenderTarget *renderTarget, const QRegion ®ion)
|
||||
void CursorDelegateOpenGL::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
||||
{
|
||||
if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto allocateTexture = [this]() {
|
||||
const QImage img = Cursors::self()->currentCursor()->image();
|
||||
if (img.isNull()) {
|
||||
|
@ -54,7 +58,7 @@ void OpenGLCursorView::paint(RenderLayer *renderLayer, RenderTarget *renderTarge
|
|||
}
|
||||
}
|
||||
|
||||
const QRect cursorRect = renderLayer->mapToGlobal(renderLayer->rect());
|
||||
const QRect cursorRect = layer()->mapToGlobal(layer()->rect());
|
||||
|
||||
QMatrix4x4 mvp;
|
||||
mvp.ortho(QRect(QPoint(0, 0), renderTarget->size() / renderTarget->devicePixelRatio()));
|
|
@ -6,22 +6,22 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "cursorview.h"
|
||||
#include "renderlayerdelegate.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class GLTexture;
|
||||
|
||||
class OpenGLCursorView final : public CursorView
|
||||
class CursorDelegateOpenGL final : public RenderLayerDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenGLCursorView(QObject *parent = nullptr);
|
||||
~OpenGLCursorView() override;
|
||||
explicit CursorDelegateOpenGL(QObject *parent = nullptr);
|
||||
~CursorDelegateOpenGL() override;
|
||||
|
||||
void paint(RenderLayer *renderLayer, RenderTarget *renderTarget, const QRegion ®ion) override;
|
||||
void paint(RenderTarget *renderTarget, const QRegion ®ion) override;
|
||||
|
||||
private:
|
||||
QScopedPointer<GLTexture> m_cursorTexture;
|
|
@ -4,7 +4,7 @@
|
|||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "cursorview_qpainter.h"
|
||||
#include "cursordelegate_qpainter.h"
|
||||
#include "cursor.h"
|
||||
#include "renderlayer.h"
|
||||
#include "rendertarget.h"
|
||||
|
@ -14,13 +14,17 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
QPainterCursorView::QPainterCursorView(QObject *parent)
|
||||
: CursorView(parent)
|
||||
CursorDelegateQPainter::CursorDelegateQPainter(QObject *parent)
|
||||
: RenderLayerDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void QPainterCursorView::paint(RenderLayer *renderLayer, RenderTarget *renderTarget, const QRegion ®ion)
|
||||
void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
||||
{
|
||||
if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
QImage *buffer = std::get<QImage *>(renderTarget->nativeHandle());
|
||||
if (Q_UNLIKELY(!buffer)) {
|
||||
return;
|
||||
|
@ -29,7 +33,7 @@ void QPainterCursorView::paint(RenderLayer *renderLayer, RenderTarget *renderTar
|
|||
const Cursor *cursor = Cursors::self()->currentCursor();
|
||||
QPainter painter(buffer);
|
||||
painter.setClipRegion(region);
|
||||
painter.drawImage(renderLayer->mapToGlobal(renderLayer->rect()), cursor->image());
|
||||
painter.drawImage(layer()->mapToGlobal(layer()->rect()), cursor->image());
|
||||
}
|
||||
|
||||
} // namespace KWin
|
24
src/cursordelegate_qpainter.h
Normal file
24
src/cursordelegate_qpainter.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderlayerdelegate.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class CursorDelegateQPainter final : public RenderLayerDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CursorDelegateQPainter(QObject *parent = nullptr);
|
||||
|
||||
void paint(RenderTarget *renderTarget, const QRegion ®ion) override;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "cursorview.h"
|
||||
#include "renderlayer.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
CursorView::CursorView(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
CursorDelegate::CursorDelegate(CursorView *view)
|
||||
: m_view(view)
|
||||
{
|
||||
}
|
||||
|
||||
void CursorDelegate::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
||||
{
|
||||
if (region.intersects(layer()->mapToGlobal(layer()->rect()))) {
|
||||
m_view->paint(layer(), renderTarget, region);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace KWin
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderlayerdelegate.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class KWIN_EXPORT CursorView : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CursorView(QObject *parent = nullptr);
|
||||
|
||||
virtual void paint(RenderLayer *layer, RenderTarget *renderTarget, const QRegion ®ion) = 0;
|
||||
};
|
||||
|
||||
class KWIN_EXPORT CursorDelegate : public RenderLayerDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CursorDelegate(CursorView *view);
|
||||
|
||||
void paint(RenderTarget *renderTarget, const QRegion ®ion) override;
|
||||
|
||||
private:
|
||||
CursorView *m_view;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cursorview.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class QPainterCursorView final : public CursorView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QPainterCursorView(QObject *parent = nullptr);
|
||||
|
||||
void paint(RenderLayer *renderLayer, RenderTarget *renderTarget, const QRegion ®ion) override;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
Loading…
Reference in a new issue