rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrTextureStripAtlas.h" |
| 10 | #include "SkPixelRef.h" |
| 11 | #include "SkTSearch.h" |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 12 | #include "GrTexture.h" |
| 13 | |
| 14 | #ifdef SK_DEBUG |
| 15 | #define VALIDATE this->validate() |
| 16 | #else |
| 17 | #define VALIDATE |
| 18 | #endif |
| 19 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 20 | class GrTextureStripAtlas::Hash : public SkTDynamicHash<GrTextureStripAtlas::AtlasEntry, |
| 21 | GrTextureStripAtlas::AtlasEntry::Key> {}; |
| 22 | |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 23 | int32_t GrTextureStripAtlas::gCacheCount = 0; |
| 24 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 25 | GrTextureStripAtlas::Hash* GrTextureStripAtlas::gAtlasCache = NULL; |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 26 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 27 | GrTextureStripAtlas::Hash* GrTextureStripAtlas::GetCache() { |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 28 | |
| 29 | if (NULL == gAtlasCache) { |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 30 | gAtlasCache = SkNEW(Hash); |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | return gAtlasCache; |
| 34 | } |
| 35 | |
| 36 | // Remove the specified atlas from the cache |
sugoi@google.com | e0e385c | 2013-03-11 18:50:03 +0000 | [diff] [blame] | 37 | void GrTextureStripAtlas::CleanUp(const GrContext*, void* info) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 38 | SkASSERT(info); |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 39 | |
| 40 | AtlasEntry* entry = static_cast<AtlasEntry*>(info); |
| 41 | |
| 42 | // remove the cache entry |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 43 | GetCache()->remove(entry->fKey); |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 44 | |
| 45 | // remove the actual entry |
| 46 | SkDELETE(entry); |
| 47 | |
| 48 | if (0 == GetCache()->count()) { |
| 49 | SkDELETE(gAtlasCache); |
| 50 | gAtlasCache = NULL; |
| 51 | } |
| 52 | } |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 53 | |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 54 | GrTextureStripAtlas* GrTextureStripAtlas::GetAtlas(const GrTextureStripAtlas::Desc& desc) { |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 55 | AtlasEntry::Key key; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 56 | key.setKeyData(desc.asKey()); |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 57 | AtlasEntry* entry = GetCache()->find(key); |
| 58 | if (NULL == entry) { |
| 59 | entry = SkNEW(AtlasEntry); |
| 60 | |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 61 | entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc)); |
| 62 | entry->fKey = key; |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 63 | |
| 64 | desc.fContext->addCleanUp(CleanUp, entry); |
| 65 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 66 | GetCache()->add(entry); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 67 | } |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 68 | |
| 69 | return entry->fAtlas; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 70 | } |
| 71 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | GrTextureStripAtlas::GrTextureStripAtlas(GrTextureStripAtlas::Desc desc) |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 73 | : fCacheKey(sk_atomic_inc(&gCacheCount)) |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 74 | , fLockedRows(0) |
| 75 | , fDesc(desc) |
| 76 | , fNumRows(desc.fHeight / desc.fRowHeight) |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 77 | , fTexture(NULL) |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 78 | , fRows(SkNEW_ARRAY(AtlasRow, fNumRows)) |
| 79 | , fLRUFront(NULL) |
| 80 | , fLRUBack(NULL) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 81 | SkASSERT(fNumRows * fDesc.fRowHeight == fDesc.fHeight); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 82 | this->initLRU(); |
bsalomon | c6327a8 | 2014-10-27 12:53:08 -0700 | [diff] [blame] | 83 | fNormalizedYHeight = SK_Scalar1 / fDesc.fHeight; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 84 | VALIDATE; |
| 85 | } |
| 86 | |
| 87 | GrTextureStripAtlas::~GrTextureStripAtlas() { |
| 88 | SkDELETE_ARRAY(fRows); |
| 89 | } |
| 90 | |
| 91 | int GrTextureStripAtlas::lockRow(const SkBitmap& data) { |
| 92 | VALIDATE; |
| 93 | if (0 == fLockedRows) { |
| 94 | this->lockTexture(); |
| 95 | } |
| 96 | |
| 97 | int key = data.getGenerationID(); |
| 98 | int rowNumber = -1; |
| 99 | int index = this->searchByKey(key); |
| 100 | |
| 101 | if (index >= 0) { |
| 102 | // We already have the data in a row, so we can just return that row |
| 103 | AtlasRow* row = fKeyTable[index]; |
| 104 | if (0 == row->fLocks) { |
| 105 | this->removeFromLRU(row); |
| 106 | } |
| 107 | ++row->fLocks; |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 108 | ++fLockedRows; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 109 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 110 | // Since all the rows are always stored in a contiguous array, we can save the memory |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 111 | // required for storing row numbers and just compute it with some pointer arithmetic |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 112 | rowNumber = static_cast<int>(row - fRows); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 113 | } else { |
| 114 | // ~index is the index where we will insert the new key to keep things sorted |
| 115 | index = ~index; |
| 116 | |
| 117 | // We don't have this data cached, so pick the least recently used row to copy into |
| 118 | AtlasRow* row = this->getLRU(); |
| 119 | |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 120 | ++fLockedRows; |
| 121 | |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 122 | if (NULL == row) { |
| 123 | // force a flush, which should unlock all the rows; then try again |
| 124 | fDesc.fContext->flush(); |
| 125 | row = this->getLRU(); |
| 126 | if (NULL == row) { |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 127 | --fLockedRows; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 128 | return -1; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | this->removeFromLRU(row); |
| 133 | |
| 134 | uint32_t oldKey = row->fKey; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 135 | |
| 136 | // If we are writing into a row that already held bitmap data, we need to remove the |
| 137 | // reference to that genID which is stored in our sorted table of key values. |
| 138 | if (oldKey != kEmptyAtlasRowKey) { |
| 139 | |
| 140 | // Find the entry in the list; if it's before the index where we plan on adding the new |
| 141 | // entry, we decrement since it will shift elements ahead of it back by one. |
| 142 | int oldIndex = this->searchByKey(oldKey); |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 143 | if (oldIndex < index) { |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 144 | --index; |
| 145 | } |
| 146 | |
| 147 | fKeyTable.remove(oldIndex); |
| 148 | } |
| 149 | |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 150 | row->fKey = key; |
| 151 | row->fLocks = 1; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 152 | fKeyTable.insert(index, 1, &row); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 153 | rowNumber = static_cast<int>(row - fRows); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 154 | |
| 155 | SkAutoLockPixels lock(data); |
| 156 | |
| 157 | // Pass in the kDontFlush flag, since we know we're writing to a part of this texture |
| 158 | // that is not currently in use |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 159 | fTexture->writePixels(0, rowNumber * fDesc.fRowHeight, |
| 160 | fDesc.fWidth, fDesc.fRowHeight, |
| 161 | SkImageInfo2GrPixelConfig(data.info()), |
| 162 | data.getPixels(), |
| 163 | data.rowBytes(), |
| 164 | GrContext::kDontFlush_PixelOpsFlag); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 165 | } |
| 166 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 167 | SkASSERT(rowNumber >= 0); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 168 | VALIDATE; |
| 169 | return rowNumber; |
| 170 | } |
| 171 | |
| 172 | void GrTextureStripAtlas::unlockRow(int row) { |
| 173 | VALIDATE; |
| 174 | --fRows[row].fLocks; |
| 175 | --fLockedRows; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 176 | SkASSERT(fRows[row].fLocks >= 0 && fLockedRows >= 0); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 177 | if (0 == fRows[row].fLocks) { |
| 178 | this->appendLRU(fRows + row); |
| 179 | } |
| 180 | if (0 == fLockedRows) { |
| 181 | this->unlockTexture(); |
| 182 | } |
| 183 | VALIDATE; |
| 184 | } |
| 185 | |
| 186 | GrTextureStripAtlas::AtlasRow* GrTextureStripAtlas::getLRU() { |
| 187 | // Front is least-recently-used |
| 188 | AtlasRow* row = fLRUFront; |
| 189 | return row; |
| 190 | } |
| 191 | |
| 192 | void GrTextureStripAtlas::lockTexture() { |
| 193 | GrTextureParams params; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 194 | GrSurfaceDesc texDesc; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 195 | texDesc.fWidth = fDesc.fWidth; |
| 196 | texDesc.fHeight = fDesc.fHeight; |
| 197 | texDesc.fConfig = fDesc.fConfig; |
skia.committer@gmail.com | 2859eb7 | 2012-12-21 02:01:28 +0000 | [diff] [blame] | 198 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 199 | static const GrCacheID::Domain gTextureStripAtlasDomain = GrCacheID::GenerateDomain(); |
| 200 | GrCacheID::Key key; |
| 201 | *key.fData32 = fCacheKey; |
| 202 | memset(key.fData32 + 1, 0, sizeof(key) - sizeof(uint32_t)); |
| 203 | GrCacheID cacheID(gTextureStripAtlasDomain, key); |
| 204 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 205 | fTexture = fDesc.fContext->findAndRefTexture(texDesc, cacheID, ¶ms); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 206 | if (NULL == fTexture) { |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 207 | fTexture = fDesc.fContext->createTexture(¶ms, texDesc, cacheID, NULL, 0); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 208 | // This is a new texture, so all of our cache info is now invalid |
| 209 | this->initLRU(); |
| 210 | fKeyTable.rewind(); |
| 211 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 212 | SkASSERT(fTexture); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void GrTextureStripAtlas::unlockTexture() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 216 | SkASSERT(fTexture && 0 == fLockedRows); |
robertphillips@google.com | 50a035d | 2012-09-07 19:44:33 +0000 | [diff] [blame] | 217 | fTexture->unref(); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 218 | fTexture = NULL; |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void GrTextureStripAtlas::initLRU() { |
| 222 | fLRUFront = NULL; |
| 223 | fLRUBack = NULL; |
| 224 | // Initially all the rows are in the LRU list |
| 225 | for (int i = 0; i < fNumRows; ++i) { |
| 226 | fRows[i].fKey = kEmptyAtlasRowKey; |
| 227 | fRows[i].fNext = NULL; |
| 228 | fRows[i].fPrev = NULL; |
| 229 | this->appendLRU(fRows + i); |
| 230 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 231 | SkASSERT(NULL == fLRUFront || NULL == fLRUFront->fPrev); |
| 232 | SkASSERT(NULL == fLRUBack || NULL == fLRUBack->fNext); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void GrTextureStripAtlas::appendLRU(AtlasRow* row) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 236 | SkASSERT(NULL == row->fPrev && NULL == row->fNext); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 237 | if (NULL == fLRUFront && NULL == fLRUBack) { |
| 238 | fLRUFront = row; |
| 239 | fLRUBack = row; |
| 240 | } else { |
| 241 | row->fPrev = fLRUBack; |
| 242 | fLRUBack->fNext = row; |
| 243 | fLRUBack = row; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void GrTextureStripAtlas::removeFromLRU(AtlasRow* row) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 248 | SkASSERT(row); |
| 249 | if (row->fNext && row->fPrev) { |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 250 | row->fPrev->fNext = row->fNext; |
| 251 | row->fNext->fPrev = row->fPrev; |
| 252 | } else { |
| 253 | if (NULL == row->fNext) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 254 | SkASSERT(row == fLRUBack); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 255 | fLRUBack = row->fPrev; |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 256 | if (fLRUBack) { |
| 257 | fLRUBack->fNext = NULL; |
| 258 | } |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 259 | } |
| 260 | if (NULL == row->fPrev) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 261 | SkASSERT(row == fLRUFront); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 262 | fLRUFront = row->fNext; |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 263 | if (fLRUFront) { |
| 264 | fLRUFront->fPrev = NULL; |
| 265 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 266 | } |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 267 | } |
| 268 | row->fNext = NULL; |
| 269 | row->fPrev = NULL; |
| 270 | } |
| 271 | |
| 272 | int GrTextureStripAtlas::searchByKey(uint32_t key) { |
| 273 | AtlasRow target; |
| 274 | target.fKey = key; |
bsalomon@google.com | 20f7f17 | 2013-05-17 19:05:03 +0000 | [diff] [blame] | 275 | return SkTSearch<const AtlasRow, |
| 276 | GrTextureStripAtlas::KeyLess>((const AtlasRow**)fKeyTable.begin(), |
| 277 | fKeyTable.count(), |
| 278 | &target, |
| 279 | sizeof(AtlasRow*)); |
skia.committer@gmail.com | 845220b | 2013-05-20 11:51:35 +0000 | [diff] [blame] | 280 | } |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 281 | |
| 282 | #ifdef SK_DEBUG |
| 283 | void GrTextureStripAtlas::validate() { |
| 284 | |
| 285 | // Our key table should be sorted |
| 286 | uint32_t prev = 1 > fKeyTable.count() ? 0 : fKeyTable[0]->fKey; |
| 287 | for (int i = 1; i < fKeyTable.count(); ++i) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 288 | SkASSERT(prev < fKeyTable[i]->fKey); |
| 289 | SkASSERT(fKeyTable[i]->fKey != kEmptyAtlasRowKey); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 290 | prev = fKeyTable[i]->fKey; |
| 291 | } |
| 292 | |
| 293 | int lruCount = 0; |
| 294 | // Validate LRU pointers, and count LRU entries |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 295 | SkASSERT(NULL == fLRUFront || NULL == fLRUFront->fPrev); |
| 296 | SkASSERT(NULL == fLRUBack || NULL == fLRUBack->fNext); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 297 | for (AtlasRow* r = fLRUFront; r != NULL; r = r->fNext) { |
| 298 | if (NULL == r->fNext) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 299 | SkASSERT(r == fLRUBack); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 300 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 301 | SkASSERT(r->fNext->fPrev == r); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 302 | } |
| 303 | ++lruCount; |
| 304 | } |
| 305 | |
| 306 | int rowLocks = 0; |
| 307 | int freeRows = 0; |
| 308 | |
| 309 | for (int i = 0; i < fNumRows; ++i) { |
| 310 | rowLocks += fRows[i].fLocks; |
| 311 | if (0 == fRows[i].fLocks) { |
| 312 | ++freeRows; |
| 313 | bool inLRU = false; |
| 314 | // Step through the LRU and make sure it's present |
| 315 | for (AtlasRow* r = fLRUFront; r != NULL; r = r->fNext) { |
| 316 | if (r == &fRows[i]) { |
| 317 | inLRU = true; |
| 318 | break; |
| 319 | } |
| 320 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 321 | SkASSERT(inLRU); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 322 | } else { |
| 323 | // If we are locked, we should have a key |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 324 | SkASSERT(kEmptyAtlasRowKey != fRows[i].fKey); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // If we have a key != kEmptyAtlasRowKey, it should be in the key table |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 328 | SkASSERT(fRows[i].fKey == kEmptyAtlasRowKey || this->searchByKey(fRows[i].fKey) >= 0); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 329 | } |
| 330 | |
rileya@google.com | b3e50f2 | 2012-08-20 17:43:08 +0000 | [diff] [blame] | 331 | // Our count of locks should equal the sum of row locks, unless we ran out of rows and flushed, |
| 332 | // in which case we'll have one more lock than recorded in the rows (to represent the pending |
| 333 | // lock of a row; which ensures we don't unlock the texture prematurely). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 334 | SkASSERT(rowLocks == fLockedRows || rowLocks + 1 == fLockedRows); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 335 | |
| 336 | // We should have one lru entry for each free row |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 337 | SkASSERT(freeRows == lruCount); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 338 | |
| 339 | // If we have locked rows, we should have a locked texture, otherwise |
| 340 | // it should be unlocked |
| 341 | if (fLockedRows == 0) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 342 | SkASSERT(NULL == fTexture); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 343 | } else { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 344 | SkASSERT(fTexture); |
rileya@google.com | 2e2aedc | 2012-08-13 20:28:48 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | #endif |