diff --git a/src/plugins/platforms/drm/drm_buffer.h b/src/plugins/platforms/drm/drm_buffer.h index 5db8c2f4bb..c7f524d0ca 100644 --- a/src/plugins/platforms/drm/drm_buffer.h +++ b/src/plugins/platforms/drm/drm_buffer.h @@ -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; diff --git a/src/plugins/platforms/drm/drm_buffer_gbm.cpp b/src/plugins/platforms/drm/drm_buffer_gbm.cpp index 10545697e8..cecd9e6189 100644 --- a/src/plugins/platforms/drm/drm_buffer_gbm.cpp +++ b/src/plugins/platforms/drm/drm_buffer_gbm.cpp @@ -28,7 +28,7 @@ namespace KWin { // DrmSurfaceBuffer -DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const std::shared_ptr &surface) +DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const QSharedPointer &surface) : DrmBuffer(fd) , m_surface(surface) { diff --git a/src/plugins/platforms/drm/drm_buffer_gbm.h b/src/plugins/platforms/drm/drm_buffer_gbm.h index 7a70d4bed9..e2970014e8 100644 --- a/src/plugins/platforms/drm/drm_buffer_gbm.h +++ b/src/plugins/platforms/drm/drm_buffer_gbm.h @@ -12,7 +12,7 @@ #include "drm_buffer.h" -#include +#include struct gbm_bo; @@ -29,7 +29,7 @@ class GbmSurface; class DrmSurfaceBuffer : public DrmBuffer { public: - DrmSurfaceBuffer(int fd, const std::shared_ptr &surface); + DrmSurfaceBuffer(int fd, const QSharedPointer &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 m_surface; + QSharedPointer m_surface; gbm_bo *m_bo = nullptr; KWaylandServer::BufferInterface *m_bufferInterface = nullptr; diff --git a/src/plugins/platforms/drm/drm_gpu.h b/src/plugins/platforms/drm/drm_gpu.h index 9f32133f16..5ae90c8b7f 100644 --- a/src/plugins/platforms/drm/drm_gpu.h +++ b/src/plugins/platforms/drm/drm_gpu.h @@ -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; } diff --git a/src/plugins/platforms/drm/drm_object_crtc.cpp b/src/plugins/platforms/drm/drm_object_crtc.cpp index 80ea75944e..7b480fbe31 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.cpp +++ b/src/plugins/platforms/drm/drm_object_crtc.cpp @@ -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; diff --git a/src/plugins/platforms/drm/drm_object_crtc.h b/src/plugins/platforms/drm/drm_object_crtc.h index 34a05e2d3a..44d1f7feda 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.h +++ b/src/plugins/platforms/drm/drm_object_crtc.h @@ -11,6 +11,8 @@ #include "drm_object.h" +#include + namespace KWin { @@ -41,13 +43,13 @@ public: return m_resIndex; } - DrmBuffer *current() { + QSharedPointer current() { return m_currentBuffer; } - DrmBuffer *next() { + QSharedPointer next() { return m_nextBuffer; } - void setNext(DrmBuffer *buffer) { + void setNext(const QSharedPointer &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 m_currentBuffer; + QSharedPointer m_nextBuffer; DrmDumbBuffer *m_blackBuffer = nullptr; DrmBackend *m_backend; DrmGpu *m_gpu; diff --git a/src/plugins/platforms/drm/drm_object_plane.cpp b/src/plugins/platforms/drm/drm_object_plane.cpp index a23c90fa72..d86869f770 100644 --- a/src/plugins/platforms/drm/drm_object_plane.cpp +++ b/src/plugins/platforms/drm/drm_object_plane.cpp @@ -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 &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; } diff --git a/src/plugins/platforms/drm/drm_object_plane.h b/src/plugins/platforms/drm/drm_object_plane.h index 109efc140d..887476a089 100644 --- a/src/plugins/platforms/drm/drm_object_plane.h +++ b/src/plugins/platforms/drm/drm_object_plane.h @@ -12,6 +12,7 @@ #include #include +#include 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 current() const { return m_current; } - DrmBuffer *next() const { + QSharedPointer next() const { return m_next; } - void setCurrent(DrmBuffer *b) { + void setCurrent(const QSharedPointer &b) { m_current = b; } - void setNext(DrmBuffer *b); + void setNext(const QSharedPointer &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 m_current; + QSharedPointer m_next; // TODO: See weston drm_output_check_plane_format for future use of these member variables QVector m_formats; // Possible formats, which can be presented on this plane diff --git a/src/plugins/platforms/drm/drm_output.cpp b/src/plugins/platforms/drm/drm_output.cpp index c3fd521c17..002ea81f4c 100644 --- a/src/plugins/platforms/drm/drm_output.cpp +++ b/src/plugins/platforms/drm/drm_output.cpp @@ -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 &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 &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 &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); diff --git a/src/plugins/platforms/drm/drm_output.h b/src/plugins/platforms/drm/drm_output.h index f4179fa067..b885ac9aa0 100644 --- a/src/plugins/platforms/drm/drm_output.h +++ b/src/plugins/platforms/drm/drm_output.h @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace KWin @@ -51,7 +52,7 @@ public: bool updateCursor(); void moveCursor(); bool init(drmModeConnector *connector); - bool present(DrmBuffer *buffer); + bool present(const QSharedPointer &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 &buffer); enum class AtomicCommitMode { Test, @@ -113,7 +114,7 @@ private: }; bool doAtomicCommit(AtomicCommitMode mode); - bool presentLegacy(DrmBuffer *buffer); + bool presentLegacy(const QSharedPointer &buffer); bool setModeLegacy(DrmBuffer *buffer); void initEdid(drmModeConnector *connector); void initDpms(drmModeConnector *connector); diff --git a/src/plugins/platforms/drm/egl_gbm_backend.cpp b/src/plugins/platforms/drm/egl_gbm_backend.cpp index 980ebe2f45..c6093f0122 100644 --- a/src/plugins/platforms/drm/egl_gbm_backend.cpp +++ b/src/plugins/platforms/drm/egl_gbm_backend.cpp @@ -162,7 +162,7 @@ bool EglGbmBackend::initRenderingContext() return true; } -EGLSurface EglGbmBackend::createEglSurface(std::shared_ptr gbmSurface) const +EGLSurface EglGbmBackend::createEglSurface(QSharedPointer 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(m_gpu->gbmDevice(), - size.width(), size.height(), - GBM_FORMAT_XRGB8888, - flags); + auto gbmSurface = QSharedPointer::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 vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static)); + QSharedPointer 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::create(m_gpu->fd(), output.directScanoutBuffer, output.bufferInterface); } else if (isPrimary()) { if (supportsSwapBuffersWithDamage()) { QVector 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::create(m_gpu->fd(), output.gbmSurface); } else { qCDebug(KWIN_DRM) << "imported gbm_bo does not exist!"; return false; diff --git a/src/plugins/platforms/drm/egl_gbm_backend.h b/src/plugins/platforms/drm/egl_gbm_backend.h index 73fd48e727..0ed3d74c45 100644 --- a/src/plugins/platforms/drm/egl_gbm_backend.h +++ b/src/plugins/platforms/drm/egl_gbm_backend.h @@ -10,7 +10,7 @@ #define KWIN_EGL_GBM_BACKEND_H #include "abstract_egl_drm_backend.h" -#include +#include struct gbm_surface; struct gbm_bo; @@ -67,8 +67,8 @@ private: struct Output { DrmOutput *output = nullptr; - DrmSurfaceBuffer *buffer = nullptr; - std::shared_ptr gbmSurface; + QSharedPointer buffer; + QSharedPointer gbmSurface; EGLSurface eglSurface = EGL_NO_SURFACE; int bufferAge = 0; /** @@ -79,7 +79,7 @@ private: struct { GLuint framebuffer = 0; GLuint texture = 0; - std::shared_ptr vbo; + QSharedPointer vbo; } render; int dmabufFd = 0; @@ -90,7 +90,7 @@ private: }; bool resetOutput(Output &output, DrmOutput *drmOutput); - EGLSurface createEglSurface(std::shared_ptr gbmSurface) const; + EGLSurface createEglSurface(QSharedPointer gbmSurface) const; bool makeContextCurrent(const Output &output) const; void setViewport(const Output &output) const; diff --git a/src/plugins/platforms/drm/egl_stream_backend.cpp b/src/plugins/platforms/drm/egl_stream_backend.cpp index e72b18019e..adef29f55f 100644 --- a/src/plugins/platforms/drm/egl_stream_backend.cpp +++ b/src/plugins/platforms/drm/egl_stream_backend.cpp @@ -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::create(m_gpu->fd(), drmOutput->pixelSize()); EGLAttrib streamAttribs[] = { EGL_STREAM_FIFO_LENGTH_KHR, 0, // mailbox mode diff --git a/src/plugins/platforms/drm/egl_stream_backend.h b/src/plugins/platforms/drm/egl_stream_backend.h index b74d26efab..76177c2cde 100644 --- a/src/plugins/platforms/drm/egl_stream_backend.h +++ b/src/plugins/platforms/drm/egl_stream_backend.h @@ -58,7 +58,7 @@ private: struct Output { DrmOutput *output = nullptr; - DrmBuffer *buffer = nullptr; + QSharedPointer buffer; EGLSurface eglSurface = EGL_NO_SURFACE; EGLStreamKHR eglStream = EGL_NO_STREAM_KHR; }; diff --git a/src/plugins/platforms/drm/scene_qpainter_drm_backend.cpp b/src/plugins/platforms/drm/scene_qpainter_drm_backend.cpp index 295e746de6..4507963e45 100644 --- a/src/plugins/platforms/drm/scene_qpainter_drm_backend.cpp +++ b/src/plugins/platforms/drm/scene_qpainter_drm_backend.cpp @@ -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::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::create(m_gpu->fd(), output->pixelSize()); if (it->buffer[index]->map()) { it->buffer[index]->image()->fill(Qt::black); } diff --git a/src/plugins/platforms/drm/scene_qpainter_drm_backend.h b/src/plugins/platforms/drm/scene_qpainter_drm_backend.h index aa3ee45067..f39c75f9f5 100644 --- a/src/plugins/platforms/drm/scene_qpainter_drm_backend.h +++ b/src/plugins/platforms/drm/scene_qpainter_drm_backend.h @@ -12,6 +12,7 @@ #include #include +#include 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 buffer[2]; DrmOutput *output; int index = 0; };