Bug 625160 - Part 3 - Create prefs, one per nsIGfxInfo feature, that will override the built-in blacklist if they're set. r=jrmuizel

The plan is to set these prefs when we evaluate the downloaded blacklist.
This commit is contained in:
Joe Drew 2011-01-19 20:30:15 -05:00
parent e1abe24c57
commit 4409928c5b

View File

@ -39,14 +39,141 @@
#include "GfxInfoBase.h"
#include "GfxInfoWebGL.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefService.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsServiceManagerUtils.h"
using namespace mozilla::widget;
NS_IMPL_ISUPPORTS1(GfxInfoBase, nsIGfxInfo)
#define BLACKLIST_PREF_BRANCH "gfx.blacklist."
#define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
static const char*
GetPrefNameForFeature(PRInt32 aFeature)
{
const char* name = nsnull;
switch(aFeature) {
case nsIGfxInfo::FEATURE_DIRECT2D:
name = BLACKLIST_PREF_BRANCH "direct2d";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.direct3d9";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.direct3d10";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.direct3d10-1";
break;
case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.opengl";
break;
case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
name = BLACKLIST_PREF_BRANCH "webgl.opengl";
break;
case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
name = BLACKLIST_PREF_BRANCH "webgl.angle";
break;
default:
break;
};
return name;
}
// Returns the value of the pref for the relevant feature in aValue.
// If the pref doesn't exist, aValue is not touched, and returns false.
static bool
GetPrefValueForFeature(PRInt32 aFeature, PRInt32& aValue)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return false;
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 val;
if (NS_SUCCEEDED(prefs->GetIntPref(prefname, &val))) {
aValue = val;
return true;
}
}
return false;
}
static void
SetPrefValueForFeature(PRInt32 aFeature, PRInt32 aValue)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return;
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->SetIntPref(prefname, aValue);
}
}
static void
RemovePrefForFeature(PRInt32 aFeature)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return;
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->ClearUserPref(prefname);
}
}
static bool
GetPrefValueForDriverVersion(nsACString& aVersion)
{
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
nsXPIDLCString version;
if (NS_SUCCEEDED(prefs->GetCharPref(SUGGESTED_VERSION_PREF,
getter_Copies(version)))) {
aVersion = version;
return true;
}
}
return false;
}
static void
SetPrefValueForDriverVersion(const nsAString& aVersion)
{
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
nsCAutoString ver = NS_LossyConvertUTF16toASCII(aVersion);
prefs->SetCharPref(SUGGESTED_VERSION_PREF,
PromiseFlatCString(ver).get());
}
}
static void
RemovePrefForDriverVersion()
{
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->ClearUserPref(SUGGESTED_VERSION_PREF);
}
}
NS_IMETHODIMP
GfxInfoBase::GetFeatureStatus(PRInt32 aFeature, PRInt32* aStatus NS_OUTPARAM)
{
if (GetPrefValueForFeature(aFeature, *aStatus))
return NS_OK;
nsString version;
return GetFeatureStatusImpl(aFeature, aStatus, version);
}
@ -55,10 +182,17 @@ NS_IMETHODIMP
GfxInfoBase::GetFeatureSuggestedDriverVersion(PRInt32 aFeature,
nsAString& aVersion NS_OUTPARAM)
{
nsCString version;
if (GetPrefValueForDriverVersion(version)) {
aVersion = NS_ConvertASCIItoUTF16(version);
return NS_OK;
}
PRInt32 status;
return GetFeatureStatusImpl(aFeature, &status, aVersion);
}
NS_IMETHODIMP
GfxInfoBase::GetWebGLParameter(const nsAString& aParam,
nsAString& aResult NS_OUTPARAM)