Commit 61b1eac5 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

platform, scenes: use std::unique_ptr for creation functions

parent f50547de
Pipeline #206534 passed with stage
in 25 minutes and 10 seconds
......@@ -549,19 +549,19 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable)
}
}
InputBackend *DrmBackend::createInputBackend()
std::unique_ptr<InputBackend> DrmBackend::createInputBackend()
{
return new LibinputBackend();
return std::make_unique<LibinputBackend>();
}
QPainterBackend *DrmBackend::createQPainterBackend()
std::unique_ptr<QPainterBackend> DrmBackend::createQPainterBackend()
{
return new DrmQPainterBackend(this);
return std::make_unique<DrmQPainterBackend>(this);
}
OpenGLBackend *DrmBackend::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> DrmBackend::createOpenGLBackend()
{
return new EglGbmBackend(this);
return std::make_unique<EglGbmBackend>(this);
}
void DrmBackend::sceneInitialized()
......
......@@ -43,9 +43,9 @@ public:
explicit DrmBackend(QObject *parent = nullptr);
~DrmBackend() override;
InputBackend *createInputBackend() override;
QPainterBackend *createQPainterBackend() override;
OpenGLBackend *createOpenGLBackend() override;
std::unique_ptr<InputBackend> createInputBackend() override;
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier) override;
......
......@@ -80,14 +80,14 @@ QString VirtualBackend::screenshotDirPath() const
return m_screenshotDir->path();
}
QPainterBackend *VirtualBackend::createQPainterBackend()
std::unique_ptr<QPainterBackend> VirtualBackend::createQPainterBackend()
{
return new VirtualQPainterBackend(this);
return std::make_unique<VirtualQPainterBackend>(this);
}
OpenGLBackend *VirtualBackend::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> VirtualBackend::createOpenGLBackend()
{
return new VirtualEglBackend(this);
return std::make_unique<VirtualEglBackend>(this);
}
Outputs VirtualBackend::outputs() const
......
......@@ -41,8 +41,8 @@ public:
}
QString screenshotDirPath() const;
QPainterBackend *createQPainterBackend() override;
OpenGLBackend *createOpenGLBackend() override;
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
Q_INVOKABLE void setVirtualOutputs(int count, QVector<QRect> geometries = QVector<QRect>(), QVector<int> scales = QVector<int>());
......
......@@ -846,23 +846,23 @@ void WaylandBackend::destroyOutputs()
}
}
InputBackend *WaylandBackend::createInputBackend()
std::unique_ptr<InputBackend> WaylandBackend::createInputBackend()
{
return new WaylandInputBackend(this);
return std::make_unique<WaylandInputBackend>(this);
}
OpenGLBackend *WaylandBackend::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> WaylandBackend::createOpenGLBackend()
{
#if HAVE_WAYLAND_EGL
return new WaylandEglBackend(this);
return std::make_unique<WaylandEglBackend>(this);
#else
return nullptr;
#endif
}
QPainterBackend *WaylandBackend::createQPainterBackend()
std::unique_ptr<QPainterBackend> WaylandBackend::createQPainterBackend()
{
return new WaylandQPainterBackend(this);
return std::make_unique<WaylandQPainterBackend>(this);
}
void WaylandBackend::flush()
......
......@@ -259,9 +259,9 @@ public:
KWayland::Client::SubCompositor *subCompositor();
KWayland::Client::ShmPool *shmPool();
InputBackend *createInputBackend() override;
OpenGLBackend *createOpenGLBackend() override;
QPainterBackend *createQPainterBackend() override;
std::unique_ptr<InputBackend> createInputBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
void flush();
......
......@@ -157,13 +157,13 @@ Session *X11StandalonePlatform::session() const
return m_session.get();
}
OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> X11StandalonePlatform::createOpenGLBackend()
{
switch (options->glPlatformInterface()) {
#if HAVE_EPOXY_GLX
case GlxPlatformInterface:
if (hasGlx()) {
return new GlxBackend(m_x11Display, this);
return std::make_unique<GlxBackend>(m_x11Display, this);
} else {
qCWarning(KWIN_X11STANDALONE) << "Glx not available, trying EGL instead.";
// no break, needs fall-through
......@@ -171,7 +171,7 @@ OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
}
#endif
case EglPlatformInterface:
return new EglBackend(m_x11Display, this);
return std::make_unique<EglBackend>(m_x11Display, this);
default:
// no backend available
return nullptr;
......
......@@ -38,7 +38,7 @@ public:
bool initialize() override;
Session *session() const override;
OpenGLBackend *createOpenGLBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
Edge *createScreenEdge(ScreenEdges *parent) override;
void createPlatformCursor(QObject *parent = nullptr) override;
bool requiresCompositing() const override;
......
......@@ -662,19 +662,19 @@ X11WindowedInputDevice *X11WindowedBackend::touchDevice() const
return m_touchDevice;
}
OpenGLBackend *X11WindowedBackend::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> X11WindowedBackend::createOpenGLBackend()
{
return new X11WindowedEglBackend(this);
return std::make_unique<X11WindowedEglBackend>(this);
}
QPainterBackend *X11WindowedBackend::createQPainterBackend()
std::unique_ptr<QPainterBackend> X11WindowedBackend::createQPainterBackend()
{
return new X11WindowedQPainterBackend(this);
return std::make_unique<X11WindowedQPainterBackend>(this);
}
InputBackend *X11WindowedBackend::createInputBackend()
std::unique_ptr<InputBackend> X11WindowedBackend::createInputBackend()
{
return new X11WindowedInputBackend(this);
return std::make_unique<X11WindowedInputBackend>(this);
}
void X11WindowedBackend::warpPointer(const QPointF &globalPos)
......
......@@ -115,9 +115,9 @@ public:
return m_hasXInput;
}
OpenGLBackend *createOpenGLBackend() override;
QPainterBackend *createQPainterBackend() override;
InputBackend *createInputBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
std::unique_ptr<InputBackend> createInputBackend() override;
void warpPointer(const QPointF &globalPos) override;
QVector<CompositingType> supportedCompositors() const override
......
......@@ -186,7 +186,7 @@ bool Compositor::attemptOpenGLCompositing()
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit);
});
QScopedPointer<OpenGLBackend> backend(kwinApp()->platform()->createOpenGLBackend());
std::unique_ptr<OpenGLBackend> backend = kwinApp()->platform()->createOpenGLBackend();
if (!backend) {
return false;
}
......@@ -197,13 +197,13 @@ bool Compositor::attemptOpenGLCompositing()
return false;
}
QScopedPointer<Scene> scene(SceneOpenGL::createScene(backend.data(), this));
std::unique_ptr<Scene> scene = SceneOpenGL::createScene(backend.get());
if (!scene || scene->initFailed()) {
return false;
}
m_backend = backend.take();
m_scene = scene.take();
m_backend = std::move(backend);
m_scene = std::move(scene);
// set strict binding
if (options->isGlStrictBindingFollowsDriver()) {
......@@ -216,18 +216,18 @@ bool Compositor::attemptOpenGLCompositing()
bool Compositor::attemptQPainterCompositing()
{
QScopedPointer<QPainterBackend> backend(kwinApp()->platform()->createQPainterBackend());
std::unique_ptr<QPainterBackend> backend(kwinApp()->platform()->createQPainterBackend());
if (!backend || backend->isFailed()) {
return false;
}
QScopedPointer<Scene> scene(SceneQPainter::createScene(backend.data(), this));
std::unique_ptr<Scene> scene = SceneQPainter::createScene(backend.get());
if (!scene || scene->initFailed()) {
return false;
}
m_backend = backend.take();
m_scene = scene.take();
m_backend = std::move(backend);
m_scene = std::move(scene);
qCDebug(KWIN_CORE) << "QPainter compositing has been successfully initialized";
return true;
......@@ -366,7 +366,7 @@ void Compositor::startupWithWorkspace()
const QVector<Output *> outputs = kwinApp()->platform()->enabledOutputs();
if (kwinApp()->operationMode() == Application::OperationModeX11) {
auto workspaceLayer = new RenderLayer(outputs.constFirst()->renderLoop());
workspaceLayer->setDelegate(new SceneDelegate(m_scene));
workspaceLayer->setDelegate(new SceneDelegate(m_scene.get()));
workspaceLayer->setGeometry(workspace()->geometry());
connect(workspace(), &Workspace::geometryChanged, workspaceLayer, [workspaceLayer]() {
workspaceLayer->setGeometry(workspace()->geometry());
......@@ -400,7 +400,7 @@ void Compositor::startupWithWorkspace()
}
// Sets also the 'effects' pointer.
kwinApp()->platform()->createEffectsHandler(this, m_scene);
kwinApp()->platform()->createEffectsHandler(this, m_scene.get());
Q_EMIT compositingToggled(true);
......@@ -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, output));
workspaceLayer->setDelegate(new SceneDelegate(m_scene.get(), output));
workspaceLayer->setGeometry(output->rect());
connect(output, &Output::geometryChanged, workspaceLayer, [output, workspaceLayer]() {
workspaceLayer->setGeometry(output->rect());
......@@ -531,11 +531,8 @@ void Compositor::stop()
disconnect(kwinApp()->platform(), &Platform::outputEnabled, this, &Compositor::addOutput);
disconnect(kwinApp()->platform(), &Platform::outputDisabled, this, &Compositor::removeOutput);
delete m_scene;
m_scene = nullptr;
delete m_backend;
m_backend = nullptr;
m_scene.reset();
m_backend.reset();
m_state = State::Off;
Q_EMIT compositingToggled(false);
......
......@@ -14,6 +14,7 @@
#include <QObject>
#include <QRegion>
#include <QTimer>
#include <memory>
namespace KWin
{
......@@ -70,11 +71,11 @@ public:
Scene *scene() const
{
return m_scene;
return m_scene.get();
}
RenderBackend *backend() const
{
return m_backend;
return m_backend.get();
}
/**
......@@ -152,8 +153,8 @@ private:
QTimer m_releaseSelectionTimer;
QList<xcb_atom_t> m_unusedSupportProperties;
QTimer m_unusedSupportPropertyTimer;
Scene *m_scene = nullptr;
RenderBackend *m_backend = nullptr;
std::unique_ptr<Scene> m_scene;
std::unique_ptr<RenderBackend> m_backend;
QHash<RenderLoop *, RenderLayer *> m_superlayers;
};
......
......@@ -2573,7 +2573,6 @@ InputRedirection::InputRedirection(QObject *parent)
InputRedirection::~InputRedirection()
{
qDeleteAll(m_inputBackends);
m_inputBackends.clear();
m_inputDevices.clear();
......@@ -3066,26 +3065,25 @@ void InputRedirection::disableTouchpads()
}
}
void InputRedirection::addInputBackend(InputBackend *inputBackend)
void InputRedirection::addInputBackend(std::unique_ptr<InputBackend> &&inputBackend)
{
Q_ASSERT(!m_inputBackends.contains(inputBackend));
m_inputBackends.append(inputBackend);
connect(inputBackend, &InputBackend::deviceAdded, this, &InputRedirection::addInputDevice);
connect(inputBackend, &InputBackend::deviceRemoved, this, &InputRedirection::removeInputDevice);
connect(inputBackend.get(), &InputBackend::deviceAdded, this, &InputRedirection::addInputDevice);
connect(inputBackend.get(), &InputBackend::deviceRemoved, this, &InputRedirection::removeInputDevice);
inputBackend->setConfig(InputConfig::self()->inputConfig());
inputBackend->initialize();
m_inputBackends.push_back(std::move(inputBackend));
}
void InputRedirection::setupInputBackends()
{
InputBackend *inputBackend = kwinApp()->platform()->createInputBackend();
std::unique_ptr<InputBackend> inputBackend = kwinApp()->platform()->createInputBackend();
if (inputBackend) {
addInputBackend(inputBackend);
addInputBackend(std::move(inputBackend));
}
if (waylandServer()) {
addInputBackend(new FakeInputBackend());
addInputBackend(std::make_unique<FakeInputBackend>());
}
}
......
......@@ -322,7 +322,7 @@ private:
void installInputEventFilter(InputEventFilter *filter);
void updateLeds(LEDs leds);
void updateAvailableInputDevices();
void addInputBackend(InputBackend *inputBackend);
void addInputBackend(std::unique_ptr<InputBackend> &&inputBackend);
KeyboardInputRedirection *m_keyboard;
PointerInputRedirection *m_pointer;
TabletInputRedirection *m_tablet;
......@@ -331,7 +331,7 @@ private:
GlobalShortcutsManager *m_shortcuts;
QList<InputBackend *> m_inputBackends;
std::vector<std::unique_ptr<InputBackend>> m_inputBackends;
QList<InputDevice *> m_inputDevices;
QList<IdleDetector *> m_idleDetectors;
......
......@@ -15,11 +15,14 @@
#include "cursor.h"
#include "dmabuftexture.h"
#include "effects.h"
#include "inputbackend.h"
#include "openglbackend.h"
#include "outline.h"
#include "output.h"
#include "outputconfiguration.h"
#include "overlaywindow.h"
#include "pointer_input.h"
#include "qpainterbackend.h"
#include "scene.h"
#include "screenedge.h"
#include "screens.h"
......@@ -66,17 +69,17 @@ PlatformCursorImage Platform::cursorImage() const
return PlatformCursorImage(cursor->image(), cursor->hotspot());
}
InputBackend *Platform::createInputBackend()
std::unique_ptr<InputBackend> Platform::createInputBackend()
{
return nullptr;
}
OpenGLBackend *Platform::createOpenGLBackend()
std::unique_ptr<OpenGLBackend> Platform::createOpenGLBackend()
{
return nullptr;
}
QPainterBackend *Platform::createQPainterBackend()
std::unique_ptr<QPainterBackend> Platform::createQPainterBackend()
{
return nullptr;
}
......
......@@ -66,9 +66,9 @@ public:
virtual Session *session() const = 0;
virtual bool initialize() = 0;
virtual InputBackend *createInputBackend();
virtual OpenGLBackend *createOpenGLBackend();
virtual QPainterBackend *createQPainterBackend();
virtual std::unique_ptr<InputBackend> createInputBackend();
virtual std::unique_ptr<OpenGLBackend> createOpenGLBackend();
virtual std::unique_ptr<QPainterBackend> createQPainterBackend();
virtual std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers);
virtual std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier);
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const DmaBufParams &attributes);
......
......@@ -131,10 +131,7 @@ QRect SceneDelegate::viewport() const
// Scene
//****************************************
Scene::Scene(QObject *parent)
: QObject(parent)
{
}
Scene::Scene() = default;
Scene::~Scene()
{
......
......@@ -72,7 +72,7 @@ class KWIN_EXPORT Scene : public QObject
Q_OBJECT
public:
explicit Scene(QObject *parent = nullptr);
explicit Scene();
~Scene() override;
void initialize();
......
......@@ -45,9 +45,8 @@ namespace KWin
* SceneOpenGL
***********************************************/
SceneOpenGL::SceneOpenGL(OpenGLBackend *backend, QObject *parent)
: Scene(parent)
, m_backend(backend)
SceneOpenGL::SceneOpenGL(OpenGLBackend *backend)
: m_backend(backend)
{
// We only support the OpenGL 2+ shader API, not GL_ARB_shader_objects
if (!hasGLVersion(2, 0)) {
......@@ -70,13 +69,13 @@ SceneOpenGL::~SceneOpenGL()
}
}
SceneOpenGL *SceneOpenGL::createScene(OpenGLBackend *backend, QObject *parent)
std::unique_ptr<SceneOpenGL> SceneOpenGL::createScene(OpenGLBackend *backend)
{
if (SceneOpenGL::supported(backend)) {
return new SceneOpenGL(backend, parent);
return std::make_unique<SceneOpenGL>(backend);
} else {
return nullptr;
}
return nullptr;
}
bool SceneOpenGL::initFailed() const
......
......@@ -49,7 +49,7 @@ public:
const bool hardwareClipping;
};
explicit SceneOpenGL(OpenGLBackend *backend, QObject *parent = nullptr);
explicit SceneOpenGL(OpenGLBackend *backend);
~SceneOpenGL() override;
bool initFailed() const override;
void paint(RenderTarget *renderTarget, const QRegion &region) override;
......@@ -72,7 +72,7 @@ public:
QVector<QByteArray> openGLPlatformInterfaceExtensions() const override;
std::shared_ptr<GLTexture> textureForOutput(Output *output) const override;
static SceneOpenGL *createScene(OpenGLBackend *backend, QObject *parent);
static std::unique_ptr<SceneOpenGL> createScene(OpenGLBackend *backend);
static bool supported(OpenGLBackend *backend);
protected:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment