VirtualBox

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

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

IFramebuffer cleanup next part:

  • removed obsolete internal framebuffer
  • removed IFramebuffer::setupInternalFramebuffer(), IFramebuffer::lockFramebuffer(), IFramebuffer::unlockFramebuffer(), IFramebuffer::registerExternalFramebuffer()
  • removed unused finished parameter of IFramebuffer::NotifyUpdate()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 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 // 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 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
123 uint32_t getGuestXRes() { return mGuestXRes; }
124 uint32_t getGuestYRes() { return mGuestYRes; }
125#ifdef VBOX_SECURELABEL
126 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
127 void setSecureLabelText(const char *text);
128 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
129 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
130#endif
131 void uninit();
132 void setWinId(uint64_t winId) { mWinId = winId; }
133
134private:
135 /** the sdl thread */
136 RTNATIVETHREAD mSdlNativeThread;
137 /** current SDL framebuffer pointer (also includes screen width/height) */
138 SDL_Surface *mScreen;
139 /** false if constructor failed */
140 bool mfInitialized;
141 /** maximum possible screen width in pixels (~0 = no restriction) */
142 uint32_t mMaxScreenWidth;
143 /** maximum possible screen height in pixels (~0 = no restriction) */
144 uint32_t mMaxScreenHeight;
145 /** current guest screen width in pixels */
146 ULONG mGuestXRes;
147 /** current guest screen height in pixels */
148 ULONG mGuestYRes;
149 /** fixed SDL screen width (~0 = not set) */
150 uint32_t mFixedSDLWidth;
151 /** fixed SDL screen height (~0 = not set) */
152 uint32_t mFixedSDLHeight;
153 /** fixed SDL bits per pixel (~0 = not set) */
154 uint32_t mFixedSDLBPP;
155 /** default BPP */
156 uint32_t mDefaultSDLBPP;
157 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
158 uint32_t mTopOffset;
159 /** X offset for guest screen centering */
160 uint32_t mCenterXOffset;
161 /** Y offset for guest screen centering */
162 uint32_t mCenterYOffset;
163 /** flag whether we're in fullscreen mode */
164 bool mfFullscreen;
165 /** flag wheter we keep the host screen resolution when switching to
166 * fullscreen or not */
167 bool mfKeepHostRes;
168 /** framebuffer update semaphore */
169 RTCRITSECT mUpdateLock;
170 /** flag whether the SDL window should be resizable */
171 bool mfResizable;
172 /** flag whether we print out SDL information */
173 bool mfShowSDLConfig;
174 /** handle to window where framebuffer context is being drawn*/
175 uint64_t mWinId;
176#ifdef VBOX_SECURELABEL
177 /** current secure label text */
178 Utf8Str mSecureLabelText;
179 /** current secure label foreground color (RGB) */
180 uint32_t mSecureLabelColorFG;
181 /** current secure label background color (RGB) */
182 uint32_t mSecureLabelColorBG;
183 /** secure label font handle */
184 TTF_Font *mLabelFont;
185 /** secure label height in pixels */
186 uint32_t mLabelHeight;
187 /** secure label offset from the top of the secure label */
188 uint32_t mLabelOffs;
189#endif
190#ifdef RT_OS_WINDOWS
191 long refcnt;
192#endif
193 SDL_Surface *mSurfVRAM;
194
195 BYTE *mPtrVRAM;
196 ULONG mBitsPerPixel;
197 ULONG mBytesPerLine;
198 ULONG mPixelFormat;
199 BOOL mUsesGuestVRAM;
200 BOOL mfSameSizeRequested;
201
202 /** the application Icon */
203 SDL_Surface *mWMIcon;
204};
205
206class VBoxSDLFBOverlay :
207 public IFramebufferOverlay
208{
209public:
210 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
211 VBoxSDLFB *aParent);
212 virtual ~VBoxSDLFBOverlay();
213
214#ifdef RT_OS_WINDOWS
215 STDMETHOD_(ULONG, AddRef)()
216 {
217 return ::InterlockedIncrement (&refcnt);
218 }
219 STDMETHOD_(ULONG, Release)()
220 {
221 long cnt = ::InterlockedDecrement (&refcnt);
222 if (cnt == 0)
223 delete this;
224 return cnt;
225 }
226 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
227 {
228 if (riid == IID_IUnknown)
229 {
230 *ppObj = this;
231 AddRef();
232 return S_OK;
233 }
234 if (riid == IID_IFramebuffer)
235 {
236 *ppObj = this;
237 AddRef();
238 return S_OK;
239 }
240 *ppObj = NULL;
241 return E_NOINTERFACE;
242 }
243#endif
244
245 NS_DECL_ISUPPORTS
246
247 STDMETHOD(COMGETTER(X))(ULONG *x);
248 STDMETHOD(COMGETTER(Y))(ULONG *y);
249 STDMETHOD(COMGETTER(Width))(ULONG *width);
250 STDMETHOD(COMGETTER(Height))(ULONG *height);
251 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
252 STDMETHOD(COMSETTER(Visible))(BOOL visible);
253 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
254 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
255 STDMETHOD(COMGETTER(Address))(ULONG *address);
256 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
257
258 /* These are not used, or return standard values. */
259 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
260 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
261 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
262 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
263 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
264 STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
265
266 STDMETHOD(Lock)();
267 STDMETHOD(Unlock)();
268 STDMETHOD(Move)(ULONG x, ULONG y);
269 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
270 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
271 ULONG bitsPerPixel, ULONG bytesPerLine,
272 ULONG w, ULONG h, BOOL *finished);
273 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
274
275 // internal public methods
276 HRESULT init();
277
278private:
279 /** Overlay X offset */
280 ULONG mOverlayX;
281 /** Overlay Y offset */
282 ULONG mOverlayY;
283 /** Overlay width */
284 ULONG mOverlayWidth;
285 /** Overlay height */
286 ULONG mOverlayHeight;
287 /** Whether the overlay is currently active */
288 BOOL mOverlayVisible;
289 /** The parent IFramebuffer */
290 VBoxSDLFB *mParent;
291 /** SDL surface containing the actual framebuffer bits */
292 SDL_Surface *mOverlayBits;
293 /** Additional SDL surface used for combining the framebuffer and the overlay */
294 SDL_Surface *mBlendedBits;
295#ifdef RT_OS_WINDOWS
296 long refcnt;
297#endif
298};
299
300#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