Bug 1646700 [wpt PR 24235] - Update picture-in-picture idlharness test, a=testonly
[gecko.git] / layout / base / nsPresArena.h
blob482e94137d52569ab2a663ed034fd163ec5b7008
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 "nsDataHashtable.h"
21 #include "nsHashKeys.h"
22 #include "nsTArray.h"
23 #include "nsTHashtable.h"
25 class nsWindowSizes;
27 template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount>
28 class nsPresArena {
29 public:
30 nsPresArena() = default;
31 ~nsPresArena();
33 /**
34 * Pool allocation with recycler lists indexed by object-type ID (see above).
35 * Every aID must always be used with the same object size, aSize.
37 void* Allocate(ObjectId aCode, size_t aSize);
38 void Free(ObjectId aCode, void* aPtr);
40 enum class ArenaKind { PresShell, DisplayList };
41 /**
42 * Increment nsWindowSizes with sizes of interesting objects allocated in this
43 * arena, and put the general unclassified size in the relevant field
44 * depending on the arena size.
46 void AddSizeOfExcludingThis(nsWindowSizes&, ArenaKind) const;
48 void Check() { mPool.Check(); }
50 private:
51 class FreeList {
52 public:
53 nsTArray<void*> mEntries;
54 size_t mEntrySize;
55 size_t mEntriesEverAllocated;
57 FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {}
59 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
60 return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf);
64 FreeList mFreeLists[ObjectIdCount];
65 mozilla::ArenaAllocator<ArenaSize, 8> mPool;
68 #endif