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/StaticPtr.h"
20 #include "mozilla/gfx/GraphicsMessages.h"
22 #include "nsIGfxInfo.h"
23 #include "nsIGfxInfoDebug.h"
24 #include "nsIObserver.h"
27 #include "nsWeakReference.h"
32 class GfxInfoBase
: public nsIGfxInfo
,
34 public nsSupportsWeakReference
37 public nsIGfxInfoDebug
43 NS_DECL_THREADSAFE_ISUPPORTS
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
RefreshMonitors() override
;
60 NS_IMETHOD
GetFailures(nsTArray
<int32_t>& indices
,
61 nsTArray
<nsCString
>& failures
) override
;
62 NS_IMETHOD_(void) LogFailure(const nsACString
& failure
) override
;
63 NS_IMETHOD
GetInfo(JSContext
*, JS::MutableHandle
<JS::Value
>) override
;
64 NS_IMETHOD
GetFeatures(JSContext
*, JS::MutableHandle
<JS::Value
>) override
;
65 NS_IMETHOD
GetFeatureLog(JSContext
*, JS::MutableHandle
<JS::Value
>) override
;
66 NS_IMETHOD
GetActiveCrashGuards(JSContext
*,
67 JS::MutableHandle
<JS::Value
>) override
;
68 NS_IMETHOD
GetContentBackend(nsAString
& aContentBackend
) override
;
69 NS_IMETHOD
GetAzureCanvasBackend(nsAString
& aBackend
) override
;
70 NS_IMETHOD
GetAzureContentBackend(nsAString
& aBackend
) override
;
71 NS_IMETHOD
GetUsingGPUProcess(bool* aOutValue
) override
;
72 NS_IMETHOD
GetWebRenderEnabled(bool* aWebRenderEnabled
) override
;
73 NS_IMETHOD
GetIsHeadless(bool* aIsHeadless
) override
;
74 NS_IMETHOD
GetUsesTiling(bool* aUsesTiling
) override
;
75 NS_IMETHOD
GetContentUsesTiling(bool* aUsesTiling
) override
;
76 NS_IMETHOD
GetOffMainThreadPaintEnabled(
77 bool* aOffMainThreadPaintEnabled
) override
;
78 NS_IMETHOD
GetOffMainThreadPaintWorkerCount(
79 int32_t* aOffMainThreadPaintWorkerCount
) override
;
80 NS_IMETHOD
GetTargetFrameRate(uint32_t* aTargetFrameRate
) override
;
82 // Non-XPCOM method to get IPC data:
83 nsTArray
<mozilla::gfx::GfxInfoFeatureStatus
> GetAllFeatures();
85 // Initialization function. If you override this, you must call this class's
86 // version of Init first.
87 // We need Init to be called separately from the constructor so we can
88 // register as an observer after all derived classes have been constructed
89 // and we know we have a non-zero refcount.
90 // Ideally, Init() would be void-return, but the rules of
91 // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
92 virtual nsresult
Init();
94 NS_IMETHOD_(void) GetData() override
;
95 NS_IMETHOD_(int32_t) GetMaxRefreshRate(bool* aMixed
) override
{
102 static void AddCollector(GfxInfoCollectorBase
* collector
);
103 static void RemoveCollector(GfxInfoCollectorBase
* collector
);
105 static nsTArray
<GfxDriverInfo
>* sDriverInfo
;
106 static StaticAutoPtr
<nsTArray
<mozilla::gfx::GfxInfoFeatureStatus
>>
108 static bool sDriverInfoObserverInitialized
;
109 static bool sShutdownOccurred
;
111 virtual nsString
Model() { return u
""_ns
; }
112 virtual nsString
Hardware() { return u
""_ns
; }
113 virtual nsString
Product() { return u
""_ns
; }
114 virtual nsString
Manufacturer() { return u
""_ns
; }
115 virtual uint32_t OperatingSystemVersion() { return 0; }
116 virtual uint32_t OperatingSystemBuild() { return 0; }
118 // Convenience to get the application version
119 static const nsCString
& GetApplicationVersion();
121 virtual nsresult
FindMonitors(JSContext
* cx
, JS::HandleObject array
);
123 static void SetFeatureStatus(
124 nsTArray
<mozilla::gfx::GfxInfoFeatureStatus
>&& aFS
);
127 virtual ~GfxInfoBase();
129 virtual nsresult
GetFeatureStatusImpl(
130 int32_t aFeature
, int32_t* aStatus
, nsAString
& aSuggestedDriverVersion
,
131 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsACString
& aFailureId
,
132 OperatingSystem
* aOS
= nullptr);
134 // Gets the driver info table. Used by GfxInfoBase to check for general cases
135 // (while subclasses check for more specific ones).
136 virtual const nsTArray
<GfxDriverInfo
>& GetGfxDriverInfo() = 0;
138 virtual void DescribeFeatures(JSContext
* aCx
, JS::Handle
<JSObject
*> obj
);
140 bool DoesDesktopEnvironmentMatch(const nsAString
& aBlocklistDesktop
,
141 const nsAString
& aDesktopEnv
);
143 virtual bool DoesWindowProtocolMatch(
144 const nsAString
& aBlocklistWindowProtocol
,
145 const nsAString
& aWindowProtocol
);
147 bool DoesVendorMatch(const nsAString
& aBlocklistVendor
,
148 const nsAString
& aAdapterVendor
);
150 virtual bool DoesDriverVendorMatch(const nsAString
& aBlocklistVendor
,
151 const nsAString
& aDriverVendor
);
153 bool InitFeatureObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aContainer
,
155 mozilla::gfx::FeatureState
& aFeatureState
,
156 JS::MutableHandle
<JSObject
*> aOutObj
);
158 NS_IMETHOD
ControlGPUProcessForXPCShell(bool aEnable
, bool* _retval
) override
;
160 // Total number of pixels for all detected screens at startup.
161 int64_t mScreenPixels
;
164 virtual int32_t FindBlocklistedDeviceInList(
165 const nsTArray
<GfxDriverInfo
>& aDriverInfo
, nsAString
& aSuggestedVersion
,
166 int32_t aFeature
, nsACString
& aFailureId
, OperatingSystem os
,
169 bool IsFeatureAllowlisted(int32_t aFeature
) const;
171 void EvaluateDownloadedBlocklist(nsTArray
<GfxDriverInfo
>& aDriverInfo
);
173 bool BuildFeatureStateLog(JSContext
* aCx
, const gfx::FeatureState
& aFeature
,
174 JS::MutableHandle
<JS::Value
> aOut
);
179 } // namespace widget
180 } // namespace mozilla
182 #endif /* __mozilla_widget_GfxInfoBase_h__ */