From ce6621e5620fd8972248c7780f0d734667f3c0d1 Mon Sep 17 00:00:00 2001 From: Ted Campbell Date: Thu, 5 Apr 2018 16:27:07 -0400 Subject: [PATCH] Bug 1451878 - Add memory reporting for gfxDWriteFontFileLoader. r=lsalzman MozReview-Commit-ID: 9EBXTiNfRrA --- gfx/thebes/gfxDWriteCommon.cpp | 29 +++++++++++++++++++++++++++-- gfx/thebes/gfxDWriteCommon.h | 9 +++------ gfx/thebes/gfxDWriteFontList.cpp | 6 ++++++ gfx/thebes/gfxPlatformFontList.cpp | 8 ++++++++ gfx/thebes/gfxPlatformFontList.h | 1 + 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/gfx/thebes/gfxDWriteCommon.cpp b/gfx/thebes/gfxDWriteCommon.cpp index 76d52538f641..d5fd4157060f 100644 --- a/gfx/thebes/gfxDWriteCommon.cpp +++ b/gfx/thebes/gfxDWriteCommon.cpp @@ -10,8 +10,10 @@ #include "mozilla/Atomics.h" #include "mozilla/gfx/Logging.h" +class gfxDWriteFontFileStream; + static mozilla::Atomic sNextFontFileKey; -static std::unordered_map sFontFileStreams; +static std::unordered_map 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 mData; nsAutoRefCnt mRefCnt; @@ -172,7 +182,7 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(const uint8_t* aFontData, } uint64_t fontFileKey = sNextFontFileKey++; - RefPtr ffsRef = + RefPtr 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; +} diff --git a/gfx/thebes/gfxDWriteCommon.h b/gfx/thebes/gfxDWriteCommon.h index 5bf6a60e0aae..1089715ca9ed 100644 --- a/gfx/thebes/gfxDWriteCommon.h +++ b/gfx/thebes/gfxDWriteCommon.h @@ -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 *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; }; diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index 52e6822278a6..18a57463185a 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -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(this) == gfxPlatformFontList::PlatformFontList()); + gfxDWriteFontFileLoader* loader = + static_cast(gfxDWriteFontFileLoader::Instance()); + aSizes->mLoaderSize += loader->SizeOfIncludingThis(aMallocSizeOf); + aSizes->mFontListSize += SizeOfFontFamilyTableExcludingThis(mFontSubstitutes, aMallocSizeOf); diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 27fc5e9689e5..4dde8d68146c 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -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; } diff --git a/gfx/thebes/gfxPlatformFontList.h b/gfx/thebes/gfxPlatformFontList.h index 3626827e37eb..8d099f1bd8c1 100644 --- a/gfx/thebes/gfxPlatformFontList.h +++ b/gfx/thebes/gfxPlatformFontList.h @@ -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;