gfx/skia/trunk/src/lazy/SkDiscardableMemoryPool.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2013 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 SkDiscardableMemoryPool_DEFINED
michael@0 9 #define SkDiscardableMemoryPool_DEFINED
michael@0 10
michael@0 11 #include "SkDiscardableMemory.h"
michael@0 12 #include "SkTInternalLList.h"
michael@0 13 #include "SkThread.h"
michael@0 14
michael@0 15 class SkPoolDiscardableMemory;
michael@0 16
michael@0 17 #ifdef SK_DEBUG
michael@0 18 #define LAZY_CACHE_STATS 1
michael@0 19 #elif !defined(LAZY_CACHE_STATS)
michael@0 20 #define LAZY_CACHE_STATS 0
michael@0 21 #endif
michael@0 22
michael@0 23 /**
michael@0 24 * This non-global pool can be used for unit tests to verify that the
michael@0 25 * pool works.
michael@0 26 */
michael@0 27 class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory {
michael@0 28 public:
michael@0 29 /**
michael@0 30 * Without mutex, will be not be thread safe.
michael@0 31 */
michael@0 32 SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL);
michael@0 33 virtual ~SkDiscardableMemoryPool();
michael@0 34
michael@0 35 virtual SkDiscardableMemory* create(size_t bytes) SK_OVERRIDE;
michael@0 36
michael@0 37 size_t getRAMUsed();
michael@0 38 void setRAMBudget(size_t budget);
michael@0 39
michael@0 40 /** purges all unlocked DMs */
michael@0 41 void dumpPool();
michael@0 42
michael@0 43 #if LAZY_CACHE_STATS
michael@0 44 int fCacheHits;
michael@0 45 int fCacheMisses;
michael@0 46 #endif // LAZY_CACHE_STATS
michael@0 47
michael@0 48 private:
michael@0 49 SkBaseMutex* fMutex;
michael@0 50 size_t fBudget;
michael@0 51 size_t fUsed;
michael@0 52 SkTInternalLList<SkPoolDiscardableMemory> fList;
michael@0 53
michael@0 54 /** Function called to free memory if needed */
michael@0 55 void dumpDownTo(size_t budget);
michael@0 56 /** called by SkDiscardableMemoryPool upon destruction */
michael@0 57 void free(SkPoolDiscardableMemory* dm);
michael@0 58 /** called by SkDiscardableMemoryPool::lock() */
michael@0 59 bool lock(SkPoolDiscardableMemory* dm);
michael@0 60 /** called by SkDiscardableMemoryPool::unlock() */
michael@0 61 void unlock(SkPoolDiscardableMemory* dm);
michael@0 62
michael@0 63 friend class SkPoolDiscardableMemory;
michael@0 64
michael@0 65 typedef SkDiscardableMemory::Factory INHERITED;
michael@0 66 };
michael@0 67
michael@0 68 /**
michael@0 69 * Returns (and creates if needed) a threadsafe global
michael@0 70 * SkDiscardableMemoryPool.
michael@0 71 */
michael@0 72 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool();
michael@0 73
michael@0 74 #if !defined(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE)
michael@0 75 #define SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE (128 * 1024 * 1024)
michael@0 76 #endif
michael@0 77
michael@0 78 #endif // SkDiscardableMemoryPool_DEFINED

mercurial