VirtualBox

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

Last change on this file since 51493 was 51436, checked in by vboxsync, 11 years ago

Main,Frontends: IDisplay provides the guest screen bitmap to frontends.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 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(NotifyChange)(ULONG aScreenId,
92 ULONG aXOrigin,
93 ULONG aYOrigin,
94 ULONG aWidth,
95 ULONG aHeight);
96 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
97
98 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
99 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
100
101 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
102
103 STDMETHOD(Notify3DEvent)(ULONG uType, BYTE *pReserved);
104
105 // internal public methods
106 bool initialized() { return mfInitialized; }
107 void notifyChange(ULONG aScreenId);
108 void resizeGuest();
109 void resizeSDL();
110 void update(int x, int y, int w, int h, bool fGuestRelative);
111 void repaint();
112 void setFullscreen(bool fFullscreen);
113 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
114 uint32_t getScreenId() { return mScreenId; }
115 uint32_t getGuestXRes() { return mGuestXRes; }
116 uint32_t getGuestYRes() { return mGuestYRes; }
117 int32_t getOriginX() { return mOriginX; }
118 int32_t getOriginY() { return mOriginY; }
119 int32_t getXOffset() { return mCenterXOffset; }
120 int32_t getYOffset() { return mCenterYOffset; }
121#ifdef VBOX_WITH_SDL13
122 bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
123#endif
124#ifdef VBOX_SECURELABEL
125 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
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 setWinId(int64_t winId) { mWinId = winId; }
131 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
132 bool getFullscreen() { return mfFullscreen; }
133
134private:
135 /** current SDL framebuffer pointer (also includes screen width/height) */
136 SDL_Surface *mScreen;
137#ifdef VBOX_WITH_SDL13
138 /** the SDL window */
139 SDL_WindowID mWindow;
140 /** the texture */
141 SDL_TextureID mTexture;
142 /** render info */
143 SDL_RendererInfo mRenderInfo;
144#endif
145 /** false if constructor failed */
146 bool mfInitialized;
147 /** the screen number of this framebuffer */
148 uint32_t mScreenId;
149 /** maximum possible screen width in pixels (~0 = no restriction) */
150 uint32_t mMaxScreenWidth;
151 /** maximum possible screen height in pixels (~0 = no restriction) */
152 uint32_t mMaxScreenHeight;
153 /** current guest screen width in pixels */
154 ULONG mGuestXRes;
155 /** current guest screen height in pixels */
156 ULONG mGuestYRes;
157 int32_t mOriginX;
158 int32_t mOriginY;
159 /** fixed SDL screen width (~0 = not set) */
160 uint32_t mFixedSDLWidth;
161 /** fixed SDL screen height (~0 = not set) */
162 uint32_t mFixedSDLHeight;
163 /** fixed SDL bits per pixel (~0 = not set) */
164 uint32_t mFixedSDLBPP;
165 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
166 uint32_t mTopOffset;
167 /** X offset for guest screen centering */
168 uint32_t mCenterXOffset;
169 /** Y offset for guest screen centering */
170 uint32_t mCenterYOffset;
171 /** flag whether we're in fullscreen mode */
172 bool mfFullscreen;
173 /** flag whether we keep the host screen resolution when switching to
174 * fullscreen or not */
175 bool mfKeepHostRes;
176 /** framebuffer update semaphore */
177 RTCRITSECT mUpdateLock;
178 /** flag whether the SDL window should be resizable */
179 bool mfResizable;
180 /** flag whether we print out SDL information */
181 bool mfShowSDLConfig;
182 /** handle to window where framebuffer context is being drawn*/
183 int64_t mWinId;
184#ifdef VBOX_SECURELABEL
185 /** current secure label text */
186 Utf8Str mSecureLabelText;
187 /** current secure label foreground color (RGB) */
188 uint32_t mSecureLabelColorFG;
189 /** current secure label background color (RGB) */
190 uint32_t mSecureLabelColorBG;
191 /** secure label font handle */
192 TTF_Font *mLabelFont;
193 /** secure label height in pixels */
194 uint32_t mLabelHeight;
195 /** secure label offset from the top of the secure label */
196 uint32_t mLabelOffs;
197
198#endif
199#ifdef RT_OS_WINDOWS
200 long refcnt;
201#endif
202 SDL_Surface *mSurfVRAM;
203
204 BYTE *mPtrVRAM;
205 ULONG mBitsPerPixel;
206 ULONG mBytesPerLine;
207 ULONG mPixelFormat;
208 BOOL mUsesGuestVRAM;
209 BOOL mfSameSizeRequested;
210
211 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
212 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
213 bool mfUpdates;
214};
215
216class VBoxSDLFBOverlay :
217 public IFramebufferOverlay
218{
219public:
220 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
221 VBoxSDLFB *aParent);
222 virtual ~VBoxSDLFBOverlay();
223
224#ifdef RT_OS_WINDOWS
225 STDMETHOD_(ULONG, AddRef)()
226 {
227 return ::InterlockedIncrement (&refcnt);
228 }
229 STDMETHOD_(ULONG, Release)()
230 {
231 long cnt = ::InterlockedDecrement (&refcnt);
232 if (cnt == 0)
233 delete this;
234 return cnt;
235 }
236#endif
237 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
238
239 NS_DECL_ISUPPORTS
240
241 STDMETHOD(COMGETTER(X))(ULONG *x);
242 STDMETHOD(COMGETTER(Y))(ULONG *y);
243 STDMETHOD(COMGETTER(Width))(ULONG *width);
244 STDMETHOD(COMGETTER(Height))(ULONG *height);
245 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
246 STDMETHOD(COMSETTER(Visible))(BOOL visible);
247 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
248 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
249 STDMETHOD(COMGETTER(Address))(ULONG *address);
250 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
251
252 /* These are not used, or return standard values. */
253 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
254 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
255 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
256 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
257 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
258 STDMETHOD(COMGETTER(WinId)) (LONG64 *winId);
259
260 STDMETHOD(Lock)();
261 STDMETHOD(Unlock)();
262 STDMETHOD(Move)(ULONG x, ULONG y);
263 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
264 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
265 ULONG bitsPerPixel, ULONG bytesPerLine,
266 ULONG w, ULONG h, BOOL *finished);
267 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
268
269 // internal public methods
270 HRESULT init();
271
272private:
273 /** Overlay X offset */
274 ULONG mOverlayX;
275 /** Overlay Y offset */
276 ULONG mOverlayY;
277 /** Overlay width */
278 ULONG mOverlayWidth;
279 /** Overlay height */
280 ULONG mOverlayHeight;
281 /** Whether the overlay is currently active */
282 BOOL mOverlayVisible;
283 /** The parent IFramebuffer */
284 VBoxSDLFB *mParent;
285 /** SDL surface containing the actual framebuffer bits */
286 SDL_Surface *mOverlayBits;
287 /** Additional SDL surface used for combining the framebuffer and the overlay */
288 SDL_Surface *mBlendedBits;
289#ifdef RT_OS_WINDOWS
290 long refcnt;
291#endif
292};
293
294#endif // __H_FRAMEBUFFER
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette