LCOV - code coverage report
Current view: top level - layout/style - RuleNodeCacheConditions.h (source / functions) Hit Total Coverage
Test: output.info Lines: 26 38 68.4 %
Date: 2017-07-14 16:53:18 Functions: 9 13 69.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; 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/. */
       5             : 
       6             : /*
       7             :  * an object that stores the result of determining whether a style struct that
       8             :  * was computed can be cached in the rule tree, and if so, what the conditions
       9             :  * it relies on are
      10             :  */
      11             : 
      12             : #ifndef RuleNodeCacheConditions_h_
      13             : #define RuleNodeCacheConditions_h_
      14             : 
      15             : #include "mozilla/Attributes.h"
      16             : #include "nsCoord.h"
      17             : #include "nsTArray.h"
      18             : 
      19             : class nsStyleContext;
      20             : 
      21             : namespace mozilla {
      22             : 
      23             : /**
      24             :  * nsRuleNodeCacheConditions is used to store information about whether
      25             :  * we can store a style struct that we're computing in the rule tree.
      26             :  *
      27             :  * For inherited structs (i.e., structs with inherited properties), we
      28             :  * cache the struct in the rule tree if it does not depend on any data
      29             :  * in the style context tree, and otherwise store it in the style
      30             :  * context tree.  This means that for inherited structs, setting any
      31             :  * conditions is equivalent to making the struct uncacheable.
      32             :  *
      33             :  * For reset structs (i.e., structs with non-inherited properties), we
      34             :  * are also able to cache structs in the rule tree conditionally on
      35             :  * certain common conditions.  For these structs, setting conditions
      36             :  * (SetFontSizeDependency, SetWritingModeDependency) instead causes the
      37             :  * struct to be stored, with the condition, in the rule tree.
      38             :  */
      39             : class RuleNodeCacheConditions
      40             : {
      41             : public:
      42       12274 :   RuleNodeCacheConditions()
      43       12274 :     : mFontSize(0), mBits(0) {}
      44        8222 :   RuleNodeCacheConditions(const RuleNodeCacheConditions& aOther)
      45        8222 :     : mFontSize(aOther.mFontSize), mBits(aOther.mBits) {}
      46           0 :   RuleNodeCacheConditions& operator=(const RuleNodeCacheConditions& aOther)
      47             :   {
      48           0 :     mFontSize = aOther.mFontSize;
      49           0 :     mBits = aOther.mBits;
      50           0 :     return *this;
      51             :   }
      52           0 :   bool operator==(const RuleNodeCacheConditions& aOther) const
      53             :   {
      54           0 :     return mFontSize == aOther.mFontSize &&
      55           0 :            mBits == aOther.mBits;
      56             :   }
      57           0 :   bool operator!=(const RuleNodeCacheConditions& aOther) const
      58             :   {
      59           0 :     return !(*this == aOther);
      60             :   }
      61             : 
      62             :   bool Matches(nsStyleContext* aStyleContext) const;
      63             : 
      64             :   /**
      65             :    * Record that the data being computed depend on the font-size
      66             :    * property of the element for which they are being computed.
      67             :    *
      68             :    * Note that we sometimes actually call this when there is a
      69             :    * dependency on the font-size property of the parent element, but we
      70             :    * only do so while computing inherited structs (nsStyleFont), and we
      71             :    * only store reset structs conditionally.
      72             :    */
      73          11 :   void SetFontSizeDependency(nscoord aCoord)
      74             :   {
      75          11 :     MOZ_ASSERT(!(mBits & eHaveFontSize) || mFontSize == aCoord);
      76          11 :     mFontSize = aCoord;
      77          11 :     mBits |= eHaveFontSize;
      78          11 :   }
      79             : 
      80             :   /**
      81             :    * Record that the data being computed depend on the writing mode of
      82             :    * the element for which they are being computed, which in turn
      83             :    * depends on its 'writing-mode', 'direction', and 'text-orientation'
      84             :    * properties.
      85             :    */
      86         194 :   void SetWritingModeDependency(uint8_t aWritingMode)
      87             :   {
      88         194 :     MOZ_ASSERT(!(mBits & eHaveWritingMode) || GetWritingMode() == aWritingMode);
      89         388 :     mBits |= (static_cast<uint64_t>(aWritingMode) << eWritingModeShift) |
      90         388 :              eHaveWritingMode;
      91         194 :   }
      92             : 
      93        4297 :   void SetUncacheable()
      94             :   {
      95        4297 :     mBits |= eUncacheable;
      96        4297 :   }
      97             : 
      98           0 :   void Clear()
      99             :   {
     100           0 :     *this = RuleNodeCacheConditions();
     101           0 :   }
     102             : 
     103         816 :   bool Cacheable() const
     104             :   {
     105         816 :     return !(mBits & eUncacheable);
     106             :   }
     107             : 
     108        4584 :   bool CacheableWithDependencies() const
     109             :   {
     110        9168 :     return !(mBits & eUncacheable) &&
     111        9168 :            (mBits & eHaveBitsMask) != 0;
     112             :   }
     113             : 
     114       24520 :   bool CacheableWithoutDependencies() const
     115             :   {
     116             :     // We're not uncacheable and we have don't have a font-size or
     117             :     // writing mode value.
     118       24520 :     return (mBits & eHaveBitsMask) == 0;
     119             :   }
     120             : 
     121             : #ifdef DEBUG
     122             :   void List() const;
     123             : #endif
     124             : 
     125             : private:
     126             :   enum {
     127             :     eUncacheable      = 0x0001,
     128             :     eHaveFontSize     = 0x0002,
     129             :     eHaveWritingMode  = 0x0004,
     130             :     eHaveBitsMask     = 0x00ff,
     131             :     eWritingModeMask  = 0xff00,
     132             :     eWritingModeShift = 8,
     133             :   };
     134             : 
     135         143 :   uint8_t GetWritingMode() const
     136             :   {
     137             :     return static_cast<uint8_t>(
     138         143 :         (mBits & eWritingModeMask) >> eWritingModeShift);
     139             :   }
     140             : 
     141             :   // The font size from which em units are derived.
     142             :   nscoord mFontSize;
     143             : 
     144             :   // Values in mBits:
     145             :   //   bit 0:      are we set to "uncacheable"?
     146             :   //   bit 1:      do we have a font size value?
     147             :   //   bit 2:      do we have a writing mode value?
     148             :   //   bits 3-7:   unused
     149             :   //   bits 8-15:  writing mode (uint8_t)
     150             :   //   bits 16-31: unused
     151             :   uint32_t mBits;
     152             : };
     153             : 
     154             : } // namespace mozilla
     155             : 
     156             : #endif // !defined(RuleNodeCacheConditions_h_)

Generated by: LCOV version 1.13