VirtualBox

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

Last change on this file since 98302 was 98302, checked in by vboxsync, 20 months ago

FE/SDL. bugref:9449. Removing secure label related code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/* $Id: Framebuffer.h 98302 2023-01-25 09:07:43Z 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-2023 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30#ifndef VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
31#define VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
32#ifndef RT_WITHOUT_PRAGMA_ONCE
33# pragma once
34#endif
35
36#include "VBoxSDL.h"
37#include <iprt/thread.h>
38
39#include <iprt/critsect.h>
40
41class VBoxSDLFBOverlay;
42
43class ATL_NO_VTABLE VBoxSDLFB :
44 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>,
45 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
46{
47public:
48 VBoxSDLFB();
49 virtual ~VBoxSDLFB();
50
51 HRESULT init(uint32_t uScreenId,
52 bool fFullscreen, bool fResizable, bool fShowSDLConfig,
53 bool fKeepHostRes, uint32_t u32FixedWidth,
54 uint32_t u32FixedHeight, uint32_t u32FixedBPP,
55 bool fUpdateImage);
56
57 static bool init(bool fShowSDLConfig);
58 static void uninit();
59
60 DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
61
62 DECLARE_PROTECT_FINAL_CONSTRUCT()
63
64 BEGIN_COM_MAP(VBoxSDLFB)
65 COM_INTERFACE_ENTRY(IFramebuffer)
66 COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
67 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.m_p)
68 END_COM_MAP()
69
70 HRESULT FinalConstruct();
71 void FinalRelease();
72
73 STDMETHOD(COMGETTER(Width))(ULONG *width);
74 STDMETHOD(COMGETTER(Height))(ULONG *height);
75 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
76 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
77 STDMETHOD(COMGETTER(PixelFormat))(BitmapFormat_T *pixelFormat);
78 STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
79 STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
80 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
81 STDMETHOD(COMGETTER(Capabilities))(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities));
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, LONG enmCmd, BOOL fGuestCmd);
96
97 STDMETHOD(Notify3DEvent)(ULONG uType, ComSafeArrayIn(BYTE, aData));
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_SDL2
116 SDL_Window *getWindow() { return mpWindow; }
117 bool hasWindow(uint32_t id) { return SDL_GetWindowID(mpWindow) == id; }
118 int setWindowTitle(const char *pcszTitle);
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
126#ifdef VBOX_WITH_SDL2
127 /** the SDL window */
128 SDL_Window *mpWindow;
129 /** the texture */
130 SDL_Texture *mpTexture;
131 /** renderer */
132 SDL_Renderer *mpRenderer;
133 /** render info */
134 SDL_RendererInfo mRenderInfo;
135#endif
136 /** false if constructor failed */
137 bool mfInitialized;
138 /** the screen number of this framebuffer */
139 uint32_t mScreenId;
140 /** use NotifyUpdateImage */
141 bool mfUpdateImage;
142 /** maximum possible screen width in pixels (~0 = no restriction) */
143 uint32_t mMaxScreenWidth;
144 /** maximum possible screen height in pixels (~0 = no restriction) */
145 uint32_t mMaxScreenHeight;
146 /** current guest screen width in pixels */
147 ULONG mGuestXRes;
148 /** current guest screen height in pixels */
149 ULONG mGuestYRes;
150 int32_t mOriginX;
151 int32_t mOriginY;
152 /** fixed SDL screen width (~0 = not set) */
153 uint32_t mFixedSDLWidth;
154 /** fixed SDL screen height (~0 = not set) */
155 uint32_t mFixedSDLHeight;
156 /** fixed SDL bits per pixel (~0 = not set) */
157 uint32_t mFixedSDLBPP;
158 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
159 uint32_t mTopOffset;
160 /** X offset for guest screen centering */
161 uint32_t mCenterXOffset;
162 /** Y offset for guest screen centering */
163 uint32_t mCenterYOffset;
164 /** flag whether we're in fullscreen mode */
165 bool mfFullscreen;
166 /** flag whether we keep the host screen resolution when switching to
167 * fullscreen or not */
168 bool mfKeepHostRes;
169 /** framebuffer update semaphore */
170 RTCRITSECT mUpdateLock;
171 /** flag whether the SDL window should be resizable */
172 bool mfResizable;
173 /** flag whether we print out SDL information */
174 bool mfShowSDLConfig;
175 /** handle to window where framebuffer context is being drawn*/
176 int64_t mWinId;
177 SDL_Surface *mSurfVRAM;
178
179 BYTE *mPtrVRAM;
180 ULONG mBitsPerPixel;
181 ULONG mBytesPerLine;
182 BOOL mfSameSizeRequested;
183
184 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
185 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
186 bool mfUpdates;
187
188#ifdef RT_OS_WINDOWS
189 ComPtr<IUnknown> m_pUnkMarshaler;
190#endif
191};
192
193class VBoxSDLFBOverlay :
194 public IFramebufferOverlay
195{
196public:
197 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
198 VBoxSDLFB *aParent);
199 virtual ~VBoxSDLFBOverlay();
200
201#ifdef RT_OS_WINDOWS
202 STDMETHOD_(ULONG, AddRef)()
203 {
204 return ::InterlockedIncrement(&refcnt);
205 }
206 STDMETHOD_(ULONG, Release)()
207 {
208 long cnt = ::InterlockedDecrement(&refcnt);
209 if (cnt == 0)
210 delete this;
211 return cnt;
212 }
213#endif
214 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
215
216 NS_DECL_ISUPPORTS
217
218 STDMETHOD(COMGETTER(X))(ULONG *x);
219 STDMETHOD(COMGETTER(Y))(ULONG *y);
220 STDMETHOD(COMGETTER(Width))(ULONG *width);
221 STDMETHOD(COMGETTER(Height))(ULONG *height);
222 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
223 STDMETHOD(COMSETTER(Visible))(BOOL visible);
224 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
225 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
226 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
227
228 /* These are not used, or return standard values. */
229 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
230 STDMETHOD(COMGETTER(PixelFormat))(ULONG *pixelFormat);
231 STDMETHOD(COMGETTER(UsesGuestVRAM))(BOOL *usesGuestVRAM);
232 STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
233 STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
234 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
235
236 STDMETHOD(Lock)();
237 STDMETHOD(Unlock)();
238 STDMETHOD(Move)(ULONG x, ULONG y);
239 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
240 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
241 ULONG bitsPerPixel, ULONG bytesPerLine,
242 ULONG w, ULONG h, BOOL *finished);
243 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
244
245 // internal public methods
246 HRESULT init();
247
248private:
249 /** Overlay X offset */
250 ULONG mOverlayX;
251 /** Overlay Y offset */
252 ULONG mOverlayY;
253 /** Overlay width */
254 ULONG mOverlayWidth;
255 /** Overlay height */
256 ULONG mOverlayHeight;
257 /** Whether the overlay is currently active */
258 BOOL mOverlayVisible;
259 /** The parent IFramebuffer */
260 VBoxSDLFB *mParent;
261 /** SDL surface containing the actual framebuffer bits */
262 SDL_Surface *mOverlayBits;
263 /** Additional SDL surface used for combining the framebuffer and the overlay */
264 SDL_Surface *mBlendedBits;
265#ifdef RT_OS_WINDOWS
266 long refcnt;
267#endif
268};
269
270#endif /* !VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h */
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