2017-10-28 01:55:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-10-28 02:10:06 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-04-29 07:52:54 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_gfx_config_gfxFeature_h
|
|
|
|
#define mozilla_gfx_config_gfxFeature_h
|
|
|
|
|
2016-11-28 19:03:53 +03:00
|
|
|
#include <functional>
|
2016-04-29 07:52:54 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "gfxTelemetry.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2020-05-04 04:01:53 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-06-03 21:54:56 +03:00
|
|
|
#include "nsString.h"
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2020-05-04 04:01:53 +03:00
|
|
|
#define GFX_FEATURE_MAP(_) \
|
|
|
|
/* Name, Type, Description */ \
|
|
|
|
_(HW_COMPOSITING, Feature, "Compositing") \
|
|
|
|
_(D3D11_COMPOSITING, Feature, "Direct3D11 Compositing") \
|
|
|
|
_(OPENGL_COMPOSITING, Feature, "OpenGL Compositing") \
|
|
|
|
_(DIRECT2D, Feature, "Direct2D") \
|
|
|
|
_(D3D11_HW_ANGLE, Feature, "Direct3D11 hardware ANGLE") \
|
|
|
|
_(DIRECT_DRAW, Feature, "DirectDraw") \
|
|
|
|
_(GPU_PROCESS, Feature, "GPU Process") \
|
|
|
|
_(WEBRENDER, Feature, "WebRender") \
|
|
|
|
_(WEBRENDER_QUALIFIED, Feature, "WebRender qualified") \
|
|
|
|
_(WEBRENDER_COMPOSITOR, Feature, "WebRender native compositor") \
|
|
|
|
_(WEBRENDER_PARTIAL, Feature, "WebRender partial present") \
|
|
|
|
_(WEBRENDER_ANGLE, Feature, "WebRender ANGLE") \
|
|
|
|
_(WEBRENDER_DCOMP_PRESENT, Feature, "WebRender DirectComposition") \
|
|
|
|
_(OMTP, Feature, "Off Main Thread Painting") \
|
|
|
|
_(ADVANCED_LAYERS, Feature, "Advanced Layers") \
|
|
|
|
_(WEBGPU, Feature, "WebGPU") \
|
2016-04-29 07:52:54 +03:00
|
|
|
/* Add new entries above this comment */
|
|
|
|
|
|
|
|
enum class Feature : uint32_t {
|
|
|
|
#define MAKE_ENUM(name, type, desc) name,
|
|
|
|
GFX_FEATURE_MAP(MAKE_ENUM)
|
|
|
|
#undef MAKE_ENUM
|
|
|
|
NumValues
|
|
|
|
};
|
|
|
|
|
|
|
|
class FeatureState {
|
2016-04-29 07:52:55 +03:00
|
|
|
friend class gfxConfig;
|
2020-05-04 04:01:53 +03:00
|
|
|
friend class GfxConfigManager; // for testing
|
2016-04-29 07:52:55 +03:00
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
public:
|
2020-05-04 04:01:53 +03:00
|
|
|
FeatureState() { Reset(); }
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
bool IsEnabled() const;
|
2016-04-29 07:52:54 +03:00
|
|
|
FeatureStatus GetValue() const;
|
|
|
|
|
|
|
|
void EnableByDefault();
|
2016-06-03 21:54:56 +03:00
|
|
|
void DisableByDefault(FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId);
|
2016-04-29 07:52:55 +03:00
|
|
|
bool SetDefault(bool aEnable, FeatureStatus aDisableStatus,
|
|
|
|
const char* aDisableMessage);
|
|
|
|
bool InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus,
|
|
|
|
const char* aMessage);
|
2020-05-04 04:01:53 +03:00
|
|
|
void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
|
|
|
|
bool aDefaultValue, Maybe<bool> aUserValue);
|
2016-04-29 07:52:56 +03:00
|
|
|
void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
|
|
|
|
bool aDefaultValue);
|
2016-04-29 07:52:55 +03:00
|
|
|
void UserEnable(const char* aMessage);
|
|
|
|
void UserForceEnable(const char* aMessage);
|
2016-06-03 21:54:56 +03:00
|
|
|
void UserDisable(const char* aMessage, const nsACString& aFailureId);
|
|
|
|
void Disable(FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId);
|
|
|
|
void ForceDisable(FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId) {
|
|
|
|
SetFailed(aStatus, aMessage, aFailureId);
|
2016-04-29 07:52:55 +03:00
|
|
|
}
|
2016-06-03 21:54:56 +03:00
|
|
|
void SetFailed(FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId);
|
|
|
|
bool MaybeSetFailed(bool aEnable, FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId);
|
|
|
|
bool MaybeSetFailed(FeatureStatus aStatus, const char* aMessage,
|
|
|
|
const nsACString& aFailureId);
|
2016-04-29 07:52:55 +03:00
|
|
|
|
2016-04-29 07:52:56 +03:00
|
|
|
// aType is "base", "user", "env", or "runtime".
|
|
|
|
// aMessage may be null.
|
2016-11-28 19:03:53 +03:00
|
|
|
typedef std::function<void(const char* aType, FeatureStatus aStatus,
|
|
|
|
const char* aMessage)>
|
|
|
|
StatusIterCallback;
|
2016-04-29 07:52:56 +03:00
|
|
|
void ForEachStatusChange(const StatusIterCallback& aCallback) const;
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
const char* GetFailureMessage() const;
|
|
|
|
const nsCString& GetFailureId() const;
|
|
|
|
|
|
|
|
bool DisabledByDefault() const;
|
2016-06-03 21:54:56 +03:00
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
private:
|
2016-04-29 07:52:54 +03:00
|
|
|
void SetUser(FeatureStatus aStatus, const char* aMessage);
|
2016-04-29 07:52:55 +03:00
|
|
|
void SetEnvironment(FeatureStatus aStatus, const char* aMessage);
|
2016-04-29 07:52:54 +03:00
|
|
|
void SetRuntime(FeatureStatus aStatus, const char* aMessage);
|
|
|
|
bool IsForcedOnByUser() const;
|
2016-04-29 07:52:55 +03:00
|
|
|
const char* GetRuntimeMessage() const;
|
2016-04-29 07:52:56 +03:00
|
|
|
bool IsInitialized() const { return mDefault.IsInitialized(); }
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
// Clear all state.
|
|
|
|
void Reset();
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
private:
|
2016-06-03 21:54:56 +03:00
|
|
|
void SetFailureId(const nsACString& aFailureId);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
struct Instance {
|
|
|
|
char mMessage[64];
|
|
|
|
FeatureStatus mStatus;
|
|
|
|
|
|
|
|
void Set(FeatureStatus aStatus, const char* aMessage = nullptr);
|
2016-04-29 07:52:56 +03:00
|
|
|
bool IsInitialized() const { return mStatus != FeatureStatus::Unused; }
|
|
|
|
const char* MessageOrNull() const {
|
|
|
|
return mMessage[0] != '\0' ? mMessage : nullptr;
|
|
|
|
}
|
|
|
|
const char* Message() const {
|
|
|
|
MOZ_ASSERT(MessageOrNull());
|
|
|
|
return mMessage;
|
|
|
|
}
|
2016-04-29 07:52:54 +03:00
|
|
|
};
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// The default state is the state we decide on startup, based on the operating
|
|
|
|
// system or a base preference.
|
2016-04-29 07:52:54 +03:00
|
|
|
//
|
|
|
|
// The user state factors in any changes to preferences that the user made.
|
|
|
|
//
|
2016-04-29 07:52:55 +03:00
|
|
|
// The environment state factors in any additional decisions made, such as
|
2020-06-23 18:13:57 +03:00
|
|
|
// availability or blocklisting.
|
2016-04-29 07:52:55 +03:00
|
|
|
//
|
2016-04-29 07:52:54 +03:00
|
|
|
// The runtime state factors in any problems discovered at runtime.
|
|
|
|
Instance mDefault;
|
|
|
|
Instance mUser;
|
2016-04-29 07:52:55 +03:00
|
|
|
Instance mEnvironment;
|
2016-04-29 07:52:54 +03:00
|
|
|
Instance mRuntime;
|
2016-06-03 21:54:56 +03:00
|
|
|
|
|
|
|
// Store the first reported failureId for now but we might want to track this
|
|
|
|
// by instance later if we need a specific breakdown.
|
|
|
|
nsCString mFailureId;
|
2016-04-29 07:52:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_gfx_config_gfxFeature_h
|