2023-04-03 18:01:05 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
2023-04-27 14:55:13 +02:00
|
|
|
#include "wlr-screencopy-unstable-v1-protocol.h"
|
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"
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
class CMonitor;
|
|
|
|
|
2023-04-16 00:43:41 +02:00
|
|
|
enum eClientOwners
|
|
|
|
{
|
|
|
|
CLIENT_SCREENCOPY = 0,
|
|
|
|
CLIENT_TOPLEVEL_EXPORT
|
|
|
|
};
|
|
|
|
|
|
|
|
class CScreencopyClient {
|
|
|
|
public:
|
|
|
|
CScreencopyClient();
|
|
|
|
~CScreencopyClient();
|
|
|
|
|
2023-04-17 23:57:24 +02:00
|
|
|
int ref = 0;
|
|
|
|
wl_resource* resource = nullptr;
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2023-04-17 23:57:24 +02:00
|
|
|
eClientOwners clientOwner = CLIENT_SCREENCOPY;
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2023-04-17 23:57:24 +02:00
|
|
|
int frameCounter = 0;
|
|
|
|
int framesInLastHalfSecond = 0;
|
|
|
|
CTimer lastMeasure;
|
|
|
|
CTimer lastFrame;
|
|
|
|
bool sentScreencast = false;
|
2023-04-16 00:43:41 +02:00
|
|
|
|
2023-04-17 23:57:24 +02:00
|
|
|
void onTick();
|
|
|
|
HOOK_CALLBACK_FN* tickCallback = nullptr;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
2023-04-17 23:57:24 +02:00
|
|
|
bool operator==(const CScreencopyClient& other) const {
|
2023-04-03 18:01:05 +02:00
|
|
|
return resource == other.resource;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SScreencopyFrame {
|
|
|
|
wl_resource* resource = nullptr;
|
2023-04-16 00:43:41 +02:00
|
|
|
CScreencopyClient* client = nullptr;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
uint32_t shmFormat = 0;
|
|
|
|
uint32_t dmabufFormat = 0;
|
2023-11-04 18:03:05 +01:00
|
|
|
CBox box = {};
|
2023-04-03 18:01:05 +02:00
|
|
|
int shmStride = 0;
|
|
|
|
|
|
|
|
bool overlayCursor = false;
|
|
|
|
bool withDamage = false;
|
|
|
|
|
|
|
|
wlr_buffer_cap bufferCap = WLR_BUFFER_CAP_SHM;
|
|
|
|
|
|
|
|
wlr_buffer* buffer = nullptr;
|
|
|
|
|
|
|
|
CMonitor* pMonitor = nullptr;
|
2023-04-16 00:43:41 +02:00
|
|
|
CWindow* pWindow = nullptr;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
bool operator==(const SScreencopyFrame& other) const {
|
|
|
|
return resource == other.resource && client == other.client;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CScreencopyProtocolManager {
|
|
|
|
public:
|
|
|
|
CScreencopyProtocolManager();
|
|
|
|
|
|
|
|
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
|
2023-04-16 00:43:41 +02:00
|
|
|
void removeClient(CScreencopyClient* client, bool force = false);
|
2023-04-03 18:01:05 +02:00
|
|
|
void removeFrame(SScreencopyFrame* frame, bool force = false);
|
|
|
|
void displayDestroy();
|
|
|
|
|
2023-11-04 18:03:05 +01:00
|
|
|
void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box = {0, 0, 0, 0});
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer);
|
|
|
|
|
2023-04-12 22:40:51 +02:00
|
|
|
void onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e);
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
wl_global* m_pGlobal = nullptr;
|
|
|
|
std::list<SScreencopyFrame> m_lFrames;
|
2023-04-16 00:43:41 +02:00
|
|
|
std::list<CScreencopyClient> m_lClients;
|
2023-04-03 18:01:05 +02:00
|
|
|
|
|
|
|
wl_listener m_liDisplayDestroy;
|
|
|
|
|
|
|
|
std::vector<SScreencopyFrame*> m_vFramesAwaitingWrite;
|
|
|
|
|
2023-04-12 22:40:51 +02:00
|
|
|
wlr_buffer* m_pLastMonitorBackBuffer = nullptr;
|
|
|
|
|
2023-07-19 00:51:38 +02:00
|
|
|
void shareAllFrames(CMonitor* pMonitor);
|
2023-04-03 18:01:05 +02:00
|
|
|
void shareFrame(SScreencopyFrame* frame);
|
|
|
|
void sendFrameDamage(SScreencopyFrame* frame);
|
|
|
|
bool copyFrameDmabuf(SScreencopyFrame* frame);
|
|
|
|
bool copyFrameShm(SScreencopyFrame* frame, timespec* now);
|
2023-04-17 23:57:24 +02:00
|
|
|
|
|
|
|
friend class CScreencopyClient;
|
2023-04-03 18:01:05 +02:00
|
|
|
};
|