[55401] | 1 | /* $Id: Framebuffer.cpp 99494 2023-04-20 19:52:23Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[63298] | 3 | * VBoxSDL - Implementation of VBoxSDLFB (SDL framebuffer) class
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #include <VBox/com/com.h>
|
---|
[51634] | 29 | #include <VBox/com/array.h>
|
---|
[1] | 30 | #include <VBox/com/string.h>
|
---|
| 31 | #include <VBox/com/Guid.h>
|
---|
| 32 | #include <VBox/com/ErrorInfo.h>
|
---|
| 33 | #include <VBox/com/VirtualBox.h>
|
---|
[3402] | 34 |
|
---|
[1] | 35 | #include <iprt/stream.h>
|
---|
[5107] | 36 | #include <iprt/env.h>
|
---|
[1] | 37 |
|
---|
[3669] | 38 | #ifdef RT_OS_OS2
|
---|
[3402] | 39 | # undef RT_MAX
|
---|
| 40 | // from <iprt/cdefs.h>
|
---|
| 41 | # define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
|
---|
| 42 | #endif
|
---|
| 43 |
|
---|
[1] | 44 | using namespace com;
|
---|
| 45 |
|
---|
| 46 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
[98303] | 47 | #include <iprt/errcore.h>
|
---|
[1] | 48 | #include <VBox/log.h>
|
---|
| 49 |
|
---|
| 50 | #include "VBoxSDL.h"
|
---|
| 51 | #include "Framebuffer.h"
|
---|
| 52 | #include "Ico64x01.h"
|
---|
| 53 |
|
---|
[21029] | 54 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX)
|
---|
[63298] | 55 | # ifdef _MSC_VER
|
---|
| 56 | # pragma warning(push)
|
---|
| 57 | # pragma warning(disable: 4121) /* warning C4121: 'SDL_SysWMmsg' : alignment of a member was sensitive to packing*/
|
---|
| 58 | # endif
|
---|
| 59 | # include <SDL_syswm.h> /* for SDL_GetWMInfo() */
|
---|
| 60 | # ifdef _MSC_VER
|
---|
| 61 | # pragma warning(pop)
|
---|
| 62 | # endif
|
---|
[21029] | 63 | #endif
|
---|
| 64 |
|
---|
[614] | 65 | #if defined(VBOX_WITH_XPCOM)
|
---|
[22911] | 66 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxSDLFB, IFramebuffer)
|
---|
[1] | 67 | NS_DECL_CLASSINFO(VBoxSDLFB)
|
---|
[42852] | 68 | NS_IMPL_THREADSAFE_ISUPPORTS2_CI(VBoxSDLFBOverlay, IFramebufferOverlay, IFramebuffer)
|
---|
[1] | 69 | NS_DECL_CLASSINFO(VBoxSDLFBOverlay)
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
[34513] | 72 | static bool gfSdlInitialized = false; /**< if SDL was initialized */
|
---|
| 73 | static SDL_Surface *gWMIcon = NULL; /**< the application icon */
|
---|
| 74 | static RTNATIVETHREAD gSdlNativeThread = NIL_RTNATIVETHREAD; /**< the SDL thread */
|
---|
[20433] | 75 |
|
---|
[1] | 76 | //
|
---|
| 77 | // Constructor / destructor
|
---|
| 78 | //
|
---|
| 79 |
|
---|
[51677] | 80 | VBoxSDLFB::VBoxSDLFB()
|
---|
| 81 | {
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | HRESULT VBoxSDLFB::FinalConstruct()
|
---|
| 85 | {
|
---|
| 86 | return 0;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void VBoxSDLFB::FinalRelease()
|
---|
| 90 | {
|
---|
| 91 | return;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[1] | 94 | /**
|
---|
[41216] | 95 | * SDL framebuffer constructor. It is called from the main
|
---|
[1] | 96 | * (i.e. SDL) thread. Therefore it is safe to use SDL calls
|
---|
| 97 | * here.
|
---|
| 98 | * @param fFullscreen flag whether we start in fullscreen mode
|
---|
| 99 | * @param fResizable flag whether the SDL window should be resizable
|
---|
| 100 | * @param fShowSDLConfig flag whether we print out SDL settings
|
---|
[10675] | 101 | * @param fKeepHostRes flag whether we switch the host screen resolution
|
---|
| 102 | * when switching to fullscreen or not
|
---|
| 103 | * @param iFixedWidth fixed SDL width (-1 means not set)
|
---|
| 104 | * @param iFixedHeight fixed SDL height (-1 means not set)
|
---|
[1] | 105 | */
|
---|
[51677] | 106 | HRESULT VBoxSDLFB::init(uint32_t uScreenId,
|
---|
[41216] | 107 | bool fFullscreen, bool fResizable, bool fShowSDLConfig,
|
---|
| 108 | bool fKeepHostRes, uint32_t u32FixedWidth,
|
---|
[51634] | 109 | uint32_t u32FixedHeight, uint32_t u32FixedBPP,
|
---|
| 110 | bool fUpdateImage)
|
---|
[1] | 111 | {
|
---|
[41216] | 112 | LogFlow(("VBoxSDLFB::VBoxSDLFB\n"));
|
---|
[1] | 113 |
|
---|
[20433] | 114 | mScreenId = uScreenId;
|
---|
[51634] | 115 | mfUpdateImage = fUpdateImage;
|
---|
[81537] | 116 | mpWindow = NULL;
|
---|
| 117 | mpTexture = NULL;
|
---|
| 118 | mpRenderer = NULL;
|
---|
[1] | 119 | mSurfVRAM = NULL;
|
---|
| 120 | mfInitialized = false;
|
---|
| 121 | mfFullscreen = fFullscreen;
|
---|
[10675] | 122 | mfKeepHostRes = fKeepHostRes;
|
---|
[1] | 123 | mTopOffset = 0;
|
---|
| 124 | mfResizable = fResizable;
|
---|
| 125 | mfShowSDLConfig = fShowSDLConfig;
|
---|
[143] | 126 | mFixedSDLWidth = u32FixedWidth;
|
---|
| 127 | mFixedSDLHeight = u32FixedHeight;
|
---|
| 128 | mFixedSDLBPP = u32FixedBPP;
|
---|
[1] | 129 | mCenterXOffset = 0;
|
---|
| 130 | mCenterYOffset = 0;
|
---|
| 131 | /* Start with standard screen dimensions. */
|
---|
| 132 | mGuestXRes = 640;
|
---|
| 133 | mGuestYRes = 480;
|
---|
| 134 | mPtrVRAM = NULL;
|
---|
[3761] | 135 | mBitsPerPixel = 0;
|
---|
| 136 | mBytesPerLine = 0;
|
---|
[15868] | 137 | mfSameSizeRequested = false;
|
---|
[51436] | 138 | mfUpdates = false;
|
---|
| 139 |
|
---|
[81537] | 140 | int rc = RTCritSectInit(&mUpdateLock);
|
---|
[1] | 141 | AssertMsg(rc == VINF_SUCCESS, ("Error from RTCritSectInit!\n"));
|
---|
| 142 |
|
---|
[20433] | 143 | resizeGuest();
|
---|
| 144 | mfInitialized = true;
|
---|
[51677] | 145 | #ifdef RT_OS_WINDOWS
|
---|
[60759] | 146 | HRESULT hr = CoCreateFreeThreadedMarshaler(this, m_pUnkMarshaler.asOutParam());
|
---|
[63298] | 147 | Log(("CoCreateFreeThreadedMarshaler hr %08X\n", hr)); NOREF(hr);
|
---|
[51677] | 148 | #endif
|
---|
| 149 |
|
---|
[81537] | 150 | rc = SDL_GetRendererInfo(mpRenderer, &mRenderInfo);
|
---|
| 151 | if (RT_SUCCESS(rc))
|
---|
| 152 | {
|
---|
| 153 | if (fShowSDLConfig)
|
---|
| 154 | RTPrintf("Render info:\n"
|
---|
| 155 | " Name: %s\n"
|
---|
| 156 | " Render flags: 0x%x\n"
|
---|
| 157 | " SDL video driver: %s\n",
|
---|
| 158 | mRenderInfo.name,
|
---|
| 159 | mRenderInfo.flags,
|
---|
| 160 | RTEnvGet("SDL_VIDEODRIVER"));
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | return rc;
|
---|
[20433] | 164 | }
|
---|
| 165 |
|
---|
[41216] | 166 | VBoxSDLFB::~VBoxSDLFB()
|
---|
[20433] | 167 | {
|
---|
[41216] | 168 | LogFlow(("VBoxSDLFB::~VBoxSDLFB\n"));
|
---|
[20433] | 169 | if (mSurfVRAM)
|
---|
| 170 | {
|
---|
| 171 | SDL_FreeSurface(mSurfVRAM);
|
---|
| 172 | mSurfVRAM = NULL;
|
---|
| 173 | }
|
---|
| 174 | RTCritSectDelete(&mUpdateLock);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[81537] | 177 | /* static */
|
---|
[41216] | 178 | bool VBoxSDLFB::init(bool fShowSDLConfig)
|
---|
[20433] | 179 | {
|
---|
| 180 | LogFlow(("VBoxSDLFB::init\n"));
|
---|
| 181 |
|
---|
| 182 | /* memorize the thread that inited us, that's the SDL thread */
|
---|
| 183 | gSdlNativeThread = RTThreadNativeSelf();
|
---|
| 184 |
|
---|
[3669] | 185 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 186 | /* default to DirectX if nothing else set */
|
---|
[50406] | 187 | if (!RTEnvExist("SDL_VIDEODRIVER"))
|
---|
[1] | 188 | {
|
---|
[81537] | 189 | RTEnvSet("SDL_VIDEODRIVER", "directx");
|
---|
[1] | 190 | }
|
---|
| 191 | #endif
|
---|
[4637] | 192 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 193 | /* On some X servers the mouse is stuck inside the bottom right corner.
|
---|
| 194 | * See http://wiki.clug.org.za/wiki/QEMU_mouse_not_working */
|
---|
[11419] | 195 | RTEnvSet("SDL_VIDEO_X11_DGAMOUSE", "0");
|
---|
[1] | 196 | #endif
|
---|
[81537] | 197 |
|
---|
[20433] | 198 | int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
|
---|
[1] | 199 | if (rc != 0)
|
---|
| 200 | {
|
---|
| 201 | RTPrintf("SDL Error: '%s'\n", SDL_GetError());
|
---|
[23170] | 202 | return false;
|
---|
[1] | 203 | }
|
---|
[34513] | 204 | gfSdlInitialized = true;
|
---|
[1] | 205 |
|
---|
[81537] | 206 | RT_NOREF(fShowSDLConfig);
|
---|
[23170] | 207 | return true;
|
---|
[1] | 208 | }
|
---|
| 209 |
|
---|
[20433] | 210 | /**
|
---|
| 211 | * Terminate SDL
|
---|
| 212 | *
|
---|
| 213 | * @remarks must be called from the SDL thread!
|
---|
| 214 | */
|
---|
[41216] | 215 | void VBoxSDLFB::uninit()
|
---|
[1] | 216 | {
|
---|
[34513] | 217 | if (gfSdlInitialized)
|
---|
[20433] | 218 | {
|
---|
[34513] | 219 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
| 220 | SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
---|
[20433] | 221 | }
|
---|
[1] | 222 | }
|
---|
| 223 |
|
---|
| 224 | /**
|
---|
| 225 | * Returns the current framebuffer width in pixels.
|
---|
| 226 | *
|
---|
| 227 | * @returns COM status code
|
---|
| 228 | * @param width Address of result buffer.
|
---|
| 229 | */
|
---|
| 230 | STDMETHODIMP VBoxSDLFB::COMGETTER(Width)(ULONG *width)
|
---|
| 231 | {
|
---|
| 232 | LogFlow(("VBoxSDLFB::GetWidth\n"));
|
---|
| 233 | if (!width)
|
---|
| 234 | return E_INVALIDARG;
|
---|
| 235 | *width = mGuestXRes;
|
---|
| 236 | return S_OK;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | /**
|
---|
| 240 | * Returns the current framebuffer height in pixels.
|
---|
| 241 | *
|
---|
| 242 | * @returns COM status code
|
---|
| 243 | * @param height Address of result buffer.
|
---|
| 244 | */
|
---|
| 245 | STDMETHODIMP VBoxSDLFB::COMGETTER(Height)(ULONG *height)
|
---|
| 246 | {
|
---|
| 247 | LogFlow(("VBoxSDLFB::GetHeight\n"));
|
---|
| 248 | if (!height)
|
---|
| 249 | return E_INVALIDARG;
|
---|
| 250 | *height = mGuestYRes;
|
---|
| 251 | return S_OK;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | /**
|
---|
| 255 | * Return the current framebuffer color depth.
|
---|
| 256 | *
|
---|
| 257 | * @returns COM status code
|
---|
[3761] | 258 | * @param bitsPerPixel Address of result variable
|
---|
[1] | 259 | */
|
---|
[3761] | 260 | STDMETHODIMP VBoxSDLFB::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
|
---|
[1] | 261 | {
|
---|
[3761] | 262 | LogFlow(("VBoxSDLFB::GetBitsPerPixel\n"));
|
---|
| 263 | if (!bitsPerPixel)
|
---|
[1] | 264 | return E_INVALIDARG;
|
---|
| 265 | /* get the information directly from the surface in use */
|
---|
| 266 | Assert(mSurfVRAM);
|
---|
[3761] | 267 | *bitsPerPixel = (ULONG)(mSurfVRAM ? mSurfVRAM->format->BitsPerPixel : 0);
|
---|
[1] | 268 | return S_OK;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /**
|
---|
| 272 | * Return the current framebuffer line size in bytes.
|
---|
| 273 | *
|
---|
| 274 | * @returns COM status code.
|
---|
| 275 | * @param lineSize Address of result variable.
|
---|
| 276 | */
|
---|
[3761] | 277 | STDMETHODIMP VBoxSDLFB::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
|
---|
[1] | 278 | {
|
---|
[3761] | 279 | LogFlow(("VBoxSDLFB::GetBytesPerLine\n"));
|
---|
| 280 | if (!bytesPerLine)
|
---|
[1] | 281 | return E_INVALIDARG;
|
---|
| 282 | /* get the information directly from the surface */
|
---|
| 283 | Assert(mSurfVRAM);
|
---|
[3761] | 284 | *bytesPerLine = (ULONG)(mSurfVRAM ? mSurfVRAM->pitch : 0);
|
---|
[1] | 285 | return S_OK;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[54828] | 288 | STDMETHODIMP VBoxSDLFB::COMGETTER(PixelFormat) (BitmapFormat_T *pixelFormat)
|
---|
[1] | 289 | {
|
---|
| 290 | if (!pixelFormat)
|
---|
| 291 | return E_POINTER;
|
---|
[52200] | 292 | *pixelFormat = BitmapFormat_BGR;
|
---|
[1] | 293 | return S_OK;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | /**
|
---|
| 297 | * Returns by how many pixels the guest should shrink its
|
---|
| 298 | * video mode height values.
|
---|
| 299 | *
|
---|
| 300 | * @returns COM status code.
|
---|
| 301 | * @param heightReduction Address of result variable.
|
---|
| 302 | */
|
---|
| 303 | STDMETHODIMP VBoxSDLFB::COMGETTER(HeightReduction)(ULONG *heightReduction)
|
---|
| 304 | {
|
---|
| 305 | if (!heightReduction)
|
---|
| 306 | return E_POINTER;
|
---|
| 307 | *heightReduction = 0;
|
---|
| 308 | return S_OK;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | /**
|
---|
| 312 | * Returns a pointer to an alpha-blended overlay used for displaying status
|
---|
| 313 | * icons above the framebuffer.
|
---|
| 314 | *
|
---|
| 315 | * @returns COM status code.
|
---|
| 316 | * @param aOverlay The overlay framebuffer.
|
---|
| 317 | */
|
---|
| 318 | STDMETHODIMP VBoxSDLFB::COMGETTER(Overlay)(IFramebufferOverlay **aOverlay)
|
---|
| 319 | {
|
---|
| 320 | if (!aOverlay)
|
---|
| 321 | return E_POINTER;
|
---|
| 322 | /* Not yet implemented */
|
---|
| 323 | *aOverlay = 0;
|
---|
| 324 | return S_OK;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | /**
|
---|
[12449] | 328 | * Returns handle of window where framebuffer context is being drawn
|
---|
| 329 | *
|
---|
| 330 | * @returns COM status code.
|
---|
| 331 | * @param winId Handle of associated window.
|
---|
| 332 | */
|
---|
[55810] | 333 | STDMETHODIMP VBoxSDLFB::COMGETTER(WinId)(LONG64 *winId)
|
---|
[12449] | 334 | {
|
---|
| 335 | if (!winId)
|
---|
| 336 | return E_POINTER;
|
---|
[99494] | 337 |
|
---|
[12449] | 338 | *winId = mWinId;
|
---|
| 339 | return S_OK;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[52574] | 342 | STDMETHODIMP VBoxSDLFB::COMGETTER(Capabilities)(ComSafeArrayOut(FramebufferCapabilities_T, aCapabilities))
|
---|
| 343 | {
|
---|
| 344 | if (ComSafeArrayOutIsNull(aCapabilities))
|
---|
| 345 | return E_POINTER;
|
---|
| 346 |
|
---|
| 347 | com::SafeArray<FramebufferCapabilities_T> caps;
|
---|
| 348 |
|
---|
| 349 | if (mfUpdateImage)
|
---|
| 350 | {
|
---|
[77370] | 351 | caps.resize(2);
|
---|
[52574] | 352 | caps[0] = FramebufferCapabilities_UpdateImage;
|
---|
[77370] | 353 | caps[1] = FramebufferCapabilities_RenderCursor;
|
---|
[52574] | 354 | }
|
---|
| 355 | else
|
---|
| 356 | {
|
---|
[77370] | 357 | caps.resize(1);
|
---|
| 358 | caps[0] = FramebufferCapabilities_RenderCursor;
|
---|
[52574] | 359 | }
|
---|
| 360 |
|
---|
| 361 | caps.detachTo(ComSafeArrayOutArg(aCapabilities));
|
---|
| 362 | return S_OK;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[12449] | 365 | /**
|
---|
[1] | 366 | * Notify framebuffer of an update.
|
---|
| 367 | *
|
---|
| 368 | * @returns COM status code
|
---|
| 369 | * @param x Update region upper left corner x value.
|
---|
| 370 | * @param y Update region upper left corner y value.
|
---|
| 371 | * @param w Update region width in pixels.
|
---|
| 372 | * @param h Update region height in pixels.
|
---|
| 373 | * @param finished Address of output flag whether the update
|
---|
| 374 | * could be fully processed in this call (which
|
---|
| 375 | * has to return immediately) or VBox should wait
|
---|
| 376 | * for a call to the update complete API before
|
---|
| 377 | * continuing with display updates.
|
---|
| 378 | */
|
---|
| 379 | STDMETHODIMP VBoxSDLFB::NotifyUpdate(ULONG x, ULONG y,
|
---|
[19817] | 380 | ULONG w, ULONG h)
|
---|
[1] | 381 | {
|
---|
| 382 | /*
|
---|
| 383 | * The input values are in guest screen coordinates.
|
---|
| 384 | */
|
---|
| 385 | LogFlow(("VBoxSDLFB::NotifyUpdate: x = %d, y = %d, w = %d, h = %d\n",
|
---|
| 386 | x, y, w, h));
|
---|
| 387 |
|
---|
[99494] | 388 | #if defined(VBOXSDL_WITH_X11) || defined(RT_OS_DARWIN)
|
---|
[1] | 389 | /*
|
---|
[3289] | 390 | * SDL does not allow us to make this call from any other thread than
|
---|
| 391 | * the main SDL thread (which initialized the video mode). So we have
|
---|
| 392 | * to send an event to the main SDL thread and process it there. For
|
---|
| 393 | * sake of simplicity, we encode all information in the event parameters.
|
---|
[1] | 394 | */
|
---|
| 395 | SDL_Event event;
|
---|
| 396 | event.type = SDL_USEREVENT;
|
---|
[20433] | 397 | event.user.code = mScreenId;
|
---|
[1] | 398 | event.user.type = SDL_USER_EVENT_UPDATERECT;
|
---|
[99090] | 399 |
|
---|
| 400 | SDL_Rect *pUpdateRect = (SDL_Rect *)RTMemAlloc(sizeof(SDL_Rect));
|
---|
| 401 | AssertPtrReturn(pUpdateRect, E_OUTOFMEMORY);
|
---|
| 402 | pUpdateRect->x = x;
|
---|
| 403 | pUpdateRect->y = y;
|
---|
| 404 | pUpdateRect->w = w;
|
---|
| 405 | pUpdateRect->h = h;
|
---|
| 406 | event.user.data1 = pUpdateRect;
|
---|
| 407 |
|
---|
| 408 | event.user.data2 = NULL;
|
---|
[3289] | 409 | PushNotifyUpdateEvent(&event);
|
---|
[4637] | 410 | #else /* !VBOXSDL_WITH_X11 */
|
---|
[1] | 411 | update(x, y, w, h, true /* fGuestRelative */);
|
---|
[4637] | 412 | #endif /* !VBOXSDL_WITH_X11 */
|
---|
[1] | 413 |
|
---|
| 414 | return S_OK;
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[51627] | 417 | STDMETHODIMP VBoxSDLFB::NotifyUpdateImage(ULONG aX,
|
---|
| 418 | ULONG aY,
|
---|
| 419 | ULONG aWidth,
|
---|
| 420 | ULONG aHeight,
|
---|
| 421 | ComSafeArrayIn(BYTE, aImage))
|
---|
| 422 | {
|
---|
[51634] | 423 | LogFlow(("NotifyUpdateImage: %d,%d %dx%d\n", aX, aY, aWidth, aHeight));
|
---|
| 424 |
|
---|
| 425 | com::SafeArray<BYTE> image(ComSafeArrayInArg(aImage));
|
---|
| 426 |
|
---|
| 427 | /* Copy to mSurfVRAM. */
|
---|
| 428 | SDL_Rect srcRect;
|
---|
| 429 | SDL_Rect dstRect;
|
---|
| 430 | srcRect.x = 0;
|
---|
| 431 | srcRect.y = 0;
|
---|
| 432 | srcRect.w = (uint16_t)aWidth;
|
---|
| 433 | srcRect.h = (uint16_t)aHeight;
|
---|
| 434 | dstRect.x = (int16_t)aX;
|
---|
| 435 | dstRect.y = (int16_t)aY;
|
---|
| 436 | dstRect.w = (uint16_t)aWidth;
|
---|
| 437 | dstRect.h = (uint16_t)aHeight;
|
---|
| 438 |
|
---|
| 439 | const uint32_t Rmask = 0x00FF0000, Gmask = 0x0000FF00, Bmask = 0x000000FF, Amask = 0;
|
---|
| 440 | SDL_Surface *surfSrc = SDL_CreateRGBSurfaceFrom(image.raw(), aWidth, aHeight, 32, aWidth * 4,
|
---|
| 441 | Rmask, Gmask, Bmask, Amask);
|
---|
| 442 | if (surfSrc)
|
---|
| 443 | {
|
---|
| 444 | RTCritSectEnter(&mUpdateLock);
|
---|
| 445 | if (mfUpdates)
|
---|
| 446 | SDL_BlitSurface(surfSrc, &srcRect, mSurfVRAM, &dstRect);
|
---|
| 447 | RTCritSectLeave(&mUpdateLock);
|
---|
| 448 |
|
---|
| 449 | SDL_FreeSurface(surfSrc);
|
---|
| 450 | }
|
---|
| 451 |
|
---|
| 452 | return NotifyUpdate(aX, aY, aWidth, aHeight);
|
---|
[51627] | 453 | }
|
---|
| 454 |
|
---|
[51436] | 455 | extern ComPtr<IDisplay> gpDisplay;
|
---|
| 456 |
|
---|
| 457 | STDMETHODIMP VBoxSDLFB::NotifyChange(ULONG aScreenId,
|
---|
| 458 | ULONG aXOrigin,
|
---|
| 459 | ULONG aYOrigin,
|
---|
| 460 | ULONG aWidth,
|
---|
| 461 | ULONG aHeight)
|
---|
| 462 | {
|
---|
| 463 | LogRel(("NotifyChange: %d %d,%d %dx%d\n",
|
---|
[51547] | 464 | aScreenId, aXOrigin, aYOrigin, aWidth, aHeight));
|
---|
[51436] | 465 |
|
---|
[51634] | 466 | ComPtr<IDisplaySourceBitmap> pSourceBitmap;
|
---|
| 467 | if (!mfUpdateImage)
|
---|
| 468 | gpDisplay->QuerySourceBitmap(aScreenId, pSourceBitmap.asOutParam());
|
---|
| 469 |
|
---|
[51436] | 470 | RTCritSectEnter(&mUpdateLock);
|
---|
| 471 |
|
---|
[51547] | 472 | /* Disable screen updates. */
|
---|
| 473 | mfUpdates = false;
|
---|
| 474 |
|
---|
[51634] | 475 | if (mfUpdateImage)
|
---|
| 476 | {
|
---|
| 477 | mGuestXRes = aWidth;
|
---|
| 478 | mGuestYRes = aHeight;
|
---|
| 479 | mPtrVRAM = NULL;
|
---|
| 480 | mBitsPerPixel = 0;
|
---|
| 481 | mBytesPerLine = 0;
|
---|
| 482 | }
|
---|
| 483 | else
|
---|
| 484 | {
|
---|
| 485 | /* Save the new bitmap. */
|
---|
| 486 | mpPendingSourceBitmap = pSourceBitmap;
|
---|
| 487 | }
|
---|
[51436] | 488 |
|
---|
| 489 | RTCritSectLeave(&mUpdateLock);
|
---|
| 490 |
|
---|
| 491 | SDL_Event event;
|
---|
| 492 | event.type = SDL_USEREVENT;
|
---|
| 493 | event.user.type = SDL_USER_EVENT_NOTIFYCHANGE;
|
---|
| 494 | event.user.code = mScreenId;
|
---|
| 495 |
|
---|
| 496 | PushSDLEventForSure(&event);
|
---|
| 497 |
|
---|
| 498 | RTThreadYield();
|
---|
| 499 |
|
---|
| 500 | return S_OK;
|
---|
| 501 | }
|
---|
| 502 |
|
---|
[1] | 503 | /**
|
---|
| 504 | * Returns whether we like the given video mode.
|
---|
| 505 | *
|
---|
| 506 | * @returns COM status code
|
---|
| 507 | * @param width video mode width in pixels
|
---|
| 508 | * @param height video mode height in pixels
|
---|
| 509 | * @param bpp video mode bit depth in bits per pixel
|
---|
| 510 | * @param supported pointer to result variable
|
---|
| 511 | */
|
---|
| 512 | STDMETHODIMP VBoxSDLFB::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported)
|
---|
| 513 | {
|
---|
[63298] | 514 | RT_NOREF(bpp);
|
---|
| 515 |
|
---|
[1] | 516 | if (!supported)
|
---|
| 517 | return E_POINTER;
|
---|
| 518 |
|
---|
| 519 | /* are constraints set? */
|
---|
[143] | 520 | if ( ( (mMaxScreenWidth != ~(uint32_t)0)
|
---|
[5917] | 521 | && (width > mMaxScreenWidth))
|
---|
[143] | 522 | || ( (mMaxScreenHeight != ~(uint32_t)0)
|
---|
[5917] | 523 | && (height > mMaxScreenHeight)))
|
---|
[1] | 524 | {
|
---|
| 525 | /* nope, we don't want that (but still don't freak out if it is set) */
|
---|
| 526 | #ifdef DEBUG
|
---|
[81537] | 527 | RTPrintf("VBoxSDL::VideoModeSupported: we refused mode %dx%dx%d\n", width, height, bpp);
|
---|
[1] | 528 | #endif
|
---|
| 529 | *supported = false;
|
---|
| 530 | }
|
---|
| 531 | else
|
---|
| 532 | {
|
---|
| 533 | /* anything will do */
|
---|
| 534 | *supported = true;
|
---|
| 535 | }
|
---|
| 536 | return S_OK;
|
---|
| 537 | }
|
---|
| 538 |
|
---|
[3576] | 539 | STDMETHODIMP VBoxSDLFB::GetVisibleRegion(BYTE *aRectangles, ULONG aCount,
|
---|
| 540 | ULONG *aCountCopied)
|
---|
[3532] | 541 | {
|
---|
[3576] | 542 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
[1] | 543 |
|
---|
[3576] | 544 | if (!rects)
|
---|
[3532] | 545 | return E_POINTER;
|
---|
| 546 |
|
---|
[3576] | 547 | /// @todo
|
---|
| 548 |
|
---|
[26509] | 549 | NOREF(aCount);
|
---|
| 550 | NOREF(aCountCopied);
|
---|
[3576] | 551 |
|
---|
[3532] | 552 | return S_OK;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[3576] | 555 | STDMETHODIMP VBoxSDLFB::SetVisibleRegion(BYTE *aRectangles, ULONG aCount)
|
---|
[3532] | 556 | {
|
---|
[3576] | 557 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
[3532] | 558 |
|
---|
[3576] | 559 | if (!rects)
|
---|
[3532] | 560 | return E_POINTER;
|
---|
| 561 |
|
---|
[3576] | 562 | /// @todo
|
---|
| 563 |
|
---|
[26509] | 564 | NOREF(aCount);
|
---|
[3576] | 565 |
|
---|
[3532] | 566 | return S_OK;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
[71651] | 569 | STDMETHODIMP VBoxSDLFB::ProcessVHWACommand(BYTE *pCommand, LONG enmCmd, BOOL fGuestCmd)
|
---|
[19844] | 570 | {
|
---|
[71651] | 571 | RT_NOREF(pCommand, enmCmd, fGuestCmd);
|
---|
[19844] | 572 | return E_NOTIMPL;
|
---|
| 573 | }
|
---|
[45940] | 574 |
|
---|
[51670] | 575 | STDMETHODIMP VBoxSDLFB::Notify3DEvent(ULONG uType, ComSafeArrayIn(BYTE, aData))
|
---|
[45940] | 576 | {
|
---|
[63384] | 577 | RT_NOREF(uType); ComSafeArrayNoRef(aData);
|
---|
[45940] | 578 | return E_NOTIMPL;
|
---|
| 579 | }
|
---|
| 580 |
|
---|
[1] | 581 | //
|
---|
| 582 | // Internal public methods
|
---|
| 583 | //
|
---|
| 584 |
|
---|
[51547] | 585 | /* This method runs on the main SDL thread. */
|
---|
| 586 | void VBoxSDLFB::notifyChange(ULONG aScreenId)
|
---|
| 587 | {
|
---|
| 588 | /* Disable screen updates. */
|
---|
| 589 | RTCritSectEnter(&mUpdateLock);
|
---|
| 590 |
|
---|
[51634] | 591 | if (!mfUpdateImage && mpPendingSourceBitmap.isNull())
|
---|
[51547] | 592 | {
|
---|
| 593 | /* Do nothing. Change event already processed. */
|
---|
| 594 | RTCritSectLeave(&mUpdateLock);
|
---|
| 595 | return;
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | /* Release the current bitmap and keep the pending one. */
|
---|
| 599 | mpSourceBitmap = mpPendingSourceBitmap;
|
---|
| 600 | mpPendingSourceBitmap.setNull();
|
---|
| 601 |
|
---|
| 602 | RTCritSectLeave(&mUpdateLock);
|
---|
| 603 |
|
---|
| 604 | if (mpSourceBitmap.isNull())
|
---|
| 605 | {
|
---|
| 606 | mPtrVRAM = NULL;
|
---|
| 607 | mBitsPerPixel = 32;
|
---|
| 608 | mBytesPerLine = mGuestXRes * 4;
|
---|
| 609 | }
|
---|
| 610 | else
|
---|
| 611 | {
|
---|
| 612 | BYTE *pAddress = NULL;
|
---|
| 613 | ULONG ulWidth = 0;
|
---|
| 614 | ULONG ulHeight = 0;
|
---|
| 615 | ULONG ulBitsPerPixel = 0;
|
---|
| 616 | ULONG ulBytesPerLine = 0;
|
---|
[54828] | 617 | BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
|
---|
[51547] | 618 |
|
---|
| 619 | mpSourceBitmap->QueryBitmapInfo(&pAddress,
|
---|
| 620 | &ulWidth,
|
---|
| 621 | &ulHeight,
|
---|
| 622 | &ulBitsPerPixel,
|
---|
| 623 | &ulBytesPerLine,
|
---|
[54828] | 624 | &bitmapFormat);
|
---|
[51547] | 625 |
|
---|
| 626 | if ( mGuestXRes == ulWidth
|
---|
| 627 | && mGuestYRes == ulHeight
|
---|
| 628 | && mBitsPerPixel == ulBitsPerPixel
|
---|
| 629 | && mBytesPerLine == ulBytesPerLine
|
---|
| 630 | && mPtrVRAM == pAddress
|
---|
| 631 | )
|
---|
| 632 | {
|
---|
| 633 | mfSameSizeRequested = true;
|
---|
| 634 | }
|
---|
| 635 | else
|
---|
| 636 | {
|
---|
| 637 | mfSameSizeRequested = false;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | mGuestXRes = ulWidth;
|
---|
| 641 | mGuestYRes = ulHeight;
|
---|
| 642 | mPtrVRAM = pAddress;
|
---|
| 643 | mBitsPerPixel = ulBitsPerPixel;
|
---|
| 644 | mBytesPerLine = ulBytesPerLine;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | resizeGuest();
|
---|
[51634] | 648 |
|
---|
[52122] | 649 | gpDisplay->InvalidateAndUpdateScreen(aScreenId);
|
---|
[51547] | 650 | }
|
---|
| 651 |
|
---|
[1] | 652 | /**
|
---|
| 653 | * Method that does the actual resize of the guest framebuffer and
|
---|
| 654 | * then changes the SDL framebuffer setup.
|
---|
| 655 | */
|
---|
| 656 | void VBoxSDLFB::resizeGuest()
|
---|
| 657 | {
|
---|
[3761] | 658 | LogFlowFunc (("mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes));
|
---|
[20433] | 659 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(),
|
---|
[3761] | 660 | ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 661 |
|
---|
[51634] | 662 | RTCritSectEnter(&mUpdateLock);
|
---|
| 663 |
|
---|
[51547] | 664 | const uint32_t Rmask = 0x00FF0000, Gmask = 0x0000FF00, Bmask = 0x000000FF, Amask = 0;
|
---|
[523] | 665 |
|
---|
[1] | 666 | /* first free the current surface */
|
---|
| 667 | if (mSurfVRAM)
|
---|
| 668 | {
|
---|
| 669 | SDL_FreeSurface(mSurfVRAM);
|
---|
| 670 | mSurfVRAM = NULL;
|
---|
| 671 | }
|
---|
| 672 |
|
---|
[51547] | 673 | if (mPtrVRAM)
|
---|
[1] | 674 | {
|
---|
[51547] | 675 | /* Create a source surface from the source bitmap. */
|
---|
[3761] | 676 | mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, mBitsPerPixel,
|
---|
| 677 | mBytesPerLine, Rmask, Gmask, Bmask, Amask);
|
---|
[51547] | 678 | LogFlow(("VBoxSDL:: using the source bitmap\n"));
|
---|
[1] | 679 | }
|
---|
| 680 | else
|
---|
| 681 | {
|
---|
[98246] | 682 | mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, 32,
|
---|
[1] | 683 | Rmask, Gmask, Bmask, Amask);
|
---|
[51547] | 684 | LogFlow(("VBoxSDL:: using SDL_SWSURFACE\n"));
|
---|
[1] | 685 | }
|
---|
| 686 | LogFlow(("VBoxSDL:: created VRAM surface %p\n", mSurfVRAM));
|
---|
| 687 |
|
---|
[51547] | 688 | if (mfSameSizeRequested)
|
---|
[15868] | 689 | {
|
---|
| 690 | mfSameSizeRequested = false;
|
---|
| 691 | LogFlow(("VBoxSDL:: the same resolution requested, skipping the resize.\n"));
|
---|
| 692 | }
|
---|
[51547] | 693 | else
|
---|
| 694 | {
|
---|
| 695 | /* now adjust the SDL resolution */
|
---|
| 696 | resizeSDL();
|
---|
| 697 | }
|
---|
[15868] | 698 |
|
---|
[51436] | 699 | /* Enable screen updates. */
|
---|
| 700 | mfUpdates = true;
|
---|
[51634] | 701 |
|
---|
[51436] | 702 | RTCritSectLeave(&mUpdateLock);
|
---|
| 703 |
|
---|
| 704 | repaint();
|
---|
[1] | 705 | }
|
---|
| 706 |
|
---|
| 707 | /**
|
---|
| 708 | * Sets SDL video mode. This is independent from guest video
|
---|
| 709 | * mode changes.
|
---|
| 710 | *
|
---|
| 711 | * @remarks Must be called from the SDL thread!
|
---|
| 712 | */
|
---|
| 713 | void VBoxSDLFB::resizeSDL(void)
|
---|
| 714 | {
|
---|
| 715 | LogFlow(("VBoxSDL:resizeSDL\n"));
|
---|
| 716 |
|
---|
[81537] | 717 | const int cDisplays = SDL_GetNumVideoDisplays();
|
---|
| 718 | if (cDisplays > 0)
|
---|
| 719 | {
|
---|
| 720 | for (int d = 0; d < cDisplays; d++)
|
---|
| 721 | {
|
---|
| 722 | const int cDisplayModes = SDL_GetNumDisplayModes(d);
|
---|
| 723 | for (int m = 0; m < cDisplayModes; m++)
|
---|
| 724 | {
|
---|
| 725 | SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
---|
| 726 | if (SDL_GetDisplayMode(d, m, &mode) != 0)
|
---|
| 727 | {
|
---|
| 728 | RTPrintf("Display #%d, mode %d:\t\t%i bpp\t%i x %i",
|
---|
| 729 | SDL_BITSPERPIXEL(mode.format), mode.w, mode.h);
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | if (m == 0)
|
---|
| 733 | {
|
---|
| 734 | /*
|
---|
| 735 | * according to the SDL documentation, the API guarantees that
|
---|
| 736 | * the modes are sorted from larger to smaller, so we just
|
---|
| 737 | * take the first entry as the maximum.
|
---|
| 738 | */
|
---|
| 739 | mMaxScreenWidth = mode.w;
|
---|
| 740 | mMaxScreenHeight = mode.h;
|
---|
| 741 | }
|
---|
| 742 |
|
---|
| 743 | /* Keep going. */
|
---|
| 744 | }
|
---|
| 745 | }
|
---|
| 746 | }
|
---|
| 747 | else
|
---|
| 748 | AssertFailed(); /** @todo */
|
---|
[1] | 749 |
|
---|
| 750 | uint32_t newWidth;
|
---|
| 751 | uint32_t newHeight;
|
---|
| 752 |
|
---|
| 753 | /* reset the centering offsets */
|
---|
| 754 | mCenterXOffset = 0;
|
---|
| 755 | mCenterYOffset = 0;
|
---|
| 756 |
|
---|
| 757 | /* we either have a fixed SDL resolution or we take the guest's */
|
---|
[143] | 758 | if (mFixedSDLWidth != ~(uint32_t)0)
|
---|
[1] | 759 | {
|
---|
| 760 | newWidth = mFixedSDLWidth;
|
---|
| 761 | newHeight = mFixedSDLHeight;
|
---|
| 762 | }
|
---|
| 763 | else
|
---|
| 764 | {
|
---|
| 765 | newWidth = RT_MIN(mGuestXRes, mMaxScreenWidth);
|
---|
| 766 | newHeight = RT_MIN(mGuestYRes, mMaxScreenHeight);
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | /* we don't have any extra space by default */
|
---|
| 770 | mTopOffset = 0;
|
---|
| 771 |
|
---|
[20433] | 772 | int sdlWindowFlags = SDL_WINDOW_SHOWN;
|
---|
| 773 | if (mfResizable)
|
---|
| 774 | sdlWindowFlags |= SDL_WINDOW_RESIZABLE;
|
---|
[81537] | 775 | if (!mpWindow)
|
---|
[20433] | 776 | {
|
---|
| 777 | SDL_DisplayMode desktop_mode;
|
---|
| 778 | int x = 40 + mScreenId * 20;
|
---|
| 779 | int y = 40 + mScreenId * 15;
|
---|
| 780 |
|
---|
[81537] | 781 | SDL_GetDesktopDisplayMode(mScreenId, &desktop_mode);
|
---|
[20433] | 782 | /* create new window */
|
---|
[21369] | 783 |
|
---|
[20433] | 784 | char szTitle[64];
|
---|
| 785 | RTStrPrintf(szTitle, sizeof(szTitle), "SDL window %d", mScreenId);
|
---|
[81537] | 786 | mpWindow = SDL_CreateWindow(szTitle, x, y,
|
---|
[20433] | 787 | newWidth, newHeight, sdlWindowFlags);
|
---|
[81537] | 788 | mpRenderer = SDL_CreateRenderer(mpWindow, -1, 0 /* SDL_RendererFlags */);
|
---|
| 789 | if (mpRenderer)
|
---|
| 790 | {
|
---|
| 791 | SDL_GetRendererInfo(mpRenderer, &mRenderInfo);
|
---|
| 792 |
|
---|
| 793 | mpTexture = SDL_CreateTexture(mpRenderer, desktop_mode.format,
|
---|
| 794 | SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight);
|
---|
| 795 | if (!mpTexture)
|
---|
| 796 | AssertReleaseFailed();
|
---|
| 797 | }
|
---|
| 798 | else
|
---|
[20433] | 799 | AssertReleaseFailed();
|
---|
| 800 |
|
---|
[81537] | 801 | if (12320 == g_cbIco64x01)
|
---|
| 802 | {
|
---|
| 803 | gWMIcon = SDL_CreateRGBSurface(0 /* Flags, must be 0 */, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0);
|
---|
| 804 | /** @todo make it as simple as possible. No PNM interpreter here... */
|
---|
| 805 | if (gWMIcon)
|
---|
| 806 | {
|
---|
| 807 | memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32);
|
---|
| 808 | SDL_SetWindowIcon(mpWindow, gWMIcon);
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
[20433] | 811 | }
|
---|
| 812 | else
|
---|
| 813 | {
|
---|
| 814 | int w, h;
|
---|
| 815 | uint32_t format;
|
---|
| 816 | int access;
|
---|
| 817 |
|
---|
| 818 | /* resize current window */
|
---|
[81537] | 819 | SDL_GetWindowSize(mpWindow, &w, &h);
|
---|
[20433] | 820 |
|
---|
| 821 | if (w != (int)newWidth || h != (int)newHeight)
|
---|
[81537] | 822 | SDL_SetWindowSize(mpWindow, newWidth, newHeight);
|
---|
[20433] | 823 |
|
---|
[81537] | 824 | SDL_QueryTexture(mpTexture, &format, &access, &w, &h);
|
---|
| 825 | SDL_DestroyTexture(mpTexture);
|
---|
| 826 | mpTexture = SDL_CreateTexture(mpRenderer, format, access, newWidth, newHeight);
|
---|
| 827 | if (!mpTexture)
|
---|
[20433] | 828 | AssertReleaseFailed();
|
---|
| 829 | }
|
---|
[1] | 830 | }
|
---|
| 831 |
|
---|
| 832 | /**
|
---|
| 833 | * Update specified framebuffer area. The coordinates can either be
|
---|
| 834 | * relative to the guest framebuffer or relative to the screen.
|
---|
| 835 | *
|
---|
| 836 | * @remarks Must be called from the SDL thread on Linux!
|
---|
| 837 | * @param x left column
|
---|
| 838 | * @param y top row
|
---|
| 839 | * @param w width in pixels
|
---|
| 840 | * @param h height in pixels
|
---|
| 841 | * @param fGuestRelative flag whether the above values are guest relative or screen relative;
|
---|
| 842 | */
|
---|
| 843 | void VBoxSDLFB::update(int x, int y, int w, int h, bool fGuestRelative)
|
---|
| 844 | {
|
---|
[99494] | 845 | #if defined(VBOXSDL_WITH_X11) || defined(RT_OS_DARWIN)
|
---|
[20433] | 846 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 847 | #endif
|
---|
[51436] | 848 | RTCritSectEnter(&mUpdateLock);
|
---|
[99090] | 849 | Log3Func(("mfUpdates=%RTbool %d,%d %dx%d\n", mfUpdates, x, y, w, h));
|
---|
[51436] | 850 | if (!mfUpdates)
|
---|
| 851 | {
|
---|
| 852 | RTCritSectLeave(&mUpdateLock);
|
---|
| 853 | return;
|
---|
| 854 | }
|
---|
[51634] | 855 |
|
---|
| 856 | Assert(mSurfVRAM);
|
---|
[98290] | 857 | if (!mSurfVRAM)
|
---|
[51634] | 858 | {
|
---|
| 859 | RTCritSectLeave(&mUpdateLock);
|
---|
| 860 | return;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[99090] | 863 | /* this is how many pixels we have to cut off from the height for this specific blit */
|
---|
| 864 | int const yCutoffGuest = 0;
|
---|
[1] | 865 |
|
---|
| 866 | /**
|
---|
| 867 | * If we get a SDL window relative update, we
|
---|
| 868 | * just perform a full screen update to keep things simple.
|
---|
| 869 | *
|
---|
| 870 | * @todo improve
|
---|
| 871 | */
|
---|
| 872 | if (!fGuestRelative)
|
---|
| 873 | {
|
---|
| 874 | x = 0;
|
---|
| 875 | w = mGuestXRes;
|
---|
| 876 | y = 0;
|
---|
| 877 | h = mGuestYRes;
|
---|
| 878 | }
|
---|
| 879 |
|
---|
[99090] | 880 | SDL_Rect srcRect;
|
---|
[1] | 881 | srcRect.x = x;
|
---|
| 882 | srcRect.y = y + yCutoffGuest;
|
---|
| 883 | srcRect.w = w;
|
---|
| 884 | srcRect.h = RT_MAX(0, h - yCutoffGuest);
|
---|
| 885 |
|
---|
| 886 | /*
|
---|
| 887 | * Destination rectangle is just offset by the label height.
|
---|
| 888 | * There are two cases though: label height is added to the
|
---|
| 889 | * guest resolution (mTopOffset == mLabelHeight; yCutoffGuest == 0)
|
---|
| 890 | * or the label cuts off a portion of the guest screen (mTopOffset == 0;
|
---|
| 891 | * yCutoffGuest >= 0)
|
---|
| 892 | */
|
---|
[99090] | 893 | SDL_Rect dstRect;
|
---|
[1] | 894 | dstRect.x = x + mCenterXOffset;
|
---|
| 895 | dstRect.y = y + yCutoffGuest + mTopOffset + mCenterYOffset;
|
---|
| 896 | dstRect.w = w;
|
---|
| 897 | dstRect.h = RT_MAX(0, h - yCutoffGuest);
|
---|
| 898 |
|
---|
[99090] | 899 | /* Calculate the offset within the VRAM to update the streaming texture directly. */
|
---|
| 900 | uint8_t const *pbOff = (uint8_t *)mSurfVRAM->pixels
|
---|
| 901 | + (srcRect.y * mBytesPerLine) + (srcRect.x * (mBitsPerPixel / 8));
|
---|
| 902 | SDL_UpdateTexture(mpTexture, &srcRect, pbOff, mSurfVRAM->pitch);
|
---|
| 903 | SDL_RenderCopy(mpRenderer, mpTexture, NULL, NULL);
|
---|
| 904 |
|
---|
| 905 | RTCritSectLeave(&mUpdateLock);
|
---|
| 906 |
|
---|
[81537] | 907 | SDL_RenderPresent(mpRenderer);
|
---|
[1] | 908 | }
|
---|
| 909 |
|
---|
| 910 | /**
|
---|
| 911 | * Repaint the whole framebuffer
|
---|
| 912 | *
|
---|
| 913 | * @remarks Must be called from the SDL thread!
|
---|
| 914 | */
|
---|
| 915 | void VBoxSDLFB::repaint()
|
---|
| 916 | {
|
---|
[20433] | 917 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 918 | LogFlow(("VBoxSDLFB::repaint\n"));
|
---|
[98290] | 919 | int w, h;
|
---|
| 920 | uint32_t format;
|
---|
| 921 | int access;
|
---|
| 922 | SDL_QueryTexture(mpTexture, &format, &access, &w, &h);
|
---|
| 923 | update(0, 0, w, h, false /* fGuestRelative */);
|
---|
[1] | 924 | }
|
---|
| 925 |
|
---|
| 926 | /**
|
---|
| 927 | * Toggle fullscreen mode
|
---|
| 928 | *
|
---|
| 929 | * @remarks Must be called from the SDL thread!
|
---|
| 930 | */
|
---|
| 931 | void VBoxSDLFB::setFullscreen(bool fFullscreen)
|
---|
| 932 | {
|
---|
[20433] | 933 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 934 | LogFlow(("VBoxSDLFB::SetFullscreen: fullscreen: %d\n", fFullscreen));
|
---|
| 935 | mfFullscreen = fFullscreen;
|
---|
| 936 | /* only change the SDL resolution, do not touch the guest framebuffer */
|
---|
| 937 | resizeSDL();
|
---|
[51547] | 938 | repaint();
|
---|
[1] | 939 | }
|
---|
| 940 |
|
---|
[10675] | 941 | /**
|
---|
[11400] | 942 | * Return the geometry of the host. This isn't very well tested but it seems
|
---|
| 943 | * to work at least on Linux hosts.
|
---|
[10675] | 944 | */
|
---|
[11400] | 945 | void VBoxSDLFB::getFullscreenGeometry(uint32_t *width, uint32_t *height)
|
---|
[10675] | 946 | {
|
---|
[81537] | 947 | SDL_DisplayMode dm;
|
---|
| 948 | int rc = SDL_GetDesktopDisplayMode(0, &dm); /** @BUGBUG Handle multi monitor setups! */
|
---|
| 949 | if (rc == 0)
|
---|
| 950 | {
|
---|
| 951 | *width = dm.w;
|
---|
| 952 | *height = dm.w;
|
---|
| 953 | }
|
---|
[10675] | 954 | }
|
---|
| 955 |
|
---|
[81537] | 956 | int VBoxSDLFB::setWindowTitle(const char *pcszTitle)
|
---|
| 957 | {
|
---|
| 958 | SDL_SetWindowTitle(mpWindow, pcszTitle);
|
---|
| 959 |
|
---|
| 960 | return VINF_SUCCESS;
|
---|
| 961 | }
|
---|