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"
17 class GfxTexturesReporter final
: public nsIMemoryReporter
{
18 ~GfxTexturesReporter() = default;
23 GfxTexturesReporter() {
25 // There must be only one instance of this class, due to |sAmount|
26 // being static. Assert this.
27 static bool hasRun
= false;
34 // when memory being allocated is reported to a memory reporter
36 // when memory being freed is reported to a memory reporter
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
{
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
,
54 "Memory used for storing GL textures.");
56 MOZ_COLLECT_REPORT("gfx-textures-peak", KIND_OTHER
, UNITS_BYTES
,
58 "Peak memory used for storing GL textures.");
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
{
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
);
88 GfxTextureWasteTracker(const GfxTextureWasteTracker
& aRef
);
94 } // namespace mozilla
96 #endif // GFXTEXTURESREPORTER_H_