widget/xpwidgets/GfxInfoBase.cpp

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* vim: se cin sw=2 ts=2 et : */
michael@0 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "mozilla/ArrayUtils.h"
michael@0 9
michael@0 10 #include "GfxInfoBase.h"
michael@0 11
michael@0 12 #include "GfxInfoWebGL.h"
michael@0 13 #include "GfxDriverInfo.h"
michael@0 14 #include "nsCOMPtr.h"
michael@0 15 #include "nsCOMArray.h"
michael@0 16 #include "nsAutoPtr.h"
michael@0 17 #include "nsString.h"
michael@0 18 #include "nsUnicharUtils.h"
michael@0 19 #include "mozilla/Services.h"
michael@0 20 #include "mozilla/Observer.h"
michael@0 21 #include "nsIObserver.h"
michael@0 22 #include "nsIObserverService.h"
michael@0 23 #include "nsIDOMElement.h"
michael@0 24 #include "nsIDOMHTMLCollection.h"
michael@0 25 #include "nsIDOMNode.h"
michael@0 26 #include "nsIDOMNodeList.h"
michael@0 27 #include "nsTArray.h"
michael@0 28 #include "nsXULAppAPI.h"
michael@0 29 #include "mozilla/Preferences.h"
michael@0 30 #include "mozilla/dom/ContentChild.h"
michael@0 31
michael@0 32 #if defined(MOZ_CRASHREPORTER)
michael@0 33 #include "nsExceptionHandler.h"
michael@0 34 #endif
michael@0 35
michael@0 36 using namespace mozilla::widget;
michael@0 37 using namespace mozilla;
michael@0 38 using mozilla::MutexAutoLock;
michael@0 39
michael@0 40 nsTArray<GfxDriverInfo>* GfxInfoBase::mDriverInfo;
michael@0 41 bool GfxInfoBase::mDriverInfoObserverInitialized;
michael@0 42
michael@0 43 // Observes for shutdown so that the child GfxDriverInfo list is freed.
michael@0 44 class ShutdownObserver : public nsIObserver
michael@0 45 {
michael@0 46 public:
michael@0 47 ShutdownObserver() {}
michael@0 48 virtual ~ShutdownObserver() {}
michael@0 49
michael@0 50 NS_DECL_ISUPPORTS
michael@0 51
michael@0 52 NS_IMETHOD Observe(nsISupports *subject, const char *aTopic,
michael@0 53 const char16_t *aData)
michael@0 54 {
michael@0 55 MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
michael@0 56
michael@0 57 delete GfxInfoBase::mDriverInfo;
michael@0 58 GfxInfoBase::mDriverInfo = nullptr;
michael@0 59
michael@0 60 for (uint32_t i = 0; i < DeviceFamilyMax; i++)
michael@0 61 delete GfxDriverInfo::mDeviceFamilies[i];
michael@0 62
michael@0 63 for (uint32_t i = 0; i < DeviceVendorMax; i++)
michael@0 64 delete GfxDriverInfo::mDeviceVendors[i];
michael@0 65
michael@0 66 return NS_OK;
michael@0 67 }
michael@0 68 };
michael@0 69
michael@0 70 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
michael@0 71
michael@0 72 void InitGfxDriverInfoShutdownObserver()
michael@0 73 {
michael@0 74 if (GfxInfoBase::mDriverInfoObserverInitialized)
michael@0 75 return;
michael@0 76
michael@0 77 GfxInfoBase::mDriverInfoObserverInitialized = true;
michael@0 78
michael@0 79 nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
michael@0 80 if (!observerService) {
michael@0 81 NS_WARNING("Could not get observer service!");
michael@0 82 return;
michael@0 83 }
michael@0 84
michael@0 85 ShutdownObserver *obs = new ShutdownObserver();
michael@0 86 observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
michael@0 87 }
michael@0 88
michael@0 89 using namespace mozilla::widget;
michael@0 90 using namespace mozilla;
michael@0 91
michael@0 92 NS_IMPL_ISUPPORTS(GfxInfoBase, nsIGfxInfo, nsIObserver, nsISupportsWeakReference)
michael@0 93
michael@0 94 #define BLACKLIST_PREF_BRANCH "gfx.blacklist."
michael@0 95 #define SUGGESTED_VERSION_PREF BLACKLIST_PREF_BRANCH "suggested-driver-version"
michael@0 96 #define BLACKLIST_ENTRY_TAG_NAME "gfxBlacklistEntry"
michael@0 97
michael@0 98 static const char*
michael@0 99 GetPrefNameForFeature(int32_t aFeature)
michael@0 100 {
michael@0 101 const char* name = nullptr;
michael@0 102 switch(aFeature) {
michael@0 103 case nsIGfxInfo::FEATURE_DIRECT2D:
michael@0 104 name = BLACKLIST_PREF_BRANCH "direct2d";
michael@0 105 break;
michael@0 106 case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
michael@0 107 name = BLACKLIST_PREF_BRANCH "layers.direct3d9";
michael@0 108 break;
michael@0 109 case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
michael@0 110 name = BLACKLIST_PREF_BRANCH "layers.direct3d10";
michael@0 111 break;
michael@0 112 case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
michael@0 113 name = BLACKLIST_PREF_BRANCH "layers.direct3d10-1";
michael@0 114 break;
michael@0 115 case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
michael@0 116 name = BLACKLIST_PREF_BRANCH "layers.opengl";
michael@0 117 break;
michael@0 118 case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
michael@0 119 name = BLACKLIST_PREF_BRANCH "webgl.opengl";
michael@0 120 break;
michael@0 121 case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
michael@0 122 name = BLACKLIST_PREF_BRANCH "webgl.angle";
michael@0 123 break;
michael@0 124 case nsIGfxInfo::FEATURE_WEBGL_MSAA:
michael@0 125 name = BLACKLIST_PREF_BRANCH "webgl.msaa";
michael@0 126 break;
michael@0 127 case nsIGfxInfo::FEATURE_STAGEFRIGHT:
michael@0 128 name = BLACKLIST_PREF_BRANCH "stagefright";
michael@0 129 break;
michael@0 130 default:
michael@0 131 break;
michael@0 132 };
michael@0 133
michael@0 134 return name;
michael@0 135 }
michael@0 136
michael@0 137 // Returns the value of the pref for the relevant feature in aValue.
michael@0 138 // If the pref doesn't exist, aValue is not touched, and returns false.
michael@0 139 static bool
michael@0 140 GetPrefValueForFeature(int32_t aFeature, int32_t& aValue)
michael@0 141 {
michael@0 142 const char *prefname = GetPrefNameForFeature(aFeature);
michael@0 143 if (!prefname)
michael@0 144 return false;
michael@0 145
michael@0 146 aValue = false;
michael@0 147 return NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue));
michael@0 148 }
michael@0 149
michael@0 150 static void
michael@0 151 SetPrefValueForFeature(int32_t aFeature, int32_t aValue)
michael@0 152 {
michael@0 153 const char *prefname = GetPrefNameForFeature(aFeature);
michael@0 154 if (!prefname)
michael@0 155 return;
michael@0 156
michael@0 157 Preferences::SetInt(prefname, aValue);
michael@0 158 }
michael@0 159
michael@0 160 static void
michael@0 161 RemovePrefForFeature(int32_t aFeature)
michael@0 162 {
michael@0 163 const char *prefname = GetPrefNameForFeature(aFeature);
michael@0 164 if (!prefname)
michael@0 165 return;
michael@0 166
michael@0 167 Preferences::ClearUser(prefname);
michael@0 168 }
michael@0 169
michael@0 170 static bool
michael@0 171 GetPrefValueForDriverVersion(nsCString& aVersion)
michael@0 172 {
michael@0 173 return NS_SUCCEEDED(Preferences::GetCString(SUGGESTED_VERSION_PREF,
michael@0 174 &aVersion));
michael@0 175 }
michael@0 176
michael@0 177 static void
michael@0 178 SetPrefValueForDriverVersion(const nsAString& aVersion)
michael@0 179 {
michael@0 180 Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
michael@0 181 }
michael@0 182
michael@0 183 static void
michael@0 184 RemovePrefForDriverVersion()
michael@0 185 {
michael@0 186 Preferences::ClearUser(SUGGESTED_VERSION_PREF);
michael@0 187 }
michael@0 188
michael@0 189 // <foo>Hello</foo> - "Hello" is stored as a child text node of the foo node.
michael@0 190 static bool
michael@0 191 BlacklistNodeToTextValue(nsIDOMNode *aBlacklistNode, nsAString& aValue)
michael@0 192 {
michael@0 193 nsAutoString value;
michael@0 194 if (NS_FAILED(aBlacklistNode->GetTextContent(value)))
michael@0 195 return false;
michael@0 196
michael@0 197 value.Trim(" \t\r\n");
michael@0 198 aValue = value;
michael@0 199
michael@0 200 return true;
michael@0 201 }
michael@0 202
michael@0 203 static OperatingSystem
michael@0 204 BlacklistOSToOperatingSystem(const nsAString& os)
michael@0 205 {
michael@0 206 if (os == NS_LITERAL_STRING("WINNT 5.1"))
michael@0 207 return DRIVER_OS_WINDOWS_XP;
michael@0 208 else if (os == NS_LITERAL_STRING("WINNT 5.2"))
michael@0 209 return DRIVER_OS_WINDOWS_SERVER_2003;
michael@0 210 else if (os == NS_LITERAL_STRING("WINNT 6.0"))
michael@0 211 return DRIVER_OS_WINDOWS_VISTA;
michael@0 212 else if (os == NS_LITERAL_STRING("WINNT 6.1"))
michael@0 213 return DRIVER_OS_WINDOWS_7;
michael@0 214 else if (os == NS_LITERAL_STRING("WINNT 6.2"))
michael@0 215 return DRIVER_OS_WINDOWS_8;
michael@0 216 else if (os == NS_LITERAL_STRING("WINNT 6.3"))
michael@0 217 return DRIVER_OS_WINDOWS_8_1;
michael@0 218 else if (os == NS_LITERAL_STRING("Linux"))
michael@0 219 return DRIVER_OS_LINUX;
michael@0 220 else if (os == NS_LITERAL_STRING("Darwin 9"))
michael@0 221 return DRIVER_OS_OS_X_10_5;
michael@0 222 else if (os == NS_LITERAL_STRING("Darwin 10"))
michael@0 223 return DRIVER_OS_OS_X_10_6;
michael@0 224 else if (os == NS_LITERAL_STRING("Darwin 11"))
michael@0 225 return DRIVER_OS_OS_X_10_7;
michael@0 226 else if (os == NS_LITERAL_STRING("Darwin 12"))
michael@0 227 return DRIVER_OS_OS_X_10_8;
michael@0 228 else if (os == NS_LITERAL_STRING("Android"))
michael@0 229 return DRIVER_OS_ANDROID;
michael@0 230 else if (os == NS_LITERAL_STRING("All"))
michael@0 231 return DRIVER_OS_ALL;
michael@0 232
michael@0 233 return DRIVER_OS_UNKNOWN;
michael@0 234 }
michael@0 235
michael@0 236 static GfxDeviceFamily*
michael@0 237 BlacklistDevicesToDeviceFamily(nsIDOMHTMLCollection* aDevices)
michael@0 238 {
michael@0 239 uint32_t length;
michael@0 240 if (NS_FAILED(aDevices->GetLength(&length)))
michael@0 241 return nullptr;
michael@0 242
michael@0 243 // For each <device>, get its device ID, and return a freshly-allocated
michael@0 244 // GfxDeviceFamily with the contents of that array.
michael@0 245 GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
michael@0 246
michael@0 247 for (uint32_t i = 0; i < length; ++i) {
michael@0 248 nsCOMPtr<nsIDOMNode> node;
michael@0 249 if (NS_FAILED(aDevices->Item(i, getter_AddRefs(node))) || !node)
michael@0 250 continue;
michael@0 251
michael@0 252 nsAutoString deviceValue;
michael@0 253 if (!BlacklistNodeToTextValue(node, deviceValue))
michael@0 254 continue;
michael@0 255
michael@0 256 deviceIds->AppendElement(deviceValue);
michael@0 257 }
michael@0 258
michael@0 259 return deviceIds;
michael@0 260 }
michael@0 261
michael@0 262 static int32_t
michael@0 263 BlacklistFeatureToGfxFeature(const nsAString& aFeature)
michael@0 264 {
michael@0 265 if (aFeature == NS_LITERAL_STRING("DIRECT2D"))
michael@0 266 return nsIGfxInfo::FEATURE_DIRECT2D;
michael@0 267 else if (aFeature == NS_LITERAL_STRING("DIRECT3D_9_LAYERS"))
michael@0 268 return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
michael@0 269 else if (aFeature == NS_LITERAL_STRING("DIRECT3D_10_LAYERS"))
michael@0 270 return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
michael@0 271 else if (aFeature == NS_LITERAL_STRING("DIRECT3D_10_1_LAYERS"))
michael@0 272 return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
michael@0 273 else if (aFeature == NS_LITERAL_STRING("OPENGL_LAYERS"))
michael@0 274 return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
michael@0 275 else if (aFeature == NS_LITERAL_STRING("WEBGL_OPENGL"))
michael@0 276 return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
michael@0 277 else if (aFeature == NS_LITERAL_STRING("WEBGL_ANGLE"))
michael@0 278 return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
michael@0 279 else if (aFeature == NS_LITERAL_STRING("WEBGL_MSAA"))
michael@0 280 return nsIGfxInfo::FEATURE_WEBGL_MSAA;
michael@0 281 else if (aFeature == NS_LITERAL_STRING("STAGEFRIGHT"))
michael@0 282 return nsIGfxInfo::FEATURE_STAGEFRIGHT;
michael@0 283 return 0;
michael@0 284 }
michael@0 285
michael@0 286 static int32_t
michael@0 287 BlacklistFeatureStatusToGfxFeatureStatus(const nsAString& aStatus)
michael@0 288 {
michael@0 289 if (aStatus == NS_LITERAL_STRING("NO_INFO"))
michael@0 290 return nsIGfxInfo::FEATURE_NO_INFO;
michael@0 291 else if (aStatus == NS_LITERAL_STRING("BLOCKED_DRIVER_VERSION"))
michael@0 292 return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
michael@0 293 else if (aStatus == NS_LITERAL_STRING("BLOCKED_DEVICE"))
michael@0 294 return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
michael@0 295 else if (aStatus == NS_LITERAL_STRING("DISCOURAGED"))
michael@0 296 return nsIGfxInfo::FEATURE_DISCOURAGED;
michael@0 297 else if (aStatus == NS_LITERAL_STRING("BLOCKED_OS_VERSION"))
michael@0 298 return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
michael@0 299
michael@0 300 // Do not allow it to set STATUS_UNKNOWN.
michael@0 301
michael@0 302 return nsIGfxInfo::FEATURE_NO_INFO;
michael@0 303 }
michael@0 304
michael@0 305 static VersionComparisonOp
michael@0 306 BlacklistComparatorToComparisonOp(const nsAString& op)
michael@0 307 {
michael@0 308 if (op == NS_LITERAL_STRING("LESS_THAN"))
michael@0 309 return DRIVER_LESS_THAN;
michael@0 310 else if (op == NS_LITERAL_STRING("LESS_THAN_OR_EQUAL"))
michael@0 311 return DRIVER_LESS_THAN_OR_EQUAL;
michael@0 312 else if (op == NS_LITERAL_STRING("GREATER_THAN"))
michael@0 313 return DRIVER_GREATER_THAN;
michael@0 314 else if (op == NS_LITERAL_STRING("GREATER_THAN_OR_EQUAL"))
michael@0 315 return DRIVER_GREATER_THAN_OR_EQUAL;
michael@0 316 else if (op == NS_LITERAL_STRING("EQUAL"))
michael@0 317 return DRIVER_EQUAL;
michael@0 318 else if (op == NS_LITERAL_STRING("NOT_EQUAL"))
michael@0 319 return DRIVER_NOT_EQUAL;
michael@0 320 else if (op == NS_LITERAL_STRING("BETWEEN_EXCLUSIVE"))
michael@0 321 return DRIVER_BETWEEN_EXCLUSIVE;
michael@0 322 else if (op == NS_LITERAL_STRING("BETWEEN_INCLUSIVE"))
michael@0 323 return DRIVER_BETWEEN_INCLUSIVE;
michael@0 324 else if (op == NS_LITERAL_STRING("BETWEEN_INCLUSIVE_START"))
michael@0 325 return DRIVER_BETWEEN_INCLUSIVE_START;
michael@0 326
michael@0 327 return DRIVER_COMPARISON_IGNORED;
michael@0 328 }
michael@0 329
michael@0 330 // Arbitrarily returns the first |tagname| child of |element|.
michael@0 331 static bool
michael@0 332 BlacklistNodeGetChildByName(nsIDOMElement *element,
michael@0 333 const nsAString& tagname,
michael@0 334 nsIDOMNode** firstchild)
michael@0 335 {
michael@0 336 nsCOMPtr<nsIDOMHTMLCollection> nodelist;
michael@0 337 if (NS_FAILED(element->GetElementsByTagName(tagname,
michael@0 338 getter_AddRefs(nodelist))) ||
michael@0 339 !nodelist) {
michael@0 340 return false;
michael@0 341 }
michael@0 342
michael@0 343 nsCOMPtr<nsIDOMNode> node;
michael@0 344 if (NS_FAILED(nodelist->Item(0, getter_AddRefs(node))) || !node)
michael@0 345 return false;
michael@0 346
michael@0 347 node.forget(firstchild);
michael@0 348 return true;
michael@0 349 }
michael@0 350
michael@0 351 /*
michael@0 352
michael@0 353 <gfxBlacklistEntry>
michael@0 354 <os>WINNT 6.0</os>
michael@0 355 <vendor>0x8086</vendor>
michael@0 356 <devices>
michael@0 357 <device>0x2582</device>
michael@0 358 <device>0x2782</device>
michael@0 359 </devices>
michael@0 360 <feature> DIRECT3D_10_LAYERS </feature>
michael@0 361 <featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
michael@0 362 <driverVersion> 8.52.322.2202 </driverVersion>
michael@0 363 <driverVersionComparator> LESS_THAN_OR_EQUAL </driverVersionComparator>
michael@0 364 </gfxBlacklistEntry>
michael@0 365
michael@0 366 */
michael@0 367 static bool
michael@0 368 BlacklistEntryToDriverInfo(nsIDOMNode* aBlacklistEntry,
michael@0 369 GfxDriverInfo& aDriverInfo)
michael@0 370 {
michael@0 371 nsAutoString nodename;
michael@0 372 if (NS_FAILED(aBlacklistEntry->GetNodeName(nodename)) ||
michael@0 373 nodename != NS_LITERAL_STRING(BLACKLIST_ENTRY_TAG_NAME)) {
michael@0 374 return false;
michael@0 375 }
michael@0 376
michael@0 377 nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aBlacklistEntry);
michael@0 378 if (!element)
michael@0 379 return false;
michael@0 380
michael@0 381 nsCOMPtr<nsIDOMNode> dataNode;
michael@0 382 nsAutoString dataValue;
michael@0 383
michael@0 384 // <os>WINNT 6.0</os>
michael@0 385 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("os"),
michael@0 386 getter_AddRefs(dataNode))) {
michael@0 387 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 388 aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
michael@0 389 }
michael@0 390
michael@0 391 // <osversion>14</osversion> currently only used for Android
michael@0 392 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("osversion"),
michael@0 393 getter_AddRefs(dataNode))) {
michael@0 394 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 395 aDriverInfo.mOperatingSystemVersion = strtoul(NS_LossyConvertUTF16toASCII(dataValue).get(),
michael@0 396 nullptr, 10);
michael@0 397 }
michael@0 398
michael@0 399 // <vendor>0x8086</vendor>
michael@0 400 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("vendor"),
michael@0 401 getter_AddRefs(dataNode))) {
michael@0 402 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 403 aDriverInfo.mAdapterVendor = dataValue;
michael@0 404 }
michael@0 405
michael@0 406 // <devices>
michael@0 407 // <device>0x2582</device>
michael@0 408 // <device>0x2782</device>
michael@0 409 // </devices>
michael@0 410 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("devices"),
michael@0 411 getter_AddRefs(dataNode))) {
michael@0 412 nsCOMPtr<nsIDOMElement> devicesElement = do_QueryInterface(dataNode);
michael@0 413 if (devicesElement) {
michael@0 414
michael@0 415 // Get only the <device> nodes, because BlacklistDevicesToDeviceFamily
michael@0 416 // assumes it is passed no other nodes.
michael@0 417 nsCOMPtr<nsIDOMHTMLCollection> devices;
michael@0 418 if (NS_SUCCEEDED(devicesElement->GetElementsByTagName(NS_LITERAL_STRING("device"),
michael@0 419 getter_AddRefs(devices)))) {
michael@0 420 GfxDeviceFamily* deviceIds = BlacklistDevicesToDeviceFamily(devices);
michael@0 421 if (deviceIds) {
michael@0 422 // Get GfxDriverInfo to adopt the devices array we created.
michael@0 423 aDriverInfo.mDeleteDevices = true;
michael@0 424 aDriverInfo.mDevices = deviceIds;
michael@0 425 }
michael@0 426 }
michael@0 427 }
michael@0 428 }
michael@0 429
michael@0 430 // <feature> DIRECT3D_10_LAYERS </feature>
michael@0 431 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("feature"),
michael@0 432 getter_AddRefs(dataNode))) {
michael@0 433 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 434 aDriverInfo.mFeature = BlacklistFeatureToGfxFeature(dataValue);
michael@0 435 }
michael@0 436
michael@0 437 // <featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
michael@0 438 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("featureStatus"),
michael@0 439 getter_AddRefs(dataNode))) {
michael@0 440 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 441 aDriverInfo.mFeatureStatus = BlacklistFeatureStatusToGfxFeatureStatus(dataValue);
michael@0 442 }
michael@0 443
michael@0 444 // <driverVersion> 8.52.322.2202 </driverVersion>
michael@0 445 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("driverVersion"),
michael@0 446 getter_AddRefs(dataNode))) {
michael@0 447 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 448 uint64_t version;
michael@0 449 if (ParseDriverVersion(dataValue, &version))
michael@0 450 aDriverInfo.mDriverVersion = version;
michael@0 451 }
michael@0 452
michael@0 453 // <driverVersionComparator> LESS_THAN_OR_EQUAL </driverVersionComparator>
michael@0 454 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("driverVersionComparator"),
michael@0 455 getter_AddRefs(dataNode))) {
michael@0 456 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 457 aDriverInfo.mComparisonOp = BlacklistComparatorToComparisonOp(dataValue);
michael@0 458 }
michael@0 459
michael@0 460 // <model>foo</model>
michael@0 461 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("model"),
michael@0 462 getter_AddRefs(dataNode))) {
michael@0 463 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 464 aDriverInfo.mModel = dataValue;
michael@0 465 }
michael@0 466 // <product>foo</product>
michael@0 467 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("product"),
michael@0 468 getter_AddRefs(dataNode))) {
michael@0 469 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 470 aDriverInfo.mProduct = dataValue;
michael@0 471 }
michael@0 472 // <manufacturer>foo</manufacturer>
michael@0 473 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("manufacturer"),
michael@0 474 getter_AddRefs(dataNode))) {
michael@0 475 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 476 aDriverInfo.mManufacturer = dataValue;
michael@0 477 }
michael@0 478 // <hardware>foo</hardware>
michael@0 479 if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("hardware"),
michael@0 480 getter_AddRefs(dataNode))) {
michael@0 481 BlacklistNodeToTextValue(dataNode, dataValue);
michael@0 482 aDriverInfo.mHardware = dataValue;
michael@0 483 }
michael@0 484
michael@0 485 // We explicitly ignore unknown elements.
michael@0 486
michael@0 487 return true;
michael@0 488 }
michael@0 489
michael@0 490 static void
michael@0 491 BlacklistEntriesToDriverInfo(nsIDOMHTMLCollection* aBlacklistEntries,
michael@0 492 nsTArray<GfxDriverInfo>& aDriverInfo)
michael@0 493 {
michael@0 494 uint32_t length;
michael@0 495 if (NS_FAILED(aBlacklistEntries->GetLength(&length)))
michael@0 496 return;
michael@0 497
michael@0 498 aDriverInfo.Clear();
michael@0 499 aDriverInfo.SetLength(length);
michael@0 500 for (uint32_t i = 0; i < length; ++i) {
michael@0 501 nsCOMPtr<nsIDOMNode> blacklistEntry;
michael@0 502 if (NS_SUCCEEDED(aBlacklistEntries->Item(i,
michael@0 503 getter_AddRefs(blacklistEntry))) &&
michael@0 504 blacklistEntry) {
michael@0 505 GfxDriverInfo di;
michael@0 506 if (BlacklistEntryToDriverInfo(blacklistEntry, di)) {
michael@0 507 aDriverInfo[i] = di;
michael@0 508 }
michael@0 509 // Prevent di falling out of scope from destroying the devices.
michael@0 510 di.mDeleteDevices = false;
michael@0 511 }
michael@0 512 }
michael@0 513 }
michael@0 514
michael@0 515 NS_IMETHODIMP
michael@0 516 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
michael@0 517 const char16_t* aData)
michael@0 518 {
michael@0 519 if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
michael@0 520 nsCOMPtr<nsIDOMElement> gfxItems = do_QueryInterface(aSubject);
michael@0 521 if (gfxItems) {
michael@0 522 nsCOMPtr<nsIDOMHTMLCollection> blacklistEntries;
michael@0 523 if (NS_SUCCEEDED(gfxItems->
michael@0 524 GetElementsByTagName(NS_LITERAL_STRING(BLACKLIST_ENTRY_TAG_NAME),
michael@0 525 getter_AddRefs(blacklistEntries))) &&
michael@0 526 blacklistEntries)
michael@0 527 {
michael@0 528 nsTArray<GfxDriverInfo> driverInfo;
michael@0 529 BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
michael@0 530 EvaluateDownloadedBlacklist(driverInfo);
michael@0 531 }
michael@0 532 }
michael@0 533 }
michael@0 534
michael@0 535 return NS_OK;
michael@0 536 }
michael@0 537
michael@0 538 GfxInfoBase::GfxInfoBase()
michael@0 539 : mFailureCount(0)
michael@0 540 , mMutex("GfxInfoBase")
michael@0 541 {
michael@0 542 }
michael@0 543
michael@0 544 GfxInfoBase::~GfxInfoBase()
michael@0 545 {
michael@0 546 }
michael@0 547
michael@0 548 nsresult
michael@0 549 GfxInfoBase::Init()
michael@0 550 {
michael@0 551 InitGfxDriverInfoShutdownObserver();
michael@0 552
michael@0 553 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
michael@0 554 if (os) {
michael@0 555 os->AddObserver(this, "blocklist-data-gfxItems", true);
michael@0 556 }
michael@0 557
michael@0 558 return NS_OK;
michael@0 559 }
michael@0 560
michael@0 561 NS_IMETHODIMP
michael@0 562 GfxInfoBase::GetFeatureStatus(int32_t aFeature, int32_t* aStatus)
michael@0 563 {
michael@0 564 if (GetPrefValueForFeature(aFeature, *aStatus))
michael@0 565 return NS_OK;
michael@0 566
michael@0 567 if (XRE_GetProcessType() == GeckoProcessType_Content) {
michael@0 568 // Delegate to the parent process.
michael@0 569 mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
michael@0 570 bool success;
michael@0 571 cc->SendGetGraphicsFeatureStatus(aFeature, aStatus, &success);
michael@0 572 return success ? NS_OK : NS_ERROR_FAILURE;
michael@0 573 }
michael@0 574
michael@0 575 nsString version;
michael@0 576 nsTArray<GfxDriverInfo> driverInfo;
michael@0 577 return GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo);
michael@0 578 }
michael@0 579
michael@0 580 int32_t
michael@0 581 GfxInfoBase::FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& info,
michael@0 582 nsAString& aSuggestedVersion,
michael@0 583 int32_t aFeature,
michael@0 584 OperatingSystem os)
michael@0 585 {
michael@0 586 int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
michael@0 587
michael@0 588 nsAutoString adapterVendorID;
michael@0 589 nsAutoString adapterDeviceID;
michael@0 590 nsAutoString adapterDriverVersionString;
michael@0 591 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
michael@0 592 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
michael@0 593 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
michael@0 594 {
michael@0 595 return 0;
michael@0 596 }
michael@0 597
michael@0 598 #if defined(XP_WIN) || defined(ANDROID)
michael@0 599 uint64_t driverVersion;
michael@0 600 ParseDriverVersion(adapterDriverVersionString, &driverVersion);
michael@0 601 #endif
michael@0 602
michael@0 603 uint32_t i = 0;
michael@0 604 for (; i < info.Length(); i++) {
michael@0 605 if (info[i].mOperatingSystem != DRIVER_OS_ALL &&
michael@0 606 info[i].mOperatingSystem != os)
michael@0 607 {
michael@0 608 continue;
michael@0 609 }
michael@0 610
michael@0 611 if (info[i].mOperatingSystemVersion && info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
michael@0 612 continue;
michael@0 613 }
michael@0 614
michael@0 615 if (!info[i].mAdapterVendor.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll), nsCaseInsensitiveStringComparator()) &&
michael@0 616 !info[i].mAdapterVendor.Equals(adapterVendorID, nsCaseInsensitiveStringComparator())) {
michael@0 617 continue;
michael@0 618 }
michael@0 619
michael@0 620 if (info[i].mDevices != GfxDriverInfo::allDevices && info[i].mDevices->Length()) {
michael@0 621 bool deviceMatches = false;
michael@0 622 for (uint32_t j = 0; j < info[i].mDevices->Length(); j++) {
michael@0 623 if ((*info[i].mDevices)[j].Equals(adapterDeviceID, nsCaseInsensitiveStringComparator())) {
michael@0 624 deviceMatches = true;
michael@0 625 break;
michael@0 626 }
michael@0 627 }
michael@0 628
michael@0 629 if (!deviceMatches) {
michael@0 630 continue;
michael@0 631 }
michael@0 632 }
michael@0 633
michael@0 634 bool match = false;
michael@0 635
michael@0 636 if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
michael@0 637 continue;
michael@0 638 }
michael@0 639 if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
michael@0 640 continue;
michael@0 641 }
michael@0 642 if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
michael@0 643 continue;
michael@0 644 }
michael@0 645 if (!info[i].mManufacturer.IsEmpty() && !info[i].mManufacturer.Equals(Manufacturer())) {
michael@0 646 continue;
michael@0 647 }
michael@0 648
michael@0 649 #if defined(XP_WIN) || defined(ANDROID)
michael@0 650 switch (info[i].mComparisonOp) {
michael@0 651 case DRIVER_LESS_THAN:
michael@0 652 match = driverVersion < info[i].mDriverVersion;
michael@0 653 break;
michael@0 654 case DRIVER_LESS_THAN_OR_EQUAL:
michael@0 655 match = driverVersion <= info[i].mDriverVersion;
michael@0 656 break;
michael@0 657 case DRIVER_GREATER_THAN:
michael@0 658 match = driverVersion > info[i].mDriverVersion;
michael@0 659 break;
michael@0 660 case DRIVER_GREATER_THAN_OR_EQUAL:
michael@0 661 match = driverVersion >= info[i].mDriverVersion;
michael@0 662 break;
michael@0 663 case DRIVER_EQUAL:
michael@0 664 match = driverVersion == info[i].mDriverVersion;
michael@0 665 break;
michael@0 666 case DRIVER_NOT_EQUAL:
michael@0 667 match = driverVersion != info[i].mDriverVersion;
michael@0 668 break;
michael@0 669 case DRIVER_BETWEEN_EXCLUSIVE:
michael@0 670 match = driverVersion > info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
michael@0 671 break;
michael@0 672 case DRIVER_BETWEEN_INCLUSIVE:
michael@0 673 match = driverVersion >= info[i].mDriverVersion && driverVersion <= info[i].mDriverVersionMax;
michael@0 674 break;
michael@0 675 case DRIVER_BETWEEN_INCLUSIVE_START:
michael@0 676 match = driverVersion >= info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
michael@0 677 break;
michael@0 678 case DRIVER_COMPARISON_IGNORED:
michael@0 679 // We don't have a comparison op, so we match everything.
michael@0 680 match = true;
michael@0 681 break;
michael@0 682 default:
michael@0 683 NS_WARNING("Bogus op in GfxDriverInfo");
michael@0 684 break;
michael@0 685 }
michael@0 686 #else
michael@0 687 // We don't care what driver version it was. We only check OS version and if
michael@0 688 // the device matches.
michael@0 689 match = true;
michael@0 690 #endif
michael@0 691
michael@0 692 if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
michael@0 693 if (info[i].mFeature == GfxDriverInfo::allFeatures ||
michael@0 694 info[i].mFeature == aFeature)
michael@0 695 {
michael@0 696 status = info[i].mFeatureStatus;
michael@0 697 break;
michael@0 698 }
michael@0 699 }
michael@0 700 }
michael@0 701
michael@0 702 // Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
michael@0 703 // back to the Windows handler, so we must handle this here.
michael@0 704 #if defined(XP_WIN)
michael@0 705 if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
michael@0 706 if (info[i].mSuggestedVersion) {
michael@0 707 aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
michael@0 708 } else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
michael@0 709 info[i].mDriverVersion != GfxDriverInfo::allDriverVersions)
michael@0 710 {
michael@0 711 aSuggestedVersion.AppendPrintf("%lld.%lld.%lld.%lld",
michael@0 712 (info[i].mDriverVersion & 0xffff000000000000) >> 48,
michael@0 713 (info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
michael@0 714 (info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
michael@0 715 (info[i].mDriverVersion & 0x000000000000ffff));
michael@0 716 }
michael@0 717 }
michael@0 718 #endif
michael@0 719
michael@0 720 return status;
michael@0 721 }
michael@0 722
michael@0 723 nsresult
michael@0 724 GfxInfoBase::GetFeatureStatusImpl(int32_t aFeature,
michael@0 725 int32_t* aStatus,
michael@0 726 nsAString& aSuggestedVersion,
michael@0 727 const nsTArray<GfxDriverInfo>& aDriverInfo,
michael@0 728 OperatingSystem* aOS /* = nullptr */)
michael@0 729 {
michael@0 730 if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
michael@0 731 // Terminate now with the status determined by the derived type (OS-specific
michael@0 732 // code).
michael@0 733 return NS_OK;
michael@0 734 }
michael@0 735
michael@0 736 // If an operating system was provided by the derived GetFeatureStatusImpl,
michael@0 737 // grab it here. Otherwise, the OS is unknown.
michael@0 738 OperatingSystem os = DRIVER_OS_UNKNOWN;
michael@0 739 if (aOS)
michael@0 740 os = *aOS;
michael@0 741
michael@0 742 nsAutoString adapterVendorID;
michael@0 743 nsAutoString adapterDeviceID;
michael@0 744 nsAutoString adapterDriverVersionString;
michael@0 745 if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
michael@0 746 NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
michael@0 747 NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
michael@0 748 {
michael@0 749 return NS_OK;
michael@0 750 }
michael@0 751
michael@0 752 // Check if the device is blocked from the downloaded blocklist. If not, check
michael@0 753 // the static list after that. This order is used so that we can later escape
michael@0 754 // out of static blocks (i.e. if we were wrong or something was patched, we
michael@0 755 // can back out our static block without doing a release).
michael@0 756 int32_t status;
michael@0 757 if (aDriverInfo.Length()) {
michael@0 758 status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature, os);
michael@0 759 } else {
michael@0 760 if (!mDriverInfo) {
michael@0 761 mDriverInfo = new nsTArray<GfxDriverInfo>();
michael@0 762 }
michael@0 763 status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion, aFeature, os);
michael@0 764 }
michael@0 765
michael@0 766 // It's now done being processed. It's safe to set the status to NO_INFO.
michael@0 767 if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
michael@0 768 *aStatus = nsIGfxInfo::FEATURE_NO_INFO;
michael@0 769 } else {
michael@0 770 *aStatus = status;
michael@0 771 }
michael@0 772
michael@0 773 return NS_OK;
michael@0 774 }
michael@0 775
michael@0 776 NS_IMETHODIMP
michael@0 777 GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
michael@0 778 nsAString& aVersion)
michael@0 779 {
michael@0 780 nsCString version;
michael@0 781 if (GetPrefValueForDriverVersion(version)) {
michael@0 782 aVersion = NS_ConvertASCIItoUTF16(version);
michael@0 783 return NS_OK;
michael@0 784 }
michael@0 785
michael@0 786 int32_t status;
michael@0 787 nsTArray<GfxDriverInfo> driverInfo;
michael@0 788 return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo);
michael@0 789 }
michael@0 790
michael@0 791
michael@0 792 NS_IMETHODIMP
michael@0 793 GfxInfoBase::GetWebGLParameter(const nsAString& aParam,
michael@0 794 nsAString& aResult)
michael@0 795 {
michael@0 796 return GfxInfoWebGL::GetWebGLParameter(aParam, aResult);
michael@0 797 }
michael@0 798
michael@0 799 void
michael@0 800 GfxInfoBase::EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo)
michael@0 801 {
michael@0 802 int32_t features[] = {
michael@0 803 nsIGfxInfo::FEATURE_DIRECT2D,
michael@0 804 nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
michael@0 805 nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
michael@0 806 nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
michael@0 807 nsIGfxInfo::FEATURE_OPENGL_LAYERS,
michael@0 808 nsIGfxInfo::FEATURE_WEBGL_OPENGL,
michael@0 809 nsIGfxInfo::FEATURE_WEBGL_ANGLE,
michael@0 810 nsIGfxInfo::FEATURE_WEBGL_MSAA,
michael@0 811 nsIGfxInfo::FEATURE_STAGEFRIGHT,
michael@0 812 0
michael@0 813 };
michael@0 814
michael@0 815 // For every feature we know about, we evaluate whether this blacklist has a
michael@0 816 // non-NO_INFO status. If it does, we set the pref we evaluate in
michael@0 817 // GetFeatureStatus above, so we don't need to hold on to this blacklist
michael@0 818 // anywhere permanent.
michael@0 819 int i = 0;
michael@0 820 while (features[i]) {
michael@0 821 int32_t status;
michael@0 822 nsAutoString suggestedVersion;
michael@0 823 if (NS_SUCCEEDED(GetFeatureStatusImpl(features[i], &status,
michael@0 824 suggestedVersion,
michael@0 825 aDriverInfo))) {
michael@0 826 switch (status) {
michael@0 827 default:
michael@0 828 case nsIGfxInfo::FEATURE_NO_INFO:
michael@0 829 RemovePrefForFeature(features[i]);
michael@0 830 break;
michael@0 831
michael@0 832 case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
michael@0 833 if (!suggestedVersion.IsEmpty()) {
michael@0 834 SetPrefValueForDriverVersion(suggestedVersion);
michael@0 835 } else {
michael@0 836 RemovePrefForDriverVersion();
michael@0 837 }
michael@0 838 // FALLTHROUGH
michael@0 839
michael@0 840 case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
michael@0 841 case nsIGfxInfo::FEATURE_DISCOURAGED:
michael@0 842 case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
michael@0 843 SetPrefValueForFeature(features[i], status);
michael@0 844 break;
michael@0 845 }
michael@0 846 }
michael@0 847
michael@0 848 ++i;
michael@0 849 }
michael@0 850 }
michael@0 851
michael@0 852 NS_IMETHODIMP_(void)
michael@0 853 GfxInfoBase::LogFailure(const nsACString &failure)
michael@0 854 {
michael@0 855 MutexAutoLock lock(mMutex);
michael@0 856 /* We only keep the first 9 failures */
michael@0 857 if (mFailureCount < ArrayLength(mFailures)) {
michael@0 858 mFailures[mFailureCount++] = failure;
michael@0 859
michael@0 860 /* record it in the crash notes too */
michael@0 861 #if defined(MOZ_CRASHREPORTER)
michael@0 862 CrashReporter::AppendAppNotesToCrashReport(failure);
michael@0 863 #endif
michael@0 864 }
michael@0 865
michael@0 866 }
michael@0 867
michael@0 868 /* void getFailures ([optional] out unsigned long failureCount, [array, size_is (failureCount), retval] out string failures); */
michael@0 869 /* XPConnect method of returning arrays is very ugly. Would not recommend. Fallable nsMemory::Alloc makes things worse */
michael@0 870 NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t *failureCount, char ***failures)
michael@0 871 {
michael@0 872
michael@0 873 NS_ENSURE_ARG_POINTER(failureCount);
michael@0 874 NS_ENSURE_ARG_POINTER(failures);
michael@0 875
michael@0 876 *failures = nullptr;
michael@0 877 *failureCount = mFailureCount;
michael@0 878
michael@0 879 if (*failureCount != 0) {
michael@0 880 *failures = (char**)nsMemory::Alloc(*failureCount * sizeof(char*));
michael@0 881 if (!failures)
michael@0 882 return NS_ERROR_OUT_OF_MEMORY;
michael@0 883
michael@0 884 /* copy over the failure messages into the array we just allocated */
michael@0 885 for (uint32_t i = 0; i < *failureCount; i++) {
michael@0 886 nsCString& flattenedFailureMessage(mFailures[i]);
michael@0 887 (*failures)[i] = (char*)nsMemory::Clone(flattenedFailureMessage.get(), flattenedFailureMessage.Length() + 1);
michael@0 888
michael@0 889 if (!(*failures)[i]) {
michael@0 890 /* <sarcasm> I'm too afraid to use an inline function... </sarcasm> */
michael@0 891 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, (*failures));
michael@0 892 return NS_ERROR_OUT_OF_MEMORY;
michael@0 893 }
michael@0 894 }
michael@0 895 }
michael@0 896
michael@0 897 return NS_OK;
michael@0 898 }
michael@0 899
michael@0 900 nsTArray<GfxInfoCollectorBase*> *sCollectors;
michael@0 901
michael@0 902 static void
michael@0 903 InitCollectors()
michael@0 904 {
michael@0 905 if (!sCollectors)
michael@0 906 sCollectors = new nsTArray<GfxInfoCollectorBase*>;
michael@0 907 }
michael@0 908
michael@0 909 nsresult GfxInfoBase::GetInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aResult)
michael@0 910 {
michael@0 911 InitCollectors();
michael@0 912 InfoObject obj(aCx);
michael@0 913
michael@0 914 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
michael@0 915 (*sCollectors)[i]->GetInfo(obj);
michael@0 916 }
michael@0 917
michael@0 918 // Some example property definitions
michael@0 919 // obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
michael@0 920 // obj.DefineProperty("renderer", mRendererIDsString);
michael@0 921 // obj.DefineProperty("five", 5);
michael@0 922
michael@0 923 if (!obj.mOk) {
michael@0 924 return NS_ERROR_FAILURE;
michael@0 925 }
michael@0 926
michael@0 927 aResult.setObject(*obj.mObj);
michael@0 928 return NS_OK;
michael@0 929 }
michael@0 930
michael@0 931 void
michael@0 932 GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector)
michael@0 933 {
michael@0 934 InitCollectors();
michael@0 935 sCollectors->AppendElement(collector);
michael@0 936 }
michael@0 937
michael@0 938 void
michael@0 939 GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector)
michael@0 940 {
michael@0 941 InitCollectors();
michael@0 942 for (uint32_t i = 0; i < sCollectors->Length(); i++) {
michael@0 943 if ((*sCollectors)[i] == collector) {
michael@0 944 sCollectors->RemoveElementAt(i);
michael@0 945 break;
michael@0 946 }
michael@0 947 }
michael@0 948 if (sCollectors->IsEmpty()) {
michael@0 949 delete sCollectors;
michael@0 950 sCollectors = nullptr;
michael@0 951 }
michael@0 952 }
michael@0 953
michael@0 954 GfxInfoCollectorBase::GfxInfoCollectorBase()
michael@0 955 {
michael@0 956 GfxInfoBase::AddCollector(this);
michael@0 957 }
michael@0 958
michael@0 959 GfxInfoCollectorBase::~GfxInfoCollectorBase()
michael@0 960 {
michael@0 961 GfxInfoBase::RemoveCollector(this);
michael@0 962 }

mercurial