VirtualBox

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

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

FE/SDL: use RenderUTF8_Blended() if available to get a better looking font

  • 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-2007 innotek GmbH
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 */
41
42class VBoxSDLFBOverlay;
43
44class VBoxSDLFB :
45 public IFramebuffer
46{
47public:
48 VBoxSDLFB(bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
49 uint32_t u32FixedWidth = ~(uint32_t)0, uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
50 virtual ~VBoxSDLFB();
51
52#ifdef RT_OS_WINDOWS
53 STDMETHOD_(ULONG, AddRef)()
54 {
55 return ::InterlockedIncrement (&refcnt);
56 }
57 STDMETHOD_(ULONG, Release)()
58 {
59 long cnt = ::InterlockedDecrement (&refcnt);
60 if (cnt == 0)
61 delete this;
62 return cnt;
63 }
64 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
65 {
66 if (riid == IID_IUnknown)
67 {
68 *ppObj = this;
69 AddRef();
70 return S_OK;
71 }
72 if (riid == IID_IFramebuffer)
73 {
74 *ppObj = this;
75 AddRef();
76 return S_OK;
77 }
78 *ppObj = NULL;
79 return E_NOINTERFACE;
80 }
81#endif
82
83 NS_DECL_ISUPPORTS
84
85 STDMETHOD(COMGETTER(Width))(ULONG *width);
86 STDMETHOD(COMGETTER(Height))(ULONG *height);
87 STDMETHOD(Lock)();
88 STDMETHOD(Unlock)();
89 STDMETHOD(COMGETTER(Address))(BYTE **address);
90 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
91 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
92 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
93 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
94 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
95 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
96
97 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
98 ULONG w, ULONG h, BOOL *finished);
99 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
100 ULONG bitsPerPixel, ULONG bytesPerLine,
101 ULONG w, ULONG h, BOOL *finished);
102 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
103 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
104 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
105 ULONG color, BOOL *handled);
106 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
107 ULONG width, ULONG height, BOOL *handled);
108
109 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
110 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
111
112 // internal public methods
113 bool initialized() { return mfInitialized; }
114 void resizeGuest();
115 void resizeSDL();
116 void update(int x, int y, int w, int h, bool fGuestRelative);
117 void repaint();
118 bool getFullscreen();
119 void setFullscreen(bool fFullscreen);
120 int getXOffset();
121 int getYOffset();
122 uint32_t getGuestXRes() { return mGuestXRes; }
123 uint32_t getGuestYRes() { return mGuestYRes; }
124#ifdef VBOX_SECURELABEL
125 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize);
126 void setSecureLabelText(const char *text);
127 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
128 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
129#endif
130 void uninit();
131
132private:
133 /** the sdl thread */
134 RTNATIVETHREAD mSdlNativeThread;
135 /** current SDL framebuffer pointer (also includes screen width/height) */
136 SDL_Surface *mScreen;
137 /** false if constructor failed */
138 bool mfInitialized;
139 /** maximum possible screen width in pixels (~0 = no restriction) */
140 uint32_t mMaxScreenWidth;
141 /** maximum possible screen height in pixels (~0 = no restriction) */
142 uint32_t mMaxScreenHeight;
143 /** current guest screen width in pixels */
144 ULONG mGuestXRes;
145 /** current guest screen height in pixels */
146 ULONG mGuestYRes;
147 /** fixed SDL screen width (~0 = not set) */
148 uint32_t mFixedSDLWidth;
149 /** fixed SDL screen height (~0 = not set) */
150 uint32_t mFixedSDLHeight;
151 /** fixed SDL bits per pixel (~0 = not set) */
152 uint32_t mFixedSDLBPP;
153 /** default BPP */
154 uint32_t mDefaultSDLBPP;
155 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
156 uint32_t mTopOffset;
157 /** X offset for guest screen centering */
158 uint32_t mCenterXOffset;
159 /** Y offset for guest screen centering */
160 uint32_t mCenterYOffset;
161 /** flag whether we're in fullscreen mode */
162 bool mfFullscreen;
163 /** framebuffer update semaphore */
164 RTCRITSECT mUpdateLock;
165 /** flag whether the SDL window should be resizable */
166 bool mfResizable;
167 /** flag whether we print out SDL information */
168 bool mfShowSDLConfig;
169#ifdef VBOX_SECURELABEL
170 /** current secure label text */
171 Utf8Str mSecureLabelText;
172 /** current secure label foreground color (RGB) */
173 uint32_t mSecureLabelColorFG;
174 /** current secure label background color (RGB) */
175 uint32_t mSecureLabelColorBG;
176 /** secure label font handle */
177 TTF_Font *mLabelFont;
178 /** secure label height in pixels */
179 uint32_t mLabelHeight;
180#endif
181#ifdef RT_OS_WINDOWS
182 long refcnt;
183#endif
184 SDL_Surface *mSurfVRAM;
185
186 BYTE *mPtrVRAM;
187 ULONG mBitsPerPixel;
188 ULONG mBytesPerLine;
189 ULONG mPixelFormat;
190 BOOL mUsesGuestVRAM;
191
192 /** the application Icon */
193 SDL_Surface *mWMIcon;
194};
195
196class VBoxSDLFBOverlay :
197 public IFramebufferOverlay
198{
199public:
200 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
201 VBoxSDLFB *aParent);
202 virtual ~VBoxSDLFBOverlay();
203
204#ifdef RT_OS_WINDOWS
205 STDMETHOD_(ULONG, AddRef)()
206 {
207 return ::InterlockedIncrement (&refcnt);
208 }
209 STDMETHOD_(ULONG, Release)()
210 {
211 long cnt = ::InterlockedDecrement (&refcnt);
212 if (cnt == 0)
213 delete this;
214 return cnt;
215 }
216 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
217 {
218 if (riid == IID_IUnknown)
219 {
220 *ppObj = this;
221 AddRef();
222 return S_OK;
223 }
224 if (riid == IID_IFramebuffer)
225 {
226 *ppObj = this;
227 AddRef();
228 return S_OK;
229 }
230 *ppObj = NULL;
231 return E_NOINTERFACE;
232 }
233#endif
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
255 STDMETHOD(Lock)();
256 STDMETHOD(Unlock)();
257 STDMETHOD(Move)(ULONG x, ULONG y);
258 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
259 ULONG w, ULONG h, BOOL *finished);
260 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
261 ULONG bitsPerPixel, ULONG bytesPerLine,
262 ULONG w, ULONG h, BOOL *finished);
263 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
264 BOOL *supported);
265 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
266 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
267 ULONG color, BOOL *handled);
268 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
269 ULONG width, ULONG height, BOOL *handled);
270
271 // internal public methods
272 HRESULT init();
273
274private:
275 /** Overlay X offset */
276 ULONG mOverlayX;
277 /** Overlay Y offset */
278 ULONG mOverlayY;
279 /** Overlay width */
280 ULONG mOverlayWidth;
281 /** Overlay height */
282 ULONG mOverlayHeight;
283 /** Whether the overlay is currently active */
284 BOOL mOverlayVisible;
285 /** The parent IFramebuffer */
286 VBoxSDLFB *mParent;
287 /** SDL surface containing the actual framebuffer bits */
288 SDL_Surface *mOverlayBits;
289 /** Additional SDL surface used for combining the framebuffer and the overlay */
290 SDL_Surface *mBlendedBits;
291#ifdef RT_OS_WINDOWS
292 long refcnt;
293#endif
294};
295
296#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