1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3  *
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/. */
7 
8 #ifndef __mozilla_widget_GfxInfoBase_h__
9 #define __mozilla_widget_GfxInfoBase_h__
10 
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"
27 
28 namespace mozilla {
29 namespace widget {
30 
31 class GfxInfoBase : public nsIGfxInfo,
32                     public nsIObserver,
33                     public nsSupportsWeakReference
34 #ifdef DEBUG
35     ,
36                     public nsIGfxInfoDebug
37 #endif
38 {
39  public:
40   GfxInfoBase();
41 
42   NS_DECL_THREADSAFE_ISUPPORTS
43   NS_DECL_NSIOBSERVER
44 
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;
55 
56   NS_IMETHOD GetMonitors(JSContext* cx,
57                          JS::MutableHandleValue _retval) override;
58   NS_IMETHOD GetFailures(uint32_t* failureCount, int32_t** indices,
59                          char*** 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 GetOffMainThreadPaintEnabled(
72       bool* aOffMainThreadPaintEnabled) override;
73   NS_IMETHOD GetOffMainThreadPaintWorkerCount(
74       int32_t* aOffMainThreadPaintWorkerCount) override;
75 
76   // Initialization function. If you override this, you must call this class's
77   // version of Init first.
78   // We need Init to be called separately from the constructor so we can
79   // register as an observer after all derived classes have been constructed
80   // and we know we have a non-zero refcount.
81   // Ideally, Init() would be void-return, but the rules of
82   // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
83   virtual nsresult Init();
84 
85   // only useful on X11
GetData()86   NS_IMETHOD_(void) GetData() override {}
87 
88   static void AddCollector(GfxInfoCollectorBase* collector);
89   static void RemoveCollector(GfxInfoCollectorBase* collector);
90 
91   static nsTArray<GfxDriverInfo>* mDriverInfo;
92   static nsTArray<mozilla::dom::GfxInfoFeatureStatus>* mFeatureStatus;
93   static bool mDriverInfoObserverInitialized;
94   static bool mShutdownOccurred;
95 
Model()96   virtual nsString Model() { return EmptyString(); }
Hardware()97   virtual nsString Hardware() { return EmptyString(); }
Product()98   virtual nsString Product() { return EmptyString(); }
Manufacturer()99   virtual nsString Manufacturer() { return EmptyString(); }
OperatingSystemVersion()100   virtual uint32_t OperatingSystemVersion() { return 0; }
101 
102   // Convenience to get the application version
103   static const nsCString& GetApplicationVersion();
104 
FindMonitors(JSContext * cx,JS::HandleObject array)105   virtual nsresult FindMonitors(JSContext* cx, JS::HandleObject array) {
106     return NS_ERROR_NOT_IMPLEMENTED;
107   }
108 
109   static void SetFeatureStatus(
110       const nsTArray<mozilla::dom::GfxInfoFeatureStatus>& aFS);
111 
112  protected:
113   virtual ~GfxInfoBase();
114 
115   virtual nsresult GetFeatureStatusImpl(
116       int32_t aFeature, int32_t* aStatus, nsAString& aSuggestedDriverVersion,
117       const nsTArray<GfxDriverInfo>& aDriverInfo, nsACString& aFailureId,
118       OperatingSystem* aOS = nullptr);
119 
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;
123 
124   virtual void DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> obj);
125   bool InitFeatureObject(JSContext* aCx, JS::Handle<JSObject*> aContainer,
126                          const char* aName, int32_t aFeature,
127                          const Maybe<mozilla::gfx::FeatureStatus>& aKnownStatus,
128                          JS::MutableHandle<JSObject*> aOutObj);
129 
130   NS_IMETHOD ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) override;
131 
132  private:
133   virtual int32_t FindBlocklistedDeviceInList(
134       const nsTArray<GfxDriverInfo>& aDriverInfo, nsAString& aSuggestedVersion,
135       int32_t aFeature, nsACString& aFailureId, OperatingSystem os);
136 
137   void EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo);
138 
139   bool BuildFeatureStateLog(JSContext* aCx, const gfx::FeatureState& aFeature,
140                             JS::MutableHandle<JS::Value> aOut);
141 
142   Mutex mMutex;
143 };
144 
145 }  // namespace widget
146 }  // namespace mozilla
147 
148 #endif /* __mozilla_widget_GfxInfoBase_h__ */
149