summaryrefslogtreecommitdiff
path: root/src/protocols/core/Shm.cpp
diff options
context:
space:
mode:
authordavc0n <dconti.dev@gmail.com>2025-05-03 16:02:49 +0200
committerGitHub <noreply@github.com>2025-05-03 16:02:49 +0200
commitd9cad5e1b63f2e1e86eb54551c72d17ee4dd070d (patch)
tree8238b613480214eaf91fc85343d25503bafa51c3 /src/protocols/core/Shm.cpp
parent0c736217a787928a87224b2bf7e984c446d4fc22 (diff)
protocols: refactor class member vars (core) (#10259)
Diffstat (limited to 'src/protocols/core/Shm.cpp')
-rw-r--r--src/protocols/core/Shm.cpp116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp
index 420b4a3f..6ebfa64f 100644
--- a/src/protocols/core/Shm.cpp
+++ b/src/protocols/core/Shm.cpp
@@ -10,22 +10,22 @@
using namespace Hyprutils::OS;
CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) {
- if UNLIKELY (!pool_->pool->data)
+ if UNLIKELY (!pool_->m_pool->m_data)
return;
g_pHyprRenderer->makeEGLCurrent();
- size = size_;
- pool = pool_->pool;
- stride = stride_;
- fmt = fmt_;
- offset = offset_;
- opaque = NFormatUtils::isFormatOpaque(NFormatUtils::shmToDRM(fmt_));
+ size = size_;
+ m_pool = pool_->m_pool;
+ m_stride = stride_;
+ m_fmt = fmt_;
+ m_offset = offset_;
+ opaque = NFormatUtils::isFormatOpaque(NFormatUtils::shmToDRM(fmt_));
- resource = CWLBufferResource::create(makeShared<CWlBuffer>(pool_->resource->client(), 1, id));
+ resource = CWLBufferResource::create(makeShared<CWlBuffer>(pool_->m_resource->client(), 1, id));
- listeners.bufferResourceDestroy = events.destroy.registerListener([this](std::any d) {
- listeners.bufferResourceDestroy.reset();
+ m_listeners.bufferResourceDestroy = events.destroy.registerListener([this](std::any d) {
+ m_listeners.bufferResourceDestroy.reset();
PROTO::shm->destroyResource(this);
});
}
@@ -50,16 +50,16 @@ bool CWLSHMBuffer::isSynchronous() {
Aquamarine::SSHMAttrs CWLSHMBuffer::shm() {
Aquamarine::SSHMAttrs attrs;
attrs.success = true;
- attrs.fd = pool->fd.get();
- attrs.format = NFormatUtils::shmToDRM(fmt);
+ attrs.fd = m_pool->m_fd.get();
+ attrs.format = NFormatUtils::shmToDRM(m_fmt);
attrs.size = size;
- attrs.stride = stride;
- attrs.offset = offset;
+ attrs.stride = m_stride;
+ attrs.offset = m_offset;
return attrs;
}
std::tuple<uint8_t*, uint32_t, size_t> CWLSHMBuffer::beginDataPtr(uint32_t flags) {
- return {(uint8_t*)pool->data + offset, fmt, stride * size.y};
+ return {(uint8_t*)m_pool->m_data + m_offset, m_fmt, m_stride * size.y};
}
void CWLSHMBuffer::endDataPtr() {
@@ -74,24 +74,24 @@ void CWLSHMBuffer::update(const CRegion& damage) {
;
}
-CSHMPool::CSHMPool(CFileDescriptor fd_, size_t size_) : fd(std::move(fd_)), size(size_), data(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0)) {
+CSHMPool::CSHMPool(CFileDescriptor fd_, size_t size_) : m_fd(std::move(fd_)), m_size(size_), m_data(mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd.get(), 0)) {
;
}
CSHMPool::~CSHMPool() {
- munmap(data, size);
+ munmap(m_data, m_size);
}
void CSHMPool::resize(size_t size_) {
- LOGM(LOG, "Resizing a SHM pool from {} to {}", size, size_);
+ LOGM(LOG, "Resizing a SHM pool from {} to {}", m_size, size_);
- if (data)
- munmap(data, size);
- size = size_;
- data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0);
+ if (m_data)
+ munmap(m_data, m_size);
+ m_size = size_;
+ m_data = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd.get(), 0);
- if UNLIKELY (data == MAP_FAILED)
- LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", size, fd.get());
+ if UNLIKELY (m_data == MAP_FAILED)
+ LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", m_size, m_fd.get());
}
static int shmIsSizeValid(CFileDescriptor& fd, size_t size) {
@@ -104,7 +104,7 @@ static int shmIsSizeValid(CFileDescriptor& fd, size_t size) {
return (size_t)st.st_size >= size;
}
-CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor fd_, size_t size_) : resource(resource_) {
+CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor fd_, size_t size_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
@@ -113,31 +113,31 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
return;
}
- pool = makeShared<CSHMPool>(std::move(fd_), size_);
+ m_pool = makeShared<CSHMPool>(std::move(fd_), size_);
- resource->setDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
- resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
+ m_resource->setDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
+ m_resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
- resource->setResize([this](CWlShmPool* r, int32_t size_) {
- if UNLIKELY (size_ < (int32_t)pool->size) {
+ m_resource->setResize([this](CWlShmPool* r, int32_t size_) {
+ if UNLIKELY (size_ < (int32_t)m_pool->m_size) {
r->error(-1, "Shrinking a shm pool is illegal");
return;
}
- if UNLIKELY (!shmIsSizeValid(pool->fd, size_)) {
+ if UNLIKELY (!shmIsSizeValid(m_pool->m_fd, size_)) {
r->error(-1, "The size of the file is not big enough for the shm pool");
return;
}
- pool->resize(size_);
+ m_pool->resize(size_);
});
- resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) {
- if UNLIKELY (!pool || !pool->data) {
+ m_resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) {
+ if UNLIKELY (!m_pool || !m_pool->m_data) {
r->error(-1, "The provided shm pool failed to allocate properly");
return;
}
- if UNLIKELY (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) {
+ if UNLIKELY (std::find(PROTO::shm->m_shmFormats.begin(), PROTO::shm->m_shmFormats.end(), fmt) == PROTO::shm->m_shmFormats.end()) {
r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid");
return;
}
@@ -147,11 +147,11 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
return;
}
- const auto RESOURCE = PROTO::shm->m_vBuffers.emplace_back(makeShared<CWLSHMBuffer>(self.lock(), id, offset, Vector2D{w, h}, stride, fmt));
+ const auto RESOURCE = PROTO::shm->m_buffers.emplace_back(makeShared<CWLSHMBuffer>(m_self.lock(), id, offset, Vector2D{w, h}, stride, fmt));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
- PROTO::shm->m_vBuffers.pop_back();
+ PROTO::shm->m_buffers.pop_back();
return;
}
@@ -159,41 +159,41 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
RESOURCE->resource->buffer = RESOURCE;
});
- if UNLIKELY (pool->data == MAP_FAILED)
- resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd");
+ if UNLIKELY (m_pool->m_data == MAP_FAILED)
+ m_resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd");
}
bool CWLSHMPoolResource::good() {
- return resource->resource();
+ return m_resource->resource();
}
-CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : resource(resource_) {
+CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
- resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); });
+ m_resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); });
- resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) {
+ m_resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) {
CFileDescriptor poolFd{fd};
- const auto RESOURCE = PROTO::shm->m_vPools.emplace_back(makeShared<CWLSHMPoolResource>(makeShared<CWlShmPool>(r->client(), r->version(), id), std::move(poolFd), size));
+ const auto RESOURCE = PROTO::shm->m_pools.emplace_back(makeShared<CWLSHMPoolResource>(makeShared<CWlShmPool>(r->client(), r->version(), id), std::move(poolFd), size));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
- PROTO::shm->m_vPools.pop_back();
+ PROTO::shm->m_pools.pop_back();
return;
}
- RESOURCE->self = RESOURCE;
+ RESOURCE->m_self = RESOURCE;
});
// send a few supported formats. No need for any other I think?
- for (auto const& s : PROTO::shm->shmFormats) {
- resource->sendFormat((wl_shm_format)s);
+ for (auto const& s : PROTO::shm->m_shmFormats) {
+ m_resource->sendFormat((wl_shm_format)s);
}
}
bool CWLSHMResource::good() {
- return resource->resource();
+ return m_resource->resource();
}
CWLSHMProtocol::CWLSHMProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@@ -201,36 +201,36 @@ CWLSHMProtocol::CWLSHMProtocol(const wl_interface* iface, const int& ver, const
}
void CWLSHMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
- if (shmFormats.empty()) {
- shmFormats.push_back(WL_SHM_FORMAT_ARGB8888);
- shmFormats.push_back(WL_SHM_FORMAT_XRGB8888);
+ if (m_shmFormats.empty()) {
+ m_shmFormats.push_back(WL_SHM_FORMAT_ARGB8888);
+ m_shmFormats.push_back(WL_SHM_FORMAT_XRGB8888);
static const std::array<DRMFormat, 6> supportedShmFourccFormats = {
DRM_FORMAT_XBGR8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_XRGB2101010, DRM_FORMAT_ARGB2101010, DRM_FORMAT_XBGR2101010, DRM_FORMAT_ABGR2101010,
};
for (auto const& fmt : supportedShmFourccFormats) {
- shmFormats.push_back(fmt);
+ m_shmFormats.push_back(fmt);
}
}
- const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLSHMResource>(makeShared<CWlShm>(client, ver, id)));
+ const auto RESOURCE = m_managers.emplace_back(makeShared<CWLSHMResource>(makeShared<CWlShm>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
- m_vManagers.pop_back();
+ m_managers.pop_back();
return;
}
}
void CWLSHMProtocol::destroyResource(CWLSHMResource* resource) {
- std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
+ std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CWLSHMProtocol::destroyResource(CWLSHMPoolResource* resource) {
- std::erase_if(m_vPools, [&](const auto& other) { return other.get() == resource; });
+ std::erase_if(m_pools, [&](const auto& other) { return other.get() == resource; });
}
void CWLSHMProtocol::destroyResource(CWLSHMBuffer* resource) {
- std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; });
+ std::erase_if(m_buffers, [&](const auto& other) { return other.get() == resource; });
}