Bug 650723. Add ClearType parameter data to about:support. r=gavin,jrmuizel

This commit is contained in:
John Daggett 2011-05-09 14:56:27 +09:00
parent 0afd743418
commit 9476a3a424
11 changed files with 218 additions and 10 deletions

View File

@ -785,6 +785,97 @@ gfxWindowsPlatform::GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion
aVersion.Assign(NS_ConvertUTF8toUTF16(buf));
}
void
gfxWindowsPlatform::GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams)
{
HKEY hKey, subKey;
DWORD i, rv, size, type;
WCHAR displayName[256], subkeyName[256];
aParams.Clear();
// construct subkeys based on HKLM subkeys, assume they are same for HKCU
rv = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"Software\\Microsoft\\Avalon.Graphics",
0, KEY_READ, &hKey);
if (rv != ERROR_SUCCESS) {
return;
}
// enumerate over subkeys
for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) {
size = NS_ARRAY_LENGTH(displayName);
rv = RegEnumKeyExW(hKey, i, displayName, &size, NULL, NULL, NULL, NULL);
if (rv != ERROR_SUCCESS) {
continue;
}
ClearTypeParameterInfo ctinfo;
ctinfo.displayName.Assign(displayName);
DWORD subrv, value;
bool foundData = false;
swprintf_s(subkeyName, NS_ARRAY_LENGTH(subkeyName),
L"Software\\Microsoft\\Avalon.Graphics\\%s", displayName);
// subkey for gamma, pixel structure
subrv = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
subkeyName, 0, KEY_QUERY_VALUE, &subKey);
if (subrv == ERROR_SUCCESS) {
size = sizeof(value);
subrv = RegQueryValueExW(subKey, L"GammaLevel", NULL, &type,
(LPBYTE)&value, &size);
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
foundData = true;
ctinfo.gamma = value;
}
size = sizeof(value);
subrv = RegQueryValueExW(subKey, L"PixelStructure", NULL, &type,
(LPBYTE)&value, &size);
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
foundData = true;
ctinfo.pixelStructure = value;
}
RegCloseKey(subKey);
}
// subkey for cleartype level, enhanced contrast
subrv = RegOpenKeyExW(HKEY_CURRENT_USER,
subkeyName, 0, KEY_QUERY_VALUE, &subKey);
if (subrv == ERROR_SUCCESS) {
size = sizeof(value);
subrv = RegQueryValueExW(subKey, L"ClearTypeLevel", NULL, &type,
(LPBYTE)&value, &size);
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
foundData = true;
ctinfo.clearTypeLevel = value;
}
size = sizeof(value);
subrv = RegQueryValueExW(subKey, L"EnhancedContrastLevel",
NULL, &type, (LPBYTE)&value, &size);
if (subrv == ERROR_SUCCESS && type == REG_DWORD) {
foundData = true;
ctinfo.enhancedContrast = value;
}
RegCloseKey(subKey);
}
if (foundData) {
aParams.AppendElement(ctinfo);
}
}
RegCloseKey(hKey);
}
void
gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
{
@ -830,19 +921,19 @@ gfxWindowsPlatform::SetupClearTypeParams(nsIPrefBranch *aPrefBranch)
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_GAMMA,
&value))) {
if (value >= 1000 && value <= 2200) {
gamma = (FLOAT)value / 1000.0;
gamma = FLOAT(value / 1000.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_CONTRAST,
&value))) {
if (value >= 0 && value <= 1000) {
contrast = (FLOAT)value / 100.0;
contrast = FLOAT(value / 100.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_LEVEL,
&value))) {
if (value >= 0 && value <= 100) {
level = (FLOAT)value / 100.0;
level = FLOAT(value / 100.0);
}
}
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_STRUCTURE,

View File

@ -114,6 +114,19 @@ struct DCFromContext {
PRBool needsRelease;
};
// ClearType parameters set by running ClearType tuner
struct ClearTypeParameterInfo {
ClearTypeParameterInfo() :
gamma(-1), pixelStructure(-1), clearTypeLevel(-1), enhancedContrast(-1)
{ }
nsString displayName; // typically just 'DISPLAY1'
PRInt32 gamma;
PRInt32 pixelStructure;
PRInt32 clearTypeLevel;
PRInt32 enhancedContrast;
};
class THEBES_API gfxWindowsPlatform : public gfxPlatform {
public:
gfxWindowsPlatform();
@ -236,6 +249,9 @@ public:
static void GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion);
// returns ClearType tuning information for each display
static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
void SetupClearTypeParams(nsIPrefBranch *aPrefBranch);

View File

@ -259,11 +259,17 @@ function populateGraphicsSection() {
try {
dwEnabled = gfxInfo.DWriteEnabled + " (" + gfxInfo.DWriteVersion + ")";
} catch(e) {}
trGraphics.push(createParentElement("tr", [
createHeader(bundle.GetStringFromName("directWriteEnabled")),
createElement("td", dwEnabled),
]));
pushInfoRow(trGraphics, "directWriteEnabled", dwEnabled);
var cleartypeParams = "";
try {
cleartypeParams = gfxInfo.cleartypeParameters;
} catch(e) {
cleartypeParams = bundle.GetStringFromName("clearTypeParametersNotFound");
}
pushInfoRow(trGraphics, "clearTypeParameters", cleartypeParams);
}
#endif
var webglrenderer;

View File

@ -1,5 +1,6 @@
# LOCALIZATION NOTE In the following string, "Direct2D" is a proper noun and should not be translated.
# Feel free to leave english strings if there are no good translations, these are only used in about:support
# LOCALIZATION NOTE In the following strings, "Direct2D", "DirectWrite" and "ClearType"
# are proper nouns and should not be translated. Feel free to leave english strings if
# there are no good translations, these are only used in about:support
# LOCALIZATION NOTE: This can be localized with a more generic term, like
# "Graphics-accelerated Windows". It describes a number of windows, e.g.:
@ -21,6 +22,8 @@ blockedOSVersion = Blocked for your operating system version.
direct2DEnabled = Direct2D Enabled
directWriteEnabled = DirectWrite Enabled
clearTypeParameters = ClearType Parameters
clearTypeParametersNotFound = ClearType parameters not found
adapterDescription = Adapter Description
adapterVendorID = Vendor ID
adapterDeviceID = Device ID

View File

@ -40,7 +40,7 @@
/* NOTE: this interface is completely undesigned, not stable and likely to change */
[scriptable, uuid(5c5de1e7-f7f4-46b4-9ced-03ab1f869eaf)]
[scriptable, uuid(a67c77af-2952-4028-93ab-e7bc3b43cf81)]
interface nsIGfxInfo : nsISupports
{
/*
@ -49,6 +49,7 @@ interface nsIGfxInfo : nsISupports
readonly attribute boolean D2DEnabled;
readonly attribute boolean DWriteEnabled;
readonly attribute DOMString DWriteVersion;
readonly attribute DOMString cleartypeParameters;
/**
* The name of the display adapter.

View File

@ -73,6 +73,13 @@ GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString cleartypeParameters; */
NS_IMETHODIMP
GfxInfo::GetCleartypeParameters(nsAString & aCleartypeParams)
{
return NS_ERROR_FAILURE;
}
nsresult
GfxInfo::Init()
{

View File

@ -55,6 +55,7 @@ public:
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteEnabled(PRBool *aDWriteEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteVersion(nsAString & aDwriteVersion);
NS_SCRIPTABLE NS_IMETHOD GetCleartypeParameters(nsAString & aCleartypeParams);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDescription(nsAString & aAdapterDescription);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDriver(nsAString & aAdapterDriver);
NS_SCRIPTABLE NS_IMETHOD GetAdapterVendorID(PRUint32 *aAdapterVendorID);

View File

@ -55,6 +55,7 @@ public:
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteEnabled(PRBool *aDWriteEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteVersion(nsAString & aDwriteVersion);
NS_SCRIPTABLE NS_IMETHOD GetCleartypeParameters(nsAString & aCleartypeParams);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDescription(nsAString & aAdapterDescription);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDriver(nsAString & aAdapterDriver);
NS_SCRIPTABLE NS_IMETHOD GetAdapterVendorID(PRUint32 *aAdapterVendorID);

View File

@ -114,6 +114,13 @@ GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString cleartypeParameters; */
NS_IMETHODIMP
GfxInfo::GetCleartypeParameters(nsAString & aCleartypeParams)
{
return NS_ERROR_FAILURE;
}
/* readonly attribute DOMString adapterDescription; */
NS_IMETHODIMP
GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)

View File

@ -106,6 +106,80 @@ GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
return NS_OK;
}
#define PIXEL_STRUCT_RGB 1
#define PIXEL_STRUCT_BGR 2
/* readonly attribute DOMString cleartypeParameters; */
NS_IMETHODIMP
GfxInfo::GetCleartypeParameters(nsAString & aCleartypeParams)
{
nsTArray<ClearTypeParameterInfo> clearTypeParams;
gfxWindowsPlatform::GetPlatform()->GetCleartypeParams(clearTypeParams);
PRUint32 d, numDisplays = clearTypeParams.Length();
bool displayNames = (numDisplays > 1);
bool foundData = false;
nsString outStr;
WCHAR valStr[256];
for (d = 0; d < numDisplays; d++) {
ClearTypeParameterInfo& params = clearTypeParams[d];
if (displayNames) {
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"%s [ ", params.displayName.get());
outStr.Append(valStr);
}
if (params.gamma >= 0) {
foundData = true;
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"Gamma: %d ", params.gamma);
outStr.Append(valStr);
}
if (params.pixelStructure >= 0) {
foundData = true;
if (params.pixelStructure == PIXEL_STRUCT_RGB ||
params.pixelStructure == PIXEL_STRUCT_BGR)
{
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"Pixel Structure: %s ",
(params.pixelStructure == PIXEL_STRUCT_RGB ?
L"RGB" : L"BGR"));
} else {
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"Pixel Structure: %d ", params.pixelStructure);
}
outStr.Append(valStr);
}
if (params.clearTypeLevel >= 0) {
foundData = true;
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"ClearType Level: %d ", params.clearTypeLevel);
outStr.Append(valStr);
}
if (params.enhancedContrast >= 0) {
foundData = true;
swprintf_s(valStr, NS_ARRAY_LENGTH(valStr),
L"Enhanced Contrast: %d ", params.enhancedContrast);
outStr.Append(valStr);
}
if (displayNames) {
outStr.Append(L"] ");
}
}
if (foundData) {
aCleartypeParams.Assign(outStr);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
/* XXX: GfxInfo doesn't handle multiple GPUs. We should try to do that. Bug #591057 */
static nsresult GetKeyValue(const WCHAR* keyLocation, const WCHAR* keyName, nsAString& destString, int type)

View File

@ -59,6 +59,7 @@ public:
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteEnabled(PRBool *aDWriteEnabled);
NS_SCRIPTABLE NS_IMETHOD GetDWriteVersion(nsAString & aDwriteVersion);
NS_SCRIPTABLE NS_IMETHOD GetCleartypeParameters(nsAString & aCleartypeParams);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDescription(nsAString & aAdapterDescription);
NS_SCRIPTABLE NS_IMETHOD GetAdapterDriver(nsAString & aAdapterDriver);
NS_SCRIPTABLE NS_IMETHOD GetAdapterVendorID(PRUint32 *aAdapterVendorID);