Bug 1770025 [wpt PR 34116] - Update wpt metadata, a=testonly
[gecko.git] / widget / GfxInfoBase.h
blobc6b1895dd630a0f5a36392deceb00adb6abfb908
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;
57 NS_IMETHOD GetMonitors(JSContext* cx,
58 JS::MutableHandleValue _retval) override;
59 NS_IMETHOD GetFailures(nsTArray<int32_t>& indices,
60 nsTArray<nsCString>& failures) override;
61 NS_IMETHOD_(void) LogFailure(const nsACString& failure) override;
62 NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override;
63 NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override;
64 NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
65 NS_IMETHOD GetActiveCrashGuards(JSContext*,
66 JS::MutableHandle<JS::Value>) override;
67 NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override;
68 NS_IMETHOD GetAzureCanvasBackend(nsAString& aBackend) override;
69 NS_IMETHOD GetAzureContentBackend(nsAString& aBackend) override;
70 NS_IMETHOD GetUsingGPUProcess(bool* aOutValue) override;
71 NS_IMETHOD GetWebRenderEnabled(bool* aWebRenderEnabled) override;
72 NS_IMETHOD GetIsHeadless(bool* aIsHeadless) override;
73 NS_IMETHOD GetTargetFrameRate(uint32_t* aTargetFrameRate) override;
75 // Non-XPCOM method to get IPC data:
76 nsTArray<mozilla::gfx::GfxInfoFeatureStatus> GetAllFeatures();
78 // Initialization function. If you override this, you must call this class's
79 // version of Init first.
80 // We need Init to be called separately from the constructor so we can
81 // register as an observer after all derived classes have been constructed
82 // and we know we have a non-zero refcount.
83 // Ideally, Init() would be void-return, but the rules of
84 // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
85 virtual nsresult Init();
87 NS_IMETHOD_(void) GetData() override;
88 NS_IMETHOD_(int32_t) GetMaxRefreshRate(bool* aMixed) override;
90 static void AddCollector(GfxInfoCollectorBase* collector);
91 static void RemoveCollector(GfxInfoCollectorBase* collector);
93 static nsTArray<GfxDriverInfo>* sDriverInfo;
94 static StaticAutoPtr<nsTArray<mozilla::gfx::GfxInfoFeatureStatus>>
95 sFeatureStatus;
96 static bool sDriverInfoObserverInitialized;
97 static bool sShutdownOccurred;
99 virtual nsString Model() { return u""_ns; }
100 virtual nsString Hardware() { return u""_ns; }
101 virtual nsString Product() { return u""_ns; }
102 virtual nsString Manufacturer() { return u""_ns; }
103 virtual uint32_t OperatingSystemVersion() { return 0; }
104 virtual uint32_t OperatingSystemBuild() { return 0; }
106 // Convenience to get the application version
107 static const nsCString& GetApplicationVersion();
109 virtual nsresult FindMonitors(JSContext* cx, JS::HandleObject array);
111 static void SetFeatureStatus(
112 nsTArray<mozilla::gfx::GfxInfoFeatureStatus>&& aFS);
114 protected:
115 virtual ~GfxInfoBase();
117 virtual nsresult GetFeatureStatusImpl(
118 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedDriverVersion,
119 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
120 OperatingSystem* aOS = nullptr);
122 // Gets the driver info table. Used by GfxInfoBase to check for general cases
123 // (while subclasses check for more specific ones).
124 virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo() = 0;
126 virtual void DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> obj);
128 bool DoesDesktopEnvironmentMatch(const nsAString& aBlocklistDesktop,
129 const nsAString& aDesktopEnv);
131 virtual bool DoesWindowProtocolMatch(
132 const nsAString& aBlocklistWindowProtocol,
133 const nsAString& aWindowProtocol);
135 bool DoesVendorMatch(const nsAString& aBlocklistVendor,
136 const nsAString& aAdapterVendor);
138 virtual bool DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
139 const nsAString& aDriverVendor);
141 bool InitFeatureObject(JSContext* aCx, JS::Handle<JSObject*> aContainer,
142 const char* aName,
143 mozilla::gfx::FeatureState& aFeatureState,
144 JS::MutableHandle<JSObject*> aOutObj);
146 NS_IMETHOD ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) override;
148 NS_IMETHOD KillGPUProcessForTests() override;
149 NS_IMETHOD CrashGPUProcessForTests() override;
151 // Total number of pixels for all detected screens at startup.
152 int64_t mScreenPixels;
154 private:
155 virtual int32_t FindBlocklistedDeviceInList(
156 const nsTArray<GfxDriverInfo>& aDriverInfo, nsAString& aSuggestedVersion,
157 int32_t aFeature, nsACString& aFailureId, OperatingSystem os,
158 bool aForAllowing);
160 bool IsFeatureAllowlisted(int32_t aFeature) const;
162 void EvaluateDownloadedBlocklist(nsTArray<GfxDriverInfo>& aDriverInfo);
164 bool BuildFeatureStateLog(JSContext* aCx, const gfx::FeatureState& aFeature,
165 JS::MutableHandle<JS::Value> aOut);
167 Mutex mMutex MOZ_UNANNOTATED;
170 } // namespace widget
171 } // namespace mozilla
173 #endif /* __mozilla_widget_GfxInfoBase_h__ */