forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGfxInfoBase.cpp
1930 lines (1697 loc) · 63.4 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 <mutex> // std::call_once
#include "GfxDriverInfo.h"
#include "js/Array.h" // JS::GetArrayLength, JS::NewArrayObject
#include "js/PropertyAndElement.h" // JS_SetElement, JS_SetProperty
#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 "nsIScreenManager.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
#include "nsIXULAppInfo.h"
#include "mozilla/ClearOnShutdown.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;
StaticAutoPtr<nsTArray<gfx::GfxInfoFeatureStatus>> GfxInfoBase::sFeatureStatus;
bool GfxInfoBase::sDriverInfoObserverInitialized;
bool GfxInfoBase::sShutdownOccurred;
// Call this when setting sFeatureStatus to a non-null pointer to
// ensure destruction even if the GfxInfo component is never instantiated.
static void InitFeatureStatus(nsTArray<gfx::GfxInfoFeatureStatus>* aPtr) {
static std::once_flag sOnce;
std::call_once(sOnce, [] { ClearOnShutdown(&GfxInfoBase::sFeatureStatus); });
GfxInfoBase::sFeatureStatus = aPtr;
}
// Observes for shutdown so that the child GfxDriverInfo list is freed.
class ShutdownObserver : public nsIObserver {
virtual ~ShutdownObserver() = default;
public:
ShutdownObserver() = default;
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;
for (auto& deviceFamily : GfxDriverInfo::sDeviceFamilies) {
delete deviceFamily;
deviceFamily = nullptr;
}
for (auto& desktop : GfxDriverInfo::sDesktopEnvironment) {
delete desktop;
desktop = nullptr;
}
for (auto& windowProtocol : GfxDriverInfo::sWindowProtocol) {
delete windowProtocol;
windowProtocol = nullptr;
}
for (auto& deviceVendor : GfxDriverInfo::sDeviceVendors) {
delete deviceVendor;
deviceVendor = nullptr;
}
for (auto& driverVendor : GfxDriverInfo::sDriverVendors) {
delete driverVendor;
driverVendor = 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 BLOCKLIST_PREF_BRANCH "gfx.blacklist."
#define SUGGESTED_VERSION_PREF BLOCKLIST_PREF_BRANCH "suggested-driver-version"
static const char* GetPrefNameForFeature(int32_t aFeature) {
const char* name = nullptr;
switch (aFeature) {
case nsIGfxInfo::FEATURE_DIRECT2D:
name = BLOCKLIST_PREF_BRANCH "direct2d";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS:
name = BLOCKLIST_PREF_BRANCH "layers.direct3d9";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS:
name = BLOCKLIST_PREF_BRANCH "layers.direct3d10";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS:
name = BLOCKLIST_PREF_BRANCH "layers.direct3d10-1";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS:
name = BLOCKLIST_PREF_BRANCH "layers.direct3d11";
break;
case nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE:
name = BLOCKLIST_PREF_BRANCH "direct3d11angle";
break;
case nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING:
name = BLOCKLIST_PREF_BRANCH "hardwarevideodecoding";
break;
case nsIGfxInfo::FEATURE_OPENGL_LAYERS:
name = BLOCKLIST_PREF_BRANCH "layers.opengl";
break;
case nsIGfxInfo::FEATURE_WEBGL_OPENGL:
name = BLOCKLIST_PREF_BRANCH "webgl.opengl";
break;
case nsIGfxInfo::FEATURE_WEBGL_ANGLE:
name = BLOCKLIST_PREF_BRANCH "webgl.angle";
break;
case nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA:
name = BLOCKLIST_PREF_BRANCH "webgl.msaa";
break;
case nsIGfxInfo::FEATURE_STAGEFRIGHT:
name = BLOCKLIST_PREF_BRANCH "stagefright";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264:
name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.h264";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE:
name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.encode";
break;
case nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE:
name = BLOCKLIST_PREF_BRANCH "webrtc.hw.acceleration.decode";
break;
case nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION:
name = BLOCKLIST_PREF_BRANCH "canvas2d.acceleration";
break;
case nsIGfxInfo::FEATURE_DX_INTEROP2:
name = BLOCKLIST_PREF_BRANCH "dx.interop2";
break;
case nsIGfxInfo::FEATURE_GPU_PROCESS:
name = BLOCKLIST_PREF_BRANCH "gpu.process";
break;
case nsIGfxInfo::FEATURE_WEBGL2:
name = BLOCKLIST_PREF_BRANCH "webgl2";
break;
case nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX:
name = BLOCKLIST_PREF_BRANCH "d3d11.keyed.mutex";
break;
case nsIGfxInfo::FEATURE_WEBRENDER:
name = BLOCKLIST_PREF_BRANCH "webrender";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR:
name = BLOCKLIST_PREF_BRANCH "webrender.compositor";
break;
case nsIGfxInfo::FEATURE_DX_NV12:
name = BLOCKLIST_PREF_BRANCH "dx.nv12";
break;
case nsIGfxInfo::FEATURE_DX_P010:
name = BLOCKLIST_PREF_BRANCH "dx.p010";
break;
case nsIGfxInfo::FEATURE_DX_P016:
name = BLOCKLIST_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 = BLOCKLIST_PREF_BRANCH "gl.swizzle";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS:
name = BLOCKLIST_PREF_BRANCH "webrender.scissored_cache_clears";
break;
case nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS:
name = BLOCKLIST_PREF_BRANCH "webgl.allow-oop";
break;
case nsIGfxInfo::FEATURE_THREADSAFE_GL:
name = BLOCKLIST_PREF_BRANCH "gl.threadsafe";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE:
name = BLOCKLIST_PREF_BRANCH "webrender.software";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_OPTIMIZED_SHADERS:
name = BLOCKLIST_PREF_BRANCH "webrender.optimized-shaders";
break;
case nsIGfxInfo::FEATURE_X11_EGL:
name = BLOCKLIST_PREF_BRANCH "x11.egl";
break;
case nsIGfxInfo::FEATURE_DMABUF:
name = BLOCKLIST_PREF_BRANCH "dmabuf";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE:
name = BLOCKLIST_PREF_BRANCH "webrender.program-binary-disk";
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_BLOCKLIST_PREF";
}
return true;
}
static void SetPrefValueForFeature(int32_t aFeature, int32_t aValue,
const nsACString& aFailureId) {
const char* prefname = GetPrefNameForFeature(aFeature);
if (!prefname) return;
if (XRE_IsParentProcess()) {
GfxInfoBase::sFeatureStatus = nullptr;
}
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;
if (XRE_IsParentProcess()) {
GfxInfoBase::sFeatureStatus = nullptr;
}
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 BlocklistOSToOperatingSystem(const nsAString& os) {
if (os.EqualsLiteral("WINNT 6.1")) {
return OperatingSystem::Windows7;
}
if (os.EqualsLiteral("WINNT 6.2")) {
return OperatingSystem::Windows8;
}
if (os.EqualsLiteral("WINNT 6.3")) {
return OperatingSystem::Windows8_1;
}
if (os.EqualsLiteral("WINNT 10.0")) {
return OperatingSystem::Windows10;
}
if (os.EqualsLiteral("Linux")) {
return OperatingSystem::Linux;
}
if (os.EqualsLiteral("Darwin 9")) {
return OperatingSystem::OSX10_5;
}
if (os.EqualsLiteral("Darwin 10")) {
return OperatingSystem::OSX10_6;
}
if (os.EqualsLiteral("Darwin 11")) {
return OperatingSystem::OSX10_7;
}
if (os.EqualsLiteral("Darwin 12")) {
return OperatingSystem::OSX10_8;
}
if (os.EqualsLiteral("Darwin 13")) {
return OperatingSystem::OSX10_9;
}
if (os.EqualsLiteral("Darwin 14")) {
return OperatingSystem::OSX10_10;
}
if (os.EqualsLiteral("Darwin 15")) {
return OperatingSystem::OSX10_11;
}
if (os.EqualsLiteral("Darwin 16")) {
return OperatingSystem::OSX10_12;
}
if (os.EqualsLiteral("Darwin 17")) {
return OperatingSystem::OSX10_13;
}
if (os.EqualsLiteral("Darwin 18")) {
return OperatingSystem::OSX10_14;
}
if (os.EqualsLiteral("Darwin 19")) {
return OperatingSystem::OSX10_15;
}
if (os.EqualsLiteral("Darwin 20")) {
return OperatingSystem::OSX11_0;
}
if (os.EqualsLiteral("Android")) {
return OperatingSystem::Android;
// For historical reasons, "All" in blocklist means "All Windows"
}
if (os.EqualsLiteral("All")) {
return OperatingSystem::Windows;
}
if (os.EqualsLiteral("Darwin")) {
return OperatingSystem::OSX;
}
return OperatingSystem::Unknown;
}
static GfxDeviceFamily* BlocklistDevicesToDeviceFamily(
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->Append(NS_ConvertUTF8toUTF16(devices[i]));
}
return deviceIds;
}
static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) {
MOZ_ASSERT(!aFeature.IsEmpty());
if (aFeature.EqualsLiteral("DIRECT2D")) {
return nsIGfxInfo::FEATURE_DIRECT2D;
}
if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS")) {
return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
}
if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS")) {
return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
}
if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS")) {
return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
}
if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS")) {
return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
}
if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE")) {
return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
}
if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING")) {
return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
}
if (aFeature.EqualsLiteral("OPENGL_LAYERS")) {
return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
}
if (aFeature.EqualsLiteral("WEBGL_OPENGL")) {
return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
}
if (aFeature.EqualsLiteral("WEBGL_ANGLE")) {
return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
}
if (aFeature.EqualsLiteral("WEBGL_MSAA")) {
return nsIGfxInfo::UNUSED_FEATURE_WEBGL_MSAA;
}
if (aFeature.EqualsLiteral("STAGEFRIGHT")) {
return nsIGfxInfo::FEATURE_STAGEFRIGHT;
}
if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE")) {
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
}
if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE")) {
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
}
if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_H264")) {
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_H264;
}
if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION")) {
return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
}
if (aFeature.EqualsLiteral("DX_INTEROP2")) {
return nsIGfxInfo::FEATURE_DX_INTEROP2;
}
if (aFeature.EqualsLiteral("GPU_PROCESS")) {
return nsIGfxInfo::FEATURE_GPU_PROCESS;
}
if (aFeature.EqualsLiteral("WEBGL2")) {
return nsIGfxInfo::FEATURE_WEBGL2;
}
if (aFeature.EqualsLiteral("D3D11_KEYED_MUTEX")) {
return nsIGfxInfo::FEATURE_D3D11_KEYED_MUTEX;
}
if (aFeature.EqualsLiteral("WEBRENDER")) {
return nsIGfxInfo::FEATURE_WEBRENDER;
}
if (aFeature.EqualsLiteral("WEBRENDER_COMPOSITOR")) {
return nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR;
}
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.
if (aFeature.EqualsLiteral("GL_SWIZZLE")) {
return nsIGfxInfo::FEATURE_GL_SWIZZLE;
}
if (aFeature.EqualsLiteral("WEBRENDER_SCISSORED_CACHE_CLEARS")) {
return nsIGfxInfo::FEATURE_WEBRENDER_SCISSORED_CACHE_CLEARS;
}
if (aFeature.EqualsLiteral("ALLOW_WEBGL_OUT_OF_PROCESS")) {
return nsIGfxInfo::FEATURE_ALLOW_WEBGL_OUT_OF_PROCESS;
}
if (aFeature.EqualsLiteral("THREADSAFE_GL")) {
return nsIGfxInfo::FEATURE_THREADSAFE_GL;
}
if (aFeature.EqualsLiteral("WEBRENDER_SOFTWARE")) {
return nsIGfxInfo::FEATURE_WEBRENDER_SOFTWARE;
}
if (aFeature.EqualsLiteral("X11_EGL")) {
return nsIGfxInfo::FEATURE_X11_EGL;
}
if (aFeature.EqualsLiteral("DMABUF")) {
return nsIGfxInfo::FEATURE_DMABUF;
}
// 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 BlocklistFeatureStatusToGfxFeatureStatus(
const nsAString& aStatus) {
if (aStatus.EqualsLiteral("STATUS_OK")) {
return nsIGfxInfo::FEATURE_STATUS_OK;
}
if (aStatus.EqualsLiteral("BLOCKED_DRIVER_VERSION")) {
return nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION;
}
if (aStatus.EqualsLiteral("BLOCKED_DEVICE")) {
return nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
}
if (aStatus.EqualsLiteral("DISCOURAGED")) {
return nsIGfxInfo::FEATURE_DISCOURAGED;
}
if (aStatus.EqualsLiteral("BLOCKED_OS_VERSION")) {
return nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
}
if (aStatus.EqualsLiteral("DENIED")) {
return nsIGfxInfo::FEATURE_DENIED;
}
if (aStatus.EqualsLiteral("ALLOW_QUALIFIED")) {
return nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
}
if (aStatus.EqualsLiteral("ALLOW_ALWAYS")) {
return nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
}
// 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 BlocklistComparatorToComparisonOp(
const nsAString& op) {
if (op.EqualsLiteral("LESS_THAN")) {
return DRIVER_LESS_THAN;
}
if (op.EqualsLiteral("BUILD_ID_LESS_THAN")) {
return DRIVER_BUILD_ID_LESS_THAN;
}
if (op.EqualsLiteral("LESS_THAN_OR_EQUAL")) {
return DRIVER_LESS_THAN_OR_EQUAL;
}
if (op.EqualsLiteral("BUILD_ID_LESS_THAN_OR_EQUAL")) {
return DRIVER_BUILD_ID_LESS_THAN_OR_EQUAL;
}
if (op.EqualsLiteral("GREATER_THAN")) {
return DRIVER_GREATER_THAN;
}
if (op.EqualsLiteral("GREATER_THAN_OR_EQUAL")) {
return DRIVER_GREATER_THAN_OR_EQUAL;
}
if (op.EqualsLiteral("EQUAL")) {
return DRIVER_EQUAL;
}
if (op.EqualsLiteral("NOT_EQUAL")) {
return DRIVER_NOT_EQUAL;
}
if (op.EqualsLiteral("BETWEEN_EXCLUSIVE")) {
return DRIVER_BETWEEN_EXCLUSIVE;
}
if (op.EqualsLiteral("BETWEEN_INCLUSIVE")) {
return DRIVER_BETWEEN_INCLUSIVE;
}
if (op.EqualsLiteral("BETWEEN_INCLUSIVE_START")) {
return DRIVER_BETWEEN_INCLUSIVE_START;
}
return DRIVER_COMPARISON_IGNORED;
}
/*
Deserialize Blocklist 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 BlocklistEntryToDriverInfo(const nsACString& aBlocklistEntry,
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();
}
aDriverInfo.mRuleId = "FEATURE_FAILURE_DL_BLOCKLIST_NO_ID"_ns;
for (const auto& keyValue : aBlocklistEntry.Split('\t')) {
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 " << nsCString(keyValue).get();
return false;
}
const nsCString& key = splitted[0];
const 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 = "FEATURE_FAILURE_DL_BLOCKLIST_"_ns + value;
aDriverInfo.mRuleId = blockIdStr.get();
} else if (key.EqualsLiteral("os")) {
aDriverInfo.mOperatingSystem = BlocklistOSToOperatingSystem(dataValue);
} else if (key.EqualsLiteral("osversion")) {
aDriverInfo.mOperatingSystemVersion = strtoul(value.get(), nullptr, 10);
} else if (key.EqualsLiteral("desktopEnvironment")) {
aDriverInfo.mDesktopEnvironment = dataValue;
} else if (key.EqualsLiteral("windowProtocol")) {
aDriverInfo.mWindowProtocol = dataValue;
} else if (key.EqualsLiteral("vendor")) {
aDriverInfo.mAdapterVendor = dataValue;
} else if (key.EqualsLiteral("driverVendor")) {
aDriverInfo.mDriverVendor = dataValue;
} else if (key.EqualsLiteral("feature")) {
aDriverInfo.mFeature = BlocklistFeatureToGfxFeature(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 =
BlocklistFeatureStatusToGfxFeatureStatus(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 = BlocklistComparatorToComparisonOp(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;
}
const nsCString& minValue = versionRange[0];
const 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 = BlocklistDevicesToDeviceFamily(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;
}
NS_IMETHODIMP
GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
nsTArray<GfxDriverInfo> driverInfo;
NS_ConvertUTF16toUTF8 utf8Data(aData);
for (const auto& blocklistEntry : utf8Data.Split('\n')) {
GfxDriverInfo di;
if (BlocklistEntryToDriverInfo(blocklistEntry, di)) {
// XXX Changing this to driverInfo.AppendElement(di) causes leaks.
// Probably some non-standard semantics of the copy/move operations?
*driverInfo.AppendElement() = di;
// Prevent di falling out of scope from destroying the devices.
di.mDeleteDevices = false;
} else {
driverInfo.AppendElement();
}
}
EvaluateDownloadedBlocklist(driverInfo);
}
return NS_OK;
}
GfxInfoBase::GfxInfoBase() : mScreenPixels(INT64_MAX), mMutex("GfxInfoBase") {}
GfxInfoBase::~GfxInfoBase() = default;
nsresult GfxInfoBase::Init() {
InitGfxDriverInfoShutdownObserver();
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "blocklist-data-gfxItems", true);
}
return NS_OK;
}
void GfxInfoBase::GetData() {
if (mScreenPixels != INT64_MAX) {
// Already initialized.
return;
}
nsCOMPtr<nsIScreenManager> manager =
do_GetService("@mozilla.org/gfx/screenmanager;1");
if (!manager) {
MOZ_ASSERT_UNREACHABLE("failed to get nsIScreenManager");
return;
}
manager->GetTotalScreenPixels(&mScreenPixels);
}
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;
}
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() || XRE_IsGPUProcess()) {
// 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;
}
nsTArray<gfx::GfxInfoFeatureStatus> GfxInfoBase::GetAllFeatures() {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
if (!sFeatureStatus) {
InitFeatureStatus(new nsTArray<gfx::GfxInfoFeatureStatus>());
for (int32_t i = 1; i <= nsIGfxInfo::FEATURE_MAX_VALUE; ++i) {
int32_t status = 0;
nsAutoCString failureId;
GetFeatureStatus(i, failureId, &status);
gfx::GfxInfoFeatureStatus gfxFeatureStatus;
gfxFeatureStatus.feature() = i;
gfxFeatureStatus.status() = status;
gfxFeatureStatus.failureId() = failureId;
sFeatureStatus->AppendElement(gfxFeatureStatus);
}
}
nsTArray<gfx::GfxInfoFeatureStatus> features;
for (const auto& status : *sFeatureStatus) {
gfx::GfxInfoFeatureStatus copy = status;
features.AppendElement(copy);
}
return features;
}
inline bool MatchingAllowStatus(int32_t aStatus) {
switch (aStatus) {
case nsIGfxInfo::FEATURE_ALLOW_ALWAYS:
case nsIGfxInfo::FEATURE_ALLOW_QUALIFIED:
return true;
default:
return false;
}
}
// 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,
uint32_t aSystemOSBuild) {
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;
}
constexpr uint32_t kMinWin10BuildNumber = 18362;
if (aBlockedOS == OperatingSystem::RecentWindows10 &&
aSystemOS == OperatingSystem::Windows10) {
// For allowlist purposes, we sometimes want to restrict to only recent
// versions of Windows 10. This is a bit of a kludge but easier than adding
// complicated blocklist infrastructure for build ID comparisons like driver
// versions.
return aSystemOSBuild >= kMinWin10BuildNumber;
}
if (aBlockedOS == OperatingSystem::NotRecentWindows10) {
if (aSystemOS == OperatingSystem::Windows10) {
return aSystemOSBuild < kMinWin10BuildNumber;
} else {
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;
}
inline bool MatchingBattery(BatteryStatus aBatteryStatus, bool aHasBattery) {
switch (aBatteryStatus) {
case BatteryStatus::All:
return true;
case BatteryStatus::None:
return !aHasBattery;
case BatteryStatus::Present:
return aHasBattery;
}
MOZ_ASSERT_UNREACHABLE("bad battery status");
return false;
}
inline bool MatchingScreenSize(ScreenSizeStatus aScreenStatus,
int64_t aScreenPixels) {
constexpr int64_t kMaxSmallPixels = 2304000; // 1920x1200
constexpr int64_t kMaxMediumPixels = 4953600; // 3440x1440
switch (aScreenStatus) {
case ScreenSizeStatus::All:
return true;
case ScreenSizeStatus::Small:
return aScreenPixels <= kMaxSmallPixels;
case ScreenSizeStatus::SmallAndMedium:
return aScreenPixels <= kMaxMediumPixels;
case ScreenSizeStatus::Medium:
return aScreenPixels > kMaxSmallPixels &&
aScreenPixels <= kMaxMediumPixels;
case ScreenSizeStatus::MediumAndLarge:
return aScreenPixels > kMaxSmallPixels;
case ScreenSizeStatus::Large:
return aScreenPixels > kMaxMediumPixels;
}
MOZ_ASSERT_UNREACHABLE("bad screen status");
return false;
}
int32_t GfxInfoBase::FindBlocklistedDeviceInList(
const nsTArray<GfxDriverInfo>& info, nsAString& aSuggestedVersion,
int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
bool aForAllowing) {
int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
// Some properties are not available on all platforms.
nsAutoString desktopEnvironment;
nsresult rv = GetDesktopEnvironment(desktopEnvironment);
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
return 0;
}
nsAutoString windowProtocol;
rv = GetWindowProtocol(windowProtocol);
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
return 0;
}
bool hasBattery = false;
rv = GetHasBattery(&hasBattery);
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_IMPLEMENTED) {
return 0;
}
uint32_t osBuild = OperatingSystemBuild();
// 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_WIDGET_GTK)
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 the status is FEATURE_ALLOW_*, then it is for the allowlist, not
// blocklisting. Only consider entries for our search mode.
if (MatchingAllowStatus(info[i].mFeatureStatus) != aForAllowing) {