The callsites now mostly use MakeAndAddRef (which just stuffs a new object into a RefPtr and calls `forget()` to yield an already_AddRefed). In cases where the callsite constructs the object earlier and retains a strong reference, they'll now use do_AddRef to explicitly generate a strong reference (as an already_AddRefed) to pass into RegisterStrongMemoryReporter. Differential Revision: https://phabricator.services.mozilla.com/D299042
52 lines
1.8 KiB
C++
52 lines
1.8 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "2D.h"
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
namespace mozilla {
|
|
namespace gfx {
|
|
|
|
static Atomic<size_t> gTotalNativeFontResourceData;
|
|
|
|
NativeFontResource::NativeFontResource(size_t aDataLength)
|
|
: mDataLength(aDataLength) {
|
|
gTotalNativeFontResourceData += mDataLength;
|
|
}
|
|
|
|
NativeFontResource::~NativeFontResource() {
|
|
gTotalNativeFontResourceData -= mDataLength;
|
|
}
|
|
|
|
// Memory reporter that estimates the amount of memory that is currently being
|
|
// allocated internally by various native font APIs for native font resources.
|
|
// The sanest way to do this, given that NativeFontResources can be created and
|
|
// used in many different threads or processes and given that such memory is
|
|
// implicitly allocated by the native APIs, is just to maintain a global atomic
|
|
// counter and report this value as such.
|
|
class NativeFontResourceDataMemoryReporter final : public nsIMemoryReporter {
|
|
~NativeFontResourceDataMemoryReporter() = default;
|
|
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
nsISupports* aData, bool aAnonymize) override {
|
|
MOZ_COLLECT_REPORT("explicit/gfx/native-font-resource-data", KIND_HEAP,
|
|
UNITS_BYTES, gTotalNativeFontResourceData,
|
|
"Total memory used by native font API resource data.");
|
|
return NS_OK;
|
|
}
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(NativeFontResourceDataMemoryReporter, nsIMemoryReporter)
|
|
|
|
void NativeFontResource::RegisterMemoryReporter() {
|
|
RegisterStrongMemoryReporter(
|
|
MakeAndAddRef<NativeFontResourceDataMemoryReporter>());
|
|
}
|
|
|
|
} // namespace gfx
|
|
} // namespace mozilla
|