1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "mozilla/Assertions.h"
11 #include "mozilla/TypedEnum.h"
13 // First time gfxPrefs::GetSingleton() needs to be called on the main thread,
14 // before any of the methods accessing the values are used, but after
15 // the Preferences system has been initialized.
17 // The static methods to access the preference value are safe to call
18 // from any thread after that first call.
20 // To register a preference, you need to add a line in this file using
21 // the DECL_GFX_PREF macro.
23 // Update argument controls whether we read the preference value and save it
24 // or connect with a callback. See UpdatePolicy enum below.
25 // Pref is the string with the preference name.
26 // Name argument is the name of the static function to create.
27 // Type is the type of the preference - bool, int32_t, uint32_t.
28 // Default is the default value for the preference.
30 // For example this line in the .h:
31 // DECL_GFX_PREF(Once,"layers.dump",LayersDump,bool,false);
32 // means that you can call
33 // bool var = gfxPrefs::LayersDump();
34 // from any thread, but that you will only get the preference value of
35 // "layers.dump" as it was set at the start of the session (subject to
36 // note 2 below). If the value was not set, the default would be false.
38 // In another example, this line in the .h:
39 // DECL_GFX_PREF(Live,"gl.msaa-level",MSAALevel,uint32_t,2);
40 // means that every time you call
41 // uint32_t var = gfxPrefs::MSAALevel();
42 // from any thread, you will get the most up to date preference value of
43 // "gl.msaa-level". If the value is not set, the default would be 2.
45 // Note 1: Changing a preference from Live to Once is now as simple
46 // as changing the Update argument. If your code worked before, it will
47 // keep working, and behave as if the user never changes the preference.
48 // Things are a bit more complicated and perhaps even dangerous when
49 // going from Once to Live, or indeed setting a preference to be Live
50 // in the first place, so be careful. You need to be ready for the
51 // values changing mid execution, and if you're using those preferences
52 // in any setup and initialization, you may need to do extra work.
54 // Note 2: Prefs can be set by using the corresponding Set method. For
55 // example, if the accessor is Foo() then calling SetFoo(...) will update
56 // the preference and also change the return value of subsequent Foo() calls.
57 // This is true even for 'Once' prefs which otherwise do not change if the
58 // pref is updated after initialization.
60 #define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \
62 static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
63 static void Set##Name(Type aVal) { MOZ_ASSERT(SingletonExists()); \
64 GetSingleton().mPref##Name.Set(UpdatePolicy::Update, Get##Name##PrefName(), aVal); } \
66 static const char* Get##Name##PrefName() { return Pref; } \
67 static Type Get##Name##PrefDefault() { return Default; } \
68 PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
71 class gfxPrefs MOZ_FINAL
74 // Enums for the update policy.
75 MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy
)
76 Skip
, // Set the value to default, skip any Preferences calls
77 Once
, // Evaluate the preference once, unchanged during the session
78 Live
// Evaluate the preference and set callback so it stays current/live
79 MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy
)
81 // Since we cannot use const char*, use a function that returns it.
82 template <MOZ_ENUM_CLASS_ENUM_TYPE(UpdatePolicy
) Update
, class T
, T
Default(void), const char* Pref(void)>
89 Register(Update
, Pref());
91 void Register(UpdatePolicy aUpdate
, const char* aPreference
)
95 case UpdatePolicy::Skip
:
97 case UpdatePolicy::Once
:
98 mValue
= PrefGet(aPreference
, mValue
);
100 case UpdatePolicy::Live
:
101 PrefAddVarCache(&mValue
,aPreference
, mValue
);
108 void Set(UpdatePolicy aUpdate
, const char* aPref
, T aValue
)
111 PrefSet(aPref
, aValue
);
113 case UpdatePolicy::Skip
:
114 case UpdatePolicy::Live
:
116 case UpdatePolicy::Once
:
117 mValue
= PrefGet(aPref
, mValue
);
127 // This is where DECL_GFX_PREF for each of the preferences should go.
128 // We will keep these in an alphabetical order to make it easier to see if
129 // a method accessing a pref already exists. Just add yours in the list.
131 // The apz prefs are explained in AsyncPanZoomController.cpp
132 DECL_GFX_PREF(Live
, "apz.allow_checkerboarding", APZAllowCheckerboarding
, bool, true);
133 DECL_GFX_PREF(Live
, "apz.asyncscroll.throttle", APZAsyncScrollThrottleTime
, int32_t, 100);
134 DECL_GFX_PREF(Live
, "apz.asyncscroll.timeout", APZAsyncScrollTimeout
, int32_t, 300);
135 DECL_GFX_PREF(Live
, "apz.axis_lock_mode", APZAxisLockMode
, int32_t, 0);
136 DECL_GFX_PREF(Live
, "apz.content_response_timeout", APZContentResponseTimeout
, int32_t, 300);
137 DECL_GFX_PREF(Live
, "apz.cross_slide.enabled", APZCrossSlideEnabled
, bool, false);
138 DECL_GFX_PREF(Live
, "apz.danger_zone_x", APZDangerZoneX
, int32_t, 50);
139 DECL_GFX_PREF(Live
, "apz.danger_zone_y", APZDangerZoneY
, int32_t, 100);
140 DECL_GFX_PREF(Live
, "apz.enlarge_displayport_when_clipped", APZEnlargeDisplayPortWhenClipped
, bool, false);
141 DECL_GFX_PREF(Live
, "apz.fling_accel_interval_ms", APZFlingAccelInterval
, int32_t, 500);
142 DECL_GFX_PREF(Live
, "apz.fling_accel_base_mult", APZFlingAccelBaseMultiplier
, float, 1.0f
);
143 DECL_GFX_PREF(Live
, "apz.fling_accel_supplemental_mult", APZFlingAccelSupplementalMultiplier
, float, 1.0f
);
144 DECL_GFX_PREF(Once
, "apz.fling_friction", APZFlingFriction
, float, 0.002f
);
145 DECL_GFX_PREF(Live
, "apz.fling_repaint_interval", APZFlingRepaintInterval
, int32_t, 75);
146 DECL_GFX_PREF(Once
, "apz.fling_stop_on_tap_threshold", APZFlingStopOnTapThreshold
, float, 0.05f
);
147 DECL_GFX_PREF(Once
, "apz.fling_stopped_threshold", APZFlingStoppedThreshold
, float, 0.01f
);
148 DECL_GFX_PREF(Once
, "apz.max_velocity_inches_per_ms", APZMaxVelocity
, float, -1.0f
);
149 DECL_GFX_PREF(Once
, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize
, uint32_t, 5);
150 DECL_GFX_PREF(Live
, "apz.min_skate_speed", APZMinSkateSpeed
, float, 1.0f
);
151 DECL_GFX_PREF(Live
, "apz.num_paint_duration_samples", APZNumPaintDurationSamples
, int32_t, 3);
152 DECL_GFX_PREF(Live
, "apz.overscroll.enabled", APZOverscrollEnabled
, bool, false);
153 DECL_GFX_PREF(Live
, "apz.overscroll.fling_friction", APZOverscrollFlingFriction
, float, 0.02f
);
154 DECL_GFX_PREF(Live
, "apz.overscroll.fling_stopped_threshold", APZOverscrollFlingStoppedThreshold
, float, 0.4f
);
155 DECL_GFX_PREF(Live
, "apz.overscroll.min_pan_distance_ratio", APZMinPanDistanceRatio
, float, 1.0f
);
156 DECL_GFX_PREF(Live
, "apz.overscroll.stretch_factor", APZOverscrollStretchFactor
, float, 0.5f
);
157 DECL_GFX_PREF(Live
, "apz.overscroll.snap_back.spring_stiffness", APZOverscrollSnapBackSpringStiffness
, float, 0.6f
);
158 DECL_GFX_PREF(Live
, "apz.overscroll.snap_back.spring_friction", APZOverscrollSnapBackSpringFriction
, float, 0.1f
);
159 DECL_GFX_PREF(Live
, "apz.overscroll.snap_back.mass", APZOverscrollSnapBackMass
, float, 1000.0f
);
160 DECL_GFX_PREF(Live
, "apz.pan_repaint_interval", APZPanRepaintInterval
, int32_t, 250);
161 DECL_GFX_PREF(Live
, "apz.printtree", APZPrintTree
, bool, false);
162 DECL_GFX_PREF(Live
, "apz.subframe.enabled", APZSubframeEnabled
, bool, false);
163 DECL_GFX_PREF(Once
, "apz.test.logging_enabled", APZTestLoggingEnabled
, bool, false);
164 DECL_GFX_PREF(Live
, "apz.touch_start_tolerance", APZTouchStartTolerance
, float, 1.0f
/4.5f
);
165 DECL_GFX_PREF(Live
, "apz.use_paint_duration", APZUsePaintDuration
, bool, true);
166 DECL_GFX_PREF(Live
, "apz.velocity_bias", APZVelocityBias
, float, 1.0f
);
167 DECL_GFX_PREF(Live
, "apz.velocity_relevance_time_ms", APZVelocityRelevanceTime
, uint32_t, 150);
168 DECL_GFX_PREF(Live
, "apz.x_skate_size_multiplier", APZXSkateSizeMultiplier
, float, 1.5f
);
169 DECL_GFX_PREF(Live
, "apz.x_stationary_size_multiplier", APZXStationarySizeMultiplier
, float, 3.0f
);
170 DECL_GFX_PREF(Live
, "apz.y_skate_size_multiplier", APZYSkateSizeMultiplier
, float, 2.5f
);
171 DECL_GFX_PREF(Live
, "apz.y_stationary_size_multiplier", APZYStationarySizeMultiplier
, float, 3.5f
);
172 DECL_GFX_PREF(Live
, "apz.zoom_animation_duration_ms", APZZoomAnimationDuration
, int32_t, 250);
174 DECL_GFX_PREF(Once
, "gfx.android.rgb16.force", AndroidRGB16Force
, bool, false);
176 DECL_GFX_PREF(Once
, "gfx.apitrace.enabled", UseApitrace
, bool, false);
178 DECL_GFX_PREF(Live
, "gfx.canvas.azure.accelerated", CanvasAzureAccelerated
, bool, false);
179 DECL_GFX_PREF(Once
, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache
, bool, false);
180 DECL_GFX_PREF(Once
, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize
, int32_t, 96);
181 DECL_GFX_PREF(Once
, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems
, int32_t, 256);
183 DECL_GFX_PREF(Live
, "gfx.color_management.enablev4", CMSEnableV4
, bool, false);
184 DECL_GFX_PREF(Live
, "gfx.color_management.mode", CMSMode
, int32_t,-1);
185 // The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
186 DECL_GFX_PREF(Live
, "gfx.color_management.rendering_intent", CMSRenderingIntent
, int32_t, 0);
188 DECL_GFX_PREF(Once
, "gfx.direct2d.disabled", Direct2DDisabled
, bool, false);
189 DECL_GFX_PREF(Once
, "gfx.direct2d.force-enabled", Direct2DForceEnabled
, bool, false);
190 DECL_GFX_PREF(Live
, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels
, bool, false);
191 DECL_GFX_PREF(Live
, "gfx.layerscope.enabled", LayerScopeEnabled
, bool, false);
192 DECL_GFX_PREF(Live
, "gfx.layerscope.port", LayerScopePort
, int32_t, 23456);
193 DECL_GFX_PREF(Live
, "gfx.perf-warnings.enabled", PerfWarnings
, bool, false);
194 DECL_GFX_PREF(Once
, "gfx.work-around-driver-bugs", WorkAroundDriverBugs
, bool, true);
196 DECL_GFX_PREF(Live
, "gfx.draw-color-bars", CompositorDrawColorBars
, bool, false);
198 // Use vsync events generated by hardware
199 DECL_GFX_PREF(Once
, "gfx.frameuniformity.hw-vsync", FrameUniformityHWVsyncEnabled
, bool, false);
200 DECL_GFX_PREF(Once
, "gfx.touch.resample", TouchResampling
, bool, false);
201 // These times should be in nanoseconds
202 DECL_GFX_PREF(Once
, "gfx.touch.resample.max-predict", TouchResampleMaxPredict
, int32_t, 8000000);
203 DECL_GFX_PREF(Once
, "gfx.touch.resample.vsync-adjust", TouchVsyncSampleAdjust
, int32_t, 5000000);
204 DECL_GFX_PREF(Once
, "gfx.touch.resample.min-resample", TouchResampleMinTime
, int32_t, 2000000);
206 DECL_GFX_PREF(Live
, "gl.msaa-level", MSAALevel
, uint32_t, 2);
208 DECL_GFX_PREF(Once
, "layers.acceleration.disabled", LayersAccelerationDisabled
, bool, false);
209 DECL_GFX_PREF(Live
, "layers.acceleration.draw-fps", LayersDrawFPS
, bool, false);
210 DECL_GFX_PREF(Live
, "layers.acceleration.draw-fps.print-histogram", FPSPrintHistogram
, bool, false);
211 DECL_GFX_PREF(Live
, "layers.acceleration.draw-fps.write-to-file", WriteFPSToFile
, bool, false);
212 DECL_GFX_PREF(Once
, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled
, bool, false);
213 DECL_GFX_PREF(Once
, "layers.async-video.enabled", AsyncVideoEnabled
, bool, true);
214 DECL_GFX_PREF(Once
, "layers.async-video-oop.enabled", AsyncVideoOOPEnabled
, bool, true);
215 DECL_GFX_PREF(Once
, "layers.async-pan-zoom.enabled", AsyncPanZoomEnabled
, bool, false);
216 DECL_GFX_PREF(Live
, "layers.bench.enabled", LayersBenchEnabled
, bool, false);
217 DECL_GFX_PREF(Once
, "layers.bufferrotation.enabled", BufferRotationEnabled
, bool, true);
218 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
219 // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
220 // and ignore the preference.
221 DECL_GFX_PREF(Skip
, "layers.componentalpha.enabled", ComponentAlphaEnabled
, bool, false);
223 // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
224 // preference value, defaulting to true.
225 DECL_GFX_PREF(Once
, "layers.componentalpha.enabled", ComponentAlphaEnabled
, bool, true);
227 DECL_GFX_PREF(Live
, "layers.draw-bigimage-borders", DrawBigImageBorders
, bool, false);
228 DECL_GFX_PREF(Live
, "layers.draw-borders", DrawLayerBorders
, bool, false);
229 DECL_GFX_PREF(Live
, "layers.draw-tile-borders", DrawTileBorders
, bool, false);
230 DECL_GFX_PREF(Live
, "layers.flash-borders", FlashLayerBorders
, bool, false);
231 DECL_GFX_PREF(Live
, "layers.draw-layer-info", DrawLayerInfo
, bool, false);
232 DECL_GFX_PREF(Live
, "layers.dump", LayersDump
, bool, false);
234 // 0 is "no change" for contrast, positive values increase it, negative values
235 // decrease it until we hit mid gray at -1 contrast, after that it gets weird.
236 DECL_GFX_PREF(Live
, "layers.effect.contrast", LayersEffectContrast
, float, 0.0f
);
237 DECL_GFX_PREF(Live
, "layers.effect.grayscale", LayersEffectGrayscale
, bool, false);
238 DECL_GFX_PREF(Live
, "layers.effect.invert", LayersEffectInvert
, bool, false);
240 DECL_GFX_PREF(Once
, "layers.enable-tiles", LayersTilesEnabled
, bool, false);
241 DECL_GFX_PREF(Once
, "layers.simple-tiles", LayersUseSimpleTiles
, bool, false);
242 DECL_GFX_PREF(Once
, "layers.force-per-tile-drawing", PerTileDrawing
, bool, false);
243 DECL_GFX_PREF(Once
, "layers.tiled-drawtarget.enabled", TiledDrawTargetEnabled
, bool, false);
244 // We allow for configurable and rectangular tile size to avoid wasting memory on devices whose
245 // screen size does not align nicely to the default tile size. Although layers can be any size,
246 // they are often the same size as the screen, especially for width.
247 DECL_GFX_PREF(Once
, "layers.tile-width", LayersTileWidth
, int32_t, 256);
248 DECL_GFX_PREF(Once
, "layers.tile-height", LayersTileHeight
, int32_t, 256);
249 DECL_GFX_PREF(Once
, "layers.tile-max-pool-size", LayersTileMaxPoolSize
, uint32_t, (uint32_t)50);
250 DECL_GFX_PREF(Once
, "layers.tile-shrink-pool-timeout", LayersTileShrinkPoolTimeout
, uint32_t, (uint32_t)1000);
251 DECL_GFX_PREF(Once
, "layers.overzealous-gralloc-unlocking", OverzealousGrallocUnlocking
, bool, false);
252 DECL_GFX_PREF(Once
, "layers.force-shmem-tiles", ForceShmemTiles
, bool, false);
253 DECL_GFX_PREF(Live
, "layers.frame-counter", DrawFrameCounter
, bool, false);
254 DECL_GFX_PREF(Live
, "layers.low-precision-buffer", UseLowPrecisionBuffer
, bool, false);
255 DECL_GFX_PREF(Live
, "layers.low-precision-resolution", LowPrecisionResolution
, float, 0.25f
);
256 DECL_GFX_PREF(Live
, "layers.low-precision-opacity", LowPrecisionOpacity
, float, 1.0f
);
257 DECL_GFX_PREF(Once
, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled
, bool, false);
258 DECL_GFX_PREF(Live
, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate
, int32_t,-1);
259 DECL_GFX_PREF(Once
, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled
, bool, false);
260 DECL_GFX_PREF(Once
, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled
, bool, false);
261 DECL_GFX_PREF(Once
, "layers.use-image-offscreen-surfaces", UseImageOffscreenSurfaces
, bool, false);
262 DECL_GFX_PREF(Live
, "layers.orientation.sync.timeout", OrientationSyncMillis
, uint32_t, (uint32_t)0);
263 DECL_GFX_PREF(Once
, "layers.prefer-d3d9", LayersPreferD3D9
, bool, false);
264 DECL_GFX_PREF(Once
, "layers.prefer-opengl", LayersPreferOpenGL
, bool, false);
265 DECL_GFX_PREF(Once
, "layers.progressive-paint", UseProgressiveTilePainting
, bool, false);
266 DECL_GFX_PREF(Once
, "layers.uniformity-info", UniformityInfo
, bool, false);
268 DECL_GFX_PREF(Live
, "layout.css.scroll-behavior.damping-ratio", ScrollBehaviorDampingRatio
, float, 1.0f
);
269 DECL_GFX_PREF(Live
, "layout.css.scroll-behavior.enabled", ScrollBehaviorEnabled
, bool, false);
270 DECL_GFX_PREF(Live
, "layout.css.scroll-behavior.spring-constant", ScrollBehaviorSpringConstant
, float, 250.0f
);
271 DECL_GFX_PREF(Once
, "layout.css.touch_action.enabled", TouchActionEnabled
, bool, false);
272 DECL_GFX_PREF(Once
, "layout.frame_rate", LayoutFrameRate
, int32_t, -1);
273 DECL_GFX_PREF(Live
, "layout.display-list.dump", LayoutDumpDisplayList
, bool, false);
274 DECL_GFX_PREF(Once
, "layout.paint_rects_separately", LayoutPaintRectsSeparately
, bool, true);
276 DECL_GFX_PREF(Live
, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing
, bool, false);
278 DECL_GFX_PREF(Live
, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay
, int32_t, 500);
280 DECL_GFX_PREF(Once
, "webgl.force-layers-readback", WebGLForceLayersReadback
, bool, false);
282 DECL_GFX_PREF(Once
, "layers.stereo-video.enabled", StereoVideoEnabled
, bool, false);
284 // Manage the singleton:
285 static gfxPrefs
& GetSingleton()
287 MOZ_ASSERT(!sInstanceHasBeenDestroyed
, "Should never recreate a gfxPrefs instance!");
289 sInstance
= new gfxPrefs
;
291 MOZ_ASSERT(SingletonExists());
294 static void DestroySingleton();
295 static bool SingletonExists();
298 static gfxPrefs
* sInstance
;
299 static bool sInstanceHasBeenDestroyed
;
302 // Creating these to avoid having to include Preferences.h in the .h
303 static void PrefAddVarCache(bool*, const char*, bool);
304 static void PrefAddVarCache(int32_t*, const char*, int32_t);
305 static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
306 static void PrefAddVarCache(float*, const char*, float);
307 static bool PrefGet(const char*, bool);
308 static int32_t PrefGet(const char*, int32_t);
309 static uint32_t PrefGet(const char*, uint32_t);
310 static float PrefGet(const char*, float);
311 static void PrefSet(const char* aPref
, bool aValue
);
312 static void PrefSet(const char* aPref
, int32_t aValue
);
313 static void PrefSet(const char* aPref
, uint32_t aValue
);
314 static void PrefSet(const char* aPref
, float aValue
);
316 static void AssertMainThread();
320 gfxPrefs(const gfxPrefs
&) MOZ_DELETE
;
321 gfxPrefs
& operator=(const gfxPrefs
&) MOZ_DELETE
;
324 #undef DECL_GFX_PREF /* Don't need it outside of this file */
326 #endif /* GFX_PREFS_H */