VirtualBox

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

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

replace underscore symbols in VBoxBFE/ and VBoxSDL/

  • 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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
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 void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
40extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
41}
42#endif /* VBOX_SECURELABEL */
43
44class VBoxSDLFBOverlay;
45
46class VBoxSDLFB :
47 public IFramebuffer
48{
49public:
50 VBoxSDLFB(bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
51 uint32_t u32FixedWidth = ~(uint32_t)0, uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
52 virtual ~VBoxSDLFB();
53
54#ifdef RT_OS_WINDOWS
55 STDMETHOD_(ULONG, AddRef)()
56 {
57 return ::InterlockedIncrement (&refcnt);
58 }
59 STDMETHOD_(ULONG, Release)()
60 {
61 long cnt = ::InterlockedDecrement (&refcnt);
62 if (cnt == 0)
63 delete this;
64 return cnt;
65 }
66 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
67 {
68 if (riid == IID_IUnknown)
69 {
70 *ppObj = this;
71 AddRef();
72 return S_OK;
73 }
74 if (riid == IID_IFramebuffer)
75 {
76 *ppObj = this;
77 AddRef();
78 return S_OK;
79 }
80 *ppObj = NULL;
81 return E_NOINTERFACE;
82 }
83#endif
84
85 NS_DECL_ISUPPORTS
86
87 STDMETHOD(COMGETTER(Width))(ULONG *width);
88 STDMETHOD(COMGETTER(Height))(ULONG *height);
89 STDMETHOD(Lock)();
90 STDMETHOD(Unlock)();
91 STDMETHOD(COMGETTER(Address))(BYTE **address);
92 STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
93 STDMETHOD(COMGETTER(LineSize))(ULONG *lineSize);
94 STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
95 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
96 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
97
98 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
99 ULONG w, ULONG h, BOOL *finished);
100 STDMETHOD(RequestResize)(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, BYTE *vram,
101 ULONG lineSize, 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 mLineSize;
188 FramebufferPixelFormat_T mPixelFormat;
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(LineSize))(ULONG *lineSize);
245
246 /* These are not used, or return standard values. */
247 STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
248 STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
249 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
250 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
251
252 STDMETHOD(Lock)();
253 STDMETHOD(Unlock)();
254 STDMETHOD(Move)(ULONG x, ULONG y);
255 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
256 ULONG w, ULONG h, BOOL *finished);
257 STDMETHOD(RequestResize)(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, ULONG vram,
258 ULONG lineSize, ULONG w, ULONG h, BOOL *finished);
259 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
260 BOOL *supported);
261 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
262 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
263 ULONG color, BOOL *handled);
264 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
265 ULONG width, ULONG height, BOOL *handled);
266
267 // internal public methods
268 HRESULT init();
269
270private:
271 /** Overlay X offset */
272 ULONG mOverlayX;
273 /** Overlay Y offset */
274 ULONG mOverlayY;
275 /** Overlay width */
276 ULONG mOverlayWidth;
277 /** Overlay height */
278 ULONG mOverlayHeight;
279 /** Whether the overlay is currently active */
280 BOOL mOverlayVisible;
281 /** The parent IFramebuffer */
282 VBoxSDLFB *mParent;
283 /** SDL surface containing the actual framebuffer bits */
284 SDL_Surface *mOverlayBits;
285 /** Additional SDL surface used for combining the framebuffer and the overlay */
286 SDL_Surface *mBlendedBits;
287#ifdef RT_OS_WINDOWS
288 long refcnt;
289#endif
290};
291
292#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