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