summaryrefslogtreecommitdiffstats
path: root/dom/base/nsWindowSizes.h
blob: aceabac99f9dc6e03c79bc2fef48237eb8468bba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsWindowSizes_h
#define nsWindowSizes_h

#include "mozilla/Assertions.h"
#include "mozilla/PodOperations.h"
#include "mozilla/SizeOfState.h"

class nsTabSizes {
 public:
  enum Kind {
    DOM,    // DOM stuff.
    Style,  // Style stuff.
    Other   // Everything else.
  };

  nsTabSizes() : mDom(0), mStyle(0), mOther(0) {}

  void add(Kind kind, size_t n) {
    switch (kind) {
      case DOM:
        mDom += n;
        break;
      case Style:
        mStyle += n;
        break;
      case Other:
        mOther += n;
        break;
      default:
        MOZ_CRASH("bad nsTabSizes kind");
    }
  }

  size_t mDom;
  size_t mStyle;
  size_t mOther;
};

#define ZERO_SIZE(kind, mSize) mSize(0),
#define ADD_TO_TAB_SIZES(kind, mSize) aSizes->add(nsTabSizes::kind, mSize);
#define ADD_TO_TOTAL_SIZE(kind, mSize) total += mSize;
#define DECL_SIZE(kind, mSize) size_t mSize;

#define NS_STYLE_SIZES_FIELD(name_) mStyle##name_

struct nsStyleSizes {
  nsStyleSizes()
      :
#define STYLE_STRUCT(name_) NS_STYLE_SIZES_FIELD(name_)(0),
#include "nsStyleStructList.h"
#undef STYLE_STRUCT

        dummy() {
  }

  void addToTabSizes(nsTabSizes* aSizes) const {
#define STYLE_STRUCT(name_) \
  aSizes->add(nsTabSizes::Style, NS_STYLE_SIZES_FIELD(name_));
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
  }

  size_t getTotalSize() const {
    size_t total = 0;

#define STYLE_STRUCT(name_) total += NS_STYLE_SIZES_FIELD(name_);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT

    return total;
  }

#define STYLE_STRUCT(name_) size_t NS_STYLE_SIZES_FIELD(name_);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT

  // Present just to absorb the trailing comma in the constructor.
  int dummy;
};

#define NS_ARENA_SIZES_FIELD(classname) mArena##classname

struct nsArenaSizes {
  nsArenaSizes()
      :
#define PRES_ARENA_OBJECT(name_) NS_ARENA_SIZES_FIELD(name_)(0),
#define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
#include "nsPresArenaObjectList.h"
#include "nsDisplayListArenaTypes.h"
#undef PRES_ARENA_OBJECT
#undef DISPLAY_LIST_ARENA_OBJECT
        dummy() {
  }

  void addToTabSizes(nsTabSizes* aSizes) const {
#define PRES_ARENA_OBJECT(name_) \
  aSizes->add(nsTabSizes::Other, NS_ARENA_SIZES_FIELD(name_));
#define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
#include "nsPresArenaObjectList.h"
#include "nsDisplayListArenaTypes.h"
#undef PRES_ARENA_OBJECT
#undef DISPLAY_LIST_ARENA_OBJECT
  }

  size_t getTotalSize() const {
    size_t total = 0;

#define PRES_ARENA_OBJECT(name_) total += NS_ARENA_SIZES_FIELD(name_);
#define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
#include "nsPresArenaObjectList.h"
#include "nsDisplayListArenaTypes.h"
#undef PRES_ARENA_OBJECT
#undef DISPLAY_LIST_ARENA_OBJECT

    return total;
  }

#define PRES_ARENA_OBJECT(name_) size_t NS_ARENA_SIZES_FIELD(name_);
#define DISPLAY_LIST_ARENA_OBJECT(name_) PRES_ARENA_OBJECT(name_)
#include "nsPresArenaObjectList.h"
#include "nsDisplayListArenaTypes.h"
#undef PRES_ARENA_OBJECT
#undef DISPLAY_LIST_ARENA_OBJECT

  // Present just to absorb the trailing comma in the constructor.
  int dummy;
};

