| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkGlyphCache_DEFINED | 10 #ifndef SkGlyphCache_DEFINED |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 /** Call proc on all cache entries, stopping early if proc returns true. | 128 /** Call proc on all cache entries, stopping early if proc returns true. |
| 129 The proc should not create or delete caches, since it could produce | 129 The proc should not create or delete caches, since it could produce |
| 130 deadlock. | 130 deadlock. |
| 131 */ | 131 */ |
| 132 static void VisitAllCaches(bool (*proc)(SkGlyphCache*, void*), void* ctx); | 132 static void VisitAllCaches(bool (*proc)(SkGlyphCache*, void*), void* ctx); |
| 133 | 133 |
| 134 /** Find a matching cache entry, and call proc() with it. If none is found | 134 /** Find a matching cache entry, and call proc() with it. If none is found |
| 135 create a new one. If the proc() returns true, detach the cache and | 135 create a new one. If the proc() returns true, detach the cache and |
| 136 return it, otherwise leave it and return NULL. | 136 return it, otherwise leave it and return NULL. |
| 137 */ | 137 */ |
| 138 static SkGlyphCache* VisitCache(const SkDescriptor* desc, | 138 static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc, |
| 139 bool (*proc)(const SkGlyphCache*, void*), | 139 bool (*proc)(const SkGlyphCache*, void*), |
| 140 void* context); | 140 void* context); |
| 141 | 141 |
| 142 /** Given a strike that was returned by either VisitCache() or DetachCache() | 142 /** Given a strike that was returned by either VisitCache() or DetachCache() |
| 143 add it back into the global cache list (after which the caller should | 143 add it back into the global cache list (after which the caller should |
| 144 not reference it anymore. | 144 not reference it anymore. |
| 145 */ | 145 */ |
| 146 static void AttachCache(SkGlyphCache*); | 146 static void AttachCache(SkGlyphCache*); |
| 147 | 147 |
| 148 /** Detach a strike from the global cache matching the specified descriptor. | 148 /** Detach a strike from the global cache matching the specified descriptor. |
| 149 Once detached, it can be queried/modified by the current thread, and | 149 Once detached, it can be queried/modified by the current thread, and |
| 150 when finished, be reattached to the global cache with AttachCache(). | 150 when finished, be reattached to the global cache with AttachCache(). |
| 151 While detached, if another request is made with the same descriptor, | 151 While detached, if another request is made with the same descriptor, |
| 152 a different strike will be generated. This is fine. It does mean we | 152 a different strike will be generated. This is fine. It does mean we |
| 153 can have more than 1 strike for the same descriptor, but that will | 153 can have more than 1 strike for the same descriptor, but that will |
| 154 eventually get purged, and the win is that different thread will never | 154 eventually get purged, and the win is that different thread will never |
| 155 block each other while a strike is being used. | 155 block each other while a strike is being used. |
| 156 */ | 156 */ |
| 157 static SkGlyphCache* DetachCache(const SkDescriptor* desc) { | 157 static SkGlyphCache* DetachCache(SkTypeface* typeface, |
| 158 return VisitCache(desc, DetachProc, NULL); | 158 const SkDescriptor* desc) { |
| 159 return VisitCache(typeface, desc, DetachProc, NULL); |
| 159 } | 160 } |
| 160 | 161 |
| 161 #ifdef SK_DEBUG | 162 #ifdef SK_DEBUG |
| 162 void validate() const; | 163 void validate() const; |
| 163 #else | 164 #else |
| 164 void validate() const {} | 165 void validate() const {} |
| 165 #endif | 166 #endif |
| 166 | 167 |
| 167 class AutoValidate : SkNoncopyable { | 168 class AutoValidate : SkNoncopyable { |
| 168 public: | 169 public: |
| 169 AutoValidate(const SkGlyphCache* cache) : fCache(cache) { | 170 AutoValidate(const SkGlyphCache* cache) : fCache(cache) { |
| 170 if (fCache) { | 171 if (fCache) { |
| 171 fCache->validate(); | 172 fCache->validate(); |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 ~AutoValidate() { | 175 ~AutoValidate() { |
| 175 if (fCache) { | 176 if (fCache) { |
| 176 fCache->validate(); | 177 fCache->validate(); |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 void forget() { | 180 void forget() { |
| 180 fCache = NULL; | 181 fCache = NULL; |
| 181 } | 182 } |
| 182 private: | 183 private: |
| 183 const SkGlyphCache* fCache; | 184 const SkGlyphCache* fCache; |
| 184 }; | 185 }; |
| 185 | 186 |
| 186 private: | 187 private: |
| 187 SkGlyphCache(const SkDescriptor*); | 188 SkGlyphCache(SkTypeface*, const SkDescriptor*); |
| 188 ~SkGlyphCache(); | 189 ~SkGlyphCache(); |
| 189 | 190 |
| 190 enum MetricsType { | 191 enum MetricsType { |
| 191 kJustAdvance_MetricsType, | 192 kJustAdvance_MetricsType, |
| 192 kFull_MetricsType | 193 kFull_MetricsType |
| 193 }; | 194 }; |
| 194 | 195 |
| 195 SkGlyph* lookupMetrics(uint32_t id, MetricsType); | 196 SkGlyph* lookupMetrics(uint32_t id, MetricsType); |
| 196 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 197 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
| 197 | 198 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 static size_t InternalFreeCache(SkGlyphCache_Globals*, size_t bytesNeeded); | 267 static size_t InternalFreeCache(SkGlyphCache_Globals*, size_t bytesNeeded); |
| 267 | 268 |
| 268 inline static SkGlyphCache* FindTail(SkGlyphCache* head); | 269 inline static SkGlyphCache* FindTail(SkGlyphCache* head); |
| 269 | 270 |
| 270 friend class SkGlyphCache_Globals; | 271 friend class SkGlyphCache_Globals; |
| 271 }; | 272 }; |
| 272 | 273 |
| 273 class SkAutoGlyphCache { | 274 class SkAutoGlyphCache { |
| 274 public: | 275 public: |
| 275 SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {} | 276 SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {} |
| 276 SkAutoGlyphCache(const SkDescriptor* desc) { | 277 SkAutoGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) { |
| 277 fCache = SkGlyphCache::DetachCache(desc); | 278 fCache = SkGlyphCache::DetachCache(typeface, desc); |
| 278 } | 279 } |
| 279 SkAutoGlyphCache(const SkPaint& paint, | 280 SkAutoGlyphCache(const SkPaint& paint, |
| 280 const SkDeviceProperties* deviceProperties, | 281 const SkDeviceProperties* deviceProperties, |
| 281 const SkMatrix* matrix) { | 282 const SkMatrix* matrix) { |
| 282 fCache = paint.detachCache(deviceProperties, matrix); | 283 fCache = paint.detachCache(deviceProperties, matrix); |
| 283 } | 284 } |
| 284 ~SkAutoGlyphCache() { | 285 ~SkAutoGlyphCache() { |
| 285 if (fCache) { | 286 if (fCache) { |
| 286 SkGlyphCache::AttachCache(fCache); | 287 SkGlyphCache::AttachCache(fCache); |
| 287 } | 288 } |
| 288 } | 289 } |
| 289 | 290 |
| 290 SkGlyphCache* getCache() const { return fCache; } | 291 SkGlyphCache* getCache() const { return fCache; } |
| 291 | 292 |
| 292 void release() { | 293 void release() { |
| 293 if (fCache) { | 294 if (fCache) { |
| 294 SkGlyphCache::AttachCache(fCache); | 295 SkGlyphCache::AttachCache(fCache); |
| 295 fCache = NULL; | 296 fCache = NULL; |
| 296 } | 297 } |
| 297 } | 298 } |
| 298 | 299 |
| 299 private: | 300 private: |
| 300 SkGlyphCache* fCache; | 301 SkGlyphCache* fCache; |
| 301 | 302 |
| 302 static bool DetachProc(const SkGlyphCache*, void*); | 303 static bool DetachProc(const SkGlyphCache*, void*); |
| 303 }; | 304 }; |
| 304 | 305 |
| 305 #endif | 306 #endif |
| OLD | NEW |