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