VirtualBox

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

Last change on this file since 59381 was 56580, checked in by vboxsync, 10 years ago

whitespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/* $Id: Framebuffer.h 56580 2015-06-22 16:20:42Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: VBoxSDL (simple frontend based on SDL):
5 * Declaration of VBoxSDLFB (SDL framebuffer) class
6 */
7
8/*
9 * Copyright (C) 2006-2015 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef __H_FRAMEBUFFER
21#define __H_FRAMEBUFFER
22
23#include "VBoxSDL.h"
24#include <iprt/thread.h>
25
26#include <iprt/critsect.h>
27
28#ifdef VBOX_SECURELABEL
29#include <SDL_ttf.h>
30/* function pointers */
31extern "C"
32{
33extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
34extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
35extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
36extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
37extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
38extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
39extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
40}
41#endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL13 */
42
43class VBoxSDLFBOverlay;
44
45class ATL_NO_VTABLE VBoxSDLFB :
46 public CComObjectRootEx<CComMultiThreadModel>,
47 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
48{
49public:
50 VBoxSDLFB();
51 ~VBoxSDLFB();
52
53 HRESULT init(uint32_t uScreenId,
54 bool fFullscreen, bool fResizable, bool fShowSDLConfig,
55 bool fKeepHostRes, uint32_t u32FixedWidth,
56 uint32_t u32FixedHeight, uint32_t u32FixedBPP,
57 bool fUpdateImage);
58
59 static bool init(bool fShowSDLConfig);
60 static void uninit();
61
62 DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
63
64 DECLARE_PROTECT_FINAL_CONSTRUCT()
65
66 BEGIN_COM_MAP(VBoxSDLFB)
67 COM_INTERFACE_ENTRY(IFramebuffer)
68 COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
69 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
70 END_COM_MAP()
71
72 HRESULT FinalConstruct();
73 void FinalRelease();
74
75 STDMETHOD(COMGETTER(Width))(ULONG *width);
76 STDMETHOD(COMGETTER(Height))(ULONG *height);
77 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
78 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
79 STDMETHOD(COMGETTER(PixelFormat))(BitmapFormat_T *pixelFormat);
80 STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
81 STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
82 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
83 STDMETHOD(COMGETTER(Capabilities))(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities));
84
85 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
86 STDMETHOD(NotifyUpdateImage)(ULONG x, ULONG y, ULONG w, ULONG h, ComSafeArrayIn(BYTE, aImage));
87 STDMETHOD(NotifyChange)(ULONG aScreenId,
88 ULONG aXOrigin,
89 ULONG aYOrigin,
90 ULONG aWidth,
91 ULONG aHeight);
92 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
93
94 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
95 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
96
97 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
98
99 STDMETHOD(Notify3DEvent)(ULONG uType, ComSafeArrayIn(BYTE, aData));
100
101 // internal public methods
102 bool initialized() { return mfInitialized; }
103 void notifyChange(ULONG aScreenId);
104 void resizeGuest();
105 void resizeSDL();
106 void update(int x, int y, int w, int h, bool fGuestRelative);
107 void repaint();
108 void setFullscreen(bool fFullscreen);
109 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
110 uint32_t getScreenId() { return mScreenId; }
111 uint32_t getGuestXRes() { return mGuestXRes; }
112 uint32_t getGuestYRes() { return mGuestYRes; }
113 int32_t getOriginX() { return mOriginX; }
114 int32_t getOriginY() { return mOriginY; }
115 int32_t getXOffset() { return mCenterXOffset; }
116 int32_t getYOffset() { return mCenterYOffset; }
117#ifdef VBOX_WITH_SDL13
118 bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
119#endif
120#ifdef VBOX_SECURELABEL
121 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
122 void setSecureLabelText(const char *text);
123 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
124 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
125#endif
126 void setWinId(int64_t winId) { mWinId = winId; }
127 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
128 bool getFullscreen() { return mfFullscreen; }
129
130private:
131 /** current SDL framebuffer pointer (also includes screen width/height) */
132 SDL_Surface *mScreen;
133#ifdef VBOX_WITH_SDL13
134 /** the SDL window */
135 SDL_WindowID mWindow;
136 /** the texture */
137 SDL_TextureID mTexture;
138 /** render info */
139 SDL_RendererInfo mRenderInfo;
140#endif
141 /** false if constructor failed */
142 bool mfInitialized;
143 /** the screen number of this framebuffer */
144 uint32_t mScreenId;
145 /** use NotifyUpdateImage */
146 bool mfUpdateImage;
147 /** maximum possible screen width in pixels (~0 = no restriction) */
148 uint32_t mMaxScreenWidth;
149 /** maximum possible screen height in pixels (~0 = no restriction) */
150 uint32_t mMaxScreenHeight;
151 /** current guest screen width in pixels */
152 ULONG mGuestXRes;
153 /** current guest screen height in pixels */
154 ULONG mGuestYRes;
155 int32_t mOriginX;
156 int32_t mOriginY;
157 /** fixed SDL screen width (~0 = not set) */
158 uint32_t mFixedSDLWidth;
159 /** fixed SDL screen height (~0 = not set) */
160 uint32_t mFixedSDLHeight;
161 /** fixed SDL bits per pixel (~0 = not set) */
162 uint32_t mFixedSDLBPP;
163 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
164 uint32_t mTopOffset;
165 /** X offset for guest screen centering */
166 uint32_t mCenterXOffset;
167 /** Y offset for guest screen centering */
168 uint32_t mCenterYOffset;
169 /** flag whether we're in fullscreen mode */
170 bool mfFullscreen;
171 /** flag whether we keep the host screen resolution when switching to
172 * fullscreen or not */
173 bool mfKeepHostRes;
174 /** framebuffer update semaphore */
175 RTCRITSECT mUpdateLock;
176 /** flag whether the SDL window should be resizable */
177 bool mfResizable;
178 /** flag whether we print out SDL information */
179 bool mfShowSDLConfig;
180 /** handle to window where framebuffer context is being drawn*/
181 int64_t mWinId;
182#ifdef VBOX_SECURELABEL
183 /** current secure label text */
184 Utf8Str mSecureLabelText;
185 /** current secure label foreground color (RGB) */
186 uint32_t mSecureLabelColorFG;
187 /** current secure label background color (RGB) */
188 uint32_t mSecureLabelColorBG;
189 /** secure label font handle */
190 TTF_Font *mLabelFont;
191 /** secure label height in pixels */
192 uint32_t mLabelHeight;
193 /** secure label offset from the top of the secure label */
194 uint32_t mLabelOffs;
195
196#endif
197
198 SDL_Surface *mSurfVRAM;
199
200 BYTE *mPtrVRAM;
201 ULONG mBitsPerPixel;
202 ULONG mBytesPerLine;
203 BOOL mfSameSizeRequested;
204
205 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
206 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
207 bool mfUpdates;
208
209#ifdef RT_OS_WINDOWS
210 CComPtr <IUnknown> m_pUnkMarshaler;
211#endif
212};
213
214class VBoxSDLFBOverlay :
215 public IFramebufferOverlay
216{
217public:
218 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
219 VBoxSDLFB *aParent);
220 virtual ~VBoxSDLFBOverlay();
221
222#ifdef RT_OS_WINDOWS
223 STDMETHOD_(ULONG, AddRef)()
224 {
225 return ::InterlockedIncrement(&refcnt);
226 }
227 STDMETHOD_(ULONG, Release)()
228 {
229 long cnt = ::InterlockedDecrement(&refcnt);
230 if (cnt == 0)
231 delete this;
232 return cnt;
233 }
234#endif
235 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
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 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
257
258 STDMETHOD(Lock)();
259 STDMETHOD(Unlock)();
260 STDMETHOD(Move)(ULONG x, ULONG y);
261 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
262 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
263 ULONG bitsPerPixel, ULONG bytesPerLine,
264 ULONG w, ULONG h, BOOL *finished);
265 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
266
267 // internal public methods
268 HRESULT init();
269
270private:
271 /** Overlay X offset */
272 ULONG mOverlayX;
273 /** Overlay Y offset */
274 ULONG mOverlayY;
275 /** Overlay width */
276 ULONG mOverlayWidth;
277 /** Overlay height */
278 ULONG mOverlayHeight;
279 /** Whether the overlay is currently active */
280 BOOL mOverlayVisible;
281 /** The parent IFramebuffer */
282 VBoxSDLFB *mParent;
283 /** SDL surface containing the actual framebuffer bits */
284 SDL_Surface *mOverlayBits;
285 /** Additional SDL surface used for combining the framebuffer and the overlay */
286 SDL_Surface *mBlendedBits;
287#ifdef RT_OS_WINDOWS
288 long refcnt;
289#endif
290};
291
292#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