| OLD | NEW |
| 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, | 20 class GrTextureStripAtlas::Hash : public SkTDynamicHash<GrTextureStripAtlas::Atl
asEntry, |
| 21 GrTextureStripAtlas::Atl
asEntry::Key> {}; | 21 GrTextureStripAtlas::Des
c> {}; |
| 22 | 22 |
| 23 int32_t GrTextureStripAtlas::gCacheCount = 0; | 23 int32_t GrTextureStripAtlas::gCacheCount = 0; |
| 24 | 24 |
| 25 GrTextureStripAtlas::Hash* GrTextureStripAtlas::gAtlasCache = NULL; | 25 GrTextureStripAtlas::Hash* GrTextureStripAtlas::gAtlasCache = NULL; |
| 26 | 26 |
| 27 GrTextureStripAtlas::Hash* GrTextureStripAtlas::GetCache() { | 27 GrTextureStripAtlas::Hash* GrTextureStripAtlas::GetCache() { |
| 28 | 28 |
| 29 if (NULL == gAtlasCache) { | 29 if (NULL == gAtlasCache) { |
| 30 gAtlasCache = SkNEW(Hash); | 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(info); | 38 SkASSERT(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); | 43 GetCache()->remove(entry->fDesc); |
| 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 AtlasEntry::Key key; | 55 AtlasEntry* entry = GetCache()->find(desc); |
| 56 key.setKeyData(desc.asKey()); | |
| 57 AtlasEntry* entry = GetCache()->find(key); | |
| 58 if (NULL == entry) { | 56 if (NULL == entry) { |
| 59 entry = SkNEW(AtlasEntry); | 57 entry = SkNEW(AtlasEntry); |
| 60 | 58 |
| 61 entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc)); | 59 entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc)); |
| 62 entry->fKey = key; | 60 entry->fDesc = desc; |
| 63 | 61 |
| 64 desc.fContext->addCleanUp(CleanUp, entry); | 62 desc.fContext->addCleanUp(CleanUp, entry); |
| 65 | 63 |
| 66 GetCache()->add(entry); | 64 GetCache()->add(entry); |
| 67 } | 65 } |
| 68 | 66 |
| 69 return entry->fAtlas; | 67 return entry->fAtlas; |
| 70 } | 68 } |
| 71 | 69 |
| 72 GrTextureStripAtlas::GrTextureStripAtlas(GrTextureStripAtlas::Desc desc) | 70 GrTextureStripAtlas::GrTextureStripAtlas(GrTextureStripAtlas::Desc desc) |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 342 |
| 345 // If we have locked rows, we should have a locked texture, otherwise | 343 // If we have locked rows, we should have a locked texture, otherwise |
| 346 // it should be unlocked | 344 // it should be unlocked |
| 347 if (fLockedRows == 0) { | 345 if (fLockedRows == 0) { |
| 348 SkASSERT(NULL == fTexture); | 346 SkASSERT(NULL == fTexture); |
| 349 } else { | 347 } else { |
| 350 SkASSERT(fTexture); | 348 SkASSERT(fTexture); |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 #endif | 351 #endif |
| OLD | NEW |