VirtualBox

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

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

Frontends/VBoxSDL: clean up framebuffer implementation in a COM-compatible fashion

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