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 "SkLazyPtr.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 //#define SPEW_PURGE_STATUS | 17 //#define SPEW_PURGE_STATUS |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 SkGlyphCache_Globals* create_globals() { return new SkGlyphCache_Globals; } | |
22 | |
23 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; | 21 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; |
24 | 22 |
25 // Used to pass context to the sk_trace_dump_visitor. | 23 // Used to pass context to the sk_trace_dump_visitor. |
26 struct SkGlyphCacheDumpContext { | 24 struct SkGlyphCacheDumpContext { |
27 int* counter; | 25 int* counter; |
28 SkTraceMemoryDump* dump; | 26 SkTraceMemoryDump* dump; |
29 }; | 27 }; |
30 | 28 |
31 } // namespace | 29 } // namespace |
32 | 30 |
33 SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals); | |
34 | |
35 // Returns the shared globals | 31 // Returns the shared globals |
| 32 SK_DECLARE_STATIC_ONCE_PTR(SkGlyphCache_Globals, globals); |
36 static SkGlyphCache_Globals& get_globals() { | 33 static SkGlyphCache_Globals& get_globals() { |
37 return *globals.get(); | 34 return *globals.get([]{ return new SkGlyphCache_Globals; }); |
38 } | 35 } |
39 | 36 |
40 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
41 | 38 |
42 // so we don't grow our arrays a lot | 39 // so we don't grow our arrays a lot |
43 #define kMinGlyphCount 16 | 40 #define kMinGlyphCount 16 |
44 #define kMinGlyphImageSize (16*2) | 41 #define kMinGlyphImageSize (16*2) |
45 #define kMinAllocAmount ((sizeof(SkGlyph) + kMinGlyphImageSize) * kMinGlyphC
ount) | 42 #define kMinAllocAmount ((sizeof(SkGlyph) + kMinGlyphImageSize) * kMinGlyphC
ount) |
46 | 43 |
47 SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc, SkSca
lerContext* ctx) | 44 SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc, SkSca
lerContext* ctx) |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 635 } |
639 | 636 |
640 void SkGraphics::PurgeFontCache() { | 637 void SkGraphics::PurgeFontCache() { |
641 get_globals().purgeAll(); | 638 get_globals().purgeAll(); |
642 SkTypefaceCache::PurgeAll(); | 639 SkTypefaceCache::PurgeAll(); |
643 } | 640 } |
644 | 641 |
645 // TODO(herb): clean up TLS apis. | 642 // TODO(herb): clean up TLS apis. |
646 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } | 643 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } |
647 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } | 644 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } |
OLD | NEW |