gfx/thebes/gfxPrefs.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxPrefs.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,246 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_PREFS_H
    1.10 +#define GFX_PREFS_H
    1.11 +
    1.12 +#include <stdint.h>
    1.13 +#include "mozilla/Assertions.h"
    1.14 +#include "mozilla/TypedEnum.h"
    1.15 +
    1.16 +// First time gfxPrefs::GetSingleton() needs to be called on the main thread,
    1.17 +// before any of the methods accessing the values are used, but after
    1.18 +// the Preferences system has been initialized.
    1.19 +
    1.20 +// The static methods to access the preference value are safe to call
    1.21 +// from any thread after that first call.
    1.22 +
    1.23 +// To register a preference, you need to add a line in this file using
    1.24 +// the DECL_GFX_PREF macro.
    1.25 +//
    1.26 +// Update argument controls whether we read the preference value and save it
    1.27 +// or connect with a callback.  See UpdatePolicy enum below.
    1.28 +// Pref is the string with the preference name.
    1.29 +// Name argument is the name of the static function to create.
    1.30 +// Type is the type of the preference - bool, int32_t, uint32_t.
    1.31 +// Default is the default value for the preference.
    1.32 +//
    1.33 +// For example this line in the .h:
    1.34 +//   DECL_GFX_PREF(Once,"layers.dump",LayersDump,bool,false);
    1.35 +// means that you can call
    1.36 +//   bool var = gfxPrefs::LayersDump();
    1.37 +// from any thread, but that you will only get the preference value of
    1.38 +// "layers.dump" as it was set at the start of the session. If the value
    1.39 +// was not set, the default would be false.
    1.40 +//
    1.41 +// In another example, this line in the .h:
    1.42 +//   DECL_GFX_PREF(Live,"gl.msaa-level",MSAALevel,uint32_t,2);
    1.43 +// means that every time you call
    1.44 +//   uint32_t var = gfxPrefs::MSAALevel();
    1.45 +// from any thread, you will get the most up to date preference value of
    1.46 +// "gl.msaa-level".  If the value is not set, the default would be 2.
    1.47 +
    1.48 +// Note that changing a preference from Live to Once is now as simple
    1.49 +// as changing the Update argument.  If your code worked before, it will
    1.50 +// keep working, and behave as if the user never changes the preference.
    1.51 +// Things are a bit more complicated and perhaps even dangerous when
    1.52 +// going from Once to Live, or indeed setting a preference to be Live
    1.53 +// in the first place, so be careful.  You need to be ready for the
    1.54 +// values changing mid execution, and if you're using those preferences
    1.55 +// in any setup and initialization, you may need to do extra work.
    1.56 +
    1.57 +#define DECL_GFX_PREF(Update, Pref, Name, Type, Default)                     \
    1.58 +public:                                                                       \
    1.59 +static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
    1.60 +private:                                                                      \
    1.61 +static const char* Get##Name##PrefName() { return Pref; }                     \
    1.62 +static Type Get##Name##PrefDefault() { return Default; }                      \
    1.63 +PrefTemplate<UpdatePolicy::Update, Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
    1.64 +
    1.65 +class gfxPrefs;
    1.66 +class gfxPrefs MOZ_FINAL
    1.67 +{
    1.68 +private:
    1.69 +  // Enums for the update policy.
    1.70 +  MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy)
    1.71 +    Skip, // Set the value to default, skip any Preferences calls
    1.72 +    Once, // Evaluate the preference once, unchanged during the session
    1.73 +    Live  // Evaluate the preference and set callback so it stays current/live
    1.74 +  MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy)
    1.75 +
    1.76 +  // Since we cannot use const char*, use a function that returns it.
    1.77 +  template <MOZ_ENUM_CLASS_ENUM_TYPE(UpdatePolicy) Update, class T, T Default(void), const char* Pref(void)>
    1.78 +  class PrefTemplate
    1.79 +  {
    1.80 +  public:
    1.81 +    PrefTemplate()
    1.82 +    : mValue(Default())
    1.83 +    {
    1.84 +      Register(Update, Pref());
    1.85 +    }
    1.86 +    void Register(UpdatePolicy aUpdate, const char* aPreference)
    1.87 +    {
    1.88 +      switch(aUpdate) {
    1.89 +        case UpdatePolicy::Skip:
    1.90 +          break;
    1.91 +        case UpdatePolicy::Once:
    1.92 +          mValue = PrefGet(aPreference, mValue);
    1.93 +          break;
    1.94 +        case UpdatePolicy::Live:
    1.95 +          PrefAddVarCache(&mValue,aPreference, mValue);
    1.96 +          break;
    1.97 +        default:
    1.98 +          MOZ_CRASH();
    1.99 +          break;
   1.100 +      }
   1.101 +    }
   1.102 +    T mValue;
   1.103 +  };
   1.104 +
   1.105 +  // This is where DECL_GFX_PREF for each of the preferences should go.
   1.106 +  // We will keep these in an alphabetical order to make it easier to see if
   1.107 +  // a method accessing a pref already exists. Just add yours in the list.
   1.108 +
   1.109 +  // The apz prefs are explained in AsyncPanZoomController.cpp
   1.110 +  DECL_GFX_PREF(Live, "apz.allow-checkerboarding",             APZAllowCheckerboarding, bool, true);
   1.111 +  DECL_GFX_PREF(Live, "apz.asyncscroll.throttle",              APZAsyncScrollThrottleTime, int32_t, 100);
   1.112 +  DECL_GFX_PREF(Live, "apz.asyncscroll.timeout",               APZAsyncScrollTimeout, int32_t, 300);
   1.113 +  DECL_GFX_PREF(Live, "apz.axis_lock_mode",                    APZAxisLockMode, int32_t, 0);
   1.114 +  DECL_GFX_PREF(Live, "apz.content_response_timeout",          APZContentResponseTimeout, int32_t, 300);
   1.115 +  DECL_GFX_PREF(Live, "apz.cross_slide.enabled",               APZCrossSlideEnabled, bool, false);
   1.116 +  DECL_GFX_PREF(Live, "apz.enlarge_displayport_when_clipped",  APZEnlargeDisplayPortWhenClipped, bool, false);
   1.117 +  DECL_GFX_PREF(Once, "apz.fling_friction",                    APZFlingFriction, float, 0.002f);
   1.118 +  DECL_GFX_PREF(Live, "apz.fling_repaint_interval",            APZFlingRepaintInterval, int32_t, 75);
   1.119 +  DECL_GFX_PREF(Once, "apz.fling_stopped_threshold",           APZFlingStoppedThreshold, float, 0.01f);
   1.120 +  DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms",        APZMaxVelocity, float, -1.0f);
   1.121 +  DECL_GFX_PREF(Once, "apz.max_velocity_queue_size",           APZMaxVelocityQueueSize, uint32_t, 5);
   1.122 +  DECL_GFX_PREF(Live, "apz.min_skate_speed",                   APZMinSkateSpeed, float, 1.0f);
   1.123 +  DECL_GFX_PREF(Live, "apz.num_paint_duration_samples",        APZNumPaintDurationSamples, int32_t, 3);
   1.124 +  DECL_GFX_PREF(Live, "apz.pan_repaint_interval",              APZPanRepaintInterval, int32_t, 250);
   1.125 +  DECL_GFX_PREF(Live, "apz.subframe.enabled",                  APZSubframeEnabled, bool, false);
   1.126 +  DECL_GFX_PREF(Live, "apz.touch_start_tolerance",             APZTouchStartTolerance, float, 1.0f/4.5f);
   1.127 +  DECL_GFX_PREF(Live, "apz.use_paint_duration",                APZUsePaintDuration, bool, true);
   1.128 +  DECL_GFX_PREF(Live, "apz.velocity_bias",                     APZVelocityBias, float, 1.0f);
   1.129 +  DECL_GFX_PREF(Live, "apz.x_skate_size_multiplier",           APZXSkateSizeMultiplier, float, 1.5f);
   1.130 +  DECL_GFX_PREF(Live, "apz.x_stationary_size_multiplier",      APZXStationarySizeMultiplier, float, 3.0f);
   1.131 +  DECL_GFX_PREF(Live, "apz.y_skate_size_multiplier",           APZYSkateSizeMultiplier, float, 2.5f);
   1.132 +  DECL_GFX_PREF(Live, "apz.y_stationary_size_multiplier",      APZYStationarySizeMultiplier, float, 3.5f);
   1.133 +
   1.134 +  DECL_GFX_PREF(Once, "gfx.android.rgb16.force",               AndroidRGB16Force, bool, false);
   1.135 +#if defined(ANDROID)
   1.136 +  DECL_GFX_PREF(Once, "gfx.apitrace.enabled",                  UseApitrace, bool, false);
   1.137 +#endif
   1.138 +  DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated",          CanvasAzureAccelerated, bool, false);
   1.139 +  DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache",       CanvasSkiaGLDynamicCache, bool, false);
   1.140 +  DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size",          CanvasSkiaGLCacheSize, int32_t, 96);
   1.141 +  DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items",         CanvasSkiaGLCacheItems, int32_t, 256);
   1.142 +
   1.143 +  DECL_GFX_PREF(Live, "gfx.color_management.enablev4",         CMSEnableV4, bool, false);
   1.144 +  DECL_GFX_PREF(Live, "gfx.color_management.mode",             CMSMode, int32_t,-1);
   1.145 +  // The zero default here should match QCMS_INTENT_DEFAULT from qcms.h
   1.146 +  DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0);
   1.147 +
   1.148 +  DECL_GFX_PREF(Once, "gfx.direct2d.disabled",                 Direct2DDisabled, bool, false);
   1.149 +  DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled",            Direct2DForceEnabled, bool, false);
   1.150 +  DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels",     GrallocFenceWithReadPixels, bool, false);
   1.151 +  DECL_GFX_PREF(Live, "gfx.layerscope.enabled",                LayerScopeEnabled, bool, false);
   1.152 +  DECL_GFX_PREF(Live, "gfx.layerscope.port",                   LayerScopePort, int32_t, 23456);
   1.153 +  DECL_GFX_PREF(Once, "gfx.work-around-driver-bugs",           WorkAroundDriverBugs, bool, true);
   1.154 +
   1.155 +  DECL_GFX_PREF(Live, "gl.msaa-level",                         MSAALevel, uint32_t, 2);
   1.156 +
   1.157 +  DECL_GFX_PREF(Once, "layers.acceleration.disabled",          LayersAccelerationDisabled, bool, false);
   1.158 +  DECL_GFX_PREF(Live, "layers.acceleration.draw-fps",          LayersDrawFPS, bool, false);
   1.159 +  DECL_GFX_PREF(Once, "layers.acceleration.force-enabled",     LayersAccelerationForceEnabled, bool, false);
   1.160 +#ifdef XP_WIN
   1.161 +  // On windows, ignore the preference value, forcing async video to false.
   1.162 +  DECL_GFX_PREF(Skip, "layers.async-video.enabled",            AsyncVideoEnabled, bool, false);
   1.163 +#else
   1.164 +  DECL_GFX_PREF(Once, "layers.async-video.enabled",            AsyncVideoEnabled, bool, false);
   1.165 +#endif
   1.166 +  DECL_GFX_PREF(Once, "layers.bufferrotation.enabled",         BufferRotationEnabled, bool, true);
   1.167 +#ifdef MOZ_GFX_OPTIMIZE_MOBILE
   1.168 +  // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
   1.169 +  // and ignore the preference.
   1.170 +  DECL_GFX_PREF(Skip, "layers.componentalpha.enabled",         ComponentAlphaEnabled, bool, false);
   1.171 +#else
   1.172 +  // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the
   1.173 +  // preference value, defaulting to true.
   1.174 +  DECL_GFX_PREF(Once, "layers.componentalpha.enabled",         ComponentAlphaEnabled, bool, true);
   1.175 +#endif
   1.176 +  DECL_GFX_PREF(Live, "layers.draw-bigimage-borders",          DrawBigImageBorders, bool, false);
   1.177 +  DECL_GFX_PREF(Live, "layers.draw-borders",                   DrawLayerBorders, bool, false);
   1.178 +  DECL_GFX_PREF(Live, "layers.draw-tile-borders",              DrawTileBorders, bool, false);
   1.179 +  DECL_GFX_PREF(Live, "layers.flash-borders",                  FlashLayerBorders, bool, false);
   1.180 +  DECL_GFX_PREF(Live, "layers.draw-layer-info",                DrawLayerInfo, bool, false);
   1.181 +  DECL_GFX_PREF(Once, "layers.dump",                           LayersDump, bool, false);
   1.182 +  DECL_GFX_PREF(Once, "layers.enable-tiles",                   LayersTilesEnabled, bool, false);
   1.183 +  DECL_GFX_PREF(Once, "layers.simple-tiles",                   LayersUseSimpleTiles, bool, false);
   1.184 +  DECL_GFX_PREF(Once, "layers.force-per-tile-drawing",         PerTileDrawing, bool, false);
   1.185 +  // We allow for configurable and rectangular tile size to avoid wasting memory on devices whose
   1.186 +  // screen size does not align nicely to the default tile size. Although layers can be any size,
   1.187 +  // they are often the same size as the screen, especially for width.
   1.188 +  DECL_GFX_PREF(Once, "layers.tile-width",                     LayersTileWidth, int32_t, 256);
   1.189 +  DECL_GFX_PREF(Once, "layers.tile-height",                    LayersTileHeight, int32_t, 256);
   1.190 +  DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking",  OverzealousGrallocUnlocking, bool, false);
   1.191 +  DECL_GFX_PREF(Once, "layers.force-shmem-tiles",              ForceShmemTiles, bool, false);
   1.192 +  DECL_GFX_PREF(Live, "layers.frame-counter",                  DrawFrameCounter, bool, false);
   1.193 +  DECL_GFX_PREF(Live, "layers.low-precision-buffer",           UseLowPrecisionBuffer, bool, false);
   1.194 +  DECL_GFX_PREF(Live, "layers.low-precision-resolution",       LowPrecisionResolution, int32_t, 250);
   1.195 +  DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled, bool, false);
   1.196 +  DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
   1.197 +  DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled, bool, false);
   1.198 +  DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled, bool, false);
   1.199 +  DECL_GFX_PREF(Live, "layers.orientation.sync.timeout",       OrientationSyncMillis, uint32_t, (uint32_t)0);
   1.200 +  DECL_GFX_PREF(Once, "layers.prefer-d3d9",                    LayersPreferD3D9, bool, false);
   1.201 +  DECL_GFX_PREF(Once, "layers.prefer-opengl",                  LayersPreferOpenGL, bool, false);
   1.202 +  DECL_GFX_PREF(Once, "layers.progressive-paint",              UseProgressiveTilePainting, bool, false);
   1.203 +  DECL_GFX_PREF(Once, "layers.scroll-graph",                   LayersScrollGraph, bool, false);
   1.204 +
   1.205 +  DECL_GFX_PREF(Once, "layout.css.touch_action.enabled",       TouchActionEnabled, bool, false);
   1.206 +  DECL_GFX_PREF(Once, "layout.frame_rate",                     LayoutFrameRate, int32_t, -1);
   1.207 +  DECL_GFX_PREF(Once, "layout.paint_rects_separately",         LayoutPaintRectsSeparately, bool, true);
   1.208 +
   1.209 +  DECL_GFX_PREF(Live, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing, bool, false);
   1.210 +
   1.211 +  DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay",     UiClickHoldContextMenusDelay, int32_t, 500);
   1.212 +
   1.213 +  DECL_GFX_PREF(Once, "webgl.force-layers-readback",           WebGLForceLayersReadback, bool, false);
   1.214 +
   1.215 +public:
   1.216 +  // Manage the singleton:
   1.217 +  static gfxPrefs& GetSingleton()
   1.218 +  {
   1.219 +    if (!sInstance) {
   1.220 +      sInstance = new gfxPrefs;
   1.221 +    }
   1.222 +    return *sInstance;
   1.223 +  }
   1.224 +  static void DestroySingleton();
   1.225 +  static bool SingletonExists();
   1.226 +
   1.227 +private:
   1.228 +  static gfxPrefs* sInstance;
   1.229 +
   1.230 +private:
   1.231 +  // Creating these to avoid having to include Preferences.h in the .h
   1.232 +  static void PrefAddVarCache(bool*, const char*, bool);
   1.233 +  static void PrefAddVarCache(int32_t*, const char*, int32_t);
   1.234 +  static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
   1.235 +  static void PrefAddVarCache(float*, const char*, float);
   1.236 +  static bool PrefGet(const char*, bool);
   1.237 +  static int32_t PrefGet(const char*, int32_t);
   1.238 +  static uint32_t PrefGet(const char*, uint32_t);
   1.239 +  static float PrefGet(const char*, float);
   1.240 +
   1.241 +  gfxPrefs();
   1.242 +  ~gfxPrefs();
   1.243 +  gfxPrefs(const gfxPrefs&) MOZ_DELETE;
   1.244 +  gfxPrefs& operator=(const gfxPrefs&) MOZ_DELETE;
   1.245 +};
   1.246 +
   1.247 +#undef DECL_GFX_PREF /* Don't need it outside of this file */
   1.248 +
   1.249 +#endif /* GFX_PREFS_H */

mercurial