Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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/. */
6 #ifndef GFX_PREFS_H
7 #define GFX_PREFS_H
9 #include <stdint.h>
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.
22 //
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.
29 //
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. If the value
36 // was not set, the default would be false.
37 //
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 that 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 #define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \
55 public: \
56 static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
57 private: \
58 static const char* Get##Name##PrefName() { return Pref; } \
59 static Type Get##Name##PrefDefault() { return Default; } \
60 PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
62 class gfxPrefs;
63 class gfxPrefs MOZ_FINAL
64 {
65 private:
66 // Enums for the update policy.
67 MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
68 Skip, // Set the value to default, skip any Preferences calls
69 Once, // Evaluate the preference once, unchanged during the session
70 Live // Evaluate the preference and set callback so it stays current/live
71 MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy)
73 // Since we cannot use const char*, use a function that returns it.
74 template <MOZ_ENUM_CLASS_ENUM_TYPE(UpdatePolicy) Update, class T, T Default(void), const char* Pref(void)>
75 class PrefTemplate
76 {
77 public:
78 PrefTemplate()
79 : mValue(Default())
80 {
81 Register(Update, Pref());
82 }
83 void Register(UpdatePolicy aUpdate, const char* aPreference)
84 {
85 switch(aUpdate) {
86 case UpdatePolicy::Skip:
87 break;
88 case UpdatePolicy::Once:
89 mValue = PrefGet(aPreference, mValue);
90 break;
91 case UpdatePolicy::Live:
92 PrefAddVarCache(&mValue,aPreference, mValue);
93 break;
94 default:
95 MOZ_CRASH();
96 break;
97 }
98 }
99 T mValue;
100 };
102 // This is where DECL_GFX_PREF for each of the preferences should go.
103 // We will keep these in an alphabetical order to make it easier to see if
104 // a method accessing a pref already exists. Just add yours in the list.
106 // The apz prefs are explained in AsyncPanZoomController.cpp
107 DECL_GFX_PREF(Live, "apz.allow-checkerboarding", APZAllowCheckerboarding, bool, true);
108 DECL_GFX_PREF(Live, "apz.asyncscroll.throttle", APZAsyncScrollThrottleTime, int32_t, 100);
109 DECL_GFX_PREF(Live, "apz.asyncscroll.timeout", APZAsyncScrollTimeout, int32_t, 300);
110 DECL_GFX_PREF(Live, "apz.axis_lock_mode", APZAxisLockMode, int32_t, 0);
111 DECL_GFX_PREF(Live, "apz.content_response_timeout", APZContentResponseTimeout, int32_t, 300);
112 DECL_GFX_PREF(Live, "apz.cross_slide.enabled", APZCrossSlideEnabled, bool, false);
113 DECL_GFX_PREF(Live, "apz.enlarge_displayport_when_clipped", APZEnlargeDisplayPortWhenClipped, bool, false);
114 DECL_GFX_PREF(Once, "apz.fling_friction", APZFlingFriction, float, 0.002f);
115 DECL_GFX_PREF(Live, "apz.fling_repaint_interval", APZFlingRepaintInterval, int32_t, 75);
116 DECL_GFX_PREF(Once, "apz.fling_stopped_threshold", APZFlingStoppedThreshold, float, 0.01f);
117 DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms", APZMaxVelocity, float, -1.0f);
118 DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
119 DECL_GFX_PREF(Live, "apz.min_skate_speed", APZMinSkateSpeed, float, 1.0f);
120 DECL_GFX_PREF(Live, "apz.num_paint_duration_samples", APZNumPaintDurationSamples, int32_t, 3);
121 DECL_GFX_PREF(Live, "apz.pan_repaint_interval", APZPanRepaintInterval, int32_t, 250);
122 DECL_GFX_PREF(Live, "apz.subframe.enabled", APZSubframeEnabled, bool, false);
123 DECL_GFX_PREF(Live, "apz.touch_start_tolerance", APZTouchStartTolerance, float, 1.0f/4.5f);
124 DECL_GFX_PREF(Live, "apz.use_paint_duration", APZUsePaintDuration, bool, true);
125 DECL_GFX_PREF(Live, "apz.velocity_bias", APZVelocityBias, float, 1.0f);
126 DECL_GFX_PREF(Live, "apz.x_skate_size_multiplier", APZXSkateSizeMultiplier, float, 1.5f);
127 DECL_GFX_PREF(Live, "apz.x_stationary_size_multiplier", APZXStationarySizeMultiplier, float, 3.0f);
128 DECL_GFX_PREF(Live, "apz.y_skate_size_multiplier", APZYSkateSizeMultiplier, float, 2.5f);
129 DECL_GFX_PREF(Live, "apz.y_stationary_size_multiplier", APZYStationarySizeMultiplier, float, 3.5f);
131 DECL_GFX_PREF(Once, "gfx.android.rgb16.force", AndroidRGB16Force, bool, false);
132 #if defined(ANDROID)
133 DECL_GFX_PREF(Once, "gfx.apitrace.enabled", UseApitrace, bool, false);
134 #endif
135 DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated", CanvasAzureAccelerated, bool, false);
136 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache, bool, false);
137 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96);
138 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256);
140 DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false);
141 DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1);
142 // The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
143 DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0);
145 DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false);
146 DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false);
147 DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false);
148 DECL_GFX_PREF(Live, "gfx.layerscope.enabled", LayerScopeEnabled, bool, false);
149 DECL_GFX_PREF(Live, "gfx.layerscope.port", LayerScopePort, int32_t, 23456);
150 DECL_GFX_PREF(Once, "gfx.work-around-driver-bugs", WorkAroundDriverBugs, bool, true);
152 DECL_GFX_PREF(Live, "gl.msaa-level", MSAALevel, uint32_t, 2);
154 DECL_GFX_PREF(Once, "layers.acceleration.disabled", LayersAccelerationDisabled, bool, false);
155 DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, false);
156 DECL_GFX_PREF(Once, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled, bool, false);
157 #ifdef XP_WIN
158 // On windows, ignore the preference value, forcing async video to false.
159 DECL_GFX_PREF(Skip, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
160 #else
161 DECL_GFX_PREF(Once, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
162 #endif
163 DECL_GFX_PREF(Once, "layers.bufferrotation.enabled", BufferRotationEnabled, bool, true);
164 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
165 // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
166 // and ignore the preference.
167 DECL_GFX_PREF(Skip, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, false);
168 #else
169 // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
170 // preference value, defaulting to true.
171 DECL_GFX_PREF(Once, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, true);
172 #endif
173 DECL_GFX_PREF(Live, "layers.draw-bigimage-borders", DrawBigImageBorders, bool, false);
174 DECL_GFX_PREF(Live, "layers.draw-borders", DrawLayerBorders, bool, false);
175 DECL_GFX_PREF(Live, "layers.draw-tile-borders", DrawTileBorders, bool, false);
176 DECL_GFX_PREF(Live, "layers.flash-borders", FlashLayerBorders, bool, false);
177 DECL_GFX_PREF(Live, "layers.draw-layer-info", DrawLayerInfo, bool, false);
178 DECL_GFX_PREF(Once, "layers.dump", LayersDump, bool, false);
179 DECL_GFX_PREF(Once, "layers.enable-tiles", LayersTilesEnabled, bool, false);
180 DECL_GFX_PREF(Once, "layers.simple-tiles", LayersUseSimpleTiles, bool, false);
181 DECL_GFX_PREF(Once, "layers.force-per-tile-drawing", PerTileDrawing, bool, false);
182 // We allow for configurable and rectangular tile size to avoid wasting memory on devices whose
183 // screen size does not align nicely to the default tile size. Although layers can be any size,
184 // they are often the same size as the screen, especially for width.
185 DECL_GFX_PREF(Once, "layers.tile-width", LayersTileWidth, int32_t, 256);
186 DECL_GFX_PREF(Once, "layers.tile-height", LayersTileHeight, int32_t, 256);
187 DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking", OverzealousGrallocUnlocking, bool, false);
188 DECL_GFX_PREF(Once, "layers.force-shmem-tiles", ForceShmemTiles, bool, false);
189 DECL_GFX_PREF(Live, "layers.frame-counter", DrawFrameCounter, bool, false);
190 DECL_GFX_PREF(Live, "layers.low-precision-buffer", UseLowPrecisionBuffer, bool, false);
191 DECL_GFX_PREF(Live, "layers.low-precision-resolution", LowPrecisionResolution, int32_t, 250);
192 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled, bool, false);
193 DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
194 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled, bool, false);
195 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled, bool, false);
196 DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0);
197 DECL_GFX_PREF(Once, "layers.prefer-d3d9", LayersPreferD3D9, bool, false);
198 DECL_GFX_PREF(Once, "layers.prefer-opengl", LayersPreferOpenGL, bool, false);
199 DECL_GFX_PREF(Once, "layers.progressive-paint", UseProgressiveTilePainting, bool, false);
200 DECL_GFX_PREF(Once, "layers.scroll-graph", LayersScrollGraph, bool, false);
202 DECL_GFX_PREF(Once, "layout.css.touch_action.enabled", TouchActionEnabled, bool, false);
203 DECL_GFX_PREF(Once, "layout.frame_rate", LayoutFrameRate, int32_t, -1);
204 DECL_GFX_PREF(Once, "layout.paint_rects_separately", LayoutPaintRectsSeparately, bool, true);
206 DECL_GFX_PREF(Live, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing, bool, false);
208 DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay, int32_t, 500);
210 DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false);
212 public:
213 // Manage the singleton:
214 static gfxPrefs& GetSingleton()
215 {
216 if (!sInstance) {
217 sInstance = new gfxPrefs;
218 }
219 return *sInstance;
220 }
221 static void DestroySingleton();
222 static bool SingletonExists();
224 private:
225 static gfxPrefs* sInstance;
227 private:
228 // Creating these to avoid having to include Preferences.h in the .h
229 static void PrefAddVarCache(bool*, const char*, bool);
230 static void PrefAddVarCache(int32_t*, const char*, int32_t);
231 static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
232 static void PrefAddVarCache(float*, const char*, float);
233 static bool PrefGet(const char*, bool);
234 static int32_t PrefGet(const char*, int32_t);
235 static uint32_t PrefGet(const char*, uint32_t);
236 static float PrefGet(const char*, float);
238 gfxPrefs();
239 ~gfxPrefs();
240 gfxPrefs(const gfxPrefs&) MOZ_DELETE;
241 gfxPrefs& operator=(const gfxPrefs&) MOZ_DELETE;
242 };
244 #undef DECL_GFX_PREF /* Don't need it outside of this file */
246 #endif /* GFX_PREFS_H */