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

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

Issue 533713003: Added Doc for GetAllocator in SkResourceCache and SkBitmapCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Please kill me Created 6 years, 3 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/SkBitmapCache.h ('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 2013 Google Inc. 2 * Copyright 2013 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 SkResourceCache_DEFINED 8 #ifndef SkResourceCache_DEFINED
9 #define SkResourceCache_DEFINED 9 #define SkResourceCache_DEFINED
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const uint32_t* as32SkipCount() const { return this->as32() + 1; } 57 const uint32_t* as32SkipCount() const { return this->as32() + 1; }
58 }; 58 };
59 59
60 struct Rec { 60 struct Rec {
61 typedef SkResourceCache::Key Key; 61 typedef SkResourceCache::Key Key;
62 62
63 Rec() : fLockCount(1) {} 63 Rec() : fLockCount(1) {}
64 virtual ~Rec() {} 64 virtual ~Rec() {}
65 65
66 uint32_t getHash() const { return this->getKey().hash(); } 66 uint32_t getHash() const { return this->getKey().hash(); }
67 67
68 virtual const Key& getKey() const = 0; 68 virtual const Key& getKey() const = 0;
69 virtual size_t bytesUsed() const = 0; 69 virtual size_t bytesUsed() const = 0;
70 70
71 // for SkTDynamicHash::Traits 71 // for SkTDynamicHash::Traits
72 static uint32_t Hash(const Key& key) { return key.hash(); } 72 static uint32_t Hash(const Key& key) { return key.hash(); }
73 static const Key& GetKey(const Rec& rec) { return rec.getKey(); } 73 static const Key& GetKey(const Rec& rec) { return rec.getKey(); }
74 74
75 private: 75 private:
76 Rec* fNext; 76 Rec* fNext;
77 Rec* fPrev; 77 Rec* fPrev;
78 int32_t fLockCount; 78 int32_t fLockCount;
79 int32_t fPad; 79 int32_t fPad;
80 80
81 friend class SkResourceCache; 81 friend class SkResourceCache;
82 }; 82 };
83 83
84 typedef const Rec* ID; 84 typedef const Rec* ID;
85 85
86 /** 86 /**
87 * Returns a locked/pinned SkDiscardableMemory instance for the specified 87 * Returns a locked/pinned SkDiscardableMemory instance for the specified
88 * number of bytes, or NULL on failure. 88 * number of bytes, or NULL on failure.
89 */ 89 */
90 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); 90 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes);
91 91
92 /* 92 /*
93 * The following static methods are thread-safe wrappers around a global 93 * The following static methods are thread-safe wrappers around a global
94 * instance of this cache. 94 * instance of this cache.
95 */ 95 */
96 96
97 static const Rec* FindAndLock(const Key& key); 97 static const Rec* FindAndLock(const Key& key);
98 static const Rec* AddAndLock(Rec*); 98 static const Rec* AddAndLock(Rec*);
99 static void Add(Rec*); 99 static void Add(Rec*);
100 static void Unlock(ID); 100 static void Unlock(ID);
101 101
102 static size_t GetTotalBytesUsed(); 102 static size_t GetTotalBytesUsed();
103 static size_t GetTotalByteLimit(); 103 static size_t GetTotalByteLimit();
104 static size_t SetTotalByteLimit(size_t newLimit); 104 static size_t SetTotalByteLimit(size_t newLimit);
105 105
106 static size_t SetSingleAllocationByteLimit(size_t); 106 static size_t SetSingleAllocationByteLimit(size_t);
107 static size_t GetSingleAllocationByteLimit(); 107 static size_t GetSingleAllocationByteLimit();
108 108
109 /**
110 * Use this allocator for bitmaps, so they can use ashmem when available.
111 * Returns NULL if the ResourceCache has not been initialized with a Discard ableFactory.
112 */
109 static SkBitmap::Allocator* GetAllocator(); 113 static SkBitmap::Allocator* GetAllocator();
110 114
111 /** 115 /**
112 * Call SkDebugf() with diagnostic information about the state of the cache 116 * Call SkDebugf() with diagnostic information about the state of the cache
113 */ 117 */
114 static void Dump(); 118 static void Dump();
115 119
116 /////////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////////
117 121
118 /** 122 /**
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 199
196 void init(); // called by constructors 200 void init(); // called by constructors
197 201
198 #ifdef SK_DEBUG 202 #ifdef SK_DEBUG
199 void validate() const; 203 void validate() const;
200 #else 204 #else
201 void validate() const {} 205 void validate() const {}
202 #endif 206 #endif
203 }; 207 };
204 #endif 208 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698