Bug 1942006 - Upstream a variety of Servo-specific code from Servo's downstream fork...
[gecko.git] / widget / GfxInfoBase.h
blobae111eaa3c47cf3247ef5dc40cce5c641417e8d2
1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef __mozilla_widget_GfxInfoBase_h__
9 #define __mozilla_widget_GfxInfoBase_h__
11 #include "GfxDriverInfo.h"
12 #include "GfxInfoCollector.h"
13 #include "gfxFeature.h"
14 #include "gfxTelemetry.h"
15 #include "js/Value.h"
16 #include "mozilla/Attributes.h"
17 #include "mozilla/Maybe.h"
18 #include "mozilla/Mutex.h"
19 #include "mozilla/StaticPtr.h"
20 #include "mozilla/gfx/GraphicsMessages.h"
21 #include "nsCOMPtr.h"
22 #include "nsIGfxInfo.h"
23 #include "nsIGfxInfoDebug.h"
24 #include "nsIObserver.h"
25 #include "nsString.h"
26 #include "nsTArray.h"
27 #include "nsWeakReference.h"
29 namespace mozilla {
30 namespace widget {
32 class GfxInfoBase : public nsIGfxInfo,
33 public nsIObserver,
34 public nsSupportsWeakReference
35 #ifdef DEBUG
37 public nsIGfxInfoDebug
38 #endif
40 public:
41 GfxInfoBase();
43 NS_DECL_THREADSAFE_ISUPPORTS
44 NS_DECL_NSIOBSERVER
46 // We only declare a subset of the nsIGfxInfo interface. It's up to derived
47 // classes to implement the rest of the interface.
48 // Derived classes need to use
49 // using GfxInfoBase::GetFeatureStatus;
50 // using GfxInfoBase::GetFeatureSuggestedDriverVersion;
51 // to import the relevant methods into their namespace.
52 NS_IMETHOD GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
53 int32_t* _retval) override;
54 NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature,
55 nsAString& _retval) override;
56 NS_IMETHOD GetFeatureStatusStr(const nsAString& aFeature,
57 nsACString& aFailureId,
58 nsAString& _retval) override;
59 NS_IMETHOD GetFeatureSuggestedDriverVersionStr(const nsAString& aFeature,
60 nsAString& _retval) override;
62 NS_IMETHOD GetMonitors(JSContext* cx,
63 JS::MutableHandle<JS::Value> _retval) override;
64 NS_IMETHOD GetFailures(nsTArray<int32_t>& indices,
65 nsTArray<nsCString>& failures) override;
66 NS_IMETHOD_(void) LogFailure(const nsACString& failure) override;
67 NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override;
68 NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override;
69 NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
70 NS_IMETHOD GetActiveCrashGuards(JSContext*,
71 JS::MutableHandle<JS::Value>) override;
72 NS_IMETHOD GetFontVisibilityDetermination(
73 nsIGfxInfo::FontVisibilityDeviceDetermination*
74 aFontVisibilityDetermination) override;
75 NS_IMETHOD GetFontVisibilityDeterminationStr(
76 nsAString& aFontVisibilityDeterminationStr) override;
77 NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override;
78 NS_IMETHOD GetAzureCanvasBackend(nsAString& aBackend) override;
79 NS_IMETHOD GetAzureContentBackend(nsAString& aBackend) override;
80 NS_IMETHOD GetUsingGPUProcess(bool* aOutValue) override;
81 NS_IMETHOD GetUsingRemoteCanvas(bool* aOutValue) override;
82 NS_IMETHOD GetUsingAcceleratedCanvas(bool* aOutValue) override;
83 NS_IMETHOD GetIsHeadless(bool* aIsHeadless) override;
84 NS_IMETHOD GetTargetFrameRate(uint32_t* aTargetFrameRate) override;
85 NS_IMETHOD GetCodecSupportInfo(nsACString& aCodecSupportInfo) override;
87 // Non-XPCOM method to get IPC data:
88 nsTArray<mozilla::gfx::GfxInfoFeatureStatus> GetAllFeatures();
90 // Initialization function. If you override this, you must call this class's
91 // version of Init first.
92 // We need Init to be called separately from the constructor so we can
93 // register as an observer after all derived classes have been constructed
94 // and we know we have a non-zero refcount.
95 // Ideally, Init() would be void-return, but the rules of
96 // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
97 virtual nsresult Init();
99 NS_IMETHOD_(void) GetData() override;
100 NS_IMETHOD_(int32_t) GetMaxRefreshRate(bool* aMixed) override;
101 NS_IMETHOD GetTextScaleFactor(float* aOutValue) override;
103 static void AddCollector(GfxInfoCollectorBase* collector);
104 static void RemoveCollector(GfxInfoCollectorBase* collector);
106 static nsTArray<GfxDriverInfo>* sDriverInfo;
107 static StaticAutoPtr<nsTArray<mozilla::gfx::GfxInfoFeatureStatus>>
108 sFeatureStatus;
109 static bool sDriverInfoObserverInitialized;
110 static bool sShutdownOccurred;
112 virtual nsString Model() { return u""_ns; }
113 virtual nsString Hardware() { return u""_ns; }
114 virtual nsString Product() { return u""_ns; }
115 virtual nsString Manufacturer() { return u""_ns; }
116 virtual uint32_t OperatingSystemVersion() { return 0; }
117 virtual uint32_t OperatingSystemBuild() { return 0; }
119 // Convenience to get the application version
120 static const nsCString& GetApplicationVersion();
122 virtual nsresult FindMonitors(JSContext* cx, JS::Handle<JSObject*> array);
124 static void SetFeatureStatus(
125 nsTArray<mozilla::gfx::GfxInfoFeatureStatus>&& aFS);
127 static bool OnlyAllowFeatureOnKnownConfig(int32_t aFeature);
129 protected:
130 virtual ~GfxInfoBase();
132 virtual OperatingSystem GetOperatingSystem() = 0;
134 virtual nsresult GetFeatureStatusImpl(
135 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedDriverVersion,
136 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
137 OperatingSystem* aOS = nullptr);
139 // Gets the driver info table. Used by GfxInfoBase to check for general cases
140 // (while subclasses check for more specific ones).
141 virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo() = 0;
143 virtual void DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> obj);
145 virtual bool DoesWindowProtocolMatch(
146 const nsAString& aBlocklistWindowProtocol,
147 const nsAString& aWindowProtocol);
149 bool DoesVendorMatch(const nsAString& aBlocklistVendor,
150 const nsAString& aAdapterVendor);
152 virtual bool DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
153 const nsAString& aDriverVendor);
155 bool InitFeatureObject(JSContext* aCx, JS::Handle<JSObject*> aContainer,
156 const char* aName,
157 mozilla::gfx::FeatureState& aFeatureState,
158 JS::MutableHandle<JSObject*> aOutObj);
160 NS_IMETHOD ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) override;
162 NS_IMETHOD KillGPUProcessForTests() override;
163 NS_IMETHOD CrashGPUProcessForTests() override;
165 // Total number of pixels for all detected screens at startup.
166 int64_t mScreenPixels;
168 private:
169 virtual int32_t FindBlocklistedDeviceInList(
170 const nsTArray<GfxDriverInfo>& aDriverInfo, nsAString& aSuggestedVersion,
171 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
172 bool aForAllowing);
174 std::pair<nsIGfxInfo::FontVisibilityDeviceDetermination, nsString>*
175 GetFontVisibilityDeterminationPair();
177 bool IsFeatureAllowlisted(int32_t aFeature) const;
179 void EvaluateDownloadedBlocklist(nsTArray<GfxDriverInfo>& aDriverInfo);
181 bool BuildFeatureStateLog(JSContext* aCx, const gfx::FeatureState& aFeature,
182 JS::MutableHandle<JS::Value> aOut);
184 Mutex mMutex MOZ_UNANNOTATED;
187 } // namespace widget
188 } // namespace mozilla
190 #endif /* __mozilla_widget_GfxInfoBase_h__ */