Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: src/core/SkGlyphCache_Globals.h

Issue 2082423002: Add guards around access to font cache global fields. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 Google Inc.
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 #ifndef SkGlyphCache_Globals_DEFINED 8 #ifndef SkGlyphCache_Globals_DEFINED
9 #define SkGlyphCache_Globals_DEFINED 9 #define SkGlyphCache_Globals_DEFINED
10 10
(...skipping 24 matching lines...) Expand all
35 35
36 ~SkGlyphCache_Globals() { 36 ~SkGlyphCache_Globals() {
37 SkGlyphCache* cache = fHead; 37 SkGlyphCache* cache = fHead;
38 while (cache) { 38 while (cache) {
39 SkGlyphCache* next = cache->fNext; 39 SkGlyphCache* next = cache->fNext;
40 delete cache; 40 delete cache;
41 cache = next; 41 cache = next;
42 } 42 }
43 } 43 }
44 44
45 SkSpinlock fLock; 45 mutable SkSpinlock fLock;
reed1 2016/06/22 16:05:36 make private?
46 46
47 SkGlyphCache* internalGetHead() const { return fHead; } 47 SkGlyphCache* internalGetHead() const { return fHead; }
48 SkGlyphCache* internalGetTail() const; 48 SkGlyphCache* internalGetTail() const;
49 49
50 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; } 50 size_t getTotalMemoryUsed() const;
51 int getCacheCountUsed() const { return fCacheCount; } 51 int getCacheCountUsed() const;
52 52
53 #ifdef SK_DEBUG 53 #ifdef SK_DEBUG
54 void validate() const; 54 void validate() const;
55 #else 55 #else
56 void validate() const {} 56 void validate() const {}
57 #endif 57 #endif
58 58
59 int getCacheCountLimit() const { return fCacheCountLimit; } 59 int getCacheCountLimit() const;
60 int setCacheCountLimit(int limit); 60 int setCacheCountLimit(int limit);
61 61
62 size_t getCacheSizeLimit() const { return fCacheSizeLimit; } 62 size_t getCacheSizeLimit() const;
63 size_t setCacheSizeLimit(size_t limit); 63 size_t setCacheSizeLimit(size_t limit);
64 64
65 // returns true if this cache is over-budget either due to size limit
66 // or count limit.
67 bool isOverBudget() const {
68 return fCacheCount > fCacheCountLimit ||
69 fTotalMemoryUsed > fCacheSizeLimit;
70 }
71
72 void purgeAll(); // does not change budget 65 void purgeAll(); // does not change budget
73 66
74 // call when a glyphcache is available for caching (i.e. not in use) 67 // call when a glyphcache is available for caching (i.e. not in use)
75 void attachCacheToHead(SkGlyphCache*); 68 void attachCacheToHead(SkGlyphCache*);
76 69
77 // can only be called when the mutex is already held 70 // can only be called when the mutex is already held
78 void internalDetachCache(SkGlyphCache*); 71 void internalDetachCache(SkGlyphCache*);
79 void internalAttachCacheToHead(SkGlyphCache*); 72 void internalAttachCacheToHead(SkGlyphCache*);
80 73
81 private: 74 private:
82 SkGlyphCache* fHead; 75 SkGlyphCache* fHead;
83 size_t fTotalMemoryUsed; 76 size_t fTotalMemoryUsed;
84 size_t fCacheSizeLimit; 77 size_t fCacheSizeLimit;
85 int32_t fCacheCountLimit; 78 int32_t fCacheCountLimit;
86 int32_t fCacheCount; 79 int32_t fCacheCount;
87 80
88 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge, 81 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
89 // and attempt to purge caches to match. 82 // and attempt to purge caches to match.
90 // Returns number of bytes freed. 83 // Returns number of bytes freed.
91 size_t internalPurge(size_t minBytesNeeded = 0); 84 size_t internalPurge(size_t minBytesNeeded = 0);
92 }; 85 };
93 86
94 #endif 87 #endif
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698