Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: src/gpu/effects/GrTextureStripAtlas.cpp

Issue 402693003: Replace GrTHash with SkTDynamicHash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix compiler complaints Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrTextureStripAtlas.h" 9 #include "GrTextureStripAtlas.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
11 #include "SkTSearch.h" 11 #include "SkTSearch.h"
12 #include "GrTexture.h" 12 #include "GrTexture.h"
13 13
14 #ifdef SK_DEBUG 14 #ifdef SK_DEBUG
15 #define VALIDATE this->validate() 15 #define VALIDATE this->validate()
16 #else 16 #else
17 #define VALIDATE 17 #define VALIDATE
18 #endif 18 #endif
19 19
20 class GrTextureStripAtlas::Hash : public SkTDynamicHash<GrTextureStripAtlas::Atl asEntry,
21 GrTextureStripAtlas::Atl asEntry::Key> {};
22
20 int32_t GrTextureStripAtlas::gCacheCount = 0; 23 int32_t GrTextureStripAtlas::gCacheCount = 0;
21 24
22 GrTHashTable<GrTextureStripAtlas::AtlasEntry, 25 GrTextureStripAtlas::Hash* GrTextureStripAtlas::gAtlasCache = NULL;
23 GrTextureStripAtlas::AtlasHashKey, 8>*
24 GrTextureStripAtlas::gAtlasCache = NULL;
25 26
26 GrTHashTable<GrTextureStripAtlas::AtlasEntry, GrTextureStripAtlas::AtlasHashKey, 8>* 27 GrTextureStripAtlas::Hash* GrTextureStripAtlas::GetCache() {
27 GrTextureStripAtlas::GetCache() {
28 28
29 if (NULL == gAtlasCache) { 29 if (NULL == gAtlasCache) {
30 gAtlasCache = SkNEW((GrTHashTable<AtlasEntry, AtlasHashKey, 8>)); 30 gAtlasCache = SkNEW(Hash);
31 } 31 }
32 32
33 return gAtlasCache; 33 return gAtlasCache;
34 } 34 }
35 35
36 // Remove the specified atlas from the cache 36 // Remove the specified atlas from the cache
37 void GrTextureStripAtlas::CleanUp(const GrContext*, void* info) { 37 void GrTextureStripAtlas::CleanUp(const GrContext*, void* info) {
38 SkASSERT(NULL != info); 38 SkASSERT(NULL != info);
39 39
40 AtlasEntry* entry = static_cast<AtlasEntry*>(info); 40 AtlasEntry* entry = static_cast<AtlasEntry*>(info);
41 41
42 // remove the cache entry 42 // remove the cache entry
43 GetCache()->remove(entry->fKey, entry); 43 GetCache()->remove(entry->fKey);
44 44
45 // remove the actual entry 45 // remove the actual entry
46 SkDELETE(entry); 46 SkDELETE(entry);
47 47
48 if (0 == GetCache()->count()) { 48 if (0 == GetCache()->count()) {
49 SkDELETE(gAtlasCache); 49 SkDELETE(gAtlasCache);
50 gAtlasCache = NULL; 50 gAtlasCache = NULL;
51 } 51 }
52 } 52 }
53 53
54 GrTextureStripAtlas* GrTextureStripAtlas::GetAtlas(const GrTextureStripAtlas::De sc& desc) { 54 GrTextureStripAtlas* GrTextureStripAtlas::GetAtlas(const GrTextureStripAtlas::De sc& desc) {
55 AtlasHashKey key; 55 AtlasEntry::Key key;
56 key.setKeyData(desc.asKey()); 56 key.setKeyData(desc.asKey());
57 AtlasEntry* entry = GetCache()->find(key); 57 AtlasEntry* entry = GetCache()->find(key);
58 if (NULL == entry) { 58 if (NULL == entry) {
59 entry = SkNEW(AtlasEntry); 59 entry = SkNEW(AtlasEntry);
60 60
61 entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc)); 61 entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc));
62 entry->fKey = key; 62 entry->fKey = key;
63 63
64 desc.fContext->addCleanUp(CleanUp, entry); 64 desc.fContext->addCleanUp(CleanUp, entry);
65 65
66 GetCache()->insert(key, entry); 66 GetCache()->add(entry);
67 } 67 }
68 68
69 return entry->fAtlas; 69 return entry->fAtlas;
70 } 70 }
71 71
72 GrTextureStripAtlas::GrTextureStripAtlas(GrTextureStripAtlas::Desc desc) 72 GrTextureStripAtlas::GrTextureStripAtlas(GrTextureStripAtlas::Desc desc)
73 : fCacheKey(sk_atomic_inc(&gCacheCount)) 73 : fCacheKey(sk_atomic_inc(&gCacheCount))
74 , fLockedRows(0) 74 , fLockedRows(0)
75 , fDesc(desc) 75 , fDesc(desc)
76 , fNumRows(desc.fHeight / desc.fRowHeight) 76 , fNumRows(desc.fHeight / desc.fRowHeight)
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 // If we have locked rows, we should have a locked texture, otherwise 340 // If we have locked rows, we should have a locked texture, otherwise
341 // it should be unlocked 341 // it should be unlocked
342 if (fLockedRows == 0) { 342 if (fLockedRows == 0) {
343 SkASSERT(NULL == fTexture); 343 SkASSERT(NULL == fTexture);
344 } else { 344 } else {
345 SkASSERT(NULL != fTexture); 345 SkASSERT(NULL != fTexture);
346 } 346 }
347 } 347 }
348 #endif 348 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698