LCOV - code coverage report
Current view: top level - gfx/config - gfxVars.h (source / functions) Hit Total Coverage
Test: output.info Lines: 22 24 91.7 %
Date: 2017-07-14 16:53:18 Functions: 99 137 72.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* vim: set sts=2 ts=8 sw=2 tw=99 et: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : #ifndef mozilla_gfx_config_gfxVars_h
       7             : #define mozilla_gfx_config_gfxVars_h
       8             : 
       9             : #include <stdint.h>
      10             : #include "mozilla/Assertions.h"
      11             : #include "mozilla/StaticPtr.h"
      12             : #include "mozilla/gfx/GraphicsMessages.h"
      13             : #include "mozilla/gfx/Point.h"
      14             : #include "mozilla/gfx/Types.h"
      15             : #include "nsTArray.h"
      16             : #include "nsXULAppAPI.h"
      17             : 
      18             : namespace mozilla {
      19             : namespace gfx {
      20             : 
      21             : class gfxVarReceiver;
      22             : 
      23             : // Generator for graphics vars.
      24             : #define GFX_VARS_LIST(_)                                                \
      25             :   /* C++ Name,                  Data Type,        Default Value */      \
      26             :   _(BrowserTabsRemoteAutostart, bool,             false)                \
      27             :   _(ContentBackend,             BackendType,      BackendType::NONE)    \
      28             :   _(SoftwareBackend,            BackendType,      BackendType::NONE)    \
      29             :   _(TileSize,                   IntSize,          IntSize(-1, -1))      \
      30             :   _(UseXRender,                 bool,             false)                \
      31             :   _(OffscreenFormat,            gfxImageFormat,   mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) \
      32             :   _(RequiresAcceleratedGLContextForCompositorOGL, bool, false)          \
      33             :   _(CanUseHardwareVideoDecoding, bool,            false)                \
      34             :   _(PDMWMFDisableD3D11Dlls,     nsCString,        nsCString())          \
      35             :   _(PDMWMFDisableD3D9Dlls,      nsCString,        nsCString())          \
      36             :   _(DXInterop2Blocked,          bool,             false)                \
      37             :   _(UseWebRender,               bool,             false)                \
      38             :   _(UseWebRenderANGLE,          bool,             false)                \
      39             :   _(ScreenDepth,                int32_t,          0)                    \
      40             :   _(GREDirectory,               nsCString,        nsCString())          \
      41             :   _(UseOMTP,                    bool,             false)                \
      42             : 
      43             :   /* Add new entries above this line. */
      44             : 
      45             : // Some graphics settings are computed on the UI process and must be
      46             : // communicated to content and GPU processes. gfxVars helps facilitate
      47             : // this. Its function is similar to gfxPrefs, except rather than hold
      48             : // user preferences, it holds dynamically computed values.
      49             : //
      50             : // Each variable in GFX_VARS_LIST exposes the following static methods:
      51             : //
      52             : //    const DataType& CxxName();
      53             : //    void SetCxxName(const DataType& aValue);
      54             : //
      55             : // Note that the setter may only be called in the UI process; a gfxVar must be
      56             : // a variable that is determined in the UI process and pushed to child
      57             : // processes.
      58           0 : class gfxVars final
      59             : {
      60             : public:
      61             :   // These values will be used during the Initialize() call if set.  Any
      62             :   // updates that come before initialization will get added to this array.
      63             :   static void SetValuesForInitialize(const nsTArray<GfxVarUpdate>& aInitUpdates);
      64             : 
      65             :   static void Initialize();
      66             :   static void Shutdown();
      67             : 
      68             :   static void ApplyUpdate(const GfxVarUpdate& aUpdate);
      69             :   static void AddReceiver(gfxVarReceiver* aReceiver);
      70             :   static void RemoveReceiver(gfxVarReceiver* aReceiver);
      71             : 
      72             :   // Return a list of updates for all variables with non-default values.
      73             :   static nsTArray<GfxVarUpdate> FetchNonDefaultVars();
      74             : 
      75             : public:
      76             :   // Each variable must expose Set and Get methods for IPDL.
      77             :   class VarBase
      78             :   {
      79             :   public:
      80             :     VarBase();
      81             :     virtual void SetValue(const GfxVarValue& aValue) = 0;
      82             :     virtual void GetValue(GfxVarValue* aOutValue) = 0;
      83             :     virtual bool HasDefaultValue() const = 0;
      84           7 :     size_t Index() const {
      85           7 :       return mIndex;
      86             :     }
      87             :   private:
      88             :     size_t mIndex;
      89             :   };
      90             : 
      91             : private:
      92             :   static StaticAutoPtr<gfxVars> sInstance;
      93             :   static StaticAutoPtr<nsTArray<VarBase*>> sVarList;
      94             : 
      95             :   template <typename T, T Default()>
      96           0 :   class VarImpl final : public VarBase
      97             :   {
      98             :   public:
      99          48 :     VarImpl()
     100          48 :      : mValue(Default())
     101          48 :     {}
     102          14 :     void SetValue(const GfxVarValue& aValue) override {
     103          14 :       aValue.get(&mValue);
     104          14 :     }
     105          21 :     void GetValue(GfxVarValue* aOutValue) override {
     106          21 :       *aOutValue = GfxVarValue(mValue);
     107          21 :     }
     108          32 :     bool HasDefaultValue() const override {
     109          32 :       return mValue == Default();
     110             :     }
     111         865 :     const T& Get() const {
     112         865 :       return mValue;
     113             :     }
     114             :     // Return true if the value changed, false otherwise.
     115          14 :     bool Set(const T& aValue) {
     116          14 :       MOZ_ASSERT(XRE_IsParentProcess());
     117          14 :       if (mValue == aValue) {
     118           7 :         return false;
     119             :       }
     120           7 :       mValue = aValue;
     121           7 :       return true;
     122             :     }
     123             :   private:
     124             :     T mValue;
     125             :   };
     126             : 
     127             : #define GFX_VAR_DECL(CxxName, DataType, DefaultValue)           \
     128             : private:                                                        \
     129             :   static DataType Get##CxxName##Default() {                     \
     130             :     return DefaultValue;                                        \
     131             :   }                                                             \
     132             :   VarImpl<DataType, Get##CxxName##Default> mVar##CxxName;       \
     133             : public:                                                         \
     134             :   static const DataType& CxxName() {                            \
     135             :     return sInstance->mVar##CxxName.Get();                      \
     136             :   }                                                             \
     137             :   static void Set##CxxName(const DataType& aValue) {            \
     138             :     if (sInstance->mVar##CxxName.Set(aValue)) {                 \
     139             :       sInstance->NotifyReceivers(&sInstance->mVar##CxxName);    \
     140             :     }                                                           \
     141             :   }
     142             : 
     143         959 :   GFX_VARS_LIST(GFX_VAR_DECL)
     144             : #undef GFX_VAR_DECL
     145             : 
     146             : private:
     147             :   gfxVars();
     148             : 
     149             :   void NotifyReceivers(VarBase* aVar);
     150             : 
     151             : private:
     152             :   nsTArray<gfxVarReceiver*> mReceivers;
     153             : };
     154             : 
     155             : #undef GFX_VARS_LIST
     156             : 
     157             : } // namespace gfx
     158             : } // namespace mozilla
     159             : 
     160             : #endif // mozilla_gfx_config_gfxVars_h

Generated by: LCOV version 1.13