OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGlyphCache.h" | 8 #include "SkGlyphCache.h" |
9 #include "SkGlyphCache_Globals.h" | 9 #include "SkGlyphCache_Globals.h" |
10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
11 #include "SkOncePtr.h" | 11 #include "SkOncePtr.h" |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
14 #include "SkTraceMemoryDump.h" | 14 #include "SkTraceMemoryDump.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 | 16 |
17 #include <string> | |
18 | |
17 //#define SPEW_PURGE_STATUS | 19 //#define SPEW_PURGE_STATUS |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; | 23 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; |
22 | 24 |
23 // Used to pass context to the sk_trace_dump_visitor. | 25 // Used to pass context to the sk_trace_dump_visitor. |
24 struct SkGlyphCacheDumpContext { | 26 struct SkGlyphCacheDumpContext { |
25 int* counter; | 27 int* counter; |
26 SkTraceMemoryDump* dump; | 28 SkTraceMemoryDump* dump; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 } | 422 } |
421 | 423 |
422 static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) { | 424 static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) { |
423 SkGlyphCacheDumpContext* dumpContext = static_cast<SkGlyphCacheDumpContext*> (context); | 425 SkGlyphCacheDumpContext* dumpContext = static_cast<SkGlyphCacheDumpContext*> (context); |
424 SkTraceMemoryDump* dump = dumpContext->dump; | 426 SkTraceMemoryDump* dump = dumpContext->dump; |
425 int* counter = dumpContext->counter; | 427 int* counter = dumpContext->counter; |
426 int index = *counter; | 428 int index = *counter; |
427 *counter += 1; | 429 *counter += 1; |
428 | 430 |
429 const SkTypeface* face = cache.getScalerContext()->getTypeface(); | 431 const SkTypeface* face = cache.getScalerContext()->getTypeface(); |
432 const SkScalerContextRec& rec = cache.getScalerContext()->getRec(); | |
433 | |
430 SkString fontName; | 434 SkString fontName; |
431 face->getFamilyName(&fontName); | 435 face->getFamilyName(&fontName); |
432 const SkScalerContextRec& rec = cache.getScalerContext()->getRec(); | 436 // Replace all special characters with '_'. |
437 for (size_t index = 0; index < fontName.size(); ++index) { | |
reed1
2015/09/23 13:21:29
What is the formal requirement for strings in your
ssid
2015/09/23 13:30:22
Ah yes. So the dump name is required to be seperat
| |
438 if (!std::isalnum(fontName[index])) { | |
439 fontName[index] = '_'; | |
440 } | |
441 } | |
433 | 442 |
434 SkString dumpName = SkStringPrintf("%s/%s_%3d/index_%d", | 443 SkString dumpName = SkStringPrintf("%s/%s_%d/index_%d", |
435 gGlyphCacheDumpName, fontName.c_str(), r ec.fFontID, index); | 444 gGlyphCacheDumpName, fontName.c_str(), re c.fFontID, index); |
436 | 445 |
437 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUse d()); | 446 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUse d()); |
438 dump->dumpNumericValue(dumpName.c_str(), "glyph_count", "objects", cache.cou ntCachedGlyphs()); | 447 dump->dumpNumericValue(dumpName.c_str(), "glyph_count", "objects", cache.cou ntCachedGlyphs()); |
439 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr); | 448 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr); |
440 } | 449 } |
441 | 450 |
442 void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { | 451 void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
443 if (!(dump->getRequestedDetails() & (SkTraceMemoryDump::kMemoryTotals | | 452 if (!(dump->getRequestedDetails() & (SkTraceMemoryDump::kMemoryTotals | |
444 SkTraceMemoryDump::kMallocDetails))) { | 453 SkTraceMemoryDump::kMallocDetails))) { |
445 return; | 454 return; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 } | 654 } |
646 | 655 |
647 void SkGraphics::PurgeFontCache() { | 656 void SkGraphics::PurgeFontCache() { |
648 get_globals().purgeAll(); | 657 get_globals().purgeAll(); |
649 SkTypefaceCache::PurgeAll(); | 658 SkTypefaceCache::PurgeAll(); |
650 } | 659 } |
651 | 660 |
652 // TODO(herb): clean up TLS apis. | 661 // TODO(herb): clean up TLS apis. |
653 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } | 662 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } |
654 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } | 663 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } |
OLD | NEW |