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

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

Issue 668223002: SkResourceCache::Key namespace support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused SkPictureShader headers Created 6 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
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/core/SkResourceCache.cpp » ('j') | 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 13 matching lines...) Expand all
24 * As a convenience, a global instance is also defined, which can be safely 24 * As a convenience, a global instance is also defined, which can be safely
25 * access across threads via the static methods (e.g. FindAndLock, etc.). 25 * access across threads via the static methods (e.g. FindAndLock, etc.).
26 */ 26 */
27 class SkResourceCache { 27 class SkResourceCache {
28 public: 28 public:
29 struct Key { 29 struct Key {
30 // Call this to access your private contents. Must not use the address a fter calling init() 30 // Call this to access your private contents. Must not use the address a fter calling init()
31 void* writableContents() { return this + 1; } 31 void* writableContents() { return this + 1; }
32 32
33 // must call this after your private data has been written. 33 // must call this after your private data has been written.
34 // nameSpace must be unique per Key subclass.
34 // length must be a multiple of 4 35 // length must be a multiple of 4
35 void init(size_t length); 36 void init(void* nameSpace, size_t length);
36 37
37 // This is only valid after having called init(). 38 // This is only valid after having called init().
38 uint32_t hash() const { return fHash; } 39 uint32_t hash() const { return fHash; }
39 40
40 bool operator==(const Key& other) const { 41 bool operator==(const Key& other) const {
41 const uint32_t* a = this->as32(); 42 const uint32_t* a = this->as32();
42 const uint32_t* b = other.as32(); 43 const uint32_t* b = other.as32();
43 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe r.fCount first.) 44 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe r.fCount first.)
44 if (a[i] != b[i]) { 45 if (a[i] != b[i]) {
45 return false; 46 return false;
46 } 47 }
47 } 48 }
48 return true; 49 return true;
49 } 50 }
50 51
51 private: 52 private:
52 int32_t fCount32; // 2 + user contents count32 53 int32_t fCount32; // local + user contents count32
53 uint32_t fHash; 54 uint32_t fHash;
55 void* fNamespace; // A unique namespace tag. This is hashed.
54 /* uint32_t fContents32[] */ 56 /* uint32_t fContents32[] */
55 57
56 const uint32_t* as32() const { return (const uint32_t*)this; } 58 const uint32_t* as32() const { return (const uint32_t*)this; }
57 }; 59 };
58 60
59 struct Rec { 61 struct Rec {
60 typedef SkResourceCache::Key Key; 62 typedef SkResourceCache::Key Key;
61 63
62 Rec() {} 64 Rec() {}
63 virtual ~Rec() {} 65 virtual ~Rec() {}
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 231
230 void init(); // called by constructors 232 void init(); // called by constructors
231 233
232 #ifdef SK_DEBUG 234 #ifdef SK_DEBUG
233 void validate() const; 235 void validate() const;
234 #else 236 #else
235 void validate() const {} 237 void validate() const {}
236 #endif 238 #endif
237 }; 239 };
238 #endif 240 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/core/SkResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698