Commit c737fde3 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

DRM: Use QSharedPointer

parent 5c15cca1
......@@ -23,9 +23,6 @@ public:
virtual ~DrmBuffer() = default;
virtual bool needsModeChange(DrmBuffer *b) const {Q_UNUSED(b) return false;}
virtual bool shouldDeleteAfterPageflip() const {
return false;
}
quint32 bufferId() const {
return m_bufferId;
......
......@@ -28,7 +28,7 @@ namespace KWin
{
// DrmSurfaceBuffer
DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const std::shared_ptr<GbmSurface> &surface)
DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const QSharedPointer<GbmSurface> &surface)
: DrmBuffer(fd)
, m_surface(surface)
{
......
......@@ -12,7 +12,7 @@
#include "drm_buffer.h"
#include <memory>
#include <QSharedPointer>
struct gbm_bo;
......@@ -29,7 +29,7 @@ class GbmSurface;
class DrmSurfaceBuffer : public DrmBuffer
{
public:
DrmSurfaceBuffer(int fd, const std::shared_ptr<GbmSurface> &surface);
DrmSurfaceBuffer(int fd, const QSharedPointer<GbmSurface> &surface);
DrmSurfaceBuffer(int fd, gbm_bo *buffer, KWaylandServer::BufferInterface *bufferInterface);
~DrmSurfaceBuffer() override;
......@@ -40,9 +40,6 @@ public:
return true;
}
}
bool shouldDeleteAfterPageflip() const override {
return true;
}
bool hasBo() const {
return m_bo != nullptr;
......@@ -55,7 +52,7 @@ public:
void releaseGbm() override;
private:
std::shared_ptr<GbmSurface> m_surface;
QSharedPointer<GbmSurface> m_surface;
gbm_bo *m_bo = nullptr;
KWaylandServer::BufferInterface *m_bufferInterface = nullptr;
......
......@@ -82,10 +82,6 @@ public:
m_eglDisplay = display;
}
DrmDumbBuffer *createBuffer(const QSize &size) const {
return new DrmDumbBuffer(m_fd, size);
}
void setEglBackend(AbstractEglBackend *eglBackend) {
m_eglBackend = eglBackend;
}
......
......@@ -67,9 +67,6 @@ bool DrmCrtc::initProps()
void DrmCrtc::flipBuffer()
{
if (m_currentBuffer && m_currentBuffer->shouldDeleteAfterPageflip() && m_currentBuffer != m_nextBuffer) {
delete m_currentBuffer;
}
m_currentBuffer = m_nextBuffer;
m_nextBuffer = nullptr;
......@@ -84,7 +81,7 @@ bool DrmCrtc::blank(DrmOutput *output)
}
if (!m_blackBuffer) {
DrmDumbBuffer *blackBuffer = m_gpu->createBuffer(output->pixelSize());
DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(m_gpu->fd(), output->pixelSize());
if (!blackBuffer->map()) {
delete blackBuffer;
return false;
......@@ -94,10 +91,6 @@ bool DrmCrtc::blank(DrmOutput *output)
}
if (output->setModeLegacy(m_blackBuffer)) {
if (m_currentBuffer && m_currentBuffer->shouldDeleteAfterPageflip()) {
delete m_currentBuffer;
delete m_nextBuffer;
}
m_currentBuffer = nullptr;
m_nextBuffer = nullptr;
return true;
......
......@@ -11,6 +11,8 @@
#include "drm_object.h"
#include <QSharedPointer>
namespace KWin
{
......@@ -41,13 +43,13 @@ public:
return m_resIndex;
}
DrmBuffer *current() {
QSharedPointer<DrmBuffer> current() {
return m_currentBuffer;
}
DrmBuffer *next() {
QSharedPointer<DrmBuffer> next() {
return m_nextBuffer;
}
void setNext(DrmBuffer *buffer) {
void setNext(const QSharedPointer<DrmBuffer> &buffer) {
m_nextBuffer = buffer;
}
......@@ -67,8 +69,8 @@ private:
int m_resIndex;
uint32_t m_gammaRampSize = 0;
DrmBuffer *m_currentBuffer = nullptr;
DrmBuffer *m_nextBuffer = nullptr;
QSharedPointer<DrmBuffer> m_currentBuffer;
QSharedPointer<DrmBuffer> m_nextBuffer;
DrmDumbBuffer *m_blackBuffer = nullptr;
DrmBackend *m_backend;
DrmGpu *m_gpu;
......
......@@ -19,12 +19,6 @@ DrmPlane::DrmPlane(uint32_t plane_id, int fd)
{
}
DrmPlane::~DrmPlane()
{
delete m_current;
delete m_next;
}
bool DrmPlane::init()
{
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
......@@ -137,7 +131,7 @@ DrmPlane::TypeIndex DrmPlane::type()
return TypeIndex::Overlay;
}
void DrmPlane::setNext(DrmBuffer *b)
void DrmPlane::setNext(const QSharedPointer<DrmBuffer> &b)
{
if (auto property = m_props.at(int(PropertyIndex::FbId))) {
property->setValue(b ? b->bufferId() : 0);
......@@ -164,9 +158,6 @@ DrmPlane::Transformations DrmPlane::transformation()
void DrmPlane::flipBuffer()
{
if (m_current != m_next && m_current && m_current->shouldDeleteAfterPageflip()) {
delete m_current;
}
m_current = m_next;
m_next = nullptr;
}
......
......@@ -12,6 +12,7 @@
#include <qobjectdefs.h>
#include <xf86drmMode.h>
#include <QSharedPointer>
namespace KWin
{
......@@ -24,8 +25,6 @@ class DrmPlane : public DrmObject
public:
DrmPlane(uint32_t plane_id, int fd);
~DrmPlane() override;
enum class PropertyIndex {
Type = 0,
SrcX,
......@@ -73,16 +72,16 @@ public:
return m_formats;
}
DrmBuffer *current() const {
QSharedPointer<DrmBuffer> current() const {
return m_current;
}
DrmBuffer *next() const {
QSharedPointer<DrmBuffer> next() const {
return m_next;
}
void setCurrent(DrmBuffer *b) {
void setCurrent(const QSharedPointer<DrmBuffer> &b) {
m_current = b;
}
void setNext(DrmBuffer *b);
void setNext(const QSharedPointer<DrmBuffer> &b);
void setTransformation(Transformations t);
Transformations transformation();
......@@ -95,8 +94,8 @@ public:
bool atomicPopulate(drmModeAtomicReq *req) const override;
private:
DrmBuffer *m_current = nullptr;
DrmBuffer *m_next = nullptr;
QSharedPointer<DrmBuffer> m_current;
QSharedPointer<DrmBuffer> m_next;
// TODO: See weston drm_output_check_plane_format for future use of these member variables
QVector<uint32_t> m_formats; // Possible formats, which can be presented on this plane
......
......@@ -70,9 +70,6 @@ void DrmOutput::teardown()
if (m_primaryPlane) {
// TODO: when having multiple planes, also clean up these
if (m_primaryPlane->current() && m_primaryPlane->current()->shouldDeleteAfterPageflip()) {
delete m_primaryPlane->current();
}
m_primaryPlane->setCurrent(nullptr);
}
......@@ -86,7 +83,7 @@ void DrmOutput::teardown()
void DrmOutput::releaseGbm()
{
if (DrmBuffer *b = m_crtc->current()) {
if (const auto &b = m_crtc->current()) {
b->releaseGbm();
}
if (m_primaryPlane && m_primaryPlane->current()) {
......@@ -362,7 +359,7 @@ void DrmOutput::initEdid(drmModeConnector *connector)
bool DrmOutput::initCursor(const QSize &cursorSize)
{
auto createCursor = [this, cursorSize] (int index) {
m_cursor[index].reset(m_gpu->createBuffer(cursorSize));
m_cursor[index].reset(new DrmDumbBuffer(m_gpu->fd(), cursorSize));
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
return false;
}
......@@ -684,7 +681,7 @@ void DrmOutput::pageFlipped()
} else {
if (!m_crtc->next()) {
// on manual vt switch
if (DrmBuffer *b = m_crtc->current()) {
if (const auto &b = m_crtc->current()) {
b->releaseGbm();
}
}
......@@ -696,27 +693,15 @@ void DrmOutput::pageFlipped()
}
}
bool DrmOutput::present(DrmBuffer *buffer)
bool DrmOutput::present(const QSharedPointer<DrmBuffer> &buffer)
{
if (!buffer || buffer->bufferId() == 0) {
if (buffer && buffer->shouldDeleteAfterPageflip()) {
delete buffer;
}
return false;
}
if (m_dpmsModePending != DpmsMode::On) {
return false;
}
bool result;
if (m_gpu->atomicModeSetting()) {
result = presentAtomically(buffer);
} else {
result = presentLegacy(buffer);
}
if (!result && buffer->shouldDeleteAfterPageflip()) {
delete buffer;
}
return result;
return m_gpu->atomicModeSetting() ? presentAtomically(buffer) : presentLegacy(buffer);
}
bool DrmOutput::dpmsAtomicOff()
......@@ -724,7 +709,6 @@ bool DrmOutput::dpmsAtomicOff()
m_atomicOffPending = false;
// TODO: With multiple planes: deactivate all of them here
delete m_primaryPlane->next();
m_primaryPlane->setNext(nullptr);
m_nextPlanesFlipList << m_primaryPlane;
......@@ -742,7 +726,7 @@ bool DrmOutput::dpmsAtomicOff()
return true;
}
bool DrmOutput::presentAtomically(DrmBuffer *buffer)
bool DrmOutput::presentAtomically(const QSharedPointer<DrmBuffer> &buffer)
{
if (!m_backend->session()->isActive()) {
qCWarning(KWIN_DRM) << "Refusing to present output because session is inactive";
......@@ -810,7 +794,7 @@ bool DrmOutput::presentAtomically(DrmBuffer *buffer)
return true;
}
bool DrmOutput::presentLegacy(DrmBuffer *buffer)
bool DrmOutput::presentLegacy(const QSharedPointer<DrmBuffer> &buffer)
{
if (m_crtc->next()) {
return false;
......@@ -821,8 +805,8 @@ bool DrmOutput::presentLegacy(DrmBuffer *buffer)
}
// Do we need to set a new mode first?
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer)) {
if (!setModeLegacy(buffer)) {
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer.get())) {
if (!setModeLegacy(buffer.get())) {
return false;
}
}
......@@ -969,12 +953,6 @@ bool DrmOutput::atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable)
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcH), targetRect.height());
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcId), m_crtc->id());
} else {
if (m_primaryPlane->current() && m_primaryPlane->current()->shouldDeleteAfterPageflip()) {
delete m_primaryPlane->current();
}
if (m_primaryPlane->next() && m_primaryPlane->next()->shouldDeleteAfterPageflip()) {
delete m_primaryPlane->next();
}
m_primaryPlane->setCurrent(nullptr);
m_primaryPlane->setNext(nullptr);
......
......@@ -19,6 +19,7 @@
#include <QPoint>
#include <QSize>
#include <QVector>
#include <QSharedPointer>
#include <xf86drmMode.h>
namespace KWin
......@@ -51,7 +52,7 @@ public:
bool updateCursor();
void moveCursor();
bool init(drmModeConnector *connector);
bool present(DrmBuffer *buffer);
bool present(const QSharedPointer<DrmBuffer> &buffer);
void pageFlipped();
// These values are defined by the kernel
......@@ -105,7 +106,7 @@ private:
// and save the connector ids in the DrmCrtc instance.
DrmOutput(DrmBackend *backend, DrmGpu* gpu);
bool presentAtomically(DrmBuffer *buffer);
bool presentAtomically(const QSharedPointer<DrmBuffer> &buffer);
enum class AtomicCommitMode {
Test,
......@@ -113,7 +114,7 @@ private:
};
bool doAtomicCommit(AtomicCommitMode mode);
bool presentLegacy(DrmBuffer *buffer);
bool presentLegacy(const QSharedPointer<DrmBuffer> &buffer);
bool setModeLegacy(DrmBuffer *buffer);
void initEdid(drmModeConnector *connector);
void initDpms(drmModeConnector *connector);
......
......@@ -162,7 +162,7 @@ bool EglGbmBackend::initRenderingContext()
return true;
}
EGLSurface EglGbmBackend::createEglSurface(std::shared_ptr<GbmSurface> gbmSurface) const
EGLSurface EglGbmBackend::createEglSurface(QSharedPointer<GbmSurface> gbmSurface) const
{
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(),
(void *)(gbmSurface->surface()), nullptr);
......@@ -184,10 +184,10 @@ bool EglGbmBackend::resetOutput(Output &output, DrmOutput *drmOutput)
} else {
flags |= GBM_BO_USE_LINEAR;
}
auto gbmSurface = std::make_shared<GbmSurface>(m_gpu->gbmDevice(),
size.width(), size.height(),
GBM_FORMAT_XRGB8888,
flags);
auto gbmSurface = QSharedPointer<GbmSurface>::create(m_gpu->gbmDevice(),
size.width(), size.height(),
GBM_FORMAT_XRGB8888,
flags);
if (!gbmSurface) {
qCCritical(KWIN_DRM) << "Creating GBM surface failed";
return false;
......@@ -376,7 +376,7 @@ void EglGbmBackend::initRenderTarget(Output &output)
// Already initialized.
return;
}
std::shared_ptr<GLVertexBuffer> vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static));
QSharedPointer<GLVertexBuffer> vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static));
vbo->setData(6, 2, vertices, texCoords);
output.render.vbo = vbo;
}
......@@ -580,7 +580,7 @@ void EglGbmBackend::aboutToStartPainting(int screenId, const QRegion &damagedReg
bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion)
{
if (output.directScanoutBuffer) {
output.buffer = new DrmSurfaceBuffer(m_gpu->fd(), output.directScanoutBuffer, output.bufferInterface);
output.buffer = QSharedPointer<DrmSurfaceBuffer>::create(m_gpu->fd(), output.directScanoutBuffer, output.bufferInterface);
} else if (isPrimary()) {
if (supportsSwapBuffersWithDamage()) {
QVector<EGLint> rects = regionToRects(output.damageHistory.constFirst(), output.output);
......@@ -595,7 +595,7 @@ bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion
return false;
}
}
output.buffer = new DrmSurfaceBuffer(m_gpu->fd(), output.gbmSurface);
output.buffer = QSharedPointer<DrmSurfaceBuffer>::create(m_gpu->fd(), output.gbmSurface);
} else {
qCDebug(KWIN_DRM) << "imported gbm_bo does not exist!";
return false;
......
......@@ -10,7 +10,7 @@
#define KWIN_EGL_GBM_BACKEND_H
#include "abstract_egl_drm_backend.h"
#include <memory>
#include <QSharedPointer>
struct gbm_surface;
struct gbm_bo;
......@@ -67,8 +67,8 @@ private:
struct Output {
DrmOutput *output = nullptr;
DrmSurfaceBuffer *buffer = nullptr;
std::shared_ptr<GbmSurface> gbmSurface;
QSharedPointer<DrmSurfaceBuffer> buffer;
QSharedPointer<GbmSurface> gbmSurface;
EGLSurface eglSurface = EGL_NO_SURFACE;
int bufferAge = 0;
/**
......@@ -79,7 +79,7 @@ private:
struct {
GLuint framebuffer = 0;
GLuint texture = 0;
std::shared_ptr<GLVertexBuffer> vbo;
QSharedPointer<GLVertexBuffer> vbo;
} render;
int dmabufFd = 0;
......@@ -90,7 +90,7 @@ private:
};
bool resetOutput(Output &output, DrmOutput *drmOutput);
EGLSurface createEglSurface(std::shared_ptr<GbmSurface> gbmSurface) const;
EGLSurface createEglSurface(QSharedPointer<GbmSurface> gbmSurface) const;
bool makeContextCurrent(const Output &output) const;
void setViewport(const Output &output) const;
......
......@@ -85,9 +85,6 @@ void EglStreamBackend::cleanupSurfaces()
void EglStreamBackend::cleanupOutput(const Output &o)
{
if (o.buffer != nullptr) {
delete o.buffer;
}
if (o.eglSurface != EGL_NO_SURFACE) {
eglDestroySurface(eglDisplay(), o.eglSurface);
}
......@@ -283,11 +280,8 @@ bool EglStreamBackend::initRenderingContext()
bool EglStreamBackend::resetOutput(Output &o, DrmOutput *drmOutput)
{
o.output = drmOutput;
if (o.buffer != nullptr) {
delete o.buffer;
}
// dumb buffer used for modesetting
o.buffer = m_gpu->createBuffer(drmOutput->pixelSize());
o.buffer = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), drmOutput->pixelSize());
EGLAttrib streamAttribs[] = {
EGL_STREAM_FIFO_LENGTH_KHR, 0, // mailbox mode
......
......@@ -58,7 +58,7 @@ private:
struct Output
{
DrmOutput *output = nullptr;
DrmBuffer *buffer = nullptr;
QSharedPointer<DrmBuffer> buffer;
EGLSurface eglSurface = EGL_NO_SURFACE;
EGLStreamKHR eglStream = EGL_NO_STREAM_KHR;
};
......
......@@ -36,26 +36,16 @@ DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu)
if (it == m_outputs.end()) {
return;
}
delete (*it).buffer[0];
delete (*it).buffer[1];
m_outputs.erase(it);
}
);
}
DrmQPainterBackend::~DrmQPainterBackend()
{
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
delete (*it).buffer[0];
delete (*it).buffer[1];
}
}
void DrmQPainterBackend::initOutput(DrmOutput *output)
{
Output o;
auto initBuffer = [&o, output, this] (int index) {
o.buffer[index] = m_gpu->createBuffer(output->pixelSize());
o.buffer[index] = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), output->pixelSize());
if (o.buffer[index]->map()) {
o.buffer[index]->image()->fill(Qt::black);
}
......@@ -70,10 +60,8 @@ void DrmQPainterBackend::initOutput(DrmOutput *output)
if (it == m_outputs.end()) {
return;
}
delete (*it).buffer[0];
delete (*it).buffer[1];
auto initBuffer = [it, output, this] (int index) {
it->buffer[index] = m_gpu->createBuffer(output->pixelSize());
it->buffer[index] = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), output->pixelSize());
if (it->buffer[index]->map()) {
it->buffer[index]->image()->fill(Qt::black);
}
......
......@@ -12,6 +12,7 @@
#include <QObject>
#include <QVector>
#include <QSharedPointer>
namespace KWin
{
......@@ -26,7 +27,6 @@ class DrmQPainterBackend : public QObject, public QPainterBackend
Q_OBJECT
public:
DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu);
~DrmQPainterBackend() override;
QImage *bufferForScreen(int screenId) override;
bool needsFullRepaint(int screenId) const override;
......@@ -36,7 +36,7 @@ public:
private:
void initOutput(DrmOutput *output);
struct Output {
DrmDumbBuffer *buffer[2];
QSharedPointer<DrmDumbBuffer> buffer[2];
DrmOutput *output;
int index = 0;
};
......
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