gecko-dev/gfx/config/gfxVars.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

213 lines
9.4 KiB
C
Raw Normal View History

/* -*- 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_gfxVars_h
#define mozilla_gfx_config_gfxVars_h
#include <stdint.h>
#include "mozilla/Assertions.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/gfx/GraphicsMessages.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/gfx/Types.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
namespace mozilla {
namespace gfx {
class gfxVarReceiver;
// Generator for graphics vars.
#define GFX_VARS_LIST(_) \
/* C++ Name, Data Type, Default Value */ \
_(AllowEglRbab, bool, true) \
_(AllowWebgl2, bool, true) \
_(AllowWebglAccelAngle, bool, true) \
_(AllowWebglOop, bool, true) \
_(BrowserTabsRemoteAutostart, bool, false) \
_(ContentBackend, BackendType, BackendType::NONE) \
_(SoftwareBackend, BackendType, BackendType::NONE) \
_(TileSize, IntSize, IntSize(-1, -1)) \
_(UseXRender, bool, false) \
_(OffscreenFormat, gfxImageFormat, \
mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) \
_(RequiresAcceleratedGLContextForCompositorOGL, bool, false) \
_(CanUseHardwareVideoDecoding, bool, false) \
_(DXInterop2Blocked, bool, false) \
_(DXNV12Blocked, bool, false) \
_(DXP010Blocked, bool, false) \
_(DXP016Blocked, bool, false) \
_(UseWebRender, bool, false) \
_(UseWebRenderANGLE, bool, false) \
_(UseWebRenderFlipSequentialWin, bool, false) \
_(UseWebRenderDCompWin, bool, false) \
_(UseWebRenderDCompVideoOverlayWin, bool, false) \
_(UseWebRenderTripleBufferingWin, bool, false) \
_(UseWebRenderCompositor, bool, false) \
_(UseWebRenderProgramBinaryDisk, bool, false) \
_(UseWebRenderOptimizedShaders, bool, false) \
_(UseWebRenderMultithreading, bool, false) \
_(UseWebRenderScissoredCacheClears, bool, true) \
Bug 1671289 - Improve WebRender's integrated profiler. r=gw In a (large-ish) nutshell: - Consolidate all counters under a single type. - Counters are all arranged in an array and referred to via index. - All counters can be displayed as average+max (float/int), graph, and change indicator. - Specify what to show and in what form via a pref. - All counters and visualizations support not having values every frame. - GPU time queries visualization is easier to read relative to the frame budget: - If the maximum value is under 16ms, the right side of the graph is fixed at 16ms. - If the maximum value is above 16ms, draw a vertical bar at 16ms. - Added a few new profile counters: - Total frame CPU time (from API send to the end of GPU command submission). - Visibility, Prepare, Batching and Glyph resolve times. The main change is how profile counters are represented. Instead of having different types for different visualizations, every counter is represented the same way, tracking average/max values over half a ms and optionally recording a graph over a number of frames. Counters are stored in a vector and referred to via index (See constants at the top of profiler.rs). The main motivation for this storage is to facilitate adding counters without having to think too much about where to store them and how to pass them to the renderer. The profiler's UI is defined by a string with with a single syntax: - Comma separated list of tokens (leading and trailing spaces ignored), which can be: - A counter name: - If prefixed with a '#' character, the counter is shown as a graph. - If prefixed with a '*' character, the counter is shown as a change indicator - By default (counter name without prefix), the counter is shown as average and max over half a second. - A preset name: - A preset is a builtin UI string in the same syntax that can be nested in the main UI string. - Presets are defined towards the top of profiler.rs and can also refer to other presets. - An empty token adds a bit of vertical space. - A '|' token begins a new column. - A '_' token begins a new row. Differential Revision: https://phabricator.services.mozilla.com/D93603
2020-10-20 08:54:04 +00:00
_(WebRenderProfilerUI, nsCString, nsCString()) \
_(WebglAllowCoreProfile, bool, true) \
_(WebglAllowWindowsNativeGl, bool, false) \
_(WebRenderMaxPartialPresentRects, int32_t, 0) \
_(WebRenderDebugFlags, int32_t, 0) \
_(WebRenderBatchingLookback, int32_t, 10) \
_(UseSoftwareWebRender, bool, false) \
_(AllowSoftwareWebRenderD3D11, bool, false) \
_(ScreenDepth, int32_t, 0) \
_(GREDirectory, nsString, nsString()) \
_(ProfDirectory, nsString, nsString()) \
_(UseOMTP, bool, false) \
_(AllowD3D11KeyedMutex, bool, false) \
_(SystemTextQuality, int32_t, 5 /* CLEARTYPE_QUALITY */) \
_(LayersWindowRecordingPath, nsCString, nsCString()) \
_(RemoteCanvasEnabled, bool, false) \
_(UseDoubleBufferingWithCompositor, bool, false) \
_(UseGLSwizzle, bool, true) \
_(ForceSubpixelAAWherePossible, bool, false) \
_(DwmCompositionEnabled, bool, true) \
_(FxREmbedded, bool, false) \
_(UseAHardwareBufferContent, bool, false) \
_(UseAHardwareBufferSharedSurface, bool, false) \
_(UseEGL, bool, false) \
_(DrmRenderDevice, nsCString, nsCString()) \
_(UseDMABuf, bool, false) \
_(WebRenderRequiresHardwareDriver, bool, false)
/* Add new entries above this line. */
// Some graphics settings are computed on the UI process and must be
// communicated to content and GPU processes. gfxVars helps facilitate
// this. Its function is similar to StaticPrefs, except rather than hold
// user preferences, it holds dynamically computed values.
//
// Each variable in GFX_VARS_LIST exposes the following static methods:
//
// const DataType& CxxName();
// void SetCxxName(const DataType& aValue);
//
// Note that the setter may only be called in the UI process; a gfxVar must be
// a variable that is determined in the UI process and pushed to child
// processes.
class gfxVars final {
public:
// These values will be used during the Initialize() call if set. Any
// updates that come before initialization will get added to this array.
static void SetValuesForInitialize(
const nsTArray<GfxVarUpdate>& aInitUpdates);
static void Initialize();
static void Shutdown();
static void ApplyUpdate(const GfxVarUpdate& aUpdate);
static void AddReceiver(gfxVarReceiver* aReceiver);
static void RemoveReceiver(gfxVarReceiver* aReceiver);
// Return a list of updates for all variables with non-default values.
static nsTArray<GfxVarUpdate> FetchNonDefaultVars();
public:
// Each variable must expose Set and Get methods for IPDL.
class VarBase {
public:
VarBase();
virtual void SetValue(const GfxVarValue& aValue) = 0;
virtual void GetValue(GfxVarValue* aOutValue) = 0;
virtual bool HasDefaultValue() const = 0;
size_t Index() const { return mIndex; }
private:
size_t mIndex;
};
private:
static StaticAutoPtr<gfxVars> sInstance;
static StaticAutoPtr<nsTArray<VarBase*>> sVarList;
template <typename T, T Default(), T GetFrom(const GfxVarValue& aValue)>
class VarImpl final : public VarBase {
public:
VarImpl() : mValue(Default()) {}
void SetValue(const GfxVarValue& aValue) override {
mValue = GetFrom(aValue);
if (mListener) {
mListener();
}
}
void GetValue(GfxVarValue* aOutValue) override {
*aOutValue = GfxVarValue(mValue);
}
bool HasDefaultValue() const override { return mValue == Default(); }
const T& Get() const { return mValue; }
// Return true if the value changed, false otherwise.
bool Set(const T& aValue) {
MOZ_ASSERT(XRE_IsParentProcess());
if (mValue == aValue) {
return false;
}
mValue = aValue;
if (mListener) {
mListener();
}
return true;
}
void SetListener(const std::function<void()>& aListener) {
mListener = aListener;
}
private:
T mValue;
std::function<void()> mListener;
};
#define GFX_VAR_DECL(CxxName, DataType, DefaultValue) \
private: \
static DataType Get##CxxName##Default() { return DefaultValue; } \
static DataType Get##CxxName##From(const GfxVarValue& aValue) { \
return aValue.get_##DataType(); \
} \
VarImpl<DataType, Get##CxxName##Default, Get##CxxName##From> mVar##CxxName; \
\
public: \
static const DataType& CxxName() { return sInstance->mVar##CxxName.Get(); } \
static DataType Get##CxxName##OrDefault() { \
if (!sInstance) { \
return DefaultValue; \
} \
return sInstance->mVar##CxxName.Get(); \
} \
static void Set##CxxName(const DataType& aValue) { \
if (sInstance->mVar##CxxName.Set(aValue)) { \
sInstance->NotifyReceivers(&sInstance->mVar##CxxName); \
} \
} \
\
static void Set##CxxName##Listener(const std::function<void()>& aListener) { \
sInstance->mVar##CxxName.SetListener(aListener); \
}
GFX_VARS_LIST(GFX_VAR_DECL)
#undef GFX_VAR_DECL
private:
gfxVars();
void NotifyReceivers(VarBase* aVar);
private:
nsTArray<gfxVarReceiver*> mReceivers;
};
#undef GFX_VARS_LIST
} // namespace gfx
} // namespace mozilla
#endif // mozilla_gfx_config_gfxVars_h