1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Basic Frontend (BFE):
|
---|
4 | * Declaration of Framebuffer class
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2023 Oracle and/or its affiliates.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox base platform packages, as
|
---|
11 | * available from https://www.virtualbox.org.
|
---|
12 | *
|
---|
13 | * This program is free software; you can redistribute it and/or
|
---|
14 | * modify it under the terms of the GNU General Public License
|
---|
15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
16 | * License.
|
---|
17 | *
|
---|
18 | * This program is distributed in the hope that it will be useful, but
|
---|
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | * General Public License for more details.
|
---|
22 | *
|
---|
23 | * You should have received a copy of the GNU General Public License
|
---|
24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | *
|
---|
26 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef VBOX_INCLUDED_SRC_VBoxBFE_Framebuffer_h
|
---|
30 | #define VBOX_INCLUDED_SRC_VBoxBFE_Framebuffer_h
|
---|
31 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
32 | # pragma once
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include <VBox/types.h>
|
---|
36 | #include <iprt/critsect.h>
|
---|
37 |
|
---|
38 | #include <SDL.h>
|
---|
39 |
|
---|
40 | /** custom SDL event for display update handling */
|
---|
41 | #define SDL_USER_EVENT_UPDATERECT (SDL_USEREVENT + 4)
|
---|
42 | /** custom SDL event for changing the guest resolution */
|
---|
43 | #define SDL_USER_EVENT_NOTIFYCHANGE (SDL_USEREVENT + 5)
|
---|
44 | /** custom SDL for XPCOM event queue processing */
|
---|
45 | #define SDL_USER_EVENT_XPCOM_EVENTQUEUE (SDL_USEREVENT + 6)
|
---|
46 | /** custom SDL event for updating the titlebar */
|
---|
47 | #define SDL_USER_EVENT_UPDATE_TITLEBAR (SDL_USEREVENT + 7)
|
---|
48 | /** custom SDL user event for terminating the session */
|
---|
49 | #define SDL_USER_EVENT_TERMINATE (SDL_USEREVENT + 8)
|
---|
50 | /** custom SDL user event for pointer shape change request */
|
---|
51 | #define SDL_USER_EVENT_POINTER_CHANGE (SDL_USEREVENT + 9)
|
---|
52 | /** custom SDL user event for a regular timer */
|
---|
53 | #define SDL_USER_EVENT_TIMER (SDL_USEREVENT + 10)
|
---|
54 | /** custom SDL user event for resetting mouse cursor */
|
---|
55 | #define SDL_USER_EVENT_GUEST_CAP_CHANGED (SDL_USEREVENT + 11)
|
---|
56 | /** custom SDL user event for window resize done */
|
---|
57 | #define SDL_USER_EVENT_WINDOW_RESIZE_DONE (SDL_USEREVENT + 12)
|
---|
58 |
|
---|
59 |
|
---|
60 | /** The user.code field of the SDL_USER_EVENT_TERMINATE event.
|
---|
61 | * @{
|
---|
62 | */
|
---|
63 | /** Normal termination. */
|
---|
64 | #define VBOXSDL_TERM_NORMAL 0
|
---|
65 | /** Abnormal termination. */
|
---|
66 | #define VBOXSDL_TERM_ABEND 1
|
---|
67 | /** @} */
|
---|
68 |
|
---|
69 | #if defined(VBOXSDL_WITH_X11) || defined(RT_OS_DARWIN)
|
---|
70 | void PushNotifyUpdateEvent(SDL_Event *event);
|
---|
71 | #endif
|
---|
72 | int PushSDLEventForSure(SDL_Event *event);
|
---|
73 |
|
---|
74 | class Display;
|
---|
75 |
|
---|
76 | class Framebuffer
|
---|
77 | {
|
---|
78 | public:
|
---|
79 | Framebuffer(Display *pDisplay, uint32_t uScreenId,
|
---|
80 | bool fFullscreen, bool fResizable, bool fShowSDLConfig,
|
---|
81 | bool fKeepHostRes, uint32_t u32FixedWidth,
|
---|
82 | uint32_t u32FixedHeight, uint32_t u32FixedBPP,
|
---|
83 | bool fUpdateImage);
|
---|
84 | Framebuffer(bool fShowSDLConfig);
|
---|
85 | virtual ~Framebuffer();
|
---|
86 |
|
---|
87 | static bool init(bool fShowSDLConfig);
|
---|
88 | static void uninit();
|
---|
89 |
|
---|
90 | uint32_t getWidth();
|
---|
91 | uint32_t getHeight();
|
---|
92 | uint32_t getBitsPerPixel();
|
---|
93 | uint32_t getBytesPerLine();
|
---|
94 | uint8_t *getPixelData();
|
---|
95 |
|
---|
96 | int notifyUpdate(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
---|
97 | int notifyChange(uint32_t idScreen, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
---|
98 |
|
---|
99 | int NotifyUpdateImage(uint32_t aX,
|
---|
100 | uint32_t aY,
|
---|
101 | uint32_t aWidth,
|
---|
102 | uint32_t aHeight,
|
---|
103 | void *pvImage);
|
---|
104 |
|
---|
105 | // internal public methods
|
---|
106 | bool initialized() { return mfInitialized; }
|
---|
107 | void notifyChange(uint32_t aScreenId);
|
---|
108 | void resizeGuest();
|
---|
109 | void resizeSDL();
|
---|
110 | void update(int x, int y, int w, int h, bool fGuestRelative);
|
---|
111 | void repaint();
|
---|
112 | void setFullscreen(bool fFullscreen);
|
---|
113 | void getFullscreenGeometry(uint32_t *width, uint32_t *height);
|
---|
114 | uint32_t getScreenId() { return mScreenId; }
|
---|
115 | uint32_t getGuestXRes() { return mGuestXRes; }
|
---|
116 | uint32_t getGuestYRes() { return mGuestYRes; }
|
---|
117 | int32_t getOriginX() { return mOriginX; }
|
---|
118 | int32_t getOriginY() { return mOriginY; }
|
---|
119 | int32_t getXOffset() { return mCenterXOffset; }
|
---|
120 | int32_t getYOffset() { return mCenterYOffset; }
|
---|
121 | SDL_Window *getWindow() { return mpWindow; }
|
---|
122 | bool hasWindow(uint32_t id) { return SDL_GetWindowID(mpWindow) == id; }
|
---|
123 | int setWindowTitle(const char *pcszTitle);
|
---|
124 | void setWinId(int64_t winId) { mWinId = winId; }
|
---|
125 | void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
|
---|
126 | bool getFullscreen() { return mfFullscreen; }
|
---|
127 |
|
---|
128 | private:
|
---|
129 |
|
---|
130 | /** the SDL window */
|
---|
131 | SDL_Window *mpWindow;
|
---|
132 | /** the texture */
|
---|
133 | SDL_Texture *mpTexture;
|
---|
134 | /** renderer */
|
---|
135 | SDL_Renderer *mpRenderer;
|
---|
136 | /** render info */
|
---|
137 | SDL_RendererInfo mRenderInfo;
|
---|
138 | /** false if constructor failed */
|
---|
139 | bool mfInitialized;
|
---|
140 | /** the screen number of this framebuffer */
|
---|
141 | uint32_t mScreenId;
|
---|
142 | /** use NotifyUpdateImage */
|
---|
143 | bool mfUpdateImage;
|
---|
144 | /** maximum possible screen width in pixels (~0 = no restriction) */
|
---|
145 | uint32_t mMaxScreenWidth;
|
---|
146 | /** maximum possible screen height in pixels (~0 = no restriction) */
|
---|
147 | uint32_t mMaxScreenHeight;
|
---|
148 | /** current guest screen width in pixels */
|
---|
149 | uint32_t mGuestXRes;
|
---|
150 | /** current guest screen height in pixels */
|
---|
151 | uint32_t mGuestYRes;
|
---|
152 | int32_t mOriginX;
|
---|
153 | int32_t mOriginY;
|
---|
154 | /** fixed SDL screen width (~0 = not set) */
|
---|
155 | uint32_t mFixedSDLWidth;
|
---|
156 | /** fixed SDL screen height (~0 = not set) */
|
---|
157 | uint32_t mFixedSDLHeight;
|
---|
158 | /** fixed SDL bits per pixel (~0 = not set) */
|
---|
159 | uint32_t mFixedSDLBPP;
|
---|
160 | /** Y offset in pixels, i.e. guest-nondrawable area at the top */
|
---|
161 | uint32_t mTopOffset;
|
---|
162 | /** X offset for guest screen centering */
|
---|
163 | uint32_t mCenterXOffset;
|
---|
164 | /** Y offset for guest screen centering */
|
---|
165 | uint32_t mCenterYOffset;
|
---|
166 | /** flag whether we're in fullscreen mode */
|
---|
167 | bool mfFullscreen;
|
---|
168 | /** flag whether we keep the host screen resolution when switching to
|
---|
169 | * fullscreen or not */
|
---|
170 | bool mfKeepHostRes;
|
---|
171 | /** framebuffer update semaphore */
|
---|
172 | RTCRITSECT mUpdateLock;
|
---|
173 | /** flag whether the SDL window should be resizable */
|
---|
174 | bool mfResizable;
|
---|
175 | /** flag whether we print out SDL information */
|
---|
176 | bool mfShowSDLConfig;
|
---|
177 | /** handle to window where framebuffer context is being drawn*/
|
---|
178 | int64_t mWinId;
|
---|
179 | SDL_Surface *mSurfVRAM;
|
---|
180 | bool mfUpdates;
|
---|
181 |
|
---|
182 | uint8_t *mPtrVRAM;
|
---|
183 | uint32_t mBitsPerPixel;
|
---|
184 | uint32_t mBytesPerLine;
|
---|
185 | bool mfSameSizeRequested;
|
---|
186 | Display *m_pDisplay;
|
---|
187 | };
|
---|
188 |
|
---|
189 | #endif /* !VBOX_INCLUDED_SRC_VBoxBFE_Framebuffer_h */
|
---|