VirtualBox

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

Last change on this file since 35273 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

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