[1] | 1 | /** @file
|
---|
| 2 | *
|
---|
| 3 | * VBox frontends: VBoxSDL (simple frontend based on SDL):
|
---|
| 4 | * Implementation of VBoxSDLFB (SDL framebuffer) class
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[34513] | 8 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
[1] | 9 | *
|
---|
| 10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 13 | * General Public License (GPL) as published by the Free Software
|
---|
| 14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[1] | 17 | */
|
---|
| 18 |
|
---|
| 19 | #include <VBox/com/com.h>
|
---|
| 20 | #include <VBox/com/string.h>
|
---|
| 21 | #include <VBox/com/Guid.h>
|
---|
| 22 | #include <VBox/com/ErrorInfo.h>
|
---|
| 23 | #include <VBox/com/EventQueue.h>
|
---|
| 24 | #include <VBox/com/VirtualBox.h>
|
---|
[3402] | 25 |
|
---|
[1] | 26 | #include <iprt/stream.h>
|
---|
[5107] | 27 | #include <iprt/env.h>
|
---|
[1] | 28 |
|
---|
[3669] | 29 | #ifdef RT_OS_OS2
|
---|
[3402] | 30 | # undef RT_MAX
|
---|
| 31 | // from <iprt/cdefs.h>
|
---|
| 32 | # define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[1] | 35 | using namespace com;
|
---|
| 36 |
|
---|
| 37 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
| 38 | #include <VBox/err.h>
|
---|
| 39 | #include <VBox/log.h>
|
---|
| 40 |
|
---|
| 41 | #include "VBoxSDL.h"
|
---|
| 42 | #include "Framebuffer.h"
|
---|
| 43 | #include "Ico64x01.h"
|
---|
| 44 |
|
---|
[21029] | 45 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX)
|
---|
| 46 | #include <SDL_syswm.h> /* for SDL_GetWMInfo() */
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
[614] | 49 | #if defined(VBOX_WITH_XPCOM)
|
---|
[22911] | 50 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxSDLFB, IFramebuffer)
|
---|
[1] | 51 | NS_DECL_CLASSINFO(VBoxSDLFB)
|
---|
[22911] | 52 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxSDLFBOverlay, IFramebufferOverlay)
|
---|
[1] | 53 | NS_DECL_CLASSINFO(VBoxSDLFBOverlay)
|
---|
| 54 | #endif
|
---|
| 55 |
|
---|
| 56 | #ifdef VBOX_SECURELABEL
|
---|
| 57 | /* function pointers */
|
---|
| 58 | extern "C"
|
---|
| 59 | {
|
---|
| 60 | DECLSPEC int (SDLCALL *pTTF_Init)(void);
|
---|
| 61 | DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
|
---|
| 62 | DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
[8144] | 63 | DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
[1] | 64 | DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
|
---|
| 65 | DECLSPEC void (SDLCALL *pTTF_Quit)(void);
|
---|
| 66 | }
|
---|
| 67 | #endif /* VBOX_SECURELABEL */
|
---|
| 68 |
|
---|
[34513] | 69 | static bool gfSdlInitialized = false; /**< if SDL was initialized */
|
---|
| 70 | static SDL_Surface *gWMIcon = NULL; /**< the application icon */
|
---|
| 71 | static RTNATIVETHREAD gSdlNativeThread = NIL_RTNATIVETHREAD; /**< the SDL thread */
|
---|
[20433] | 72 |
|
---|
[1] | 73 | //
|
---|
| 74 | // Constructor / destructor
|
---|
| 75 | //
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * SDL framebuffer constructor. It is called from the main
|
---|
| 79 | * (i.e. SDL) thread. Therefore it is safe to use SDL calls
|
---|
| 80 | * here.
|
---|
| 81 | * @param fFullscreen flag whether we start in fullscreen mode
|
---|
| 82 | * @param fResizable flag whether the SDL window should be resizable
|
---|
| 83 | * @param fShowSDLConfig flag whether we print out SDL settings
|
---|
[10675] | 84 | * @param fKeepHostRes flag whether we switch the host screen resolution
|
---|
| 85 | * when switching to fullscreen or not
|
---|
| 86 | * @param iFixedWidth fixed SDL width (-1 means not set)
|
---|
| 87 | * @param iFixedHeight fixed SDL height (-1 means not set)
|
---|
[1] | 88 | */
|
---|
[20433] | 89 | VBoxSDLFB::VBoxSDLFB(uint32_t uScreenId,
|
---|
| 90 | bool fFullscreen, bool fResizable, bool fShowSDLConfig,
|
---|
[10675] | 91 | bool fKeepHostRes, uint32_t u32FixedWidth,
|
---|
| 92 | uint32_t u32FixedHeight, uint32_t u32FixedBPP)
|
---|
[1] | 93 | {
|
---|
| 94 | int rc;
|
---|
| 95 | LogFlow(("VBoxSDLFB::VBoxSDLFB\n"));
|
---|
| 96 |
|
---|
[3669] | 97 | #if defined (RT_OS_WINDOWS)
|
---|
[1] | 98 | refcnt = 0;
|
---|
| 99 | #endif
|
---|
| 100 |
|
---|
[20433] | 101 | mScreenId = uScreenId;
|
---|
[1] | 102 | mScreen = NULL;
|
---|
[20433] | 103 | #ifdef VBOX_WITH_SDL13
|
---|
| 104 | mWindow = 0;
|
---|
| 105 | mTexture = 0;
|
---|
| 106 | #endif
|
---|
[1] | 107 | mSurfVRAM = NULL;
|
---|
| 108 | mfInitialized = false;
|
---|
| 109 | mfFullscreen = fFullscreen;
|
---|
[10675] | 110 | mfKeepHostRes = fKeepHostRes;
|
---|
[1] | 111 | mTopOffset = 0;
|
---|
| 112 | mfResizable = fResizable;
|
---|
| 113 | mfShowSDLConfig = fShowSDLConfig;
|
---|
[143] | 114 | mFixedSDLWidth = u32FixedWidth;
|
---|
| 115 | mFixedSDLHeight = u32FixedHeight;
|
---|
| 116 | mFixedSDLBPP = u32FixedBPP;
|
---|
[1] | 117 | mCenterXOffset = 0;
|
---|
| 118 | mCenterYOffset = 0;
|
---|
| 119 | /* Start with standard screen dimensions. */
|
---|
| 120 | mGuestXRes = 640;
|
---|
| 121 | mGuestYRes = 480;
|
---|
[7207] | 122 | mPixelFormat = FramebufferPixelFormat_Opaque;
|
---|
[3761] | 123 | mUsesGuestVRAM = FALSE;
|
---|
[1] | 124 | mPtrVRAM = NULL;
|
---|
[3761] | 125 | mBitsPerPixel = 0;
|
---|
| 126 | mBytesPerLine = 0;
|
---|
[15868] | 127 | mfSameSizeRequested = false;
|
---|
[1] | 128 | #ifdef VBOX_SECURELABEL
|
---|
| 129 | mLabelFont = NULL;
|
---|
| 130 | mLabelHeight = 0;
|
---|
[8154] | 131 | mLabelOffs = 0;
|
---|
[1] | 132 | #endif
|
---|
| 133 |
|
---|
| 134 | rc = RTCritSectInit(&mUpdateLock);
|
---|
| 135 | AssertMsg(rc == VINF_SUCCESS, ("Error from RTCritSectInit!\n"));
|
---|
| 136 |
|
---|
[20433] | 137 | resizeGuest();
|
---|
| 138 | Assert(mScreen);
|
---|
| 139 | mfInitialized = true;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | VBoxSDLFB::~VBoxSDLFB()
|
---|
| 143 | {
|
---|
| 144 | LogFlow(("VBoxSDLFB::~VBoxSDLFB\n"));
|
---|
| 145 | if (mSurfVRAM)
|
---|
| 146 | {
|
---|
| 147 | SDL_FreeSurface(mSurfVRAM);
|
---|
| 148 | mSurfVRAM = NULL;
|
---|
| 149 | }
|
---|
| 150 | mScreen = NULL;
|
---|
| 151 |
|
---|
| 152 | #ifdef VBOX_SECURELABEL
|
---|
| 153 | if (mLabelFont)
|
---|
| 154 | pTTF_CloseFont(mLabelFont);
|
---|
| 155 | if (pTTF_Quit)
|
---|
| 156 | pTTF_Quit();
|
---|
| 157 | #endif
|
---|
| 158 |
|
---|
| 159 | RTCritSectDelete(&mUpdateLock);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[23170] | 162 | bool VBoxSDLFB::init(bool fShowSDLConfig)
|
---|
[20433] | 163 | {
|
---|
| 164 | LogFlow(("VBoxSDLFB::init\n"));
|
---|
| 165 |
|
---|
| 166 | /* memorize the thread that inited us, that's the SDL thread */
|
---|
| 167 | gSdlNativeThread = RTThreadNativeSelf();
|
---|
| 168 |
|
---|
[3669] | 169 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 170 | /* default to DirectX if nothing else set */
|
---|
[5107] | 171 | if (!RTEnvGet("SDL_VIDEODRIVER"))
|
---|
[1] | 172 | {
|
---|
| 173 | _putenv("SDL_VIDEODRIVER=directx");
|
---|
| 174 | // _putenv("SDL_VIDEODRIVER=windib");
|
---|
| 175 | }
|
---|
| 176 | #endif
|
---|
[4637] | 177 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 178 | /* On some X servers the mouse is stuck inside the bottom right corner.
|
---|
| 179 | * See http://wiki.clug.org.za/wiki/QEMU_mouse_not_working */
|
---|
[11419] | 180 | RTEnvSet("SDL_VIDEO_X11_DGAMOUSE", "0");
|
---|
[1] | 181 | #endif
|
---|
[20433] | 182 | int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
|
---|
[1] | 183 | if (rc != 0)
|
---|
| 184 | {
|
---|
| 185 | RTPrintf("SDL Error: '%s'\n", SDL_GetError());
|
---|
[23170] | 186 | return false;
|
---|
[1] | 187 | }
|
---|
[34513] | 188 | gfSdlInitialized = true;
|
---|
[1] | 189 |
|
---|
[523] | 190 | const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
---|
| 191 | Assert(videoInfo);
|
---|
| 192 | if (videoInfo)
|
---|
[1] | 193 | {
|
---|
| 194 | /* output what SDL is capable of */
|
---|
[20433] | 195 | if (fShowSDLConfig)
|
---|
[1] | 196 | RTPrintf("SDL capabilities:\n"
|
---|
| 197 | " Hardware surface support: %s\n"
|
---|
| 198 | " Window manager available: %s\n"
|
---|
| 199 | " Screen to screen blits accelerated: %s\n"
|
---|
| 200 | " Screen to screen colorkey blits accelerated: %s\n"
|
---|
| 201 | " Screen to screen alpha blits accelerated: %s\n"
|
---|
| 202 | " Memory to screen blits accelerated: %s\n"
|
---|
| 203 | " Memory to screen colorkey blits accelerated: %s\n"
|
---|
| 204 | " Memory to screen alpha blits accelerated: %s\n"
|
---|
| 205 | " Color fills accelerated: %s\n"
|
---|
| 206 | " Video memory in kilobytes: %d\n"
|
---|
| 207 | " Optimal bpp mode: %d\n"
|
---|
| 208 | "SDL video driver: %s\n",
|
---|
| 209 | videoInfo->hw_available ? "yes" : "no",
|
---|
| 210 | videoInfo->wm_available ? "yes" : "no",
|
---|
| 211 | videoInfo->blit_hw ? "yes" : "no",
|
---|
| 212 | videoInfo->blit_hw_CC ? "yes" : "no",
|
---|
| 213 | videoInfo->blit_hw_A ? "yes" : "no",
|
---|
| 214 | videoInfo->blit_sw ? "yes" : "no",
|
---|
| 215 | videoInfo->blit_sw_CC ? "yes" : "no",
|
---|
| 216 | videoInfo->blit_sw_A ? "yes" : "no",
|
---|
| 217 | videoInfo->blit_fill ? "yes" : "no",
|
---|
| 218 | videoInfo->video_mem,
|
---|
| 219 | videoInfo->vfmt->BitsPerPixel,
|
---|
[5107] | 220 | RTEnvGet("SDL_VIDEODRIVER"));
|
---|
[1] | 221 | }
|
---|
| 222 |
|
---|
| 223 | if (12320 == g_cbIco64x01)
|
---|
| 224 | {
|
---|
[20433] | 225 | gWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0);
|
---|
[1] | 226 | /** @todo make it as simple as possible. No PNM interpreter here... */
|
---|
[20433] | 227 | if (gWMIcon)
|
---|
[1] | 228 | {
|
---|
[20433] | 229 | memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32);
|
---|
| 230 | SDL_WM_SetIcon(gWMIcon, NULL);
|
---|
[1] | 231 | }
|
---|
| 232 | }
|
---|
[23170] | 233 |
|
---|
| 234 | return true;
|
---|
[1] | 235 | }
|
---|
| 236 |
|
---|
[20433] | 237 | /**
|
---|
| 238 | * Terminate SDL
|
---|
| 239 | *
|
---|
| 240 | * @remarks must be called from the SDL thread!
|
---|
| 241 | */
|
---|
| 242 | void VBoxSDLFB::uninit()
|
---|
[1] | 243 | {
|
---|
[34513] | 244 | if (gfSdlInitialized)
|
---|
[20433] | 245 | {
|
---|
[34513] | 246 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
| 247 | SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
---|
| 248 | if (gWMIcon)
|
---|
| 249 | {
|
---|
| 250 | SDL_FreeSurface(gWMIcon);
|
---|
| 251 | gWMIcon = NULL;
|
---|
| 252 | }
|
---|
[20433] | 253 | }
|
---|
[1] | 254 | }
|
---|
| 255 |
|
---|
| 256 | /**
|
---|
| 257 | * Returns the current framebuffer width in pixels.
|
---|
| 258 | *
|
---|
| 259 | * @returns COM status code
|
---|
| 260 | * @param width Address of result buffer.
|
---|
| 261 | */
|
---|
| 262 | STDMETHODIMP VBoxSDLFB::COMGETTER(Width)(ULONG *width)
|
---|
| 263 | {
|
---|
| 264 | LogFlow(("VBoxSDLFB::GetWidth\n"));
|
---|
| 265 | if (!width)
|
---|
| 266 | return E_INVALIDARG;
|
---|
| 267 | *width = mGuestXRes;
|
---|
| 268 | return S_OK;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /**
|
---|
| 272 | * Returns the current framebuffer height in pixels.
|
---|
| 273 | *
|
---|
| 274 | * @returns COM status code
|
---|
| 275 | * @param height Address of result buffer.
|
---|
| 276 | */
|
---|
| 277 | STDMETHODIMP VBoxSDLFB::COMGETTER(Height)(ULONG *height)
|
---|
| 278 | {
|
---|
| 279 | LogFlow(("VBoxSDLFB::GetHeight\n"));
|
---|
| 280 | if (!height)
|
---|
| 281 | return E_INVALIDARG;
|
---|
| 282 | *height = mGuestYRes;
|
---|
| 283 | return S_OK;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | /**
|
---|
| 287 | * Lock the framebuffer (make its address immutable).
|
---|
| 288 | *
|
---|
| 289 | * @returns COM status code
|
---|
| 290 | */
|
---|
| 291 | STDMETHODIMP VBoxSDLFB::Lock()
|
---|
| 292 | {
|
---|
| 293 | LogFlow(("VBoxSDLFB::Lock\n"));
|
---|
| 294 | RTCritSectEnter(&mUpdateLock);
|
---|
| 295 | return S_OK;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | /**
|
---|
| 299 | * Unlock the framebuffer.
|
---|
| 300 | *
|
---|
| 301 | * @returns COM status code
|
---|
| 302 | */
|
---|
| 303 | STDMETHODIMP VBoxSDLFB::Unlock()
|
---|
| 304 | {
|
---|
| 305 | LogFlow(("VBoxSDLFB::Unlock\n"));
|
---|
| 306 | RTCritSectLeave(&mUpdateLock);
|
---|
| 307 | return S_OK;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /**
|
---|
| 311 | * Return the framebuffer start address.
|
---|
| 312 | *
|
---|
| 313 | * @returns COM status code.
|
---|
| 314 | * @param address Pointer to result variable.
|
---|
| 315 | */
|
---|
[470] | 316 | STDMETHODIMP VBoxSDLFB::COMGETTER(Address)(BYTE **address)
|
---|
[1] | 317 | {
|
---|
| 318 | LogFlow(("VBoxSDLFB::GetAddress\n"));
|
---|
| 319 | if (!address)
|
---|
| 320 | return E_INVALIDARG;
|
---|
| 321 |
|
---|
[20433] | 322 | if (!mSurfVRAM)
|
---|
[1] | 323 | {
|
---|
| 324 | /* That's actually rather bad. */
|
---|
| 325 | AssertMsgFailed(("mSurfVRAM is NULL!\n"));
|
---|
| 326 | return E_FAIL;
|
---|
| 327 | }
|
---|
[20433] | 328 |
|
---|
| 329 | *address = (BYTE *) mSurfVRAM->pixels;
|
---|
[1] | 330 | LogFlow(("VBoxSDL::GetAddress returning %p\n", *address));
|
---|
| 331 | return S_OK;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | /**
|
---|
| 335 | * Return the current framebuffer color depth.
|
---|
| 336 | *
|
---|
| 337 | * @returns COM status code
|
---|
[3761] | 338 | * @param bitsPerPixel Address of result variable
|
---|
[1] | 339 | */
|
---|
[3761] | 340 | STDMETHODIMP VBoxSDLFB::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
|
---|
[1] | 341 | {
|
---|
[3761] | 342 | LogFlow(("VBoxSDLFB::GetBitsPerPixel\n"));
|
---|
| 343 | if (!bitsPerPixel)
|
---|
[1] | 344 | return E_INVALIDARG;
|
---|
| 345 | /* get the information directly from the surface in use */
|
---|
| 346 | Assert(mSurfVRAM);
|
---|
[3761] | 347 | *bitsPerPixel = (ULONG)(mSurfVRAM ? mSurfVRAM->format->BitsPerPixel : 0);
|
---|
[1] | 348 | return S_OK;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /**
|
---|
| 352 | * Return the current framebuffer line size in bytes.
|
---|
| 353 | *
|
---|
| 354 | * @returns COM status code.
|
---|
| 355 | * @param lineSize Address of result variable.
|
---|
| 356 | */
|
---|
[3761] | 357 | STDMETHODIMP VBoxSDLFB::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
|
---|
[1] | 358 | {
|
---|
[3761] | 359 | LogFlow(("VBoxSDLFB::GetBytesPerLine\n"));
|
---|
| 360 | if (!bytesPerLine)
|
---|
[1] | 361 | return E_INVALIDARG;
|
---|
| 362 | /* get the information directly from the surface */
|
---|
| 363 | Assert(mSurfVRAM);
|
---|
[3761] | 364 | *bytesPerLine = (ULONG)(mSurfVRAM ? mSurfVRAM->pitch : 0);
|
---|
[1] | 365 | return S_OK;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[3761] | 368 | STDMETHODIMP VBoxSDLFB::COMGETTER(PixelFormat) (ULONG *pixelFormat)
|
---|
[1] | 369 | {
|
---|
| 370 | if (!pixelFormat)
|
---|
| 371 | return E_POINTER;
|
---|
| 372 | *pixelFormat = mPixelFormat;
|
---|
| 373 | return S_OK;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[3761] | 376 | STDMETHODIMP VBoxSDLFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM)
|
---|
| 377 | {
|
---|
| 378 | if (!usesGuestVRAM)
|
---|
| 379 | return E_POINTER;
|
---|
| 380 | *usesGuestVRAM = mUsesGuestVRAM;
|
---|
| 381 | return S_OK;
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[1] | 384 | /**
|
---|
| 385 | * Returns by how many pixels the guest should shrink its
|
---|
| 386 | * video mode height values.
|
---|
| 387 | *
|
---|
| 388 | * @returns COM status code.
|
---|
| 389 | * @param heightReduction Address of result variable.
|
---|
| 390 | */
|
---|
| 391 | STDMETHODIMP VBoxSDLFB::COMGETTER(HeightReduction)(ULONG *heightReduction)
|
---|
| 392 | {
|
---|
| 393 | if (!heightReduction)
|
---|
| 394 | return E_POINTER;
|
---|
| 395 | #ifdef VBOX_SECURELABEL
|
---|
| 396 | *heightReduction = mLabelHeight;
|
---|
| 397 | #else
|
---|
| 398 | *heightReduction = 0;
|
---|
| 399 | #endif
|
---|
| 400 | return S_OK;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | /**
|
---|
| 404 | * Returns a pointer to an alpha-blended overlay used for displaying status
|
---|
| 405 | * icons above the framebuffer.
|
---|
| 406 | *
|
---|
| 407 | * @returns COM status code.
|
---|
| 408 | * @param aOverlay The overlay framebuffer.
|
---|
| 409 | */
|
---|
| 410 | STDMETHODIMP VBoxSDLFB::COMGETTER(Overlay)(IFramebufferOverlay **aOverlay)
|
---|
| 411 | {
|
---|
| 412 | if (!aOverlay)
|
---|
| 413 | return E_POINTER;
|
---|
| 414 | /* Not yet implemented */
|
---|
| 415 | *aOverlay = 0;
|
---|
| 416 | return S_OK;
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | /**
|
---|
[12449] | 420 | * Returns handle of window where framebuffer context is being drawn
|
---|
| 421 | *
|
---|
| 422 | * @returns COM status code.
|
---|
| 423 | * @param winId Handle of associated window.
|
---|
| 424 | */
|
---|
[31698] | 425 | STDMETHODIMP VBoxSDLFB::COMGETTER(WinId)(int64_t *winId)
|
---|
[12449] | 426 | {
|
---|
| 427 | if (!winId)
|
---|
| 428 | return E_POINTER;
|
---|
| 429 | *winId = mWinId;
|
---|
| 430 | return S_OK;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | /**
|
---|
[1] | 434 | * Notify framebuffer of an update.
|
---|
| 435 | *
|
---|
| 436 | * @returns COM status code
|
---|
| 437 | * @param x Update region upper left corner x value.
|
---|
| 438 | * @param y Update region upper left corner y value.
|
---|
| 439 | * @param w Update region width in pixels.
|
---|
| 440 | * @param h Update region height in pixels.
|
---|
| 441 | * @param finished Address of output flag whether the update
|
---|
| 442 | * could be fully processed in this call (which
|
---|
| 443 | * has to return immediately) or VBox should wait
|
---|
| 444 | * for a call to the update complete API before
|
---|
| 445 | * continuing with display updates.
|
---|
| 446 | */
|
---|
| 447 | STDMETHODIMP VBoxSDLFB::NotifyUpdate(ULONG x, ULONG y,
|
---|
[19817] | 448 | ULONG w, ULONG h)
|
---|
[1] | 449 | {
|
---|
| 450 | /*
|
---|
| 451 | * The input values are in guest screen coordinates.
|
---|
| 452 | */
|
---|
| 453 | LogFlow(("VBoxSDLFB::NotifyUpdate: x = %d, y = %d, w = %d, h = %d\n",
|
---|
| 454 | x, y, w, h));
|
---|
| 455 |
|
---|
[4637] | 456 | #ifdef VBOXSDL_WITH_X11
|
---|
[1] | 457 | /*
|
---|
[3289] | 458 | * SDL does not allow us to make this call from any other thread than
|
---|
| 459 | * the main SDL thread (which initialized the video mode). So we have
|
---|
| 460 | * to send an event to the main SDL thread and process it there. For
|
---|
| 461 | * sake of simplicity, we encode all information in the event parameters.
|
---|
[1] | 462 | */
|
---|
| 463 | SDL_Event event;
|
---|
| 464 | event.type = SDL_USEREVENT;
|
---|
[20433] | 465 | event.user.code = mScreenId;
|
---|
[1] | 466 | event.user.type = SDL_USER_EVENT_UPDATERECT;
|
---|
| 467 | // 16 bit is enough for coordinates
|
---|
| 468 | event.user.data1 = (void*)(x << 16 | y);
|
---|
| 469 | event.user.data2 = (void*)(w << 16 | h);
|
---|
[3289] | 470 | PushNotifyUpdateEvent(&event);
|
---|
[4637] | 471 | #else /* !VBOXSDL_WITH_X11 */
|
---|
[1] | 472 | update(x, y, w, h, true /* fGuestRelative */);
|
---|
[4637] | 473 | #endif /* !VBOXSDL_WITH_X11 */
|
---|
[1] | 474 |
|
---|
| 475 | return S_OK;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | /**
|
---|
| 479 | * Request a display resize from the framebuffer.
|
---|
| 480 | *
|
---|
| 481 | * @returns COM status code.
|
---|
| 482 | * @param pixelFormat The requested pixel format.
|
---|
| 483 | * @param vram Pointer to the guest VRAM buffer (can be NULL).
|
---|
[3761] | 484 | * @param bitsPerPixel Color depth in bits.
|
---|
| 485 | * @param bytesPerLine Size of a scanline in bytes.
|
---|
[1] | 486 | * @param w New display width in pixels.
|
---|
| 487 | * @param h New display height in pixels.
|
---|
| 488 | * @param finished Address of output flag whether the update
|
---|
| 489 | * could be fully processed in this call (which
|
---|
| 490 | * has to return immediately) or VBox should wait
|
---|
| 491 | * for all call to the resize complete API before
|
---|
| 492 | * continuing with display updates.
|
---|
| 493 | */
|
---|
[3761] | 494 | STDMETHODIMP VBoxSDLFB::RequestResize(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
|
---|
| 495 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
| 496 | ULONG w, ULONG h, BOOL *finished)
|
---|
[1] | 497 | {
|
---|
[3761] | 498 | LogFlowFunc (("w=%d, h=%d, pixelFormat=0x%08lX, vram=%p, "
|
---|
| 499 | "bpp=%d, bpl=%d\n",
|
---|
| 500 | w, h, pixelFormat, vram, bitsPerPixel, bytesPerLine));
|
---|
[1] | 501 |
|
---|
| 502 | /*
|
---|
[3289] | 503 | * SDL does not allow us to make this call from any other thread than
|
---|
| 504 | * the main thread (the one which initialized the video mode). So we
|
---|
| 505 | * have to send an event to the main SDL thread and tell VBox to wait.
|
---|
[1] | 506 | */
|
---|
| 507 | if (!finished)
|
---|
| 508 | {
|
---|
| 509 | AssertMsgFailed(("RequestResize requires the finished flag!\n"));
|
---|
| 510 | return E_FAIL;
|
---|
| 511 | }
|
---|
[3761] | 512 |
|
---|
[15868] | 513 | /*
|
---|
| 514 | * Optimize the case when the guest has changed only the VRAM ptr
|
---|
| 515 | * and the framebuffer uses the guest VRAM as the source bitmap.
|
---|
| 516 | */
|
---|
| 517 | if ( mGuestXRes == w
|
---|
| 518 | && mGuestYRes == h
|
---|
| 519 | && mPixelFormat == pixelFormat
|
---|
| 520 | && mBitsPerPixel == bitsPerPixel
|
---|
| 521 | && mBytesPerLine == bytesPerLine
|
---|
| 522 | && mUsesGuestVRAM
|
---|
| 523 | )
|
---|
| 524 | {
|
---|
| 525 | mfSameSizeRequested = true;
|
---|
| 526 | }
|
---|
| 527 | else
|
---|
| 528 | {
|
---|
| 529 | mfSameSizeRequested = false;
|
---|
| 530 | }
|
---|
| 531 |
|
---|
[3289] | 532 | mGuestXRes = w;
|
---|
| 533 | mGuestYRes = h;
|
---|
[1] | 534 | mPixelFormat = pixelFormat;
|
---|
[3289] | 535 | mPtrVRAM = vram;
|
---|
[3761] | 536 | mBitsPerPixel = bitsPerPixel;
|
---|
| 537 | mBytesPerLine = bytesPerLine;
|
---|
| 538 | mUsesGuestVRAM = FALSE; /* yet */
|
---|
[1] | 539 |
|
---|
| 540 | SDL_Event event;
|
---|
| 541 | event.type = SDL_USEREVENT;
|
---|
| 542 | event.user.type = SDL_USER_EVENT_RESIZE;
|
---|
[20433] | 543 | event.user.code = mScreenId;
|
---|
[1] | 544 |
|
---|
[3289] | 545 | /* Try multiple times if necessary */
|
---|
| 546 | PushSDLEventForSure(&event);
|
---|
| 547 |
|
---|
[1] | 548 | /* we want this request to be processed quickly, so yield the CPU */
|
---|
| 549 | RTThreadYield();
|
---|
| 550 |
|
---|
| 551 | *finished = false;
|
---|
| 552 |
|
---|
| 553 | return S_OK;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | /**
|
---|
| 557 | * Returns whether we like the given video mode.
|
---|
| 558 | *
|
---|
| 559 | * @returns COM status code
|
---|
| 560 | * @param width video mode width in pixels
|
---|
| 561 | * @param height video mode height in pixels
|
---|
| 562 | * @param bpp video mode bit depth in bits per pixel
|
---|
| 563 | * @param supported pointer to result variable
|
---|
| 564 | */
|
---|
| 565 | STDMETHODIMP VBoxSDLFB::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported)
|
---|
| 566 | {
|
---|
| 567 | if (!supported)
|
---|
| 568 | return E_POINTER;
|
---|
| 569 |
|
---|
| 570 | /* are constraints set? */
|
---|
[143] | 571 | if ( ( (mMaxScreenWidth != ~(uint32_t)0)
|
---|
[5917] | 572 | && (width > mMaxScreenWidth))
|
---|
[143] | 573 | || ( (mMaxScreenHeight != ~(uint32_t)0)
|
---|
[5917] | 574 | && (height > mMaxScreenHeight)))
|
---|
[1] | 575 | {
|
---|
| 576 | /* nope, we don't want that (but still don't freak out if it is set) */
|
---|
| 577 | #ifdef DEBUG
|
---|
| 578 | printf("VBoxSDL::VideoModeSupported: we refused mode %dx%dx%d\n", width, height, bpp);
|
---|
| 579 | #endif
|
---|
| 580 | *supported = false;
|
---|
| 581 | }
|
---|
| 582 | else
|
---|
| 583 | {
|
---|
| 584 | /* anything will do */
|
---|
| 585 | *supported = true;
|
---|
| 586 | }
|
---|
| 587 | return S_OK;
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[3576] | 590 | STDMETHODIMP VBoxSDLFB::GetVisibleRegion(BYTE *aRectangles, ULONG aCount,
|
---|
| 591 | ULONG *aCountCopied)
|
---|
[3532] | 592 | {
|
---|
[3576] | 593 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
[1] | 594 |
|
---|
[3576] | 595 | if (!rects)
|
---|
[3532] | 596 | return E_POINTER;
|
---|
| 597 |
|
---|
[3576] | 598 | /// @todo
|
---|
| 599 |
|
---|
[26509] | 600 | NOREF(aCount);
|
---|
| 601 | NOREF(aCountCopied);
|
---|
[3576] | 602 |
|
---|
[3532] | 603 | return S_OK;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[3576] | 606 | STDMETHODIMP VBoxSDLFB::SetVisibleRegion(BYTE *aRectangles, ULONG aCount)
|
---|
[3532] | 607 | {
|
---|
[3576] | 608 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
[3532] | 609 |
|
---|
[3576] | 610 | if (!rects)
|
---|
[3532] | 611 | return E_POINTER;
|
---|
| 612 |
|
---|
[3576] | 613 | /// @todo
|
---|
| 614 |
|
---|
[26509] | 615 | NOREF(aCount);
|
---|
[3576] | 616 |
|
---|
[3532] | 617 | return S_OK;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[19844] | 620 | STDMETHODIMP VBoxSDLFB::ProcessVHWACommand(BYTE *pCommand)
|
---|
| 621 | {
|
---|
| 622 | return E_NOTIMPL;
|
---|
| 623 | }
|
---|
[1] | 624 | //
|
---|
| 625 | // Internal public methods
|
---|
| 626 | //
|
---|
| 627 |
|
---|
| 628 | /**
|
---|
| 629 | * Method that does the actual resize of the guest framebuffer and
|
---|
| 630 | * then changes the SDL framebuffer setup.
|
---|
| 631 | */
|
---|
| 632 | void VBoxSDLFB::resizeGuest()
|
---|
| 633 | {
|
---|
[3761] | 634 | LogFlowFunc (("mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes));
|
---|
[20433] | 635 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(),
|
---|
[3761] | 636 | ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 637 |
|
---|
[523] | 638 | uint32_t Rmask, Gmask, Bmask, Amask = 0;
|
---|
| 639 |
|
---|
[3761] | 640 | mUsesGuestVRAM = FALSE;
|
---|
[1] | 641 |
|
---|
[3761] | 642 | /* pixel characteristics. if we don't support the format directly, we will
|
---|
| 643 | * fallback to the indirect 32bpp buffer (mUsesGuestVRAM will remain
|
---|
| 644 | * FALSE) */
|
---|
| 645 | if (mPixelFormat == FramebufferPixelFormat_FOURCC_RGB)
|
---|
[1] | 646 | {
|
---|
[3761] | 647 | switch (mBitsPerPixel)
|
---|
| 648 | {
|
---|
| 649 | case 16:
|
---|
| 650 | case 24:
|
---|
| 651 | case 32:
|
---|
| 652 | mUsesGuestVRAM = TRUE;
|
---|
| 653 | break;
|
---|
| 654 | default:
|
---|
| 655 | /* the fallback buffer is always 32bpp */
|
---|
| 656 | mBitsPerPixel = 32;
|
---|
| 657 | mBytesPerLine = mGuestXRes * 4;
|
---|
| 658 | break;
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 | else
|
---|
| 662 | {
|
---|
| 663 | /* the fallback buffer is always RGB, 32bpp */
|
---|
| 664 | mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
|
---|
| 665 | mBitsPerPixel = 32;
|
---|
| 666 | mBytesPerLine = mGuestXRes * 4;
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | switch (mBitsPerPixel)
|
---|
| 670 | {
|
---|
[524] | 671 | case 16: Rmask = 0x0000F800; Gmask = 0x000007E0; Bmask = 0x0000001F; break;
|
---|
[523] | 672 | default: Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; break;
|
---|
[1] | 673 | }
|
---|
| 674 |
|
---|
| 675 | /* first free the current surface */
|
---|
| 676 | if (mSurfVRAM)
|
---|
| 677 | {
|
---|
| 678 | SDL_FreeSurface(mSurfVRAM);
|
---|
| 679 | mSurfVRAM = NULL;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | /* is the guest in a linear framebuffer mode we support? */
|
---|
[3761] | 683 | if (mUsesGuestVRAM)
|
---|
[1] | 684 | {
|
---|
| 685 | /* Create a source surface from guest VRAM. */
|
---|
[3761] | 686 | mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, mBitsPerPixel,
|
---|
| 687 | mBytesPerLine, Rmask, Gmask, Bmask, Amask);
|
---|
[20433] | 688 | LogRel(("mSurfVRAM from guest %d x %d\n", mGuestXRes, mGuestYRes));
|
---|
[1] | 689 | }
|
---|
| 690 | else
|
---|
| 691 | {
|
---|
| 692 | /* Create a software surface for which SDL allocates the RAM */
|
---|
[3761] | 693 | mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, mBitsPerPixel,
|
---|
[1] | 694 | Rmask, Gmask, Bmask, Amask);
|
---|
[20433] | 695 | LogRel(("mSurfVRAM from SDL %d x %d\n", mGuestXRes, mGuestYRes));
|
---|
[1] | 696 | }
|
---|
| 697 | LogFlow(("VBoxSDL:: created VRAM surface %p\n", mSurfVRAM));
|
---|
| 698 |
|
---|
[15868] | 699 | if (mfSameSizeRequested && mUsesGuestVRAM)
|
---|
| 700 | {
|
---|
| 701 | /*
|
---|
| 702 | * Same size has been requested and the framebuffer still uses the guest VRAM.
|
---|
| 703 | * Reset the condition and return.
|
---|
| 704 | */
|
---|
| 705 | mfSameSizeRequested = false;
|
---|
| 706 | LogFlow(("VBoxSDL:: the same resolution requested, skipping the resize.\n"));
|
---|
| 707 | return;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
[1] | 710 | /* now adjust the SDL resolution */
|
---|
| 711 | resizeSDL();
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | /**
|
---|
| 715 | * Sets SDL video mode. This is independent from guest video
|
---|
| 716 | * mode changes.
|
---|
| 717 | *
|
---|
| 718 | * @remarks Must be called from the SDL thread!
|
---|
| 719 | */
|
---|
| 720 | void VBoxSDLFB::resizeSDL(void)
|
---|
| 721 | {
|
---|
| 722 | LogFlow(("VBoxSDL:resizeSDL\n"));
|
---|
| 723 |
|
---|
| 724 | /*
|
---|
| 725 | * We request a hardware surface from SDL so that we can perform
|
---|
| 726 | * accelerated system memory to VRAM blits. The way video handling
|
---|
| 727 | * works it that on the one hand we have the screen surface from SDL
|
---|
| 728 | * and on the other hand we have a software surface that we create
|
---|
| 729 | * using guest VRAM memory for linear modes and using SDL allocated
|
---|
| 730 | * system memory for text and non linear graphics modes. We never
|
---|
| 731 | * directly write to the screen surface but always use SDL blitting
|
---|
| 732 | * functions to blit from our system memory surface to the VRAM.
|
---|
| 733 | * Therefore, SDL can take advantage of hardware acceleration.
|
---|
| 734 | */
|
---|
| 735 | int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
|
---|
[4637] | 736 | #ifndef RT_OS_OS2 /* doesn't seem to work for some reason... */
|
---|
[1] | 737 | if (mfResizable)
|
---|
| 738 | sdlFlags |= SDL_RESIZABLE;
|
---|
[4637] | 739 | #endif
|
---|
[1] | 740 | if (mfFullscreen)
|
---|
| 741 | sdlFlags |= SDL_FULLSCREEN;
|
---|
| 742 |
|
---|
| 743 | /*
|
---|
| 744 | * Now we have to check whether there are video mode restrictions
|
---|
| 745 | */
|
---|
| 746 | SDL_Rect **modes;
|
---|
| 747 | /* Get available fullscreen/hardware modes */
|
---|
| 748 | modes = SDL_ListModes(NULL, sdlFlags);
|
---|
| 749 | Assert(modes != NULL);
|
---|
| 750 | /* -1 means that any mode is possible (usually non fullscreen) */
|
---|
| 751 | if (modes != (SDL_Rect **)-1)
|
---|
| 752 | {
|
---|
| 753 | /*
|
---|
| 754 | * according to the SDL documentation, the API guarantees that
|
---|
| 755 | * the modes are sorted from larger to smaller, so we just
|
---|
| 756 | * take the first entry as the maximum.
|
---|
| 757 | */
|
---|
| 758 | mMaxScreenWidth = modes[0]->w;
|
---|
| 759 | mMaxScreenHeight = modes[0]->h;
|
---|
| 760 | }
|
---|
| 761 | else
|
---|
| 762 | {
|
---|
| 763 | /* no restriction */
|
---|
[143] | 764 | mMaxScreenWidth = ~(uint32_t)0;
|
---|
| 765 | mMaxScreenHeight = ~(uint32_t)0;
|
---|
[1] | 766 | }
|
---|
| 767 |
|
---|
| 768 | uint32_t newWidth;
|
---|
| 769 | uint32_t newHeight;
|
---|
| 770 |
|
---|
| 771 | /* reset the centering offsets */
|
---|
| 772 | mCenterXOffset = 0;
|
---|
| 773 | mCenterYOffset = 0;
|
---|
| 774 |
|
---|
| 775 | /* we either have a fixed SDL resolution or we take the guest's */
|
---|
[143] | 776 | if (mFixedSDLWidth != ~(uint32_t)0)
|
---|
[1] | 777 | {
|
---|
| 778 | newWidth = mFixedSDLWidth;
|
---|
| 779 | newHeight = mFixedSDLHeight;
|
---|
| 780 | }
|
---|
| 781 | else
|
---|
| 782 | {
|
---|
| 783 | newWidth = RT_MIN(mGuestXRes, mMaxScreenWidth);
|
---|
| 784 | #ifdef VBOX_SECURELABEL
|
---|
| 785 | newHeight = RT_MIN(mGuestYRes + mLabelHeight, mMaxScreenHeight);
|
---|
| 786 | #else
|
---|
| 787 | newHeight = RT_MIN(mGuestYRes, mMaxScreenHeight);
|
---|
| 788 | #endif
|
---|
| 789 | }
|
---|
| 790 |
|
---|
| 791 | /* we don't have any extra space by default */
|
---|
| 792 | mTopOffset = 0;
|
---|
| 793 |
|
---|
[20433] | 794 | #if defined(VBOX_WITH_SDL13)
|
---|
| 795 | int sdlWindowFlags = SDL_WINDOW_SHOWN;
|
---|
| 796 | if (mfResizable)
|
---|
| 797 | sdlWindowFlags |= SDL_WINDOW_RESIZABLE;
|
---|
| 798 | if (!mWindow)
|
---|
| 799 | {
|
---|
| 800 | SDL_DisplayMode desktop_mode;
|
---|
| 801 | int x = 40 + mScreenId * 20;
|
---|
| 802 | int y = 40 + mScreenId * 15;
|
---|
| 803 |
|
---|
| 804 | SDL_GetDesktopDisplayMode(&desktop_mode);
|
---|
| 805 | /* create new window */
|
---|
[21369] | 806 |
|
---|
[20433] | 807 | char szTitle[64];
|
---|
| 808 | RTStrPrintf(szTitle, sizeof(szTitle), "SDL window %d", mScreenId);
|
---|
| 809 | mWindow = SDL_CreateWindow(szTitle, x, y,
|
---|
| 810 | newWidth, newHeight, sdlWindowFlags);
|
---|
| 811 | if (SDL_CreateRenderer(mWindow, -1,
|
---|
| 812 | SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD) < 0)
|
---|
| 813 | AssertReleaseFailed();
|
---|
| 814 |
|
---|
| 815 | SDL_GetRendererInfo(&mRenderInfo);
|
---|
| 816 |
|
---|
| 817 | mTexture = SDL_CreateTexture(desktop_mode.format,
|
---|
| 818 | SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight);
|
---|
| 819 | if (!mTexture)
|
---|
| 820 | AssertReleaseFailed();
|
---|
| 821 | }
|
---|
| 822 | else
|
---|
| 823 | {
|
---|
| 824 | int w, h;
|
---|
| 825 | uint32_t format;
|
---|
| 826 | int access;
|
---|
| 827 |
|
---|
| 828 | /* resize current window */
|
---|
| 829 | SDL_GetWindowSize(mWindow, &w, &h);
|
---|
| 830 |
|
---|
| 831 | if (w != (int)newWidth || h != (int)newHeight)
|
---|
| 832 | SDL_SetWindowSize(mWindow, newWidth, newHeight);
|
---|
| 833 |
|
---|
| 834 | SDL_QueryTexture(mTexture, &format, &access, &w, &h);
|
---|
| 835 | SDL_SelectRenderer(mWindow);
|
---|
| 836 | SDL_DestroyTexture(mTexture);
|
---|
| 837 | mTexture = SDL_CreateTexture(format, access, newWidth, newHeight);
|
---|
| 838 | if (!mTexture)
|
---|
| 839 | AssertReleaseFailed();
|
---|
| 840 | }
|
---|
| 841 |
|
---|
| 842 | void *pixels;
|
---|
| 843 | int pitch;
|
---|
| 844 | int w, h, bpp;
|
---|
| 845 | uint32_t Rmask, Gmask, Bmask, Amask;
|
---|
| 846 | uint32_t format;
|
---|
| 847 |
|
---|
| 848 | if (SDL_QueryTexture(mTexture, &format, NULL, &w, &h) < 0)
|
---|
| 849 | AssertReleaseFailed();
|
---|
| 850 |
|
---|
| 851 | if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask))
|
---|
| 852 | AssertReleaseFailed();
|
---|
| 853 |
|
---|
| 854 | if (SDL_QueryTexturePixels(mTexture, &pixels, &pitch) == 0)
|
---|
| 855 | {
|
---|
| 856 | mScreen = SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch,
|
---|
| 857 | Rmask, Gmask, Bmask, Amask);
|
---|
| 858 | }
|
---|
| 859 | else
|
---|
| 860 | {
|
---|
| 861 | mScreen = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
|
---|
| 862 | AssertReleaseFailed();
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | SDL_SetClipRect(mScreen, NULL);
|
---|
| 866 |
|
---|
| 867 | #else
|
---|
[1] | 868 | /*
|
---|
| 869 | * Now set the screen resolution and get the surface pointer
|
---|
| 870 | * @todo BPP is not supported!
|
---|
| 871 | */
|
---|
| 872 | mScreen = SDL_SetVideoMode(newWidth, newHeight, 0, sdlFlags);
|
---|
[21029] | 873 |
|
---|
| 874 | /*
|
---|
| 875 | * Set the Window ID. Currently used for OpenGL accelerated guests.
|
---|
| 876 | */
|
---|
| 877 | # if defined (RT_OS_WINDOWS)
|
---|
| 878 | SDL_SysWMinfo info;
|
---|
| 879 | SDL_VERSION(&info.version);
|
---|
| 880 | if (SDL_GetWMInfo(&info))
|
---|
[31698] | 881 | mWinId = (LONG64) info.window;
|
---|
[21029] | 882 | # elif defined (RT_OS_LINUX)
|
---|
| 883 | SDL_SysWMinfo info;
|
---|
| 884 | SDL_VERSION(&info.version);
|
---|
| 885 | if (SDL_GetWMInfo(&info))
|
---|
[31698] | 886 | mWinId = (LONG64) info.info.x11.wmwindow;
|
---|
[21029] | 887 | # else
|
---|
| 888 | /* XXX ignore this for other architectures */
|
---|
| 889 | # endif
|
---|
[20433] | 890 | #endif
|
---|
[1] | 891 | #ifdef VBOX_SECURELABEL
|
---|
| 892 | /*
|
---|
| 893 | * For non fixed SDL resolution, the above call tried to add the label height
|
---|
| 894 | * to the guest height. If it worked, we have an offset. If it didn't the below
|
---|
| 895 | * code will try again with the original guest resolution.
|
---|
| 896 | */
|
---|
[143] | 897 | if (mFixedSDLWidth == ~(uint32_t)0)
|
---|
[1] | 898 | {
|
---|
| 899 | /* if it didn't work, then we have to go for the original resolution and paint over the guest */
|
---|
| 900 | if (!mScreen)
|
---|
| 901 | {
|
---|
| 902 | mScreen = SDL_SetVideoMode(newWidth, newHeight - mLabelHeight, 0, sdlFlags);
|
---|
| 903 | }
|
---|
| 904 | else
|
---|
| 905 | {
|
---|
| 906 | /* we now have some extra space */
|
---|
| 907 | mTopOffset = mLabelHeight;
|
---|
| 908 | }
|
---|
| 909 | }
|
---|
| 910 | else
|
---|
| 911 | {
|
---|
| 912 | /* in case the guest resolution is small enough, we do have a top offset */
|
---|
| 913 | if (mFixedSDLHeight - mGuestYRes >= mLabelHeight)
|
---|
| 914 | mTopOffset = mLabelHeight;
|
---|
| 915 |
|
---|
| 916 | /* we also might have to center the guest picture */
|
---|
| 917 | if (mFixedSDLWidth > mGuestXRes)
|
---|
| 918 | mCenterXOffset = (mFixedSDLWidth - mGuestXRes) / 2;
|
---|
| 919 | if (mFixedSDLHeight > mGuestYRes + mLabelHeight)
|
---|
| 920 | mCenterYOffset = (mFixedSDLHeight - (mGuestYRes + mLabelHeight)) / 2;
|
---|
| 921 | }
|
---|
| 922 | #endif
|
---|
| 923 | AssertMsg(mScreen, ("Error: SDL_SetVideoMode failed!\n"));
|
---|
| 924 | if (mScreen)
|
---|
| 925 | {
|
---|
| 926 | #ifdef VBOX_WIN32_UI
|
---|
| 927 | /* inform the UI code */
|
---|
| 928 | resizeUI(mScreen->w, mScreen->h);
|
---|
| 929 | #endif
|
---|
| 930 | if (mfShowSDLConfig)
|
---|
| 931 | RTPrintf("Resized to %dx%d, screen surface type: %s\n", mScreen->w, mScreen->h,
|
---|
| 932 | ((mScreen->flags & SDL_HWSURFACE) == 0) ? "software" : "hardware");
|
---|
| 933 | }
|
---|
| 934 | repaint();
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | /**
|
---|
| 938 | * Update specified framebuffer area. The coordinates can either be
|
---|
| 939 | * relative to the guest framebuffer or relative to the screen.
|
---|
| 940 | *
|
---|
| 941 | * @remarks Must be called from the SDL thread on Linux!
|
---|
| 942 | * @param x left column
|
---|
| 943 | * @param y top row
|
---|
| 944 | * @param w width in pixels
|
---|
| 945 | * @param h height in pixels
|
---|
| 946 | * @param fGuestRelative flag whether the above values are guest relative or screen relative;
|
---|
| 947 | */
|
---|
| 948 | void VBoxSDLFB::update(int x, int y, int w, int h, bool fGuestRelative)
|
---|
| 949 | {
|
---|
[4637] | 950 | #ifdef VBOXSDL_WITH_X11
|
---|
[20433] | 951 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 952 | #endif
|
---|
| 953 | Assert(mScreen);
|
---|
| 954 | Assert(mSurfVRAM);
|
---|
| 955 | if (!mScreen || !mSurfVRAM)
|
---|
| 956 | return;
|
---|
[21369] | 957 |
|
---|
[1] | 958 | /* the source and destination rectangles */
|
---|
| 959 | SDL_Rect srcRect;
|
---|
| 960 | SDL_Rect dstRect;
|
---|
| 961 |
|
---|
| 962 | /* this is how many pixels we have to cut off from the height for this specific blit */
|
---|
| 963 | int yCutoffGuest = 0;
|
---|
| 964 |
|
---|
| 965 | #ifdef VBOX_SECURELABEL
|
---|
| 966 | bool fPaintLabel = false;
|
---|
| 967 | /* if we have a label and no space for it, we have to cut off a bit */
|
---|
| 968 | if (mLabelHeight && !mTopOffset)
|
---|
| 969 | {
|
---|
| 970 | if (y < (int)mLabelHeight)
|
---|
| 971 | yCutoffGuest = mLabelHeight - y;
|
---|
| 972 | }
|
---|
| 973 | #endif
|
---|
| 974 |
|
---|
| 975 | /**
|
---|
| 976 | * If we get a SDL window relative update, we
|
---|
| 977 | * just perform a full screen update to keep things simple.
|
---|
| 978 | *
|
---|
| 979 | * @todo improve
|
---|
| 980 | */
|
---|
| 981 | if (!fGuestRelative)
|
---|
| 982 | {
|
---|
| 983 | #ifdef VBOX_SECURELABEL
|
---|
| 984 | /* repaint the label if necessary */
|
---|
| 985 | if (y < (int)mLabelHeight)
|
---|
| 986 | fPaintLabel = true;
|
---|
| 987 | #endif
|
---|
| 988 | x = 0;
|
---|
| 989 | w = mGuestXRes;
|
---|
| 990 | y = 0;
|
---|
| 991 | h = mGuestYRes;
|
---|
| 992 | }
|
---|
| 993 |
|
---|
| 994 | srcRect.x = x;
|
---|
| 995 | srcRect.y = y + yCutoffGuest;
|
---|
| 996 | srcRect.w = w;
|
---|
| 997 | srcRect.h = RT_MAX(0, h - yCutoffGuest);
|
---|
| 998 |
|
---|
| 999 | /*
|
---|
| 1000 | * Destination rectangle is just offset by the label height.
|
---|
| 1001 | * There are two cases though: label height is added to the
|
---|
| 1002 | * guest resolution (mTopOffset == mLabelHeight; yCutoffGuest == 0)
|
---|
| 1003 | * or the label cuts off a portion of the guest screen (mTopOffset == 0;
|
---|
| 1004 | * yCutoffGuest >= 0)
|
---|
| 1005 | */
|
---|
| 1006 | dstRect.x = x + mCenterXOffset;
|
---|
| 1007 | #ifdef VBOX_SECURELABEL
|
---|
| 1008 | dstRect.y = RT_MAX(mLabelHeight, y + yCutoffGuest + mTopOffset) + mCenterYOffset;
|
---|
| 1009 | #else
|
---|
| 1010 | dstRect.y = y + yCutoffGuest + mTopOffset + mCenterYOffset;
|
---|
| 1011 | #endif
|
---|
| 1012 | dstRect.w = w;
|
---|
| 1013 | dstRect.h = RT_MAX(0, h - yCutoffGuest);
|
---|
| 1014 |
|
---|
| 1015 | /*
|
---|
| 1016 | * Now we just blit
|
---|
| 1017 | */
|
---|
| 1018 | SDL_BlitSurface(mSurfVRAM, &srcRect, mScreen, &dstRect);
|
---|
| 1019 | /* hardware surfaces don't need update notifications */
|
---|
[20433] | 1020 | #if defined(VBOX_WITH_SDL13)
|
---|
| 1021 | AssertRelease(mScreen->flags & SDL_PREALLOC);
|
---|
| 1022 | SDL_SelectRenderer(mWindow);
|
---|
| 1023 | SDL_DirtyTexture(mTexture, 1, &dstRect);
|
---|
| 1024 | AssertRelease(mRenderInfo.flags & SDL_RENDERER_PRESENTCOPY);
|
---|
| 1025 | SDL_RenderCopy(mTexture, &dstRect, &dstRect);
|
---|
| 1026 | SDL_RenderPresent();
|
---|
| 1027 | #else
|
---|
[1] | 1028 | if ((mScreen->flags & SDL_HWSURFACE) == 0)
|
---|
| 1029 | SDL_UpdateRect(mScreen, dstRect.x, dstRect.y, dstRect.w, dstRect.h);
|
---|
[20433] | 1030 | #endif
|
---|
[1] | 1031 |
|
---|
| 1032 | #ifdef VBOX_SECURELABEL
|
---|
| 1033 | if (fPaintLabel)
|
---|
| 1034 | paintSecureLabel(0, 0, 0, 0, false);
|
---|
| 1035 | #endif
|
---|
| 1036 | }
|
---|
| 1037 |
|
---|
| 1038 | /**
|
---|
| 1039 | * Repaint the whole framebuffer
|
---|
| 1040 | *
|
---|
| 1041 | * @remarks Must be called from the SDL thread!
|
---|
| 1042 | */
|
---|
| 1043 | void VBoxSDLFB::repaint()
|
---|
| 1044 | {
|
---|
[20433] | 1045 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 1046 | LogFlow(("VBoxSDLFB::repaint\n"));
|
---|
| 1047 | update(0, 0, mScreen->w, mScreen->h, false /* fGuestRelative */);
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
| 1050 | /**
|
---|
| 1051 | * Toggle fullscreen mode
|
---|
| 1052 | *
|
---|
| 1053 | * @remarks Must be called from the SDL thread!
|
---|
| 1054 | */
|
---|
| 1055 | void VBoxSDLFB::setFullscreen(bool fFullscreen)
|
---|
| 1056 | {
|
---|
[20433] | 1057 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 1058 | LogFlow(("VBoxSDLFB::SetFullscreen: fullscreen: %d\n", fFullscreen));
|
---|
| 1059 | mfFullscreen = fFullscreen;
|
---|
| 1060 | /* only change the SDL resolution, do not touch the guest framebuffer */
|
---|
| 1061 | resizeSDL();
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
[10675] | 1064 | /**
|
---|
[11400] | 1065 | * Return the geometry of the host. This isn't very well tested but it seems
|
---|
| 1066 | * to work at least on Linux hosts.
|
---|
[10675] | 1067 | */
|
---|
[11400] | 1068 | void VBoxSDLFB::getFullscreenGeometry(uint32_t *width, uint32_t *height)
|
---|
[10675] | 1069 | {
|
---|
| 1070 | SDL_Rect **modes;
|
---|
[1] | 1071 |
|
---|
[10675] | 1072 | /* Get available fullscreen/hardware modes */
|
---|
| 1073 | modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
|
---|
| 1074 | Assert(modes != NULL);
|
---|
| 1075 | /* -1 means that any mode is possible (usually non fullscreen) */
|
---|
| 1076 | if (modes != (SDL_Rect **)-1)
|
---|
| 1077 | {
|
---|
| 1078 | /*
|
---|
| 1079 | * According to the SDL documentation, the API guarantees that the modes
|
---|
| 1080 | * are sorted from larger to smaller, so we just take the first entry as
|
---|
| 1081 | * the maximum.
|
---|
| 1082 | *
|
---|
| 1083 | * XXX Crude Xinerama hack :-/
|
---|
| 1084 | */
|
---|
| 1085 | if ( modes[0]->w > (16*modes[0]->h/9)
|
---|
| 1086 | && modes[1]
|
---|
| 1087 | && modes[1]->h == modes[0]->h)
|
---|
| 1088 | {
|
---|
| 1089 | *width = modes[1]->w;
|
---|
| 1090 | *height = modes[1]->h;
|
---|
| 1091 | }
|
---|
| 1092 | else
|
---|
| 1093 | {
|
---|
| 1094 | *width = modes[0]->w;
|
---|
| 1095 | *height = modes[0]->w;
|
---|
| 1096 | }
|
---|
| 1097 | }
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
[1] | 1100 | #ifdef VBOX_SECURELABEL
|
---|
| 1101 | /**
|
---|
| 1102 | * Setup the secure labeling parameters
|
---|
| 1103 | *
|
---|
| 1104 | * @returns VBox status code
|
---|
| 1105 | * @param height height of the secure label area in pixels
|
---|
| 1106 | * @param font file path fo the TrueType font file
|
---|
| 1107 | * @param pointsize font size in points
|
---|
| 1108 | */
|
---|
[8154] | 1109 | int VBoxSDLFB::initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs)
|
---|
[1] | 1110 | {
|
---|
| 1111 | LogFlow(("VBoxSDLFB:initSecureLabel: new offset: %d pixels, new font: %s, new pointsize: %d\n",
|
---|
| 1112 | height, font, pointsize));
|
---|
| 1113 | mLabelHeight = height;
|
---|
[8154] | 1114 | mLabelOffs = labeloffs;
|
---|
[1] | 1115 | Assert(font);
|
---|
| 1116 | pTTF_Init();
|
---|
| 1117 | mLabelFont = pTTF_OpenFont(font, pointsize);
|
---|
| 1118 | if (!mLabelFont)
|
---|
| 1119 | {
|
---|
| 1120 | AssertMsgFailed(("Failed to open TTF font file %s\n", font));
|
---|
| 1121 | return VERR_OPEN_FAILED;
|
---|
| 1122 | }
|
---|
| 1123 | mSecureLabelColorFG = 0x0000FF00;
|
---|
| 1124 | mSecureLabelColorBG = 0x00FFFF00;
|
---|
| 1125 | repaint();
|
---|
| 1126 | return VINF_SUCCESS;
|
---|
| 1127 | }
|
---|
| 1128 |
|
---|
| 1129 | /**
|
---|
| 1130 | * Set the secure label text and repaint the label
|
---|
| 1131 | *
|
---|
| 1132 | * @param text UTF-8 string of new label
|
---|
| 1133 | * @remarks must be called from the SDL thread!
|
---|
| 1134 | */
|
---|
| 1135 | void VBoxSDLFB::setSecureLabelText(const char *text)
|
---|
| 1136 | {
|
---|
| 1137 | mSecureLabelText = text;
|
---|
| 1138 | paintSecureLabel(0, 0, 0, 0, true);
|
---|
| 1139 | }
|
---|
| 1140 |
|
---|
| 1141 | /**
|
---|
| 1142 | * Sets the secure label background color.
|
---|
| 1143 | *
|
---|
| 1144 | * @param colorFG encoded RGB value for text
|
---|
| 1145 | * @param colorBG encored RGB value for background
|
---|
| 1146 | * @remarks must be called from the SDL thread!
|
---|
| 1147 | */
|
---|
| 1148 | void VBoxSDLFB::setSecureLabelColor(uint32_t colorFG, uint32_t colorBG)
|
---|
| 1149 | {
|
---|
| 1150 | mSecureLabelColorFG = colorFG;
|
---|
| 1151 | mSecureLabelColorBG = colorBG;
|
---|
| 1152 | paintSecureLabel(0, 0, 0, 0, true);
|
---|
| 1153 | }
|
---|
| 1154 |
|
---|
| 1155 | /**
|
---|
| 1156 | * Paint the secure label if required
|
---|
| 1157 | *
|
---|
| 1158 | * @param fForce Force the repaint
|
---|
| 1159 | * @remarks must be called from the SDL thread!
|
---|
| 1160 | */
|
---|
| 1161 | void VBoxSDLFB::paintSecureLabel(int x, int y, int w, int h, bool fForce)
|
---|
| 1162 | {
|
---|
[4637] | 1163 | #ifdef VBOXSDL_WITH_X11
|
---|
[20433] | 1164 | AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
|
---|
[1] | 1165 | #endif
|
---|
| 1166 | /* only when the function is present */
|
---|
| 1167 | if (!pTTF_RenderUTF8_Solid)
|
---|
| 1168 | return;
|
---|
| 1169 | /* check if we can skip the paint */
|
---|
| 1170 | if (!fForce && ((uint32_t)y > mLabelHeight))
|
---|
| 1171 | {
|
---|
| 1172 | return;
|
---|
| 1173 | }
|
---|
| 1174 | /* first fill the background */
|
---|
| 1175 | SDL_Rect rect = {0, 0, (Uint16)mScreen->w, (Uint16)mLabelHeight};
|
---|
| 1176 | SDL_FillRect(mScreen, &rect, SDL_MapRGB(mScreen->format,
|
---|
| 1177 | (mSecureLabelColorBG & 0x00FF0000) >> 16, /* red */
|
---|
| 1178 | (mSecureLabelColorBG & 0x0000FF00) >> 8, /* green */
|
---|
| 1179 | mSecureLabelColorBG & 0x000000FF)); /* blue */
|
---|
| 1180 |
|
---|
| 1181 | /* now the text */
|
---|
[21369] | 1182 | if ( mLabelFont != NULL
|
---|
[21394] | 1183 | && !mSecureLabelText.isEmpty()
|
---|
[21369] | 1184 | )
|
---|
[1] | 1185 | {
|
---|
| 1186 | SDL_Color clrFg = {(mSecureLabelColorFG & 0x00FF0000) >> 16,
|
---|
| 1187 | (mSecureLabelColorFG & 0x0000FF00) >> 8,
|
---|
| 1188 | mSecureLabelColorFG & 0x000000FF, 0};
|
---|
[8144] | 1189 | SDL_Surface *sText = (pTTF_RenderUTF8_Blended != NULL)
|
---|
[31539] | 1190 | ? pTTF_RenderUTF8_Blended(mLabelFont, mSecureLabelText.c_str(), clrFg)
|
---|
| 1191 | : pTTF_RenderUTF8_Solid(mLabelFont, mSecureLabelText.c_str(), clrFg);
|
---|
[1] | 1192 | rect.x = 10;
|
---|
[8154] | 1193 | rect.y = mLabelOffs;
|
---|
[1] | 1194 | SDL_BlitSurface(sText, NULL, mScreen, &rect);
|
---|
| 1195 | SDL_FreeSurface(sText);
|
---|
| 1196 | }
|
---|
| 1197 | /* make sure to update the screen */
|
---|
| 1198 | SDL_UpdateRect(mScreen, 0, 0, mScreen->w, mLabelHeight);
|
---|
| 1199 | }
|
---|
| 1200 | #endif /* VBOX_SECURELABEL */
|
---|
| 1201 |
|
---|
| 1202 | // IFramebufferOverlay
|
---|
| 1203 | ///////////////////////////////////////////////////////////////////////////////////
|
---|
| 1204 |
|
---|
| 1205 | /**
|
---|
| 1206 | * Constructor for the VBoxSDLFBOverlay class (IFramebufferOverlay implementation)
|
---|
| 1207 | *
|
---|
| 1208 | * @param x Initial X offset for the overlay
|
---|
| 1209 | * @param y Initial Y offset for the overlay
|
---|
| 1210 | * @param width Initial width for the overlay
|
---|
| 1211 | * @param height Initial height for the overlay
|
---|
| 1212 | * @param visible Whether the overlay is initially visible
|
---|
| 1213 | * @param alpha Initial alpha channel value for the overlay
|
---|
| 1214 | */
|
---|
| 1215 | VBoxSDLFBOverlay::VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height,
|
---|
| 1216 | BOOL visible, VBoxSDLFB *aParent) :
|
---|
| 1217 | mOverlayX(x), mOverlayY(y), mOverlayWidth(width),
|
---|
| 1218 | mOverlayHeight(height), mOverlayVisible(visible),
|
---|
| 1219 | mParent(aParent)
|
---|
| 1220 | {}
|
---|
| 1221 |
|
---|
| 1222 | /**
|
---|
| 1223 | * Destructor for the VBoxSDLFBOverlay class.
|
---|
| 1224 | */
|
---|
| 1225 | VBoxSDLFBOverlay::~VBoxSDLFBOverlay()
|
---|
| 1226 | {
|
---|
| 1227 | SDL_FreeSurface(mBlendedBits);
|
---|
| 1228 | SDL_FreeSurface(mOverlayBits);
|
---|
| 1229 | }
|
---|
| 1230 |
|
---|
| 1231 | /**
|
---|
| 1232 | * Perform any initialisation of the overlay that can potentially fail
|
---|
| 1233 | *
|
---|
| 1234 | * @returns S_OK on success or the reason for the failure
|
---|
| 1235 | */
|
---|
| 1236 | HRESULT VBoxSDLFBOverlay::init()
|
---|
| 1237 | {
|
---|
| 1238 | mBlendedBits = SDL_CreateRGBSurface(SDL_ANYFORMAT, mOverlayWidth, mOverlayHeight, 32,
|
---|
| 1239 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0);
|
---|
| 1240 | AssertMsgReturn(mBlendedBits != NULL, ("Failed to create an SDL surface\n"),
|
---|
| 1241 | E_OUTOFMEMORY);
|
---|
| 1242 | mOverlayBits = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, mOverlayWidth,
|
---|
| 1243 | mOverlayHeight, 32, 0x00ff0000, 0x0000ff00,
|
---|
| 1244 | 0x000000ff, 0xff000000);
|
---|
| 1245 | AssertMsgReturn(mOverlayBits != NULL, ("Failed to create an SDL surface\n"),
|
---|
| 1246 | E_OUTOFMEMORY);
|
---|
| 1247 | return S_OK;
|
---|
| 1248 | }
|
---|
| 1249 |
|
---|
| 1250 | /**
|
---|
| 1251 | * Returns the current overlay X offset in pixels.
|
---|
| 1252 | *
|
---|
| 1253 | * @returns COM status code
|
---|
| 1254 | * @param x Address of result buffer.
|
---|
| 1255 | */
|
---|
| 1256 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(X)(ULONG *x)
|
---|
| 1257 | {
|
---|
| 1258 | LogFlow(("VBoxSDLFBOverlay::GetX\n"));
|
---|
| 1259 | if (!x)
|
---|
| 1260 | return E_INVALIDARG;
|
---|
| 1261 | *x = mOverlayX;
|
---|
| 1262 | return S_OK;
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
| 1265 | /**
|
---|
| 1266 | * Returns the current overlay height in pixels.
|
---|
| 1267 | *
|
---|
| 1268 | * @returns COM status code
|
---|
| 1269 | * @param height Address of result buffer.
|
---|
| 1270 | */
|
---|
| 1271 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Y)(ULONG *y)
|
---|
| 1272 | {
|
---|
| 1273 | LogFlow(("VBoxSDLFBOverlay::GetY\n"));
|
---|
| 1274 | if (!y)
|
---|
| 1275 | return E_INVALIDARG;
|
---|
| 1276 | *y = mOverlayY;
|
---|
| 1277 | return S_OK;
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | /**
|
---|
| 1281 | * Returns the current overlay width in pixels. In fact, this returns the line size.
|
---|
| 1282 | *
|
---|
| 1283 | * @returns COM status code
|
---|
| 1284 | * @param width Address of result buffer.
|
---|
| 1285 | */
|
---|
| 1286 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Width)(ULONG *width)
|
---|
| 1287 | {
|
---|
| 1288 | LogFlow(("VBoxSDLFBOverlay::GetWidth\n"));
|
---|
| 1289 | if (!width)
|
---|
| 1290 | return E_INVALIDARG;
|
---|
| 1291 | *width = mOverlayBits->pitch;
|
---|
| 1292 | return S_OK;
|
---|
| 1293 | }
|
---|
| 1294 |
|
---|
| 1295 | /**
|
---|
| 1296 | * Returns the current overlay line size in pixels.
|
---|
| 1297 | *
|
---|
| 1298 | * @returns COM status code
|
---|
| 1299 | * @param lineSize Address of result buffer.
|
---|
| 1300 | */
|
---|
[3761] | 1301 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
|
---|
[1] | 1302 | {
|
---|
[3761] | 1303 | LogFlow(("VBoxSDLFBOverlay::GetBytesPerLine\n"));
|
---|
| 1304 | if (!bytesPerLine)
|
---|
[1] | 1305 | return E_INVALIDARG;
|
---|
[3761] | 1306 | *bytesPerLine = mOverlayBits->pitch;
|
---|
[1] | 1307 | return S_OK;
|
---|
| 1308 | }
|
---|
| 1309 |
|
---|
| 1310 | /**
|
---|
| 1311 | * Returns the current overlay height in pixels.
|
---|
| 1312 | *
|
---|
| 1313 | * @returns COM status code
|
---|
| 1314 | * @param height Address of result buffer.
|
---|
| 1315 | */
|
---|
| 1316 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Height)(ULONG *height)
|
---|
| 1317 | {
|
---|
| 1318 | LogFlow(("VBoxSDLFBOverlay::GetHeight\n"));
|
---|
| 1319 | if (!height)
|
---|
| 1320 | return E_INVALIDARG;
|
---|
| 1321 | *height = mOverlayHeight;
|
---|
| 1322 | return S_OK;
|
---|
| 1323 | }
|
---|
| 1324 |
|
---|
| 1325 | /**
|
---|
| 1326 | * Returns whether the overlay is currently visible.
|
---|
| 1327 | *
|
---|
| 1328 | * @returns COM status code
|
---|
| 1329 | * @param visible Address of result buffer.
|
---|
| 1330 | */
|
---|
| 1331 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Visible)(BOOL *visible)
|
---|
| 1332 | {
|
---|
| 1333 | LogFlow(("VBoxSDLFBOverlay::GetVisible\n"));
|
---|
| 1334 | if (!visible)
|
---|
| 1335 | return E_INVALIDARG;
|
---|
| 1336 | *visible = mOverlayVisible;
|
---|
| 1337 | return S_OK;
|
---|
| 1338 | }
|
---|
| 1339 |
|
---|
| 1340 | /**
|
---|
| 1341 | * Sets whether the overlay is currently visible.
|
---|
| 1342 | *
|
---|
| 1343 | * @returns COM status code
|
---|
| 1344 | * @param visible New value.
|
---|
| 1345 | */
|
---|
| 1346 | STDMETHODIMP VBoxSDLFBOverlay::COMSETTER(Visible)(BOOL visible)
|
---|
| 1347 | {
|
---|
| 1348 | LogFlow(("VBoxSDLFBOverlay::SetVisible\n"));
|
---|
| 1349 | mOverlayVisible = visible;
|
---|
| 1350 | return S_OK;
|
---|
| 1351 | }
|
---|
| 1352 |
|
---|
| 1353 | /**
|
---|
| 1354 | * Returns the value of the global alpha channel.
|
---|
| 1355 | *
|
---|
| 1356 | * @returns COM status code
|
---|
| 1357 | * @param alpha Address of result buffer.
|
---|
| 1358 | */
|
---|
| 1359 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Alpha)(ULONG *alpha)
|
---|
| 1360 | {
|
---|
| 1361 | LogFlow(("VBoxSDLFBOverlay::GetAlpha\n"));
|
---|
| 1362 | return E_NOTIMPL;
|
---|
| 1363 | }
|
---|
| 1364 |
|
---|
| 1365 | /**
|
---|
| 1366 | * Sets whether the overlay is currently visible.
|
---|
| 1367 | *
|
---|
| 1368 | * @returns COM status code
|
---|
| 1369 | * @param alpha new value.
|
---|
| 1370 | */
|
---|
| 1371 | STDMETHODIMP VBoxSDLFBOverlay::COMSETTER(Alpha)(ULONG alpha)
|
---|
| 1372 | {
|
---|
| 1373 | LogFlow(("VBoxSDLFBOverlay::SetAlpha\n"));
|
---|
| 1374 | return E_NOTIMPL;
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
| 1377 | /**
|
---|
| 1378 | * Returns the address of the framebuffer bits for writing to.
|
---|
| 1379 | *
|
---|
| 1380 | * @returns COM status code
|
---|
| 1381 | * @param alpha Address of result buffer.
|
---|
| 1382 | */
|
---|
| 1383 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Address)(ULONG *address)
|
---|
| 1384 | {
|
---|
| 1385 | LogFlow(("VBoxSDLFBOverlay::GetAddress\n"));
|
---|
| 1386 | if (!address)
|
---|
| 1387 | return E_INVALIDARG;
|
---|
[143] | 1388 | *address = (uintptr_t) mOverlayBits->pixels;
|
---|
[1] | 1389 | return S_OK;
|
---|
| 1390 | }
|
---|
| 1391 |
|
---|
| 1392 | /**
|
---|
| 1393 | * Returns the current colour depth. In fact, this is always 32bpp.
|
---|
| 1394 | *
|
---|
| 1395 | * @returns COM status code
|
---|
[3761] | 1396 | * @param bitsPerPixel Address of result buffer.
|
---|
[1] | 1397 | */
|
---|
[3761] | 1398 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
|
---|
[1] | 1399 | {
|
---|
[3761] | 1400 | LogFlow(("VBoxSDLFBOverlay::GetBitsPerPixel\n"));
|
---|
| 1401 | if (!bitsPerPixel)
|
---|
[1] | 1402 | return E_INVALIDARG;
|
---|
[3761] | 1403 | *bitsPerPixel = 32;
|
---|
[1] | 1404 | return S_OK;
|
---|
| 1405 | }
|
---|
| 1406 |
|
---|
| 1407 | /**
|
---|
[3761] | 1408 | * Returns the current pixel format. In fact, this is always RGB.
|
---|
[1] | 1409 | *
|
---|
| 1410 | * @returns COM status code
|
---|
| 1411 | * @param pixelFormat Address of result buffer.
|
---|
| 1412 | */
|
---|
[3761] | 1413 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(PixelFormat)(ULONG *pixelFormat)
|
---|
[1] | 1414 | {
|
---|
| 1415 | LogFlow(("VBoxSDLFBOverlay::GetPixelFormat\n"));
|
---|
| 1416 | if (!pixelFormat)
|
---|
| 1417 | return E_INVALIDARG;
|
---|
[3761] | 1418 | *pixelFormat = FramebufferPixelFormat_FOURCC_RGB;
|
---|
[1] | 1419 | return S_OK;
|
---|
| 1420 | }
|
---|
| 1421 |
|
---|
| 1422 | /**
|
---|
[3761] | 1423 | * Returns whether the guest VRAM is used directly. In fact, this is always FALSE.
|
---|
| 1424 | *
|
---|
| 1425 | * @returns COM status code
|
---|
| 1426 | * @param usesGuestVRAM Address of result buffer.
|
---|
| 1427 | */
|
---|
| 1428 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(UsesGuestVRAM)(BOOL *usesGuestVRAM)
|
---|
| 1429 | {
|
---|
| 1430 | LogFlow(("VBoxSDLFBOverlay::GetUsesGuestVRAM\n"));
|
---|
| 1431 | if (!usesGuestVRAM)
|
---|
| 1432 | return E_INVALIDARG;
|
---|
| 1433 | *usesGuestVRAM = FALSE;
|
---|
| 1434 | return S_OK;
|
---|
| 1435 | }
|
---|
| 1436 |
|
---|
| 1437 | /**
|
---|
[1] | 1438 | * Returns the height reduction. In fact, this is always 0.
|
---|
| 1439 | *
|
---|
| 1440 | * @returns COM status code
|
---|
| 1441 | * @param heightReduction Address of result buffer.
|
---|
| 1442 | */
|
---|
| 1443 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(HeightReduction)(ULONG *heightReduction)
|
---|
| 1444 | {
|
---|
| 1445 | LogFlow(("VBoxSDLFBOverlay::GetHeightReduction\n"));
|
---|
| 1446 | if (!heightReduction)
|
---|
| 1447 | return E_INVALIDARG;
|
---|
| 1448 | *heightReduction = 0;
|
---|
| 1449 | return S_OK;
|
---|
| 1450 | }
|
---|
| 1451 |
|
---|
| 1452 | /**
|
---|
| 1453 | * Returns the overlay for this framebuffer. Obviously, we return NULL here.
|
---|
| 1454 | *
|
---|
| 1455 | * @returns COM status code
|
---|
| 1456 | * @param overlay Address of result buffer.
|
---|
| 1457 | */
|
---|
| 1458 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(Overlay)(IFramebufferOverlay **aOverlay)
|
---|
| 1459 | {
|
---|
| 1460 | LogFlow(("VBoxSDLFBOverlay::GetOverlay\n"));
|
---|
| 1461 | if (!aOverlay)
|
---|
| 1462 | return E_INVALIDARG;
|
---|
| 1463 | *aOverlay = 0;
|
---|
| 1464 | return S_OK;
|
---|
| 1465 | }
|
---|
| 1466 |
|
---|
| 1467 | /**
|
---|
[12449] | 1468 | * Returns associated window handle. We return NULL here.
|
---|
| 1469 | *
|
---|
| 1470 | * @returns COM status code
|
---|
| 1471 | * @param winId Address of result buffer.
|
---|
| 1472 | */
|
---|
[31698] | 1473 | STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(WinId)(LONG64 *winId)
|
---|
[12449] | 1474 | {
|
---|
| 1475 | LogFlow(("VBoxSDLFBOverlay::GetWinId\n"));
|
---|
| 1476 | if (!winId)
|
---|
| 1477 | return E_INVALIDARG;
|
---|
| 1478 | *winId = 0;
|
---|
| 1479 | return S_OK;
|
---|
| 1480 | }
|
---|
| 1481 |
|
---|
| 1482 |
|
---|
| 1483 | /**
|
---|
[1] | 1484 | * Lock the overlay. This should not be used - lock the parent IFramebuffer instead.
|
---|
| 1485 | *
|
---|
| 1486 | * @returns COM status code
|
---|
| 1487 | */
|
---|
| 1488 | STDMETHODIMP VBoxSDLFBOverlay::Lock()
|
---|
| 1489 | {
|
---|
| 1490 | LogFlow(("VBoxSDLFBOverlay::Lock\n"));
|
---|
| 1491 | AssertMsgFailed(("You should not attempt to lock an IFramebufferOverlay object -\n"
|
---|
| 1492 | "lock the parent IFramebuffer object instead.\n"));
|
---|
| 1493 | return E_NOTIMPL;
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | /**
|
---|
| 1497 | * Unlock the overlay.
|
---|
| 1498 | *
|
---|
| 1499 | * @returns COM status code
|
---|
| 1500 | */
|
---|
| 1501 | STDMETHODIMP VBoxSDLFBOverlay::Unlock()
|
---|
| 1502 | {
|
---|
| 1503 | LogFlow(("VBoxSDLFBOverlay::Unlock\n"));
|
---|
| 1504 | AssertMsgFailed(("You should not attempt to lock an IFramebufferOverlay object -\n"
|
---|
| 1505 | "lock the parent IFramebuffer object instead.\n"));
|
---|
| 1506 | return E_NOTIMPL;
|
---|
| 1507 | }
|
---|
| 1508 |
|
---|
| 1509 | /**
|
---|
| 1510 | * Change the X and Y co-ordinates of the overlay area.
|
---|
| 1511 | *
|
---|
| 1512 | * @returns COM status code
|
---|
| 1513 | * @param x New X co-ordinate.
|
---|
| 1514 | * @param y New Y co-ordinate.
|
---|
| 1515 | */
|
---|
| 1516 | STDMETHODIMP VBoxSDLFBOverlay::Move(ULONG x, ULONG y)
|
---|
| 1517 | {
|
---|
| 1518 | mOverlayX = x;
|
---|
| 1519 | mOverlayY = y;
|
---|
| 1520 | return S_OK;
|
---|
| 1521 | }
|
---|
| 1522 |
|
---|
| 1523 | /**
|
---|
| 1524 | * Notify the overlay that a section of the framebuffer has been redrawn.
|
---|
| 1525 | *
|
---|
| 1526 | * @returns COM status code
|
---|
| 1527 | * @param x X co-ordinate of upper left corner of modified area.
|
---|
| 1528 | * @param y Y co-ordinate of upper left corner of modified area.
|
---|
| 1529 | * @param w Width of modified area.
|
---|
| 1530 | * @param h Height of modified area.
|
---|
| 1531 | * @retval finished Set if the operation has completed.
|
---|
| 1532 | *
|
---|
| 1533 | * All we do here is to send a request to the parent to update the affected area,
|
---|
| 1534 | * translating between our co-ordinate system and the parent's. It would be have
|
---|
| 1535 | * been better to call the parent directly, but such is life. We leave bounds
|
---|
| 1536 | * checking to the parent.
|
---|
| 1537 | */
|
---|
| 1538 | STDMETHODIMP VBoxSDLFBOverlay::NotifyUpdate(ULONG x, ULONG y,
|
---|
[19817] | 1539 | ULONG w, ULONG h)
|
---|
[1] | 1540 | {
|
---|
[19817] | 1541 | return mParent->NotifyUpdate(x + mOverlayX, y + mOverlayY, w, h);
|
---|
[1] | 1542 | }
|
---|
| 1543 |
|
---|
| 1544 | /**
|
---|
| 1545 | * Change the dimensions of the overlay.
|
---|
| 1546 | *
|
---|
| 1547 | * @returns COM status code
|
---|
| 1548 | * @param pixelFormat Must be FramebufferPixelFormat_PixelFormatRGB32.
|
---|
| 1549 | * @param vram Must be NULL.
|
---|
| 1550 | * @param lineSize Ignored.
|
---|
| 1551 | * @param w New overlay width.
|
---|
| 1552 | * @param h New overlay height.
|
---|
| 1553 | * @retval finished Set if the operation has completed.
|
---|
| 1554 | */
|
---|
[3761] | 1555 | STDMETHODIMP VBoxSDLFBOverlay::RequestResize(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
|
---|
| 1556 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
| 1557 | ULONG w, ULONG h, BOOL *finished)
|
---|
[1] | 1558 | {
|
---|
[3761] | 1559 | AssertReturn(pixelFormat == FramebufferPixelFormat_FOURCC_RGB, E_INVALIDARG);
|
---|
[1] | 1560 | AssertReturn(vram == 0, E_INVALIDARG);
|
---|
[3761] | 1561 | AssertReturn(bitsPerPixel == 32, E_INVALIDARG);
|
---|
[1] | 1562 | mOverlayWidth = w;
|
---|
| 1563 | mOverlayHeight = h;
|
---|
| 1564 | SDL_FreeSurface(mOverlayBits);
|
---|
| 1565 | mBlendedBits = SDL_CreateRGBSurface(SDL_ANYFORMAT, mOverlayWidth, mOverlayHeight, 32,
|
---|
| 1566 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0);
|
---|
| 1567 | AssertMsgReturn(mBlendedBits != NULL, ("Failed to create an SDL surface\n"),
|
---|
| 1568 | E_OUTOFMEMORY);
|
---|
| 1569 | mOverlayBits = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, mOverlayWidth,
|
---|
| 1570 | mOverlayHeight, 32, 0x00ff0000, 0x0000ff00,
|
---|
| 1571 | 0x000000ff, 0xff000000);
|
---|
| 1572 | AssertMsgReturn(mOverlayBits != NULL, ("Failed to create an SDL surface\n"),
|
---|
| 1573 | E_OUTOFMEMORY);
|
---|
| 1574 | return S_OK;
|
---|
| 1575 | }
|
---|
| 1576 |
|
---|
| 1577 | /**
|
---|
| 1578 | * Returns whether we like the given video mode.
|
---|
| 1579 | *
|
---|
| 1580 | * @returns COM status code
|
---|
| 1581 | * @param width video mode width in pixels
|
---|
| 1582 | * @param height video mode height in pixels
|
---|
| 1583 | * @param bpp video mode bit depth in bits per pixel
|
---|
| 1584 | * @retval supported pointer to result variable
|
---|
| 1585 | *
|
---|
| 1586 | * Basically, we support anything with 32bpp.
|
---|
| 1587 | */
|
---|
| 1588 | STDMETHODIMP VBoxSDLFBOverlay::VideoModeSupported(ULONG width, ULONG height, ULONG bpp,
|
---|
| 1589 | BOOL *supported)
|
---|
| 1590 | {
|
---|
| 1591 | if (!supported)
|
---|
| 1592 | return E_POINTER;
|
---|
| 1593 | if (bpp == 32)
|
---|
| 1594 | *supported = true;
|
---|
| 1595 | else
|
---|
| 1596 | *supported = false;
|
---|
| 1597 | return S_OK;
|
---|
| 1598 | }
|
---|