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 uint16_t fWidth, fHeight, fRowHeight; | 29 uint16_t fWidth, fHeight, fRowHeight; |
mtklein
2015/07/13 19:26:11
It might be a good idea to explicitly add
uint1
| |
30 GrPixelConfig fConfig; | 30 GrPixelConfig fConfig; |
31 GrContext* fContext; | 31 GrContext* fContext; |
32 const uint32_t* asKey() const { return reinterpret_cast<const uint32_t*> (this); } | 32 bool operator==(const Desc& other) const { |
33 return 0 == memcmp(this, &other, sizeof(Desc)); | |
34 } | |
33 }; | 35 }; |
34 | 36 |
35 /** | 37 /** |
36 * Try to find an atlas with the required parameters, creates a new one if n ecessary | 38 * Try to find an atlas with the required parameters, creates a new one if n ecessary |
37 */ | 39 */ |
38 static GrTextureStripAtlas* GetAtlas(const Desc& desc); | 40 static GrTextureStripAtlas* GetAtlas(const Desc& desc); |
39 | 41 |
40 ~GrTextureStripAtlas(); | 42 ~GrTextureStripAtlas(); |
41 | 43 |
42 /** | 44 /** |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 /** | 133 /** |
132 * Clean up callback registered with GrContext. Allows this class to | 134 * Clean up callback registered with GrContext. Allows this class to |
133 * free up any allocated AtlasEntry and GrTextureStripAtlas objects | 135 * free up any allocated AtlasEntry and GrTextureStripAtlas objects |
134 */ | 136 */ |
135 static void CleanUp(const GrContext* context, void* info); | 137 static void CleanUp(const GrContext* context, void* info); |
136 | 138 |
137 // Hash table entry for atlases | 139 // Hash table entry for atlases |
138 class AtlasEntry : public ::SkNoncopyable { | 140 class AtlasEntry : public ::SkNoncopyable { |
139 public: | 141 public: |
140 // for SkTDynamicHash | 142 // for SkTDynamicHash |
141 class Key : public GrMurmur3HashKey<sizeof(GrTextureStripAtlas::Desc)> { }; | 143 static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc; } |
142 static const Key& GetKey(const AtlasEntry& entry) { return entry.fKey; } | 144 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 | 145 |
145 // AtlasEntry proper | 146 // AtlasEntry proper |
146 AtlasEntry() : fAtlas(NULL) {} | 147 AtlasEntry() : fAtlas(NULL) {} |
147 ~AtlasEntry() { SkDELETE(fAtlas); } | 148 ~AtlasEntry() { SkDELETE(fAtlas); } |
148 Key fKey; | 149 Desc fDesc; |
149 GrTextureStripAtlas* fAtlas; | 150 GrTextureStripAtlas* fAtlas; |
150 }; | 151 }; |
151 | 152 |
152 class Hash; | 153 class Hash; |
153 static Hash* gAtlasCache; | 154 static Hash* gAtlasCache; |
154 | 155 |
155 static Hash* GetCache(); | 156 static Hash* GetCache(); |
156 | 157 |
157 // We increment gCacheCount for each atlas | 158 // We increment gCacheCount for each atlas |
158 static int32_t gCacheCount; | 159 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). | 179 // 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. | 180 // Note that when a texture is locked, it gets removed from this list until it is unlocked. |
180 AtlasRow* fLRUFront; | 181 AtlasRow* fLRUFront; |
181 AtlasRow* fLRUBack; | 182 AtlasRow* fLRUBack; |
182 | 183 |
183 // A list of pointers to AtlasRows that currently contain cached images, sor ted by key | 184 // A list of pointers to AtlasRows that currently contain cached images, sor ted by key |
184 SkTDArray<AtlasRow*> fKeyTable; | 185 SkTDArray<AtlasRow*> fKeyTable; |
185 }; | 186 }; |
186 | 187 |
187 #endif | 188 #endif |
OLD | NEW |