VirtualBox

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

Last change on this file since 53404 was 52574, checked in by vboxsync, 10 years ago

IFramebuffer::capabilities

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