VirtualBox

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

Last change on this file since 41201 was 41201, checked in by vboxsync, 12 years ago

Main+Frontends: replace custom QueryInterface method to eliminate unnecessary code variation

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