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

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 8
bungeman-skia 2013/09/25 14:46:07 8 seems rather small, though I suppose one hardly
reed1 2013/09/25 17:30:31 Doh! I had set it to 8 just for testing. I'll rese
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
bungeman-skia 2013/09/25 14:46:07 These enum names seem a bit silly in that you've n
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 // call when SkGlyphCache is constructed
55 void registerCache(SkGlyphCache*);
56 // call when SkGlyphCache is destroyed
57 void unregisterCache(SkGlyphCache*);
58
59 SkMutex* fMutex;
bungeman-skia 2013/09/25 14:46:07 SkAutoTDelete<SkMutex> ?
60 SkGlyphCache* fHead;
61 size_t fTotalMemoryUsed;
62
63 #ifdef SK_DEBUG
64 void validate() const;
65 #else
66 void validate() const {}
67 #endif
68
69 int getCacheCountLimit() const { return fCacheCountLimit; }
70 void setCacheCountLimit(int limit);
71
72 size_t getCacheSizeLimit() const { return fCacheSizeLimit; }
73 size_t setCacheSizeLimit(size_t limit);
74
75 // returns true if this cache is over-budget either due to size limit
76 // or count limit.
77 bool isOverBudget() const {
78 return fCacheCount > fCacheCountLimit ||
79 fTotalMemoryUsed > fCacheSizeLimit;
80 }
81
82 void purgeAll(); // does not change budget
83
84 // call when a glyphcache is available for caching (i.e. not in use)
85 void attachCache(SkGlyphCache*);
86
87 // can return NULL
88 static SkGlyphCache_Globals* FindTLS() {
89 return (SkGlyphCache_Globals*)SkTLS::Find(CreateTLS);
90 }
91
92 static SkGlyphCache_Globals& GetTLS() {
93 return *(SkGlyphCache_Globals*)SkTLS::Get(CreateTLS, DeleteTLS);
94 }
95
96 static void DeleteTLS() { SkTLS::Delete(CreateTLS); }
97
98 private:
99 size_t fCacheSizeLimit;
100 int32_t fCacheCount;
101 int32_t fCacheCountLimit;
102
103 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
104 // and attempt to purge caches to match.
105 // Returns number of bytes freed.
106 size_t internalPurge(size_t minBytesNeeded = 0);
107
108 static void* CreateTLS() {
109 return SkNEW_ARGS(SkGlyphCache_Globals, (kNo_UseMutex));
110 }
111
112 static void DeleteTLS(void* ptr) {
113 SkDELETE((SkGlyphCache_Globals*)ptr);
114 }
115 };
116
117 #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