Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set ts=8 sts=4 et sw=4 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 GFXTEXTURESREPORTER_H_
8 : #define GFXTEXTURESREPORTER_H_
9 :
10 : #include "mozilla/Atomics.h"
11 : #include "nsIMemoryReporter.h"
12 : #include "GLTypes.h"
13 :
14 : namespace mozilla {
15 : namespace gl {
16 :
17 : class GfxTexturesReporter final : public nsIMemoryReporter
18 : {
19 0 : ~GfxTexturesReporter() {}
20 :
21 : public:
22 : NS_DECL_ISUPPORTS
23 :
24 3 : GfxTexturesReporter()
25 3 : {
26 : #ifdef DEBUG
27 : // There must be only one instance of this class, due to |sAmount|
28 : // being static. Assert this.
29 : static bool hasRun = false;
30 3 : MOZ_ASSERT(!hasRun);
31 3 : hasRun = true;
32 : #endif
33 3 : }
34 :
35 : enum MemoryUse {
36 : // when memory being allocated is reported to a memory reporter
37 : MemoryAllocated,
38 : // when memory being freed is reported to a memory reporter
39 : MemoryFreed
40 : };
41 :
42 : // When memory is used/freed for tile textures, call this method to update
43 : // the value reported by this memory reporter.
44 : static void UpdateAmount(MemoryUse action, size_t amount);
45 :
46 6 : static void UpdateWasteAmount(size_t delta) {
47 6 : sTileWasteAmount += delta;
48 6 : }
49 :
50 0 : NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
51 : nsISupports* aData, bool aAnonymize) override
52 : {
53 0 : MOZ_COLLECT_REPORT(
54 : "gfx-tiles-waste", KIND_OTHER, UNITS_BYTES,
55 : int64_t(sTileWasteAmount),
56 0 : "Memory lost due to tiles extending past content boundaries");
57 :
58 0 : MOZ_COLLECT_REPORT(
59 : "gfx-textures", KIND_OTHER, UNITS_BYTES,
60 : int64_t(sAmount),
61 0 : "Memory used for storing GL textures.");
62 :
63 0 : MOZ_COLLECT_REPORT(
64 : "gfx-textures-peak", KIND_OTHER, UNITS_BYTES,
65 : int64_t(sPeakAmount),
66 0 : "Peak memory used for storing GL textures.");
67 :
68 0 : return NS_OK;
69 : }
70 :
71 : private:
72 : static Atomic<size_t> sAmount;
73 : static Atomic<size_t> sPeakAmount;
74 : // Count the amount of memory lost to tile waste
75 : static Atomic<size_t> sTileWasteAmount;
76 : };
77 :
78 : class GfxTextureWasteTracker {
79 : public:
80 9 : GfxTextureWasteTracker()
81 9 : : mBytes(0)
82 : {
83 9 : MOZ_COUNT_CTOR(GfxTextureWasteTracker);
84 9 : }
85 :
86 : void Update(int32_t aPixelArea, int32_t aBytesPerPixel) {
87 : GfxTexturesReporter::UpdateWasteAmount(-mBytes);
88 : mBytes = aPixelArea * aBytesPerPixel;
89 : GfxTexturesReporter::UpdateWasteAmount(mBytes);
90 : }
91 :
92 12 : ~GfxTextureWasteTracker() {
93 6 : GfxTexturesReporter::UpdateWasteAmount(-mBytes);
94 6 : MOZ_COUNT_DTOR(GfxTextureWasteTracker);
95 6 : }
96 : private:
97 : GfxTextureWasteTracker(const GfxTextureWasteTracker& aRef);
98 :
99 : int32_t mBytes;
100 : };
101 :
102 : } // namespace gl
103 : } // namespace mozilla
104 :
105 : #endif // GFXTEXTURESREPORTER_H_
|