/** @file
*
* VBox frontends: VBoxSDL (simple frontend based on SDL):
* VBoxSDL testcases
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#if defined(RT_OS_WINDOWS) ///@todo someone please explain why we don't follow the book!
# define _SDL_main_h
#endif
#include <SDL.h>
#include <iprt/initterm.h>
#include <stdlib.h>
#include <signal.h>
#ifdef VBOX_OPENGL
#include "SDL_opengl.h"
#endif
#ifdef RT_OS_WINDOWS
#define ESC_NORM
#define ESC_BOLD
#else
#endif
#ifdef VBOX_OPENGL
static unsigned int gTexture;
#endif
static void benchExecute(void);
static void checkEvents(void);
int
{
int rc;
for (int i = 1; i < argc; i++)
{
#ifdef VBOX_OPENGL
{
gfOpenGL = 1;
continue;
}
#endif
{
continue;
}
return -1;
}
#ifdef RT_OS_WINDOWS
/* Default to DirectX if nothing else set. "windib" would be possible. */
if (!RTEnvExist("SDL_VIDEODRIVER"))
{
_putenv("SDL_VIDEODRIVER=directx");
}
#endif
#ifdef RT_OS_WINDOWS
_putenv("SDL_VIDEO_WINDOW_POS=0,0");
#else
#endif
if (rc != 0)
{
return -1;
}
/* output what SDL is capable of */
if (!videoInfo)
{
RTPrintf("No SDL video info available!\n");
return -1;
}
RTPrintf("SDL capabilities:\n");
RTPrintf(" Screen to screen colorkey blits accelerated: %s\n", videoInfo->blit_hw_CC ? "yes" : "no");
RTPrintf(" Memory to screen colorkey blits accelerated: %s\n", videoInfo->blit_sw_CC ? "yes" : "no");
RTPrintf("\n"
"Starting tests. Any key pressed inside the SDL window will abort this\n"
"program at the end of the current test. Iterations = %u\n", guLoop);
#ifdef VBOX_OPENGL
#endif
RTPrintf("\nSuccess!\n");
return 0;
}
/**
* Method that does the actual resize of the guest framebuffer and
* then changes the SDL framebuffer setup.
*/
{
guGuestXRes = w;
guGuestYRes = h;
guGuestBpp = bpp;
RTPrintf("\n");
/* a different format we support directly? */
switch (guGuestBpp)
{
case 16:
{
Rmask = 0xF800;
Gmask = 0x07E0;
Bmask = 0x001F;
Amask = 0x0000;
Rsize = 5;
Gsize = 6;
Bsize = 5;
break;
}
case 24:
{
Rmask = 0x00FF0000;
Gmask = 0x0000FF00;
Bmask = 0x000000FF;
Amask = 0x00000000;
Rsize = 8;
Gsize = 8;
Bsize = 8;
break;
}
default:
Rmask = 0x00FF0000;
Gmask = 0x0000FF00;
Bmask = 0x000000FF;
Amask = 0x00000000;
Rsize = 8;
Gsize = 8;
Bsize = 8;
break;
}
#ifdef VBOX_OPENGL
if (gfOpenGL)
sdlFlags |= SDL_OPENGL;
#endif
if (gfResizable)
if (gfFullscreen)
/*
* Now we have to check whether there are video mode restrictions
*/
/* Get available fullscreen/hardware modes */
{
return;
}
/* -1 means that any mode is possible (usually non fullscreen) */
{
/*
* according to the SDL documentation, the API guarantees that
* the modes are sorted from larger to smaller, so we just
* take the first entry as the maximum.
*/
guMaxScreenWidth = modes[0]->w;
guMaxScreenHeight = modes[0]->h;
}
else
{
/* no restriction */
guMaxScreenWidth = ~0;
guMaxScreenHeight = ~0;
}
/*
* Now set the screen resolution and get the surface pointer
* @todo BPP is not supported!
*/
#ifdef VBOX_OPENGL
if (gfOpenGL)
{
}
#else
#endif
if (!gScreen)
{
return;
}
/* first free the current surface */
if (gSurfVRAM)
{
}
if (gPtrVRAM)
{
}
{
/* Create a source surface from guest VRAM. */
}
else
{
/* Create a software surface for which SDL allocates the RAM */
}
if (!gSurfVRAM)
{
RTPrintf("Failed to allocate surface %ldx%ld@%ld\n",
return;
}
RTPrintf(" gScreen=%dx%d@%d (surface: %s)\n",
checkSDL("SDL_FillRect",
#ifdef VBOX_OPENGL
if (gfOpenGL)
{
int r, g, b, d, o;
RTPrintf(" OpenGL ctxt red=%d, green=%d, blue=%d, depth=%d, dbl=%d", r, g, b, d, o);
;
;
switch (guGuestBpp)
{
break;
GL_BGR, GL_UNSIGNED_BYTE, 0);
break;
GL_BGRA, GL_UNSIGNED_BYTE, 0);
break;
return;
}
}
#endif
checkEvents();
benchExecute();
#ifdef VBOX_OPENGL
if (gfOpenGL)
{
}
#endif
}
static void benchExecute()
{
for (unsigned i=0; i<guLoop; i++)
{
#ifdef VBOX_OPENGL
if (!gfOpenGL)
{
#endif
/* SDL backend */
#ifdef VBOX_OPENGL
}
else
{
/* OpenGL backend */
{
break;
break;
break;
return;
}
glEnd();
glFlush();
}
#endif
}
}
{
if (rc == -1)
return rc;
}
static void checkEvents(void)
{
while (SDL_PollEvent(&event))
{
{
case SDL_KEYDOWN:
RTPrintf("\nKey pressed, exiting ...\n");
exit(-1);
break;
}
}
}