VirtualBox

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

Last change on this file since 3774 was 3761, checked in by vboxsync, 18 years ago

Main/Frontends: Cleaned up IFramebuffer interface.

  • 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 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(BitsPerPixel))(ULONG *bitsPerPixel);
93 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
94 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
95 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
96 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
97 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
98
99 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
100 ULONG w, ULONG h, BOOL *finished);
101 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
102 ULONG bitsPerPixel, ULONG bytesPerLine,
103 ULONG w, ULONG h, BOOL *finished);
104 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
105 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
106 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
107 ULONG color, BOOL *handled);
108 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
109 ULONG width, ULONG height, BOOL *handled);
110
111 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
112 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
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 uint32_t getGuestXRes() { return mGuestXRes; }
125 uint32_t getGuestYRes() { return mGuestYRes; }
126#ifdef VBOX_SECURELABEL
127 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize);
128 void setSecureLabelText(const char *text);
129 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
130 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
131#endif
132 void uninit();
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 /** framebuffer update semaphore */
166 RTCRITSECT mUpdateLock;
167 /** flag whether the SDL window should be resizable */
168 bool mfResizable;
169 /** flag whether we print out SDL information */
170 bool mfShowSDLConfig;
171#ifdef VBOX_SECURELABEL
172 /** current secure label text */
173 Utf8Str mSecureLabelText;
174 /** current secure label foreground color (RGB) */
175 uint32_t mSecureLabelColorFG;
176 /** current secure label background color (RGB) */
177 uint32_t mSecureLabelColorBG;
178 /** secure label font handle */
179 TTF_Font *mLabelFont;
180 /** secure label height in pixels */
181 uint32_t mLabelHeight;
182#endif
183#ifdef RT_OS_WINDOWS
184 long refcnt;
185#endif
186 SDL_Surface *mSurfVRAM;
187
188 BYTE *mPtrVRAM;
189 ULONG mBitsPerPixel;
190 ULONG mBytesPerLine;
191 ULONG mPixelFormat;
192 BOOL mUsesGuestVRAM;
193
194 /** the application Icon */
195 SDL_Surface *mWMIcon;
196};
197
198class VBoxSDLFBOverlay :
199 public IFramebufferOverlay
200{
201public:
202 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
203 VBoxSDLFB *aParent);
204 virtual ~VBoxSDLFBOverlay();
205
206#ifdef RT_OS_WINDOWS
207 STDMETHOD_(ULONG, AddRef)()
208 {
209 return ::InterlockedIncrement (&refcnt);
210 }
211 STDMETHOD_(ULONG, Release)()
212 {
213 long cnt = ::InterlockedDecrement (&refcnt);
214 if (cnt == 0)
215 delete this;
216 return cnt;
217 }
218 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
219 {
220 if (riid == IID_IUnknown)
221 {
222 *ppObj = this;
223 AddRef();
224 return S_OK;
225 }
226 if (riid == IID_IFramebuffer)
227 {
228 *ppObj = this;
229 AddRef();
230 return S_OK;
231 }
232 *ppObj = NULL;
233 return E_NOINTERFACE;
234 }
235#endif
236
237 NS_DECL_ISUPPORTS
238
239 STDMETHOD(COMGETTER(X))(ULONG *x);
240 STDMETHOD(COMGETTER(Y))(ULONG *y);
241 STDMETHOD(COMGETTER(Width))(ULONG *width);
242 STDMETHOD(COMGETTER(Height))(ULONG *height);
243 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
244 STDMETHOD(COMSETTER(Visible))(BOOL visible);
245 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
246 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
247 STDMETHOD(COMGETTER(Address))(ULONG *address);
248 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
249
250 /* These are not used, or return standard values. */
251 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
252 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
253 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
254 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
255 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
256
257 STDMETHOD(Lock)();
258 STDMETHOD(Unlock)();
259 STDMETHOD(Move)(ULONG x, ULONG y);
260 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
261 ULONG w, ULONG h, BOOL *finished);
262 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
263 ULONG bitsPerPixel, ULONG bytesPerLine,
264 ULONG w, ULONG h, BOOL *finished);
265 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
266 BOOL *supported);
267 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
268 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
269 ULONG color, BOOL *handled);
270 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
271 ULONG width, ULONG height, BOOL *handled);
272
273 // internal public methods
274 HRESULT init();
275
276private:
277 /** Overlay X offset */
278 ULONG mOverlayX;
279 /** Overlay Y offset */
280 ULONG mOverlayY;
281 /** Overlay width */
282 ULONG mOverlayWidth;
283 /** Overlay height */
284 ULONG mOverlayHeight;
285 /** Whether the overlay is currently active */
286 BOOL mOverlayVisible;
287 /** The parent IFramebuffer */
288 VBoxSDLFB *mParent;
289 /** SDL surface containing the actual framebuffer bits */
290 SDL_Surface *mOverlayBits;
291 /** Additional SDL surface used for combining the framebuffer and the overlay */
292 SDL_Surface *mBlendedBits;
293#ifdef RT_OS_WINDOWS
294 long refcnt;
295#endif
296};
297
298#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