Bug 625160 - Part 4 - Register for the blocklist service's gfxInfo notifications, and convert that DOM tree heirarchy into a GfxDriverInfo. r=jrmuizel,mossop

This commit is contained in:
Joe Drew 2011-01-19 20:33:51 -05:00
parent 05afe3a844
commit 4409587cdb
11 changed files with 480 additions and 43 deletions

View File

@ -77,12 +77,12 @@ GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
return NS_ERROR_FAILURE;
}
void
nsresult
GfxInfo::Init()
{
return GfxInfoBase::Init();
}
/* readonly attribute DOMString adapterDescription; */
NS_IMETHODIMP
GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)

View File

@ -50,9 +50,6 @@ namespace widget {
class GfxInfo : public GfxInfoBase
{
public:
GfxInfo() {Init();}
virtual ~GfxInfo() {}
// We only declare the subset of nsIGfxInfo that we actually implement. The
// rest is brought forward from GfxInfoBase.
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
@ -69,13 +66,14 @@ public:
using GfxInfoBase::GetFeatureSuggestedDriverVersion;
using GfxInfoBase::GetWebGLParameter;
virtual nsresult Init();
protected:
virtual nsresult GetFeatureStatusImpl(PRInt32 aFeature, PRInt32 *aStatus, nsAString & aSuggestedDriverVersion);
private:
void Init();
void AddCrashReportAnnotations();
nsString mRendererIDsString;
nsString mAdapterRAMString;

View File

@ -103,7 +103,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListShortcut)
namespace mozilla {
namespace widget {
NS_GENERIC_FACTORY_CONSTRUCTOR(GfxInfo)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init);
}
}

View File

