summaryrefslogtreecommitdiff
path: root/src/protocols/Screencopy.hpp
blob: b73c090dd97b80500cda1548530dd8bc562e8955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include "WaylandProtocol.hpp"
#include "wlr-screencopy-unstable-v1.hpp"

#include "../helpers/time/Time.hpp"
#include "./types/Buffer.hpp"
#include <aquamarine/buffer/Buffer.hpp>

#include <vector>

class CMonitor;
class IHLBuffer;
namespace Screenshare {
    class CScreenshareSession;
    class CScreenshareFrame;
};

class CScreencopyClient {
  public:
    CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_);

    bool good();

  private:
    SP<CZwlrScreencopyManagerV1> m_resource;
    WP<CScreencopyClient>        m_self;

    wl_client*                   m_savedClient = nullptr;

    void                         captureOutput(uint32_t frame, int32_t overlayCursor, wl_resource* output, CBox box);

    friend class CScreencopyProtocol;
};

class CScreencopyFrame {
  public:
    CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource, WP<Screenshare::CScreenshareSession> session, bool overlayCursor);

    bool good();

  private:
    SP<CZwlrScreencopyFrameV1>           m_resource;
    WP<CScreencopyFrame>                 m_self;
    WP<CScreencopyClient>                m_client;

    WP<Screenshare::CScreenshareSession> m_session;
    UP<Screenshare::CScreenshareFrame>   m_frame;

    CHLBufferReference                   m_buffer;
    Time::steady_tp                      m_timestamp;
    bool                                 m_overlayCursor = true;

    //
    void shareFrame(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer, bool withDamage);

    friend class CScreencopyProtocol;
    friend class CScreencopyClient;
};

class CScreencopyProtocol : public IWaylandProtocol {
  public:
    CScreencopyProtocol(const wl_interface* iface, const int& ver, const std::string& name);

    virtual void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
    void         destroyResource(CScreencopyClient* resource);
    void         destroyResource(CScreencopyFrame* resource);

  private:
    std::vector<SP<CScreencopyFrame>>  m_frames;
    std::vector<SP<CScreencopyClient>> m_clients;

    friend class CScreencopyFrame;
    friend class CScreencopyClient;
};

namespace PROTO {
    inline UP<CScreencopyProtocol> screencopy;
};