| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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(NULL != 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->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()) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 memset(key.fData32 + 1, 0, sizeof(key) - sizeof(uint32_t)); | 202 memset(key.fData32 + 1, 0, sizeof(key) - sizeof(uint32_t)); |
| 203 GrCacheID cacheID(gTextureStripAtlasDomain, key); | 203 GrCacheID cacheID(gTextureStripAtlasDomain, key); |
| 204 | 204 |
| 205 fTexture = fDesc.fContext->findAndRefTexture(texDesc, cacheID, ¶ms); | 205 fTexture = fDesc.fContext->findAndRefTexture(texDesc, cacheID, ¶ms); |
| 206 if (NULL == fTexture) { | 206 if (NULL == fTexture) { |
| 207 fTexture = fDesc.fContext->createTexture(¶ms, texDesc, cacheID, NULL
, 0); | 207 fTexture = fDesc.fContext->createTexture(¶ms, texDesc, cacheID, NULL
, 0); |
| 208 // This is a new texture, so all of our cache info is now invalid | 208 // This is a new texture, so all of our cache info is now invalid |
| 209 this->initLRU(); | 209 this->initLRU(); |
| 210 fKeyTable.rewind(); | 210 fKeyTable.rewind(); |
| 211 } | 211 } |
| 212 SkASSERT(NULL != fTexture); | 212 SkASSERT(fTexture); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void GrTextureStripAtlas::unlockTexture() { | 215 void GrTextureStripAtlas::unlockTexture() { |
| 216 SkASSERT(NULL != fTexture && 0 == fLockedRows); | 216 SkASSERT(fTexture && 0 == fLockedRows); |
| 217 fTexture->unref(); | 217 fTexture->unref(); |
| 218 fTexture = NULL; | 218 fTexture = NULL; |
| 219 fDesc.fContext->purgeCache(); | 219 fDesc.fContext->purgeCache(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void GrTextureStripAtlas::initLRU() { | 222 void GrTextureStripAtlas::initLRU() { |
| 223 fLRUFront = NULL; | 223 fLRUFront = NULL; |
| 224 fLRUBack = NULL; | 224 fLRUBack = NULL; |
| 225 // Initially all the rows are in the LRU list | 225 // Initially all the rows are in the LRU list |
| 226 for (int i = 0; i < fNumRows; ++i) { | 226 for (int i = 0; i < fNumRows; ++i) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 239 fLRUFront = row; | 239 fLRUFront = row; |
| 240 fLRUBack = row; | 240 fLRUBack = row; |
| 241 } else { | 241 } else { |
| 242 row->fPrev = fLRUBack; | 242 row->fPrev = fLRUBack; |
| 243 fLRUBack->fNext = row; | 243 fLRUBack->fNext = row; |
| 244 fLRUBack = row; | 244 fLRUBack = row; |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 void GrTextureStripAtlas::removeFromLRU(AtlasRow* row) { | 248 void GrTextureStripAtlas::removeFromLRU(AtlasRow* row) { |
| 249 SkASSERT(NULL != row); | 249 SkASSERT(row); |
| 250 if (NULL != row->fNext && NULL != row->fPrev) { | 250 if (row->fNext && row->fPrev) { |
| 251 row->fPrev->fNext = row->fNext; | 251 row->fPrev->fNext = row->fNext; |
| 252 row->fNext->fPrev = row->fPrev; | 252 row->fNext->fPrev = row->fPrev; |
| 253 } else { | 253 } else { |
| 254 if (NULL == row->fNext) { | 254 if (NULL == row->fNext) { |
| 255 SkASSERT(row == fLRUBack); | 255 SkASSERT(row == fLRUBack); |
| 256 fLRUBack = row->fPrev; | 256 fLRUBack = row->fPrev; |
| 257 if (fLRUBack) { | 257 if (fLRUBack) { |
| 258 fLRUBack->fNext = NULL; | 258 fLRUBack->fNext = NULL; |
| 259 } | 259 } |
| 260 } | 260 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 SkASSERT(rowLocks == fLockedRows || rowLocks + 1 == fLockedRows); | 335 SkASSERT(rowLocks == fLockedRows || rowLocks + 1 == fLockedRows); |
| 336 | 336 |
| 337 // We should have one lru entry for each free row | 337 // We should have one lru entry for each free row |
| 338 SkASSERT(freeRows == lruCount); | 338 SkASSERT(freeRows == lruCount); |
| 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(fTexture); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 #endif | 348 #endif |
| OLD | NEW |