Bug 1580312 - Refactor ResponsiveUI into its own module. r=mtigley
[gecko.git] / widget / GfxInfoBase.h
blob527aa2fccb51c04f9e167f25b09ff30734ec4e4a
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/dom/PContentParent.h"
20 #include "nsCOMPtr.h"
21 #include "nsIGfxInfo.h"
22 #include "nsIGfxInfoDebug.h"
23 #include "nsIObserver.h"
24 #include "nsString.h"
25 #include "nsTArray.h"
26 #include "nsWeakReference.h"
28 namespace mozilla {
29 namespace widget {
31 class GfxInfoBase : public nsIGfxInfo,
32 public nsIObserver,
33 public nsSupportsWeakReference
34 #ifdef DEBUG
36 public nsIGfxInfoDebug
37 #endif
39 public:
40 GfxInfoBase();
42 NS_DECL_THREADSAFE_ISUPPORTS
43 NS_DECL_NSIOBSERVER
45 // We only declare a subset of the nsIGfxInfo interface. It's up to derived
46 // classes to implement the rest of the interface.
47 // Derived classes need to use
48 // using GfxInfoBase::GetFeatureStatus;
49 // using GfxInfoBase::GetFeatureSuggestedDriverVersion;
50 // to import the relevant methods into their namespace.
51 NS_IMETHOD GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
52 int32_t* _retval) override;
53 NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature,
54 nsAString& _retval) override;
56 NS_IMETHOD GetMonitors(JSContext* cx,
57 JS::MutableHandleValue _retval) override;
58 NS_IMETHOD GetFailures(nsTArray<int32_t>& indices,
59 nsTArray<nsCString>& failures) override;
60 NS_IMETHOD_(void) LogFailure(const nsACString& failure) override;
61 NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override;
62 NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override;
63 NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
64 NS_IMETHOD GetActiveCrashGuards(JSContext*,
65 JS::MutableHandle<JS::Value>) override;
66 NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override;
67 NS_IMETHOD GetUsingGPUProcess(bool* aOutValue) override;
68 NS_IMETHOD GetWebRenderEnabled(bool* aWebRenderEnabled) override;
69 NS_IMETHOD GetIsHeadless(bool* aIsHeadless) override;
70 NS_IMETHOD GetUsesTiling(bool* aUsesTiling) override;
71 NS_IMETHOD GetContentUsesTiling(bool* aUsesTiling) override;
72 NS_IMETHOD GetOffMainThreadPaintEnabled(
73 bool* aOffMainThreadPaintEnabled) override;
74 NS_IMETHOD GetOffMainThreadPaintWorkerCount(
75 int32_t* aOffMainThreadPaintWorkerCount) override;
76 NS_IMETHOD GetTargetFrameRate(uint32_t* aTargetFrameRate) override;
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 // only useful on X11
88 NS_IMETHOD_(void) GetData() override {}
90 static void AddCollector(GfxInfoCollectorBase* collector);
91 static void RemoveCollector(GfxInfoCollectorBase* collector);
93 static nsTArray<GfxDriverInfo>* sDriverInfo;
94 static nsTArray<mozilla::dom::GfxInfoFeatureStatus>* sFeatureStatus;
95 static bool sDriverInfoObserverInitialized;
96 static bool sShutdownOccurred;
98 virtual nsString Model() { return EmptyString(); }
99 virtual nsString Hardware() { return EmptyString(); }
100 virtual nsString Product() { return EmptyString(); }
101 virtual nsString Manufacturer() { return EmptyString(); }
102 virtual uint32_t OperatingSystemVersion() { return 0; }
104 // Convenience to get the application version
105 static const nsCString& GetApplicationVersion();
107 virtual nsresult FindMonitors(JSContext* cx, JS::HandleObject array);
109 static void SetFeatureStatus(
110 const nsTArray<mozilla::dom::GfxInfoFeatureStatus>& aFS);
112 protected:
113 virtual ~GfxInfoBase();
115 virtual nsresult GetFeatureStatusImpl(
116 int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedDriverVersion,
117 const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
118 OperatingSystem* aOS = nullptr);
120 // Gets the driver info table. Used by GfxInfoBase to check for general cases
121 // (while subclasses check for more specific ones).
122 virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo() = 0;
124 virtual void DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> obj);
126 bool DoesVendorMatch(const nsAString& aBlocklistVendor,
127 const nsAString& aAdapterVendor);
129 virtual bool DoesDriverVendorMatch(const nsAString& aBlocklistVendor,
130 const nsAString& aDriverVendor);
132 bool InitFeatureObject(JSContext* aCx, JS::Handle<JSObject*> aContainer,
133 const char* aName,
134 mozilla::gfx::FeatureStatus& aKnownStatus,
135 JS::MutableHandle<JSObject*> aOutObj);
137 NS_IMETHOD ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) override;
139 private:
140 virtual int32_t FindBlocklistedDeviceInList(
141 const nsTArray<GfxDriverInfo>& aDriverInfo, nsAString& aSuggestedVersion,
142 int32_t aFeature, nsACString& aFailureId, OperatingSystem os);
144 void EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo);
146 bool BuildFeatureStateLog(JSContext* aCx, const gfx::FeatureState& aFeature,
147 JS::MutableHandle<JS::Value> aOut);
149 Mutex mMutex;
152 } // namespace widget
153 } // namespace mozilla
155 #endif /* __mozilla_widget_GfxInfoBase_h__ */