VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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