gfx/thebes/gfxPrefs.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef GFX_PREFS_H
michael@0 7 #define GFX_PREFS_H
michael@0 8
michael@0 9 #include <stdint.h>
michael@0 10 #include "mozilla/Assertions.h"
michael@0 11 #include "mozilla/TypedEnum.h"
michael@0 12
michael@0 13 // First time gfxPrefs::GetSingleton() needs to be called on the main thread,
michael@0 14 // before any of the methods accessing the values are used, but after
michael@0 15 // the Preferences system has been initialized.
michael@0 16
michael@0 17 // The static methods to access the preference value are safe to call
michael@0 18 // from any thread after that first call.
michael@0 19
michael@0 20 // To register a preference, you need to add a line in this file using
michael@0 21 // the DECL_GFX_PREF macro.
michael@0 22 //
michael@0 23 // Update argument controls whether we read the preference value and save it
michael@0 24 // or connect with a callback. See UpdatePolicy enum below.
michael@0 25 // Pref is the string with the preference name.
michael@0 26 // Name argument is the name of the static function to create.
michael@0 27 // Type is the type of the preference - bool, int32_t, uint32_t.
michael@0 28 // Default is the default value for the preference.
michael@0 29 //
michael@0 30 // For example this line in the .h:
michael@0 31 // DECL_GFX_PREF(Once,"layers.dump",LayersDump,bool,false);
michael@0 32 // means that you can call
michael@0 33 // bool var = gfxPrefs::LayersDump();
michael@0 34 // from any thread, but that you will only get the preference value of
michael@0 35 // "layers.dump" as it was set at the start of the session. If the value
michael@0 36 // was not set, the default would be false.
michael@0 37 //
michael@0 38 // In another example, this line in the .h:
michael@0 39 // DECL_GFX_PREF(Live,"gl.msaa-level",MSAALevel,uint32_t,2);
michael@0 40 // means that every time you call
michael@0 41 // uint32_t var = gfxPrefs::MSAALevel();
michael@0 42 // from any thread, you will get the most up to date preference value of
michael@0 43 // "gl.msaa-level". If the value is not set, the default would be 2.
michael@0 44
michael@0 45 // Note that changing a preference from Live to Once is now as simple
michael@0 46 // as changing the Update argument. If your code worked before, it will
michael@0 47 // keep working, and behave as if the user never changes the preference.
michael@0 48 // Things are a bit more complicated and perhaps even dangerous when
michael@0 49 // going from Once to Live, or indeed setting a preference to be Live
michael@0 50 // in the first place, so be careful. You need to be ready for the
michael@0 51 // values changing mid execution, and if you're using those preferences
michael@0 52 // in any setup and initialization, you may need to do extra work.
michael@0 53
michael@0 54 #define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \
michael@0 55 public: \
michael@0 56 static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
michael@0 57 private: \
michael@0 58 static const char* Get##Name##PrefName() { return Pref; } \
michael@0 59 static Type Get##Name##PrefDefault() { return Default; } \
michael@0 60 PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
michael@0 61
michael@0 62 class gfxPrefs;
michael@0 63 class gfxPrefs MOZ_FINAL
michael@0 64 {
michael@0 65 private:
michael@0 66 // Enums for the update policy.
michael@0 67 MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
michael@0 68 Skip, // Set the value to default, skip any Preferences calls
michael@0 69 Once, // Evaluate the preference once, unchanged during the session
michael@0 70 Live // Evaluate the preference and set callback so it stays current/live
michael@0 71 MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy)
michael@0 72
michael@0 73 // Since we cannot use const char*, use a function that returns it.
michael@0 74 template <MOZ_ENUM_CLASS_ENUM_TYPE(UpdatePolicy) Update, class T, T Default(void), const char* Pref(void)>
michael@0 75 class PrefTemplate
michael@0 76 {
michael@0 77 public:
michael@0 78 PrefTemplate()
michael@0 79 : mValue(Default())
michael@0 80 {
michael@0 81 Register(Update, Pref());
michael@0 82 }
michael@0 83 void Register(UpdatePolicy aUpdate, const char* aPreference)
michael@0 84 {
michael@0 85 switch(aUpdate) {
michael@0 86 case UpdatePolicy::Skip:
michael@0 87 break;
michael@0 88 case UpdatePolicy::Once:
michael@0 89 mValue = PrefGet(aPreference, mValue);
michael@0 90 break;
michael@0 91 case UpdatePolicy::Live:
michael@0 92 PrefAddVarCache(&mValue,aPreference, mValue);
michael@0 93 break;
michael@0 94 default:
michael@0 95 MOZ_CRASH();
michael@0 96 break;
michael@0 97 }
michael@0 98 }
michael@0 99 T mValue;
michael@0 100 };
michael@0 101
michael@0 102 // This is where DECL_GFX_PREF for each of the preferences should go.
michael@0 103 // We will keep these in an alphabetical order to make it easier to see if
michael@0 104 // a method accessing a pref already exists. Just add yours in the list.
michael@0 105
michael@0 106 // The apz prefs are explained in AsyncPanZoomController.cpp
michael@0 107 DECL_GFX_PREF(Live, "apz.allow-checkerboarding", APZAllowCheckerboarding, bool, true);
michael@0 108 DECL_GFX_PREF(Live, "apz.asyncscroll.throttle", APZAsyncScrollThrottleTime, int32_t, 100);
michael@0 109 DECL_GFX_PREF(Live, "apz.asyncscroll.timeout", APZAsyncScrollTimeout, int32_t, 300);
michael@0 110 DECL_GFX_PREF(Live, "apz.axis_lock_mode", APZAxisLockMode, int32_t, 0);
michael@0 111 DECL_GFX_PREF(Live, "apz.content_response_timeout", APZContentResponseTimeout, int32_t, 300);
michael@0 112 DECL_GFX_PREF(Live, "apz.cross_slide.enabled", APZCrossSlideEnabled, bool, false);
michael@0 113 DECL_GFX_PREF(Live, "apz.enlarge_displayport_when_clipped", APZEnlargeDisplayPortWhenClipped, bool, false);
michael@0 114 DECL_GFX_PREF(Once, "apz.fling_friction", APZFlingFriction, float, 0.002f);
michael@0 115 DECL_GFX_PREF(Live, "apz.fling_repaint_interval", APZFlingRepaintInterval, int32_t, 75);
michael@0 116 DECL_GFX_PREF(Once, "apz.fling_stopped_threshold", APZFlingStoppedThreshold, float, 0.01f);
michael@0 117 DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms", APZMaxVelocity, float, -1.0f);
michael@0 118 DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
michael@0 119 DECL_GFX_PREF(Live, "apz.min_skate_speed", APZMinSkateSpeed, float, 1.0f);
michael@0 120 DECL_GFX_PREF(Live, "apz.num_paint_duration_samples", APZNumPaintDurationSamples, int32_t, 3);
michael@0 121 DECL_GFX_PREF(Live, "apz.pan_repaint_interval", APZPanRepaintInterval, int32_t, 250);
michael@0 122 DECL_GFX_PREF(Live, "apz.subframe.enabled", APZSubframeEnabled, bool, false);
michael@0 123 DECL_GFX_PREF(Live, "apz.touch_start_tolerance", APZTouchStartTolerance, float, 1.0f/4.5f);
michael@0 124 DECL_GFX_PREF(Live, "apz.use_paint_duration", APZUsePaintDuration, bool, true);
michael@0 125 DECL_GFX_PREF(Live, "apz.velocity_bias", APZVelocityBias, float, 1.0f);
michael@0 126 DECL_GFX_PREF(Live, "apz.x_skate_size_multiplier", APZXSkateSizeMultiplier, float, 1.5f);
michael@0 127 DECL_GFX_PREF(Live, "apz.x_stationary_size_multiplier", APZXStationarySizeMultiplier, float, 3.0f);
michael@0 128 DECL_GFX_PREF(Live, "apz.y_skate_size_multiplier", APZYSkateSizeMultiplier, float, 2.5f);
michael@0 129 DECL_GFX_PREF(Live, "apz.y_stationary_size_multiplier", APZYStationarySizeMultiplier, float, 3.5f);
michael@0 130
michael@0 131 DECL_GFX_PREF(Once, "gfx.android.rgb16.force", AndroidRGB16Force, bool, false);
michael@0 132 #if defined(ANDROID)
michael@0 133 DECL_GFX_PREF(Once, "gfx.apitrace.enabled", UseApitrace, bool, false);
michael@0 134 #endif
michael@0 135 DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated", CanvasAzureAccelerated, bool, false);
michael@0 136 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache, bool, false);
michael@0 137 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96);
michael@0 138 DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256);
michael@0 139
michael@0 140 DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false);
michael@0 141 DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1);
michael@0 142 // The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
michael@0 143 DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0);
michael@0 144
michael@0 145 DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false);
michael@0 146 DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false);
michael@0 147 DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false);
michael@0 148 DECL_GFX_PREF(Live, "gfx.layerscope.enabled", LayerScopeEnabled, bool, false);
michael@0 149 DECL_GFX_PREF(Live, "gfx.layerscope.port", LayerScopePort, int32_t, 23456);
michael@0 150 DECL_GFX_PREF(Once, "gfx.work-around-driver-bugs", WorkAroundDriverBugs, bool, true);
michael@0 151
michael@0 152 DECL_GFX_PREF(Live, "gl.msaa-level", MSAALevel, uint32_t, 2);
michael@0 153
michael@0 154 DECL_GFX_PREF(Once, "layers.acceleration.disabled", LayersAccelerationDisabled, bool, false);
michael@0 155 DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, false);
michael@0 156 DECL_GFX_PREF(Once, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled, bool, false);
michael@0 157 #ifdef XP_WIN
michael@0 158 // On windows, ignore the preference value, forcing async video to false.
michael@0 159 DECL_GFX_PREF(Skip, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
michael@0 160 #else
michael@0 161 DECL_GFX_PREF(Once, "layers.async-video.enabled", AsyncVideoEnabled, bool, false);
michael@0 162 #endif
michael@0 163 DECL_GFX_PREF(Once, "layers.bufferrotation.enabled", BufferRotationEnabled, bool, true);
michael@0 164 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
michael@0 165 // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
michael@0 166 // and ignore the preference.
michael@0 167 DECL_GFX_PREF(Skip, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, false);
michael@0 168 #else
michael@0 169 // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
michael@0 170 // preference value, defaulting to true.
michael@0 171 DECL_GFX_PREF(Once, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, true);
michael@0 172 #endif
michael@0 173 DECL_GFX_PREF(Live, "layers.draw-bigimage-borders", DrawBigImageBorders, bool, false);
michael@0 174 DECL_GFX_PREF(Live, "layers.draw-borders", DrawLayerBorders, bool, false);
michael@0 175 DECL_GFX_PREF(Live, "layers.draw-tile-borders", DrawTileBorders, bool, false);
michael@0 176 DECL_GFX_PREF(Live, "layers.flash-borders", FlashLayerBorders, bool, false);
michael@0 177 DECL_GFX_PREF(Live, "layers.draw-layer-info", DrawLayerInfo, bool, false);
michael@0 178 DECL_GFX_PREF(Once, "layers.dump", LayersDump, bool, false);
michael@0 179 DECL_GFX_PREF(Once, "layers.enable-tiles", LayersTilesEnabled, bool, false);
michael@0 180 DECL_GFX_PREF(Once, "layers.simple-tiles", LayersUseSimpleTiles, bool, false);
michael@0 181 DECL_GFX_PREF(Once, "layers.force-per-tile-drawing", PerTileDrawing, bool, false);
michael@0 182 // We allow for configurable and rectangular tile size to avoid wasting memory on devices whose
michael@0 183 // screen size does not align nicely to the default tile size. Although layers can be any size,
michael@0 184 // they are often the same size as the screen, especially for width.
michael@0 185 DECL_GFX_PREF(Once, "layers.tile-width", LayersTileWidth, int32_t, 256);
michael@0 186 DECL_GFX_PREF(Once, "layers.tile-height", LayersTileHeight, int32_t, 256);
michael@0 187 DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking", OverzealousGrallocUnlocking, bool, false);
michael@0 188 DECL_GFX_PREF(Once, "layers.force-shmem-tiles", ForceShmemTiles, bool, false);
michael@0 189 DECL_GFX_PREF(Live, "layers.frame-counter", DrawFrameCounter, bool, false);
michael@0 190 DECL_GFX_PREF(Live, "layers.low-precision-buffer", UseLowPrecisionBuffer, bool, false);
michael@0 191 DECL_GFX_PREF(Live, "layers.low-precision-resolution", LowPrecisionResolution, int32_t, 250);
michael@0 192 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled, bool, false);
michael@0 193 DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
michael@0 194 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled, bool, false);
michael@0 195 DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled, bool, false);
michael@0 196 DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0);
michael@0 197 DECL_GFX_PREF(Once, "layers.prefer-d3d9", LayersPreferD3D9, bool, false);
michael@0 198 DECL_GFX_PREF(Once, "layers.prefer-opengl", LayersPreferOpenGL, bool, false);
michael@0 199 DECL_GFX_PREF(Once, "layers.progressive-paint", UseProgressiveTilePainting, bool, false);
michael@0 200 DECL_GFX_PREF(Once, "layers.scroll-graph", LayersScrollGraph, bool, false);
michael@0 201
michael@0 202 DECL_GFX_PREF(Once, "layout.css.touch_action.enabled", TouchActionEnabled, bool, false);
michael@0 203 DECL_GFX_PREF(Once, "layout.frame_rate", LayoutFrameRate, int32_t, -1);
michael@0 204 DECL_GFX_PREF(Once, "layout.paint_rects_separately", LayoutPaintRectsSeparately, bool, true);
michael@0 205
michael@0 206 DECL_GFX_PREF(Live, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing, bool, false);
michael@0 207
michael@0 208 DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay, int32_t, 500);
michael@0 209
michael@0 210 DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false);
michael@0 211
michael@0 212 public:
michael@0 213 // Manage the singleton:
michael@0 214 static gfxPrefs& GetSingleton()
michael@0 215 {
michael@0 216 if (!sInstance) {
michael@0 217 sInstance = new gfxPrefs;
michael@0 218 }
michael@0 219 return *sInstance;
michael@0 220 }
michael@0 221 static void DestroySingleton();
michael@0 222 static bool SingletonExists();
michael@0 223
michael@0 224 private:
michael@0 225 static gfxPrefs* sInstance;
michael@0 226
michael@0 227 private:
michael@0 228 // Creating these to avoid having to include Preferences.h in the .h
michael@0 229 static void PrefAddVarCache(bool*, const char*, bool);
michael@0 230 static void PrefAddVarCache(int32_t*, const char*, int32_t);
michael@0 231 static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
michael@0 232 static void PrefAddVarCache(float*, const char*, float);
michael@0 233 static bool PrefGet(const char*, bool);
michael@0 234 static int32_t PrefGet(const char*, int32_t);
michael@0 235 static uint32_t PrefGet(const char*, uint32_t);
michael@0 236 static float PrefGet(const char*, float);
michael@0 237
michael@0 238 gfxPrefs();
michael@0 239 ~gfxPrefs();
michael@0 240 gfxPrefs(const gfxPrefs&) MOZ_DELETE;
michael@0 241 gfxPrefs& operator=(const gfxPrefs&) MOZ_DELETE;
michael@0 242 };
michael@0 243
michael@0 244 #undef DECL_GFX_PREF /* Don't need it outside of this file */
michael@0 245
michael@0 246 #endif /* GFX_PREFS_H */

mercurial