VirtualBox

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

Last change on this file since 20371 was 19844, checked in by vboxsync, 16 years ago

HGSMI: post host VBVA commands to display; Video HW Accel: mechanism for passing/processing commands to framebuffer

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