tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsWindowSizes.h (6873B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 
      7 #ifndef nsWindowSizes_h
      8 #define nsWindowSizes_h
      9 
     10 #include "mozilla/Assertions.h"
     11 #include "mozilla/SizeOfState.h"
     12 #include "nsStyleStructList.h"
     13 
     14 class nsTabSizes {
     15 public:
     16  enum Kind {
     17    DOM,    // DOM stuff.
     18    Style,  // Style stuff.
     19    Other   // Everything else.
     20  };
     21 
     22  nsTabSizes() : mDom(0), mStyle(0), mOther(0) {}
     23 
     24  void add(Kind kind, size_t n) {
     25    switch (kind) {
     26      case DOM:
     27        mDom += n;
     28        break;
     29      case Style:
     30        mStyle += n;
     31        break;
     32      case Other:
     33        mOther += n;
     34        break;
     35      default:
     36        MOZ_CRASH("bad nsTabSizes kind");
     37    }
     38  }
     39 
     40  size_t mDom;
     41  size_t mStyle;
     42  size_t mOther;
     43 };
     44 
     45 #define ZERO_SIZE(kind, mSize) mSize(0),
     46 #define ADD_TO_TAB_SIZES(kind, mSize) aSizes->add(nsTabSizes::kind, mSize);
     47 #define ADD_TO_TOTAL_SIZE(kind, mSize) total += mSize;
     48 #define DECL_SIZE(kind, mSize) size_t mSize;
     49 
     50 #define NS_STYLE_SIZES_FIELD(name_) mStyle##name_
     51 
     52 struct nsStyleSizes {
     53  nsStyleSizes()
     54      :
     55 #define INIT_FIELD(name_) NS_STYLE_SIZES_FIELD(name_)(0),
     56        FOR_EACH_STYLE_STRUCT(INIT_FIELD, INIT_FIELD)
     57 #undef INIT_FIELD
     58 
     59            dummy() {
     60  }
     61 
     62  void addToTabSizes(nsTabSizes* aSizes) const {
     63 #define ADD_TO_TAB(name_) \
     64  aSizes->add(nsTabSizes::Style, NS_STYLE_SIZES_FIELD(name_));
     65      FOR_EACH_STYLE_STRUCT(ADD_TO_TAB, ADD_TO_TAB)
     66 #undef ADD_TO_TAB
     67  }
     68 
     69  size_t getTotalSize() const {
     70    size_t total = 0;
     71 
     72 #define ADD_TO_TOTAL(name_) total += NS_STYLE_SIZES_FIELD(name_);
     73    FOR_EACH_STYLE_STRUCT(ADD_TO_TOTAL, ADD_TO_TOTAL)
     74 #undef ADD_TO_TOTAL
     75 
     76    return total;
     77  }
     78 
     79 #define DECLARE_FIELD(name_) size_t NS_STYLE_SIZES_FIELD(name_);
     80  FOR_EACH_STYLE_STRUCT(DECLARE_FIELD, DECLARE_FIELD)
     81 #undef DECLARE_FIELD
     82 
     83  // Present just to absorb the trailing comma in the constructor.
     84  int dummy;
     85 };
     86 
     87 #define NS_ARENA_SIZES_FIELD(classname) mArena##classname
     88 
     89 struct nsArenaSizes {
     90  nsArenaSizes()
     91      :
     92 #define PRES_ARENA_OBJECT(name_) NS_ARENA_SIZES_FIELD(name_)(0),
     93 #define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
     94 #include "nsDisplayListArenaTypes.h"
     95 #include "nsPresArenaObjectList.h"
     96 #undef PRES_ARENA_OBJECT
     97 #undef DISPLAY_LIST_ARENA_OBJECT
     98        dummy() {
     99  }
    100 
    101  void addToTabSizes(nsTabSizes* aSizes) const {
    102 #define PRES_ARENA_OBJECT(name_) \
    103  aSizes->add(nsTabSizes::Other, NS_ARENA_SIZES_FIELD(name_));
    104 #define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
    105 #include "nsDisplayListArenaTypes.h"
    106 #include "nsPresArenaObjectList.h"
    107 #undef PRES_ARENA_OBJECT
    108 #undef DISPLAY_LIST_ARENA_OBJECT
    109  }
    110 
    111  size_t getTotalSize() const {
    112    size_t total = 0;
    113 
    114 #define PRES_ARENA_OBJECT(name_) total += NS_ARENA_SIZES_FIELD(name_);
    115 #define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
    116 #include "nsDisplayListArenaTypes.h"
    117 #include "nsPresArenaObjectList.h"
    118 #undef PRES_ARENA_OBJECT
    119 #undef DISPLAY_LIST_ARENA_OBJECT
    120 
    121    return total;
    122  }
    123 
    124 #define PRES_ARENA_OBJECT(name_) size_t NS_ARENA_SIZES_FIELD(name_);
    125 #define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
    126 #include "nsDisplayListArenaTypes.h"
    127 #include "nsPresArenaObjectList.h"
    128 #undef PRES_ARENA_OBJECT
    129 #undef DISPLAY_LIST_ARENA_OBJECT
    130 
    131  // Present just to absorb the trailing comma in the constructor.
    132  int dummy;
    133 };
    134 
    135 struct nsDOMSizes {
    136 #define FOR_EACH_SIZE(MACRO)                 \
    137  MACRO(DOM, mDOMElementNodesSize)           \
    138  MACRO(DOM, mDOMTextNodesSize)              \
    139  MACRO(DOM, mDOMCDATANodesSize)             \
    140  MACRO(DOM, mDOMCommentNodesSize)           \
    141  MACRO(DOM, mDOMEventTargetsSize)           \
    142  MACRO(DOM, mDOMMediaQueryLists)            \
    143  MACRO(DOM, mDOMPerformanceEventEntries)    \
    144  MACRO(DOM, mDOMPerformanceUserEntries)     \
    145  MACRO(DOM, mDOMPerformanceResourceEntries) \
    146  MACRO(DOM, mDOMResizeObserverControllerSize)
    147 
    148  nsDOMSizes() : FOR_EACH_SIZE(ZERO_SIZE) mDOMOtherSize(0) {}
    149 
    150  void addToTabSizes(nsTabSizes* aSizes) const {
    151    FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
    152    aSizes->add(nsTabSizes::DOM, mDOMOtherSize);
    153  }
    154 
    155  size_t getTotalSize() const {
    156    size_t total = 0;
    157    FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
    158    total += mDOMOtherSize;
    159    return total;
    160  }
    161 
    162  FOR_EACH_SIZE(DECL_SIZE)
    163 
    164  size_t mDOMOtherSize;
    165 #undef FOR_EACH_SIZE
    166 };
    167 
    168 class nsWindowSizes {
    169 #define FOR_EACH_SIZE(MACRO)                                 \
    170  MACRO(Style, mLayoutStyleSheetsSize)                       \
    171  MACRO(Style, mLayoutShadowDomStyleSheetsSize)              \
    172  MACRO(Style, mLayoutShadowDomAuthorStyles)                 \
    173  MACRO(Other, mLayoutPresShellSize)                         \
    174  MACRO(Other, mLayoutRetainedDisplayListSize)               \
    175  MACRO(Style, mLayoutStyleSetsStylistRuleTree)              \
    176  MACRO(Style, mLayoutStyleSetsStylistElementAndPseudosMaps) \
    177  MACRO(Style, mLayoutStyleSetsStylistInvalidationMap)       \
    178  MACRO(Style, mLayoutStyleSetsStylistRevalidationSelectors) \
    179  MACRO(Style, mLayoutStyleSetsStylistOther)                 \
    180  MACRO(Style, mLayoutStyleSetsOther)                        \
    181  MACRO(Style, mLayoutElementDataObjects)                    \
    182  MACRO(Other, mLayoutTextRunsSize)                          \
    183  MACRO(Other, mLayoutPresContextSize)                       \
    184  MACRO(Other, mLayoutFramePropertiesSize)                   \
    185  MACRO(Style, mLayoutComputedValuesDom)                     \
    186  MACRO(Style, mLayoutComputedValuesNonDom)                  \
    187  MACRO(Style, mLayoutComputedValuesVisited)                 \
    188  MACRO(Style, mLayoutSvgMappedDeclarations)                 \
    189  MACRO(Other, mPropertyTablesSize)                          \
    190  MACRO(Other, mBindingsSize)
    191 
    192 public:
    193  explicit nsWindowSizes(mozilla::SizeOfState& aState)
    194      : FOR_EACH_SIZE(ZERO_SIZE) mDOMEventTargetsCount(0),
    195        mDOMEventListenersCount(0),
    196        mState(aState) {}
    197 
    198  void addToTabSizes(nsTabSizes* aSizes) const {
    199    FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
    200    mDOMSizes.addToTabSizes(aSizes);
    201    mArenaSizes.addToTabSizes(aSizes);
    202    mStyleSizes.addToTabSizes(aSizes);
    203  }
    204 
    205  size_t getTotalSize() const {
    206    size_t total = 0;
    207 
    208    FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
    209    total += mDOMSizes.getTotalSize();
    210    total += mArenaSizes.getTotalSize();
    211    total += mStyleSizes.getTotalSize();
    212 
    213    return total;
    214  }
    215 
    216  FOR_EACH_SIZE(DECL_SIZE);
    217 
    218  uint32_t mDOMEventTargetsCount;
    219  uint32_t mDOMEventListenersCount;
    220 
    221  nsDOMSizes mDOMSizes;
    222 
    223  nsArenaSizes mArenaSizes;
    224 
    225  nsStyleSizes mStyleSizes;
    226 
    227  mozilla::SizeOfState& mState;
    228 
    229 #undef FOR_EACH_SIZE
    230 };
    231 
    232 #undef ZERO_SIZE
    233 #undef ADD_TO_TAB_SIZES
    234 #undef ADD_TO_TOTAL_SIZE
    235 #undef DECL_SIZE
    236 
    237 #endif  // nsWindowSizes_h