VirtualBox

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

Last change on this file since 7392 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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