📄 dalmode.c
字号:
{
// cannot Set a mode for a driver which has never called
// DALEnableDriverInstance. This one cause me to burn a few hours, so
// I've added an ASSERT to the code to prevent other developers from
// running into the same problem! [GG]
DALASSERT(FALSE, "DALResetMode - driver instance never enabled!");
DALDEBUG((DALDBG_ENTRY_EXIT, "DALResetMode - Exit"));
return;
}
// Notify DDL event - driver reset mode
ZEROMEMORY(&sEventInfo, sizeof(EVENTINFO));
sEventInfo.ulSize = sizeof(EVENTINFO);
sEventInfo.ulDriverID = ulDriverID;
sEventInfo.ulEvent = DAL_EVENT_DRIVERRESETMODE;
DDLEventNotification(lpHDE->hDDL, &sEventInfo);
ulControllers = lpHDE->aControllerMap[ulDriverID];
// loop through the controllers specified by the caller, marking them
// as inactive.
for (i = 0; i < lpHDE->ulControllersCount; i++)
{
if (VECTORFROMINDEX(i) & ulControllers)
{
// found a specified controller from the bit vector of controllers
// so reset it.
lpController = (LPDEVGCO) &lpHDE->aControllers[i];
vControllerResetMode(lpHDE, lpController);
}
}
// release the memory used by this driver for this mode.
lpHDE->ulVideoMemorySizeAvailable += lpHDE->aDriverData[ulDriverID].ulMemoryUsed;
lpHDE->aDriverData[ulDriverID].ulMemoryUsed = 0;
// reset the flag indicating the mode has been set for this driver
lpHDE->aDriverData[ulDriverID].ulFlags &= ~DRIVERDATA_ACTIVE;
DALASSERT((lpHDE->ulVideoMemorySizeAvailable <= lpHDE->ulVideoMemorySize),
"DALResetMode - no conservation of memory?");
DALDEBUG((DALDBG_ENTRY_EXIT, "DALResetMode - Exit"));
}
/******************************Public*Routine******************************\
*
* ULONG DALSetMode()
*
* [cd]: DALSetMode will be called only by GDI.
* Keep in mind it is called with desktop values, which may not
* necessarily coincide with the actual mode we wish to set.
* CWDDE will call vControllerSetMode itself to change modes.
\**************************************************************************/
ULONG DALSetMode(
HDAL hDAL,
ULONG ulDriverID,
LPDEVMODE_INFO lpMode,
ULONG ulDisplayOffset,
ULONG ulDisplayPitch,
BOOL bForce)
{
LPHW_DAL_EXTENSION lpHDE;
//LPDEVMODE_INFO lpDefaultMode;
LPDEVGCO lpController;
LPDEVGDO lpDisplay;
ULONG i;
ULONG j;
ULONG ulModeTableIndex;
ULONG ulControllers;
ULONG ulViewOffset;
DEVMODE_INFO dmModesSent[MAX_NUMBER_CONTROLLERS];
DEVMODE_INFO dmModesRet[MAX_NUMBER_CONTROLLERS];
ULONG ulDisplayType[MAX_NUMBER_CONTROLLERS];
ULONG ulDisplay[MAX_NUMBER_CONTROLLERS];
BOOL bCanSetModes;
ULONG ulPanType;
ULONG ulOptions = 0;
BOOL bPseudoLargeDesktop = FALSE;
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Entry"));
DALASSERT((hDAL != NULL), "DAL handle 'hDAL' is NULL!");
// grab the structure for the DAL out of the DDL's handle to it
lpHDE = (LPHW_DAL_EXTENSION)hDAL;
lpHDE->ulFlags &= ~(HDAL_INITIALIZING | HDAL_RESUMING);
if (!(lpHDE->aDriverData[ulDriverID].ulFlags & DRIVERDATA_ENABLED))
{
// cannot Set a mode for a driver which has never called
// DALEnableDriverInstance. This one cause me to burn a few hours, so
// I've added an ASSERT to the code to prevent other developers from
// running into the same problem! [GG]
DALASSERT(FALSE, "DALSetMode - driver instance never enabled!");
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Exit"));
return(0);
}
// if (lpHDE->ulDalRule1 & DALRULE1_NOFORCEBOOT)
// {
// lpHDE->aDriverData[ulDriverID].bFailNextMode = FALSE;
// }
//
// if (lpHDE->aDriverData[ulDriverID].bFailNextMode == TRUE)
// {
// // if DAL is forcing the driver to set a specific mode, DAL will continue
// // to fail the set mode, and validate mode calls until the driver
// // calls DALGetDefaultMode and programs the default mode as requested
// // by the DAL [GG]
//
// lpDefaultMode = (LPDEVMODE_INFO) &lpHDE->aDriverData[ulDriverID].sDefaultMode;
//
// if ((lpDefaultMode->ulPelsWidth == lpMode->ulPelsWidth) &&
// (lpDefaultMode->ulPelsHeight == lpMode->ulPelsHeight) &&
// (lpDefaultMode->ulBitsPerPixel == lpMode->ulBitsPerPixel) &&
// (lpDefaultMode->ulDisplayFrequency == lpMode->ulDisplayFrequency))
// {
// // turn off the fail next mode flag for this driver as it actually
// // set the mode the driver was requesting. Pixel depth was removed from
// // the force, so Win9X cannot change the pixel depth at boot [GG]
//
// lpHDE->aDriverData[ulDriverID].bFailNextMode = FALSE;
// } else
// {
// // keep failing the mode until the driver get's the hint and sets the
// // default mode as specified in DALGetDefaultMode [GG]
// DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Exit"));
// return(0);
// }
// }
// else
{
// If DALRULE1_RESTRICT8BPPON2NDDRV is set and
// if this is not the primary driver and the mode is
// a 8 BPP mode then fail the validation.
if((lpHDE->ulDalRule1 & DALRULE1_RESTRICT8BPPON2NDDRV) &&
(ulDriverID != 0) &&
(lpMode->ulBitsPerPixel == 8))
{
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Exit"));
return(0);
}
// We are not setting a default mode so let us check
// if flag that define the Optimum or Default
// refresh rate is set.
if (lpMode->ulModeFlags & DEVMODEFLAG_DEFAULTFREQUENCY)
{
lpMode->ulDisplayFrequency = DAL_DEFAULT_ADAPTER_FREQUENCY;
}
else if (lpMode->ulModeFlags & DEVMODEFLAG_OPTIMUMFREQUENCY)
{
lpMode->ulDisplayFrequency = lpHDE->ulOptimumFrequency;
}
else if (lpMode->ulModeFlags & DEVMODEFLAG_DEFINEDFREQUENCY)
{
if(lpMode->ulDisplayFrequency == 0)
{
lpMode->ulDisplayFrequency = lpHDE->ulOptimumFrequency;
}
}
else
{
// Since Default or Optimum flag are not set by the driver
// it means that the Driver is requesting a specific frequency.
// we will set the exact frequency flag in devmode info ModeFlags
// fields to use later in bFindClosestMode for show all refresh
// rate implementation
ulOptions |= DAL_OPTIONS_EXACTFREQUENCY;
}
if ((lpMode->ulPelsWidth < 640) ||
(lpMode->ulPelsHeight < 480))
{
// flag any mode smaller than 640x480 as a LowRes mode.
ulOptions |= DAL_OPTIONS_LOWRESMODE;
}
}
// first step, ensure the mode actually exists in the mode table,
// of if the mode has an adapter optimal flag a similar mode independant
// of refresh rate exists. otherwise how could DAL be called to set a
// mode it never enumerated in the first place?!?! [GG] 09/12/98
// Moved this chunk of the code from bFindClosestMode to DalSetMode
// and Dalvalidate mode because it breaks 2 driver case [sah] 16/12/98
// If bForce is set refresh rate should be disregarded. Check the validity
// of the mode by comparing the Xres, Yres and Bpp. [sah]
if (!((bSearchModeTable(lpHDE, (LPDEVMODE_INFO)lpMode, (LPULONG)&ulModeTableIndex)) ||
((bForce == TRUE) &&
(lpHDE->lpaModes[ulModeTableIndex].sDevModeInfo.ulPelsWidth == lpMode->ulPelsWidth) &&
(lpHDE->lpaModes[ulModeTableIndex].sDevModeInfo.ulPelsHeight == lpMode->ulPelsHeight) &&
(lpHDE->lpaModes[ulModeTableIndex].sDevModeInfo.ulBitsPerPixel == lpMode->ulBitsPerPixel))))
{
// if the mode does not exist in the mode table, then obviously it cannot
// be set as a valid mode.
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Exit"));
return(0);
}
lpMode->ulModeFlags |= lpHDE->lpaModes[ulModeTableIndex].sDevModeInfo.ulModeFlags;
ulControllers = lpHDE->aControllerMap[ulDriverID];
if (!ulControllers)
{
if(!bForceDriverMaping(lpHDE, ulDriverID))
{
DALASSERT(FALSE, "DALSetMode - Invalid Driver Mapping, No display or Controller free!");
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetMode - Exit"));
return(0);
}
ulControllers = lpHDE->aControllerMap[ulDriverID];
}
if (lpHDE->bPowerPlaySupported)
vPowerPlayAdjustBPP(hDAL,ulDriverID,lpMode);
// read registry key for pan lock info
// currently we only implement to support Appian (i.e. 2 controllers mapped to
// same driver case. The complete solution have to be implemented later.
ZEROMEMORY((LPVOID)&lpHDE->sPanLock[0], sizeof(RECT)*MAX_NUMBER_CONTROLLERS);
if ( DALRULE1_SAVEPANLOCK & lpHDE->ulDalRule1)
{
ULONG ulControllerVector = VECTORFROMINDEX(DAL_PRIMARY_CONTROLLER) |
VECTORFROMINDEX(DAL_SECONDARY_CONTROLLER);
if((ulControllerVector & ulControllers) == ulControllerVector)
{
UCHAR aucName[64];
ULONG ulSize = sizeof(RECT)*MAX_NUMBER_CONTROLLERS;
DEVMODE_INFO sMode;
ZEROMEMORY((LPVOID)&sMode, sizeof(sMode));
sMode.ulPelsHeight = lpMode->ulPelsHeight;
sMode.ulPelsWidth = lpMode->ulPelsWidth;
vGetDisplayPerModeValueName(lpHDE,
(LPUCHAR)DALREGKEY_VIEWLOCK,
(LPDEVMODE_INFO)&sMode,
(LPUCHAR)&aucName[0]);
if ((!DDLGetRegistryParameters(lpHDE->hDDL,
(LPUCHAR)&aucName[0],
(LPVOID)&lpHDE->sPanLock[0],
(LPULONG)&ulSize)) ||
(ulSize != (sizeof(RECT)*MAX_NUMBER_CONTROLLERS)))
{
ZEROMEMORY((LPVOID)&lpHDE->sPanLock[0], sizeof(RECT)*MAX_NUMBER_CONTROLLERS);
}
}
}
// need ensure that the mode can be set on each controller with it's
// mapping of displays [GG]
bCanSetModes = TRUE;
for (i = 0; i < lpHDE->ulControllersCount; i++)
{
if (VECTORFROMINDEX(i) & ulControllers)
{
lpController = (LPDEVGCO) &lpHDE->aControllers[i];
// Update the GCO mapping flag. This could have changed due to dynamic
// remapping of the controllers and displays.
lpController->ulFlags |= GCO_MAPPED;
if (lpController->ulFlags & GCO_ACTIVE)
{
// if the controller is already active it cannot be programmed into
// a new mode until it is released, hence fail the call.
DALASSERT(FALSE, "DALSetMode - controller still active!");
// todo / hack - remove this.
// bCanSetModes = FALSE;
}
}
}
ZEROMEMORY((LPVOID)&lpHDE->aulRefreshRate[0], sizeof(ULONG)*MAX_NUMBER_CONTROLLERS);
if (DEVMODEFLAG_LARGEDESKTOP & lpMode->ulModeFlags)
{
UCHAR aucName[64];
DEVMODE_INFO sMode;
ULONG ulSize = sizeof(ULONG)*MAX_NUMBER_CONTROLLERS;
ZEROMEMORY((LPVOID)&sMode, sizeof(sMode));
sMode.ulPelsHeight = lpMode->ulPelsHeight;
sMode.ulPelsWidth = lpMode->ulPelsWidth;
vGetDisplayPerModeValueName(lpHDE,
(LPUCHAR)DALREGKEY_REFRESHRATE,
(LPDEVMODE_INFO)&sMode,
(LPUCHAR)&aucName[0]);
if (!(DDLGetRegistryParameters(lpHDE->hDDL,
(LPUCHAR)&aucName[0],
(LPVOID)&lpHDE->aulRefreshRate[0],
(LPULONG)&ulSize) &&
(ulSize == (sizeof(ULONG)*MAX_NUMBER_CONTROLLERS))))
{
ZEROMEMORY((LPVOID)&lpHDE->aulRefreshRate[0], sizeof(ULONG)*MAX_NUMBER_CONTROLLERS);
}
}
for (i = 0; i < lpHDE->ulControllersCount; i++)
{
// fill up the current displays for the controllers on this driver
lpController = (LPDEVGCO) &lpHDE->aControllers[i];
if (VECTORFROMINDEX(i) & ulControllers)
{
ulDisplay[i] = lpController->ulDisplays;
// fill up the current display types for the controllers on this driver
ulDisplayType[i] = ulGetDisplayTypesFromDisplayVector(lpHDE,
lpController->ulDisplays,
(1 && (lpController->ulFlags & GCO_EXPANSION)));
MOVEMEMORY((LPDEVMODE_INFO)&dmModesSent[i], lpMode, sizeof(DEVMODE_INFO));
// If we want to validate the mode, fill up the dmModesRet table
if ( !(bForce) )
MOVEMEMORY((LPDEVMODE_INFO)&dmModesRet[i], lpMode, sizeof(DEVMODE_INFO));
if ( ( lpMode->ulModeFlags & DEVMODEFLAG_OPTIMUMFREQUENCY ) &&
( lpHDE->ulDalRule3 & DALRULE3_MATCHEDIDSBEFOREUSINGOSMONITORINFO ) )
{
// for all non-DDC displays, we want to set the refresh "optimum" for the display-mapped
// controller to 60Hz to be safe, since we cannot tell which display "belongs" to the
// current OSMonitorInfo being used.
for ( j = 0; j < lpHDE->ulDisplaysCount; j++)
{
if ( ulDisplay[i] & VECTORFROMINDEX(j) ) // only care about displays on THIS controller.
{
lpDisplay = (LPDEVGDO) &lpHDE->aDisplays[j];
if ( ( ( lpDisplay->lpHWED->ulDisplayType == HW_DISPLAY_TYPE_CRT ) ||
( lpDisplay->lpHWED->ulDisplayType == HW_DISPLAY_TYPE_CRT_2NDDAC ) ) &&
!( lpDisplay->ulFlags & GDO_EDID ) ) // this is the non-DDC condition.
{
dmModesSent[i].ulDisplayFrequency = 60;
if ( (!bForce) )
dmModesRet[i].ulDisplayFrequency = 60;
}
}
} // end of for loop
} // end of if OPTIMUM_FREQ...
// "Pseudo" extended desktop support
if (DEVMODEFLAG_LARGEDESKTOP & lpMode->ulModeFlags)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -