1 | /* $Id: Framebuffer.h 96407 2022-08-22 17:43:14Z 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-2022 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 mScreen && 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 | /** current SDL framebuffer pointer (also includes screen width/height) */
|
---|
147 | SDL_Surface *mScreen;
|
---|
148 | #ifdef VBOX_WITH_SDL2
|
---|
149 | /** the SDL window */
|
---|
150 | SDL_Window *mpWindow;
|
---|
151 | /** the texture */
|
---|
152 | SDL_Texture *mpTexture;
|
---|
153 | /** renderer */
|
---|
154 | SDL_Renderer *mpRenderer;
|
---|
155 | /** render info */
|
---|
156 | SDL_RendererInfo mRenderInfo;
|
---|
157 | #endif
|
---|
158 | /** false if constructor failed */
|
---|
159 | bool mfInitialized;
|
---|
160 | /** the screen number of this framebuffer */
|
---|
161 | uint32_t mScreenId;
|
---|
162 | /** use NotifyUpdateImage */
|
---|
163 | bool mfUpdateImage;
|
---|
164 | /** maximum possible screen width in pixels (~0 = no restriction) */
|
---|
165 | uint32_t mMaxScreenWidth;
|
---|
166 | /** maximum possible screen height in pixels (~0 = no restriction) */
|
---|
167 | uint32_t mMaxScreenHeight;
|
---|
168 | /** current guest screen width in pixels */
|
---|
169 | ULONG mGuestXRes;
|
---|
170 | /** current guest screen height in pixels */
|
---|
171 | ULONG mGuestYRes;
|
---|
172 | int32_t mOriginX;
|
---|
173 | int32_t mOriginY;
|
---|
174 | /** fixed SDL screen width (~0 = not set) */
|
---|
175 | uint32_t mFixedSDLWidth;
|
---|
176 | /** fixed SDL screen height (~0 = not set) */
|
---|
177 | uint32_t mFixedSDLHeight;
|
---|
178 | /** fixed SDL bits per pixel (~0 = not set) */
|
---|
179 | uint32_t mFixedSDLBPP;
|
---|
180 | /** Y offset in pixels, i.e. guest-nondrawable area at the top */
|
---|
181 | uint32_t mTopOffset;
|
---|
182 | /** X offset for guest screen centering */
|
---|
183 | uint32_t mCenterXOffset;
|
---|
184 | /** Y offset for guest screen centering */
|
---|
185 | uint32_t mCenterYOffset;
|
---|
186 | /** flag whether we're in fullscreen mode */
|
---|
187 | bool mfFullscreen;
|
---|
188 | /** flag whether we keep the host screen resolution when switching to
|
---|
189 | * fullscreen or not */
|
---|
190 | bool mfKeepHostRes;
|
---|
191 | /** framebuffer update semaphore */
|
---|
192 | RTCRITSECT mUpdateLock;
|
---|
193 | /** flag whether the SDL window should be resizable */
|
---|
194 | bool mfResizable;
|
---|
195 | /** flag whether we print out SDL information */
|
---|
196 | bool mfShowSDLConfig;
|
---|
197 | /** handle to window where framebuffer context is being drawn*/
|
---|
198 | int64_t mWinId;
|
---|
199 | #ifdef VBOX_SECURELABEL
|
---|
200 | /** current secure label text */
|
---|
201 | Utf8Str mSecureLabelText;
|
---|
202 | /** current secure label foreground color (RGB) */
|
---|
203 | uint32_t mSecureLabelColorFG;
|
---|
204 | /** current secure label background color (RGB) */
|
---|
205 | uint32_t mSecureLabelColorBG;
|
---|
206 | /** secure label font handle */
|
---|
207 | TTF_Font *mLabelFont;
|
---|
208 | /** secure label height in pixels */
|
---|
209 | uint32_t mLabelHeight;
|
---|
210 | /** secure label offset from the top of the secure label */
|
---|
211 | uint32_t mLabelOffs;
|
---|
212 |
|
---|
213 | #endif
|
---|
214 |
|
---|
215 | SDL_Surface *mSurfVRAM;
|
---|
216 |
|
---|
217 | BYTE *mPtrVRAM;
|
---|
218 | ULONG mBitsPerPixel;
|
---|
219 | ULONG mBytesPerLine;
|
---|
220 | BOOL mfSameSizeRequested;
|
---|
221 |
|
---|
222 | ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
|
---|
223 | ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
|
---|
224 | bool mfUpdates;
|
---|
225 |
|
---|
226 | #ifdef RT_OS_WINDOWS
|
---|
227 | ComPtr<IUnknown> m_pUnkMarshaler;
|
---|
228 | #endif
|
---|
229 | };
|
---|
230 |
|
---|
231 | class VBoxSDLFBOverlay :
|
---|
232 | public IFramebufferOverlay
|
---|
233 | {
|
---|
234 | public:
|
---|
235 | VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
|
---|
236 | VBoxSDLFB *aParent);
|
---|
237 | virtual ~VBoxSDLFBOverlay();
|
---|
238 |
|
---|
239 | #ifdef RT_OS_WINDOWS
|
---|
240 | STDMETHOD_(ULONG, AddRef)()
|
---|
241 | {
|
---|
242 | return ::InterlockedIncrement(&refcnt);
|
---|
243 | }
|
---|
244 | STDMETHOD_(ULONG, Release)()
|
---|
245 | {
|
---|
246 | long cnt = ::InterlockedDecrement(&refcnt);
|
---|
247 | if (cnt == 0)
|
---|
248 | delete this;
|
---|
249 | return cnt;
|
---|
250 | }
|
---|
251 | #endif
|
---|
252 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
253 |
|
---|
254 | NS_DECL_ISUPPORTS
|
---|
255 |
|
---|
256 | STDMETHOD(COMGETTER(X))(ULONG *x);
|
---|
257 | STDMETHOD(COMGETTER(Y))(ULONG *y);
|
---|
258 | STDMETHOD(COMGETTER(Width))(ULONG *width);
|
---|
259 | STDMETHOD(COMGETTER(Height))(ULONG *height);
|
---|
260 | STDMETHOD(COMGETTER(Visible))(BOOL *visible);
|
---|
261 | STDMETHOD(COMSETTER(Visible))(BOOL visible);
|
---|
262 | STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
|
---|
263 | STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
|
---|
264 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
|
---|
265 |
|
---|
266 | /* These are not used, or return standard values. */
|
---|
267 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
|
---|
268 | STDMETHOD(COMGETTER(PixelFormat))(ULONG *pixelFormat);
|
---|
269 | STDMETHOD(COMGETTER(UsesGuestVRAM))(BOOL *usesGuestVRAM);
|
---|
270 | STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
|
---|
271 | STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
|
---|
272 | STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
|
---|
273 |
|
---|
274 | STDMETHOD(Lock)();
|
---|
275 | STDMETHOD(Unlock)();
|
---|
276 | STDMETHOD(Move)(ULONG x, ULONG y);
|
---|
277 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
278 | STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
|
---|
279 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
280 | ULONG w, ULONG h, BOOL *finished);
|
---|
281 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
|
---|
282 |
|
---|
283 | // internal public methods
|
---|
284 | HRESULT init();
|
---|
285 |
|
---|
286 | private:
|
---|
287 | /** Overlay X offset */
|
---|
288 | ULONG mOverlayX;
|
---|
289 | /** Overlay Y offset */
|
---|
290 | ULONG mOverlayY;
|
---|
291 | /** Overlay width */
|
---|
292 | ULONG mOverlayWidth;
|
---|
293 | /** Overlay height */
|
---|
294 | ULONG mOverlayHeight;
|
---|
295 | /** Whether the overlay is currently active */
|
---|
296 | BOOL mOverlayVisible;
|
---|
297 | /** The parent IFramebuffer */
|
---|
298 | VBoxSDLFB *mParent;
|
---|
299 | /** SDL surface containing the actual framebuffer bits */
|
---|
300 | SDL_Surface *mOverlayBits;
|
---|
301 | /** Additional SDL surface used for combining the framebuffer and the overlay */
|
---|
302 | SDL_Surface *mBlendedBits;
|
---|
303 | #ifdef RT_OS_WINDOWS
|
---|
304 | long refcnt;
|
---|
305 | #endif
|
---|
306 | };
|
---|
307 |
|
---|
308 | #endif /* !VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h */
|
---|