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