@ -50,9 +50,6 @@ namespace widget {
class GfxInfo : public GfxInfoBase
{
public:
GfxInfo() {Init();}
virtual ~GfxInfo() {}
// We only declare the subset of nsIGfxInfo that we actually implement. The
// rest is brought forward from GfxInfoBase.
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
@ -69,13 +66,14 @@ public:
using GfxInfoBase::GetFeatureSuggestedDriverVersion;
using GfxInfoBase::GetWebGLParameter;
virtual nsresult Init();
protected:
virtual nsresult GetFeatureStatusImpl(PRInt32 aFeature, PRInt32 *aStatus, nsAString & aSuggestedDriverVersion);
private:
void Init();
void AddCrashReportAnnotations();
nsString mRendererIDsString;
nsString mAdapterRAMString;

View File

@ -52,18 +52,20 @@
using namespace mozilla::widget;
void
nsresult
GfxInfo::Init()
{
NS_TIME_FUNCTION;
nsresult rv = GfxInfoBase::Init();
CGLRendererInfoObj renderer = 0;
GLint rendererCount = 0;
memset(mRendererIDs, 0, sizeof(mRendererIDs));
if (CGLQueryRendererInfo(0xffffffff, &renderer, &rendererCount) != kCGLNoError)
return;
return rv;
rendererCount = (GLint) PR_MIN(rendererCount, (GLint) NS_ARRAY_LENGTH(mRendererIDs));
for (GLint i = 0; i < rendererCount; i++) {
@ -88,6 +90,8 @@ GfxInfo::Init()
CGLDestroyRendererInfo(renderer);
AddCrashReportAnnotations();
return rv;
}
NS_IMETHODIMP

View File

@ -170,11 +170,13 @@ static void normalizeDriverId(nsString& driverid) {
* */
#define DEVICE_KEY_PREFIX L"\\Registry\\Machine\\"
void
nsresult
GfxInfo::Init()
{
NS_TIME_FUNCTION;
nsresult rv = GfxInfoBase::Init();
DISPLAY_DEVICEW displayDevice;
displayDevice.cb = sizeof(displayDevice);
int deviceIndex = 0;
@ -193,7 +195,7 @@ GfxInfo::Init()
if (wcsnlen(displayDevice.DeviceKey, NS_ARRAY_LENGTH(displayDevice.DeviceKey))
== NS_ARRAY_LENGTH(displayDevice.DeviceKey)) {
// we did not find a NULL
return;
return rv;
}
mDeviceKeyDebug = displayDevice.DeviceKey;
@ -202,7 +204,7 @@ GfxInfo::Init()
/* check that DeviceKey begins with DEVICE_KEY_PREFIX */
/* some systems have a DeviceKey starting with \REGISTRY\Machine\ so we need to compare case insenstively */
if (_wcsnicmp(displayDevice.DeviceKey, DEVICE_KEY_PREFIX, NS_ARRAY_LENGTH(DEVICE_KEY_PREFIX)-1) != 0)
return;
return rv;
// chop off DEVICE_KEY_PREFIX
mDeviceKey = displayDevice.DeviceKey + NS_ARRAY_LENGTH(DEVICE_KEY_PREFIX)-1;
@ -223,7 +225,7 @@ GfxInfo::Init()
L"System\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}",
0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &key);
if (result != ERROR_SUCCESS) {
return;
return rv;
}
nsAutoString wantedDriverId(mDeviceID);
@ -256,8 +258,9 @@ GfxInfo::Init()
RegCloseKey(key);
AddCrashReportAnnotations();
return rv;
}
/* readonly attribute DOMString adapterDescription; */
@ -509,20 +512,20 @@ static const GfxDriverInfo driverInfo[] = {
/*
* Implement special Direct2D blocklist from bug 595364
*/
{ DRIVER_OS_ALL,
vendorIntel, deviceFamilyIntelBlockDirect2D,
GfxDriverInfo( DRIVER_OS_ALL,
vendorIntel, (GfxDeviceFamily) deviceFamilyIntelBlockDirect2D,
nsIGfxInfo::FEATURE_DIRECT2D, nsIGfxInfo::FEATURE_BLOCKED_DEVICE,
DRIVER_LESS_THAN, allDriverVersions },
DRIVER_LESS_THAN, allDriverVersions ),
/* implement the blocklist from bug 594877
* Block all features on any drivers before this, as there's a crash when a MS Hotfix is installed.
* The crash itself is Direct2D-related, but for safety we block all features.
*/
#define IMPLEMENT_INTEL_DRIVER_BLOCKLIST(winVer, devFamily, driverVer) \
{ winVer, \
vendorIntel, devFamily, \
GfxDriverInfo( winVer, \
vendorIntel, (GfxDeviceFamily) devFamily, \
allFeatures, nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION, \
DRIVER_LESS_THAN, driverVer },
DRIVER_LESS_THAN, driverVer ),
IMPLEMENT_INTEL_DRIVER_BLOCKLIST(DRIVER_OS_WINDOWS_XP, deviceFamilyIntelGMA500, V(6,14,11,1018))
IMPLEMENT_INTEL_DRIVER_BLOCKLIST(DRIVER_OS_WINDOWS_XP, deviceFamilyIntelGMA900, V(6,14,10,4764))
@ -546,14 +549,14 @@ static const GfxDriverInfo driverInfo[] = {
IMPLEMENT_INTEL_DRIVER_BLOCKLIST(DRIVER_OS_WINDOWS_7, deviceFamilyIntelGMAX4500HD, V(8,15,10,2202))
/* OpenGL on any Intel hardware is discouraged */
{ DRIVER_OS_ALL,
vendorIntel, nsnull,
GfxDriverInfo( DRIVER_OS_ALL,
vendorIntel, GfxDriverInfo::allDevices,
nsIGfxInfo::FEATURE_OPENGL_LAYERS, nsIGfxInfo::FEATURE_DISCOURAGED,
DRIVER_LESS_THAN, allDriverVersions },
{ DRIVER_OS_ALL,
vendorIntel, nsnull,
DRIVER_LESS_THAN, allDriverVersions ),
GfxDriverInfo( DRIVER_OS_ALL,
vendorIntel, GfxDriverInfo::allDevices,
nsIGfxInfo::FEATURE_WEBGL_OPENGL, nsIGfxInfo::FEATURE_DISCOURAGED,
DRIVER_LESS_THAN, allDriverVersions },
DRIVER_LESS_THAN, allDriverVersions ),
/*
* NVIDIA entries
@ -563,7 +566,7 @@ static const GfxDriverInfo driverInfo[] = {
* AMD entries
*/
{ (OperatingSystem)0, 0, nsnull, 0 }
GfxDriverInfo()
};
static OperatingSystem

View File

@ -48,9 +48,6 @@ namespace widget {
class GfxInfo : public GfxInfoBase
{
public:
GfxInfo() {Init();}
virtual ~GfxInfo() {}
// We only declare the subset of nsIGfxInfo that we actually implement. The
// rest is brought forward from GfxInfoBase.
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(PRBool *aD2DEnabled);
@ -67,13 +64,14 @@ public:
using GfxInfoBase::GetFeatureSuggestedDriverVersion;
using GfxInfoBase::GetWebGLParameter;
virtual nsresult Init();
protected:
virtual nsresult GetFeatureStatusImpl(PRInt32 aFeature, PRInt32 *aStatus, nsAString & aSuggestedDriverVersion);
private:
void Init();
void AddCrashReportAnnotations();
nsString mDeviceString;
nsString mDeviceID;

View File

@ -36,13 +36,73 @@
* ***** END LICENSE BLOCK ***** */
#include "GfxDriverInfo.h"
#include "nsIGfxInfo.h"
namespace mozilla {
namespace widget {
using namespace mozilla::widget;
PRUint32 GfxDriverInfo::allAdapterVendors = 0;
PRInt32 GfxDriverInfo::allFeatures = 0;
GfxDeviceFamily GfxDriverInfo::allDevices = nsnull;
};
};
GfxDriverInfo::GfxDriverInfo()
: mOperatingSystem(DRIVER_OS_UNKNOWN),
mAdapterVendor(allAdapterVendors),
mDevices(allDevices),
mDeleteDevices(false),
mFeature(allFeatures),
mFeatureStatus(nsIGfxInfo::FEATURE_NO_INFO),
mComparisonOp(DRIVER_UNKNOWN_COMPARISON),
mDriverVersion(0),
mDriverVersionMax(0)
{}
GfxDriverInfo::GfxDriverInfo(OperatingSystem os, PRUint32 vendor,
GfxDeviceFamily devices,
PRInt32 feature, PRInt32 featureStatus,
VersionComparisonOp op,
PRUint64 driverVersion,
bool ownDevices /* = false */)
: mOperatingSystem(os),
mAdapterVendor(vendor),
mDevices(devices),
mDeleteDevices(ownDevices),
mFeature(feature),
mFeatureStatus(featureStatus),
mComparisonOp(op),
mDriverVersion(driverVersion),
mDriverVersionMax(0)
{}
GfxDriverInfo::GfxDriverInfo(const GfxDriverInfo& aOrig)
: mOperatingSystem(aOrig.mOperatingSystem),
mAdapterVendor(aOrig.mAdapterVendor),
mFeature(aOrig.mFeature),
mFeatureStatus(aOrig.mFeatureStatus),
mComparisonOp(aOrig.mComparisonOp),
mDriverVersion(aOrig.mDriverVersion),
mDriverVersionMax(aOrig.mDriverVersionMax)
{
// If we're managing the lifetime of the devices array, we have to make a
// copy of the original's array.
if (aOrig.mDeleteDevices) {
PRUint32 count = 0;
const PRUint32 *device = aOrig.mDevices;
while (*device) {
count++;
device++;
}
mDevices = new PRUint32[count + 1];
memcpy(mDevices, aOrig.mDevices, sizeof(PRUint32) * (count + 1));
} else {
mDevices = aOrig.mDevices;
}
mDeleteDevices = aOrig.mDeleteDevices;
}
GfxDriverInfo::~GfxDriverInfo()
{
if (mDeleteDevices)
delete[] mDevices;
}

View File

@ -71,10 +71,20 @@ enum VersionComparisonOp {
};
/* A zero-terminated array of devices to match, or all devices */
typedef const PRUint32 *GfxDeviceFamily;
typedef PRUint32 *GfxDeviceFamily;
struct GfxDriverInfo
{
// If |ownDevices| is true, you are transferring ownership of the devices
// array, and it will be deleted when this GfxDriverInfo is destroyed.
GfxDriverInfo(OperatingSystem os, PRUint32 vendor, GfxDeviceFamily devices,
PRInt32 feature, PRInt32 featureStatus, VersionComparisonOp op,
PRUint64 driverVersion, bool ownDevices = false);
GfxDriverInfo();
GfxDriverInfo(const GfxDriverInfo&);
~GfxDriverInfo();
OperatingSystem mOperatingSystem;
PRUint32 mAdapterVendor;
@ -83,6 +93,10 @@ struct GfxDriverInfo
GfxDeviceFamily mDevices;
static GfxDeviceFamily allDevices;
// Whether the mDevices array should be deleted when this structure is
// deallocated. False by default.
bool mDeleteDevices;
/* A feature from nsIGfxInfo, or all features */
PRInt32 mFeature;
static PRInt32 allFeatures;

View File

@ -38,19 +38,32 @@
* ***** END LICENSE BLOCK ***** */
#include "GfxInfoBase.h"
#include "GfxInfoWebGL.h"
#include "GfxDriverInfo.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefService.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/Services.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#include "nsTArray.h"
using namespace mozilla::widget;
NS_IMPL_ISUPPORTS1(GfxInfoBase, nsIGfxInfo)
NS_IMPL_ISUPPORTS3(GfxInfoBase, nsIGfxInfo, nsIObserver, nsISupportsWeakReference)
#define BLACKLIST_PREF_BRANCH "gfx.blacklist."
#define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
#define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
static const char*
GetPrefNameForFeature(PRInt32 aFeature)
@ -168,6 +181,340 @@ RemovePrefForDriverVersion()
}
}
// <foo>Hello</foo> - "Hello" is stored as a child text node of the foo node.
static bool
BlacklistNodeToTextValue(nsIDOMNode *aBlacklistNode, nsAString& aValue)
{
nsCOMPtr<nsIDOM3Node> dom3 = do_QueryInterface(aBlacklistNode);
if (!dom3)
return false;
nsAutoString value;
if (NS_FAILED(dom3->GetTextContent(value)))
return false;
value.Trim(" \t\r\n");
aValue = value;
return true;
}
static OperatingSystem
BlacklistOSToOperatingSystem(const nsAString& os)
{
if (os == NS_LITERAL_STRING("WINNT 5.0"))
return DRIVER_OS_WINDOWS_2000;
else if (os == NS_LITERAL_STRING("WINNT 5.1"))
return DRIVER_OS_WINDOWS_XP;
else if (os == NS_LITERAL_STRING("WINNT 5.2"))
return DRIVER_OS_WINDOWS_SERVER_2003;
else if (os == NS_LITERAL_STRING("WINNT 6.0"))
return DRIVER_OS_WINDOWS_VISTA;
else if (os == NS_LITERAL_STRING("WINNT 6.1"))
return DRIVER_OS_WINDOWS_7;
else if (os == NS_LITERAL_STRING("Linux"))
return DRIVER_OS_LINUX;
else if (os == NS_LITERAL_STRING("Darwin 9"))
return DRIVER_OS_OS_X_10_5;
else if (os == NS_LITERAL_STRING("Darwin 10"))
return DRIVER_OS_OS_X_10_6;
else if (os == NS_LITERAL_STRING("All"))
return DRIVER_OS_ALL;
return DRIVER_OS_UNKNOWN;
}
static PRUint32
BlacklistHexToInt(const nsAString& aHex)
{
PRInt32 err;
// nsAString doesn't have .ToInteger() :(
nsAutoString hex(aHex);
PRInt32 value = hex.ToInteger(&err, 16);
if (NS_FAILED(err))
return 0;
return (PRUint32) value;
}
static PRUint32*
BlacklistDevicesToDeviceFamily(nsIDOMNodeList* aDevices)
{
PRUint32 length;
if (NS_FAILED(aDevices->GetLength(&length)))
return nsnull;
// For each <device>, get its device ID, and return a freshly-allocated array
// with the contents of that array.
nsAutoArrayPtr<PRUint32> deviceIds(new PRUint32[length + 1]);
memset(deviceIds, 0, sizeof(PRUint32) * (length + 1));
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> node;
if (NS_FAILED(aDevices->Item(i, getter_AddRefs(node))) || !node)
continue;
nsAutoString deviceValue;
if (!BlacklistNodeToTextValue(node, deviceValue))
continue;
deviceIds[i] = BlacklistHexToInt(deviceValue);
}
return deviceIds.forget();
}
static PRInt32
BlacklistFeatureToGfxFeature(const nsAString& aFeature)
{
if (aFeature == NS_LITERAL_STRING("DIRECT2D"))
return nsIGfxInfo::FEATURE_DIRECT2D;
else if (aFeature == NS_LITERAL_STRING("DIRECT3D_9_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
else if (aFeature == NS_LITERAL_STRING("DIRECT3D_10_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
else if (aFeature == NS_LITERAL_STRING("DIRECT3D_10_1_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
else if (aFeature == NS_LITERAL_STRING("OPENGL_LAYERS"))
return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
else if (aFeature == NS_LITERAL_STRING("WEBGL_OPENGL"))
return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
else if (aFeature == NS_LITERAL_STRING("WEBGL_ANGLE"))
return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
return 0;
}
static PRInt32
BlacklistFeatureStatusToGfxFeatureStatus(const nsAString& aStatus)
{
if (aStatus == NS_LITERAL_STRING("NO_INFO"))
return nsIGfxInfo::FEATURE_NO_INFO;
else if (aStatus == NS_LITERAL_STRING("BLOCKED_DRIVER_VERSION"))
return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
else if (aStatus == NS_LITERAL_STRING("BLOCKED_DEVICE"))
return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
else if (aStatus == NS_LITERAL_STRING("DISCOURAGED"))
return nsIGfxInfo::FEATURE_DISCOURAGED;
else if (aStatus == NS_LITERAL_STRING("BLOCKED_OS_VERSION"))
return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
return nsIGfxInfo::FEATURE_NO_INFO;
}
static VersionComparisonOp
BlacklistComparatorToComparisonOp(const nsAString& op)
{
if (op == NS_LITERAL_STRING("LESS_THAN"))
return DRIVER_LESS_THAN;
else if (op == NS_LITERAL_STRING("LESS_THAN_OR_EQUAL"))
return DRIVER_LESS_THAN_OR_EQUAL;
else if (op == NS_LITERAL_STRING("GREATER_THAN"))
return DRIVER_GREATER_THAN;
else if (op == NS_LITERAL_STRING("GREATER_THAN_OR_EQUAL"))
return DRIVER_GREATER_THAN_OR_EQUAL;
else if (op == NS_LITERAL_STRING("EQUAL"))
return DRIVER_EQUAL;
else if (op == NS_LITERAL_STRING("NOT_EQUAL"))
return DRIVER_NOT_EQUAL;
else if (op == NS_LITERAL_STRING("BETWEEN_EXCLUSIVE"))
return DRIVER_BETWEEN_EXCLUSIVE;
else if (op == NS_LITERAL_STRING("BETWEEN_INCLUSIVE"))
return DRIVER_BETWEEN_INCLUSIVE;
else if (op == NS_LITERAL_STRING("BETWEEN_INCLUSIVE_START"))
return DRIVER_BETWEEN_INCLUSIVE_START;
return DRIVER_UNKNOWN_COMPARISON;
}
// Arbitrarily returns the first |tagname| child of |element|.
static bool
BlacklistNodeGetChildByName(nsIDOMElement *element,
const nsAString& tagname,
nsIDOMNode** firstchild)
{
nsCOMPtr<nsIDOMNodeList> nodelist;
if (NS_FAILED(element->GetElementsByTagName(tagname,
getter_AddRefs(nodelist))) ||
!nodelist) {
return false;
}
nsCOMPtr<nsIDOMNode> node;
if (NS_FAILED(nodelist->Item(0, getter_AddRefs(node))) || !node)
return false;
*firstchild = node.forget().get();
return true;
}
/*
<gfxBlacklistEntry>
<os>WINNT 6.0</os>
<vendor>0x8086</vendor>
<devices>
<device>0x2582</device>
<device>0x2782</device>
</devices>
<feature> DIRECT3D_10_LAYERS </feature>
<featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
<driverVersion> 8.52.322.2202 </driverVersion>
<driverVersionComparator> LESS_THAN_OR_EQUAL </driverVersionComparator>
</gfxBlacklistEntry>
*/
static bool
BlacklistEntryToDriverInfo(nsIDOMNode* aBlacklistEntry,
GfxDriverInfo& aDriverInfo)
{
nsAutoString nodename;
if (NS_FAILED(aBlacklistEntry->GetNodeName(nodename)) ||
nodename != NS_LITERAL_STRING(BLACKLIST_ENTRY_TAG_NAME)) {
return false;
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aBlacklistEntry);
if (!element)
return false;
nsCOMPtr<nsIDOMNode> dataNode;
nsAutoString dataValue;
// <os>WINNT 6.0</os>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("os"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
}
// <vendor>0x8086</vendor>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("vendor"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mAdapterVendor = BlacklistHexToInt(dataValue);
}
// <devices>
// <device>0x2582</device>
// <device>0x2782</device>
// </devices>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("devices"),
getter_AddRefs(dataNode))) {
nsCOMPtr<nsIDOMElement> devicesElement = do_QueryInterface(dataNode);
if (devicesElement) {
// Get only the <device> nodes, because BlacklistDevicesToDeviceFamily
// assumes it is passed no other nodes.
nsCOMPtr<nsIDOMNodeList> devices;
if (NS_SUCCEEDED(devicesElement->GetElementsByTagName(NS_LITERAL_STRING("device"),
getter_AddRefs(devices)))) {
PRUint32* deviceIds = BlacklistDevicesToDeviceFamily(devices);
if (deviceIds) {
// Get GfxDriverInfo to adopt the devices array we created.
aDriverInfo.mDeleteDevices = true;
aDriverInfo.mDevices = deviceIds;
}
}
}
}
// <feature> DIRECT3D_10_LAYERS </feature>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("feature"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mFeature = BlacklistFeatureToGfxFeature(dataValue);
}
// <featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("featureStatus"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mFeatureStatus = BlacklistFeatureStatusToGfxFeatureStatus(dataValue);
}
// <driverVersion> 8.52.322.2202 </driverVersion>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("driverVersion"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
PRUint64 version;
if (ParseDriverVersion(dataValue, &version))
aDriverInfo.mDriverVersion = version;
}
// <driverVersionComparator> LESS_THAN_OR_EQUAL </driverVersionComparator>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("driverVersionComparator"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mComparisonOp = BlacklistComparatorToComparisonOp(dataValue);
}
// We explicitly ignore unknown elements.
return true;
}
static void
BlacklistEntriesToDriverInfo(nsIDOMNodeList* aBlacklistEntries,
nsTArray<GfxDriverInfo>& aDriverInfo)
{
PRUint32 length;
if (NS_FAILED(aBlacklistEntries->GetLength(&length)))
return;
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> blacklistEntry;
if (NS_SUCCEEDED(aBlacklistEntries->Item(i,
getter_AddRefs(blacklistEntry))) &&
blacklistEntry) {
GfxDriverInfo di;
if (BlacklistEntryToDriverInfo(blacklistEntry, di)) {
aDriverInfo.AppendElement(di);
}
}
}
}
NS_IMETHODIMP
GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
{
if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
nsCOMPtr<nsIDOMElement> gfxItems = do_QueryInterface(aSubject);
if (gfxItems) {
nsCOMPtr<nsIDOMNodeList> blacklistEntries;
if (NS_SUCCEEDED(gfxItems->
GetElementsByTagName(NS_LITERAL_STRING(BLACKLIST_ENTRY_TAG_NAME),
getter_AddRefs(blacklistEntries))) &&
blacklistEntries)
{
nsTArray<GfxDriverInfo> driverInfo;
BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
}
}
}
return NS_OK;
}
GfxInfoBase::GfxInfoBase()
{
}
GfxInfoBase::~GfxInfoBase()
{
}
nsresult
GfxInfoBase::Init()
{
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "blocklist-data-gfxItems", PR_TRUE);
}
return NS_OK;
}
NS_IMETHODIMP
GfxInfoBase::GetFeatureStatus(PRInt32 aFeature, PRInt32* aStatus NS_OUTPARAM)
{

View File

@ -40,15 +40,24 @@
#ifndef __mozilla_widget_GfxInfoBase_h__
#define __mozilla_widget_GfxInfoBase_h__
#include <nsIGfxInfo.h>
#include "nsIGfxInfo.h"
#include "nsCOMPtr.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
namespace mozilla {
namespace widget {
class GfxInfoBase : public nsIGfxInfo
class GfxInfoBase : public nsIGfxInfo,
public nsIObserver,
public nsSupportsWeakReference
{
public:
GfxInfoBase();
virtual ~GfxInfoBase();
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
// We only declare a subset of the nsIGfxInfo interface. It's up to derived
// classes to implement the rest of the interface.
@ -61,6 +70,12 @@ public:
NS_SCRIPTABLE NS_IMETHOD GetFeatureSuggestedDriverVersion(PRInt32 aFeature, nsAString & _retval NS_OUTPARAM);
NS_SCRIPTABLE NS_IMETHOD GetWebGLParameter(const nsAString & aParam, nsAString & _retval NS_OUTPARAM);
// Initialization function. If you override this, you must call this class's
// version of Init first.
// Ideally, Init() would be void-return, but the rules of
// NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
virtual nsresult Init();
protected:
virtual nsresult GetFeatureStatusImpl(PRInt32 aFeature, PRInt32* aStatus,
nsAString& aSuggestedDriverVersion) = 0;