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_gfxConfig_h
|
|
|
|
#define mozilla_gfx_config_gfxConfig_h
|
|
|
|
|
2016-11-28 19:03:53 +03:00
|
|
|
#include <functional>
|
2016-04-29 07:52:54 +03:00
|
|
|
#include "gfxFeature.h"
|
|
|
|
#include "gfxFallback.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2019-03-29 00:13:53 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
// Defined in GraphicsMessages.ipdlh.
|
2019-03-29 00:13:53 +03:00
|
|
|
class FeatureFailure;
|
2016-08-21 06:59:11 +03:00
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Manages the history and state of a graphics feature. The flow of a feature
|
|
|
|
// is:
|
2019-05-25 09:07:49 +03:00
|
|
|
// - A default value, set by all.js, gfxPrefs, or gfxPlatform.
|
2016-04-29 07:52:55 +03:00
|
|
|
// - A user value, set by an external value or user pref.
|
|
|
|
// - An environment value, determined by system/hardware factors or
|
|
|
|
// nsIGfxInfo.
|
|
|
|
// - A runtime value, determined by any failures encountered after enabling
|
|
|
|
// the feature.
|
|
|
|
//
|
|
|
|
// Each state change for a feature is recorded in this class.
|
2016-04-29 07:52:54 +03:00
|
|
|
class gfxConfig {
|
|
|
|
public:
|
2016-04-29 07:52:55 +03:00
|
|
|
// Return the full state history of a feature.
|
|
|
|
static FeatureState& GetFeature(Feature aFeature);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
// Query whether a parameter is enabled, taking into account any user or
|
|
|
|
// runtime overrides. The algorithm works as follow:
|
|
|
|
//
|
2016-04-29 07:52:55 +03:00
|
|
|
// 1. If a runtime decision disabled the feature, return false.
|
|
|
|
// 2. If the user force-enabled the feature, return true.
|
|
|
|
// 3. If the environment disabled the feature, return false.
|
|
|
|
// 4. If the user specified a decision, return it.
|
|
|
|
// 5. Return the base setting for the feature.
|
2016-04-29 07:52:54 +03:00
|
|
|
static bool IsEnabled(Feature aFeature);
|
|
|
|
|
|
|
|
// Query the history of a parameter. ForcedOnByUser returns whether or not
|
|
|
|
// the user specifically used a "force" preference to enable the parameter.
|
|
|
|
// IsDisabledByDefault returns whether or not the initial status of the
|
|
|
|
// feature, before adding user prefs and runtime decisions, was disabled.
|
|
|
|
static bool IsForcedOnByUser(Feature aFeature);
|
2016-08-21 06:59:11 +03:00
|
|
|
|
|
|
|
// This returns true if the feature was disabled by default, or was never
|
|
|
|
// initialized to begin with.
|
2016-04-29 07:52:54 +03:00
|
|
|
static bool IsDisabledByDefault(Feature aFeature);
|
|
|
|
|
2016-04-29 07:52:56 +03:00
|
|
|
// Query the status value of a parameter. This is computed similar to
|
|
|
|
// IsEnabled:
|
2016-04-29 07:52:55 +03:00
|
|
|
//
|
|
|
|
// 1. If a runtime failure was set, return it.
|
|
|
|
// 2. If the user force-enabled the feature, return ForceEnabled.
|
|
|
|
// 3. If an environment status was set, return it.
|
|
|
|
// 4. If a user status was set, return it.
|
|
|
|
// 5. Return the default status.
|
2016-04-29 07:52:54 +03:00
|
|
|
static FeatureStatus GetValue(Feature aFeature);
|
|
|
|
|
2017-07-11 05:30:58 +03:00
|
|
|
// Reset the entire state of a feature.
|
|
|
|
static void Reset(Feature aFeature);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
// Initialize the base value of a parameter. The return value is aEnable.
|
|
|
|
static bool SetDefault(Feature aFeature, bool aEnable,
|
|
|
|
FeatureStatus aDisableStatus,
|
|
|
|
const char* aDisableMessage);
|
2016-04-29 07:52:55 +03:00
|
|
|
static void DisableByDefault(Feature aFeature, FeatureStatus aDisableStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aDisableMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString());
|
2016-04-29 07:52:55 +03:00
|
|
|
static void EnableByDefault(Feature aFeature);
|
2016-04-29 07:52:54 +03:00
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
// Inherit a computed value from another process.
|
|
|
|
static void Inherit(Feature aFeature, FeatureStatus aStatus);
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Set a environment status that overrides both the default and user
|
|
|
|
// statuses; this should be used to disable features based on system
|
|
|
|
// or hardware problems that can be determined up-front. The only
|
|
|
|
// status that can override this decision is the user force-enabling
|
|
|
|
// the feature.
|
2016-04-29 07:52:54 +03:00
|
|
|
static void Disable(Feature aFeature, FeatureStatus aStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString());
|
2016-04-29 07:52:54 +03:00
|
|
|
|
2016-04-29 07:52:56 +03:00
|
|
|
// Given a preference name, infer the default value and whether or not the
|
|
|
|
// user has changed it. |aIsEnablePref| specifies whether or not the pref
|
|
|
|
// is intended to enable a feature (true), or disable it (false).
|
|
|
|
static void SetDefaultFromPref(Feature aFeature, const char* aPrefName,
|
|
|
|
bool aIsEnablePref, bool aDefaultValue);
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Disable a parameter based on a runtime decision. This permanently
|
|
|
|
// disables the feature, since runtime decisions override all other
|
|
|
|
// decisions.
|
|
|
|
static void SetFailed(Feature aFeature, FeatureStatus aStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString());
|
2016-04-29 07:52:55 +03:00
|
|
|
|
|
|
|
// Force a feature to be disabled permanently. This is the same as
|
|
|
|
// SetFailed(), but the name may be clearer depending on the context.
|
|
|
|
static void ForceDisable(Feature aFeature, FeatureStatus aStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString()) {
|
|
|
|
SetFailed(aFeature, aStatus, aMessage, aFailureId);
|
2016-04-29 07:52:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience helpers for SetFailed().
|
|
|
|
static bool MaybeSetFailed(Feature aFeature, bool aEnable,
|
2016-04-29 07:52:54 +03:00
|
|
|
FeatureStatus aDisableStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aDisableMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString()) {
|
2016-04-29 07:52:54 +03:00
|
|
|
if (!aEnable) {
|
2016-06-03 21:54:56 +03:00
|
|
|
SetFailed(aFeature, aDisableStatus, aDisableMessage, aFailureId);
|
2016-04-29 07:52:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Convenience helper for SetFailed().
|
|
|
|
static bool MaybeSetFailed(Feature aFeature, FeatureStatus aStatus,
|
2016-06-03 21:54:56 +03:00
|
|
|
const char* aDisableMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString()) {
|
2016-04-29 07:52:55 +03:00
|
|
|
return MaybeSetFailed(aFeature,
|
|
|
|
(aStatus != FeatureStatus::Available &&
|
|
|
|
aStatus != FeatureStatus::ForceEnabled),
|
2016-06-03 21:54:56 +03:00
|
|
|
aStatus, aDisableMessage, aFailureId);
|
2016-04-29 07:52:55 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Re-enables a feature that was previously disabled, by attaching it to a
|
|
|
|
// fallback. The fallback inherits the message that was used for disabling
|
|
|
|
// the feature. This can be used, for example, when D3D11 fails at runtime
|
|
|
|
// but we acquire a second, successful device with WARP.
|
|
|
|
static void Reenable(Feature aFeature, Fallback aFallback);
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Same as SetDefault, except if the feature already has a default value
|
|
|
|
// set, the new value will be set as a runtime value. This is useful for
|
|
|
|
// when the base value can change (for example, via an update from the
|
|
|
|
// parent process).
|
|
|
|
static bool InitOrUpdate(Feature aFeature, bool aEnable,
|
|
|
|
FeatureStatus aDisableStatus,
|
|
|
|
const char* aDisableMessage);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
// Set a user status that overrides the base value (but not runtime value)
|
|
|
|
// of a parameter.
|
|
|
|
static void UserEnable(Feature aFeature, const char* aMessage);
|
|
|
|
static void UserForceEnable(Feature aFeature, const char* aMessage);
|
2016-06-03 21:54:56 +03:00
|
|
|
static void UserDisable(Feature aFeature, const char* aMessage,
|
|
|
|
const nsACString& aFailureId = EmptyCString());
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
// Query whether a fallback has been toggled.
|
|
|
|
static bool UseFallback(Fallback aFallback);
|
|
|
|
|
2017-07-11 10:13:26 +03:00
|
|
|
// Add a log entry denoting that a given fallback had to be used. This can
|
|
|
|
// be called from any thread in the UI or GPU process.
|
2016-04-29 07:52:54 +03:00
|
|
|
static void EnableFallback(Fallback aFallback, const char* aMessage);
|
|
|
|
|
2016-04-29 07:52:56 +03:00
|
|
|
// Run a callback for each initialized FeatureState.
|
2016-11-28 19:03:53 +03:00
|
|
|
typedef std::function<void(const char* aName, const char* aDescription,
|
|
|
|
FeatureState& aFeature)>
|
|
|
|
FeatureIterCallback;
|
2016-04-29 07:52:56 +03:00
|
|
|
static void ForEachFeature(const FeatureIterCallback& aCallback);
|
|
|
|
|
|
|
|
// Run a callback for each enabled fallback.
|
2016-11-28 19:03:53 +03:00
|
|
|
typedef std::function<void(const char* aName, const char* aMsg)>
|
2016-04-29 07:52:56 +03:00
|
|
|
FallbackIterCallback;
|
|
|
|
static void ForEachFallback(const FallbackIterCallback& aCallback);
|
|
|
|
|
2016-06-03 21:54:56 +03:00
|
|
|
// Get the most descriptive failure id message for this feature.
|
2016-08-21 06:59:11 +03:00
|
|
|
static const nsCString& GetFailureId(Feature aFeature);
|
|
|
|
|
2019-03-29 00:13:53 +03:00
|
|
|
static void ImportChange(Feature aFeature,
|
|
|
|
const Maybe<FeatureFailure>& aChange);
|
2016-06-03 21:54:56 +03:00
|
|
|
|
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
|
|
|
|
2016-04-29 07:52:56 +03:00
|
|
|
private:
|
|
|
|
void ForEachFallbackImpl(const FallbackIterCallback& aCallback);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
private:
|
|
|
|
FeatureState& GetState(Feature aFeature) {
|
|
|
|
MOZ_ASSERT(size_t(aFeature) < kNumFeatures);
|
|
|
|
return mFeatures[size_t(aFeature)];
|
|
|
|
}
|
|
|
|
const FeatureState& GetState(Feature aFeature) const {
|
|
|
|
MOZ_ASSERT(size_t(aFeature) < kNumFeatures);
|
|
|
|
return mFeatures[size_t(aFeature)];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UseFallbackImpl(Fallback aFallback) const;
|
2016-04-29 07:52:56 +03:00
|
|
|
void EnableFallbackImpl(Fallback aFallback, const char* aMessage);
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const size_t kNumFeatures = size_t(Feature::NumValues);
|
2016-04-29 07:52:56 +03:00
|
|
|
static const size_t kNumFallbacks = size_t(Fallback::NumValues);
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
FeatureState mFeatures[kNumFeatures];
|
|
|
|
uint64_t mFallbackBits;
|
2016-04-29 07:52:56 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct FallbackLogEntry {
|
|
|
|
Fallback mFallback;
|
|
|
|
char mMessage[80];
|
|
|
|
};
|
|
|
|
|
|
|
|
FallbackLogEntry mFallbackLog[kNumFallbacks];
|
|
|
|
size_t mNumFallbackLogEntries;
|
2016-04-29 07:52:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_gfx_config_gfxConfig_h
|