2023-04-03 18:01:05 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
2024-07-27 17:02:02 +02:00
|
|
|
#include "wlr-screencopy-unstable-v1.hpp"
|
|
|
|
#include "WaylandProtocol.hpp"
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2023-04-16 00:43:41 +02:00
|
|
|
#include "../managers/HookSystemManager.hpp"
|
2023-04-17 23:57:24 +02:00
|
|
|
#include "../helpers/Timer.hpp"
|
2024-05-11 23:10:42 +02:00
|
|
|
#include "../managers/eventLoop/EventLoopTimer.hpp"
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <aquamarine/buffer/Buffer.hpp>
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
class CMonitor;
|
2024-07-21 13:09:54 +02:00
|
|
|
class IHLBuffer;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2023-12-06 23:54:56 +01:00
|
|
|
enum eClientOwners {
|
2023-04-16 00:43:41 +02:00
|
|
|
CLIENT_SCREENCOPY = 0,
|
|
|
|
CLIENT_TOPLEVEL_EXPORT
|
|
|
|
};
|
|
|
|
|
|
|
|
class CScreencopyClient {
|
|
|
|
public:
|
2024-07-27 17:02:02 +02:00
|
|
|
CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_);
|
2023-04-16 00:43:41 +02:00
|
|
|
~CScreencopyClient();
|
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
bool good();
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
WP<CScreencopyClient> self;
|
|
|
|
eClientOwners clientOwner = CLIENT_SCREENCOPY;
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
CTimer lastFrame;
|
|
|
|
int frameCounter = 0;
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
private:
|
|
|
|
SP<CZwlrScreencopyManagerV1> resource;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
int framesInLastHalfSecond = 0;
|
|
|
|
CTimer lastMeasure;
|
|
|
|
bool sentScreencast = false;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
SP<HOOK_CALLBACK_FN> tickCallback;
|
|
|
|
void onTick();
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
void captureOutput(uint32_t frame, int32_t overlayCursor, wl_resource* output, CBox box);
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
friend class CScreencopyProtocol;
|
|
|
|
};
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
class CScreencopyFrame {
|
|
|
|
public:
|
|
|
|
CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource, int32_t overlay_cursor, wl_resource* output, CBox box);
|
|
|
|
~CScreencopyFrame();
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
bool good();
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-10-08 02:23:48 +02:00
|
|
|
WP<CScreencopyFrame> self;
|
2024-07-27 17:02:02 +02:00
|
|
|
WP<CScreencopyClient> client;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
private:
|
|
|
|
SP<CZwlrScreencopyFrameV1> resource;
|
|
|
|
|
2024-10-20 00:03:29 +02:00
|
|
|
PHLMONITORREF pMonitor;
|
2024-07-27 17:02:02 +02:00
|
|
|
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;
|
2023-04-03 18:01:05 +02:00
|
|
|
};
|
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
class CScreencopyProtocol : public IWaylandProtocol {
|
2023-04-03 18:01:05 +02:00
|
|
|
public:
|
2024-07-27 17:02:02 +02:00
|
|
|
CScreencopyProtocol(const wl_interface* iface, const int& ver, const std::string& name);
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
virtual void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
|
|
|
|
void destroyResource(CScreencopyClient* resource);
|
|
|
|
void destroyResource(CScreencopyFrame* resource);
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-10-20 00:03:29 +02:00
|
|
|
void onOutputCommit(PHLMONITOR pMonitor);
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
private:
|
2024-07-27 17:02:02 +02:00
|
|
|
std::vector<SP<CScreencopyFrame>> m_vFrames;
|
2024-10-08 02:23:48 +02:00
|
|
|
std::vector<WP<CScreencopyFrame>> m_vFramesAwaitingWrite;
|
2024-07-27 17:02:02 +02:00
|
|
|
std::vector<SP<CScreencopyClient>> m_vClients;
|
2024-05-11 23:10:42 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
SP<CEventLoopTimer> m_pSoftwareCursorTimer;
|
|
|
|
bool m_bTimerArmed = false;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2024-10-20 00:03:29 +02:00
|
|
|
void shareAllFrames(PHLMONITOR pMonitor);
|
2024-07-27 17:02:02 +02:00
|
|
|
void shareFrame(CScreencopyFrame* frame);
|
|
|
|
void sendFrameDamage(CScreencopyFrame* frame);
|
|
|
|
bool copyFrameDmabuf(CScreencopyFrame* frame);
|
|
|
|
bool copyFrameShm(CScreencopyFrame* frame, timespec* now);
|
2023-04-17 23:57:24 +02:00
|
|
|
|
2024-07-27 17:02:02 +02:00
|
|
|
friend class CScreencopyFrame;
|
2023-04-17 23:57:24 +02:00
|
|
|
friend class CScreencopyClient;
|
2024-07-24 19:07:36 +02:00
|
|
|
};
|
2024-07-27 17:02:02 +02:00
|
|
|
|
|
|
|
namespace PROTO {
|
|
|
|
inline UP<CScreencopyProtocol> screencopy;
|
|
|
|
};
|