VirtualBox

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

Last change on this file since 9723 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 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 uint32_t u32FixedWidth = ~(uint32_t)0, uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
54 virtual ~VBoxSDLFB();
55
56#ifdef RT_OS_WINDOWS
57 STDMETHOD_(ULONG, AddRef)()
58 {
59 return ::InterlockedIncrement (&refcnt);
60 }
61 STDMETHOD_(ULONG, Release)()
62 {
63 long cnt = ::InterlockedDecrement (&refcnt);
64 if (cnt == 0)
65 delete this;
66 return cnt;
67 }
68 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
69 {
70 if (riid == IID_IUnknown)
71 {
72 *ppObj = this;
73 AddRef();
74 return S_OK;
75 }
76 if (riid == IID_IFramebuffer)
77 {
78 *ppObj = this;
79 AddRef();
80 return S_OK;
81 }
82 *ppObj = NULL;
83 return E_NOINTERFACE;
84 }
85#endif
86
87 NS_DECL_ISUPPORTS
88
89 STDMETHOD(COMGETTER(Width))(ULONG *width);
90 STDMETHOD(COMGETTER(Height))(ULONG *height);
91 STDMETHOD(Lock)();
92 STDMETHOD(Unlock)();
93 STDMETHOD(COMGETTER(Address))(BYTE **address);
94 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
95 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
96 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
97 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
98 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
99 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
100
101 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
102 ULONG w, ULONG h, BOOL *finished);
103 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
104 ULONG bitsPerPixel, ULONG bytesPerLine,
105 ULONG w, ULONG h, BOOL *finished);
106 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
107 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
108 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
109 ULONG color, BOOL *handled);
110 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
111 ULONG width, ULONG height, BOOL *handled);
112
113 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
114 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
115
116 // internal public methods
117 bool initialized() { return mfInitialized; }
118 void resizeGuest();
119 void resizeSDL();
120 void update(int x, int y, int w, int h, bool fGuestRelative);
121 void repaint();
122 bool getFullscreen();
123 void setFullscreen(bool fFullscreen);
124 int getXOffset();
125 int getYOffset();
126 uint32_t getGuestXRes() { return mGuestXRes; }
127 uint32_t getGuestYRes() { return mGuestYRes; }
128#ifdef VBOX_SECURELABEL
129 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
130 void setSecureLabelText(const char *text);
131 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
132 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
133#endif
134 void uninit();
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 /** framebuffer update semaphore */
168 RTCRITSECT mUpdateLock;
169 /** flag whether the SDL window should be resizable */
170 bool mfResizable;
171 /** flag whether we print out SDL information */
172 bool mfShowSDLConfig;
173#ifdef VBOX_SECURELABEL
174 /** current secure label text */
175 Utf8Str mSecureLabelText;
176 /** current secure label foreground color (RGB) */
177 uint32_t mSecureLabelColorFG;
178 /** current secure label background color (RGB) */
179 uint32_t mSecureLabelColorBG;
180 /** secure label font handle */
181 TTF_Font *mLabelFont;
182 /** secure label height in pixels */
183 uint32_t mLabelHeight;
184 /** secure label offset from the top of the secure label */
185 uint32_t mLabelOffs;
186#endif
187#ifdef RT_OS_WINDOWS
188 long refcnt;
189#endif
190 SDL_Surface *mSurfVRAM;
191
192 BYTE *mPtrVRAM;
193 ULONG mBitsPerPixel;
194 ULONG mBytesPerLine;
195 ULONG mPixelFormat;
196 BOOL mUsesGuestVRAM;
197
198 /** the application Icon */
199 SDL_Surface *mWMIcon;
200};
201
202class VBoxSDLFBOverlay :
203 public IFramebufferOverlay
204{
205public:
206 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
207 VBoxSDLFB *aParent);
208 virtual ~VBoxSDLFBOverlay();
209
210#ifdef RT_OS_WINDOWS
211 STDMETHOD_(ULONG, AddRef)()
212 {
213 return ::InterlockedIncrement (&refcnt);
214 }
215 STDMETHOD_(ULONG, Release)()
216 {
217 long cnt = ::InterlockedDecrement (&refcnt);
218 if (cnt == 0)
219 delete this;
220 return cnt;
221 }
222 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
223 {
224 if (riid == IID_IUnknown)
225 {
226 *ppObj = this;
227 AddRef();
228 return S_OK;
229 }
230 if (riid == IID_IFramebuffer)
231 {
232 *ppObj = this;
233 AddRef();
234 return S_OK;
235 }
236 *ppObj = NULL;
237 return E_NOINTERFACE;
238 }
239#endif
240
241 NS_DECL_ISUPPORTS
242
243 STDMETHOD(COMGETTER(X))(ULONG *x);
244 STDMETHOD(COMGETTER(Y))(ULONG *y);
245 STDMETHOD(COMGETTER(Width))(ULONG *width);
246 STDMETHOD(COMGETTER(Height))(ULONG *height);
247 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
248 STDMETHOD(COMSETTER(Visible))(BOOL visible);
249 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
250 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
251 STDMETHOD(COMGETTER(Address))(ULONG *address);
252 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
253
254 /* These are not used, or return standard values. */
255 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
256 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
257 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
258 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
259 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
260
261 STDMETHOD(Lock)();
262 STDMETHOD(Unlock)();
263 STDMETHOD(Move)(ULONG x, ULONG y);
264 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
265 ULONG w, ULONG h, BOOL *finished);
266 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
267 ULONG bitsPerPixel, ULONG bytesPerLine,
268 ULONG w, ULONG h, BOOL *finished);
269 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
270 BOOL *supported);
271 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
272 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
273 ULONG color, BOOL *handled);
274 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
275 ULONG width, ULONG height, BOOL *handled);
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