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

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

Issue 24447003: add counting to glyphcache, and refactor some for clarity (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« src/core/SkGlyphCache.cpp ('K') | « 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
(Empty)
1 /*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkGlyphCache_Globals_DEFINED
9 #define SkGlyphCache_Globals_DEFINED
10
11 #include "SkGlyphCache.h"
12 #include "SkTLS.h"
13
14 #ifndef SK_DEFAULT_FONT_CACHE_COUNT_LIMIT
15 #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 256
16 #endif
17
18 #ifndef SK_DEFAULT_FONT_CACHE_LIMIT
19 #define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024)
20 #endif
21
22 ///////////////////////////////////////////////////////////////////////////////
23
24 class SkMutex;
25
26 class SkGlyphCache_Globals {
27 public:
28 enum UseMutex {
29 kNo_UseMutex, // thread-local cache
30 kYes_UseMutex // shared cache
31 };
32
33 SkGlyphCache_Globals(UseMutex um) {
34 fHead = NULL;
35 fTotalMemoryUsed = 0;
36 fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT;
37 fCacheCount = 0;
38 fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT;
39
40 fMutex = (kYes_UseMutex == um) ? SkNEW(SkMutex) : NULL;
41 }
42
43 ~SkGlyphCache_Globals() {
44 SkGlyphCache* cache = fHead;
45 while (cache) {
46 SkGlyphCache* next = cache->fNext;
47 SkDELETE(cache);
48 cache = next;
49 }
50
51 SkDELETE(fMutex);
52 }
53
54 SkMutex* fMutex;
55
56 SkGlyphCache* internalGetHead() const { return fHead; }
57 SkGlyphCache* internalGetTail() const;
58
59 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; }
60
61 #ifdef SK_DEBUG
62 void validate() const;
63 #else
64 void validate() const {}
65 #endif
66
67 int getCacheCountLimit() const { return fCacheCountLimit; }
bungeman-skia 2013/09/26 18:40:27 How are these exposed?
reed1 2013/09/26 19:17:14 Done.
68 void setCacheCountLimit(int limit);
69
70 size_t getCacheSizeLimit() const { return fCacheSizeLimit; }
71 size_t setCacheSizeLimit(size_t limit);
72
73 // returns true if this cache is over-budget either due to size limit
74 // or count limit.
75 bool isOverBudget() const {
76 return fCacheCount > fCacheCountLimit ||
77 fTotalMemoryUsed > fCacheSizeLimit;
78 }
79
80 void purgeAll(); // does not change budget
81
82 // call when a glyphcache is available for caching (i.e. not in use)
83 void attachCacheToHead(SkGlyphCache*);
84
85 // can only be called when the mutex is already held
86 void internalDetachCache(SkGlyphCache*);
87 void internalAttachCacheToHead(SkGlyphCache*);
88
89 // can return NULL
90 static SkGlyphCache_Globals* FindTLS() {
91 return (SkGlyphCache_Globals*)SkTLS::Find(CreateTLS);
92 }
93
94 static SkGlyphCache_Globals& GetTLS() {
95 return *(SkGlyphCache_Globals*)SkTLS::Get(CreateTLS, DeleteTLS);
96 }
97
98 static void DeleteTLS() { SkTLS::Delete(CreateTLS); }
99
100 private:
101 SkGlyphCache* fHead;
102 size_t fTotalMemoryUsed;
103 size_t fCacheSizeLimit;
104 int32_t fCacheCountLimit;
105 int32_t fCacheCount;
106
107 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
108 // and attempt to purge caches to match.
109 // Returns number of bytes freed.
110 size_t internalPurge(size_t minBytesNeeded = 0);
111
112 static void* CreateTLS() {
113 return SkNEW_ARGS(SkGlyphCache_Globals, (kNo_UseMutex));
114 }
115
116 static void DeleteTLS(void* ptr) {
117 SkDELETE((SkGlyphCache_Globals*)ptr);
118 }
119 };
120
121 #endif
OLDNEW
« src/core/SkGlyphCache.cpp ('K') | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698