VirtualBox

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

Last change on this file since 11725 was 11400, checked in by vboxsync, 16 years ago

VBoxSDL: improve fullscreenresize hack a little bit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifndef __H_FRAMEBUFFER
24#define __H_FRAMEBUFFER
25
26#include "VBoxSDL.h"
27#include <iprt/thread.h>
28
29#include <iprt/critsect.h>
30
31#ifdef VBOX_SECURELABEL
32#include <SDL_ttf.h>
33/* function pointers */
34extern "C"
35{
36extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
37extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
38extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
39extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
40extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
41extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
42extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
43}
44#endif /* VBOX_SECURELABEL */
45
46class VBoxSDLFBOverlay;
47
48class VBoxSDLFB :
49 public IFramebuffer
50{
51public:
52 VBoxSDLFB(bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
53 bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
54 uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
55 virtual ~VBoxSDLFB();
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 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
70 {
71 if (riid == IID_IUnknown)
72 {
73 *ppObj = this;
74 AddRef();
75 return S_OK;
76 }
77 if (riid == IID_IFramebuffer)
78 {
79 *ppObj = this;
80 AddRef();
81 return S_OK;
82 }
83 *ppObj = NULL;
84 return E_NOINTERFACE;
85 }
86#endif
87
88 NS_DECL_ISUPPORTS
89
90 STDMETHOD(COMGETTER(Width))(ULONG *width);
91 STDMETHOD(COMGETTER(Height))(ULONG *height);
92 STDMETHOD(Lock)();
93 STDMETHOD(Unlock)();
94 STDMETHOD(COMGETTER(Address))(BYTE **address);
95 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
96 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
97 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
98 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
99 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
100 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
101
102 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
103 ULONG w, ULONG h, BOOL *finished);
104 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
105 ULONG bitsPerPixel, ULONG bytesPerLine,
106 ULONG w, ULONG h, BOOL *finished);
107 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
108 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
109 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
110 ULONG color, BOOL *handled);
111 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
112 ULONG width, ULONG height, BOOL *handled);
113
114 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
115 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
116
117 // internal public methods
118 bool initialized() { return mfInitialized; }
119 void resizeGuest();
120 void resizeSDL();
121 void update(int x, int y, int w, int h, bool fGuestRelative);
122 void repaint();
123 bool getFullscreen();
124 void setFullscreen(bool fFullscreen);
125 int getXOffset();
126 int getYOffset();
127 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
128 uint32_t getGuestXRes() { return mGuestXRes; }
129 uint32_t getGuestYRes() { return mGuestYRes; }
130#ifdef VBOX_SECURELABEL
131 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
132 void setSecureLabelText(const char *text);
133 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
134 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
135#endif
136 void uninit();
137
138private:
139 /** the sdl thread */
140 RTNATIVETHREAD mSdlNativeThread;
141 /** current SDL framebuffer pointer (also includes screen width/height) */
142 SDL_Surface *mScreen;
143 /** false if constructor failed */
144 bool mfInitialized;
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 /** fixed SDL screen width (~0 = not set) */
154 uint32_t mFixedSDLWidth;
155 /** fixed SDL screen height (~0 = not set) */
156 uint32_t mFixedSDLHeight;
157 /** fixed SDL bits per pixel (~0 = not set) */
158 uint32_t mFixedSDLBPP;
159 /** default BPP */
160 uint32_t mDefaultSDLBPP;
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 wheter 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#ifdef VBOX_SECURELABEL
179 /** current secure label text */
180 Utf8Str mSecureLabelText;
181 /** current secure label foreground color (RGB) */
182 uint32_t mSecureLabelColorFG;
183 /** current secure label background color (RGB) */
184 uint32_t mSecureLabelColorBG;
185 /** secure label font handle */
186 TTF_Font *mLabelFont;
187 /** secure label height in pixels */
188 uint32_t mLabelHeight;
189 /** secure label offset from the top of the secure label */
190 uint32_t mLabelOffs;
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
203 /** the application Icon */
204 SDL_Surface *mWMIcon;
205};
206
207class VBoxSDLFBOverlay :
208 public IFramebufferOverlay
209{
210public:
211 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
212 VBoxSDLFB *aParent);
213 virtual ~VBoxSDLFBOverlay();
214
215#ifdef RT_OS_WINDOWS
216 STDMETHOD_(ULONG, AddRef)()
217 {
218 return ::InterlockedIncrement (&refcnt);
219 }
220 STDMETHOD_(ULONG, Release)()
221 {
222 long cnt = ::InterlockedDecrement (&refcnt);
223 if (cnt == 0)
224 delete this;
225 return cnt;
226 }
227 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
228 {
229 if (riid == IID_IUnknown)
230 {
231 *ppObj = this;
232 AddRef();
233 return S_OK;
234 }
235 if (riid == IID_IFramebuffer)
236 {
237 *ppObj = this;
238 AddRef();
239 return S_OK;
240 }
241 *ppObj = NULL;
242 return E_NOINTERFACE;
243 }
244#endif
245
246 NS_DECL_ISUPPORTS
247
248 STDMETHOD(COMGETTER(X))(ULONG *x);
249 STDMETHOD(COMGETTER(Y))(ULONG *y);
250 STDMETHOD(COMGETTER(Width))(ULONG *width);
251 STDMETHOD(COMGETTER(Height))(ULONG *height);
252 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
253 STDMETHOD(COMSETTER(Visible))(BOOL visible);
254 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
255 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
256 STDMETHOD(COMGETTER(Address))(ULONG *address);
257 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
258
259 /* These are not used, or return standard values. */
260 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
261 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
262 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
263 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
264 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
265
266 STDMETHOD(Lock)();
267 STDMETHOD(Unlock)();
268 STDMETHOD(Move)(ULONG x, ULONG y);
269 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
270 ULONG w, ULONG h, BOOL *finished);
271 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
272 ULONG bitsPerPixel, ULONG bytesPerLine,
273 ULONG w, ULONG h, BOOL *finished);
274 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
275 BOOL *supported);
276 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
277 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
278 ULONG color, BOOL *handled);
279 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
280 ULONG width, ULONG height, BOOL *handled);
281
282 // internal public methods
283 HRESULT init();
284
285private:
286 /** Overlay X offset */
287 ULONG mOverlayX;
288 /** Overlay Y offset */
289 ULONG mOverlayY;
290 /** Overlay width */
291 ULONG mOverlayWidth;
292 /** Overlay height */
293 ULONG mOverlayHeight;
294 /** Whether the overlay is currently active */
295 BOOL mOverlayVisible;
296 /** The parent IFramebuffer */
297 VBoxSDLFB *mParent;
298 /** SDL surface containing the actual framebuffer bits */
299 SDL_Surface *mOverlayBits;
300 /** Additional SDL surface used for combining the framebuffer and the overlay */
301 SDL_Surface *mBlendedBits;
302#ifdef RT_OS_WINDOWS
303 long refcnt;
304#endif
305};
306
307#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