VirtualBox

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

Last change on this file since 49502 was 45940, checked in by vboxsync, 12 years ago

crOpenGL->Fe/Qt notification mechanism

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 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-2012 Oracle Corporation
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 SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
36extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
37extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
38extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
39}
40#endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL13 */
41
42class VBoxSDLFBOverlay;
43
44class VBoxSDLFB :
45 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
46{
47public:
48 VBoxSDLFB(uint32_t uScreenId,
49 bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
50 bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
51 uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
52 virtual ~VBoxSDLFB();
53
54 static bool init(bool fShowSDLConfig);
55 static void uninit();
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#endif
70 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
71
72 NS_DECL_ISUPPORTS
73
74 STDMETHOD(COMGETTER(Width))(ULONG *width);
75 STDMETHOD(COMGETTER(Height))(ULONG *height);
76 STDMETHOD(Lock)();
77 STDMETHOD(Unlock)();
78 STDMETHOD(COMGETTER(Address))(BYTE **address);
79 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
80 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
81 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
82 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
83 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
84 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
85 STDMETHOD(COMGETTER(WinId)) (int64_t *winId);
86
87 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
88 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
89 ULONG bitsPerPixel, ULONG bytesPerLine,
90 ULONG w, ULONG h, BOOL *finished);
91 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
92
93 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
94 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
95
96 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
97
98 STDMETHOD(Notify3DEvent)(ULONG uType, BYTE *pReserved);
99
100 // internal public methods
101 bool initialized() { return mfInitialized; }
102 void resizeGuest();
103 void resizeSDL();
104 void update(int x, int y, int w, int h, bool fGuestRelative);
105 void repaint();
106 void setFullscreen(bool fFullscreen);
107 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
108 uint32_t getScreenId() { return mScreenId; }
109 uint32_t getGuestXRes() { return mGuestXRes; }
110 uint32_t getGuestYRes() { return mGuestYRes; }
111 int32_t getOriginX() { return mOriginX; }
112 int32_t getOriginY() { return mOriginY; }
113 int32_t getXOffset() { return mCenterXOffset; }
114 int32_t getYOffset() { return mCenterYOffset; }
115#ifdef VBOX_WITH_SDL13
116 bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
117#endif
118#ifdef VBOX_SECURELABEL
119 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
120 void setSecureLabelText(const char *text);
121 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
122 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
123#endif
124 void setWinId(int64_t winId) { mWinId = winId; }
125 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
126 bool getFullscreen() { return mfFullscreen; }
127
128private:
129 /** current SDL framebuffer pointer (also includes screen width/height) */
130 SDL_Surface *mScreen;
131#ifdef VBOX_WITH_SDL13
132 /** the SDL window */
133 SDL_WindowID mWindow;
134 /** the texture */
135 SDL_TextureID mTexture;
136 /** render info */
137 SDL_RendererInfo mRenderInfo;
138#endif
139 /** false if constructor failed */
140 bool mfInitialized;
141 /** the screen number of this framebuffer */
142 uint32_t mScreenId;
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 int32_t mOriginX;
152 int32_t mOriginY;
153 /** fixed SDL screen width (~0 = not set) */
154 uint32_t mFixedSDLWidth;
155 /** fixed SDL screen height (~0 = not set) */
156 uint32_t mFixedSDLHeight;
157 /** fixed SDL bits per pixel (~0 = not set) */
158 uint32_t mFixedSDLBPP;
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 /** flag whether we keep the host screen resolution when switching to
168 * fullscreen or not */
169 bool mfKeepHostRes;
170 /** framebuffer update semaphore */
171 RTCRITSECT mUpdateLock;
172 /** flag whether the SDL window should be resizable */
173 bool mfResizable;
174 /** flag whether we print out SDL information */
175 bool mfShowSDLConfig;
176 /** handle to window where framebuffer context is being drawn*/
177 int64_t mWinId;
178#ifdef VBOX_SECURELABEL
179 /** current secure label text */
180 Utf8Str mSecureLabelText;
181 /** current secure label foreground color (RGB) */
182 uint32_t mSecureLabelColorFG;
183 /** current secure label background color (RGB) */
184 uint32_t mSecureLabelColorBG;
185 /** secure label font handle */
186 TTF_Font *mLabelFont;
187 /** secure label height in pixels */
188 uint32_t mLabelHeight;
189 /** secure label offset from the top of the secure label */
190 uint32_t mLabelOffs;
191
192#endif
193#ifdef RT_OS_WINDOWS
194 long refcnt;
195#endif
196 SDL_Surface *mSurfVRAM;
197
198 BYTE *mPtrVRAM;
199 ULONG mBitsPerPixel;
200 ULONG mBytesPerLine;
201 ULONG mPixelFormat;
202 BOOL mUsesGuestVRAM;
203 BOOL mfSameSizeRequested;
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#endif
227 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
228
229 NS_DECL_ISUPPORTS
230
231 STDMETHOD(COMGETTER(X))(ULONG *x);
232 STDMETHOD(COMGETTER(Y))(ULONG *y);
233 STDMETHOD(COMGETTER(Width))(ULONG *width);
234 STDMETHOD(COMGETTER(Height))(ULONG *height);
235 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
236 STDMETHOD(COMSETTER(Visible))(BOOL visible);
237 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
238 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
239 STDMETHOD(COMGETTER(Address))(ULONG *address);
240 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
241
242 /* These are not used, or return standard values. */
243 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
244 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
245 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
246 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
247 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
248 STDMETHOD(COMGETTER(WinId)) (LONG64 *winId);
249
250 STDMETHOD(Lock)();
251 STDMETHOD(Unlock)();
252 STDMETHOD(Move)(ULONG x, ULONG y);
253 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
254 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
255 ULONG bitsPerPixel, ULONG bytesPerLine,
256 ULONG w, ULONG h, BOOL *finished);
257 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
258
259 // internal public methods
260 HRESULT init();
261
262private:
263 /** Overlay X offset */
264 ULONG mOverlayX;
265 /** Overlay Y offset */
266 ULONG mOverlayY;
267 /** Overlay width */
268 ULONG mOverlayWidth;
269 /** Overlay height */
270 ULONG mOverlayHeight;
271 /** Whether the overlay is currently active */
272 BOOL mOverlayVisible;
273 /** The parent IFramebuffer */
274 VBoxSDLFB *mParent;
275 /** SDL surface containing the actual framebuffer bits */
276 SDL_Surface *mOverlayBits;
277 /** Additional SDL surface used for combining the framebuffer and the overlay */
278 SDL_Surface *mBlendedBits;
279#ifdef RT_OS_WINDOWS
280 long refcnt;
281#endif
282};
283
284#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