Helper.cpp revision a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fc
98N/A/** @file
98N/A *
98N/A * VBox frontends: Framebuffer (FB, DirectFB):
98N/A * Helper routines
98N/A */
98N/A
98N/A/*
98N/A * Copyright (C) 2006-2007 innotek GmbH
98N/A *
98N/A * This file is part of VirtualBox Open Source Edition (OSE), as
98N/A * available from http://www.virtualbox.org. This file is free software;
98N/A * you can redistribute it and/or modify it under the terms of the GNU
98N/A * General Public License (GPL) as published by the Free Software
98N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
98N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
98N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
98N/A */
98N/A
98N/A#include "VBoxFB.h"
98N/A#include "Helper.h"
98N/A
98N/A/**
98N/A * Globals
98N/A */
98N/AvideoMode videoModes[MAX_VIDEOMODES] = {0};
98N/Auint32_t numVideoModes = 0;
98N/A
98N/A/**
98N/A * callback handler for populating the supported video modes
98N/A *
98N/A * @returns callback success indicator
98N/A * @param width width in pixels of the current video mode
112N/A * @param height height in pixels of the current video mode
98N/A * @param bpp bits per pixel of the current video mode
98N/A * @param callbackdata user data pointer
98N/A */
98N/ADFBEnumerationResult enumVideoModesHandler(int width, int height, int bpp, void *callbackdata)
98N/A{
98N/A if (numVideoModes >= MAX_VIDEOMODES)
98N/A {
98N/A return DFENUM_CANCEL;
98N/A }
98N/A // don't take palette based modes
98N/A if (bpp >= 16)
98N/A {
98N/A // don't take modes we already have (I have seen many cases where
98N/A // DirectFB returns the same modes several times)
98N/A int32_t existingMode = getBestVideoMode(width, height, bpp);
98N/A if ((existingMode == -1) ||
98N/A ((videoModes[existingMode].width != (uint32_t)width) ||
98N/A (videoModes[existingMode].height != (uint32_t)height) ||
98N/A (videoModes[existingMode].bpp != (uint32_t)bpp)))
98N/A {
98N/A videoModes[numVideoModes].width = (uint32_t)width;
98N/A videoModes[numVideoModes].height = (uint32_t)height;
98N/A videoModes[numVideoModes].bpp = (uint32_t)bpp;
98N/A numVideoModes++;
98N/A }
98N/A }
112N/A return DFENUM_OK;
98N/A}
112N/A
98N/A/**
98N/A * Returns the best fitting video mode for the given characteristics.
*
* @returns index of the best video mode, -1 if no suitable mode found
* @param width requested width
* @param height requested height
* @param bpp requested bit depth
*/
int32_t getBestVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
{
int32_t bestMode = -1;
for (uint32_t i = 0; i < numVideoModes; i++)
{
// is this mode compatible?
if ((videoModes[i].width >= width) && (videoModes[i].height >= height) &&
(videoModes[i].bpp >= bpp))
{
// first suitable mode?
if (bestMode == -1)
{
bestMode = i;
} else
{
// is it better than the one we got before?
if ((videoModes[i].width < videoModes[bestMode].width) ||
(videoModes[i].height < videoModes[bestMode].height) ||
(videoModes[i].bpp < videoModes[bestMode].bpp))
{
bestMode = i;
}
}
}
}
return bestMode;
}