From a537d36d9e1906c4e2dab6d6c851fdd0781bdf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 21 Aug 2014 07:54:16 +0200 Subject: [PATCH] [kwin_wayland] Make ShmPool more like the other wrapper classes Normal QObject ctor and the setup method to bind to the interface. --- src/wayland/shm_pool.cpp | 47 +++++++++++++++++++++++++++++++++++++--- src/wayland/shm_pool.h | 8 +++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/wayland/shm_pool.cpp b/src/wayland/shm_pool.cpp index a08f7b7b29..dccdc24c92 100644 --- a/src/wayland/shm_pool.cpp +++ b/src/wayland/shm_pool.cpp @@ -32,30 +32,71 @@ namespace KWin namespace Wayland { -ShmPool::ShmPool(wl_shm *shm) - : m_shm(shm) +ShmPool::ShmPool(QObject *parent) + : QObject(parent) + , m_shm(nullptr) , m_pool(nullptr) , m_poolData(nullptr) , m_size(1024) , m_tmpFile(new QTemporaryFile()) - , m_valid(createPool()) + , m_valid(false) , m_offset(0) { } ShmPool::~ShmPool() +{ + release(); +} + +void ShmPool::release() { qDeleteAll(m_buffers); + m_buffers.clear(); if (m_poolData) { munmap(m_poolData, m_size); + m_poolData = nullptr; } if (m_pool) { wl_shm_pool_destroy(m_pool); + m_pool = nullptr; } if (m_shm) { wl_shm_destroy(m_shm); + m_shm = nullptr; } m_tmpFile->close(); + m_valid = false; + m_offset = 0; +} + +void ShmPool::destroy() +{ + qDeleteAll(m_buffers); + m_buffers.clear(); + if (m_poolData) { + munmap(m_poolData, m_size); + m_poolData = nullptr; + } + if (m_pool) { + free(m_pool); + m_pool = nullptr; + } + if (m_shm) { + free(m_shm); + m_shm = nullptr; + } + m_tmpFile->close(); + m_valid = false; + m_offset = 0; +} + +void ShmPool::setup(wl_shm *shm) +{ + Q_ASSERT(shm); + Q_ASSERT(!m_shm); + m_shm = shm; + m_valid = createPool(); } bool ShmPool::createPool() diff --git a/src/wayland/shm_pool.h b/src/wayland/shm_pool.h index 9b1c8ff314..e0319ec22f 100644 --- a/src/wayland/shm_pool.h +++ b/src/wayland/shm_pool.h @@ -40,9 +40,13 @@ class ShmPool : public QObject { Q_OBJECT public: - ShmPool(wl_shm *shm); - ~ShmPool(); + explicit ShmPool(QObject *parent = nullptr); + virtual ~ShmPool(); bool isValid() const; + void setup(wl_shm *shm); + void release(); + void destroy(); + wl_buffer *createBuffer(const QImage &image); wl_buffer *createBuffer(const QSize &size, int32_t stride, const void *src); void *poolAddress() const;