Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / gl / GfxTexturesReporter.h
blob077fc0e879455fcfc4bde916437f0b6f5e3f34e0
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/. */
7 #ifndef GFXTEXTURESREPORTER_H_
8 #define GFXTEXTURESREPORTER_H_
10 #include "mozilla/Atomics.h"
11 #include "nsIMemoryReporter.h"
12 #include "GLTypes.h"
14 namespace mozilla {
15 namespace gl {
17 class GfxTexturesReporter final : public nsIMemoryReporter {
18 ~GfxTexturesReporter() = default;
20 public:
21 NS_DECL_ISUPPORTS
23 GfxTexturesReporter() {
24 #ifdef DEBUG
25 // There must be only one instance of this class, due to |sAmount|
26 // being static. Assert this.
27 static bool hasRun = false;
28 MOZ_ASSERT(!hasRun);
29 hasRun = true;
30 #endif
33 enum MemoryUse {
34 // when memory being allocated is reported to a memory reporter
35 MemoryAllocated,
36 // when memory being freed is reported to a memory reporter
37 MemoryFreed
40 // When memory is used/freed for tile textures, call this method to update
41 // the value reported by this memory reporter.
42 static void UpdateAmount(MemoryUse action, size_t amount);
44 static void UpdateWasteAmount(size_t delta) { sTileWasteAmount += delta; }
46 NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
47 nsISupports* aData, bool aAnonymize) override {
48 MOZ_COLLECT_REPORT(
49 "gfx-tiles-waste", KIND_OTHER, UNITS_BYTES, int64_t(sTileWasteAmount),
50 "Memory lost due to tiles extending past content boundaries");
52 MOZ_COLLECT_REPORT("gfx-textures", KIND_OTHER, UNITS_BYTES,
53 int64_t(sAmount),
54 "Memory used for storing GL textures.");
56 MOZ_COLLECT_REPORT("gfx-textures-peak", KIND_OTHER, UNITS_BYTES,
57 int64_t(sPeakAmount),
58 "Peak memory used for storing GL textures.");
60 return NS_OK;
63 private:
64 static Atomic<size_t> sAmount;
65 static Atomic<size_t> sPeakAmount;
66 // Count the amount of memory lost to tile waste
67 static Atomic<size_t> sTileWasteAmount;
70 class GfxTextureWasteTracker {
71 public:
72 GfxTextureWasteTracker() : mBytes(0) {
73 MOZ_COUNT_CTOR(GfxTextureWasteTracker);
76 void Update(int32_t aPixelArea, int32_t aBytesPerPixel) {
77 GfxTexturesReporter::UpdateWasteAmount(-mBytes);
78 mBytes = aPixelArea * aBytesPerPixel;
79 GfxTexturesReporter::UpdateWasteAmount(mBytes);
82 ~GfxTextureWasteTracker() {
83 GfxTexturesReporter::UpdateWasteAmount(-mBytes);
84 MOZ_COUNT_DTOR(GfxTextureWasteTracker);
87 private:
88 GfxTextureWasteTracker(const GfxTextureWasteTracker& aRef);
90 int32_t mBytes;
93 } // namespace gl
94 } // namespace mozilla
96 #endif // GFXTEXTURESREPORTER_H_