2014-02-13 21:38:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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 GFX_PREFS_H
|
|
|
|
#define GFX_PREFS_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/TypedEnum.h"
|
|
|
|
|
2014-03-04 21:26:33 +04:00
|
|
|
// First time gfxPrefs::GetSingleton() needs to be called on the main thread,
|
2014-02-13 21:38:40 +04:00
|
|
|
// before any of the methods accessing the values are used, but after
|
|
|
|
// the Preferences system has been initialized.
|
|
|
|
|
|
|
|
// The static methods to access the preference value are safe to call
|
|
|
|
// from any thread after that first call.
|
|
|
|
|
|
|
|
// To register a preference, you need to add a line in this file using
|
2014-02-23 03:53:04 +04:00
|
|
|
// the DECL_GFX_PREF macro.
|
2014-02-13 21:38:40 +04:00
|
|
|
//
|
|
|
|
// Update argument controls whether we read the preference value and save it
|
|
|
|
// or connect with a callback. See UpdatePolicy enum below.
|
|
|
|
// Pref is the string with the preference name.
|
|
|
|
// Name argument is the name of the static function to create.
|
|
|
|
// Type is the type of the preference - bool, int32_t, uint32_t.
|
|
|
|
// Default is the default value for the preference.
|
|
|
|
//
|
|
|
|
// For example this line in the .h:
|
2014-02-23 03:53:04 +04:00
|
|
|
// DECL_GFX_PREF(Once,"layers.dump",LayersDump,bool,false);
|
2014-02-13 21:38:40 +04:00
|
|
|
// means that you can call
|
|
|
|
// bool var = gfxPrefs::LayersDump();
|
|
|
|
// from any thread, but that you will only get the preference value of
|
|
|
|
// "layers.dump" as it was set at the start of the session. If the value
|
|
|
|
// was not set, the default would be false.
|
|
|
|
//
|
|
|
|
// In another example, this line in the .h:
|
2014-02-23 03:53:04 +04:00
|
|
|
// DECL_GFX_PREF(Live,"gl.msaa-level",MSAALevel,uint32_t,2);
|
2014-02-13 21:38:40 +04:00
|
|
|
// means that every time you call
|
|
|
|
// uint32_t var = gfxPrefs::MSAALevel();
|
|
|
|
// from any thread, you will get the most up to date preference value of
|
|
|
|
// "gl.msaa-level". If the value is not set, the default would be 2.
|
|
|
|
|
|
|
|
// Note that changing a preference from Live to Once is now as simple
|
|
|
|
// as changing the Update argument. If your code worked before, it will
|
|
|
|
// keep working, and behave as if the user never changes the preference.
|
|
|
|
// Things are a bit more complicated and perhaps even dangerous when
|
|
|
|
// going from Once to Live, or indeed setting a preference to be Live
|
|
|
|
// in the first place, so be careful. You need to be ready for the
|
|
|
|
// values changing mid execution, and if you're using those preferences
|
|
|
|
// in any setup and initialization, you may need to do extra work.
|
|
|
|
|
2014-02-23 03:53:04 +04:00
|
|
|
#define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \
|
2014-02-13 21:38:40 +04:00
|
|
|
public: \
|
2014-03-04 21:26:33 +04:00
|
|
|
static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
|
2014-02-13 21:38:40 +04:00
|
|
|
private: \
|
|
|
|
static const char* Get##Name##PrefName() { return Pref; } \
|
2014-03-03 20:53:21 +04:00
|
|
|
static Type Get##Name##PrefDefault() { return Default; } \
|
|
|
|
PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
|
2014-02-13 21:38:40 +04:00
|
|
|
|
|
|
|
class gfxPrefs;
|
|
|
|
class gfxPrefs MOZ_FINAL
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Enums for the update policy.
|
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
|
|
|
|
Skip, // Set the value to default, skip any Preferences calls
|
|
|
|
Once, // Evaluate the preference once, unchanged during the session
|
|
|
|
Live // Evaluate the preference and set callback so it stays current/live
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy)
|
|
|
|
|
|
|
|
// Since we cannot use const char*, use a function that returns it.
|
2014-03-03 20:53:21 +04:00
|
|
|
template <MOZ_ENUM_CLASS_ENUM_TYPE(UpdatePolicy) Update, class T, T Default(void), const char* Pref(void)>
|
2014-02-13 21:38:40 +04:00
|
|
|
class PrefTemplate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PrefTemplate()
|
2014-03-03 20:53:21 +04:00
|
|
|
: mValue(Default())
|
2014-02-13 21:38:40 +04:00
|
|
|
{
|
|
|
|
Register(Update, Pref());
|
|
|
|
}
|
|
|
|
void Register(UpdatePolicy aUpdate, const char* aPreference)
|
|
|
|
{
|
|
|
|
switch(aUpdate) {
|
|
|
|
case UpdatePolicy::Skip:
|
|
|
|
break;
|
|
|
|
case UpdatePolicy::Once:
|
|
|
|
mValue = PrefGet(aPreference, mValue);
|
|
|
|
break;
|
|
|
|
case UpdatePolicy::Live:
|
|
|
|
PrefAddVarCache(&mValue,aPreference, mValue);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T mValue;
|
|
|
|
};
|
|
|
|
|
2014-02-23 03:53:04 +04:00
|
|
|
// This is where DECL_GFX_PREF for each of the preferences should go.
|
2014-02-13 21:38:40 +04:00
|
|
|
// We will keep these in an alphabetical order to make it easier to see if
|
|
|
|
// a method accessing a pref already exists. Just add yours in the list.
|
|
|
|
|
2014-03-03 20:53:21 +04:00
|
|
|
DECL_GFX_PREF(Once, "apz.fling_friction", APZFlingFriction, float, 0.002f);
|
|
|
|
DECL_GFX_PREF(Once, "apz.fling_stopped_threshold", APZFlingStoppedThreshold, float, 0.01f);
|
|
|
|
DECL_GFX_PREF(Once, "apz.max_event_acceleration", APZMaxEventAcceleration, float, 999.0f);
|
|
|
|
DECL_GFX_PREF(Once, "apz.max_velocity_pixels_per_ms", APZMaxVelocity, float, -1.0f);
|
|
|
|
DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
|
|
|
|
|
2014-03-04 02:11:06 +04:00
|
|
|
DECL_GFX_PREF(Once, "gfx.android.rgb16.force", AndroidRGB16Force, bool, false);
|
2014-02-28 21:59:38 +04:00
|
|
|
#if defined(ANDROID)
|
|
|
|
DECL_GFX_PREF(Once, "gfx.apitrace.enabled", UseApitrace, bool, false);
|
|
|
|
#endif
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated", CanvasAzureAccelerated, bool, false);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96);
|
|
|
|
DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256);
|
2014-02-27 06:53:32 +04:00
|
|
|
|
2014-03-06 01:25:09 +04:00
|
|
|
DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false);
|
|
|
|
DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1);
|
|
|
|
// The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
|
|
|
|
DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0);
|
|
|
|
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false);
|
2014-03-04 02:11:06 +04:00
|
|
|
DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false);
|
2014-02-28 21:59:38 +04:00
|
|
|
DECL_GFX_PREF(Live, "gfx.layerscope.enabled", LayerScopeEnabled, bool, false);
|
|
|
|
DECL_GFX_PREF(Live, "gfx.layerscope.port", LayerScopePort, int32_t, 23456);
|
2014-02-23 03:53:04 +04:00
|
|
|
DECL_GFX_PREF(Once, "gfx.work-around-driver-bugs", WorkAroundDriverBugs, bool, true);
|
|
|
|
|
|
|
|
DECL_GFX_PREF(Live, "gl.msaa-level", MSAALevel, uint32_t, 2);
|
|
|
|
|
2014-02-27 06:53:27 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.acceleration.disabled", LayersAccelerationDisabled, bool, false);
|
2014-03-04 21:26:33 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, false);
|
2014-02-27 06:53:27 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled, bool, false);
|
2014-02-27 06:52:54 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// On windows, ignore the preference value, forcing async video to false.
|
|
|
|
DECL_GFX_PREF(Skip, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
|
|
|
|
#else
|
|
|
|
DECL_GFX_PREF(Once, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
|
2014-02-27 06:53:27 +04:00
|
|
|
#endif
|
|
|
|
DECL_GFX_PREF(Once, "layers.bufferrotation.enabled", BufferRotationEnabled, bool, true);
|
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
// If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
|
|
|
|
// and ignore the preference.
|
|
|
|
DECL_GFX_PREF(Skip, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, false);
|
|
|
|
#else
|
|
|
|
// If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
|
|
|
|
// preference value, defaulting to true.
|
|
|
|
DECL_GFX_PREF(Once, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, true);
|
2014-02-27 06:52:54 +04:00
|
|
|
#endif
|
2014-02-27 06:53:31 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.draw-bigimage-borders", DrawBigImageBorders, bool, false);
|
|
|
|
DECL_GFX_PREF(Live, "layers.draw-borders", DrawLayerBorders, bool, false);
|
|
|
|
DECL_GFX_PREF(Live, "layers.draw-tile-borders", DrawTileBorders, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "layers.dump", LayersDump, bool, false);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.enable-tiles", LayersTilesEnabled, bool, false);
|
2014-03-08 01:34:04 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.force-per-tile-drawing", PerTileDrawing, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking", OverzealousGrallocUnlocking, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "layers.force-shmem-tiles", ForceShmemTiles, bool, false);
|
2014-02-27 06:53:31 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.frame-counter", DrawFrameCounter, bool, false);
|
|
|
|
DECL_GFX_PREF(Live, "layers.low-precision-buffer", UseLowPrecisionBuffer, bool, false);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.low-precision-resolution", LowPrecisionResolution, int32_t, 250);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled, bool, false);
|
2014-02-27 06:52:54 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled, bool, false);
|
2014-02-27 06:52:54 +04:00
|
|
|
DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0);
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.prefer-d3d9", LayersPreferD3D9, bool, false);
|
|
|
|
DECL_GFX_PREF(Once, "layers.prefer-opengl", LayersPreferOpenGL, bool, false);
|
2014-02-27 06:53:31 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.progressive-paint", UseProgressiveTilePainting, bool, false);
|
2014-02-27 06:53:27 +04:00
|
|
|
DECL_GFX_PREF(Once, "layers.scroll-graph", LayersScrollGraph, bool, false);
|
2014-02-27 06:52:54 +04:00
|
|
|
|
|
|
|
DECL_GFX_PREF(Once, "layout.frame_rate", LayoutFrameRate, int32_t, -1);
|
2014-02-27 06:52:54 +04:00
|
|
|
|
2014-02-27 06:53:32 +04:00
|
|
|
DECL_GFX_PREF(Live, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing, bool, false);
|
|
|
|
|
2014-02-28 21:59:37 +04:00
|
|
|
DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false);
|
|
|
|
|
2014-02-13 21:38:40 +04:00
|
|
|
public:
|
|
|
|
// Manage the singleton:
|
2014-03-04 21:26:33 +04:00
|
|
|
static gfxPrefs& GetSingleton()
|
2014-02-23 03:53:04 +04:00
|
|
|
{
|
2014-02-13 21:38:40 +04:00
|
|
|
if (!sInstance) {
|
|
|
|
sInstance = new gfxPrefs;
|
|
|
|
}
|
|
|
|
return *sInstance;
|
|
|
|
}
|
2014-03-04 21:26:33 +04:00
|
|
|
static void DestroySingleton();
|
|
|
|
static bool SingletonExists();
|
2014-02-13 21:38:40 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
static gfxPrefs* sInstance;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Creating these to avoid having to include Preferences.h in the .h
|
|
|
|
static void PrefAddVarCache(bool*, const char*, bool);
|
|
|
|
static void PrefAddVarCache(int32_t*, const char*, int32_t);
|
|
|
|
static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
|
2014-03-03 20:53:21 +04:00
|
|
|
static void PrefAddVarCache(float*, const char*, float);
|
2014-02-13 21:38:40 +04:00
|
|
|
static bool PrefGet(const char*, bool);
|
|
|
|
static int32_t PrefGet(const char*, int32_t);
|
|
|
|
static uint32_t PrefGet(const char*, uint32_t);
|
2014-03-03 20:53:21 +04:00
|
|
|
static float PrefGet(const char*, float);
|
2014-02-13 21:38:40 +04:00
|
|
|
|
|
|
|
gfxPrefs();
|
|
|
|
~gfxPrefs();
|
|
|
|
gfxPrefs(const gfxPrefs&) MOZ_DELETE;
|
|
|
|
gfxPrefs& operator=(const gfxPrefs&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
2014-02-23 03:53:04 +04:00
|
|
|
#undef DECL_GFX_PREF /* Don't need it outside of this file */
|
2014-02-13 21:38:40 +04:00
|
|
|
|
|
|
|
#endif /* GFX_PREFS_H */
|