GfxInfoBase.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef __mozilla_widget_GfxInfoBase_h__
  8. #define __mozilla_widget_GfxInfoBase_h__
  9. #include "GfxDriverInfo.h"
  10. #include "GfxInfoCollector.h"
  11. #include "gfxFeature.h"
  12. #include "gfxTelemetry.h"
  13. #include "js/Value.h"
  14. #include "mozilla/Attributes.h"
  15. #include "mozilla/Maybe.h"
  16. #include "mozilla/Mutex.h"
  17. #include "nsCOMPtr.h"
  18. #include "nsIGfxInfo.h"
  19. #include "nsIGfxInfoDebug.h"
  20. #include "nsIObserver.h"
  21. #include "nsString.h"
  22. #include "nsTArray.h"
  23. #include "nsWeakReference.h"
  24. namespace mozilla {
  25. namespace widget {
  26. class GfxInfoBase : public nsIGfxInfo,
  27. public nsIObserver,
  28. public nsSupportsWeakReference
  29. #ifdef DEBUG
  30. , public nsIGfxInfoDebug
  31. #endif
  32. {
  33. public:
  34. GfxInfoBase();
  35. NS_DECL_THREADSAFE_ISUPPORTS
  36. NS_DECL_NSIOBSERVER
  37. // We only declare a subset of the nsIGfxInfo interface. It's up to derived
  38. // classes to implement the rest of the interface.
  39. // Derived classes need to use
  40. // using GfxInfoBase::GetFeatureStatus;
  41. // using GfxInfoBase::GetFeatureSuggestedDriverVersion;
  42. // using GfxInfoBase::GetWebGLParameter;
  43. // to import the relevant methods into their namespace.
  44. NS_IMETHOD GetFeatureStatus(int32_t aFeature, nsACString& aFailureId, int32_t *_retval) override;
  45. NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature, nsAString & _retval) override;
  46. NS_IMETHOD GetWebGLParameter(const nsAString & aParam, nsAString & _retval) override;
  47. NS_IMETHOD GetMonitors(JSContext* cx, JS::MutableHandleValue _retval) override;
  48. NS_IMETHOD GetFailures(uint32_t *failureCount, int32_t** indices, char ***failures) override;
  49. NS_IMETHOD_(void) LogFailure(const nsACString &failure) override;
  50. NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override;
  51. NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override;
  52. NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
  53. NS_IMETHOD GetActiveCrashGuards(JSContext*, JS::MutableHandle<JS::Value>) override;
  54. NS_IMETHOD GetContentBackend(nsAString & aContentBackend) override;
  55. // Initialization function. If you override this, you must call this class's
  56. // version of Init first.
  57. // We need Init to be called separately from the constructor so we can
  58. // register as an observer after all derived classes have been constructed
  59. // and we know we have a non-zero refcount.
  60. // Ideally, Init() would be void-return, but the rules of
  61. // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
  62. virtual nsresult Init();
  63. // only useful on X11
  64. NS_IMETHOD_(void) GetData() override { }
  65. static void AddCollector(GfxInfoCollectorBase* collector);
  66. static void RemoveCollector(GfxInfoCollectorBase* collector);
  67. static nsTArray<GfxDriverInfo>* mDriverInfo;
  68. static bool mDriverInfoObserverInitialized;
  69. static bool mShutdownOccurred;
  70. virtual nsString Model() { return EmptyString(); }
  71. virtual nsString Hardware() { return EmptyString(); }
  72. virtual nsString Product() { return EmptyString(); }
  73. virtual nsString Manufacturer() { return EmptyString(); }
  74. virtual uint32_t OperatingSystemVersion() { return 0; }
  75. // Convenience to get the application version
  76. static const nsCString& GetApplicationVersion();
  77. virtual nsresult FindMonitors(JSContext* cx, JS::HandleObject array) {
  78. return NS_ERROR_NOT_IMPLEMENTED;
  79. }
  80. protected:
  81. virtual ~GfxInfoBase();
  82. virtual nsresult GetFeatureStatusImpl(int32_t aFeature, int32_t* aStatus,
  83. nsAString& aSuggestedDriverVersion,
  84. const nsTArray<GfxDriverInfo>& aDriverInfo,
  85. nsACString& aFailureId,
  86. OperatingSystem* aOS = nullptr);
  87. // Gets the driver info table. Used by GfxInfoBase to check for general cases
  88. // (while subclasses check for more specific ones).
  89. virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo() = 0;
  90. virtual void DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> obj);
  91. bool InitFeatureObject(
  92. JSContext* aCx,
  93. JS::Handle<JSObject*> aContainer,
  94. const char* aName,
  95. int32_t aFeature,
  96. Maybe<mozilla::gfx::FeatureStatus> aKnownStatus,
  97. JS::MutableHandle<JSObject*> aOutObj);
  98. private:
  99. virtual int32_t FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& aDriverInfo,
  100. nsAString& aSuggestedVersion,
  101. int32_t aFeature,
  102. nsACString &aFailureId,
  103. OperatingSystem os);
  104. void EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo);
  105. bool BuildFeatureStateLog(JSContext* aCx, const gfx::FeatureState& aFeature,
  106. JS::MutableHandle<JS::Value> aOut);
  107. Mutex mMutex;
  108. };
  109. } // namespace widget
  110. } // namespace mozilla
  111. #endif /* __mozilla_widget_GfxInfoBase_h__ */