Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/gl/GfxTexturesReporter.h
Line
Count
Source (jump to first uncovered line)
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
    GfxTexturesReporter()
25
0
    {
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
        MOZ_ASSERT(!hasRun);
31
        hasRun = true;
32
#endif
33
    }
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
    static void UpdateWasteAmount(size_t delta) {
47
      sTileWasteAmount += delta;
48
    }
49
50
    NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
51
                              nsISupports* aData, bool aAnonymize) override
52
0
    {
53
0
        MOZ_COLLECT_REPORT(
54
0
            "gfx-tiles-waste", KIND_OTHER, UNITS_BYTES,
55
0
            int64_t(sTileWasteAmount),
56
0
            "Memory lost due to tiles extending past content boundaries");
57
0
58
0
        MOZ_COLLECT_REPORT(
59
0
            "gfx-textures", KIND_OTHER, UNITS_BYTES,
60
0
            int64_t(sAmount),
61
0
            "Memory used for storing GL textures.");
62
0
63
0
        MOZ_COLLECT_REPORT(
64
0
            "gfx-textures-peak", KIND_OTHER, UNITS_BYTES,
65
0
            int64_t(sPeakAmount),
66
0
            "Peak memory used for storing GL textures.");
67
0
68
0
        return NS_OK;
69
0
    }
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
  GfxTextureWasteTracker()
81
    : mBytes(0)
82
  {
83
    MOZ_COUNT_CTOR(GfxTextureWasteTracker);
84
  }
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
  ~GfxTextureWasteTracker() {
93
    GfxTexturesReporter::UpdateWasteAmount(-mBytes);
94
    MOZ_COUNT_DTOR(GfxTextureWasteTracker);
95
  }
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_