зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1639385 - add memory reporter for NativeFontResource data. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D76259
This commit is contained in:
Родитель
5884693b75
Коммит
c452d01a0d
|
@ -1040,7 +1040,13 @@ class NativeFontResource
|
|||
uint32_t aIndex, const uint8_t* aInstanceData,
|
||||
uint32_t aInstanceDataLength) = 0;
|
||||
|
||||
virtual ~NativeFontResource() = default;
|
||||
NativeFontResource(size_t aDataLength);
|
||||
virtual ~NativeFontResource();
|
||||
|
||||
static void RegisterMemoryReporter();
|
||||
|
||||
private:
|
||||
size_t mDataLength;
|
||||
};
|
||||
|
||||
class DrawTargetCapture;
|
||||
|
|
|
@ -236,6 +236,8 @@ mozilla::gfx::Config* Factory::sConfig = nullptr;
|
|||
void Factory::Init(const Config& aConfig) {
|
||||
MOZ_ASSERT(!sConfig);
|
||||
sConfig = new Config(aConfig);
|
||||
|
||||
NativeFontResource::RegisterMemoryReporter();
|
||||
}
|
||||
|
||||
void Factory::ShutDown() {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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(new NativeFontResourceDataMemoryReporter);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
|
@ -238,7 +238,8 @@ already_AddRefed<NativeFontResourceDWrite> NativeFontResourceDWrite::Create(
|
|||
}
|
||||
|
||||
RefPtr<NativeFontResourceDWrite> fontResource = new NativeFontResourceDWrite(
|
||||
factory, fontFile.forget(), ffsRef.forget(), faceType, numberOfFaces);
|
||||
factory, fontFile.forget(), ffsRef.forget(), faceType, numberOfFaces,
|
||||
aDataLength);
|
||||
return fontResource.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,10 @@ class NativeFontResourceDWrite final : public NativeFontResource {
|
|||
NativeFontResourceDWrite(
|
||||
IDWriteFactory* aFactory, already_AddRefed<IDWriteFontFile> aFontFile,
|
||||
already_AddRefed<IDWriteFontFileStream> aFontFileStream,
|
||||
DWRITE_FONT_FACE_TYPE aFaceType, uint32_t aNumberOfFaces)
|
||||
: mFactory(aFactory),
|
||||
DWRITE_FONT_FACE_TYPE aFaceType, uint32_t aNumberOfFaces,
|
||||
size_t aDataLength)
|
||||
: NativeFontResource(aDataLength),
|
||||
mFactory(aFactory),
|
||||
mFontFile(aFontFile),
|
||||
mFontFileStream(aFontFileStream),
|
||||
mFaceType(aFaceType),
|
||||
|
|
|
@ -13,7 +13,8 @@ namespace mozilla::gfx {
|
|||
NativeFontResourceFreeType::NativeFontResourceFreeType(
|
||||
UniquePtr<uint8_t[]>&& aFontData, uint32_t aDataLength,
|
||||
FT_Library aFTLibrary)
|
||||
: mFontData(std::move(aFontData)),
|
||||
: NativeFontResource(aDataLength),
|
||||
mFontData(std::move(aFontData)),
|
||||
mDataLength(aDataLength),
|
||||
mFTLibrary(aFTLibrary) {}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ already_AddRefed<NativeFontResourceGDI> NativeFontResourceGDI::Create(
|
|||
}
|
||||
|
||||
RefPtr<NativeFontResourceGDI> fontResouce =
|
||||
new NativeFontResourceGDI(fontResourceHandle);
|
||||
new NativeFontResourceGDI(fontResourceHandle, aDataLength);
|
||||
|
||||
return fontResouce.forget();
|
||||
}
|
||||
|
|
|
@ -38,8 +38,9 @@ class NativeFontResourceGDI final : public NativeFontResource {
|
|||
uint32_t aInstanceDataLength) final;
|
||||
|
||||
private:
|
||||
explicit NativeFontResourceGDI(HANDLE aFontResourceHandle)
|
||||
: mFontResourceHandle(aFontResourceHandle) {}
|
||||
explicit NativeFontResourceGDI(HANDLE aFontResourceHandle, size_t aDataLength)
|
||||
: NativeFontResource(aDataLength),
|
||||
mFontResourceHandle(aFontResourceHandle) {}
|
||||
|
||||
HANDLE mFontResourceHandle;
|
||||
};
|
||||
|
|
|
@ -46,7 +46,7 @@ already_AddRefed<NativeFontResourceMac> NativeFontResourceMac::Create(
|
|||
|
||||
// passes ownership of fontRef to the NativeFontResourceMac instance
|
||||
RefPtr<NativeFontResourceMac> fontResource =
|
||||
new NativeFontResourceMac(fontRef);
|
||||
new NativeFontResourceMac(fontRef, aDataLength);
|
||||
|
||||
return fontResource.forget();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ class NativeFontResourceMac final : public NativeFontResource {
|
|||
~NativeFontResourceMac() { CFRelease(mFontRef); }
|
||||
|
||||
private:
|
||||
explicit NativeFontResourceMac(CGFontRef aFontRef) : mFontRef(aFontRef) {}
|
||||
explicit NativeFontResourceMac(CGFontRef aFontRef, size_t aDataLength)
|
||||
: NativeFontResource(aDataLength), mFontRef(aFontRef) {}
|
||||
|
||||
CGFontRef mFontRef;
|
||||
};
|
||||
|
|
|
@ -189,6 +189,7 @@ UNIFIED_SOURCES += [
|
|||
'ImageScaling.cpp',
|
||||
'JobScheduler.cpp',
|
||||
'Matrix.cpp',
|
||||
'NativeFontResource.cpp',
|
||||
'Path.cpp',
|
||||
'PathCairo.cpp',
|
||||
'PathCapture.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче