Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / base / nsPresArena.h
blob884f2b44c57843e14b8a60864386040b9153715e
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 */
8 /* arena allocation for the frame tree and closely-related objects */
10 #ifndef nsPresArena_h___
11 #define nsPresArena_h___
13 #include "mozilla/ArenaAllocator.h"
14 #include "mozilla/ArenaObjectID.h"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below
17 #include "mozilla/MemoryReporting.h"
18 #include <stdint.h>
19 #include "nscore.h"
20 #include "nsHashKeys.h"
21 #include "nsTArray.h"
22 #include "nsTHashtable.h"
24 class nsWindowSizes;
26 template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount>
27 class nsPresArena {
28 public:
29 nsPresArena() = default;
30 ~nsPresArena();
32 /**
33 * Pool allocation with recycler lists indexed by object-type ID (see above).
34 * Every aID must always be used with the same object size, aSize.
36 void* Allocate(ObjectId aCode, size_t aSize);
37 void Free(ObjectId aCode, void* aPtr);
39 enum class ArenaKind { PresShell, DisplayList };
40 /**
41 * Increment nsWindowSizes with sizes of interesting objects allocated in this
42 * arena, and put the general unclassified size in the relevant field
43 * depending on the arena size.
45 void AddSizeOfExcludingThis(nsWindowSizes&, ArenaKind) const;
47 void Check() { mPool.Check(); }
49 private:
50 class FreeList {
51 public:
52 nsTArray<void*> mEntries;
53 size_t mEntrySize;
54 size_t mEntriesEverAllocated;
56 FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {}
58 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
59 return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf);
63 FreeList mFreeLists[ObjectIdCount];
64 mozilla::ArenaAllocator<ArenaSize, 8> mPool;
67 #endif