michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_PREFS_H michael@0: #define GFX_PREFS_H michael@0: michael@0: #include michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/TypedEnum.h" michael@0: michael@0: // First time gfxPrefs::GetSingleton() needs to be called on the main thread, michael@0: // before any of the methods accessing the values are used, but after michael@0: // the Preferences system has been initialized. michael@0: michael@0: // The static methods to access the preference value are safe to call michael@0: // from any thread after that first call. michael@0: michael@0: // To register a preference, you need to add a line in this file using michael@0: // the DECL_GFX_PREF macro. michael@0: // michael@0: // Update argument controls whether we read the preference value and save it michael@0: // or connect with a callback. See UpdatePolicy enum below. michael@0: // Pref is the string with the preference name. michael@0: // Name argument is the name of the static function to create. michael@0: // Type is the type of the preference - bool, int32_t, uint32_t. michael@0: // Default is the default value for the preference. michael@0: // michael@0: // For example this line in the .h: michael@0: // DECL_GFX_PREF(Once,"layers.dump",LayersDump,bool,false); michael@0: // means that you can call michael@0: // bool var = gfxPrefs::LayersDump(); michael@0: // from any thread, but that you will only get the preference value of michael@0: // "layers.dump" as it was set at the start of the session. If the value michael@0: // was not set, the default would be false. michael@0: // michael@0: // In another example, this line in the .h: michael@0: // DECL_GFX_PREF(Live,"gl.msaa-level",MSAALevel,uint32_t,2); michael@0: // means that every time you call michael@0: // uint32_t var = gfxPrefs::MSAALevel(); michael@0: // from any thread, you will get the most up to date preference value of michael@0: // "gl.msaa-level". If the value is not set, the default would be 2. michael@0: michael@0: // Note that changing a preference from Live to Once is now as simple michael@0: // as changing the Update argument. If your code worked before, it will michael@0: // keep working, and behave as if the user never changes the preference. michael@0: // Things are a bit more complicated and perhaps even dangerous when michael@0: // going from Once to Live, or indeed setting a preference to be Live michael@0: // in the first place, so be careful. You need to be ready for the michael@0: // values changing mid execution, and if you're using those preferences michael@0: // in any setup and initialization, you may need to do extra work. michael@0: michael@0: #define DECL_GFX_PREF(Update, Pref, Name, Type, Default) \ michael@0: public: \ michael@0: static Type Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \ michael@0: private: \ michael@0: static const char* Get##Name##PrefName() { return Pref; } \ michael@0: static Type Get##Name##PrefDefault() { return Default; } \ michael@0: PrefTemplate mPref##Name michael@0: michael@0: class gfxPrefs; michael@0: class gfxPrefs MOZ_FINAL michael@0: { michael@0: private: michael@0: // Enums for the update policy. michael@0: MOZ_BEGIN_NESTED_ENUM_CLASS(UpdatePolicy) michael@0: Skip, // Set the value to default, skip any Preferences calls michael@0: Once, // Evaluate the preference once, unchanged during the session michael@0: Live // Evaluate the preference and set callback so it stays current/live michael@0: MOZ_END_NESTED_ENUM_CLASS(UpdatePolicy) michael@0: michael@0: // Since we cannot use const char*, use a function that returns it. michael@0: template michael@0: class PrefTemplate michael@0: { michael@0: public: michael@0: PrefTemplate() michael@0: : mValue(Default()) michael@0: { michael@0: Register(Update, Pref()); michael@0: } michael@0: void Register(UpdatePolicy aUpdate, const char* aPreference) michael@0: { michael@0: switch(aUpdate) { michael@0: case UpdatePolicy::Skip: michael@0: break; michael@0: case UpdatePolicy::Once: michael@0: mValue = PrefGet(aPreference, mValue); michael@0: break; michael@0: case UpdatePolicy::Live: michael@0: PrefAddVarCache(&mValue,aPreference, mValue); michael@0: break; michael@0: default: michael@0: MOZ_CRASH(); michael@0: break; michael@0: } michael@0: } michael@0: T mValue; michael@0: }; michael@0: michael@0: // This is where DECL_GFX_PREF for each of the preferences should go. michael@0: // We will keep these in an alphabetical order to make it easier to see if michael@0: // a method accessing a pref already exists. Just add yours in the list. michael@0: michael@0: // The apz prefs are explained in AsyncPanZoomController.cpp michael@0: DECL_GFX_PREF(Live, "apz.allow-checkerboarding", APZAllowCheckerboarding, bool, true); michael@0: DECL_GFX_PREF(Live, "apz.asyncscroll.throttle", APZAsyncScrollThrottleTime, int32_t, 100); michael@0: DECL_GFX_PREF(Live, "apz.asyncscroll.timeout", APZAsyncScrollTimeout, int32_t, 300); michael@0: DECL_GFX_PREF(Live, "apz.axis_lock_mode", APZAxisLockMode, int32_t, 0); michael@0: DECL_GFX_PREF(Live, "apz.content_response_timeout", APZContentResponseTimeout, int32_t, 300); michael@0: DECL_GFX_PREF(Live, "apz.cross_slide.enabled", APZCrossSlideEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "apz.enlarge_displayport_when_clipped", APZEnlargeDisplayPortWhenClipped, bool, false); michael@0: DECL_GFX_PREF(Once, "apz.fling_friction", APZFlingFriction, float, 0.002f); michael@0: DECL_GFX_PREF(Live, "apz.fling_repaint_interval", APZFlingRepaintInterval, int32_t, 75); michael@0: DECL_GFX_PREF(Once, "apz.fling_stopped_threshold", APZFlingStoppedThreshold, float, 0.01f); michael@0: DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms", APZMaxVelocity, float, -1.0f); michael@0: DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5); michael@0: DECL_GFX_PREF(Live, "apz.min_skate_speed", APZMinSkateSpeed, float, 1.0f); michael@0: DECL_GFX_PREF(Live, "apz.num_paint_duration_samples", APZNumPaintDurationSamples, int32_t, 3); michael@0: DECL_GFX_PREF(Live, "apz.pan_repaint_interval", APZPanRepaintInterval, int32_t, 250); michael@0: DECL_GFX_PREF(Live, "apz.subframe.enabled", APZSubframeEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "apz.touch_start_tolerance", APZTouchStartTolerance, float, 1.0f/4.5f); michael@0: DECL_GFX_PREF(Live, "apz.use_paint_duration", APZUsePaintDuration, bool, true); michael@0: DECL_GFX_PREF(Live, "apz.velocity_bias", APZVelocityBias, float, 1.0f); michael@0: DECL_GFX_PREF(Live, "apz.x_skate_size_multiplier", APZXSkateSizeMultiplier, float, 1.5f); michael@0: DECL_GFX_PREF(Live, "apz.x_stationary_size_multiplier", APZXStationarySizeMultiplier, float, 3.0f); michael@0: DECL_GFX_PREF(Live, "apz.y_skate_size_multiplier", APZYSkateSizeMultiplier, float, 2.5f); michael@0: DECL_GFX_PREF(Live, "apz.y_stationary_size_multiplier", APZYStationarySizeMultiplier, float, 3.5f); michael@0: michael@0: DECL_GFX_PREF(Once, "gfx.android.rgb16.force", AndroidRGB16Force, bool, false); michael@0: #if defined(ANDROID) michael@0: DECL_GFX_PREF(Once, "gfx.apitrace.enabled", UseApitrace, bool, false); michael@0: #endif michael@0: DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated", CanvasAzureAccelerated, bool, false); michael@0: DECL_GFX_PREF(Once, "gfx.canvas.skiagl.dynamic-cache", CanvasSkiaGLDynamicCache, bool, false); michael@0: DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-size", CanvasSkiaGLCacheSize, int32_t, 96); michael@0: DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items", CanvasSkiaGLCacheItems, int32_t, 256); michael@0: michael@0: DECL_GFX_PREF(Live, "gfx.color_management.enablev4", CMSEnableV4, bool, false); michael@0: DECL_GFX_PREF(Live, "gfx.color_management.mode", CMSMode, int32_t,-1); michael@0: // The zero default here should match QCMS_INTENT_DEFAULT from qcms.h michael@0: DECL_GFX_PREF(Live, "gfx.color_management.rendering_intent", CMSRenderingIntent, int32_t, 0); michael@0: michael@0: DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false); michael@0: DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false); michael@0: DECL_GFX_PREF(Live, "gfx.layerscope.enabled", LayerScopeEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "gfx.layerscope.port", LayerScopePort, int32_t, 23456); michael@0: DECL_GFX_PREF(Once, "gfx.work-around-driver-bugs", WorkAroundDriverBugs, bool, true); michael@0: michael@0: DECL_GFX_PREF(Live, "gl.msaa-level", MSAALevel, uint32_t, 2); michael@0: michael@0: DECL_GFX_PREF(Once, "layers.acceleration.disabled", LayersAccelerationDisabled, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.acceleration.draw-fps", LayersDrawFPS, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.acceleration.force-enabled", LayersAccelerationForceEnabled, bool, false); michael@0: #ifdef XP_WIN michael@0: // On windows, ignore the preference value, forcing async video to false. michael@0: DECL_GFX_PREF(Skip, "layers.async-video.enabled", AsyncVideoEnabled, bool, false); michael@0: #else michael@0: DECL_GFX_PREF(Once, "layers.async-video.enabled", AsyncVideoEnabled, bool, false); michael@0: #endif michael@0: DECL_GFX_PREF(Once, "layers.bufferrotation.enabled", BufferRotationEnabled, bool, true); michael@0: #ifdef MOZ_GFX_OPTIMIZE_MOBILE michael@0: // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off michael@0: // and ignore the preference. michael@0: DECL_GFX_PREF(Skip, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, false); michael@0: #else michael@0: // If MOZ_GFX_OPTIMIZE_MOBILE is not defined, we actually take the michael@0: // preference value, defaulting to true. michael@0: DECL_GFX_PREF(Once, "layers.componentalpha.enabled", ComponentAlphaEnabled, bool, true); michael@0: #endif michael@0: DECL_GFX_PREF(Live, "layers.draw-bigimage-borders", DrawBigImageBorders, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.draw-borders", DrawLayerBorders, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.draw-tile-borders", DrawTileBorders, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.flash-borders", FlashLayerBorders, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.draw-layer-info", DrawLayerInfo, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.dump", LayersDump, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.enable-tiles", LayersTilesEnabled, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.simple-tiles", LayersUseSimpleTiles, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.force-per-tile-drawing", PerTileDrawing, bool, false); michael@0: // We allow for configurable and rectangular tile size to avoid wasting memory on devices whose michael@0: // screen size does not align nicely to the default tile size. Although layers can be any size, michael@0: // they are often the same size as the screen, especially for width. michael@0: DECL_GFX_PREF(Once, "layers.tile-width", LayersTileWidth, int32_t, 256); michael@0: DECL_GFX_PREF(Once, "layers.tile-height", LayersTileHeight, int32_t, 256); michael@0: DECL_GFX_PREF(Once, "layers.overzealous-gralloc-unlocking", OverzealousGrallocUnlocking, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.force-shmem-tiles", ForceShmemTiles, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.frame-counter", DrawFrameCounter, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.low-precision-buffer", UseLowPrecisionBuffer, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.low-precision-resolution", LowPrecisionResolution, int32_t, 250); michael@0: DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.enabled", LayersOffMainThreadCompositionEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1); michael@0: DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-enabled", LayersOffMainThreadCompositionForceEnabled, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.testing.enabled", LayersOffMainThreadCompositionTestingEnabled, bool, false); michael@0: DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0); michael@0: DECL_GFX_PREF(Once, "layers.prefer-d3d9", LayersPreferD3D9, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.prefer-opengl", LayersPreferOpenGL, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.progressive-paint", UseProgressiveTilePainting, bool, false); michael@0: DECL_GFX_PREF(Once, "layers.scroll-graph", LayersScrollGraph, bool, false); michael@0: michael@0: DECL_GFX_PREF(Once, "layout.css.touch_action.enabled", TouchActionEnabled, bool, false); michael@0: DECL_GFX_PREF(Once, "layout.frame_rate", LayoutFrameRate, int32_t, -1); michael@0: DECL_GFX_PREF(Once, "layout.paint_rects_separately", LayoutPaintRectsSeparately, bool, true); michael@0: michael@0: DECL_GFX_PREF(Live, "nglayout.debug.widget_update_flashing", WidgetUpdateFlashing, bool, false); michael@0: michael@0: DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay, int32_t, 500); michael@0: michael@0: DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false); michael@0: michael@0: public: michael@0: // Manage the singleton: michael@0: static gfxPrefs& GetSingleton() michael@0: { michael@0: if (!sInstance) { michael@0: sInstance = new gfxPrefs; michael@0: } michael@0: return *sInstance; michael@0: } michael@0: static void DestroySingleton(); michael@0: static bool SingletonExists(); michael@0: michael@0: private: michael@0: static gfxPrefs* sInstance; michael@0: michael@0: private: michael@0: // Creating these to avoid having to include Preferences.h in the .h michael@0: static void PrefAddVarCache(bool*, const char*, bool); michael@0: static void PrefAddVarCache(int32_t*, const char*, int32_t); michael@0: static void PrefAddVarCache(uint32_t*, const char*, uint32_t); michael@0: static void PrefAddVarCache(float*, const char*, float); michael@0: static bool PrefGet(const char*, bool); michael@0: static int32_t PrefGet(const char*, int32_t); michael@0: static uint32_t PrefGet(const char*, uint32_t); michael@0: static float PrefGet(const char*, float); michael@0: michael@0: gfxPrefs(); michael@0: ~gfxPrefs(); michael@0: gfxPrefs(const gfxPrefs&) MOZ_DELETE; michael@0: gfxPrefs& operator=(const gfxPrefs&) MOZ_DELETE; michael@0: }; michael@0: michael@0: #undef DECL_GFX_PREF /* Don't need it outside of this file */ michael@0: michael@0: #endif /* GFX_PREFS_H */