gfx/skia/trunk/src/core/SkGlyphCache_Globals.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial