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" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 //! Add a proc/data pair to the glyphcache. proc should be non-null | 123 //! Add a proc/data pair to the glyphcache. proc should be non-null |
124 void setAuxProc(void (*auxProc)(void*), void* auxData); | 124 void setAuxProc(void (*auxProc)(void*), void* auxData); |
125 | 125 |
126 SkScalerContext* getScalerContext() const { return fScalerContext; } | 126 SkScalerContext* getScalerContext() const { return fScalerContext; } |
127 | 127 |
128 /** Find a matching cache entry, and call proc() with it. If none is found c
reate a new one. | 128 /** Find a matching cache entry, and call proc() with it. If none is found c
reate a new one. |
129 If the proc() returns true, detach the cache and return it, otherwise le
ave it and return | 129 If the proc() returns true, detach the cache and return it, otherwise le
ave it and return |
130 nullptr. | 130 nullptr. |
131 */ | 131 */ |
132 static SkGlyphCache* VisitCache(SkTypeface*, const SkScalerContextEffects&,
const SkDescriptor*, | 132 static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc, |
133 bool (*proc)(const SkGlyphCache*, void*), | 133 bool (*proc)(const SkGlyphCache*, void*), |
134 void* context); | 134 void* context); |
135 | 135 |
136 /** Given a strike that was returned by either VisitCache() or DetachCache()
add it back into | 136 /** Given a strike that was returned by either VisitCache() or DetachCache()
add it back into |
137 the global cache list (after which the caller should not reference it an
ymore. | 137 the global cache list (after which the caller should not reference it an
ymore. |
138 */ | 138 */ |
139 static void AttachCache(SkGlyphCache*); | 139 static void AttachCache(SkGlyphCache*); |
140 using AttachCacheFunctor = SkFunctionWrapper<void, SkGlyphCache, AttachCache
>; | 140 using AttachCacheFunctor = SkFunctionWrapper<void, SkGlyphCache, AttachCache
>; |
141 | 141 |
142 /** Detach a strike from the global cache matching the specified descriptor.
Once detached, | 142 /** Detach a strike from the global cache matching the specified descriptor.
Once detached, |
143 it can be queried/modified by the current thread, and when finished, be
reattached to the | 143 it can be queried/modified by the current thread, and when finished, be
reattached to the |
144 global cache with AttachCache(). While detached, if another request is m
ade with the same | 144 global cache with AttachCache(). While detached, if another request is m
ade with the same |
145 descriptor, a different strike will be generated. This is fine. It does
mean we can have | 145 descriptor, a different strike will be generated. This is fine. It does
mean we can have |
146 more than 1 strike for the same descriptor, but that will eventually get
purged, and the | 146 more than 1 strike for the same descriptor, but that will eventually get
purged, and the |
147 win is that different thread will never block each other while a strike
is being used. | 147 win is that different thread will never block each other while a strike
is being used. |
148 */ | 148 */ |
149 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkScalerContext
Effects& effects, | 149 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* d
esc) { |
150 const SkDescriptor* desc) { | 150 return VisitCache(typeface, desc, DetachProc, nullptr); |
151 return VisitCache(typeface, effects, desc, DetachProc, nullptr); | |
152 } | 151 } |
153 | 152 |
154 static void Dump(); | 153 static void Dump(); |
155 | 154 |
156 /** Dump memory usage statistics of all the attaches caches in the process u
sing the | 155 /** Dump memory usage statistics of all the attaches caches in the process u
sing the |
157 SkTraceMemoryDump interface. | 156 SkTraceMemoryDump interface. |
158 */ | 157 */ |
159 static void DumpMemoryStatistics(SkTraceMemoryDump* dump); | 158 static void DumpMemoryStatistics(SkTraceMemoryDump* dump); |
160 | 159 |
161 typedef void (*Visitor)(const SkGlyphCache&, void* context); | 160 typedef void (*Visitor)(const SkGlyphCache&, void* context); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 271 |
273 AuxProcRec* fAuxProcList; | 272 AuxProcRec* fAuxProcList; |
274 }; | 273 }; |
275 | 274 |
276 class SkAutoGlyphCache : public std::unique_ptr<SkGlyphCache, SkGlyphCache::Atta
chCacheFunctor> { | 275 class SkAutoGlyphCache : public std::unique_ptr<SkGlyphCache, SkGlyphCache::Atta
chCacheFunctor> { |
277 public: | 276 public: |
278 /** deprecated: use get() */ | 277 /** deprecated: use get() */ |
279 SkGlyphCache* getCache() const { return this->get(); } | 278 SkGlyphCache* getCache() const { return this->get(); } |
280 | 279 |
281 SkAutoGlyphCache(SkGlyphCache* cache) : INHERITED(cache) {} | 280 SkAutoGlyphCache(SkGlyphCache* cache) : INHERITED(cache) {} |
282 SkAutoGlyphCache(SkTypeface* typeface, const SkScalerContextEffects& effects
, | 281 SkAutoGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) |
283 const SkDescriptor* desc) | 282 : INHERITED(SkGlyphCache::DetachCache(typeface, desc)) |
284 : INHERITED(SkGlyphCache::DetachCache(typeface, effects, desc)) | |
285 {} | 283 {} |
286 /** deprecated: always enables fake gamma */ | 284 /** deprecated: always enables fake gamma */ |
287 SkAutoGlyphCache(const SkPaint& paint, | 285 SkAutoGlyphCache(const SkPaint& paint, |
288 const SkSurfaceProps* surfaceProps, | 286 const SkSurfaceProps* surfaceProps, |
289 const SkMatrix* matrix) | 287 const SkMatrix* matrix) |
290 : INHERITED(paint.detachCache(surfaceProps, | 288 : INHERITED(paint.detachCache(surfaceProps, |
291 SkPaint::kFakeGammaAndBoostContrast_Scaler
ContextFlags, | 289 SkPaint::kFakeGammaAndBoostContrast_Scaler
ContextFlags, |
292 matrix)) | 290 matrix)) |
293 {} | 291 {} |
294 SkAutoGlyphCache(const SkPaint& paint, | 292 SkAutoGlyphCache(const SkPaint& paint, |
(...skipping 11 matching lines...) Expand all Loading... |
306 SkAutoGlyphCacheNoGamma(const SkPaint& paint, | 304 SkAutoGlyphCacheNoGamma(const SkPaint& paint, |
307 const SkSurfaceProps* surfaceProps, | 305 const SkSurfaceProps* surfaceProps, |
308 const SkMatrix* matrix) | 306 const SkMatrix* matrix) |
309 : SkAutoGlyphCache(paint, surfaceProps, SkPaint::kNone_ScalerContextFlag
s, matrix) | 307 : SkAutoGlyphCache(paint, surfaceProps, SkPaint::kNone_ScalerContextFlag
s, matrix) |
310 {} | 308 {} |
311 }; | 309 }; |
312 #define SkAutoGlyphCache(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCache) | 310 #define SkAutoGlyphCache(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCache) |
313 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 311 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
314 | 312 |
315 #endif | 313 #endif |
OLD | NEW |