| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrTextureStripAtlas_DEFINED | 8 #ifndef GrTextureStripAtlas_DEFINED |
| 9 #define GrTextureStripAtlas_DEFINED | 9 #define GrTextureStripAtlas_DEFINED |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 private: | 76 private: |
| 77 | 77 |
| 78 // Key to indicate an atlas row without any meaningful data stored in it | 78 // Key to indicate an atlas row without any meaningful data stored in it |
| 79 const static uint32_t kEmptyAtlasRowKey = 0xffffffff; | 79 const static uint32_t kEmptyAtlasRowKey = 0xffffffff; |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * The state of a single row in our cache, next/prev pointers allow these to
be chained | 82 * The state of a single row in our cache, next/prev pointers allow these to
be chained |
| 83 * together to represent LRU status | 83 * together to represent LRU status |
| 84 */ | 84 */ |
| 85 struct AtlasRow : SkNoncopyable { | 85 struct AtlasRow : SkNoncopyable { |
| 86 AtlasRow() : fKey(kEmptyAtlasRowKey), fLocks(0), fNext(NULL), fPrev(NULL
) { } | 86 AtlasRow() : fKey(kEmptyAtlasRowKey), fLocks(0), fNext(nullptr), fPrev(n
ullptr) { } |
| 87 // GenerationID of the bitmap that is represented by this row, 0xfffffff
f means "empty" | 87 // GenerationID of the bitmap that is represented by this row, 0xfffffff
f means "empty" |
| 88 uint32_t fKey; | 88 uint32_t fKey; |
| 89 // How many times this has been locked (0 == unlocked) | 89 // How many times this has been locked (0 == unlocked) |
| 90 int32_t fLocks; | 90 int32_t fLocks; |
| 91 // We maintain an LRU linked list between unlocked nodes with these poin
ters | 91 // We maintain an LRU linked list between unlocked nodes with these poin
ters |
| 92 AtlasRow* fNext; | 92 AtlasRow* fNext; |
| 93 AtlasRow* fPrev; | 93 AtlasRow* fPrev; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * We'll only allow construction via the static GrTextureStripAtlas::GetAtla
s | 97 * We'll only allow construction via the static GrTextureStripAtlas::GetAtla
s |
| 98 */ | 98 */ |
| 99 GrTextureStripAtlas(Desc desc); | 99 GrTextureStripAtlas(Desc desc); |
| 100 | 100 |
| 101 void lockTexture(); | 101 void lockTexture(); |
| 102 void unlockTexture(); | 102 void unlockTexture(); |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Initialize our LRU list (if one already exists, clear it and start anew) | 105 * Initialize our LRU list (if one already exists, clear it and start anew) |
| 106 */ | 106 */ |
| 107 void initLRU(); | 107 void initLRU(); |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Grabs the least recently used free row out of the LRU list, returns NULL
if no rows are free. | 110 * Grabs the least recently used free row out of the LRU list, returns nullp
tr if no rows are free. |
| 111 */ | 111 */ |
| 112 AtlasRow* getLRU(); | 112 AtlasRow* getLRU(); |
| 113 | 113 |
| 114 void appendLRU(AtlasRow* row); | 114 void appendLRU(AtlasRow* row); |
| 115 void removeFromLRU(AtlasRow* row); | 115 void removeFromLRU(AtlasRow* row); |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * Searches the key table for a key and returns the index if found; if not f
ound, it returns | 118 * Searches the key table for a key and returns the index if found; if not f
ound, it returns |
| 119 * the bitwise not of the index at which we could insert the key to maintain
a sorted list. | 119 * the bitwise not of the index at which we could insert the key to maintain
a sorted list. |
| 120 **/ | 120 **/ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 138 static void CleanUp(const GrContext* context, void* info); | 138 static void CleanUp(const GrContext* context, void* info); |
| 139 | 139 |
| 140 // Hash table entry for atlases | 140 // Hash table entry for atlases |
| 141 class AtlasEntry : public ::SkNoncopyable { | 141 class AtlasEntry : public ::SkNoncopyable { |
| 142 public: | 142 public: |
| 143 // for SkTDynamicHash | 143 // for SkTDynamicHash |
| 144 static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc;
} | 144 static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc;
} |
| 145 static uint32_t Hash(const Desc& desc) { return SkChecksum::Murmur3(&des
c, sizeof(Desc)); } | 145 static uint32_t Hash(const Desc& desc) { return SkChecksum::Murmur3(&des
c, sizeof(Desc)); } |
| 146 | 146 |
| 147 // AtlasEntry proper | 147 // AtlasEntry proper |
| 148 AtlasEntry() : fAtlas(NULL) {} | 148 AtlasEntry() : fAtlas(nullptr) {} |
| 149 ~AtlasEntry() { delete fAtlas; } | 149 ~AtlasEntry() { delete fAtlas; } |
| 150 Desc fDesc; | 150 Desc fDesc; |
| 151 GrTextureStripAtlas* fAtlas; | 151 GrTextureStripAtlas* fAtlas; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 class Hash; | 154 class Hash; |
| 155 static Hash* gAtlasCache; | 155 static Hash* gAtlasCache; |
| 156 | 156 |
| 157 static Hash* GetCache(); | 157 static Hash* GetCache(); |
| 158 | 158 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 180 // Head and tail for linked list of least-recently-used rows (front = least
recently used). | 180 // Head and tail for linked list of least-recently-used rows (front = least
recently used). |
| 181 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. | 181 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. |
| 182 AtlasRow* fLRUFront; | 182 AtlasRow* fLRUFront; |
| 183 AtlasRow* fLRUBack; | 183 AtlasRow* fLRUBack; |
| 184 | 184 |
| 185 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key | 185 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key |
| 186 SkTDArray<AtlasRow*> fKeyTable; | 186 SkTDArray<AtlasRow*> fKeyTable; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 #endif | 189 #endif |
| OLD | NEW |