VirtualBox

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

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

Main,Frontends: IFramebuffer::NotifyUpdateImage

  • 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-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(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
77 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
78 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
79 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
80 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
81 STDMETHOD(COMGETTER(WinId)) (int64_t *winId);
82
83 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
84 STDMETHOD(NotifyUpdateImage)(ULONG x, ULONG y, ULONG w, ULONG h, ComSafeArrayIn(BYTE, aImage));
85 STDMETHOD(NotifyChange)(ULONG aScreenId,
86 ULONG aXOrigin,
87 ULONG aYOrigin,
88 ULONG aWidth,
89 ULONG aHeight);
90 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
91
92 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
93 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
94
95 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
96
97 STDMETHOD(Notify3DEvent)(ULONG uType, BYTE *pReserved);
98
99 // internal public methods
100 bool initialized() { return mfInitialized; }
101 void notifyChange(ULONG aScreenId);
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 BOOL mfSameSizeRequested;
202
203 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
204 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
205 bool mfUpdates;
206};
207
208class VBoxSDLFBOverlay :
209 public IFramebufferOverlay
210{
211public:
212 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
213 VBoxSDLFB *aParent);
214 virtual ~VBoxSDLFBOverlay();
215
216#ifdef RT_OS_WINDOWS
217 STDMETHOD_(ULONG, AddRef)()
218 {
219 return ::InterlockedIncrement (&refcnt);
220 }
221 STDMETHOD_(ULONG, Release)()
222 {
223 long cnt = ::InterlockedDecrement (&refcnt);
224 if (cnt == 0)
225 delete this;
226 return cnt;
227 }
228#endif
229 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
230
231 NS_DECL_ISUPPORTS
232
233 STDMETHOD(COMGETTER(X))(ULONG *x);
234 STDMETHOD(COMGETTER(Y))(ULONG *y);
235 STDMETHOD(COMGETTER(Width))(ULONG *width);
236 STDMETHOD(COMGETTER(Height))(ULONG *height);
237 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
238 STDMETHOD(COMSETTER(Visible))(BOOL visible);
239 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
240 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
241 STDMETHOD(COMGETTER(Address))(ULONG *address);
242 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
243
244 /* These are not used, or return standard values. */
245 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
246 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
247 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
248 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
249 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
250 STDMETHOD(COMGETTER(WinId)) (LONG64 *winId);
251
252 STDMETHOD(Lock)();
253 STDMETHOD(Unlock)();
254 STDMETHOD(Move)(ULONG x, ULONG y);
255 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
256 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
257 ULONG bitsPerPixel, ULONG bytesPerLine,
258 ULONG w, ULONG h, BOOL *finished);
259 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
260
261 // internal public methods
262 HRESULT init();
263
264private:
265 /** Overlay X offset */
266 ULONG mOverlayX;
267 /** Overlay Y offset */
268 ULONG mOverlayY;
269 /** Overlay width */
270 ULONG mOverlayWidth;
271 /** Overlay height */
272 ULONG mOverlayHeight;
273 /** Whether the overlay is currently active */
274 BOOL mOverlayVisible;
275 /** The parent IFramebuffer */
276 VBoxSDLFB *mParent;
277 /** SDL surface containing the actual framebuffer bits */
278 SDL_Surface *mOverlayBits;
279 /** Additional SDL surface used for combining the framebuffer and the overlay */
280 SDL_Surface *mBlendedBits;
281#ifdef RT_OS_WINDOWS
282 long refcnt;
283#endif
284};
285
286#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