VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.h@ 51602

Last change on this file since 51602 was 51547, checked in by vboxsync, 11 years ago

VBoxSDL: new IFramebuffer interface cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
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 */
30extern "C"
31{
32extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
33extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
34extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
35extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
36extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
37extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
38extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
39}
40#endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL13 */
41
42class VBoxSDLFBOverlay;
43
44class VBoxSDLFB :
45 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
46{
47public:
48 VBoxSDLFB(uint32_t uScreenId,
49 bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
50 bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
51 uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
52 virtual ~VBoxSDLFB();
53
54 static bool init(bool fShowSDLConfig);
55 static void uninit();
56
57#ifdef RT_OS_WINDOWS
58 STDMETHOD_(ULONG, AddRef)()
59 {
60 return ::InterlockedIncrement (&refcnt);
61 }
62 STDMETHOD_(ULONG, Release)()
63 {
64 long cnt = ::InterlockedDecrement (&refcnt);
65 if (cnt == 0)
66 delete this;
67 return cnt;
68 }
69#endif
70 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
71
72 NS_DECL_ISUPPORTS
73
74 STDMETHOD(COMGETTER(Width))(ULONG *width);
75 STDMETHOD(COMGETTER(Height))(ULONG *height);
76 STDMETHOD(Lock)();
77 STDMETHOD(Unlock)();
78 STDMETHOD(COMGETTER(Address))(BYTE **address);
79 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
80 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
81 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
82 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
83 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
84 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
85 STDMETHOD(COMGETTER(WinId)) (int64_t *winId);
86
87 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
88 STDMETHOD(NotifyChange)(ULONG aScreenId,
89 ULONG aXOrigin,
90 ULONG aYOrigin,
91 ULONG aWidth,
92 ULONG aHeight);
93 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
94
95 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
96 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
97
98 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
99
100 STDMETHOD(Notify3DEvent)(ULONG uType, BYTE *pReserved);
101
102 // internal public methods
103 bool initialized() { return mfInitialized; }
104 void notifyChange(ULONG aScreenId);
105 void resizeGuest();
106 void resizeSDL();
107 void update(int x, int y, int w, int h, bool fGuestRelative);
108 void repaint();
109 void setFullscreen(bool fFullscreen);
110 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
111 uint32_t getScreenId() { return mScreenId; }
112 uint32_t getGuestXRes() { return mGuestXRes; }
113 uint32_t getGuestYRes() { return mGuestYRes; }
114 int32_t getOriginX() { return mOriginX; }
115 int32_t getOriginY() { return mOriginY; }
116 int32_t getXOffset() { return mCenterXOffset; }
117 int32_t getYOffset() { return mCenterYOffset; }
118#ifdef VBOX_WITH_SDL13
119 bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
120#endif
121#ifdef VBOX_SECURELABEL
122 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
123 void setSecureLabelText(const char *text);
124 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
125 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
126#endif
127 void setWinId(int64_t winId) { mWinId = winId; }
128 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
129 bool getFullscreen() { return mfFullscreen; }
130
131private:
132 /** current SDL framebuffer pointer (also includes screen width/height) */
133 SDL_Surface *mScreen;
134#ifdef VBOX_WITH_SDL13
135 /** the SDL window */
136 SDL_WindowID mWindow;
137 /** the texture */
138 SDL_TextureID mTexture;
139 /** render info */
140 SDL_RendererInfo mRenderInfo;
141#endif
142 /** false if constructor failed */
143 bool mfInitialized;
144 /** the screen number of this framebuffer */
145 uint32_t mScreenId;
146 /** maximum possible screen width in pixels (~0 = no restriction) */
147 uint32_t mMaxScreenWidth;
148 /** maximum possible screen height in pixels (~0 = no restriction) */
149 uint32_t mMaxScreenHeight;
150 /** current guest screen width in pixels */
151 ULONG mGuestXRes;
152 /** current guest screen height in pixels */
153 ULONG mGuestYRes;
154 int32_t mOriginX;
155 int32_t mOriginY;
156 /** fixed SDL screen width (~0 = not set) */
157 uint32_t mFixedSDLWidth;
158 /** fixed SDL screen height (~0 = not set) */
159 uint32_t mFixedSDLHeight;
160 /** fixed SDL bits per pixel (~0 = not set) */
161 uint32_t mFixedSDLBPP;
162 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
163 uint32_t mTopOffset;
164 /** X offset for guest screen centering */
165 uint32_t mCenterXOffset;
166 /** Y offset for guest screen centering */
167 uint32_t mCenterYOffset;
168 /** flag whether we're in fullscreen mode */
169 bool mfFullscreen;
170 /** flag whether we keep the host screen resolution when switching to
171 * fullscreen or not */
172 bool mfKeepHostRes;
173 /** framebuffer update semaphore */
174 RTCRITSECT mUpdateLock;
175 /** flag whether the SDL window should be resizable */
176 bool mfResizable;
177 /** flag whether we print out SDL information */
178 bool mfShowSDLConfig;
179 /** handle to window where framebuffer context is being drawn*/
180 int64_t mWinId;
181#ifdef VBOX_SECURELABEL
182 /** current secure label text */
183 Utf8Str mSecureLabelText;
184 /** current secure label foreground color (RGB) */
185 uint32_t mSecureLabelColorFG;
186 /** current secure label background color (RGB) */
187 uint32_t mSecureLabelColorBG;
188 /** secure label font handle */
189 TTF_Font *mLabelFont;
190 /** secure label height in pixels */
191 uint32_t mLabelHeight;
192 /** secure label offset from the top of the secure label */
193 uint32_t mLabelOffs;
194
195#endif
196#ifdef RT_OS_WINDOWS
197 long refcnt;
198#endif
199 SDL_Surface *mSurfVRAM;
200
201 BYTE *mPtrVRAM;
202 ULONG mBitsPerPixel;
203 ULONG mBytesPerLine;
204 BOOL mfSameSizeRequested;
205
206 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
207 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
208 bool mfUpdates;
209};
210
211class VBoxSDLFBOverlay :
212 public IFramebufferOverlay
213{
214public:
215 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
216 VBoxSDLFB *aParent);
217 virtual ~VBoxSDLFBOverlay();
218
219#ifdef RT_OS_WINDOWS
220 STDMETHOD_(ULONG, AddRef)()
221 {
222 return ::InterlockedIncrement (&refcnt);
223 }
224 STDMETHOD_(ULONG, Release)()
225 {
226 long cnt = ::InterlockedDecrement (&refcnt);
227 if (cnt == 0)
228 delete this;
229 return cnt;
230 }
231#endif
232 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
233
234 NS_DECL_ISUPPORTS
235
236 STDMETHOD(COMGETTER(X))(ULONG *x);
237 STDMETHOD(COMGETTER(Y))(ULONG *y);
238 STDMETHOD(COMGETTER(Width))(ULONG *width);
239 STDMETHOD(COMGETTER(Height))(ULONG *height);
240 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
241 STDMETHOD(COMSETTER(Visible))(BOOL visible);
242 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
243 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
244 STDMETHOD(COMGETTER(Address))(ULONG *address);
245 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
246
247 /* These are not used, or return standard values. */
248 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
249 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
250 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
251 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
252 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
253 STDMETHOD(COMGETTER(WinId)) (LONG64 *winId);
254
255 STDMETHOD(Lock)();
256 STDMETHOD(Unlock)();
257 STDMETHOD(Move)(ULONG x, ULONG y);
258 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
259 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
260 ULONG bitsPerPixel, ULONG bytesPerLine,
261 ULONG w, ULONG h, BOOL *finished);
262 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
263
264 // internal public methods
265 HRESULT init();
266
267private:
268 /** Overlay X offset */
269 ULONG mOverlayX;
270 /** Overlay Y offset */
271 ULONG mOverlayY;
272 /** Overlay width */
273 ULONG mOverlayWidth;
274 /** Overlay height */
275 ULONG mOverlayHeight;
276 /** Whether the overlay is currently active */
277 BOOL mOverlayVisible;
278 /** The parent IFramebuffer */
279 VBoxSDLFB *mParent;
280 /** SDL surface containing the actual framebuffer bits */
281 SDL_Surface *mOverlayBits;
282 /** Additional SDL surface used for combining the framebuffer and the overlay */
283 SDL_Surface *mBlendedBits;
284#ifdef RT_OS_WINDOWS
285 long refcnt;
286#endif
287};
288
289#endif // __H_FRAMEBUFFER
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette