Files
palemoon27/widget/GfxInfoBase.cpp
T
roytam1 136569692c import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1212148 - Outline DialogValueHolder::Get() and create the variant directly. r=bz (1f3eb24a70)
- Bug 1210591, part 1 - Use nsVariantCC in various places. r=smaug (960ec7f9d3)
- Bug 1210591, part 2 - Cycle collect DataTransfer::mItems. r=smaug (3bc922fd42)
- Bug 931283, part 1 - Rename nsVariant to nsVariantBase. r=froydnj (1ba409004e)
- Bug 931283, part 2 - Split out nsVariant into a subclass. r=froydnj (6fc4012db0)
- Bug 931283, part 3 - Implement a cycle collected version of nsVariant. r=froydnj (9dd0e97d28)
- Bug 1208815 - Use the legacy opt-out in GetMozSourceNode to avoid crashes. r=bholley (b8aaa945fd)
- Bug 1217614 - Remove nsIDOMDataTransfer::mozGetDataAt and refactor associated code. r=bz (6a5a403776)
- Bug 1197002 - Use channel->Open2() in editor/libeditor/nsHTMLDataTransfer.cpp (r=sicking) (4995576e25)
- Bug 1169268 - Don't crash when pasting files. r=ndeakin (b52b5e9971)
- Bug 1156062 part 1b - Convert some callers of nsEditor::SplitNodeDeep; r=ehsan (c0ecbdf8ec)
- Bug 1156062 part 1c - Convert remaining callers of nsEditor::SplitNodeDeep; r=ehsan (e9cb446bef)
- Bug 1156062 part 1d - Clean up nsEditor::SplitNodeDeep; r=ehsan (d8513a605c)
- Bug 1156062 part 2 - Make GetBlockNodeParent and GetEnclosingTable return regular pointers; r=ehsan (8e80c4c53c)
- Bug 1156062 part 3 - New helper nsHTMLEditor::GetBlock; r=ehsan (9466c926f3)
- Bug 1145395 - Call nsINode::Length directly in nsHTMLEditor::CreateDOMFragmentFromPaste; r=ehsan (5b9d9b208c)
- Bug 1152229 Define FnLock as a KeyboardEvent.code value r=smaug (0f0ba16ba2)
- Bug 1192774 - Rename nsOuterWindowProxy::GetWindow to GetOuterWindow and add an assertion; r=khuey (5bbad7f98a)
- Bug 920734 - Part 1: Implement window.orientation and window.onorientationchange. r=baku (3f350de924)
- Bug 920734 - Part 2: Update tests to avoid using orientation as variable name. r=seth (a5c98bcc6f)
- Bug 1216072 - Pass aCallerIsChrome in more places. r=bz Bug 1215398 - Hoist the IsCallerChrome call in CanMoveResizeWindows to the script-only entry points. r=bz (3ff7d3d1a2)
- Bug 1107443. Make WindowProxy throw if you attempt to explicitly define a non-configurable property. r=peterv (d4659731fe)
- Bug 1196317 - Optimize CallbackObject::mCreationStack out from cycle collection graph when possible, r=mccr8 (6221298ec7)
- Bug 1184058 - AudioChannelAgent should be muted when used without a proper window object. r=alwu (3bc66c7727)
- Bug 1196361 - Remove the media.useAudioChannelService pref; r=baku (ba976d4402)
- Bug 1190040 - Part 2: Teach the audio channel service how to not notify audio-playback, and do that when a media element has no audio track; r=padenot (b163cbd6e2)
- Bug 1180940 - Changed return type of AudioDestinationNode::CreateAudioChannelAgent method to return errors, if any methods that it calls fail. Added code to handle the return value in AudioContext::Init(), and its callers. r=baku (03671277dc)
- Bug 1183304 - Unregister the actor when unlinked by CC. r=ehsan (ad0a3a7050)
- Bug 1191814 - WebSpeech synthesis API and AudioChannelService, r=eeejay (2140326485)
- Bug 1043165 - Part 1: Add TelephonyCall.disconnectedReason (webidl). r=hsinyi (a08a2e3b19)
- Bug 1043165 - Part 2: Add TelephonyCall.disconnectedReason (dom). r=hsinyi (1403f942fd)
- Bug 1043165 - Part 3: Add TelephonyCall.disconnectedReason (ril). r=hsinyi (cdb3991ed0)
- Bug 1043165 - Part 4: Update test cases. r=hsinyi (aa3f784b07)
- Bug 1131047 - Part 1: Obsolete some events (WebIDL). r=hsinyi (64e098a773)
- Bug 1131047 - Part 2: Obsolete some events (DOM). r=aknow (75caf5fa03)
- Bug 1161403 - Part 1: Deprecate internal states. r=aknow (dfd955bf8b)
- Bug 1161403 - Part 2: A new testcase. r=aknow (4798f3ec44)
- Bug 1129882 - create agent in telephony object. r=baku, r=hsinyi (1d7e7e44a4)
- Bug 1129882 - add mozInterrupt in telephony object. r=baku (f52465229b)
- Bug 1211511 - AudioChannelAgent::NotifyStartedPlaying and NotifyStoppedPlaying should use the same level of playback notification, r=roc (a73b0fda70)
- Bug 1187204 - AudioChannelService must exist before calling IsAudioChannelMutedByDefault(), r=alwu (665d082d4f)
- Bug 1089526 - Correct function name. r=baku (0706ced01f)
- Bug 1183925 - Part 1: Clean up the SpeakerManagerService shutdown; r=baku (7aefa655d5)
- Bug 1223734 - AudioChannelService should not be re-initialized after the XPCOM shutdown, r=smaug (1e35895d8d)
- Bug 1223734 - Add crashtest. r=baku (cfb753dcf2)
- Bug 1151992 - Use call state to decide the usages of output device. r=baku (37ea21895f)
- Bug 1215684 - Shut down AudioChannelService in the child process. r=mccr8 (389b137630)
- Bug 1183033 - Don't mute the system channel type. r=baku (da88f69119)
- Bug 1218396 - By default window-less AudioChannelAgents should be muted, r=alwu (3a74b6e8e0)
- Bug 1222902 - Create log system for the AudioChannel. r=baku. (4734efd27b)
- var-let (9849b3f3a9)
- Bug 1138354 - Add proxy authencation info for 'mozbrowserusernameandpasswordrequired' event. r=mayhemer (e1717f0113)
- Bug 1195801 - part 2: Tests for getStructuredData. r=kanru (221d9b4fa8)
- Bug 1169633 - [Browser API] getWebManifest(). r=kanru, r=bholley (904c043d16)
- Bug 1206581 - Implement notifyChannel() on AudioChannel API. r=kanru, r=baku. (42554161e7)
- Bug 1196654 - navigator.mozBrowserElementProxy for access Browser API methods from the embedded, r=kanru, sr=sicking (878b701d4b)
- Bug 1214133 - Preload ExtensionContent.jsm to get rid of the overhead. r=fabrice (50f6584735)
- Bug 1212321 - Stop painting on app launch. r=fabrice (a4cadc9577)
- Bug 1203068 - Add system type into kMozAudioChannelAttributeTable. r=baku (c908fef580)
- Bug 1208353 - Fix -Wshadow warnings in dom/audiochannel. r=padenot (85193d75a2)
- Bug 1184970 - Remove unused struct in AudioChannelService, r=ehsan (f0511a942b)
- Bug 1214491 - Rejigger entry points for nsGlobalWindow::Close. r=bz (6eccbffe1f)
- Bug 1212360. Split up the MozStorageChanged event into separate events for sessionstorage and localstorage. r=khuey (ff0047fe22)
- Bug 1162013. Process the Promise queue between adjacent setTimeout callback invocations when we're going through the callback list without returning to the event loop. r=smaug (f4966fa41e)
- Bug 1214491 - Remove CanCallerAccess check for XPIDL version of nsGlobalWindow::AddEventListener. r=bz (5bb993e1ea)
- Bug 1181176 - Pass along x and y position for context menus on Graphene. r=fabrice (652b528a92)
- Bug 1211481 - Expose screenX and screenY to context menu events. r=fabrice (e9679e9d6c)
- Bug 952456 - Part 2: Support copy image in BrowserElement. r=kchen (f91eb8ae95)
- Bug 952456 - Part 3: Enable test_copyimage.html on gonk/cocoa r=fabrice (be0d20fd99)
- Bug 1121463 - Support copy link on context menu. r=kanru (a981b7e05c)
- Backout c7c68c4389d6 (bug 1125713) for gaia app startup regression r=me (ed1d13993f)
- Bug 1178484 - Part 2: Regenerate gecko's in-tree parser. r=hsivone (42d5b50cf1)
- Bug 1164123 - Add support for a theme-group meta to make theme-color"themable". r=fabrice (40757cf461)
- Bug 1178484 - Part 4: Fire metachange event when a <meta> tag has Open Graph data. r=kanru (111cf1c43f)
- Bug 1178484 - Part 5: Test for metachange event when Open Graph property is loaded. r=kanru (0b464de5de)
- Bug 1156615 - (Browser API) ctrl/cmd/middle-click doesn't work if <a> element has children. r=kchen (673a7031f9)
- Bug 1210265 - Add a pref toggle for copying/pasting only plain text on B2G. r=timdream (4fbbad858e)
- Bug 1198522 - Add a flag to make sure customized menu is added. r=timdream, r=kanru (81e611997d)
- Bug 1168658 - Enable tracking protection in b2g r=francois (fc04c160ae)
- Bug 1189494 - Pass tracking information to BrowserElement's mozbrowsersecuritychange event. r=fabrice (bb24e94178)
- Bug 1170644 - Fix forced reflow in BrowserElementChildPreload. r=bz (73078e79fa)
- Bug 1178069 - Check devices capability before enable use of vp8 hardware acceleration using android.media.MediaCodecList and android.media.MediaCodecInfo r=jrmuizel (883351b87c)
- Bug 1164036 - Add an xpcshell test for graphics blocklist versioning. r=kats (c846c5b142)
- Bug 1183725 - Windows 10 not recognized in downloadable blocklist. r=bas (6a07f03ea3)
- Bug 1191404 - Update the comments to avoid confusion about what happens with blocklisting when the OS is unknown. No code change. r=milan (40bec16ce6)
- Bug 1215892 - Fix clang's -Wimplicit-fallthrough warnings in gfx. r=BenWa (83d160740c)
- var/const crashreporter (c9e5ccbb70)
- Bug 1225233 - Make MovableCellHasher a public interface, usable by embedders; r=jonco (603b00a836)
- Bug 1214508: SharedStubs - Part 1: Move the getprop stubs in to shared stub files, r=jandem (7cddae3b9e)
- Bug 1214508: SharedStubs - Part 2: Adjust the getprop stubs to report which engine they use, r=jandem (03ae066cad)
- Bug 1214508: SharedStubs - Part 3: Enable the getprop stubs in ionmonkey, r=jandem (e002db87c2)
- Bug 1214508: SharedStubs - Part 4: Make sure the frame pushed are set correctly for ion vmcalls, r=jandem (6238ed03c4)
- Bug 1214508: SharedStubs - Part 5: Fix ion vmcalls in shared stub, r=jandem (5a914ccfe6)
- Bug 1214508: SharedStubs - Part 6: Move the monitor stubs in to shared stub files, r=jandem (6f03cfaa1f)
- Bug 1214508: SharedStubs - Part 7: Adjust the getprop stubs to report which engine they use, r=jandem (e3849fde89)
- Bug 1214508: SharedStubs - Part 8: Dont sync for the decompiler in ion, r=jandem (7fe1a01bca)
- Bug 1214508: SharedStubs - Fix bustage in arm64, r=bustage on CLOSED TREE (0b60ba5974)
- Bug 1214508: SharedStubs - fix bustage, r=bustage (968a63544d)
- Bug 1212624 - Make WeakMapBase be a LinkedListElement, r=Waldo (744bb6eb8d)
- Bug 1223519 - Remove unused rekeying logic from WeakMap; r=sfink (3a4fe3b5df)
- Bug 1219288 - Ensure module environment object is not extensible and contains only non-configurable properties r=shu (0b9ac212b9)
2023-01-05 23:57:13 +08:00

1286 lines
41 KiB
C++

/* vim: se cin sw=2 ts=2 et : */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ArrayUtils.h"
#include "GfxInfoBase.h"
#include "GfxInfoWebGL.h"
#include "GfxDriverInfo.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsUnicharUtils.h"
#include "nsVersionComparator.h"
#include "mozilla/Services.h"
#include "mozilla/Observer.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
#include "nsIXULAppInfo.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Logging.h"
#include "gfxPrefs.h"
#include "gfxPlatform.h"
#if defined(MOZ_CRASHREPORTER)
#include "nsExceptionHandler.h"
#endif
using namespace mozilla::widget;
using namespace mozilla;
using mozilla::MutexAutoLock;
nsTArray<GfxDriverInfo>* GfxInfoBase::mDriverInfo;
bool GfxInfoBase::mDriverInfoObserverInitialized;
// Observes for shutdown so that the child GfxDriverInfo list is freed.
class ShutdownObserver : public nsIObserver
{
virtual ~ShutdownObserver() {}
public:
ShutdownObserver() {}
NS_DECL_ISUPPORTS
NS_IMETHOD Observe(nsISupports *subject, const char *aTopic,
const char16_t *aData) override
{
MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
delete GfxInfoBase::mDriverInfo;
GfxInfoBase::mDriverInfo = nullptr;
for (uint32_t i = 0; i < DeviceFamilyMax; i++)
delete GfxDriverInfo::mDeviceFamilies[i];
for (uint32_t i = 0; i < DeviceVendorMax; i++)
delete GfxDriverInfo::mDeviceVendors[i];
return NS_OK;
}
};
NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
void InitGfxDriverInfoShutdownObserver()
{
if (GfxInfoBase::mDriverInfoObserverInitialized)
return;
GfxInfoBase::mDriverInfoObserverInitialized = true;
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
if (!observerService) {
NS_WARNING("Could not get observer service!");
return;
}
ShutdownObserver *obs = new ShutdownObserver();
observerService->AddObserver(obs, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
}
using namespace mozilla::widget;
using namespace mozilla::gfx;
using namespace mozilla;
NS_IMPL_ISUPPORTS(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(int32_t aFeature)
{
const char* name = nullptr;
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_DIRECT3D_11_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.direct3d11";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
name = BLACKLIST_PREF_BRANCH "direct3d11angle";
break;
case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
name = BLACKLIST_PREF_BRANCH "hardwarevideodecoding";
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;
case nsIGfxInfo::FEATURE_WEBGL_MSAA:
name = BLACKLIST_PREF_BRANCH "webgl.msaa";
break;
case nsIGfxInfo::FEATURE_STAGEFRIGHT:
name = BLACKLIST_PREF_BRANCH "stagefright";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION:
name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
name = BLACKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
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(int32_t aFeature, int32_t& aValue)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return false;
aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
return NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue));
}
static void
SetPrefValueForFeature(int32_t aFeature, int32_t aValue)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return;
Preferences::SetInt(prefname, aValue);
}
static void
RemovePrefForFeature(int32_t aFeature)
{
const char *prefname = GetPrefNameForFeature(aFeature);
if (!prefname)
return;
Preferences::ClearUser(prefname);
}
static bool
GetPrefValueForDriverVersion(nsCString& aVersion)
{
return NS_SUCCEEDED(Preferences::GetCString(SUGGESTED_VERSION_PREF,
&aVersion));
}
static void
SetPrefValueForDriverVersion(const nsAString& aVersion)
{
Preferences::SetString(SUGGESTED_VERSION_PREF, aVersion);
}
static void
RemovePrefForDriverVersion()
{
Preferences::ClearUser(SUGGESTED_VERSION_PREF);
}
// <foo>Hello</foo> - "Hello" is stored as a child text node of the foo node.
static bool
BlacklistNodeToTextValue(nsIDOMNode *aBlacklistNode, nsAString& aValue)
{
nsAutoString value;
if (NS_FAILED(aBlacklistNode->GetTextContent(value)))
return false;
value.Trim(" \t\r\n");
aValue = value;
return true;
}
// <foo attr=Hello/> finds "Hello" if the aAttrName is "attr".
static bool
BlacklistAttrToTextValue(nsIDOMNode *aBlacklistNode,
const nsAString& aAttrName,
nsAString& aValue)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aBlacklistNode);
if (!element) {
return false;
}
nsAutoString value;
if (NS_FAILED(element->GetAttribute(aAttrName, value))) {
return false;
}
value.Trim(" \t\r\n");
aValue = value;
return true;
}
static OperatingSystem
BlacklistOSToOperatingSystem(const nsAString& os)
{
if (os.EqualsLiteral("WINNT 5.1"))
return DRIVER_OS_WINDOWS_XP;
else if (os.EqualsLiteral("WINNT 5.2"))
return DRIVER_OS_WINDOWS_SERVER_2003;
else if (os.EqualsLiteral("WINNT 6.0"))
return DRIVER_OS_WINDOWS_VISTA;
else if (os.EqualsLiteral("WINNT 6.1"))
return DRIVER_OS_WINDOWS_7;
else if (os.EqualsLiteral("WINNT 6.2"))
return DRIVER_OS_WINDOWS_8;
else if (os.EqualsLiteral("WINNT 6.3"))
return DRIVER_OS_WINDOWS_8_1;
else if (os.EqualsLiteral("WINNT 10.0"))
return DRIVER_OS_WINDOWS_10;
else if (os.EqualsLiteral("Linux"))
return DRIVER_OS_LINUX;
else if (os.EqualsLiteral("Darwin 9"))
return DRIVER_OS_OS_X_10_5;
else if (os.EqualsLiteral("Darwin 10"))
return DRIVER_OS_OS_X_10_6;
else if (os.EqualsLiteral("Darwin 11"))
return DRIVER_OS_OS_X_10_7;
else if (os.EqualsLiteral("Darwin 12"))
return DRIVER_OS_OS_X_10_8;
else if (os.EqualsLiteral("Darwin 13"))
return DRIVER_OS_OS_X_10_9;
else if (os.EqualsLiteral("Darwin 14"))
return DRIVER_OS_OS_X_10_10;
else if (os.EqualsLiteral("Android"))
return DRIVER_OS_ANDROID;
else if (os.EqualsLiteral("All"))
return DRIVER_OS_ALL;
return DRIVER_OS_UNKNOWN;
}
static GfxDeviceFamily*
BlacklistDevicesToDeviceFamily(nsIDOMHTMLCollection* aDevices)
{
uint32_t length;
if (NS_FAILED(aDevices->GetLength(&length)))
return nullptr;
// For each <device>, get its device ID, and return a freshly-allocated
// GfxDeviceFamily with the contents of that array.
GfxDeviceFamily* deviceIds = new GfxDeviceFamily;
for (uint32_t 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->AppendElement(deviceValue);
}
return deviceIds;
}
static int32_t
BlacklistFeatureToGfxFeature(const nsAString& aFeature)
{
MOZ_ASSERT(!aFeature.IsEmpty());
if (aFeature.EqualsLiteral("DIRECT2D"))
return nsIGfxInfo::FEATURE_DIRECT2D;
else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
return nsIGfxInfo::FEATURE_WEBGL_MSAA;
else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
return nsIGfxInfo::FEATURE_STAGEFRIGHT;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION;
// If we don't recognize the feature, it may be new, and something
// this version doesn't understand. So, nothing to do. This is
// different from feature not being specified at all, in which case
// this method should not get called and we should continue with the
// "all features" blocklisting.
return -1;
}
static int32_t
BlacklistFeatureStatusToGfxFeatureStatus(const nsAString& aStatus)
{
if (aStatus.EqualsLiteral("STATUS_OK"))
return nsIGfxInfo::FEATURE_STATUS_OK;
else if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION"))
return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
else if (aStatus.EqualsLiteral("BLOCKED_DEVICE"))
return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
else if (aStatus.EqualsLiteral("DISCOURAGED"))
return nsIGfxInfo::FEATURE_DISCOURAGED;
else if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION"))
return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
// Do not allow it to set STATUS_UNKNOWN. Also, we are not
// expecting the "mismatch" status showing up here.
return nsIGfxInfo::FEATURE_STATUS_OK;
}
static VersionComparisonOp
BlacklistComparatorToComparisonOp(const nsAString& op)
{
if (op.EqualsLiteral("LESS_THAN"))
return DRIVER_LESS_THAN;
else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
return DRIVER_LESS_THAN_OR_EQUAL;
else if (op.EqualsLiteral("GREATER_THAN"))
return DRIVER_GREATER_THAN;
else if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL"))
return DRIVER_GREATER_THAN_OR_EQUAL;
else if (op.EqualsLiteral("EQUAL"))
return DRIVER_EQUAL;
else if (op.EqualsLiteral("NOT_EQUAL"))
return DRIVER_NOT_EQUAL;
else if (op.EqualsLiteral("BETWEEN_EXCLUSIVE"))
return DRIVER_BETWEEN_EXCLUSIVE;
else if (op.EqualsLiteral("BETWEEN_INCLUSIVE"))
return DRIVER_BETWEEN_INCLUSIVE;
else if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START"))
return DRIVER_BETWEEN_INCLUSIVE_START;
return DRIVER_COMPARISON_IGNORED;
}
// Arbitrarily returns the first |tagname| child of |element|.
static bool
BlacklistNodeGetChildByName(nsIDOMElement *element,
const nsAString& tagname,
nsIDOMNode** firstchild)
{
nsCOMPtr<nsIDOMHTMLCollection> 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;
node.forget(firstchild);
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;
// If we get an application version to be zero, something is not working
// and we are not going to bother checking the blocklist versions.
// See TestGfxWidgets.cpp for how version comparison works.
// <versionRange minVersion="42.0a1" maxVersion="45.0"></versionRange>
static mozilla::Version zeroV("0");
static mozilla::Version appV(GfxInfoBase::GetApplicationVersion().get());
if (appV <= zeroV) {
gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Invalid application version " << GfxInfoBase::GetApplicationVersion().get();
} else if (BlacklistNodeGetChildByName(element,
NS_LITERAL_STRING("versionRange"),
getter_AddRefs(dataNode))) {
if (BlacklistAttrToTextValue(dataNode,
NS_LITERAL_STRING("minVersion"),
dataValue)) {
mozilla::Version minV(NS_ConvertUTF16toUTF8(dataValue).get());
if (minV > zeroV && appV < minV) {
// The version of the application is less than the minimal version
// this blocklist entry applies to, so we can just ignore it by
// returning false and letting the caller deal with it.
return false;
}
}
if (BlacklistAttrToTextValue(dataNode,
NS_LITERAL_STRING("maxVersion"),
dataValue)) {
mozilla::Version maxV(NS_ConvertUTF16toUTF8(dataValue).get());
if (maxV > zeroV && appV > maxV) {
// The version of the application is more than the maximal version
// this blocklist entry applies to, so we can just ignore it by
// returning false and letting the caller deal with it.
return false;
}
}
}
// <os>WINNT 6.0</os>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("os"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
}
// <osversion>14</osversion> currently only used for Android
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("osversion"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mOperatingSystemVersion = strtoul(NS_LossyConvertUTF16toASCII(dataValue).get(),
nullptr, 10);
}
// <vendor>0x8086</vendor>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("vendor"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mAdapterVendor = 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<nsIDOMHTMLCollection> devices;
if (NS_SUCCEEDED(devicesElement->GetElementsByTagName(NS_LITERAL_STRING("device"),
getter_AddRefs(devices)))) {
GfxDeviceFamily* 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);
if (aDriverInfo.mFeature < 0) {
// If we don't recognize the feature, we do not want to proceed.
gfxWarning() << "Unrecognized feature " << NS_ConvertUTF16toUTF8(dataValue).get();
return false;
}
}
// <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);
uint64_t 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);
}
// <model>foo</model>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("model"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mModel = dataValue;
}
// <product>foo</product>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("product"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mProduct = dataValue;
}
// <manufacturer>foo</manufacturer>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("manufacturer"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mManufacturer = dataValue;
}
// <hardware>foo</hardware>
if (BlacklistNodeGetChildByName(element, NS_LITERAL_STRING("hardware"),
getter_AddRefs(dataNode))) {
BlacklistNodeToTextValue(dataNode, dataValue);
aDriverInfo.mHardware = dataValue;
}
// We explicitly ignore unknown elements.
return true;
}
static void
BlacklistEntriesToDriverInfo(nsIDOMHTMLCollection* aBlacklistEntries,
nsTArray<GfxDriverInfo>& aDriverInfo)
{
uint32_t length;
if (NS_FAILED(aBlacklistEntries->GetLength(&length)))
return;
aDriverInfo.Clear();
aDriverInfo.SetLength(length);
for (uint32_t 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[i] = di;
// Prevent di falling out of scope from destroying the devices.
di.mDeleteDevices = false;
}
}
}
}
NS_IMETHODIMP
GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
nsCOMPtr<nsIDOMElement> gfxItems = do_QueryInterface(aSubject);
if (gfxItems) {
nsCOMPtr<nsIDOMHTMLCollection> blacklistEntries;
if (NS_SUCCEEDED(gfxItems->
GetElementsByTagName(NS_LITERAL_STRING(BLACKLIST_ENTRY_TAG_NAME),
getter_AddRefs(blacklistEntries))) &&
blacklistEntries)
{
nsTArray<GfxDriverInfo> driverInfo;
BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
EvaluateDownloadedBlacklist(driverInfo);
}
}
}
return NS_OK;
}
GfxInfoBase::GfxInfoBase()
: mMutex("GfxInfoBase")
{
}
GfxInfoBase::~GfxInfoBase()
{
}
nsresult
GfxInfoBase::Init()
{
InitGfxDriverInfoShutdownObserver();
gfxPrefs::GetSingleton();
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "blocklist-data-gfxItems", true);
}
return NS_OK;
}
NS_IMETHODIMP
GfxInfoBase::GetFeatureStatus(int32_t aFeature, int32_t* aStatus)
{
int32_t blocklistAll = gfxPrefs::BlocklistAll();
if (blocklistAll > 0) {
gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Forcing blocklisting all features";
*aStatus = FEATURE_BLOCKED_DEVICE;
return NS_OK;
} else if (blocklistAll < 0) {
gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false)) << "Ignoring any feature blocklisting.";
*aStatus = FEATURE_STATUS_OK;
return NS_OK;
}
if (GetPrefValueForFeature(aFeature, *aStatus))
return NS_OK;
if (XRE_IsContentProcess()) {
// Delegate to the parent process.
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
bool success;
cc->SendGetGraphicsFeatureStatus(aFeature, aStatus, &success);
return success ? NS_OK : NS_ERROR_FAILURE;
}
nsString version;
nsTArray<GfxDriverInfo> driverInfo;
return GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo);
}
int32_t
GfxInfoBase::FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& info,
nsAString& aSuggestedVersion,
int32_t aFeature,
OperatingSystem os)
{
int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
uint32_t i = 0;
for (; i < info.Length(); i++) {
// Do the operating system check first, no point in getting the driver
// info if we won't need to use it. If the OS of the system we are running
// on is unknown, we still let DRIVER_OS_ALL catch and disable it;
// if the OS of the downloadable entry is unknown, we skip the entry
// as invalid.
if (info[i].mOperatingSystem == DRIVER_OS_UNKNOWN ||
(info[i].mOperatingSystem != DRIVER_OS_ALL &&
info[i].mOperatingSystem != os))
{
continue;
}
if (info[i].mOperatingSystemVersion && info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
continue;
}
// XXX: it would be better not to do this everytime round the loop
nsAutoString adapterVendorID;
nsAutoString adapterDeviceID;
nsAutoString adapterDriverVersionString;
if (info[i].mGpu2) {
if (NS_FAILED(GetAdapterVendorID2(adapterVendorID)) ||
NS_FAILED(GetAdapterDeviceID2(adapterDeviceID)) ||
NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString)))
{
return 0;
}
} else {
if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
{
return 0;
}
}
#if defined(XP_WIN) || defined(ANDROID)
uint64_t driverVersion;
ParseDriverVersion(adapterDriverVersionString, &driverVersion);
#endif
if (!info[i].mAdapterVendor.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll), nsCaseInsensitiveStringComparator()) &&
!info[i].mAdapterVendor.Equals(adapterVendorID, nsCaseInsensitiveStringComparator())) {
continue;
}
if (info[i].mDevices != GfxDriverInfo::allDevices && info[i].mDevices->Length()) {
bool deviceMatches = false;
for (uint32_t j = 0; j < info[i].mDevices->Length(); j++) {
if ((*info[i].mDevices)[j].Equals(adapterDeviceID, nsCaseInsensitiveStringComparator())) {
deviceMatches = true;
break;
}
}
if (!deviceMatches) {
continue;
}
}
bool match = false;
if (!info[i].mHardware.IsEmpty() && !info[i].mHardware.Equals(Hardware())) {
continue;
}
if (!info[i].mModel.IsEmpty() && !info[i].mModel.Equals(Model())) {
continue;
}
if (!info[i].mProduct.IsEmpty() && !info[i].mProduct.Equals(Product())) {
continue;
}
if (!info[i].mManufacturer.IsEmpty() && !info[i].mManufacturer.Equals(Manufacturer())) {
continue;
}
#if defined(XP_WIN) || defined(ANDROID)
switch (info[i].mComparisonOp) {
case DRIVER_LESS_THAN:
match = driverVersion < info[i].mDriverVersion;
break;
case DRIVER_LESS_THAN_OR_EQUAL:
match = driverVersion <= info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN:
match = driverVersion > info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN_OR_EQUAL:
match = driverVersion >= info[i].mDriverVersion;
break;
case DRIVER_EQUAL:
match = driverVersion == info[i].mDriverVersion;
break;
case DRIVER_NOT_EQUAL:
match = driverVersion != info[i].mDriverVersion;
break;
case DRIVER_BETWEEN_EXCLUSIVE:
match = driverVersion > info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE:
match = driverVersion >= info[i].mDriverVersion && driverVersion <= info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE_START:
match = driverVersion >= info[i].mDriverVersion && driverVersion < info[i].mDriverVersionMax;
break;
case DRIVER_COMPARISON_IGNORED:
// We don't have a comparison op, so we match everything.
match = true;
break;
default:
NS_WARNING("Bogus op in GfxDriverInfo");
break;
}
#else
// We don't care what driver version it was. We only check OS version and if
// the device matches.
match = true;
#endif
if (match || info[i].mDriverVersion == GfxDriverInfo::allDriverVersions) {
if (info[i].mFeature == GfxDriverInfo::allFeatures ||
info[i].mFeature == aFeature)
{
status = info[i].mFeatureStatus;
break;
}
}
}
#if defined(XP_WIN)
// As a very special case, we block D2D on machines with an NVidia 310M GPU
// as either the primary or secondary adapter. D2D is also blocked when the
// NV 310M is the primary adapter (using the standard blocklisting mechanism).
// If the primary GPU already matched something in the blocklist then we
// ignore this special rule. See bug 1008759.
if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN &&
(aFeature == nsIGfxInfo::FEATURE_DIRECT2D)) {
nsAutoString adapterVendorID2;
nsAutoString adapterDeviceID2;
if ((!NS_FAILED(GetAdapterVendorID2(adapterVendorID2))) &&
(!NS_FAILED(GetAdapterDeviceID2(adapterDeviceID2))))
{
nsAString &nvVendorID = (nsAString &)GfxDriverInfo::GetDeviceVendor(VendorNVIDIA);
const nsString nv310mDeviceId = NS_LITERAL_STRING("0x0A70");
if (nvVendorID.Equals(adapterVendorID2, nsCaseInsensitiveStringComparator()) &&
nv310mDeviceId.Equals(adapterDeviceID2, nsCaseInsensitiveStringComparator())) {
status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
}
}
}
// Depends on Windows driver versioning. We don't pass a GfxDriverInfo object
// back to the Windows handler, so we must handle this here.
if (status == FEATURE_BLOCKED_DRIVER_VERSION) {
if (info[i].mSuggestedVersion) {
aSuggestedVersion.AppendPrintf("%s", info[i].mSuggestedVersion);
} else if (info[i].mComparisonOp == DRIVER_LESS_THAN &&
info[i].mDriverVersion != GfxDriverInfo::allDriverVersions)
{
aSuggestedVersion.AppendPrintf("%lld.%lld.%lld.%lld",
(info[i].mDriverVersion & 0xffff000000000000) >> 48,
(info[i].mDriverVersion & 0x0000ffff00000000) >> 32,
(info[i].mDriverVersion & 0x00000000ffff0000) >> 16,
(info[i].mDriverVersion & 0x000000000000ffff));
}
}
#endif
return status;
}
nsresult
GfxInfoBase::GetFeatureStatusImpl(int32_t aFeature,
int32_t* aStatus,
nsAString& aSuggestedVersion,
const nsTArray<GfxDriverInfo>& aDriverInfo,
OperatingSystem* aOS /* = nullptr */)
{
if (aFeature <= 0) {
gfxWarning() << "Invalid feature <= 0";
return NS_OK;
}
if (*aStatus != nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
// Terminate now with the status determined by the derived type (OS-specific
// code).
return NS_OK;
}
// If an operating system was provided by the derived GetFeatureStatusImpl,
// grab it here. Otherwise, the OS is unknown.
OperatingSystem os = DRIVER_OS_UNKNOWN;
if (aOS)
os = *aOS;
nsAutoString adapterVendorID;
nsAutoString adapterDeviceID;
nsAutoString adapterDriverVersionString;
if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString)))
{
return NS_OK;
}
// Check if the device is blocked from the downloaded blocklist. If not, check
// the static list after that. This order is used so that we can later escape
// out of static blocks (i.e. if we were wrong or something was patched, we
// can back out our static block without doing a release).
int32_t status;
if (aDriverInfo.Length()) {
status = FindBlocklistedDeviceInList(aDriverInfo, aSuggestedVersion, aFeature, os);
} else {
if (!mDriverInfo) {
mDriverInfo = new nsTArray<GfxDriverInfo>();
}
status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion, aFeature, os);
}
// It's now done being processed. It's safe to set the status to STATUS_OK.
if (status == nsIGfxInfo::FEATURE_STATUS_UNKNOWN) {
*aStatus = nsIGfxInfo::FEATURE_STATUS_OK;
} else {
*aStatus = status;
}
return NS_OK;
}
NS_IMETHODIMP
GfxInfoBase::GetFeatureSuggestedDriverVersion(int32_t aFeature,
nsAString& aVersion)
{
nsCString version;
if (GetPrefValueForDriverVersion(version)) {
aVersion = NS_ConvertASCIItoUTF16(version);
return NS_OK;
}
int32_t status;
nsTArray<GfxDriverInfo> driverInfo;
return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo);
}
NS_IMETHODIMP
GfxInfoBase::GetWebGLParameter(const nsAString& aParam,
nsAString& aResult)
{
return GfxInfoWebGL::GetWebGLParameter(aParam, aResult);
}
void
GfxInfoBase::EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo)
{
int32_t features[] = {
nsIGfxInfo::FEATURE_DIRECT2D,
nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS,
nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS,
nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS,
nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS,
nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE,
nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
nsIGfxInfo::FEATURE_OPENGL_LAYERS,
nsIGfxInfo::FEATURE_WEBGL_OPENGL,
nsIGfxInfo::FEATURE_WEBGL_ANGLE,
nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE,
nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE,
nsIGfxInfo::FEATURE_WEBGL_MSAA,
nsIGfxInfo::FEATURE_STAGEFRIGHT,
nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION,
0
};
// For every feature we know about, we evaluate whether this blacklist has a
// non-STATUS_OK status. If it does, we set the pref we evaluate in
// GetFeatureStatus above, so we don't need to hold on to this blacklist
// anywhere permanent.
int i = 0;
while (features[i]) {
int32_t status;
nsAutoString suggestedVersion;
if (NS_SUCCEEDED(GetFeatureStatusImpl(features[i], &status,
suggestedVersion,
aDriverInfo))) {
switch (status) {
default:
case nsIGfxInfo::FEATURE_STATUS_OK:
RemovePrefForFeature(features[i]);
break;
case nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION:
if (!suggestedVersion.IsEmpty()) {
SetPrefValueForDriverVersion(suggestedVersion);
} else {
RemovePrefForDriverVersion();
}
MOZ_FALLTHROUGH;
case nsIGfxInfo::FEATURE_BLOCKED_MISMATCHED_VERSION:
case nsIGfxInfo::FEATURE_BLOCKED_DEVICE:
case nsIGfxInfo::FEATURE_DISCOURAGED:
case nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION:
SetPrefValueForFeature(features[i], status);
break;
}
}
++i;
}
}
NS_IMETHODIMP_(void)
GfxInfoBase::LogFailure(const nsACString &failure)
{
// gfxCriticalError has a mutex lock of its own, so we may not actually
// need this lock. ::GetFailures() accesses the data but the LogForwarder
// will not return the copy of the logs unless it can get the same lock
// that gfxCriticalError uses. Still, that is so much of an implementation
// detail that it's nicer to just add an extra lock here and in ::GetFailures()
MutexAutoLock lock(mMutex);
// By default, gfxCriticalError asserts; make it not assert in this case.
gfxCriticalError(CriticalLog::DefaultOptions(false)) << "(LF) " << failure.BeginReading();
}
/* XPConnect method of returning arrays is very ugly. Would not recommend. */
NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
int32_t** indices,
char ***failures)
{
MutexAutoLock lock(mMutex);
NS_ENSURE_ARG_POINTER(failureCount);
NS_ENSURE_ARG_POINTER(failures);
*failures = nullptr;
*failureCount = 0;
// indices is "allowed" to be null, the caller may not care about them,
// although calling from JS doesn't seem to get us there.
if (indices) *indices = nullptr;
LogForwarder* logForwarder = Factory::GetLogForwarder();
if (!logForwarder) {
return NS_ERROR_UNEXPECTED;
}
// There are two stirng copies in this method, starting with this one. We are
// assuming this is not a big deal, as the size of the array should be small
// and the strings in it should be small as well (the error messages in the
// code.) The second copy happens with the Clone() calls. Technically,
// we don't need the mutex lock after the StringVectorCopy() call.
std::vector<std::pair<int32_t,std::string> > loggedStrings = logForwarder->StringsVectorCopy();
*failureCount = loggedStrings.size();
if (*failureCount != 0) {
*failures = (char**)moz_xmalloc(*failureCount * sizeof(char*));
if (!(*failures)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (indices) {
*indices = (int32_t*)moz_xmalloc(*failureCount * sizeof(int32_t));
if (!(*indices)) {
free(*failures);
*failures = nullptr;
return NS_ERROR_OUT_OF_MEMORY;
}
}
/* copy over the failure messages into the array we just allocated */
std::vector<std::pair<int32_t, std::string> >::const_iterator it;
uint32_t i=0;
for(it = loggedStrings.begin() ; it != loggedStrings.end(); ++it, i++) {
(*failures)[i] = (char*)nsMemory::Clone((*it).second.c_str(), (*it).second.size() + 1);
if (indices) (*indices)[i] = (*it).first;
if (!(*failures)[i]) {
/* <sarcasm> I'm too afraid to use an inline function... </sarcasm> */
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, (*failures));
*failureCount = i;
return NS_ERROR_OUT_OF_MEMORY;
}
}
}
return NS_OK;
}
nsTArray<GfxInfoCollectorBase*> *sCollectors;
static void
InitCollectors()
{
if (!sCollectors)
sCollectors = new nsTArray<GfxInfoCollectorBase*>;
}
nsresult GfxInfoBase::GetInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aResult)
{
InitCollectors();
InfoObject obj(aCx);
for (uint32_t i = 0; i < sCollectors->Length(); i++) {
(*sCollectors)[i]->GetInfo(obj);
}
// Some example property definitions
// obj.DefineProperty("wordCacheSize", gfxTextRunWordCache::Count());
// obj.DefineProperty("renderer", mRendererIDsString);
// obj.DefineProperty("five", 5);
if (!obj.mOk) {
return NS_ERROR_FAILURE;
}
aResult.setObject(*obj.mObj);
return NS_OK;
}
const nsCString&
GfxInfoBase::GetApplicationVersion()
{
static nsAutoCString version;
static bool versionInitialized = false;
if (!versionInitialized) {
// If we fail to get the version, we will not try again.
versionInitialized = true;
// Get the version from xpcom/system/nsIXULAppInfo.idl
nsCOMPtr<nsIXULAppInfo> app = do_GetService("@mozilla.org/xre/app-info;1");
if (app) {
app->GetVersion(version);
}
}
return version;
}
void
GfxInfoBase::AddCollector(GfxInfoCollectorBase* collector)
{
InitCollectors();
sCollectors->AppendElement(collector);
}
void
GfxInfoBase::RemoveCollector(GfxInfoCollectorBase* collector)
{
InitCollectors();
for (uint32_t i = 0; i < sCollectors->Length(); i++) {
if ((*sCollectors)[i] == collector) {
sCollectors->RemoveElementAt(i);
break;
}
}
if (sCollectors->IsEmpty()) {
delete sCollectors;
sCollectors = nullptr;
}
}
NS_IMETHODIMP
GfxInfoBase::GetMonitors(JSContext* aCx, JS::MutableHandleValue aResult)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
nsresult rv = FindMonitors(aCx, array);
if (NS_FAILED(rv)) {
return rv;
}
aResult.setObject(*array);
return NS_OK;
}
static const char*
GetLayersBackendName(layers::LayersBackend aBackend)
{
switch (aBackend) {
case layers::LayersBackend::LAYERS_NONE:
return "none";
case layers::LayersBackend::LAYERS_OPENGL:
return "opengl";
case layers::LayersBackend::LAYERS_D3D9:
return "d3d9";
case layers::LayersBackend::LAYERS_D3D11:
return "d3d11";
case layers::LayersBackend::LAYERS_CLIENT:
return "client";
case layers::LayersBackend::LAYERS_BASIC:
return "basic";
default:
MOZ_ASSERT_UNREACHABLE("unknown layers backend");
return "unknown";
}
}
nsresult
GfxInfoBase::GetFeatures(JSContext* aCx, JS::MutableHandle<JS::Value> aOut)
{
JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
if (!obj) {
return NS_ERROR_OUT_OF_MEMORY;
}
aOut.setObject(*obj);
layers::LayersBackend backend = gfxPlatform::Initialized()
? gfxPlatform::GetPlatform()->GetCompositorBackend()
: layers::LayersBackend::LAYERS_NONE;
const char* backendName = GetLayersBackendName(backend);
{
JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, backendName));
JS::Rooted<JS::Value> val(aCx, StringValue(str));
JS_SetProperty(aCx, obj, "compositor", val);
}
// If graphics isn't initialized yet, just stop now.
if (!gfxPlatform::Initialized()) {
return NS_OK;
}
DescribeFeatures(aCx, obj);
return NS_OK;
}
void
GfxInfoBase::DescribeFeatures(JSContext* cx, JS::Handle<JSObject*> aOut)
{
}
bool
GfxInfoBase::InitFeatureObject(JSContext* aCx,
JS::Handle<JSObject*> aContainer,
const char* aName,
mozilla::gfx::FeatureStatus aFeatureStatus,
JS::MutableHandle<JSObject*> aOutObj)
{
JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
if (!obj) {
return false;
}
const char* status = FeatureStatusToString(aFeatureStatus);
// Set "status".
{
JS::Rooted<JSString*> str(aCx, JS_NewStringCopyZ(aCx, status));
JS::Rooted<JS::Value> val(aCx, JS::StringValue(str));
JS_SetProperty(aCx, obj, "status", val);
}
// Add the feature object to the container.
{
JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
JS_SetProperty(aCx, aContainer, aName, val);
}
aOutObj.set(obj);
return true;
}
GfxInfoCollectorBase::GfxInfoCollectorBase()
{
GfxInfoBase::AddCollector(this);
}
GfxInfoCollectorBase::~GfxInfoCollectorBase()
{
GfxInfoBase::RemoveCollector(this);
}