FreeRDP
Loading...
Searching...
No Matches
sdl_overlay.hpp
1
19
20#pragma once
21
22#include <atomic>
23#include <chrono>
24#include <cstdint>
25#include <memory>
26#include <mutex>
27#include <optional>
28#include <vector>
29
30#include <SDL3/SDL.h>
31#include <SDL3_ttf/SDL_ttf.h>
32
33#include <freerdp/freerdp.h>
34#include <freerdp/timer.h>
35
36#include "sdl_overlay_model.hpp"
37
38class SdlContext;
39
45class SdlOverlay
46{
47 public:
48 explicit SdlOverlay(SdlContext* sdl);
49 SdlOverlay(const SdlOverlay& other) = delete;
50 SdlOverlay(SdlOverlay&& other) = delete;
51 ~SdlOverlay() = default;
52 SdlOverlay& operator=(const SdlOverlay& other) = delete;
53 SdlOverlay& operator=(SdlOverlay&& other) = delete;
54
55 [[nodiscard]] bool visible() const;
56
58 [[nodiscard]] bool show(bool on);
59
61 [[nodiscard]] bool connected();
62
65 [[nodiscard]] bool update(int windowWidth, int windowHeight, const char* rendererName);
66
69 [[nodiscard]] const std::vector<sdl::overlay::Row>& left() const;
70 [[nodiscard]] const std::vector<sdl::overlay::Row>& right() const;
71 [[nodiscard]] uint64_t generation() const;
72
73 private:
74 [[nodiscard]] bool arm();
75 [[nodiscard]] static uint64_t onTimer(rdpContext* context, void* userdata,
76 FreeRDP_TimerID timerID, uint64_t timestamp,
77 uint64_t interval);
78 [[nodiscard]] bool read(rdpContext* context, uint64_t timestamp);
79 void clientRows(const char* rendererName);
80
81 SdlContext* _sdl;
82 std::atomic<bool> _visible = false;
83 std::atomic<bool> _armed = false;
84
85 /* written on the session thread, taken on SDL's */
86 std::mutex _mutex;
87 std::optional<sdl::overlay::Reading> _pending;
88 std::chrono::steady_clock::time_point _since;
89 bool _restart = false;
90
91 /* SDL's thread only */
92 std::optional<sdl::overlay::Names> _names;
93 std::optional<sdl::overlay::Reading> _prev;
94 std::vector<sdl::overlay::Row> _client;
95 std::vector<sdl::overlay::Row> _left;
96 std::vector<sdl::overlay::Row> _right;
97 uint64_t _generation = 0;
98};
99
102class SdlOverlayPainter
103{
104 public:
105 explicit SdlOverlayPainter(SDL_Renderer* renderer);
106 SdlOverlayPainter(const SdlOverlayPainter& other) = delete;
107 SdlOverlayPainter(SdlOverlayPainter&& other) = delete;
108 ~SdlOverlayPainter();
109 SdlOverlayPainter& operator=(const SdlOverlayPainter& other) = delete;
110 SdlOverlayPainter& operator=(SdlOverlayPainter&& other) = delete;
111
113 void draw(const SdlOverlay& overlay, int width, int height, float scale);
114
115 private:
116 struct Cell
117 {
118 TTF_Text* label = nullptr;
119 TTF_Text* value = nullptr;
120 };
121
122 void clear();
123 [[nodiscard]] bool rebuild(const SdlOverlay& overlay, float scale);
124 [[nodiscard]] std::vector<Cell> cells(const std::vector<sdl::overlay::Row>& rows);
125 void drawPanel(const std::vector<Cell>& list, const sdl::overlay::Box& where);
126 [[nodiscard]] SDL_FPoint panelSize(const std::vector<Cell>& list, float& labelWidth) const;
127
128 SDL_Renderer* _renderer;
129 TTF_TextEngine* _engine = nullptr;
130 TTF_Font* _font = nullptr;
131 float _scale = 0.0F;
132 uint64_t _generation = UINT64_MAX;
133 std::vector<Cell> _left;
134 std::vector<Cell> _right;
135};
void draw(const SdlOverlay &overlay, int width, int height, float scale)
const std::vector< sdl::overlay::Row > & left() const
bool update(int windowWidth, int windowHeight, const char *rendererName)
bool connected()
bool show(bool on)