VirtualBox

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

Last change on this file since 106131 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: Framebuffer.h 106061 2024-09-16 14:03:52Z 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-2024 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 SDL_Window *getWindow() { return mpWindow; }
116 bool hasWindow(uint32_t id) { return SDL_GetWindowID(mpWindow) == id; }
117 int setWindowTitle(const char *pcszTitle);
118 void setWinId(int64_t winId) { mWinId = winId; }
119 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
120 bool getFullscreen() { return mfFullscreen; }
121
122private:
123
124 /** the SDL window */
125 SDL_Window *mpWindow;
126 /** the texture */
127 SDL_Texture *mpTexture;
128 /** renderer */
129 SDL_Renderer *mpRenderer;
130 /** render info */
131 SDL_RendererInfo mRenderInfo;
132 /** false if constructor failed */
133 bool mfInitialized;
134 /** the screen number of this framebuffer */
135 uint32_t mScreenId;
136 /** use NotifyUpdateImage */
137 bool mfUpdateImage;
138 /** maximum possible screen width in pixels (~0 = no restriction) */
139 uint32_t mMaxScreenWidth;
140 /** maximum possible screen height in pixels (~0 = no restriction) */
141 uint32_t mMaxScreenHeight;
142 /** current guest screen width in pixels */
143 ULONG mGuestXRes;
144 /** current guest screen height in pixels */
145 ULONG mGuestYRes;
146 int32_t mOriginX;
147 int32_t mOriginY;
148 /** fixed SDL screen width (~0 = not set) */
149 uint32_t mFixedSDLWidth;
150 /** fixed SDL screen height (~0 = not set) */
151 uint32_t mFixedSDLHeight;
152 /** fixed SDL bits per pixel (~0 = not set) */
153 uint32_t mFixedSDLBPP;
154 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
155 uint32_t mTopOffset;
156 /** X offset for guest screen centering */
157 uint32_t mCenterXOffset;
158 /** Y offset for guest screen centering */
159 uint32_t mCenterYOffset;
160 /** flag whether we're in fullscreen mode */
161 bool mfFullscreen;
162 /** flag whether we keep the host screen resolution when switching to
163 * fullscreen or not */
164 bool mfKeepHostRes;
165 /** framebuffer update semaphore */
166 RTCRITSECT mUpdateLock;
167 /** flag whether the SDL window should be resizable */
168 bool mfResizable;
169 /** flag whether we print out SDL information */
170 bool mfShowSDLConfig;
171 /** handle to window where framebuffer context is being drawn*/
172 int64_t mWinId;
173 SDL_Surface *mSurfVRAM;
174
175 BYTE *mPtrVRAM;
176 ULONG mBitsPerPixel;
177 ULONG mBytesPerLine;
178 BOOL mfSameSizeRequested;
179
180 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
181 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
182 bool mfUpdates;
183
184#ifdef RT_OS_WINDOWS
185 ComPtr<IUnknown> m_pUnkMarshaler;
186#endif
187};
188
189class VBoxSDLFBOverlay :
190 public IFramebufferOverlay
191{
192public:
193 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
194 VBoxSDLFB *aParent);
195 virtual ~VBoxSDLFBOverlay();
196
197#ifdef RT_OS_WINDOWS
198 STDMETHOD_(ULONG, AddRef)()
199 {
200 return ::InterlockedIncrement(&refcnt);
201 }
202 STDMETHOD_(ULONG, Release)()
203 {
204 long cnt = ::InterlockedDecrement(&refcnt);
205 if (cnt == 0)
206 delete this;
207 return cnt;
208 }
209#endif
210 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
211
212 NS_DECL_ISUPPORTS
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(BytesPerLine))(ULONG *bytesPerLine);
223
224 /* These are not used, or return standard values. */
225 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
226 STDMETHOD(COMGETTER(PixelFormat))(ULONG *pixelFormat);
227 STDMETHOD(COMGETTER(UsesGuestVRAM))(BOOL *usesGuestVRAM);
228 STDMETHOD(COMGETTER(HeightReduction))(ULONG *heightReduction);
229 STDMETHOD(COMGETTER(Overlay))(IFramebufferOverlay **aOverlay);
230 STDMETHOD(COMGETTER(WinId))(LONG64 *winId);
231
232 STDMETHOD(Lock)();
233 STDMETHOD(Unlock)();
234 STDMETHOD(Move)(ULONG x, ULONG y);
235 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
236 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
237 ULONG bitsPerPixel, ULONG bytesPerLine,
238 ULONG w, ULONG h, BOOL *finished);
239 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
240
241 // internal public methods
242 HRESULT init();
243
244private:
245 /** Overlay X offset */
246 ULONG mOverlayX;
247 /** Overlay Y offset */
248 ULONG mOverlayY;
249 /** Overlay width */
250 ULONG mOverlayWidth;
251 /** Overlay height */
252 ULONG mOverlayHeight;
253 /** Whether the overlay is currently active */
254 BOOL mOverlayVisible;
255 /** The parent IFramebuffer */
256 VBoxSDLFB *mParent;
257 /** SDL surface containing the actual framebuffer bits */
258 SDL_Surface *mOverlayBits;
259 /** Additional SDL surface used for combining the framebuffer and the overlay */
260 SDL_Surface *mBlendedBits;
261#ifdef RT_OS_WINDOWS
262 long refcnt;
263#endif
264};
265
266#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