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"
16 #include "mozilla/Attributes.h"
17 #include "mozilla/Maybe.h"
18 #include "mozilla/Mutex.h"
19 #include "mozilla/dom/PContentParent.h"
21 #include "nsIGfxInfo.h"
22 #include "nsIGfxInfoDebug.h"
23 #include "nsIObserver.h"
26 #include "nsWeakReference.h"
31 class GfxInfoBase
: public nsIGfxInfo
,
33 public nsSupportsWeakReference
36 public nsIGfxInfoDebug
42 NS_DECL_THREADSAFE_ISUPPORTS
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 // Non-XPCOM method to get IPC data:
79 void GetAllFeatures(dom::XPCOMInitData
& xpcomInit
);
81 // Initialization function. If you override this, you must call this class's
82 // version of Init first.
83 // We need Init to be called separately from the constructor so we can
84 // register as an observer after all derived classes have been constructed
85 // and we know we have a non-zero refcount.
86 // Ideally, Init() would be void-return, but the rules of
87 // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
88 virtual nsresult
Init();
90 NS_IMETHOD_(void) GetData() override
;
91 NS_IMETHOD_(int32_t) GetMaxRefreshRate() override
{ return -1; }
93 static void AddCollector(GfxInfoCollectorBase
* collector
);
94 static void RemoveCollector(GfxInfoCollectorBase
* collector
);
96 static nsTArray
<GfxDriverInfo
>* sDriverInfo
;
97 static nsTArray
<mozilla::dom::GfxInfoFeatureStatus
>* sFeatureStatus
;
98 static bool sDriverInfoObserverInitialized
;
99 static bool sShutdownOccurred
;
101 virtual nsString
Model() { return EmptyString(); }
102 virtual nsString
Hardware() { return EmptyString(); }
103 virtual nsString
Product() { return EmptyString(); }
104 virtual nsString
Manufacturer() { return EmptyString(); }
105 virtual uint32_t OperatingSystemVersion() { return 0; }
106 virtual uint32_t OperatingSystemBuild() { return 0; }
108 // Convenience to get the application version
109 static const nsCString
& GetApplicationVersion();
111 virtual nsresult
FindMonitors(JSContext
* cx
, JS::HandleObject array
);
113 static void SetFeatureStatus(
114 const nsTArray
<mozilla::dom::GfxInfoFeatureStatus
>& aFS
);
117 virtual ~GfxInfoBase();
119 virtual nsresult
GetFeatureStatusImpl(
120 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedDriverVersion
,
121 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
122 OperatingSystem
* aOS
= nullptr);
124 // Gets the driver info table. Used by GfxInfoBase to check for general cases
125 // (while subclasses check for more specific ones).
126 virtual const nsTArray
<GfxDriverInfo
>& GetGfxDriverInfo() = 0;
128 virtual void DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> obj
);
130 bool DoesDesktopEnvironmentMatch(const nsAString
& aBlocklistDesktop
,
131 const nsAString
& aDesktopEnv
);
133 virtual bool DoesWindowProtocolMatch(
134 const nsAString
& aBlocklistWindowProtocol
,
135 const nsAString
& aWindowProtocol
);
137 bool DoesVendorMatch(const nsAString
& aBlocklistVendor
,
138 const nsAString
& aAdapterVendor
);
140 virtual bool DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
141 const nsAString
& aDriverVendor
);
143 bool InitFeatureObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aContainer
,
145 mozilla::gfx::FeatureState
& aFeatureState
,
146 JS::MutableHandle
<JSObject
*> aOutObj
);
148 NS_IMETHOD
ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) override
;
150 // Total number of pixels for all detected screens at startup.
151 int64_t mScreenPixels
;
154 virtual int32_t FindBlocklistedDeviceInList(
155 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsAString
& aSuggestedVersion
,
156 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
159 bool IsFeatureAllowlisted(int32_t aFeature
) const;
161 void EvaluateDownloadedBlocklist(nsTArray
<GfxDriverInfo
>& aDriverInfo
);
163 bool BuildFeatureStateLog(JSContext
* aCx
, const gfx::FeatureState
& aFeature
,
164 JS::MutableHandle
<JS::Value
> aOut
);
169 } // namespace widget
170 } // namespace mozilla
172 #endif /* __mozilla_widget_GfxInfoBase_h__ */