Do not embed glyph image data in SkGlyphCache.
authorHerb Derby <herb@google.com>
Tue, 24 Jan 2017 16:01:59 +0000 (11:01 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 24 Jan 2017 16:45:59 +0000 (16:45 +0000)
Instead of allocating memory for glyph images eagerly by embedding
the memory in the glyph cache, allocate memory dynamically on need.

TBR=bungeman@google.com

BUG=chromium:684366

Change-Id: If32bbc4d2608c976b93868feb519dcfa1212ce59
Reviewed-on: https://skia-review.googlesource.com/7433
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>

src/core/SkGlyphCache.h

index ab1c9ba89f08c90df6a09a9a70e0a19bacd9803f..4140bc5cd81c0cfa7e5399d074f01f9c34903207 100644 (file)
@@ -237,18 +237,16 @@ private:
     SkTHashTable<SkGlyph, SkPackedGlyphID, SkGlyph::HashTraits> fGlyphMap;
 
     // so we don't grow our arrays a lot
-    static constexpr size_t       kMinGlyphCount = 16;
-    static constexpr size_t       kMinGlyphImageSize = (16*2);
-    static constexpr size_t       kMinAllocAmount
-        = ((sizeof(SkGlyph) + kMinGlyphImageSize) * kMinGlyphCount);
+    static constexpr size_t kMinGlyphCount = 8;
+    static constexpr size_t kMinGlyphImageSize = 16 /* height */ * 8 /* width */;
+    static constexpr size_t kMinAllocAmount = kMinGlyphImageSize * kMinGlyphCount;
 
-    char                   storage[kMinAllocAmount];
-    SkArenaAlloc           fAlloc {storage};
+    SkArenaAlloc            fAlloc {kMinAllocAmount};
 
     std::unique_ptr<CharGlyphRec[]> fPackedUnicharIDToPackedGlyphID;
 
     // used to track (approx) how much ram is tied-up in this cache
-    size_t                 fMemoryUsed;
+    size_t                  fMemoryUsed;
 };
 
 class SkAutoGlyphCache : public std::unique_ptr<SkGlyphCache, SkGlyphCache::AttachCacheFunctor> {