Bug 1451878 - Add memory reporting for gfxDWriteFontFileLoader. r=lsalzman

MozReview-Commit-ID: 9EBXTiNfRrA
This commit is contained in:
Ted Campbell 2018-04-05 16:27:07 -04:00
Родитель ded1566056
Коммит ce6621e562
5 изменённых файлов: 45 добавлений и 8 удалений

Просмотреть файл

@ -10,8 +10,10 @@
#include "mozilla/Atomics.h"
#include "mozilla/gfx/Logging.h"
class gfxDWriteFontFileStream;
static mozilla::Atomic<uint64_t> sNextFontFileKey;
static std::unordered_map<uint64_t, IDWriteFontFileStream*> sFontFileStreams;
static std::unordered_map<uint64_t, gfxDWriteFontFileStream*> sFontFileStreams;
IDWriteFontFileLoader* gfxDWriteFontFileLoader::mInstance = nullptr;
@ -77,6 +79,14 @@ public:
virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
return mData.ShallowSizeOfExcludingThis(mallocSizeOf);
}
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
}
private:
FallibleTArray<uint8_t> mData;
nsAutoRefCnt mRefCnt;
@ -172,7 +182,7 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(const uint8_t* aFontData,
}
uint64_t fontFileKey = sNextFontFileKey++;
RefPtr<IDWriteFontFileStream> ffsRef =
RefPtr<gfxDWriteFontFileStream> ffsRef =
new gfxDWriteFontFileStream(aFontData, aLength, fontFileKey);
sFontFileStreams[fontFileKey] = ffsRef;
@ -188,3 +198,18 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(const uint8_t* aFontData,
return S_OK;
}
size_t
gfxDWriteFontFileLoader::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t sizes = mallocSizeOf(this);
// We are a singleton type that is effective owner of sFontFileStreams.
MOZ_ASSERT(this == mInstance);
for (const auto& entry : sFontFileStreams) {
gfxDWriteFontFileStream* fileStream = entry.second;
sizes += fileStream->SizeOfIncludingThis(mallocSizeOf);
}
return sizes;
}

Просмотреть файл

@ -7,6 +7,7 @@
#define GFX_DWRITECOMMON_H
// Mozilla includes
#include "mozilla/MemoryReporting.h"
#include "nscore.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
@ -73,12 +74,6 @@ FontStretchFromDWriteStretch(DWRITE_FONT_STRETCH aStretch)
}
}
struct ffReferenceKey
{
FallibleTArray<uint8_t> *mArray;
nsID mGUID;
};
class gfxDWriteFontFileLoader : public IDWriteFontFileLoader
{
public:
@ -149,6 +144,8 @@ public:
IDWriteFontFile** aFontFile,
IDWriteFontFileStream** aFontFileStream);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
private:
static IDWriteFontFileLoader* mInstance;
};

Просмотреть файл

@ -1450,6 +1450,12 @@ gfxDWriteFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
{
gfxPlatformFontList::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
// We are a singleton, so include the font loader singleton's memory.
MOZ_ASSERT(static_cast<const gfxPlatformFontList*>(this) == gfxPlatformFontList::PlatformFontList());
gfxDWriteFontFileLoader* loader =
static_cast<gfxDWriteFontFileLoader*>(gfxDWriteFontFileLoader::Instance());
aSizes->mLoaderSize += loader->SizeOfIncludingThis(aMallocSizeOf);
aSizes->mFontListSize +=
SizeOfFontFamilyTableExcludingThis(mFontSubstitutes, aMallocSizeOf);

Просмотреть файл

@ -161,6 +161,7 @@ gfxPlatformFontList::MemoryReporter::CollectReports(
sizes.mFontListSize = 0;
sizes.mFontTableCacheSize = 0;
sizes.mCharMapsSize = 0;
sizes.mLoaderSize = 0;
gfxPlatformFontList::PlatformFontList()->AddSizeOfIncludingThis(&FontListMallocSizeOf,
&sizes);
@ -182,6 +183,13 @@ gfxPlatformFontList::MemoryReporter::CollectReports(
"Memory used for cached font metrics and layout tables.");
}
if (sizes.mLoaderSize) {
MOZ_COLLECT_REPORT(
"explicit/gfx/font-loader", KIND_HEAP, UNITS_BYTES,
sizes.mLoaderSize,
"Memory used for (platform-specific) font loader.");
}
return NS_OK;
}

Просмотреть файл

@ -87,6 +87,7 @@ struct FontListSizes {
// including the font table cache and the cmaps
uint32_t mFontTableCacheSize; // memory used for the gfxFontEntry table caches
uint32_t mCharMapsSize; // memory used for cmap coverage info
uint32_t mLoaderSize; // memory used for (platform-specific) loader
};
class gfxUserFontSet;