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 "GrMurmur3HashKey.h" | |
12 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkChecksum.h" |
13 #include "SkGr.h" | 13 #include "SkGr.h" |
14 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
15 #include "SkTDynamicHash.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 |
26 **/ | 26 **/ |
27 struct Desc { | 27 struct Desc { |
28 Desc() { memset(this, 0, sizeof(*this)); } | 28 Desc() { sk_bzero(this, sizeof(*this)); } |
| 29 GrContext* fContext; |
| 30 GrPixelConfig fConfig; |
29 uint16_t fWidth, fHeight, fRowHeight; | 31 uint16_t fWidth, fHeight, fRowHeight; |
30 GrPixelConfig fConfig; | 32 uint16_t fUnusedPadding; |
31 GrContext* fContext; | 33 bool operator==(const Desc& other) const { |
32 const uint32_t* asKey() const { return reinterpret_cast<const uint32_t*>
(this); } | 34 return 0 == memcmp(this, &other, sizeof(Desc)); |
| 35 } |
33 }; | 36 }; |
34 | 37 |
35 /** | 38 /** |
36 * Try to find an atlas with the required parameters, creates a new one if n
ecessary | 39 * Try to find an atlas with the required parameters, creates a new one if n
ecessary |
37 */ | 40 */ |
38 static GrTextureStripAtlas* GetAtlas(const Desc& desc); | 41 static GrTextureStripAtlas* GetAtlas(const Desc& desc); |
39 | 42 |
40 ~GrTextureStripAtlas(); | 43 ~GrTextureStripAtlas(); |
41 | 44 |
42 /** | 45 /** |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 /** | 134 /** |
132 * Clean up callback registered with GrContext. Allows this class to | 135 * Clean up callback registered with GrContext. Allows this class to |
133 * free up any allocated AtlasEntry and GrTextureStripAtlas objects | 136 * free up any allocated AtlasEntry and GrTextureStripAtlas objects |
134 */ | 137 */ |
135 static void CleanUp(const GrContext* context, void* info); | 138 static void CleanUp(const GrContext* context, void* info); |
136 | 139 |
137 // Hash table entry for atlases | 140 // Hash table entry for atlases |
138 class AtlasEntry : public ::SkNoncopyable { | 141 class AtlasEntry : public ::SkNoncopyable { |
139 public: | 142 public: |
140 // for SkTDynamicHash | 143 // for SkTDynamicHash |
141 class Key : public GrMurmur3HashKey<sizeof(GrTextureStripAtlas::Desc)> {
}; | 144 static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc;
} |
142 static const Key& GetKey(const AtlasEntry& entry) { return entry.fKey; } | 145 static uint32_t Hash(const Desc& desc) { return SkChecksum::Murmur3(&des
c, sizeof(Desc)); } |
143 static uint32_t Hash(const Key& key) { return key.getHash(); } | |
144 | 146 |
145 // AtlasEntry proper | 147 // AtlasEntry proper |
146 AtlasEntry() : fAtlas(NULL) {} | 148 AtlasEntry() : fAtlas(NULL) {} |
147 ~AtlasEntry() { SkDELETE(fAtlas); } | 149 ~AtlasEntry() { SkDELETE(fAtlas); } |
148 Key fKey; | 150 Desc fDesc; |
149 GrTextureStripAtlas* fAtlas; | 151 GrTextureStripAtlas* fAtlas; |
150 }; | 152 }; |
151 | 153 |
152 class Hash; | 154 class Hash; |
153 static Hash* gAtlasCache; | 155 static Hash* gAtlasCache; |
154 | 156 |
155 static Hash* GetCache(); | 157 static Hash* GetCache(); |
156 | 158 |
157 // We increment gCacheCount for each atlas | 159 // We increment gCacheCount for each atlas |
158 static int32_t gCacheCount; | 160 static int32_t gCacheCount; |
(...skipping 19 matching lines...) Expand all Loading... |
178 // 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). |
179 // 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. |
180 AtlasRow* fLRUFront; | 182 AtlasRow* fLRUFront; |
181 AtlasRow* fLRUBack; | 183 AtlasRow* fLRUBack; |
182 | 184 |
183 // 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 |
184 SkTDArray<AtlasRow*> fKeyTable; | 186 SkTDArray<AtlasRow*> fKeyTable; |
185 }; | 187 }; |
186 | 188 |
187 #endif | 189 #endif |
OLD | NEW |