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 found
in the LICENSE file. | 4 * Use of this source code is governed by a BSD-style license that can be found
in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #ifndef SkGlyphCache_DEFINED | 7 #ifndef SkGlyphCache_DEFINED |
8 #define SkGlyphCache_DEFINED | 8 #define SkGlyphCache_DEFINED |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkChunkAlloc.h" | 11 #include "SkChunkAlloc.h" |
12 #include "SkDescriptor.h" | 12 #include "SkDescriptor.h" |
13 #include "SkGlyph.h" | 13 #include "SkGlyph.h" |
14 #include "SkTHash.h" | 14 #include "SkTHash.h" |
15 #include "SkScalerContext.h" | 15 #include "SkScalerContext.h" |
16 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
17 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
18 | 18 |
19 class SkPaint; | 19 class SkPaint; |
| 20 class SkTraceMemoryDump; |
20 | 21 |
21 class SkGlyphCache_Globals; | 22 class SkGlyphCache_Globals; |
22 | 23 |
23 /** \class SkGlyphCache | 24 /** \class SkGlyphCache |
24 | 25 |
25 This class represents a strike: a specific combination of typeface, size, ma
trix, etc., and | 26 This class represents a strike: a specific combination of typeface, size, ma
trix, etc., and |
26 holds the glyphs for that strike. Calling any of the getUnichar.../getGlyphI
D... methods will | 27 holds the glyphs for that strike. Calling any of the getUnichar.../getGlyphI
D... methods will |
27 return the requested glyph, either instantly if it is already cached, or by
first generating | 28 return the requested glyph, either instantly if it is already cached, or by
first generating |
28 it and then adding it to the strike. | 29 it and then adding it to the strike. |
29 | 30 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const SkDescriptor& getDescriptor() const { return *fDesc; } | 91 const SkDescriptor& getDescriptor() const { return *fDesc; } |
91 | 92 |
92 SkMask::Format getMaskFormat() const { | 93 SkMask::Format getMaskFormat() const { |
93 return fScalerContext->getMaskFormat(); | 94 return fScalerContext->getMaskFormat(); |
94 } | 95 } |
95 | 96 |
96 bool isSubpixel() const { | 97 bool isSubpixel() const { |
97 return fScalerContext->isSubpixel(); | 98 return fScalerContext->isSubpixel(); |
98 } | 99 } |
99 | 100 |
| 101 /** Return the approx RAM usage for this cache. */ |
| 102 size_t getMemoryUsed() const { return fMemoryUsed; } |
| 103 |
100 void dump() const; | 104 void dump() const; |
101 | 105 |
102 /* AuxProc/Data allow a client to associate data with this cache entry. Mul
tiple clients can | 106 /** AuxProc/Data allow a client to associate data with this cache entry. Mul
tiple clients can |
103 use this, as their data is keyed with a function pointer. In addition to
serving as a | 107 use this, as their data is keyed with a function pointer. In addition to
serving as a |
104 key, the function pointer is called with the data when the glyphcache ob
ject is deleted, | 108 key, the function pointer is called with the data when the glyphcache ob
ject is deleted, |
105 so the client can cleanup their data as well. | 109 so the client can cleanup their data as well. |
106 NOTE: the auxProc must not try to access this glyphcache in any way, sin
ce it may be in | 110 NOTE: the auxProc must not try to access this glyphcache in any way, sin
ce it may be in |
107 the process of being deleted. | 111 the process of being deleted. |
108 */ | 112 */ |
109 | 113 |
110 //! If the proc is found, return true and set *dataPtr to its data | 114 //! If the proc is found, return true and set *dataPtr to its data |
111 bool getAuxProcData(void (*auxProc)(void*), void** dataPtr) const; | 115 bool getAuxProcData(void (*auxProc)(void*), void** dataPtr) const; |
112 | 116 |
(...skipping 21 matching lines...) Expand all Loading... |
134 descriptor, a different strike will be generated. This is fine. It does
mean we can have | 138 descriptor, a different strike will be generated. This is fine. It does
mean we can have |
135 more than 1 strike for the same descriptor, but that will eventually get
purged, and the | 139 more than 1 strike for the same descriptor, but that will eventually get
purged, and the |
136 win is that different thread will never block each other while a strike
is being used. | 140 win is that different thread will never block each other while a strike
is being used. |
137 */ | 141 */ |
138 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* d
esc) { | 142 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* d
esc) { |
139 return VisitCache(typeface, desc, DetachProc, NULL); | 143 return VisitCache(typeface, desc, DetachProc, NULL); |
140 } | 144 } |
141 | 145 |
142 static void Dump(); | 146 static void Dump(); |
143 | 147 |
| 148 /** Dump memory usage statistics of all the attaches caches in the process u
sing the |
| 149 SkTraceMemoryDump interface. |
| 150 */ |
| 151 static void DumpMemoryStatistics(SkTraceMemoryDump* dump); |
| 152 |
144 typedef void (*Visitor)(const SkGlyphCache&, void* context); | 153 typedef void (*Visitor)(const SkGlyphCache&, void* context); |
145 static void VisitAll(Visitor, void* context); | 154 static void VisitAll(Visitor, void* context); |
146 | 155 |
147 #ifdef SK_DEBUG | 156 #ifdef SK_DEBUG |
148 void validate() const; | 157 void validate() const; |
149 #else | 158 #else |
150 void validate() const {} | 159 void validate() const {} |
151 #endif | 160 #endif |
152 | 161 |
153 class AutoValidate : SkNoncopyable { | 162 class AutoValidate : SkNoncopyable { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 const SkMatrix* matrix) { | 315 const SkMatrix* matrix) { |
307 fCache = paint.detachCache(surfaceProps, matrix, true); | 316 fCache = paint.detachCache(surfaceProps, matrix, true); |
308 } | 317 } |
309 | 318 |
310 private: | 319 private: |
311 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 320 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
312 }; | 321 }; |
313 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 322 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
314 | 323 |
315 #endif | 324 #endif |
OLD | NEW |