VBoxMPVidModes.cpp revision 635c83753ed04cf3637e019af0e15ba40e07f2fe
/* $Id$ */
/** @file
* VBox Miniport video modes related functions
*/
/*
* Copyright (C) 2011-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.
*/
#include "VBoxMPCommon.h"
#define _INC_SWPRINTF_INL_
#endif
#include <wchar.h>
#ifdef VBOX_WITH_WDDM
# define VBOX_WITHOUT_24BPP_MODES
#endif
/* Custom video modes which are being read from registry at driver startup. */
static BOOLEAN
VBoxMPValidateVideoModeParamsGuest(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t xres, uint32_t yres, uint32_t bpp)
{
switch (bpp)
{
case 32:
break;
case 24:
#ifdef VBOX_WITHOUT_24BPP_MODES
return FALSE;
#else
break;
#endif
case 16:
break;
case 8:
#ifndef VBOX_WITH_8BPP_MODES
return FALSE;
#else
#ifdef VBOX_XPDM_MINIPORT
return FALSE;
#endif
break;
#endif
default:
return FALSE;
}
return TRUE;
}
/* Fills given video mode BPP related fields */
static void
{
}
/* Fills given video mode structure */
static void
VBoxFillVidModeInfo(VIDEO_MODE_INFORMATION *pMode, ULONG xres, ULONG yres, ULONG bpp, ULONG index, ULONG yoffset)
{
/*Common entries*/
/*BPP related entries*/
switch (bpp)
{
#ifdef VBOX_WITH_8BPP_MODES
case 8:
break;
#endif
case 16:
break;
case 24:
case 32:
break;
default:
Assert(0);
break;
}
}
{
int iMode;
LOGF_ENTER();
/* Initialize all custom modes to the 800x600x32 */
{
}
/* Read stored custom resolution info from registry */
{
if (iMode==0)
{
/*First name without a suffix*/
}
else
{
wchar_t keyname[32];
}
{
if (CustomXRes == 0)
{
}
if (CustomYRes == 0)
{
}
if (CustomBPP == 0)
{
}
{
}
}
}
LOGF_LEAVE();
}
{
}
#ifdef VBOX_XPDM_MINIPORT
{
}
#endif
static bool VBoxMPVideoModesMatch(const PVIDEO_MODE_INFORMATION pMode1, const PVIDEO_MODE_INFORMATION pMode2)
{
}
static int
VBoxMPFindVideoMode(const PVIDEO_MODE_INFORMATION pModesTable, int cModes, const PVIDEO_MODE_INFORMATION pMode)
{
for (int i = 0; i < cModes; ++i)
{
{
return i;
}
}
return -1;
}
/* Helper function to dynamically build our table of standard video
* modes. We take the amount of VRAM and create modes with standard
* geometries until we've either reached the maximum number of modes
* or the available VRAM does not allow for additional modes.
* We also check registry for manually added video modes.
* Returns number of modes added to the table.
*/
static uint32_t
VBoxMPFillModesTable(PVBOXMP_DEVEXT pExt, int iDisplay, PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize,
{
/* the resolution matrix */
struct
{
} resolutionMatrix[] =
{
/* standard modes */
{ 640, 480 },
{ 800, 600 },
{ 1024, 768 },
{ 1152, 864 },
{ 1280, 960 },
{ 1280, 1024 },
{ 1400, 1050 },
{ 1600, 1200 },
{ 1920, 1440 },
#ifndef VBOX_WITH_WDDM
/* multi screen modes with 1280x1024 */
{ 2560, 1024 },
{ 3840, 1024 },
{ 5120, 1024 },
/* multi screen modes with 1600x1200 */
{ 3200, 1200 },
{ 4800, 1200 },
{ 6400, 1200 },
#endif
};
#ifdef VBOX_XPDM_MINIPORT
#else
# ifdef VBOX_WDDM_WIN8
if (!g_VBoxDisplayOnly)
# endif
{
/* at least two surfaces will be needed: primary & shadow */
vramSize /= 2;
}
vramSize &= ~PAGE_OFFSET_MASK;
#endif
/* there are 4 color depths: 8, 16, 24 and 32bpp and we reserve 50% of the modes for other sources */
/* Always add 800x600 video modes. Windows XP+ needs at least 800x600 resolution
* and fallbacks to 800x600x4bpp VGA mode if the driver did not report suitable modes.
* This resolution could be rejected by a low resolution host (netbooks, etc).
*/
#ifdef VBOX_WITH_8BPP_MODES
int bytesPerPixel=1;
#else
int bytesPerPixel=2;
#endif
{
{
/* we don't have enough VRAM for this mode */
continue;
}
continue;
if (32==bitsPerPixel)
{
}
++iMode;
}
/* Query yoffset from the host */
/* Iterate through our static resolution table and add supported video modes for different bpp's */
#ifdef VBOX_WITH_8BPP_MODES
#else
#endif
{
for (cAdded=0, resIndex=0; resIndex<RT_ELEMENTS(resolutionMatrix) && cAdded<maxModesPerColorDepth; resIndex++)
{
if (resolutionMatrix[resIndex].xRes * resolutionMatrix[resIndex].yRes * bytesPerPixel > (LONG)vramSize)
{
/* we don't have enough VRAM for this mode */
continue;
}
if (yOffset == 0 && resolutionMatrix[resIndex].xRes == 800 && resolutionMatrix[resIndex].yRes == 600)
{
/* this mode was already added */
continue;
}
if (
#ifdef VBOX_WDDM_MINIPORT
/* 1024x768 resolution is a minimal resolutions for win8 to make most metro apps run.
* For small host display resolutions, host will dislike the mode 1024x768 and above
* if the framebuffer window requires scrolling to fit the guest resolution.
* So add 1024x768 resolution for win8 guest to allow user switch to it */
&&
#endif
{
/* host doesn't like this mode */
continue;
}
if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel))
{
/* guest does not like this mode */
continue;
}
/* Sanity check, we shouldn't ever get here */
{
WARN(("video modes table overflow!"));
break;
}
VBoxFillVidModeInfo(&pModesTable[iMode], resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel, iMode+1, yOffset);
++iMode;
++cAdded;
}
}
/* Check registry for manually added modes, up to 128 entries is supported
* Give up on the first error encountered.
*/
int fPrefSet=0;
{
{
WARN(("ignoring possible custom mode(s), table is full!"));
break;
}
wchar_t keyname[24];
/* round down width to be a multiple of 8 if necessary */
{
xres &= 0xFFF8;
}
|| ( (bpp != 16)
&& (bpp != 24)
&& (bpp != 32)))
{
/* incorrect values */
break;
}
/* does it fit within our VRAM? */
{
/* we don't have enough VRAM for this mode */
break;
}
{
/* host doesn't like this mode */
break;
}
{
/* guest does not like this mode */
continue;
}
LOG(("adding video mode from registry."));
if (!fPrefSet)
{
fPrefSet = 1;
}
#ifdef VBOX_WDDM_MINIPORT
/*check if the same mode has been added to the table already*/
if (foundIdx>=0)
{
{
}
}
else
#endif
{
++iMode;
}
}
if (pPrefModeIdx)
{
*pPrefModeIdx = iPrefIdx;
}
return iMode;
}
/* Returns if we're in the first mode change, ie doesn't have valid video mode set yet */
{
#ifdef VBOX_XPDM_MINIPORT
return (pExt->CurrentMode == 0);
#else
#endif
}
#ifdef VBOX_WDDM_MINIPORT
static const uint32_t g_aVBoxVidModesSupportedBpps[] = {
32
#ifndef VBOX_WITHOUT_24BPP_MODES
, 24
#endif
, 16
#ifdef VBOX_WITH_8BPP_MODES
, 8
#endif
};
{
for (int i = 0; i < RT_ELEMENTS(g_aVBoxVidModesSupportedBpps); ++i)
{
if (bpp == g_aVBoxVidModesSupportedBpps[i])
return TRUE;
}
return FALSE;
}
{
if (VBoxMPIsSupportedBpp(bpp))
return bpp;
return g_aVBoxVidModesSupportedBpps[0];
}
#endif
/* Updates missing video mode params with current values,
* Checks if resulting mode is liked by the host and fits into VRAM.
* Returns TRUE if resulting mode could be used.
*/
static BOOLEAN
VBoxMPValidateVideoModeParams(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t &xres, uint32_t &yres, uint32_t &bpp)
{
/* Make sure all important video mode values are set */
{
/* Use stored custom values only if nothing was read from host. */
}
else
{
/* Use current values for field which weren't read from host. */
#ifdef VBOX_XPDM_MINIPORT
#else
/* VBox WDDM driver does not allow 24 modes since OS could choose the 24bit mode as default in that case,
* the pExt->aSources[iDisplay].AllocData.SurfDesc.bpp could be initially 24 though,
* i.e. when driver occurs the current mode on driver load via DxgkCbAcquirePostDisplayOwnership
* and until driver reports the supported modes
* This is true for Win8 Display-Only driver currently since DxgkCbAcquirePostDisplayOwnership is only used by it
*
* This is why we need to adjust the current mode bpp to the value we actually report as supported */
#endif
}
/* Round down width to be a multiple of 8 if necessary */
{
xres &= 0xFFF8;
}
/* We always need bpp to be set */
if (!bpp)
{
bpp=32;
}
{
return FALSE;
}
/* Check if host likes this mode */
{
return FALSE;
}
#ifdef VBOX_XPDM_MINIPORT
#else
# ifdef VBOX_WDDM_WIN8
if (!g_VBoxDisplayOnly)
# endif
{
/* at least two surfaces will be needed: primary & shadow */
vramSize /= 2;
}
vramSize &= ~PAGE_OFFSET_MASK;
#endif
/* Check that values are valid and mode fits into VRAM */
|| !((bpp == 16)
#ifdef VBOX_WITH_8BPP_MODES
|| (bpp == 8)
#endif
|| (bpp == 24)
|| (bpp == 32)))
{
return FALSE;
}
{
/* Store values of last reported release log message to avoid log flooding. */
LOG(("not enough VRAM for video mode %dx%dx%dbpp. Available: %d bytes. Required: more than %d bytes.",
s_xresNoVRAM = xres;
s_yresNoVRAM = yres;
s_bppNoVRAM = bpp;
return FALSE;
}
return TRUE;
}
/* Checks if there's a pending video mode change hint,
* and fills pPendingMode with associated info.
* returns TRUE if there's a pending change. Otherwise returns FALSE.
*/
static BOOLEAN
{
/* Check if there's a pending display change request for this display */
{
{
/*display = RT_ELEMENTS(g_CustomVideoModes) - 1;*/
return FALSE;
}
}
else
{
LOG(("no pending request"));
return FALSE;
}
/* Correct video mode params and check if host likes it */
{
return TRUE;
}
return FALSE;
}
/* Save custom mode info to registry */
static void VBoxMPRegSaveModeInfo(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, PVIDEO_MODE_INFORMATION pMode)
{
if (iDisplay==0)
{
/*First name without a suffix*/
}
else
{
wchar_t keyname[32];
}
}
#ifdef VBOX_XPDM_MINIPORT
{
}
{
return pExt->cVideoModes;
}
/* Makes a table of video modes consisting of:
* Default modes
* Custom modes manually added to registry
* Custom modes for all displays (either from a display change hint or stored in registry)
* 2 special modes, for a pending display change for this adapter. See comments below.
*/
{
/* Fill table with standart modes and ones manually added to registry.
* Up to VBOXMP_MAX_VIDEO_MODES elements can be used, the rest is reserved
* for custom mode alternating indexes.
*/
cStandartModes = VBoxMPFillModesTable(pExt, pExt->iDevice, pExt->aVideoModes, VBOXMP_MAX_VIDEO_MODES, NULL);
/* Add custom mode for this display to the table */
/* Make 2 entries in the video mode table. */
/* Take the alternating index into account. */
/* Fill the special mode. */
memcpy(&pExt->aVideoModes[iSpecialMode], &g_CustomVideoModes[pExt->iDevice], sizeof(VIDEO_MODE_INFORMATION));
/* Wipe the other entry so it is not selected. */
LOG(("added special mode[%d] %dx%d:%d for display %d\n",
/* Check if host wants us to switch video mode and it's for this adapter */
LOG(("bPending %d, pExt->iDevice %d, specialMode.ModeIndex %d",
/* Check the startup case */
{
/* Check if we could make valid mode from values stored to registry */
{
bHaveSpecial = TRUE;
}
}
/* Update number of modes. Each display has 2 entries for alternating custom mode index. */
if (bHaveSpecial)
{
/* We need to alternate mode index entry for a pending mode change,
* else windows will ignore actual mode change call.
* Only alternate index if one of mode parameters changed and
* regardless of conditions always add 2 entries to the table.
*/
LOG(("prev %dx%dx%d, special %dx%dx%d",
if (bChanged)
{
}
/* Check if we need to alternate the index */
{
if (bChanged)
{
}
{
}
}
LOG(("add special mode[%d] %dx%d:%d for display %d (bChanged=%d, bAlternativeIndex=%d)",
iSpecialModeElement, specialMode.VisScreenWidth, specialMode.VisScreenHeight, specialMode.BitsPerPlane,
/* Add special mode to the table
* Note: Y offset isn't used for a host-supplied modes
*/
/* Save special mode in the custom modes table */
/* Wipe the old entry so the special mode will be found in the new positions. */
memcpy(&pExt->aVideoModes[iSpecialModeElementOld], &pExt->aVideoModes[3], sizeof(VIDEO_MODE_INFORMATION));
/* Save special mode info to registry */
}
#if defined(LOG_ENABLED)
do
{
{
LOG(("Mode[%2d]: %4dx%4d:%2d (idx=%d)",
}
} while (0);
#endif
}
#endif /*VBOX_XPDM_MINIPORT*/