summaryrefslogtreecommitdiff
path: root/src/protocols/Screencopy.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols/Screencopy.hpp')
-rw-r--r--src/protocols/Screencopy.hpp128
1 files changed, 67 insertions, 61 deletions
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 <list>
#include <vector>
@@ -20,88 +21,93 @@ enum eClientOwners {
class CScreencopyClient {
public:
- CScreencopyClient();
+ CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_);
~CScreencopyClient();
- int ref = 0;
- wl_resource* resource = nullptr;
+ bool good();
- eClientOwners clientOwner = CLIENT_SCREENCOPY;
+ WP<CScreencopyClient> 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<HOOK_CALLBACK_FN> tickCallback;
+ private:
+ SP<CZwlrScreencopyManagerV1> 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<HOOK_CALLBACK_FN> 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<CZwlrScreencopyFrameV1> resource, int32_t overlay_cursor, wl_resource* output, CBox box);
+ ~CScreencopyFrame();
- WP<IHLBuffer> buffer;
+ bool good();
- CMonitor* pMonitor = nullptr;
- PHLWINDOWREF pWindow;
+ SP<CScreencopyFrame> self;
+ WP<CScreencopyClient> client;
- bool operator==(const SScreencopyFrame& other) const {
- return resource == other.resource && client == other.client;
- }
+ private:
+ SP<CZwlrScreencopyFrameV1> resource;
+
+ CMonitor* pMonitor = nullptr;
+ bool overlayCursor = false;
+ bool withDamage = false;
+ bool lockedSWCursors = false;
+
+ WP<IHLBuffer> 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<SScreencopyFrame> m_lFrames;
- std::list<CScreencopyClient> m_lClients;
-
- SP<CEventLoopTimer> m_pSoftwareCursorTimer;
- bool m_bTimerArmed = false;
+ std::vector<SP<CScreencopyFrame>> m_vFrames;
+ std::vector<SP<CScreencopyFrame>> m_vFramesAwaitingWrite;
+ std::vector<SP<CScreencopyClient>> m_vClients;
- std::vector<SScreencopyFrame*> m_vFramesAwaitingWrite;
+ SP<CEventLoopTimer> m_pSoftwareCursorTimer;
+ bool m_bTimerArmed = false;
- SP<Aquamarine::IBuffer> 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<CScreencopyProtocol> screencopy;
+};