VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp@ 3340

Last change on this file since 3340 was 3289, checked in by vboxsync, 18 years ago

FE/SDL: Improved SDL event handling. Don't enqueue further XPCOM events if there is already an XPCOM event on air. Immediately signal the main thread when a new SDL event was enqueued.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette