VirtualBox

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

Last change on this file since 8144 was 8144, checked in by vboxsync, 17 years ago

FE/SDL: use RenderUTF8_Blended() if available to get a better looking font

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

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