📄 dalgco.c
字号:
// programming the gamma correction.
if (lpController->ulFlags & GCO_ACTIVE)
{
if (lpController->lpHWED->ulFunctionHooks & GCO_HOOK_GAMMA16)
{
(*lpController->lpHWED->pfnSetGamma16Correction)(lpController->hGCO, i,
lpaGamma16);
} else
{
(*lpController->lpHWED->pfnSetGammaCorrection)(lpController->hGCO, i,
lpaGamma);
}
}
}
i += 1;
ulControllers = (ulControllers >> 1);
}
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetGammaCorrection - Exit"));
}
/******************************Public*Routine******************************\
*
* VOID DALSetGamma16Correction
*
* Programs the gamma correction of the specified controllers.
*
* Note: DAL does nothing if the controller is inactive. If multiple
* controllers are specified in the same call, both need be working
* cooperatively from the same desktop, and hence will require the
* same gamma correction values.
*
* Gamma correction is normally programmed via ATI's property pages,
* but Microsoft has their own API into the driver for Gamma Correction
* via ExtEscape .... hence DAL has to support a call to process Gamma.
*
\**************************************************************************/
VOID DALSetGamma16Correction(
HDAL hDAL,
ULONG ulDriverID,
LPDEVCLUT16 lpaGamma16)
{
LPHW_DAL_EXTENSION lpHDE;
LPDEVGCO lpController;
LPDRIVERDATA lpDriverData;
LPDEVCLUT lpaGamma;
DEVCLUT aGamma[256];
ULONG ulControllers;
ULONG i;
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetGamma16Correction - 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;
// save the gamma correction in DAL DRIVERDATA structure.
lpDriverData = (LPDRIVERDATA) &lpHDE->aDriverData[ulDriverID];
if (lpHDE->aDriverData[ulDriverID].ulFlags & DRIVERDATA_USEGAMEGAMMA)
{
// DAL does not save out the game gamma when modified by a gaming
// application because this will change from game to game, and the
// DAL should ensure each gaming session starts from the same
// default gamma
MOVEMEMORY((LPVOID)lpDriverData->aGameGamma16,
(LPVOID)lpaGamma16,
(sizeof(DEVCLUT16) * 256));
} else
{
// Set the Gamma Save flag, so that it would be flushed to the registry
// Gamma will be saved only if adjusted via CWDDE interface
//lpDriverData->ulFlags |= DRIVERDATA_SAVEGAMMA;
MOVEMEMORY((LPVOID)lpDriverData->aGamma16,
(LPVOID)lpaGamma16,
(sizeof(DEVCLUT16) * 256));
}
ulControllers = lpHDE->aControllerMap[ulDriverID];
i = 0;
// loop through the specified controller programming gamma correction
// if the controller is active.
while((ulControllers != 0) && (i < lpHDE->ulControllersCount))
{
if (ulControllers & 1)
{
lpController = (LPDEVGCO)&lpHDE->aControllers[i];
// if this controller was specified, test if it is active, before
// programming the gamma correction.
if (lpController->lpHWED->ulFunctionHooks & GCO_HOOK_GAMMA16)
{
(*lpController->lpHWED->pfnSetGamma16Correction)(lpController->hGCO,
i,
lpaGamma16);
} else
{
// legacy GCO's don't support 16bit gamma correct, hence DAL will
// accomodate the 8bit format, by performing the truncation
// directly before calling the GCO to set gamma correction
lpaGamma = (LPDEVCLUT)aGamma;
vConvert16To8Gamma(lpaGamma16, lpaGamma);
(*lpController->lpHWED->pfnSetGammaCorrection)(lpController->hGCO,
i,
lpaGamma);
}
}
i += 1;
ulControllers = (ulControllers >> 1);
}
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetGamma16Correction - Exit"));
}
// -------------------------- Private Routine ---------------------------------
// If DALRULE2_ENABLELOG registry option is enabled, this function will fire up
// ATI_MESSAGECODE_DAL_LOGINFO_xxxx driver message event to inform ExtEvent
// Utility to take down log informations
// Note: Implementation is calling convention sensitive. So force __cdecl constraint
// ----------------------------------------------------------------------------
void __cdecl LogInfo( LPHW_DAL_EXTENSION lpHDE, ULONG ulDriverId, ULONG ulMessageCode,
ULONG ulNumOfParams, ... )
{
ULONG aBuf[256/sizeof(ULONG)];
LPULONG lpParams = (&ulNumOfParams) + 1;
if ( !lpHDE || !(lpHDE->ulDalRule2 & DALRULE2_ENABLELOG) ) return;
// Test buffer overflow
if ( ulNumOfParams > sizeof(aBuf)/sizeof(ULONG) - 1 )
ulNumOfParams = sizeof(aBuf)/sizeof(ULONG) - 1;
DDLMessageCode( lpHDE->hDDL, ulDriverId, ulMessageCode, (ulNumOfParams+1)*sizeof(ULONG), aBuf );
};
/******************************Public*Routine******************************\
*
* VOID DALSetPalette
*
* Programs the palette of the specified controllers.
*
* Note: DAL does nothing if the controller is inactive. If multiple
* controllers are specified in the same call, both need be working
* cooperatively from the same desktop, and hence will require the
* same palette.
*
\**************************************************************************/
VOID DALSetPalette(
HDAL hDAL,
ULONG ulDriverID,
LPDEVCLUT lpPalette,
ULONG ulStart,
ULONG ulLength)
{
LPHW_DAL_EXTENSION lpHDE;
LPDEVGCO lpController;
ULONG ulControllers;
ULONG i;
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetPalette - 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;
ulControllers = lpHDE->aControllerMap[ulDriverID];
i = 0;
// loop through the specified controller programming the palette if
// the controller is active and in a palletized mode.
while((ulControllers != 0) && (i < lpHDE->ulControllersCount))
{
if (ulControllers & 1)
{
// if this controller was specified, test if it is active, and in
// a palletized pixel depth (namely 8bpp) then program the palette.
lpController = (LPDEVGCO) &lpHDE->aControllers[i];
if ((lpController->ulFlags & GCO_ACTIVE) &&
(8 == lpController->sModeInfo.ulBitsPerPixel))
{
(*lpController->lpHWED->pfnSetPalette)(lpController->hGCO,
i,
lpPalette,
ulStart,
ulLength);
}
}
i += 1;
ulControllers = (ulControllers >> 1);
}
DALDEBUG((DALDBG_ENTRY_EXIT, "DALSetPalette - Exit"));
}
/****************************Private*Routine*******************************\
*
* VOID vFillModeChangeInfo()
*
* Fills in MODECHANGEINFO structure.
*
\**************************************************************************/
VOID vFillModeChangeInfo(
LPHW_DAL_EXTENSION lpHDE,
LPDEVMODE_INFO lpMI,
LPDEVGCO lpController,
ULONG ulDisplays,
LPEVENTINFO lpEventInfo)
{
ULONG i;
LPDEVGDO lpDisplay;
ULONG ulDisplayTypes;
DALASSERT((lpEventInfo != 0), "vFillModeChangeInfo - Invalid lpEventInfo" );
DALASSERT((lpMI != 0), "vFillModeChangeInfo - Invalid lpMI pointer");
DALASSERT((lpController != 0), "vFillModeChangeInfo - Invalid lpController");
// initialize ModeChangeInfo structure by zeroed it out
ZEROMEMORY(lpEventInfo, sizeof(EVENTINFO));
// fill in structure size
lpEventInfo->ulSize = sizeof(EVENTINFO);
// fill in desktop size
MOVEMEMORY(&lpEventInfo->sDesktop, &lpController->siDesktop, sizeof(SIZE));
// fill in mode info
if( ulDisplays )
{
MOVEMEMORY(&lpEventInfo->sModeInfo, lpMI, sizeof(DEVMODE_INFO));
}
// fill in controller index
lpEventInfo->ulController = lpController->ulController;
// fill in driver ID
for (i = 0; i < MAX_NUMBER_CONTROLLERS; i++)
{
if (lpHDE->aDriverData[i].ulFlags & DRIVERDATA_ENABLED)
{
if (lpHDE->aControllerMap[i] & VECTORFROMINDEX(lpController->ulController))
{
lpEventInfo->ulDriverID = i;
break;
}
}
}
// Set DAL_MODECHANGE_MAJOR_DESKTOPRESORBPPCHANGE if needed
if ((lpHDE->aDriverData[lpEventInfo->ulDriverID].sMode.ulPelsWidth !=
lpHDE->aDriverData[lpEventInfo->ulDriverID].sLastMode.ulPelsWidth) ||
(lpHDE->aDriverData[lpEventInfo->ulDriverID].sMode.ulPelsHeight !=
lpHDE->aDriverData[lpEventInfo->ulDriverID].sLastMode.ulPelsHeight) ||
(lpHDE->aDriverData[lpEventInfo->ulDriverID].sMode.ulBitsPerPixel!=
lpHDE->aDriverData[lpEventInfo->ulDriverID].sLastMode.ulBitsPerPixel))
{
// desktop resolution or color depth change
lpEventInfo->ulModeMajorFlag |= DAL_MODECHANGE_MAJOR_DESKTOPRESORBPPCHANGE;
}
// Set DAL_MODECHANGE_MINOR_VIEWRESCHANGE if needed
if (lpController->sModeInfo.ulPelsWidth != lpMI->ulPelsWidth ||
lpController->sModeInfo.ulPelsHeight != lpMI->ulPelsHeight)
{
// Check for view change
lpEventInfo->ulModeMinorFlag |= DAL_MODECHANGE_MINOR_VIEWRESCHANGE ;
}
// Set DAL_MODECHANGE_MINOR_RATIOMETRICEXPANSIONON if needed
if (lpController->ulFlags & GCO_EXPANSION)
{
for (i = 0; i < lpHDE->ulDisplaysCount; i++)
{
if (ulDisplays & VECTORFROMINDEX(i))
{
lpDisplay = &lpHDE->aDisplays[i];
ulDisplayTypes = lpDisplay->lpHWED->ulDisplayType;
if (ulDisplayTypes & HW_DISPLAY_TYPES_DIGITAL_MASK)
{
if ( lpMI->ulPelsWidth < lpDisplay->sMaxModeInfo.ulPelsWidth
|| lpMI->ulPelsHeight < lpDisplay->sMaxModeInfo.ulPelsHeight)
{
lpEventInfo->ulModeMinorFlag |= DAL_MODECHANGE_MINOR_RATIOMETRICEXPANSIONON;
break;
}
}
}
}
}
if(lpController->ulStateChangeFlags & GCO_EXPANSION_CHANGE)
{
lpEventInfo->ulModeMinorFlag |= DAL_MODECHANGE_MINOR_EXPANSIONONCHANGE;
}
}
/****************************Private*Routine*******************************\
*
* USHORT usChecksum()
*
* Performs checksum
*
\**************************************************************************/
USHORT usCheckSum(
LPVOID lpBuffer,
ULONG ulSize )
{
ULONG i;
ULONG ulSum = 0;
USHORT usResult = 0;
LPUSHORT lpusBuf = (LPUSHORT)lpBuffer;
if (lpBuffer)
{
for (i = 0; i < ulSize / sizeof(USHORT); i++)
{
ulSum += (ULONG)(*lpusBuf++);
}
if (ulSize % sizeof(USHORT))
{
// take care of the odd byte if any
ulSum += *((BYTE*)lpusBuf);
}
ulSum = (ulSum >> 16) + (ulSum & 0xFFFF); //add high-16 to low-16
ulSum += ulSum >> 16; //add carry
usResult = (USHORT)~ulSum; //one-complement, trucate to 16 bits
}
return usResult;
}
/****************************Private*Routine*******************************\
*
* ULONG bGetDetailedTimingIndexFromCache()
*
* Retrieves detailed timing for the specified mode from the cache.
*
\**************************************************************************/
ULONG bGetDetailedTimingIndexFromCache(
LPHW_DAL_EXTENSION lpHDE,
ULONG ulDisplayType,
LPDEVMODE_INFO lpMI )
{
ULONG i;
LPREGDETAILEDTIMINGINFO lpCache;
DALASSERT((NULL != lpHDE), "bGetDetailedTimingFromCache - invalide DAL handle!");
DALASSERT((NULL != lpMI), "bGetDetailedTimingFromCache - invalid mode handle!");
if (DALRULE1_READDETAILEDTIMINGPERMODE != lpHDE->ulDalRule1)
{
for (i = 0; i < MAX_CACHEDDTM; i++)
{
lpCache = &lpHDE->aCachedDetailedTimings[i];
if ( ((USHORT)lpMI->ulPelsWidth == lpCache->usPelsWidth )
&& ((USHORT)lpMI->ulPelsHeight == lpCache->usPelsHeight )
&& ((USHORT)lpMI->ulDisplayFrequency == lpCache->usDisplayFrequency))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -