forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GfxInfoBase.cpp
1579 lines (1380 loc) · 53.3 KB
/
GfxInfoBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 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 "GfxDriverInfo.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.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 "nsTArray.h"
#include "nsXULAppAPI.h"
#include "nsIXULAppInfo.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_gfx.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/PaintThread.h"
#include "gfxPlatform.h"
#include "gfxConfig.h"
#include "DriverCrashGuard.h"
using namespace mozilla::widget;
using namespace mozilla;
using mozilla::MutexAutoLock;
nsTArray<GfxDriverInfo>* GfxInfoBase::sDriverInfo;
nsTArray<dom::GfxInfoFeatureStatus>* GfxInfoBase::sFeatureStatus;
bool GfxInfoBase::sDriverInfoObserverInitialized;
bool GfxInfoBase::sShutdownOccurred;
// 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::sDriverInfo;
GfxInfoBase::sDriverInfo = nullptr;
delete GfxInfoBase::sFeatureStatus;
GfxInfoBase::sFeatureStatus = nullptr;
for (uint32_t i = 0; i < DeviceFamilyMax; i++) {
delete GfxDriverInfo::sDeviceFamilies[i];
GfxDriverInfo::sDeviceFamilies[i] = nullptr;
}
for (uint32_t i = 0; i < DeviceVendorMax; i++) {
delete GfxDriverInfo::sDeviceVendors[i];
GfxDriverInfo::sDeviceVendors[i] = nullptr;
}
for (uint32_t i = 0; i < DriverVendorMax; i++) {
delete GfxDriverInfo::sDriverVendors[i];
GfxDriverInfo::sDriverVendors[i] = nullptr;
}
GfxInfoBase::sShutdownOccurred = true;
return NS_OK;
}
};
NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
static void InitGfxDriverInfoShutdownObserver() {
if (GfxInfoBase::sDriverInfoObserverInitialized) return;
GfxInfoBase::sDriverInfoObserverInitialized = 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;
case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
name = BLACKLIST_PREF_BRANCH "canvas2d.acceleration";
break;
case nsIGfxInfo::FEATURE_DX_INTEROP2:
name = BLACKLIST_PREF_BRANCH "dx.interop2";
break;
case nsIGfxInfo::FEATURE_GPU_PROCESS:
name = BLACKLIST_PREF_BRANCH "gpu.process";
break;
case nsIGfxInfo::FEATURE_WEBGL2:
name = BLACKLIST_PREF_BRANCH "webgl2";
break;
case nsIGfxInfo::FEATURE_ADVANCED_LAYERS:
name = BLACKLIST_PREF_BRANCH "layers.advanced";
break;
case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
name = BLACKLIST_PREF_BRANCH "d3d11.keyed.mutex";
break;
case nsIGfxInfo::FEATURE_WEBRENDER:
name = BLACKLIST_PREF_BRANCH "webrender";
break;
case nsIGfxInfo::FEATURE_DX_NV12:
name = BLACKLIST_PREF_BRANCH "dx.nv12";
break;
case nsIGfxInfo::FEATURE_DX_P010:
name = BLACKLIST_PREF_BRANCH "dx.p010";
break;
case nsIGfxInfo::FEATURE_DX_P016:
name = BLACKLIST_PREF_BRANCH "dx.p016";
break;
case nsIGfxInfo::FEATURE_VP8_HW_DECODE:
case nsIGfxInfo::FEATURE_VP9_HW_DECODE:
// We don't provide prefs for these features as these are
// not handling downloadable blocklist.
break;
case nsIGfxInfo::FEATURE_GL_SWIZZLE:
name = BLACKLIST_PREF_BRANCH "gl.swizzle";
break;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
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,
nsACString& aFailureId) {
const char* prefname = GetPrefNameForFeature(aFeature);
if (!prefname) return false;
aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
return false;
}
nsCString failureprefname(prefname);
failureprefname += ".failureid";
nsAutoCString failureValue;
nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
if (NS_SUCCEEDED(rv)) {
aFailureId = failureValue.get();
} else {
aFailureId = "FEATURE_FAILURE_BLACKLIST_PREF";
}
return true;
}
static void SetPrefValueForFeature(int32_t aFeature, int32_t aValue,
const nsACString& aFailureId) {
const char* prefname = GetPrefNameForFeature(aFeature);
if (!prefname) return;
Preferences::SetInt(prefname, aValue);
if (!aFailureId.IsEmpty()) {
nsCString failureprefname(prefname);
failureprefname += ".failureid";
Preferences::SetCString(failureprefname.get(), aFailureId);
}
}
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);
}
static OperatingSystem BlacklistOSToOperatingSystem(const nsAString& os) {
if (os.EqualsLiteral("WINNT 6.1"))
return OperatingSystem::Windows7;
else if (os.EqualsLiteral("WINNT 6.2"))
return OperatingSystem::Windows8;
else if (os.EqualsLiteral("WINNT 6.3"))
return OperatingSystem::Windows8_1;
else if (os.EqualsLiteral("WINNT 10.0"))
return OperatingSystem::Windows10;
else if (os.EqualsLiteral("Linux"))
return OperatingSystem::Linux;
else if (os.EqualsLiteral("Darwin 9"))
return OperatingSystem::OSX10_5;
else if (os.EqualsLiteral("Darwin 10"))
return OperatingSystem::OSX10_6;
else if (os.EqualsLiteral("Darwin 11"))
return OperatingSystem::OSX10_7;
else if (os.EqualsLiteral("Darwin 12"))
return OperatingSystem::OSX10_8;
else if (os.EqualsLiteral("Darwin 13"))
return OperatingSystem::OSX10_9;
else if (os.EqualsLiteral("Darwin 14"))
return OperatingSystem::OSX10_10;
else if (os.EqualsLiteral("Darwin 15"))
return OperatingSystem::OSX10_11;
else if (os.EqualsLiteral("Darwin 16"))
return OperatingSystem::OSX10_12;
else if (os.EqualsLiteral("Darwin 17"))
return OperatingSystem::OSX10_13;
else if (os.EqualsLiteral("Android"))
return OperatingSystem::Android;
// For historical reasons, "All" in blocklist means "All Windows"
else if (os.EqualsLiteral("All"))
return OperatingSystem::Windows;
return OperatingSystem::Unknown;
}
static GfxDeviceFamily* BlacklistDevicesToDeviceFamily(
nsTArray<nsCString>& devices) {
if (devices.Length() == 0) 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 < devices.Length(); ++i) {
// We make sure we don't add any "empty" device entries to the array, so
// we don't need to check if devices[i] is empty.
deviceIds->AppendElement(NS_ConvertUTF8toUTF16(devices[i]));
}
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;
else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
else if (aFeature.EqualsLiteral("DX_INTEROP2"))
return nsIGfxInfo::FEATURE_DX_INTEROP2;
else if (aFeature.EqualsLiteral("GPU_PROCESS"))
return nsIGfxInfo::FEATURE_GPU_PROCESS;
else if (aFeature.EqualsLiteral("WEBGL2"))
return nsIGfxInfo::FEATURE_WEBGL2;
else if (aFeature.EqualsLiteral("ADVANCED_LAYERS"))
return nsIGfxInfo::FEATURE_ADVANCED_LAYERS;
else if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX"))
return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
else if (aFeature.EqualsLiteral("WEBRENDER"))
return nsIGfxInfo::FEATURE_WEBRENDER;
else if (aFeature.EqualsLiteral("DX_NV12"))
return nsIGfxInfo::FEATURE_DX_NV12;
// We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE
// in downloadable blocklist.
else if (aFeature.EqualsLiteral("GL_SWIZZLE"))
return nsIGfxInfo::FEATURE_GL_SWIZZLE;
// 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("BUILD_ID_LESS_THAN"))
return DRIVER_BUILD_ID_LESS_THAN;
else if (op.EqualsLiteral("LESS_THAN_OR_EQUAL"))
return DRIVER_LESS_THAN_OR_EQUAL;
else if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL"))
return DRIVER_BUILD_ID_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;
}
/*
Deserialize Blacklist entries from string.
e.g:
os:WINNT 6.0\tvendor:0x8086\tdevices:0x2582,0x2782\tfeature:DIRECT3D_10_LAYERS\tfeatureStatus:BLOCKED_DRIVER_VERSION\tdriverVersion:8.52.322.2202\tdriverVersionComparator:LESS_THAN_OR_EQUAL
*/
static bool BlacklistEntryToDriverInfo(nsCString& aBlacklistEntry,
GfxDriverInfo& aDriverInfo) {
// 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();
}
nsTArray<nsCString> keyValues;
ParseString(aBlacklistEntry, '\t', keyValues);
aDriverInfo.mRuleId =
NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_NO_ID");
for (uint32_t i = 0; i < keyValues.Length(); ++i) {
nsCString keyValue = keyValues[i];
nsTArray<nsCString> splitted;
ParseString(keyValue, ':', splitted);
if (splitted.Length() != 2) {
// If we don't recognize the input data, we do not want to proceed.
gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
<< "Unrecognized data " << keyValue.get();
return false;
}
nsCString key = splitted[0];
nsCString value = splitted[1];
NS_ConvertUTF8toUTF16 dataValue(value);
if (value.Length() == 0) {
// Safety check for empty values.
gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
<< "Empty value for " << key.get();
return false;
}
if (key.EqualsLiteral("blockID")) {
nsCString blockIdStr =
NS_LITERAL_CSTRING("FEATURE_FAILURE_DL_BLACKLIST_") + value;
aDriverInfo.mRuleId = blockIdStr.get();
} else if (key.EqualsLiteral("os")) {
aDriverInfo.mOperatingSystem = BlacklistOSToOperatingSystem(dataValue);
} else if (key.EqualsLiteral("osversion")) {
aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
} else if (key.EqualsLiteral("vendor")) {
aDriverInfo.mAdapterVendor = dataValue;
} else if (key.EqualsLiteral("driverVendor")) {
aDriverInfo.mDriverVendor = dataValue;
} else if (key.EqualsLiteral("feature")) {
aDriverInfo.mFeature = BlacklistFeatureToGfxFeature(dataValue);
if (aDriverInfo.mFeature < 0) {
// If we don't recognize the feature, we do not want to proceed.
gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
<< "Unrecognized feature " << value.get();
return false;
}
} else if (key.EqualsLiteral("featureStatus")) {
aDriverInfo.mFeatureStatus =
BlacklistFeatureStatusToGfxFeatureStatus(dataValue);
} else if (key.EqualsLiteral("driverVersion")) {
uint64_t version;
if (ParseDriverVersion(dataValue, &version))
aDriverInfo.mDriverVersion = version;
} else if (key.EqualsLiteral("driverVersionMax")) {
uint64_t version;
if (ParseDriverVersion(dataValue, &version))
aDriverInfo.mDriverVersionMax = version;
} else if (key.EqualsLiteral("driverVersionComparator")) {
aDriverInfo.mComparisonOp = BlacklistComparatorToComparisonOp(dataValue);
} else if (key.EqualsLiteral("model")) {
aDriverInfo.mModel = dataValue;
} else if (key.EqualsLiteral("product")) {
aDriverInfo.mProduct = dataValue;
} else if (key.EqualsLiteral("manufacturer")) {
aDriverInfo.mManufacturer = dataValue;
} else if (key.EqualsLiteral("hardware")) {
aDriverInfo.mHardware = dataValue;
} else if (key.EqualsLiteral("versionRange")) {
nsTArray<nsCString> versionRange;
ParseString(value, ',', versionRange);
if (versionRange.Length() != 2) {
gfxCriticalErrorOnce(CriticalLog::DefaultOptions(false))
<< "Unrecognized versionRange " << value.get();
return false;
}
nsCString minValue = versionRange[0];
nsCString maxValue = versionRange[1];
mozilla::Version minV(minValue.get());
mozilla::Version maxV(maxValue.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 (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;
}
} else if (key.EqualsLiteral("devices")) {
nsTArray<nsCString> devices;
ParseString(value, ',', devices);
GfxDeviceFamily* deviceIds = BlacklistDevicesToDeviceFamily(devices);
if (deviceIds) {
// Get GfxDriverInfo to adopt the devices array we created.
aDriverInfo.mDeleteDevices = true;
aDriverInfo.mDevices = deviceIds;
}
}
// We explicitly ignore unknown elements.
}
return true;
}
static void BlacklistEntriesToDriverInfo(nsTArray<nsCString>& aBlacklistEntries,
nsTArray<GfxDriverInfo>& aDriverInfo) {
aDriverInfo.Clear();
aDriverInfo.SetLength(aBlacklistEntries.Length());
for (uint32_t i = 0; i < aBlacklistEntries.Length(); ++i) {
nsCString blacklistEntry = aBlacklistEntries[i];
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) {
nsTArray<GfxDriverInfo> driverInfo;
nsTArray<nsCString> blacklistEntries;
nsCString utf8Data = NS_ConvertUTF16toUTF8(aData);
if (utf8Data.Length() > 0) {
ParseString(utf8Data, '\n', blacklistEntries);
}
BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
EvaluateDownloadedBlacklist(driverInfo);
}
return NS_OK;
}
GfxInfoBase::GfxInfoBase() : mMutex("GfxInfoBase") {}
GfxInfoBase::~GfxInfoBase() {}
nsresult GfxInfoBase::Init() {
InitGfxDriverInfoShutdownObserver();
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, nsACString& aFailureId,
int32_t* aStatus) {
// Ignore the gfx.blocklist.all pref on release and beta.
#if defined(RELEASE_OR_BETA)
int32_t blocklistAll = 0;
#else
int32_t blocklistAll = StaticPrefs::gfx_blocklist_all_AtStartup();
#endif
if (blocklistAll > 0) {
gfxCriticalErrorOnce(gfxCriticalError::DefaultOptions(false))
<< "Forcing blocklisting all features";
*aStatus = FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_BLOCK_ALL";
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, aFailureId)) {
return NS_OK;
}
if (XRE_IsContentProcess()) {
// Use the cached data received from the parent process.
MOZ_ASSERT(sFeatureStatus);
bool success = false;
for (const auto& fs : *sFeatureStatus) {
if (fs.feature() == aFeature) {
aFailureId = fs.failureId();
*aStatus = fs.status();
success = true;
break;
}
}
return success ? NS_OK : NS_ERROR_FAILURE;
}
nsString version;
nsTArray<GfxDriverInfo> driverInfo;
nsresult rv =
GetFeatureStatusImpl(aFeature, aStatus, version, driverInfo, aFailureId);
return rv;
}
// Matching OS go somewhat beyond the simple equality check because of the
// "All Windows" and "All OS X" variations.
//
// aBlockedOS is describing the system(s) we are trying to block.
// aSystemOS is describing the system we are running on.
//
// aSystemOS should not be "Windows" or "OSX" - it should be set to
// a particular version instead.
// However, it is valid for aBlockedOS to be one of those generic values,
// as we could be blocking all of the versions.
inline bool MatchingOperatingSystems(OperatingSystem aBlockedOS,
OperatingSystem aSystemOS) {
MOZ_ASSERT(aSystemOS != OperatingSystem::Windows &&
aSystemOS != OperatingSystem::OSX);
// If the block entry OS is unknown, it doesn't match
if (aBlockedOS == OperatingSystem::Unknown) {
return false;
}
#if defined(XP_WIN)
if (aBlockedOS == OperatingSystem::Windows) {
// We do want even "unknown" aSystemOS to fall under "all windows"
return true;
}
#endif
#if defined(XP_MACOSX)
if (aBlockedOS == OperatingSystem::OSX) {
// We do want even "unknown" aSystemOS to fall under "all OS X"
return true;
}
#endif
return aSystemOS == aBlockedOS;
}
int32_t GfxInfoBase::FindBlocklistedDeviceInList(
const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
int32_t aFeature, nsACString& aFailureId, OperatingSystem os) {
int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
// Get the adapters once then reuse below
nsAutoString adapterVendorID[2];
nsAutoString adapterDeviceID[2];
nsAutoString adapterDriverVendor[2];
nsAutoString adapterDriverVersionString[2];
bool adapterInfoFailed[2];
adapterInfoFailed[0] =
(NS_FAILED(GetAdapterVendorID(adapterVendorID[0])) ||
NS_FAILED(GetAdapterDeviceID(adapterDeviceID[0])) ||
NS_FAILED(GetAdapterDriverVendor(adapterDriverVendor[0])) ||
NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString[0])));
adapterInfoFailed[1] =
(NS_FAILED(GetAdapterVendorID2(adapterVendorID[1])) ||
NS_FAILED(GetAdapterDeviceID2(adapterDeviceID[1])) ||
NS_FAILED(GetAdapterDriverVendor2(adapterDriverVendor[1])) ||
NS_FAILED(GetAdapterDriverVersion2(adapterDriverVersionString[1])));
// No point in going on if we don't have adapter info
if (adapterInfoFailed[0] && adapterInfoFailed[1]) {
return 0;
}
#if defined(XP_WIN) || defined(ANDROID) || defined(MOZ_X11)
uint64_t driverVersion[2] = {0, 0};
if (!adapterInfoFailed[0]) {
ParseDriverVersion(adapterDriverVersionString[0], &driverVersion[0]);
}
if (!adapterInfoFailed[1]) {
ParseDriverVersion(adapterDriverVersionString[1], &driverVersion[1]);
}
#endif
uint32_t i = 0;
for (; i < info.Length(); i++) {
// If we don't have the info for this GPU, no need to check further.
// It is unclear that we would ever have a mixture of 1st and 2nd
// GPU, but leaving the code in for that possibility for now.
// (Actually, currently mGpu2 will never be true, so this can
// be optimized out.)
uint32_t infoIndex = info[i].mGpu2 ? 1 : 0;
if (adapterInfoFailed[infoIndex]) {
continue;
}
// Do the operating system check first, no point in getting the driver
// info if we won't need to use it.
if (!MatchingOperatingSystems(info[i].mOperatingSystem, os)) {
continue;
}
if (info[i].mOperatingSystemVersion &&
info[i].mOperatingSystemVersion != OperatingSystemVersion()) {
continue;
}
if (!DoesVendorMatch(info[i].mAdapterVendor, adapterVendorID[infoIndex])) {
continue;
}
if (!DoesDriverVendorMatch(info[i].mDriverVendor,
adapterDriverVendor[infoIndex])) {
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[infoIndex],
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) || defined(MOZ_X11)
switch (info[i].mComparisonOp) {
case DRIVER_LESS_THAN:
match = driverVersion[infoIndex] < info[i].mDriverVersion;
break;
case DRIVER_BUILD_ID_LESS_THAN:
match = (driverVersion[infoIndex] & 0xFFFF) < info[i].mDriverVersion;
break;
case DRIVER_LESS_THAN_OR_EQUAL:
match = driverVersion[infoIndex] <= info[i].mDriverVersion;
break;
case DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL:
match = (driverVersion[infoIndex] & 0xFFFF) <= info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN:
match = driverVersion[infoIndex] > info[i].mDriverVersion;
break;
case DRIVER_GREATER_THAN_OR_EQUAL:
match = driverVersion[infoIndex] >= info[i].mDriverVersion;
break;
case DRIVER_EQUAL:
match = driverVersion[infoIndex] == info[i].mDriverVersion;
break;
case DRIVER_NOT_EQUAL:
match = driverVersion[infoIndex] != info[i].mDriverVersion;
break;
case DRIVER_BETWEEN_EXCLUSIVE:
match = driverVersion[infoIndex] > info[i].mDriverVersion &&
driverVersion[infoIndex] < info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE:
match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
driverVersion[infoIndex] <= info[i].mDriverVersionMax;
break;
case DRIVER_BETWEEN_INCLUSIVE_START:
match = driverVersion[infoIndex] >= info[i].mDriverVersion &&
driverVersion[infoIndex] < 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;
if (!info[i].mRuleId.IsEmpty()) {
aFailureId = info[i].mRuleId.get();
} else {
aFailureId = "FEATURE_FAILURE_DL_BLACKLIST_NO_ID";
}
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)) {
if (!adapterInfoFailed[1]) {
nsAString& nvVendorID =
(nsAString&)GfxDriverInfo::GetDeviceVendor(VendorNVIDIA);
const nsString nv310mDeviceId = NS_LITERAL_STRING("0x0A70");
if (nvVendorID.Equals(adapterVendorID[1],
nsCaseInsensitiveStringComparator()) &&
nv310mDeviceId.Equals(adapterDeviceID[1],
nsCaseInsensitiveStringComparator())) {
status = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_D2D_NV310M_BLOCK";
}
}
}
// 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;
}
void GfxInfoBase::SetFeatureStatus(
const nsTArray<dom::GfxInfoFeatureStatus>& aFS) {
MOZ_ASSERT(!sFeatureStatus);
sFeatureStatus = new nsTArray<dom::GfxInfoFeatureStatus>(aFS);
}
bool GfxInfoBase::DoesVendorMatch(const nsAString& aBlocklistVendor,
const nsAString& aAdapterVendor) {
return aBlocklistVendor.Equals(aAdapterVendor,
nsCaseInsensitiveStringComparator()) ||
aBlocklistVendor.Equals(GfxDriverInfo::GetDeviceVendor(VendorAll),
nsCaseInsensitiveStringComparator());
}
bool GfxInfoBase::DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
const nsAString& aDriverVendor) {
return aBlocklistVendor.Equals(aDriverVendor,
nsCaseInsensitiveStringComparator()) ||
aBlocklistVendor.Equals(
GfxDriverInfo::GetDriverVendor(DriverVendorAll),
nsCaseInsensitiveStringComparator());
}
nsresult GfxInfoBase::GetFeatureStatusImpl(
int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedVersion,
const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
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 (sShutdownOccurred) {
// This is futile; we've already commenced shutdown and our blocklists have
// been deleted. We may want to look into resurrecting the blocklist instead
// but for now, just don't even go there.
return NS_OK;
}
// If an operating system was provided by the derived GetFeatureStatusImpl,
// grab it here. Otherwise, the OS is unknown.
OperatingSystem os = (aOS ? *aOS : OperatingSystem::Unknown);
nsAutoString adapterVendorID;
nsAutoString adapterDeviceID;
nsAutoString adapterDriverVersionString;
if (NS_FAILED(GetAdapterVendorID(adapterVendorID)) ||
NS_FAILED(GetAdapterDeviceID(adapterDeviceID)) ||
NS_FAILED(GetAdapterDriverVersion(adapterDriverVersionString))) {
aFailureId = "FEATURE_FAILURE_CANT_RESOLVE_ADAPTER";
*aStatus = FEATURE_BLOCKED_DEVICE;
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, aFailureId, os);
} else {
if (!sDriverInfo) {
sDriverInfo = new nsTArray<GfxDriverInfo>();
}
status = FindBlocklistedDeviceInList(GetGfxDriverInfo(), aSuggestedVersion,
aFeature, aFailureId, 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;
nsCString discardFailureId;
nsTArray<GfxDriverInfo> driverInfo;
return GetFeatureStatusImpl(aFeature, &status, aVersion, driverInfo,
discardFailureId);