VirtualBox

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

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

FE/SDL. bugref:9449. Removing VBOX_WITH_SDL2 define.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
RevLine 
[55401]1/* $Id: Framebuffer.h 98305 2023-01-25 16:48:39Z vboxsync $ */
[1]2/** @file
3 *
4 * VBox frontends: VBoxSDL (simple frontend based on SDL):
5 * Declaration of VBoxSDLFB (SDL framebuffer) class
6 */
7
8/*
[98103]9 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[1]10 *
[96407]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
[1]28 */
29
[76582]30#ifndef VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
31#define VBOX_INCLUDED_SRC_VBoxSDL_Framebuffer_h
[76532]32#ifndef RT_WITHOUT_PRAGMA_ONCE
33# pragma once
34#endif
[1]35
36#include "VBoxSDL.h"
37#include <iprt/thread.h>
38
39#include <iprt/critsect.h>
40
41class VBoxSDLFBOverlay;
42
[51677]43class ATL_NO_VTABLE VBoxSDLFB :
[60759]44 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>,
[19134]45 VBOX_SCRIPTABLE_IMPL(IFramebuffer)
[1]46{
47public:
[51677]48 VBoxSDLFB();
[62157]49 virtual ~VBoxSDLFB();
[1]50
[51677]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
[41216]57 static bool init(bool fShowSDLConfig);
58 static void uninit();
[20433]59
[51677]60 DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
[1]61
[51677]62 DECLARE_PROTECT_FINAL_CONSTRUCT()
[41215]63
[51677]64 BEGIN_COM_MAP(VBoxSDLFB)
65 COM_INTERFACE_ENTRY(IFramebuffer)
66 COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
[60759]67 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.m_p)
[51677]68 END_COM_MAP()
69
70 HRESULT FinalConstruct();
71 void FinalRelease();
72
[1]73 STDMETHOD(COMGETTER(Width))(ULONG *width);
74 STDMETHOD(COMGETTER(Height))(ULONG *height);
[3761]75 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
76 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
[56580]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);
[52574]81 STDMETHOD(COMGETTER(Capabilities))(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities));
[1]82
[19817]83 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
[51627]84 STDMETHOD(NotifyUpdateImage)(ULONG x, ULONG y, ULONG w, ULONG h, ComSafeArrayIn(BYTE, aImage));
[51436]85 STDMETHOD(NotifyChange)(ULONG aScreenId,
86 ULONG aXOrigin,
87 ULONG aYOrigin,
88 ULONG aWidth,
89 ULONG aHeight);
[1]90 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
91
[3576]92 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
93 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
[3532]94
[71651]95 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand, LONG enmCmd, BOOL fGuestCmd);
[19844]96
[51670]97 STDMETHOD(Notify3DEvent)(ULONG uType, ComSafeArrayIn(BYTE, aData));
[45940]98
[1]99 // internal public methods
100 bool initialized() { return mfInitialized; }
[51436]101 void notifyChange(ULONG aScreenId);
[1]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);
[11400]107 void getFullscreenGeometry(uint32_t *width, uint32_t *height);
[20433]108 uint32_t getScreenId() { return mScreenId; }
[1]109 uint32_t getGuestXRes() { return mGuestXRes; }
110 uint32_t getGuestYRes() { return mGuestYRes; }
[20433]111 int32_t getOriginX() { return mOriginX; }
112 int32_t getOriginY() { return mOriginY; }
113 int32_t getXOffset() { return mCenterXOffset; }
114 int32_t getYOffset() { return mCenterYOffset; }
[81537]115 SDL_Window *getWindow() { return mpWindow; }
[98290]116 bool hasWindow(uint32_t id) { return SDL_GetWindowID(mpWindow) == id; }
[81537]117 int setWindowTitle(const char *pcszTitle);
[31698]118 void setWinId(int64_t winId) { mWinId = winId; }
[20433]119 void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
120 bool getFullscreen() { return mfFullscreen; }
[1]121
122private:
[98290]123
[20433]124 /** the SDL window */
[81537]125 SDL_Window *mpWindow;
[20433]126 /** the texture */
[81537]127 SDL_Texture *mpTexture;
128 /** renderer */
129 SDL_Renderer *mpRenderer;
[20433]130 /** render info */
131 SDL_RendererInfo mRenderInfo;
[1]132 /** false if constructor failed */
133 bool mfInitialized;
[20433]134 /** the screen number of this framebuffer */
135 uint32_t mScreenId;
[51634]136 /** use NotifyUpdateImage */
137 bool mfUpdateImage;
[1]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;
[20433]146 int32_t mOriginX;
147 int32_t mOriginY;
[1]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;
[33540]162 /** flag whether we keep the host screen resolution when switching to
[10675]163 * fullscreen or not */
164 bool mfKeepHostRes;
[1]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;
[12449]171 /** handle to window where framebuffer context is being drawn*/
[31698]172 int64_t mWinId;
[1]173 SDL_Surface *mSurfVRAM;
174
[470]175 BYTE *mPtrVRAM;
[3761]176 ULONG mBitsPerPixel;
177 ULONG mBytesPerLine;
[15868]178 BOOL mfSameSizeRequested;
[51436]179
180 ComPtr<IDisplaySourceBitmap> mpSourceBitmap;
181 ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
182 bool mfUpdates;
[51677]183
184#ifdef RT_OS_WINDOWS
[60759]185 ComPtr<IUnknown> m_pUnkMarshaler;
[51677]186#endif
[1]187};
188
189class VBoxSDLFBOverlay :
[41216]190 public IFramebufferOverlay
[1]191{
192public:
193 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
194 VBoxSDLFB *aParent);
195 virtual ~VBoxSDLFBOverlay();
196
[41216]197#ifdef RT_OS_WINDOWS
198 STDMETHOD_(ULONG, AddRef)()
199 {
[56580]200 return ::InterlockedIncrement(&refcnt);
[41216]201 }
202 STDMETHOD_(ULONG, Release)()
203 {
[56580]204 long cnt = ::InterlockedDecrement(&refcnt);
[41216]205 if (cnt == 0)
206 delete this;
207 return cnt;
208 }
209#endif
210 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
[1]211
[41216]212 NS_DECL_ISUPPORTS
213
[1]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);
[3761]222 STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
[1]223
224 /* These are not used, or return standard values. */
[3761]225 STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
[56580]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);
[1]231
232 STDMETHOD(Lock)();
233 STDMETHOD(Unlock)();
234 STDMETHOD(Move)(ULONG x, ULONG y);
[19817]235 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
[3761]236 STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
237 ULONG bitsPerPixel, ULONG bytesPerLine,
238 ULONG w, ULONG h, BOOL *finished);
[1]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;
[41216]261#ifdef RT_OS_WINDOWS
262 long refcnt;
263#endif
[1]264};
265
[76582]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