From ec672b1ab95e341a0dcb6679592ae4e5eea9b1cf Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Sat, 27 Jul 2024 10:02:02 -0500 Subject: protocols: move screencopy and toplevel export to hyprwayland-scanner (#7065) * move screencopy and toplevel export to hyprwayland-scanner * oops --- src/protocols/Screencopy.hpp | 128 ++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 61 deletions(-) (limited to 'src/protocols/Screencopy.hpp') diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp index d564e432..cbc56edb 100644 --- a/src/protocols/Screencopy.hpp +++ b/src/protocols/Screencopy.hpp @@ -1,7 +1,8 @@ #pragma once #include "../defines.hpp" -#include "wlr-screencopy-unstable-v1-protocol.h" +#include "wlr-screencopy-unstable-v1.hpp" +#include "WaylandProtocol.hpp" #include #include @@ -20,88 +21,93 @@ enum eClientOwners { class CScreencopyClient { public: - CScreencopyClient(); + CScreencopyClient(SP resource_); ~CScreencopyClient(); - int ref = 0; - wl_resource* resource = nullptr; + bool good(); - eClientOwners clientOwner = CLIENT_SCREENCOPY; + WP self; + eClientOwners clientOwner = CLIENT_SCREENCOPY; - int frameCounter = 0; - int framesInLastHalfSecond = 0; - CTimer lastMeasure; - CTimer lastFrame; - bool sentScreencast = false; + CTimer lastFrame; + int frameCounter = 0; - void onTick(); - SP tickCallback; + private: + SP resource; - bool operator==(const CScreencopyClient& other) const { - return resource == other.resource; - } -}; + int framesInLastHalfSecond = 0; + CTimer lastMeasure; + bool sentScreencast = false; -struct SScreencopyFrame { - wl_resource* resource = nullptr; - CScreencopyClient* client = nullptr; + SP tickCallback; + void onTick(); - uint32_t shmFormat = 0; - uint32_t dmabufFormat = 0; - CBox box = {}; - int shmStride = 0; + void captureOutput(uint32_t frame, int32_t overlayCursor, wl_resource* output, CBox box); - bool overlayCursor = false; - bool withDamage = false; - bool lockedSWCursors = false; + friend class CScreencopyProtocol; +}; - bool bufferDMA = false; +class CScreencopyFrame { + public: + CScreencopyFrame(SP resource, int32_t overlay_cursor, wl_resource* output, CBox box); + ~CScreencopyFrame(); - WP buffer; + bool good(); - CMonitor* pMonitor = nullptr; - PHLWINDOWREF pWindow; + SP self; + WP client; - bool operator==(const SScreencopyFrame& other) const { - return resource == other.resource && client == other.client; - } + private: + SP resource; + + CMonitor* pMonitor = nullptr; + bool overlayCursor = false; + bool withDamage = false; + bool lockedSWCursors = false; + + WP buffer; + bool bufferDMA = false; + uint32_t shmFormat = 0; + uint32_t dmabufFormat = 0; + int shmStride = 0; + CBox box = {}; + + void copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer); + bool copyDmabuf(); + bool copyShm(); + void share(); + + friend class CScreencopyProtocol; }; -class CScreencopyProtocolManager { +class CScreencopyProtocol : public IWaylandProtocol { public: - CScreencopyProtocolManager(); - ~CScreencopyProtocolManager(); - - void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id); - void removeClient(CScreencopyClient* client, bool force = false); - void removeFrame(SScreencopyFrame* frame, bool force = false); - void displayDestroy(); + CScreencopyProtocol(const wl_interface* iface, const int& ver, const std::string& name); - void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box = {0, 0, 0, 0}); + virtual void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id); + void destroyResource(CScreencopyClient* resource); + void destroyResource(CScreencopyFrame* resource); - void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer); - - void onOutputCommit(CMonitor* pMonitor); - - wl_listener m_liDisplayDestroy; + void onOutputCommit(CMonitor* pMonitor); private: - wl_global* m_pGlobal = nullptr; - std::list m_lFrames; - std::list m_lClients; - - SP m_pSoftwareCursorTimer; - bool m_bTimerArmed = false; + std::vector> m_vFrames; + std::vector> m_vFramesAwaitingWrite; + std::vector> m_vClients; - std::vector m_vFramesAwaitingWrite; + SP m_pSoftwareCursorTimer; + bool m_bTimerArmed = false; - SP m_pLastMonitorBackBuffer; - - void shareAllFrames(CMonitor* pMonitor); - void shareFrame(SScreencopyFrame* frame); - void sendFrameDamage(SScreencopyFrame* frame); - bool copyFrameDmabuf(SScreencopyFrame* frame); - bool copyFrameShm(SScreencopyFrame* frame, timespec* now); + void shareAllFrames(CMonitor* pMonitor); + void shareFrame(CScreencopyFrame* frame); + void sendFrameDamage(CScreencopyFrame* frame); + bool copyFrameDmabuf(CScreencopyFrame* frame); + bool copyFrameShm(CScreencopyFrame* frame, timespec* now); + friend class CScreencopyFrame; friend class CScreencopyClient; }; + +namespace PROTO { + inline UP screencopy; +}; -- cgit v1.2.3