core/renderlayerdelegate: remove QObject parent

Managing an object with both std::unique_ptr and a QObject parent at the
same time is unnecessary and potentially dangerous
This commit is contained in:
Xaver Hugl 2022-12-20 02:23:21 +01:00
parent 5553d0e0f4
commit f90ec209d4
11 changed files with 17 additions and 43 deletions

View file

@ -366,7 +366,7 @@ void Compositor::startupWithWorkspace()
const QList<Output *> outputs = workspace()->outputs();
if (kwinApp()->operationMode() == Application::OperationModeX11) {
auto workspaceLayer = new RenderLayer(outputs.constFirst()->renderLoop());
workspaceLayer->setDelegate(new SceneDelegate(m_scene.get()));
workspaceLayer->setDelegate(std::make_unique<SceneDelegate>(m_scene.get()));
workspaceLayer->setGeometry(workspace()->geometry());
connect(workspace(), &Workspace::geometryChanged, workspaceLayer, [workspaceLayer]() {
workspaceLayer->setGeometry(workspace()->geometry());
@ -425,7 +425,7 @@ void Compositor::addOutput(Output *output)
Q_ASSERT(kwinApp()->operationMode() != Application::OperationModeX11);
auto workspaceLayer = new RenderLayer(output->renderLoop());
workspaceLayer->setDelegate(new SceneDelegate(m_scene.get(), output));
workspaceLayer->setDelegate(std::make_unique<SceneDelegate>(m_scene.get(), output));
workspaceLayer->setGeometry(output->rect());
connect(output, &Output::geometryChanged, workspaceLayer, [output, workspaceLayer]() {
workspaceLayer->setGeometry(output->rect());
@ -434,9 +434,9 @@ void Compositor::addOutput(Output *output)
auto cursorLayer = new RenderLayer(output->renderLoop());
cursorLayer->setVisible(false);
if (m_backend->compositingType() == OpenGLCompositing) {
cursorLayer->setDelegate(new CursorDelegateOpenGL());
cursorLayer->setDelegate(std::make_unique<CursorDelegateOpenGL>());
} else {
cursorLayer->setDelegate(new CursorDelegateQPainter());
cursorLayer->setDelegate(std::make_unique<CursorDelegateQPainter>());
}
cursorLayer->setParent(workspaceLayer);
cursorLayer->setSuperlayer(workspaceLayer);

View file

@ -95,9 +95,9 @@ RenderLayerDelegate *RenderLayer::delegate() const
return m_delegate.get();
}
void RenderLayer::setDelegate(RenderLayerDelegate *delegate)
void RenderLayer::setDelegate(std::unique_ptr<RenderLayerDelegate> delegate)
{
m_delegate.reset(delegate);
m_delegate = std::move(delegate);
m_delegate->setLayer(this);
}

View file

@ -45,7 +45,7 @@ public:
RenderLoop *loop() const;
RenderLayerDelegate *delegate() const;
void setDelegate(RenderLayerDelegate *delegate);
void setDelegate(std::unique_ptr<RenderLayerDelegate> delegate);
QList<RenderLayer *> sublayers() const;
RenderLayer *superlayer() const;

View file

@ -9,11 +9,6 @@
namespace KWin
{
RenderLayerDelegate::RenderLayerDelegate(QObject *parent)
: QObject(parent)
{
}
RenderLayer *RenderLayerDelegate::layer() const
{
return m_layer;

View file

@ -8,7 +8,6 @@
#include "kwin_export.h"
#include <QObject>
#include <QRegion>
namespace KWin
@ -21,12 +20,10 @@ class SurfaceItem;
/**
* The RenderLayerDelegate class represents a render layer's contents.
*/
class KWIN_EXPORT RenderLayerDelegate : public QObject
class KWIN_EXPORT RenderLayerDelegate
{
Q_OBJECT
public:
explicit RenderLayerDelegate(QObject *parent = nullptr);
virtual ~RenderLayerDelegate() = default;
RenderLayer *layer() const;
void setLayer(RenderLayer *layer);

View file

@ -14,11 +14,6 @@
namespace KWin
{
CursorDelegateOpenGL::CursorDelegateOpenGL(QObject *parent)
: RenderLayerDelegate(parent)
{
}
CursorDelegateOpenGL::~CursorDelegateOpenGL()
{
}

View file

@ -5,6 +5,7 @@
*/
#pragma once
#include <QObject>
#include <memory>
#include "core/renderlayerdelegate.h"
@ -14,12 +15,11 @@ namespace KWin
class GLTexture;
class CursorDelegateOpenGL final : public RenderLayerDelegate
class CursorDelegateOpenGL final : public QObject, public RenderLayerDelegate
{
Q_OBJECT
public:
explicit CursorDelegateOpenGL(QObject *parent = nullptr);
~CursorDelegateOpenGL() override;
void paint(RenderTarget *renderTarget, const QRegion &region) override;

View file

@ -14,11 +14,6 @@
namespace KWin
{
CursorDelegateQPainter::CursorDelegateQPainter(QObject *parent)
: RenderLayerDelegate(parent)
{
}
void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion &region)
{
if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) {

View file

@ -13,11 +13,7 @@ namespace KWin
class CursorDelegateQPainter final : public RenderLayerDelegate
{
Q_OBJECT
public:
explicit CursorDelegateQPainter(QObject *parent = nullptr);
void paint(RenderTarget *renderTarget, const QRegion &region) override;
};

View file

@ -79,16 +79,14 @@
namespace KWin
{
SceneDelegate::SceneDelegate(Scene *scene, QObject *parent)
: RenderLayerDelegate(parent)
, m_scene(scene)
SceneDelegate::SceneDelegate(Scene *scene)
: m_scene(scene)
{
m_scene->addDelegate(this);
}
SceneDelegate::SceneDelegate(Scene *scene, Output *output, QObject *parent)
: RenderLayerDelegate(parent)
, m_scene(scene)
SceneDelegate::SceneDelegate(Scene *scene, Output *output)
: m_scene(scene)
, m_output(output)
{
m_scene->addDelegate(this);

View file

@ -44,11 +44,9 @@ class WindowItem;
class SceneDelegate : public RenderLayerDelegate
{
Q_OBJECT
public:
explicit SceneDelegate(Scene *scene, QObject *parent = nullptr);
explicit SceneDelegate(Scene *scene, Output *output, QObject *parent = nullptr);
explicit SceneDelegate(Scene *scene);
explicit SceneDelegate(Scene *scene, Output *output);
~SceneDelegate() override;
Output *output() const;