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

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

Issue 1425443002: [tracing] Remove counter logic and just use address on glyph cache dumps (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | no next file » | 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> 17 #include <cctype>
18 18
19 //#define SPEW_PURGE_STATUS 19 //#define SPEW_PURGE_STATUS
20 20
21 namespace { 21 namespace {
22
23 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; 22 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache";
24
25 // Used to pass context to the sk_trace_dump_visitor.
26 struct SkGlyphCacheDumpContext {
27 int* counter;
28 SkTraceMemoryDump* dump;
29 };
30
31 } // namespace 23 } // namespace
32 24
33 // Returns the shared globals 25 // Returns the shared globals
34 SK_DECLARE_STATIC_ONCE_PTR(SkGlyphCache_Globals, globals); 26 SK_DECLARE_STATIC_ONCE_PTR(SkGlyphCache_Globals, globals);
35 static SkGlyphCache_Globals& get_globals() { 27 static SkGlyphCache_Globals& get_globals() {
36 return *globals.get([]{ return new SkGlyphCache_Globals; }); 28 return *globals.get([]{ return new SkGlyphCache_Globals; });
37 } 29 }
38 30
39 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
40 32
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 SkDebugf(" bytes [ %8zu %8zu ]\n", 418 SkDebugf(" bytes [ %8zu %8zu ]\n",
427 SkGraphics::GetFontCacheUsed(), SkGraphics::GetFontCacheLimit()); 419 SkGraphics::GetFontCacheUsed(), SkGraphics::GetFontCacheLimit());
428 SkDebugf(" count [ %8zu %8zu ]\n", 420 SkDebugf(" count [ %8zu %8zu ]\n",
429 SkGraphics::GetFontCacheCountUsed(), SkGraphics::GetFontCacheCountL imit()); 421 SkGraphics::GetFontCacheCountUsed(), SkGraphics::GetFontCacheCountL imit());
430 422
431 int counter = 0; 423 int counter = 0;
432 SkGlyphCache::VisitAll(dump_visitor, &counter); 424 SkGlyphCache::VisitAll(dump_visitor, &counter);
433 } 425 }
434 426
435 static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) { 427 static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) {
436 SkGlyphCacheDumpContext* dumpContext = static_cast<SkGlyphCacheDumpContext*> (context); 428 SkTraceMemoryDump* dump = static_cast<SkTraceMemoryDump*>(context);
437 SkTraceMemoryDump* dump = dumpContext->dump;
438 int* counter = dumpContext->counter;
439 int index = *counter;
440 *counter += 1;
441 429
442 const SkTypeface* face = cache.getScalerContext()->getTypeface(); 430 const SkTypeface* face = cache.getScalerContext()->getTypeface();
443 const SkScalerContextRec& rec = cache.getScalerContext()->getRec(); 431 const SkScalerContextRec& rec = cache.getScalerContext()->getRec();
444 432
445 SkString fontName; 433 SkString fontName;
446 face->getFamilyName(&fontName); 434 face->getFamilyName(&fontName);
447 // Replace all special characters with '_'. 435 // Replace all special characters with '_'.
448 for (size_t index = 0; index < fontName.size(); ++index) { 436 for (size_t index = 0; index < fontName.size(); ++index) {
449 if (!std::isalnum(fontName[index])) { 437 if (!std::isalnum(fontName[index])) {
450 fontName[index] = '_'; 438 fontName[index] = '_';
451 } 439 }
452 } 440 }
453 441
454 SkString dumpName = SkStringPrintf("%s/%s_%d/index_%d", 442 SkString dumpName = SkStringPrintf("%s/%s_%d/%p",
455 gGlyphCacheDumpName, fontName.c_str(), re c.fFontID, index); 443 gGlyphCacheDumpName, fontName.c_str(), re c.fFontID, &cache);
456 444
457 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUse d()); 445 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUse d());
458 dump->dumpNumericValue(dumpName.c_str(), "glyph_count", "objects", cache.cou ntCachedGlyphs()); 446 dump->dumpNumericValue(dumpName.c_str(), "glyph_count", "objects", cache.cou ntCachedGlyphs());
459 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr); 447 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
460 } 448 }
461 449
462 void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { 450 void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
463 dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::Get FontCacheUsed()); 451 dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::Get FontCacheUsed());
464 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes", 452 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes",
465 SkGraphics::GetFontCacheLimit()); 453 SkGraphics::GetFontCacheLimit());
466 dump->dumpNumericValue(gGlyphCacheDumpName, "glyph_count", "objects", 454 dump->dumpNumericValue(gGlyphCacheDumpName, "glyph_count", "objects",
467 SkGraphics::GetFontCacheCountUsed()); 455 SkGraphics::GetFontCacheCountUsed());
468 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_glyph_count", "objects", 456 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_glyph_count", "objects",
469 SkGraphics::GetFontCacheCountLimit()); 457 SkGraphics::GetFontCacheCountLimit());
470 458
471 if (dump->getRequestedDetails() == SkTraceMemoryDump::kLight_LevelOfDetail) { 459 if (dump->getRequestedDetails() == SkTraceMemoryDump::kLight_LevelOfDetail) {
472 dump->setMemoryBacking(gGlyphCacheDumpName, "malloc", nullptr); 460 dump->setMemoryBacking(gGlyphCacheDumpName, "malloc", nullptr);
473 return; 461 return;
474 } 462 }
475 463
476 int counter = 0; 464 SkGlyphCache::VisitAll(sk_trace_dump_visitor, dump);
477 SkGlyphCacheDumpContext context = { &counter, dump };
478 SkGlyphCache::VisitAll(sk_trace_dump_visitor, &context);
479 } 465 }
480 466
481 void SkGlyphCache::VisitAll(Visitor visitor, void* context) { 467 void SkGlyphCache::VisitAll(Visitor visitor, void* context) {
482 SkGlyphCache_Globals& globals = get_globals(); 468 SkGlyphCache_Globals& globals = get_globals();
483 AutoAcquire ac(globals.fLock); 469 AutoAcquire ac(globals.fLock);
484 SkGlyphCache* cache; 470 SkGlyphCache* cache;
485 471
486 globals.validate(); 472 globals.validate();
487 473
488 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) { 474 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } 646 }
661 647
662 void SkGraphics::PurgeFontCache() { 648 void SkGraphics::PurgeFontCache() {
663 get_globals().purgeAll(); 649 get_globals().purgeAll();
664 SkTypefaceCache::PurgeAll(); 650 SkTypefaceCache::PurgeAll();
665 } 651 }
666 652
667 // TODO(herb): clean up TLS apis. 653 // TODO(herb): clean up TLS apis.
668 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 654 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
669 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 655 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698