struct nsDOMSizes {
#define FOR_EACH_SIZE(MACRO)                 \
  MACRO(DOM, mDOMElementNodesSize)           \
  MACRO(DOM, mDOMTextNodesSize)              \
  MACRO(DOM, mDOMCDATANodesSize)             \
  MACRO(DOM, mDOMCommentNodesSize)           \
  MACRO(DOM, mDOMEventTargetsSize)           \
  MACRO(DOM, mDOMMediaQueryLists)            \
  MACRO(DOM, mDOMPerformanceEventEntries)    \
  MACRO(DOM, mDOMPerformanceUserEntries)     \
  MACRO(DOM, mDOMPerformanceResourceEntries) \
  MACRO(DOM, mDOMResizeObserverControllerSize)

  nsDOMSizes() : FOR_EACH_SIZE(ZERO_SIZE) mDOMOtherSize(0) {}

  void addToTabSizes(nsTabSizes* aSizes) const {
    FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
    aSizes->add(nsTabSizes::DOM, mDOMOtherSize);
  }

  size_t getTotalSize() const {
    size_t total = 0;
    FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
    total += mDOMOtherSize;
    return total;
  }

  FOR_EACH_SIZE(DECL_SIZE)

  size_t mDOMOtherSize;
#undef FOR_EACH_SIZE
};

class nsWindowSizes {
#define FOR_EACH_SIZE(MACRO)                                 \
  MACRO(Style, mLayoutStyleSheetsSize)                       \
  MACRO(Style, mLayoutShadowDomStyleSheetsSize)              \
  MACRO(Style, mLayoutShadowDomAuthorStyles)                 \
  MACRO(Other, mLayoutPresShellSize)                         \
  MACRO(Other, mLayoutRetainedDisplayListSize)               \
  MACRO(Style, mLayoutStyleSetsStylistRuleTree)              \
  MACRO(Style, mLayoutStyleSetsStylistElementAndPseudosMaps) \
  MACRO(Style, mLayoutStyleSetsStylistInvalidationMap)       \
  MACRO(Style, mLayoutStyleSetsStylistRevalidationSelectors) \
  MACRO(Style, mLayoutStyleSetsStylistOther)                 \
  MACRO(Style, mLayoutStyleSetsOther)                        \
  MACRO(Style, mLayoutElementDataObjects)                    \
  MACRO(Other, mLayoutTextRunsSize)                          \
  MACRO(Other, mLayoutPresContextSize)                       \
  MACRO(Other, mLayoutFramePropertiesSize)                   \
  MACRO(Style, mLayoutComputedValuesDom)                     \
  MACRO(Style, mLayoutComputedValuesNonDom)                  \
  MACRO(Style, mLayoutComputedValuesVisited)                 \
  MACRO(Style, mLayoutSvgMappedDeclarations)                 \
  MACRO(Other, mPropertyTablesSize)                          \
  MACRO(Other, mBindingsSize)

 public:
  explicit nsWindowSizes(mozilla::SizeOfState& aState)
      : FOR_EACH_SIZE(ZERO_SIZE) mDOMEventTargetsCount(0),
        mDOMEventListenersCount(0),
        mState(aState) {}

  void addToTabSizes(nsTabSizes* aSizes) const {
    FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
    mDOMSizes.addToTabSizes(aSizes);
    mArenaSizes.addToTabSizes(aSizes);
    mStyleSizes.addToTabSizes(aSizes);
  }

  size_t getTotalSize() const {
    size_t total = 0;

    FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
    total += mDOMSizes.getTotalSize();
    total += mArenaSizes.getTotalSize();
    total += mStyleSizes.getTotalSize();

    return total;
  }

  FOR_EACH_SIZE(DECL_SIZE);

  uint32_t mDOMEventTargetsCount;
  uint32_t mDOMEventListenersCount;

  nsDOMSizes mDOMSizes;

  nsArenaSizes mArenaSizes;

  nsStyleSizes mStyleSizes;

  mozilla::SizeOfState& mState;

#undef FOR_EACH_SIZE
};

#undef ZERO_SIZE
#undef ADD_TO_TAB_SIZES
#undef ADD_TO_TOTAL_SIZE
#undef DECL_SIZE

#endif  // nsWindowSizes_h