| 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 |
| 11 #include "GrBinHashKey.h" | 11 #include "GrBinHashKey.h" |
| 12 #include "GrTHashTable.h" | |
| 13 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 14 #include "SkGr.h" | 13 #include "SkGr.h" |
| 15 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
| 15 #include "SkTDynamicHash.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Maintains a single large texture whose rows store many textures of a small fi
xed height, | 19 * Maintains a single large texture whose rows store many textures of a small fi
xed height, |
| 20 * stored in rows across the x-axis such that we can safely wrap/repeat them hor
izontally. | 20 * stored in rows across the x-axis such that we can safely wrap/repeat them hor
izontally. |
| 21 */ | 21 */ |
| 22 class GrTextureStripAtlas { | 22 class GrTextureStripAtlas { |
| 23 public: | 23 public: |
| 24 /** | 24 /** |
| 25 * Descriptor struct which we'll use as a hash table key | 25 * Descriptor struct which we'll use as a hash table key |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void validate(); | 128 void validate(); |
| 129 #endif | 129 #endif |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * Clean up callback registered with GrContext. Allows this class to | 132 * Clean up callback registered with GrContext. Allows this class to |
| 133 * free up any allocated AtlasEntry and GrTextureStripAtlas objects | 133 * free up any allocated AtlasEntry and GrTextureStripAtlas objects |
| 134 */ | 134 */ |
| 135 static void CleanUp(const GrContext* context, void* info); | 135 static void CleanUp(const GrContext* context, void* info); |
| 136 | 136 |
| 137 // Hash table entry for atlases | 137 // Hash table entry for atlases |
| 138 class AtlasEntry; | |
| 139 class AtlasHashKey : public GrBinHashKey<sizeof(GrTextureStripAtlas::Desc)>
{ | |
| 140 public: | |
| 141 static bool Equals(const AtlasEntry& entry, const AtlasHashKey& key); | |
| 142 static bool LessThan(const AtlasEntry& entry, const AtlasHashKey& key); | |
| 143 }; | |
| 144 class AtlasEntry : public ::SkNoncopyable { | 138 class AtlasEntry : public ::SkNoncopyable { |
| 145 public: | 139 public: |
| 140 // for SkTDynamicHash |
| 141 class Key : public GrMurmur3HashKey<sizeof(GrTextureStripAtlas::Desc)> {
}; |
| 142 static const Key& GetKey(const AtlasEntry& entry) { return entry.fKey; } |
| 143 static uint32_t Hash(const Key& key) { return key.getHash(); } |
| 144 |
| 145 // AtlasEntry proper |
| 146 AtlasEntry() : fAtlas(NULL) {} | 146 AtlasEntry() : fAtlas(NULL) {} |
| 147 ~AtlasEntry() { SkDELETE(fAtlas); } | 147 ~AtlasEntry() { SkDELETE(fAtlas); } |
| 148 AtlasHashKey fKey; | 148 Key fKey; |
| 149 GrTextureStripAtlas* fAtlas; | 149 GrTextureStripAtlas* fAtlas; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* gAtlasCache; | 152 class Hash; |
| 153 static Hash* gAtlasCache; |
| 153 | 154 |
| 154 static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* GetCache(); | 155 static Hash* GetCache(); |
| 155 | 156 |
| 156 // We increment gCacheCount for each atlas | 157 // We increment gCacheCount for each atlas |
| 157 static int32_t gCacheCount; | 158 static int32_t gCacheCount; |
| 158 | 159 |
| 159 // A unique ID for this texture (formed with: gCacheCount++), so we can be s
ure that if we | 160 // A unique ID for this texture (formed with: gCacheCount++), so we can be s
ure that if we |
| 160 // get a texture back from the texture cache, that it's the same one we last
used. | 161 // get a texture back from the texture cache, that it's the same one we last
used. |
| 161 const int32_t fCacheKey; | 162 const int32_t fCacheKey; |
| 162 | 163 |
| 163 // Total locks on all rows (when this reaches zero, we can unlock our textur
e) | 164 // Total locks on all rows (when this reaches zero, we can unlock our textur
e) |
| 164 int32_t fLockedRows; | 165 int32_t fLockedRows; |
| 165 | 166 |
| 166 const Desc fDesc; | 167 const Desc fDesc; |
| 167 const uint16_t fNumRows; | 168 const uint16_t fNumRows; |
| 168 GrTexture* fTexture; | 169 GrTexture* fTexture; |
| 169 | 170 |
| 170 // Array of AtlasRows which store the state of all our rows. Stored in a con
tiguous array, in | 171 // Array of AtlasRows which store the state of all our rows. Stored in a con
tiguous array, in |
| 171 // order that they appear in our texture, this means we can subtract this po
inter from a row | 172 // order that they appear in our texture, this means we can subtract this po
inter from a row |
| 172 // pointer to get its index in the texture, and can save storing a row numbe
r in AtlasRow. | 173 // pointer to get its index in the texture, and can save storing a row numbe
r in AtlasRow. |
| 173 AtlasRow* fRows; | 174 AtlasRow* fRows; |
| 174 | 175 |
| 175 // Head and tail for linked list of least-recently-used rows (front = least
recently used). | 176 // Head and tail for linked list of least-recently-used rows (front = least
recently used). |
| 176 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. | 177 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. |
| 177 AtlasRow* fLRUFront; | 178 AtlasRow* fLRUFront; |
| 178 AtlasRow* fLRUBack; | 179 AtlasRow* fLRUBack; |
| 179 | 180 |
| 180 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key | 181 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key |
| 181 SkTDArray<AtlasRow*> fKeyTable; | 182 SkTDArray<AtlasRow*> fKeyTable; |
| 182 }; | 183 }; |
| 183 | 184 |
| 184 inline bool GrTextureStripAtlas::AtlasHashKey::Equals(const AtlasEntry& entry, | |
| 185 const AtlasHashKey& key) { | |
| 186 return entry.fKey == key; | |
| 187 } | |
| 188 | |
| 189 inline bool GrTextureStripAtlas::AtlasHashKey::LessThan(const AtlasEntry& entry, | |
| 190 const AtlasHashKey& key)
{ | |
| 191 return entry.fKey < key; | |
| 192 } | |
| 193 | |
| 194 #endif | 185 #endif |
| OLD | NEW |