Bug 1641886 [wpt PR 23851] - Support interpolating contain-intrinsic-size, a=testonly
[gecko.git] / gfx / 2d / NativeFontResource.cpp
blob1c6a9fe0af164c3766f15d4a044cd4f707e7493e
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 #include "2D.h"
8 #include "nsIMemoryReporter.h"
10 namespace mozilla {
11 namespace gfx {
13 static Atomic<size_t> gTotalNativeFontResourceData;
15 NativeFontResource::NativeFontResource(size_t aDataLength)
16 : mDataLength(aDataLength) {
17 gTotalNativeFontResourceData += mDataLength;
20 NativeFontResource::~NativeFontResource() {
21 gTotalNativeFontResourceData -= mDataLength;
24 // Memory reporter that estimates the amount of memory that is currently being
25 // allocated internally by various native font APIs for native font resources.
26 // The sanest way to do this, given that NativeFontResources can be created and
27 // used in many different threads or processes and given that such memory is
28 // implicitly allocated by the native APIs, is just to maintain a global atomic
29 // counter and report this value as such.
30 class NativeFontResourceDataMemoryReporter final : public nsIMemoryReporter {
31 ~NativeFontResourceDataMemoryReporter() = default;
33 public:
34 NS_DECL_ISUPPORTS
36 NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
37 nsISupports* aData, bool aAnonymize) override {
38 MOZ_COLLECT_REPORT("explicit/gfx/native-font-resource-data", KIND_HEAP,
39 UNITS_BYTES, gTotalNativeFontResourceData,
40 "Total memory used by native font API resource data.");
41 return NS_OK;
45 NS_IMPL_ISUPPORTS(NativeFontResourceDataMemoryReporter, nsIMemoryReporter)
47 void NativeFontResource::RegisterMemoryReporter() {
48 RegisterStrongMemoryReporter(new NativeFontResourceDataMemoryReporter);
51 } // namespace gfx
52 } // namespace mozilla