vboxutils.c revision acca7ab818eb8c2832aa27e27ce53133fba927db
/** @file
* VirtualBox X11 Additions graphics driver utility functions
*/
/*
* Copyright (C) 2006-2007 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.
*/
#include <VBox/VBoxGuestLib.h>
#ifndef PCIACCESS
# include <xf86Pci.h>
# include <Pci.h>
#endif
#include "xf86.h"
#define NEED_XF86_TYPES
#include "compiler.h"
#include "vboxvideo.h"
#ifdef XORG_7X
# include <stdio.h>
# include <stdlib.h>
#endif
/**************************************************************************
* Main functions *
**************************************************************************/
/**
* Inform VBox that we are aware of advanced graphics functions
* (i.e. dynamic resizing, seamless).
*
* @returns TRUE for success, FALSE for failure
*/
{
TRACE_ENTRY();
return FALSE;
}
/**
* Inform VBox that we are no longer aware of advanced graphics functions
* (i.e. dynamic resizing, seamless).
*
* @returns TRUE for success, FALSE for failure
*/
{
TRACE_ENTRY();
return FALSE;
}
/**
* Query the last display change request.
*
* @returns boolean success indicator.
* @param pScrn Pointer to the X screen info structure.
* @param pcx Where to store the horizontal pixel resolution (0 = do not change).
* @param pcy Where to store the vertical pixel resolution (0 = do not change).
* @param pcBits Where to store the bits per pixel (0 = do not change).
* @param iDisplay Where to store the display number the request was for - 0 for the
* primary display, 1 for the first secondary, etc.
*/
{
TRACE_ENTRY();
return FALSE;
if (RT_SUCCESS(rc))
return TRUE;
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to obtain the last resolution requested by the guest, rc=%d.\n", rc);
return FALSE;
}
/**
* Query the host as to whether it likes a specific video mode.
*
* @returns the result of the query
* @param cx the width of the mode being queried
* @param cy the height of the mode being queried
* @param cBits the bpp of the mode being queried
*/
{
TRACE_ENTRY();
return TRUE; /* If we can't ask the host then we like everything. */
}
/**
* Check if any seamless mode is enabled.
* Seamless is only relevant for the newer Xorg modules.
*
* @returns the result of the query
* (true = seamless enabled, false = seamless not enabled)
* @param pScrn Screen info pointer.
*/
{
TRACE_ENTRY();
return FALSE;
return FALSE;
return (mode != VMMDev_Seamless_Disabled);
}
/**
* Save video mode parameters to the registry.
*
* @returns iprt status value
* @param pszName the name to save the mode parameters under
* @param cx mode width
* @param cy mode height
* @param cBits bits per pixel for the mode
*/
{
TRACE_ENTRY();
return FALSE;
}
/**
* Retrieve video mode parameters from the registry.
*
* @returns iprt status value
* @param pszName the name under which the mode parameters are saved
* @param pcx where to store the mode width
* @param pcy where to store the mode height
* @param pcBits where to store the bits per pixel for the mode
*/
{
int rc;
TRACE_ENTRY();
else
if (RT_SUCCESS(rc))
else
return (RT_SUCCESS(rc));
}
/**
* Fills a display mode M with a built-in mode of name pszName and dimensions
* cx and cy.
*/
{
m->type = M_T_BUILTIN;
/* Older versions of VBox only support screen widths which are a multiple
* of 8 */
else
if (pszName)
{
if (m->name)
}
}
/** vboxvideo's list of standard video modes */
struct
{
/** mode width */
/** mode height */
} vboxStandardModes[] =
{
{ 1600, 1200 },
{ 1440, 1050 },
{ 1280, 960 },
{ 1024, 768 },
{ 800, 600 },
{ 640, 480 },
{ 0, 0 }
};
enum
{
};
/**
* Returns a standard mode which the host likes. Can be called multiple
* times with the index returned by the previous call to get a list of modes.
* @returns the index of the mode in the list, or 0 if no more modes are
* available
* @param pScrn the screen information structure
* @param pScrn->bitsPerPixel
* if this is non-null, only modes with this BPP will be
* returned
* @param cIndex the index of the last mode queried, or 0 to query the
* first mode available. Note: the first index is 1
* @param pcx where to store the mode's width
* @param pcy where to store the mode's height
* @param pcBits where to store the mode's BPP
*/
{
("cIndex = %d, vboxNumStdModes = %d\n", cIndex,
{
continue;
cBits = 32;
cBits = 16;
else
continue;
if (pcx)
if (pcy)
if (pcBits)
return i + 1;
}
return 0;
}
/**
* Returns the preferred video mode. The current order of preference is
* (from highest to least preferred):
* - The mode corresponding to the last size hint from the host
* - The video mode saved from the last session
* - The largest standard mode which the host likes, falling back to
* 640x480x32 as a worst case
* - If the host can't be contacted at all, we return 1024x768x32
*
* The return type is void as we guarantee we will return some mode.
*/
{
/* Query the host for the preferred resolution and colour depth */
bool found = false;
{
found = true;
}
{
if (!found)
&iScreenIn);
found = false;
if (!found)
found = false;
if (!found)
if (!found)
{
/* Last resort */
cx = 640;
cy = 480;
cBits = 32;
}
}
else
{
cx = 1024;
cy = 768;
}
if (pcx)
if (pcy)
if (pcBits)
}
/* Move a screen mode found to the end of the list, so that RandR will give
* it the highest priority when a mode switch is requested. Returns the mode
* that was previously before the mode in the list in order to allow the
* caller to continue walking the list. */
{
{
}
return pPrev;
}
/**
* Rewrites the first dynamic mode found which is not the current screen mode
* to contain the host's currently preferred screen size, then moves that
* mode to the front of the screen information structure's mode list.
* Additionally, if the current mode is not dynamic, the second dynamic mode
* will be set to match the current mode and also added to the front. This
* ensures that the user can always reset the current size to kick the driver
* to update its mode list.
*/
{
bool found = false;
TRACE_ENTRY();
#ifdef DEBUG
/* Count the number of modes for sanity */
break;
#endif
{
#ifdef DEBUG
#endif
{
if (!found)
else if (pCurrent)
found = true;
}
break;
}
("vboxvideo: no free dynamic mode found. Exiting.\n"));
("pScrn->modes->HDisplay=%u, pScrn->modes->next->HDisplay=%u\n",
("pScrn->modes->VDisplay=%u, pScrn->modes->next->VDisplay=%u\n",
}
/**
* Allocates an empty display mode and links it into the doubly linked list of
* modes pointed to by pScrn->modes. Returns a pointer to the newly allocated
* memory.
*/
{
TRACE_ENTRY();
{
}
else
{
}
return pMode;
}
/**
* Create display mode entries in the screen information structure for each
* of the initial graphics modes that we wish to support. This includes:
* - An initial mode, of the size requested by the caller
* - Two dynamic modes, one of which will be updated to match the last size
* hint from the host on each mode switch, but initially also of the
* requested size
* - Several standard modes, if possible ones that the host likes
* - Any modes that the user requested in xorg.conf/XFree86Config
*/
{
/* For reasons related to the way RandR 1.1 is implemented, we need to
* make sure that the initial mode (more precisely, a mode equal to the
* initial virtual resolution) is always present in the mode list. RandR
* has the assumption build in that there will either be a mode of that
* size present at all times, or that the first mode in the list will
* always be smaller than the initial virtual resolution. Since our
* approach to dynamic resizing isn't quite the way RandR was intended to
* be, and breaks the second assumption, we guarantee the first. */
/* Create our two dynamic modes. */
/* Add standard modes supported by the host */
for ( ; ; )
{
char szName[256];
if (cIndex == 0)
break;
}
/* And finally any modes specified by the user. We assume here that
* the mode names reflect the mode sizes. */
{
{
}
}
}