| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #ifndef GrTextureStripAtlas_DEFINED | 8 #ifndef GrTextureStripAtlas_DEFINED |
| 10 #define GrTextureStripAtlas_DEFINED | 9 #define GrTextureStripAtlas_DEFINED |
| 11 | 10 |
| 11 #include "GrBinHashKey.h" |
| 12 #include "GrTHashCache.h" |
| 12 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
| 13 #include "GrTHashCache.h" | |
| 14 #include "SkGr.h" | 14 #include "SkGr.h" |
| 15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 16 #include "GrBinHashKey.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 |
| 26 **/ | 26 **/ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 | 74 |
| 75 // Key to indicate an atlas row without any meaningful data stored in it | 75 // Key to indicate an atlas row without any meaningful data stored in it |
| 76 const static uint32_t kEmptyAtlasRowKey = 0xffffffff; | 76 const static uint32_t kEmptyAtlasRowKey = 0xffffffff; |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * The state of a single row in our cache, next/prev pointers allow these to
be chained | 79 * The state of a single row in our cache, next/prev pointers allow these to
be chained |
| 80 * together to represent LRU status | 80 * together to represent LRU status |
| 81 */ | 81 */ |
| 82 struct AtlasRow : public GrNoncopyable { | 82 struct AtlasRow : public SkNoncopyable { |
| 83 AtlasRow() : fKey(kEmptyAtlasRowKey), fLocks(0), fNext(NULL), fPrev(NULL
) { } | 83 AtlasRow() : fKey(kEmptyAtlasRowKey), fLocks(0), fNext(NULL), fPrev(NULL
) { } |
| 84 // GenerationID of the bitmap that is represented by this row, 0xfffffff
f means "empty" | 84 // GenerationID of the bitmap that is represented by this row, 0xfffffff
f means "empty" |
| 85 uint32_t fKey; | 85 uint32_t fKey; |
| 86 // How many times this has been locked (0 == unlocked) | 86 // How many times this has been locked (0 == unlocked) |
| 87 int32_t fLocks; | 87 int32_t fLocks; |
| 88 // We maintain an LRU linked list between unlocked nodes with these poin
ters | 88 // We maintain an LRU linked list between unlocked nodes with these poin
ters |
| 89 AtlasRow* fNext; | 89 AtlasRow* fNext; |
| 90 AtlasRow* fPrev; | 90 AtlasRow* fPrev; |
| 91 }; | 91 }; |
| 92 | 92 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | 138 class AtlasEntry; |
| 139 typedef GrTBinHashKey<AtlasEntry, sizeof(GrTextureStripAtlas::Desc)> AtlasHa
shKey; | 139 typedef GrTBinHashKey<AtlasEntry, sizeof(GrTextureStripAtlas::Desc)> AtlasHa
shKey; |
| 140 class AtlasEntry : public ::GrNoncopyable { | 140 class AtlasEntry : public ::SkNoncopyable { |
| 141 public: | 141 public: |
| 142 AtlasEntry() : fAtlas(NULL) {} | 142 AtlasEntry() : fAtlas(NULL) {} |
| 143 ~AtlasEntry() { SkDELETE(fAtlas); } | 143 ~AtlasEntry() { SkDELETE(fAtlas); } |
| 144 int compare(const AtlasHashKey& key) const { return fKey.compare(key); } | 144 int compare(const AtlasHashKey& key) const { return fKey.compare(key); } |
| 145 AtlasHashKey fKey; | 145 AtlasHashKey fKey; |
| 146 GrTextureStripAtlas* fAtlas; | 146 GrTextureStripAtlas* fAtlas; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* gAtlasCache; | 149 static GrTHashTable<AtlasEntry, AtlasHashKey, 8>* gAtlasCache; |
| 150 | 150 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 172 // Head and tail for linked list of least-recently-used rows (front = least
recently used). | 172 // Head and tail for linked list of least-recently-used rows (front = least
recently used). |
| 173 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. | 173 // Note that when a texture is locked, it gets removed from this list until
it is unlocked. |
| 174 AtlasRow* fLRUFront; | 174 AtlasRow* fLRUFront; |
| 175 AtlasRow* fLRUBack; | 175 AtlasRow* fLRUBack; |
| 176 | 176 |
| 177 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key | 177 // A list of pointers to AtlasRows that currently contain cached images, sor
ted by key |
| 178 SkTDArray<AtlasRow*> fKeyTable; | 178 SkTDArray<AtlasRow*> fKeyTable; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 #endif | 181 #endif |
| OLD | NEW |