1 | /* $Id: Framebuffer.h 98290 2023-01-24 17:31:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: VBoxSDL (simple frontend based on SDL):
|
---|
5 | * Declaration of VBoxSDLFB (SDL framebuffer) class
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox base platform packages, as
|
---|
12 | * available from https://www.virtualbox.org.
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or
|
---|
15 | * modify it under the terms of the GNU General Public License
|
---|
16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful, but
|
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | * General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | *
|
---|
27 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
|
---|
31 | #define VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
|
---|
32 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
33 | # pragma once
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include "VBoxSDL.h"
|
---|
37 | #include <iprt/thread.h>
|
---|
38 |
|
---|
39 | #include <iprt/critsect.h>
|
---|
40 |
|
---|
41 | #ifdef VBOX_SECURELABEL
|
---|
42 | #include <SDL_ttf.h>
|
---|
43 | /* function pointers */
|
---|
44 | extern "C"
|
---|
45 | {
|
---|
46 | extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
|
---|
47 | extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
|
---|
48 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
49 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
|
---|
50 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
51 | extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
|
---|
52 | extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
|
---|
53 | }
|
---|
54 | #endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL2 */
|
---|
55 |
|
---|
56 | class VBoxSDLFBOverlay;
|
---|
57 |
|
---|
58 | class ATL_NO_VTABLE VBoxSDLFB :
|
---|
59 | public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>,
|
---|
60 | VBOX_SCRIPTABLE_IMPL(IFramebuffer)
|
---|
61 | {
|
---|
62 | public:
|
---|
63 | VBoxSDLFB();
|
---|
64 | virtual ~VBoxSDLFB();
|
---|
65 |
|
---|
66 | HRESULT init(uint32_t uScreenId,
|
---|
67 | bool fFullscreen, bool fResizable, bool fShowSDLConfig,
|
---|
68 | bool fKeepHostRes, uint32_t u32FixedWidth,
|
---|
69 | uint32_t u32FixedHeight, uint32_t u32FixedBPP,
|
---|
70 | bool fUpdateImage);
|
---|
71 |
|
---|
72 | static bool init(bool fShowSDLConfig);
|
---|
73 | static void uninit();
|
---|
74 |
|
---|
75 | DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
|
---|
76 |
|
---|
77 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
78 |
|
---|
79 | BEGIN_COM_MAP(VBoxSDLFB)
|
---|
80 | COM_INTERFACE_ENTRY(IFramebuffer)
|
---|
81 | COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
|
---|
82 | COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.m_p)
|
---|
83 | END_COM_MAP()
|
---|
84 |
|
---|
85 | HRESULT FinalConstruct();
|
---|
86 | void FinalRelease();
|
---|
87 |
|
---|
88 | STDMETHOD(COMGETTER(Width))(ULONG *width);
|
---|
89 | STDMETHOD(COMGETTER(Height))(ULONG *height);
|
---|
90 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
|
---|
91 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
|
---|
92 | STDMETHOD(COMGETTER(PixelFormat))(BitmapFormat_T *pixelFormat);
|
---|
93 | STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
|
---|
94 | STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
|
---|
95 | STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
|
---|
96 | STDMETHOD(COMGETTER(Capabilities))(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities));
|
---|
97 |
|
---|
98 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
99 | STDMETHOD(NotifyUpdateImage)(ULONG x, ULONG y, ULONG w, ULONG h, ComSafeArrayIn(BYTE, aImage));
|
---|
100 | STDMETHOD(NotifyChange)(ULONG aScreenId,
|
---|
101 | ULONG aXOrigin,
|
---|
102 | ULONG aYOrigin,
|
---|
103 | ULONG aWidth,
|
---|
104 | ULONG aHeight);
|
---|
105 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
|
---|
106 |
|
---|
107 | STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
|
---|
108 | STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
|
---|
109 |
|
---|
110 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand, LONG enmCmd, BOOL fGuestCmd);
|
---|
111 |
|
---|
112 | STDMETHOD(Notify3DEvent)(ULONG uType, ComSafeArrayIn(BYTE, aData));
|
---|
113 |
|
---|
114 | // internal public methods
|
---|
115 | bool initialized() { return mfInitialized; }
|
---|
116 | void notifyChange(ULONG aScreenId);
|
---|
117 | void resizeGuest();
|
---|
118 | void resizeSDL();
|
---|
119 | void update(int x, int y, int w, int h, bool fGuestRelative);
|
---|
120 | void repaint();
|
---|
121 | void setFullscreen(bool fFullscreen);
|
---|
122 | void getFullscreenGeometry(uint32_t *width, uint32_t *height);
|
---|
123 | uint32_t getScreenId() { return mScreenId; }
|
---|
124 | uint32_t getGuestXRes() { return mGuestXRes; }
|
---|
125 | uint32_t getGuestYRes() { return mGuestYRes; }
|
---|
126 | int32_t getOriginX() { return mOriginX; }
|
---|
127 | int32_t getOriginY() { return mOriginY; }
|
---|
128 | int32_t getXOffset() { return mCenterXOffset; }
|
---|
129 | int32_t getYOffset() { return mCenterYOffset; }
|
---|
130 | #ifdef VBOX_WITH_SDL2
|
---|
131 | SDL_Window *getWindow() { return mpWindow; }
|
---|
132 | bool hasWindow(uint32_t id) { return SDL_GetWindowID(mpWindow) == id; }
|
---|
133 | int setWindowTitle(const char *pcszTitle);
|
---|
134 | #endif
|
---|
135 | #ifdef VBOX_SECURELABEL
|
---|
136 | int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
|
---|
137 | void setSecureLabelText(const char *text);
|
---|
138 | void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
|
---|
139 | void paintSecureLabel(int x, int y, int w, int h, bool fForce);
|
---|
140 | #endif
|
---|
141 | void setWinId(int64_t winId) { mWinId = winId; }
|
---|
142 | void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
|
---|
143 | bool getFullscreen() { return mfFullscreen; }
|
---|
144 |
|
---|
145 | private:
|
---|
146 |
|
---|
147 | #ifdef VBOX_WITH_SDL2
|
---|
148 | /** the SDL window */
|
---|
149 | SDL_Window *mpWindow;
|
---|
150 | /** the texture */
|
---|
151 | SDL_Texture *mpTexture;
|
---|
152 | /** renderer */
|
---|
153 | SDL_Renderer *mpRenderer;
|
---|
154 | /** render info */
|
---|
155 | SDL_RendererInfo mRenderInfo;
|
---|
156 | #endif
|
---|
157 | /** false if constructor failed */
|
---|
158 | bool mfInitialized;
|
---|
159 | /** the screen number of this framebuffer */
|
---|
160 | uint32_t mScreenId;
|
---|
161 | /** use NotifyUpdateImage */
|
---|
162 | bool mfUpdateImage;
|
---|
163 | /** maximum possible screen width in pixels (~0 = no restriction) */
|
---|
164 | uint32_t mMaxScreenWidth;
|
---|
165 | /** maximum possible screen height in pixels (~0 = no restriction) */
|
---|
166 | uint32_t mMaxScreenHeight;
|
---|
167 | /** current guest screen width in pixels */
|
---|
168 | ULONG mGuestXRes;
|
---|
169 | /** current guest screen height in pixels */
|
---|
170 | ULONG mGuestYRes;
|
---|
171 | int32_t mOriginX;
|
---|
172 | int32_t mOriginY;
|
---|
173 | /** fixed SDL screen width (~0 = not set) */
|
---|
174 | uint32_t mFixedSDLWidth;
|
---|
175 | /** fixed SDL screen height (~0 = not set) */
|
---|
176 | uint32_t mFixedSDLHeight;
|
---|
177 | /** fixed SDL bits per pixel (~0 = not set) */
|
---|
178 | uint32_t mFixedSDLBPP;
|
---|
179 | /** Y offset in pixels, i.e. guest-nondrawable area at the top */
|
---|
180 | uint32_t mTopOffset;
|
---|
181 | /** X offset for guest screen centering */
|
---|
182 | uint32_t mCenterXOffset;
|
---|
183 | /** Y offset for guest screen centering */
|
---|
184 | uint32_t mCenterYOffset;
|
---|
185 | /** flag whether we're in fullscreen mode */
|
---|
186 | bool mfFullscreen;
|
---|
187 | /** flag whether we keep the host screen resolution when switching to
|
---|
188 | * fullscreen or not */
|
---|
189 | bool mfKeepHostRes;
|
---|
190 | /** framebuffer update semaphore */
|
---|
191 | RTCRITSECT mUpdateLock;
|
---|
192 | /** flag whether the SDL window should be resizable */
|
---|
193 | bool mfResizable;
|
---|
194 | /** flag whether we print out SDL information */
|
---|
195 | bool mfShowSDLConfig;
|
---|
196 | /** handle to window where framebuffer context is being drawn*/
|
---|
197 | int64_t mWinId;
|
---|
198 | #ifdef VBOX_SECURELABEL
|
---|
199 | /** current secure label text */
|
---|
200 | Utf8Str mSecureLabelText;
|
---|
201 | /** current secure label foreground color (RGB) */
|
---|
202 | uint32_t mSecureLabelColorFG;
|
---|
203 | /** current secure label background color (RGB) */
|
---|
204 | uint32_t mSecureLabelColorBG;
|
---|
205 | /** secure label font handle */
|
---|
206 | TTF_Font *mLabelFont;
|
---|
207 | /** secure label height in pixels */
|
---|
208 | uint32_t mLabelHeight;
|
---|
209 | /** secure label offset from the top of the secure label */
|
---|
210 | uint32_t mLabelOffs;
|
---|
211 |
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | SDL_Surface *mSurfVRAM;
|
---|
215 |
|
---|
216 | BYTE *mPtrVRAM;
|
---|
217 | ULONG mBitsPerPixel;
|
---|
218 | ULONG mBytesPerLine;
|
---|
219 | BOOL mfSameSizeRequested;
|
---|
220 |
|
---|
221 | ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
|
---|
222 | ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
|
---|
223 | bool mfUpdates;
|
---|
224 |
|
---|
225 | #ifdef RT_OS_WINDOWS
|
---|
226 | ComPtr<IUnknown> m_pUnkMarshaler;
|
---|
227 | #endif
|
---|
228 | };
|
---|
229 |
|
---|
230 | class VBoxSDLFBOverlay :
|
---|
231 | public IFramebufferOverlay
|
---|
232 | {
|
---|
233 | public:
|
---|
234 | VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
|
---|
235 | VBoxSDLFB *aParent);
|
---|
236 | virtual ~VBoxSDLFBOverlay();
|
---|
237 |
|
---|
238 | #ifdef RT_OS_WINDOWS
|
---|
239 | STDMETHOD_(ULONG, AddRef)()
|
---|
240 | {
|
---|
241 | return ::InterlockedIncrement(&refcnt);
|
---|
242 | }
|
---|
243 | STDMETHOD_(ULONG, Release)()
|
---|
244 | {
|
---|
245 | long cnt = ::InterlockedDecrement(&refcnt);
|
---|
246 | if (cnt == 0)
|
---|
247 | delete this;
|
---|
248 | return cnt;
|
---|
249 | }
|
---|
250 | #endif
|
---|
251 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
252 |
|
---|
253 | NS_DECL_ISUPPORTS
|
---|
254 |
|
---|
255 | STDMETHOD(COMGETTER(X))(ULONG *x);
|
---|
256 | STDMETHOD(COMGETTER(Y))(ULONG *y);
|
---|
257 | STDMETHOD(COMGETTER(Width))(ULONG *width);
|
---|
258 | STDMETHOD(COMGETTER(Height))(ULONG *height);
|
---|
259 | STDMETHOD(COMGETTER(Visible))(BOOL *visible);
|
---|
260 | STDMETHOD(COMSETTER(Visible))(BOOL visible);
|
---|
261 | STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
|
---|
262 | STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
|
---|
263 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
|
---|
264 |
|
---|
265 | /* These are not used, or return standard values. */
|
---|
266 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
|
---|
267 | STDMETHOD(COMGETTER(PixelFormat))(ULONG *pixelFormat);
|
---|
268 | STDMETHOD(COMGETTER(UsesGuestVRAM))(BOOL *usesGuestVRAM);
|
---|
269 | STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
|
---|
270 | STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
|
---|
271 | STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
|
---|
272 |
|
---|
273 | STDMETHOD(Lock)();
|
---|
274 | STDMETHOD(Unlock)();
|
---|
275 | STDMETHOD(Move)(ULONG x, ULONG y);
|
---|
276 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
277 | STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
|
---|
278 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
279 | ULONG w, ULONG h, BOOL *finished);
|
---|
280 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
|
---|
281 |
|
---|
282 | // internal public methods
|
---|
283 | HRESULT init();
|
---|
284 |
|
---|
285 | private:
|
---|
286 | /** Overlay X offset */
|
---|
287 | ULONG mOverlayX;
|
---|
288 | /** Overlay Y offset */
|
---|
289 | ULONG mOverlayY;
|
---|
290 | /** Overlay width */
|
---|
291 | ULONG mOverlayWidth;
|
---|
292 | /** Overlay height */
|
---|
293 | ULONG mOverlayHeight;
|
---|
294 | /** Whether the overlay is currently active */
|
---|
295 | BOOL mOverlayVisible;
|
---|
296 | /** The parent IFramebuffer */
|
---|
297 | VBoxSDLFB *mParent;
|
---|
298 | /** SDL surface containing the actual framebuffer bits */
|
---|
299 | SDL_Surface *mOverlayBits;
|
---|
300 | /** Additional SDL surface used for combining the framebuffer and the overlay */
|
---|
301 | SDL_Surface *mBlendedBits;
|
---|
302 | #ifdef RT_OS_WINDOWS
|
---|
303 | long refcnt;
|
---|
304 | #endif
|
---|
305 | };
|
---|
306 |
|
---|
307 | #endif /* !VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h */
|
---|