FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_window.hpp
1
20#pragma once
21
22#include <functional>
23#include <map>
24#include <memory>
25#include <string>
26#include <vector>
27
28#include <SDL3/SDL.h>
29
30#include <freerdp/settings_types.h>
31
32class SdlOverlay;
34
35class SdlWindow
36{
37 public:
38 [[nodiscard]] static SdlWindow create(SDL_DisplayID id, const std::string& title, Uint32 flags,
39 Uint32 width = 0, Uint32 height = 0);
40 /* Create at an explicit position+size (RAIL windows: server-driven geometry). */
41 [[nodiscard]] static SdlWindow create(SDL_DisplayID id, const std::string& title, Uint32 flags,
42 const SDL_Rect& rect);
43 /* Popup: no taskbar entry, no keyboard focus, Wayland-positionable (xdg_popup). */
44 [[nodiscard]] static SdlWindow createPopup(SDL_Window* parent, const SDL_Rect& rect,
45 bool transparent, bool tooltip = false);
46 [[nodiscard]] static rdpMonitor query(SDL_DisplayID id, bool forceAsPrimary = false);
47
48 SdlWindow(SdlWindow&& other) noexcept;
49 SdlWindow(const SdlWindow& other) = delete;
50 virtual ~SdlWindow();
51
52 SdlWindow& operator=(const SdlWindow& other) = delete;
53 SdlWindow& operator=(SdlWindow&& other) = delete;
54
55 [[nodiscard]] SDL_WindowID id() const;
56 [[nodiscard]] SDL_DisplayID displayIndex() const;
57 [[nodiscard]] SDL_Rect rect() const;
58 [[nodiscard]] SDL_Rect bounds() const;
59 [[nodiscard]] SDL_Window* window() const;
60 [[nodiscard]] SDL_Renderer* renderer() const;
61
62 [[nodiscard]] Sint32 offsetX() const;
63 void setOffsetX(Sint32 x);
64
65 void setOffsetY(Sint32 y);
66 [[nodiscard]] Sint32 offsetY() const;
67
68 /* Top left of the area this window shows, in the monitor layout sent to the server. */
69 [[nodiscard]] SDL_Point layoutPosition() const;
70 void setLayoutPosition(const SDL_Point& pos);
71
72 [[nodiscard]] rdpMonitor monitor(bool isPrimary) const;
73 void setMonitor(rdpMonitor monitor);
74
75 [[nodiscard]] float scale() const;
76 [[nodiscard]] SDL_DisplayOrientation orientation() const;
77
78 [[nodiscard]] bool grabKeyboard(bool enable);
79 [[nodiscard]] bool grabMouse(bool enable);
80 void setBordered(bool bordered);
81 void raise();
82 void resizeable(bool use);
83 void fullscreen(bool enter, bool forceOriginalDisplay);
84 void minimize();
85
86 [[nodiscard]] bool resizeToScale();
87 [[nodiscard]] bool resize(const SDL_Point& size);
88
89 [[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
90 [[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
91 const std::vector<SDL_Rect>& rects = {});
92 [[nodiscard]] bool drawScaledRect(SDL_Surface* surface, const SDL_FPoint& scale,
93 const SDL_Rect& srcRect);
94
95 [[nodiscard]] bool drawScaledRects(SDL_Surface* surface, const SDL_FPoint& scale,
96 const std::vector<SDL_Rect>& rects = {});
97
98 [[nodiscard]] bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
99
100 [[nodiscard]] bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
101 [[nodiscard]] bool upload(SDL_Surface* surface, const SDL_Rect& src);
102 [[nodiscard]] bool render(const SDL_Rect& src, const SDL_Rect& dst);
103 /* Render interactive resize feedback overlay. */
104 bool paintResizeFrame(SDL_Surface* surface, SDL_Point off, bool contentChanged,
105 const SDL_Rect& inset = { 0, 0, 0, 0 }, bool fillRevealed = true,
106 bool dashedBorder = true);
108 void updateSurface(const SdlOverlay* overlay = nullptr);
109 [[nodiscard]] const char* rendererName() const;
110
115 [[nodiscard]] bool setVideoOverlay(Uint64 id, const void* pixels, int pitch, int w, int h,
116 const SDL_FRect& dst, const std::vector<SDL_FRect>& clip,
117 bool visible);
119 void pruneVideoOverlays(const std::function<bool(Uint64)>& keep);
120
121 protected:
122 SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect& rect, Uint32 flags);
123 SdlWindow(SDL_Window* parent, const SDL_Rect& rect, bool transparent, bool tooltip);
124
125 [[nodiscard]] static bool fill(SDL_Window* window, Uint8 r = 0x00, Uint8 g = 0x00,
126 Uint8 b = 0x00, Uint8 a = 0xff);
127 [[nodiscard]] static rdpMonitor query(SDL_Window* window, SDL_DisplayID id,
128 bool forceAsPrimary = false);
129 [[nodiscard]] static SDL_Rect rect(SDL_Window* window, bool forceAsPrimary = false);
130 [[nodiscard]] static SDL_Rect rect(SDL_DisplayID id, bool forceAsPrimary = false);
131
132 [[nodiscard]] static bool tryFallback(bool isFullscreen);
133
134 enum HighDPIMode
135 {
136 MODE_INVALID,
137 MODE_NONE,
138 MODE_WINDOWS,
139 MODE_MACOS
140 };
141
142 [[nodiscard]] static enum HighDPIMode isHighDPIWindowsMode(SDL_Window* window);
143
144 private:
145 void ensureRenderTarget();
146 void drawOverlay(const SdlOverlay& overlay);
147 bool ensureGdiTexture(SDL_Surface* surface);
148
149 SDL_Window* _window = nullptr;
150 /* redirected videos, drawn over the session at each present */
151 struct VideoOverlay
152 {
153 SDL_Texture* texture = nullptr;
154 int w = 0;
155 int h = 0;
156 SDL_FRect dst{};
157 std::vector<SDL_FRect> clip;
158 bool visible = false;
159 };
160 std::map<Uint64, VideoOverlay> _videoOverlays;
161 void drawVideoOverlays();
162
163 SDL_Renderer* _renderer = nullptr;
164 SDL_Texture* _renderTarget = nullptr;
165 SDL_Texture* _gdiTexture = nullptr;
166 std::unique_ptr<SdlOverlayPainter> _overlayPainter;
167 int _gdiTextureW = 0;
168 int _gdiTextureH = 0;
169 int _initialW = 0;
170 int _initialH = 0;
171 SDL_DisplayID _displayID = 0;
172 SDL_Point _layoutPosition{};
173 Sint32 _offset_x = 0;
174 Sint32 _offset_y = 0;
175 rdpMonitor _monitor{};
176};
void pruneVideoOverlays(const std::function< bool(Uint64)> &keep)
drops the overlays keep returns false for
bool setVideoOverlay(Uint64 id, const void *pixels, int pitch, int w, int h, const SDL_FRect &dst, const std::vector< SDL_FRect > &clip, bool visible)
redirected video id, drawn over the session at each present at dst (render coordinates),...
SdlWindow(const std::string &title, Sint32 startupX, Sint32 startupY, Sint32 width, Sint32 height, Uint32 flags)