| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 //! If the proc is found, return true and set *dataPtr to its data | 110 //! If the proc is found, return true and set *dataPtr to its data |
| 111 bool getAuxProcData(void (*auxProc)(void*), void** dataPtr) const; | 111 bool getAuxProcData(void (*auxProc)(void*), void** dataPtr) const; |
| 112 | 112 |
| 113 //! Add a proc/data pair to the glyphcache. proc should be non-null | 113 //! Add a proc/data pair to the glyphcache. proc should be non-null |
| 114 void setAuxProc(void (*auxProc)(void*), void* auxData); | 114 void setAuxProc(void (*auxProc)(void*), void* auxData); |
| 115 | 115 |
| 116 SkScalerContext* getScalerContext() const { return fScalerContext; } | 116 SkScalerContext* getScalerContext() const { return fScalerContext; } |
| 117 | 117 |
| 118 /** Find a matching cache entry, and call proc() with it. If none is found c
reate a new one. | 118 /** Find a matching cache entry, and call proc() with it. If none is found c
reate a new one. |
| 119 If the proc() returns true, detach the cache and return it, otherwise le
ave it and return | 119 If the proc() returns true, detach the cache and return it, otherwise le
ave it and return |
| 120 NULL. | 120 nullptr. |
| 121 */ | 121 */ |
| 122 static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc, | 122 static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc, |
| 123 bool (*proc)(const SkGlyphCache*, void*), | 123 bool (*proc)(const SkGlyphCache*, void*), |
| 124 void* context); | 124 void* context); |
| 125 | 125 |
| 126 /** Given a strike that was returned by either VisitCache() or DetachCache()
add it back into | 126 /** Given a strike that was returned by either VisitCache() or DetachCache()
add it back into |
| 127 the global cache list (after which the caller should not reference it an
ymore. | 127 the global cache list (after which the caller should not reference it an
ymore. |
| 128 */ | 128 */ |
| 129 static void AttachCache(SkGlyphCache*); | 129 static void AttachCache(SkGlyphCache*); |
| 130 | 130 |
| 131 /** Detach a strike from the global cache matching the specified descriptor.
Once detached, | 131 /** Detach a strike from the global cache matching the specified descriptor.
Once detached, |
| 132 it can be queried/modified by the current thread, and when finished, be
reattached to the | 132 it can be queried/modified by the current thread, and when finished, be
reattached to the |
| 133 global cache with AttachCache(). While detached, if another request is m
ade with the same | 133 global cache with AttachCache(). While detached, if another request is m
ade with the same |
| 134 descriptor, a different strike will be generated. This is fine. It does
mean we can have | 134 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 | 135 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. | 136 win is that different thread will never block each other while a strike
is being used. |
| 137 */ | 137 */ |
| 138 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* d
esc) { | 138 static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* d
esc) { |
| 139 return VisitCache(typeface, desc, DetachProc, NULL); | 139 return VisitCache(typeface, desc, DetachProc, nullptr); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static void Dump(); | 142 static void Dump(); |
| 143 | 143 |
| 144 typedef void (*Visitor)(const SkGlyphCache&, void* context); | 144 typedef void (*Visitor)(const SkGlyphCache&, void* context); |
| 145 static void VisitAll(Visitor, void* context); | 145 static void VisitAll(Visitor, void* context); |
| 146 | 146 |
| 147 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
| 148 void validate() const; | 148 void validate() const; |
| 149 #else | 149 #else |
| 150 void validate() const {} | 150 void validate() const {} |
| 151 #endif | 151 #endif |
| 152 | 152 |
| 153 class AutoValidate : SkNoncopyable { | 153 class AutoValidate : SkNoncopyable { |
| 154 public: | 154 public: |
| 155 AutoValidate(const SkGlyphCache* cache) : fCache(cache) { | 155 AutoValidate(const SkGlyphCache* cache) : fCache(cache) { |
| 156 if (fCache) { | 156 if (fCache) { |
| 157 fCache->validate(); | 157 fCache->validate(); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 ~AutoValidate() { | 160 ~AutoValidate() { |
| 161 if (fCache) { | 161 if (fCache) { |
| 162 fCache->validate(); | 162 fCache->validate(); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 void forget() { | 165 void forget() { |
| 166 fCache = NULL; | 166 fCache = nullptr; |
| 167 } | 167 } |
| 168 private: | 168 private: |
| 169 const SkGlyphCache* fCache; | 169 const SkGlyphCache* fCache; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 friend class SkGlyphCache_Globals; | 173 friend class SkGlyphCache_Globals; |
| 174 | 174 |
| 175 enum MetricsType { | 175 enum MetricsType { |
| 176 kJustAdvance_MetricsType, | 176 kJustAdvance_MetricsType, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 AuxProcRec* fAuxProcList; | 242 AuxProcRec* fAuxProcList; |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 class SkAutoGlyphCacheBase { | 245 class SkAutoGlyphCacheBase { |
| 246 public: | 246 public: |
| 247 SkGlyphCache* getCache() const { return fCache; } | 247 SkGlyphCache* getCache() const { return fCache; } |
| 248 | 248 |
| 249 void release() { | 249 void release() { |
| 250 if (fCache) { | 250 if (fCache) { |
| 251 SkGlyphCache::AttachCache(fCache); | 251 SkGlyphCache::AttachCache(fCache); |
| 252 fCache = NULL; | 252 fCache = nullptr; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 protected: | 256 protected: |
| 257 // Hide the constructors so we can't create one of these directly. Create Sk
AutoGlyphCache or | 257 // Hide the constructors so we can't create one of these directly. Create Sk
AutoGlyphCache or |
| 258 // SkAutoGlyphCacheNoCache instead. | 258 // SkAutoGlyphCacheNoCache instead. |
| 259 SkAutoGlyphCacheBase(SkGlyphCache* cache) : fCache(cache) {} | 259 SkAutoGlyphCacheBase(SkGlyphCache* cache) : fCache(cache) {} |
| 260 SkAutoGlyphCacheBase(SkTypeface* typeface, const SkDescriptor* desc) { | 260 SkAutoGlyphCacheBase(SkTypeface* typeface, const SkDescriptor* desc) { |
| 261 fCache = SkGlyphCache::DetachCache(typeface, desc); | 261 fCache = SkGlyphCache::DetachCache(typeface, desc); |
| 262 } | 262 } |
| 263 SkAutoGlyphCacheBase(const SkPaint& /*paint*/, | 263 SkAutoGlyphCacheBase(const SkPaint& /*paint*/, |
| 264 const SkSurfaceProps* /*surfaceProps*/, | 264 const SkSurfaceProps* /*surfaceProps*/, |
| 265 const SkMatrix* /*matrix*/) { | 265 const SkMatrix* /*matrix*/) { |
| 266 fCache = NULL; | 266 fCache = nullptr; |
| 267 } | 267 } |
| 268 SkAutoGlyphCacheBase() { | 268 SkAutoGlyphCacheBase() { |
| 269 fCache = NULL; | 269 fCache = nullptr; |
| 270 } | 270 } |
| 271 ~SkAutoGlyphCacheBase() { | 271 ~SkAutoGlyphCacheBase() { |
| 272 if (fCache) { | 272 if (fCache) { |
| 273 SkGlyphCache::AttachCache(fCache); | 273 SkGlyphCache::AttachCache(fCache); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 SkGlyphCache* fCache; | 277 SkGlyphCache* fCache; |
| 278 | 278 |
| 279 private: | 279 private: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 306 const SkMatrix* matrix) { | 306 const SkMatrix* matrix) { |
| 307 fCache = paint.detachCache(surfaceProps, matrix, true); | 307 fCache = paint.detachCache(surfaceProps, matrix, true); |
| 308 } | 308 } |
| 309 | 309 |
| 310 private: | 310 private: |
| 311 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 311 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
| 312 }; | 312 }; |
| 313 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 313 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
| 314 | 314 |
| 315 #endif | 315 #endif |
| OLD | NEW |