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 [[nodiscard]] rdpMonitor monitor(bool isPrimary) const;
69 void setMonitor(rdpMonitor monitor);
70
71 [[nodiscard]] float scale() const;
72 [[nodiscard]] SDL_DisplayOrientation orientation() const;
73
74 [[nodiscard]] bool grabKeyboard(bool enable);
75 [[nodiscard]] bool grabMouse(bool enable);
76 void setBordered(bool bordered);
77 void raise();
78 void resizeable(bool use);
79 void fullscreen(bool enter, bool forceOriginalDisplay);
80 void minimize();
81
82 [[nodiscard]] bool resizeToScale();
83 [[nodiscard]] bool resize(const SDL_Point& size);
84
85 [[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
86 [[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
87 const std::vector<SDL_Rect>& rects = {});
88 [[nodiscard]] bool drawScaledRect(SDL_Surface* surface, const SDL_FPoint& scale,
89 const SDL_Rect& srcRect);
90
91 [[nodiscard]] bool drawScaledRects(SDL_Surface* surface, const SDL_FPoint& scale,
92 const std::vector<SDL_Rect>& rects = {});
93
94 [[nodiscard]] bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
95
96 [[nodiscard]] bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
97 [[nodiscard]] bool upload(SDL_Surface* surface, const SDL_Rect& src);
98 [[nodiscard]] bool render(const SDL_Rect& src, const SDL_Rect& dst);
99 /* Render interactive resize feedback overlay. */
100 bool paintResizeFrame(SDL_Surface* surface, SDL_Point off, bool contentChanged,
101 const SDL_Rect& inset = { 0, 0, 0, 0 }, bool fillRevealed = true,
102 bool dashedBorder = true);
104 void updateSurface(const SdlOverlay* overlay = nullptr);
105 [[nodiscard]] const char* rendererName() const;
106
111 [[nodiscard]] bool setVideoOverlay(Uint64 id, const void* pixels, int pitch, int w, int h,
112 const SDL_FRect& dst, const std::vector<SDL_FRect>& clip,
113 bool visible);
115 void pruneVideoOverlays(const std::function<bool(Uint64)>& keep);
116
117 protected:
118 SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect& rect, Uint32 flags);
119 SdlWindow(SDL_Window* parent, const SDL_Rect& rect, bool transparent, bool tooltip);
120
121 [[nodiscard]] static bool fill(SDL_Window* window, Uint8 r = 0x00, Uint8 g = 0x00,
122 Uint8 b = 0x00, Uint8 a = 0xff);
123 [[nodiscard]] static rdpMonitor query(SDL_Window* window, SDL_DisplayID id,
124 bool forceAsPrimary = false);
125 [[nodiscard]] static SDL_Rect rect(SDL_Window* window, bool forceAsPrimary = false);
126 [[nodiscard]] static SDL_Rect rect(SDL_DisplayID id, bool forceAsPrimary = false);
127
128 [[nodiscard]] static bool tryFallback(bool isFullscreen);
129
130 enum HighDPIMode
131 {
132 MODE_INVALID,
133 MODE_NONE,
134 MODE_WINDOWS,
135 MODE_MACOS
136 };
137
138 [[nodiscard]] static enum HighDPIMode isHighDPIWindowsMode(SDL_Window* window);
139
140 private:
141 void ensureRenderTarget();
142 void drawOverlay(const SdlOverlay& overlay);
143 bool ensureGdiTexture(SDL_Surface* surface);
144
145 SDL_Window* _window = nullptr;
146 /* redirected videos, drawn over the session at each present */
147 struct VideoOverlay
148 {
149 SDL_Texture* texture = nullptr;
150 int w = 0;
151 int h = 0;
152 SDL_FRect dst{};
153 std::vector<SDL_FRect> clip;
154 bool visible = false;
155 };
156 std::map<Uint64, VideoOverlay> _videoOverlays;
157 void drawVideoOverlays();
158
159 SDL_Renderer* _renderer = nullptr;
160 SDL_Texture* _renderTarget = nullptr;
161 SDL_Texture* _gdiTexture = nullptr;
162 std::unique_ptr<SdlOverlayPainter> _overlayPainter;
163 int _gdiTextureW = 0;
164 int _gdiTextureH = 0;
165 int _initialW = 0;
166 int _initialH = 0;
167 SDL_DisplayID _displayID = 0;
168 Sint32 _offset_x = 0;
169 Sint32 _offset_y = 0;
170 rdpMonitor _monitor{};
171};
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)