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