gecko-dev/gfx/config/gfxFeature.h
Narcis Beleuzu 1f50773a6e Backed out 8 changesets (bug 1647225) for xpcshell failures on test_gfxBlacklist_Version.js CLOSED TREE
Backed out changeset b6f88195da61 (bug 1647225)
Backed out changeset a5b3f54cb5f2 (bug 1647225)
Backed out changeset 6a1025189b0e (bug 1647225)
Backed out changeset b95de94b444e (bug 1647225)
Backed out changeset ed2c7dfd8373 (bug 1647225)
Backed out changeset 1adc99494bcb (bug 1647225)
Backed out changeset 5d0cf22c335a (bug 1647225)
Backed out changeset 956b43a8636f (bug 1647225)
2020-06-23 04:34:12 +03:00

149 lines
5.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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
#include <functional>
#include <stdint.h>
#include "gfxTelemetry.h"
#include "mozilla/Assertions.h"
#include "mozilla/Maybe.h"
#include "nsString.h"
namespace mozilla {
namespace gfx {
#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") \
/* 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 {
friend class gfxConfig;
friend class GfxConfigManager; // for testing
public:
FeatureState() { Reset(); }
bool IsEnabled() const;
FeatureStatus GetValue() const;
void EnableByDefault();
void DisableByDefault(FeatureStatus aStatus, const char* aMessage,
const nsACString& aFailureId);
bool SetDefault(bool aEnable, FeatureStatus aDisableStatus,
const char* aDisableMessage);
bool InitOrUpdate(bool aEnable, FeatureStatus aDisableStatus,
const char* aMessage);
void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
bool aDefaultValue, Maybe<bool> aUserValue);
void SetDefaultFromPref(const char* aPrefName, bool aIsEnablePref,
bool aDefaultValue);
void UserEnable(const char* aMessage);
void UserForceEnable(const char* aMessage);
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);
}
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);
// aType is "base", "user", "env", or "runtime".
// aMessage may be null.
typedef std::function<void(const char* aType, FeatureStatus aStatus,
const char* aMessage)>
StatusIterCallback;
void ForEachStatusChange(const StatusIterCallback& aCallback) const;
const char* GetFailureMessage() const;
const nsCString& GetFailureId() const;
bool DisabledByDefault() const;
private:
void SetUser(FeatureStatus aStatus, const char* aMessage);
void SetEnvironment(FeatureStatus aStatus, const char* aMessage);
void SetRuntime(FeatureStatus aStatus, const char* aMessage);
bool IsForcedOnByUser() const;
const char* GetRuntimeMessage() const;
bool IsInitialized() const { return mDefault.IsInitialized(); }
void AssertInitialized() const { MOZ_ASSERT(IsInitialized()); }
// Clear all state.
void Reset();
private:
void SetFailureId(const nsACString& aFailureId);
struct Instance {
char mMessage[64];
FeatureStatus mStatus;
void Set(FeatureStatus aStatus, const char* aMessage = nullptr);
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;
}
};
// The default state is the state we decide on startup, based on the operating
// system or a base preference.
//
// The user state factors in any changes to preferences that the user made.
//
// The environment state factors in any additional decisions made, such as
// availability or blacklisting.
//
// The runtime state factors in any problems discovered at runtime.
Instance mDefault;
Instance mUser;
Instance mEnvironment;
Instance mRuntime;
// 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;
};
} // namespace gfx
} // namespace mozilla
#endif // mozilla_gfx_config_gfxFeature_h