Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/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
    ~GfxTexturesReporter() {}
20
21
public:
22
    NS_DECL_ISUPPORTS
23
24
    GfxTexturesReporter()
25
    {
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
0
    static void UpdateWasteAmount(size_t delta) {
47
0
      sTileWasteAmount += delta;
48
0
    }
49
50
    NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
51
                              nsISupports* aData, bool aAnonymize) override
52
    {
53
        MOZ_COLLECT_REPORT(
54
            "gfx-tiles-waste", KIND_OTHER, UNITS_BYTES,
55
            int64_t(sTileWasteAmount),
56
            "Memory lost due to tiles extending past content boundaries");
57
58
        MOZ_COLLECT_REPORT(
59
            "gfx-textures", KIND_OTHER, UNITS_BYTES,
60
            int64_t(sAmount),
61
            "Memory used for storing GL textures.");
62
63
        MOZ_COLLECT_REPORT(
64
            "gfx-textures-peak", KIND_OTHER, UNITS_BYTES,
65
            int64_t(sPeakAmount),
66
            "Peak memory used for storing GL textures.");
67
68
        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
  GfxTextureWasteTracker()
81
    : mBytes(0)
82
0
  {
83
0
    MOZ_COUNT_CTOR(GfxTextureWasteTracker);
84
0
  }
85
86
0
  void Update(int32_t aPixelArea, int32_t aBytesPerPixel) {
87
0
    GfxTexturesReporter::UpdateWasteAmount(-mBytes);
88
0
    mBytes = aPixelArea * aBytesPerPixel;
89
0
    GfxTexturesReporter::UpdateWasteAmount(mBytes);
90
0
  }
91
92
0
  ~GfxTextureWasteTracker() {
93
0
    GfxTexturesReporter::UpdateWasteAmount(-mBytes);
94
0
    MOZ_COUNT_DTOR(GfxTextureWasteTracker);
95
0
  }
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_