#pragma once /* Implementations for: - wl_shm - wl_shm_pool - wl_buffer with shm */ #include #include #include #include "../WaylandProtocol.hpp" #include "wayland.hpp" #include "../types/Buffer.hpp" #include "../../helpers/math/Math.hpp" class CWLSHMPoolResource; class CSHMPool { public: CSHMPool(int fd, size_t size); ~CSHMPool(); int fd = 0; size_t size = 0; void* data = nullptr; void resize(size_t size); }; class CWLSHMBuffer : public IWLBuffer { public: CWLSHMBuffer(SP pool, uint32_t id, int32_t offset, const Vector2D& size, int32_t stride, uint32_t fmt); virtual ~CWLSHMBuffer(); virtual eBufferCapability caps(); virtual eBufferType type(); virtual void update(const CRegion& damage); virtual bool isSynchronous(); virtual SSHMAttrs shm(); virtual std::tuple beginDataPtr(uint32_t flags); virtual void endDataPtr(); bool good(); void updateTexture(); int32_t offset = 0, stride = 0; uint32_t fmt = 0; SP pool; private: bool success = false; struct { CHyprSignalListener bufferResourceDestroy; } listeners; }; class CWLSHMPoolResource { public: CWLSHMPoolResource(SP resource_, int fd, size_t size); bool good(); SP pool; WP self; private: SP resource; friend class CWLSHMBuffer; }; class CWLSHMResource { public: CWLSHMResource(SP resource_); bool good(); private: SP resource; }; class CWLSHMProtocol : public IWaylandProtocol { public: CWLSHMProtocol(const wl_interface* iface, const int& ver, const std::string& name); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); private: void destroyResource(CWLSHMResource* resource); void destroyResource(CWLSHMPoolResource* resource); void destroyResource(CWLSHMBuffer* resource); // std::vector> m_vManagers; std::vector> m_vPools; std::vector> m_vBuffers; // std::vector shmFormats; friend class CWLSHMResource; friend class CWLSHMPoolResource; friend class CWLSHMBuffer; }; namespace PROTO { inline UP shm; };