VirtualBox

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

Last change on this file since 80012 was 76582, checked in by vboxsync, 5 years ago

Frontends: scm header guard alignment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/* $Id: Framebuffer.h 76582 2019-01-01 06:25:48Z 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-2019 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 VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
21#define VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
22#ifndef RT_WITHOUT_PRAGMA_ONCE
23# pragma once
24#endif
25
26#include "VBoxSDL.h"
27#include <iprt/thread.h>
28
29#include <iprt/critsect.h>
30
31#ifdef VBOX_SECURELABEL
32#include <SDL_ttf.h>
33/* function pointers */
34extern "C"
35{
36extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
37extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
38extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
39extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
40extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
41extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
42extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
43}
44#endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL13 */
45
46class VBoxSDLFBOverlay;
47
48class ATL_NO_VTABLE VBoxSDLFB :
49 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>,
50 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
51{
52public:
53 VBoxSDLFB();
54 virtual ~VBoxSDLFB();
55
56 HRESULT init(uint32_t uScreenId,
57 bool fFullscreen, bool fResizable, bool fShowSDLConfig,
58 bool fKeepHostRes, uint32_t u32FixedWidth,
59 uint32_t u32FixedHeight, uint32_t u32FixedBPP,
60 bool fUpdateImage);
61
62 static bool init(bool fShowSDLConfig);
63 static void uninit();
64
65 DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
66
67 DECLARE_PROTECT_FINAL_CONSTRUCT()
68
69 BEGIN_COM_MAP(VBoxSDLFB)
70 COM_INTERFACE_ENTRY(IFramebuffer)
71 COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
72 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.m_p)
73 END_COM_MAP()
74
75 HRESULT FinalConstruct();
76 void FinalRelease();
77
78 STDMETHOD(COMGETTER(Width))(ULONG *width);
79 STDMETHOD(COMGETTER(Height))(ULONG *height);
80 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
81 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
82 STDMETHOD(COMGETTER(PixelFormat))(BitmapFormat_T *pixelFormat);
83 STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
84 STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
85 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
86 STDMETHOD(COMGETTER(Capabilities))(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities));
87
88 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
89 STDMETHOD(NotifyUpdateImage)(ULONG x, ULONG y, ULONG w, ULONG h, ComSafeArrayIn(BYTE, aImage));
90 STDMETHOD(NotifyChange)(ULONG aScreenId,
91 ULONG aXOrigin,
92 ULONG aYOrigin,
93 ULONG aWidth,
94 ULONG aHeight);
95 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
96
97 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
98 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
99
100 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand, LONG enmCmd, BOOL fGuestCmd);
101
102 STDMETHOD(Notify3DEvent)(ULONG uType, ComSafeArrayIn(BYTE, aData));
103
104 // internal public methods
105 bool initialized() { return mfInitialized; }
106 void notifyChange(ULONG aScreenId);
107 void resizeGuest();
108 void resizeSDL();
109 void update(int x, int y, int w, int h, bool fGuestRelative);
110 void repaint();
111 void setFullscreen(bool fFullscreen);
112 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
113 uint32_t getScreenId() { return mScreenId; }
114 uint32_t getGuestXRes() { return mGuestXRes; }
115 uint32_t getGuestYRes() { return mGuestYRes; }
116 int32_t getOriginX() { return mOriginX; }
117 int32_t getOriginY() { return mOriginY; }
118 int32_t getXOffset() { return mCenterXOffset; }
119 int32_t getYOffset() { return mCenterYOffset; }
120#ifdef VBOX_WITH_SDL13
121 bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
122#endif
123#ifdef VBOX_SECURELABEL
124 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
125 void setSecureLabelText(const char *text);
126 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
127 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
128#endif
129 void setWinId(int64_t winId) { mWinId = winId; }
130 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
131 bool getFullscreen() { return mfFullscreen; }
132
133private:
134 /** current SDL framebuffer pointer (also includes screen width/height) */
135 SDL_Surface *mScreen;
136#ifdef VBOX_WITH_SDL13
137 /** the SDL window */
138 SDL_WindowID mWindow;
139 /** the texture */
140 SDL_TextureID mTexture;
141 /** render info */
142 SDL_RendererInfo mRenderInfo;
143#endif
144 /** false if constructor failed */
145 bool mfInitialized;
146 /** the screen number of this framebuffer */
147 uint32_t mScreenId;
148 /** use NotifyUpdateImage */
149 bool mfUpdateImage;
150 /** maximum possible screen width in pixels (~0 = no restriction) */
151 uint32_t mMaxScreenWidth;
152 /** maximum possible screen height in pixels (~0 = no restriction) */
153 uint32_t mMaxScreenHeight;
154 /** current guest screen width in pixels */
155 ULONG mGuestXRes;
156 /** current guest screen height in pixels */
157 ULONG mGuestYRes;
158 int32_t mOriginX;
159 int32_t mOriginY;
160 /** fixed SDL screen width (~0 = not set) */
161 uint32_t mFixedSDLWidth;
162 /** fixed SDL screen height (~0 = not set) */
163 uint32_t mFixedSDLHeight;
164 /** fixed SDL bits per pixel (~0 = not set) */
165 uint32_t mFixedSDLBPP;
166 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
167 uint32_t mTopOffset;
168 /** X offset for guest screen centering */
169 uint32_t mCenterXOffset;
170 /** Y offset for guest screen centering */
171 uint32_t mCenterYOffset;
172 /** flag whether we're in fullscreen mode */
173 bool mfFullscreen;
174 /** flag whether we keep the host screen resolution when switching to
175 * fullscreen or not */
176 bool mfKeepHostRes;
177 /** framebuffer update semaphore */
178 RTCRITSECT mUpdateLock;
179 /** flag whether the SDL window should be resizable */
180 bool mfResizable;
181 /** flag whether we print out SDL information */
182 bool mfShowSDLConfig;
183 /** handle to window where framebuffer context is being drawn*/
184 int64_t mWinId;
185#ifdef VBOX_SECURELABEL
186 /** current secure label text */
187 Utf8Str mSecureLabelText;
188 /** current secure label foreground color (RGB) */
189 uint32_t mSecureLabelColorFG;
190 /** current secure label background color (RGB) */
191 uint32_t mSecureLabelColorBG;
192 /** secure label font handle */
193 TTF_Font *mLabelFont;
194 /** secure label height in pixels */
195 uint32_t mLabelHeight;
196 /** secure label offset from the top of the secure label */
197 uint32_t mLabelOffs;
198
199#endif
200
201 SDL_Surface *mSurfVRAM;
202
203 BYTE *mPtrVRAM;
204 ULONG mBitsPerPixel;
205 ULONG mBytesPerLine;
206 BOOL mfSameSizeRequested;
207
208 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
209 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
210 bool mfUpdates;
211
212#ifdef RT_OS_WINDOWS
213 ComPtr<IUnknown> m_pUnkMarshaler;
214#endif
215};
216
217class VBoxSDLFBOverlay :
218 public IFramebufferOverlay
219{
220public:
221 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
222 VBoxSDLFB *aParent);
223 virtual ~VBoxSDLFBOverlay();
224
225#ifdef RT_OS_WINDOWS
226 STDMETHOD_(ULONG, AddRef)()
227 {
228 return ::InterlockedIncrement(&refcnt);
229 }
230 STDMETHOD_(ULONG, Release)()
231 {
232 long cnt = ::InterlockedDecrement(&refcnt);
233 if (cnt == 0)
234 delete this;
235 return cnt;
236 }
237#endif
238 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
239
240 NS_DECL_ISUPPORTS
241
242 STDMETHOD(COMGETTER(X))(ULONG *x);
243 STDMETHOD(COMGETTER(Y))(ULONG *y);
244 STDMETHOD(COMGETTER(Width))(ULONG *width);
245 STDMETHOD(COMGETTER(Height))(ULONG *height);
246 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
247 STDMETHOD(COMSETTER(Visible))(BOOL visible);
248 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
249 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
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 /* !VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use