VirtualBox

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

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

HGSMI: post host VBVA commands to display; Video HW Accel: mechanism for passing/processing commands to framebuffer

  • 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 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 VBOX_SCRIPTABLE_IMPL(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 STDMETHOD(COMGETTER(WinId)) (uint64_t *winId);
102
103 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
104 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
105 ULONG bitsPerPixel, ULONG bytesPerLine,
106 ULONG w, ULONG h, BOOL *finished);
107 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
108
109 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
110 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
111
112 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
113
114 // internal public methods
115 bool initialized() { return mfInitialized; }
116 void resizeGuest();
117 void resizeSDL();
118 void update(int x, int y, int w, int h, bool fGuestRelative);
119 void repaint();
120 bool getFullscreen();
121 void setFullscreen(bool fFullscreen);
122 int getXOffset();
123 int getYOffset();
124 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
125 uint32_t getGuestXRes() { return mGuestXRes; }
126 uint32_t getGuestYRes() { return mGuestYRes; }
127#ifdef VBOX_SECURELABEL
128 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
129 void setSecureLabelText(const char *text);
130 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
131 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
132#endif
133 void uninit();
134 void setWinId(uint64_t winId) { mWinId = winId; }
135
136private:
137 /** the sdl thread */
138 RTNATIVETHREAD mSdlNativeThread;
139 /** current SDL framebuffer pointer (also includes screen width/height) */
140 SDL_Surface *mScreen;
141 /** false if constructor failed */
142 bool mfInitialized;
143 /** maximum possible screen width in pixels (~0 = no restriction) */
144 uint32_t mMaxScreenWidth;
145 /** maximum possible screen height in pixels (~0 = no restriction) */
146 uint32_t mMaxScreenHeight;
147 /** current guest screen width in pixels */
148 ULONG mGuestXRes;
149 /** current guest screen height in pixels */
150 ULONG mGuestYRes;
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 /** default BPP */
158 uint32_t mDefaultSDLBPP;
159 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
160 uint32_t mTopOffset;
161 /** X offset for guest screen centering */
162 uint32_t mCenterXOffset;
163 /** Y offset for guest screen centering */
164 uint32_t mCenterYOffset;
165 /** flag whether we're in fullscreen mode */
166 bool mfFullscreen;
167 /** flag wheter we keep the host screen resolution when switching to
168 * fullscreen or not */
169 bool mfKeepHostRes;
170 /** framebuffer update semaphore */
171 RTCRITSECT mUpdateLock;
172 /** flag whether the SDL window should be resizable */
173 bool mfResizable;
174 /** flag whether we print out SDL information */
175 bool mfShowSDLConfig;
176 /** handle to window where framebuffer context is being drawn*/
177 uint64_t mWinId;
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 BOOL mfSameSizeRequested;
203
204 /** the application Icon */
205 SDL_Surface *mWMIcon;
206};
207
208class VBoxSDLFBOverlay :
209 public IFramebufferOverlay
210{
211public:
212 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
213 VBoxSDLFB *aParent);
214 virtual ~VBoxSDLFBOverlay();
215
216#ifdef RT_OS_WINDOWS
217 STDMETHOD_(ULONG, AddRef)()
218 {
219 return ::InterlockedIncrement (&refcnt);
220 }
221 STDMETHOD_(ULONG, Release)()
222 {
223 long cnt = ::InterlockedDecrement (&refcnt);
224 if (cnt == 0)
225 delete this;
226 return cnt;
227 }
228 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
229 {
230 if (riid == IID_IUnknown)
231 {
232 *ppObj = this;
233 AddRef();
234 return S_OK;
235 }
236 if (riid == IID_IFramebuffer)
237 {
238 *ppObj = this;
239 AddRef();
240 return S_OK;
241 }
242 *ppObj = NULL;
243 return E_NOINTERFACE;
244 }
245#endif
246
247 NS_DECL_ISUPPORTS
248
249 STDMETHOD(COMGETTER(X))(ULONG *x);
250 STDMETHOD(COMGETTER(Y))(ULONG *y);
251 STDMETHOD(COMGETTER(Width))(ULONG *width);
252 STDMETHOD(COMGETTER(Height))(ULONG *height);
253 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
254 STDMETHOD(COMSETTER(Visible))(BOOL visible);
255 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
256 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
257 STDMETHOD(COMGETTER(Address))(ULONG *address);
258 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
259
260 /* These are not used, or return standard values. */
261 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
262 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
263 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
264 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
265 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
266 STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
267
268 STDMETHOD(Lock)();
269 STDMETHOD(Unlock)();
270 STDMETHOD(Move)(ULONG x, ULONG y);
271 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
272 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
273 ULONG bitsPerPixel, ULONG bytesPerLine,
274 ULONG w, ULONG h, BOOL *finished);
275 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
276
277 // internal public methods
278 HRESULT init();
279
280private:
281 /** Overlay X offset */
282 ULONG mOverlayX;
283 /** Overlay Y offset */
284 ULONG mOverlayY;
285 /** Overlay width */
286 ULONG mOverlayWidth;
287 /** Overlay height */
288 ULONG mOverlayHeight;
289 /** Whether the overlay is currently active */
290 BOOL mOverlayVisible;
291 /** The parent IFramebuffer */
292 VBoxSDLFB *mParent;
293 /** SDL surface containing the actual framebuffer bits */
294 SDL_Surface *mOverlayBits;
295 /** Additional SDL surface used for combining the framebuffer and the overlay */
296 SDL_Surface *mBlendedBits;
297#ifdef RT_OS_WINDOWS
298 long refcnt;
299#endif
300};
301
302#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