Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: src/core/SkGlyphCache.cpp

Issue 1346993006: Strip font name of special characters before dumping (Closed) Base URL: https://chromium.googlesource.com/skia.git@resource
Patch Set: Nit. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkResourceCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cctype>
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
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) {
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 dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::Get FontCacheUsed()); 452 dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::Get FontCacheUsed());
444 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes", 453 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes",
445 SkGraphics::GetFontCacheLimit()); 454 SkGraphics::GetFontCacheLimit());
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 } 649 }
641 650
642 void SkGraphics::PurgeFontCache() { 651 void SkGraphics::PurgeFontCache() {
643 get_globals().purgeAll(); 652 get_globals().purgeAll();
644 SkTypefaceCache::PurgeAll(); 653 SkTypefaceCache::PurgeAll();
645 } 654 }
646 655
647 // TODO(herb): clean up TLS apis. 656 // TODO(herb): clean up TLS apis.
648 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 657 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
649 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 658 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698