aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltexturecache.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2010-02-08 17:01:00 -0600
committerJacek Antonelli2010-02-08 17:01:00 -0600
commitd96e672c7fa0cb59ef0c30163326bb40220e745a (patch)
tree0578f6258788f44f91dbf84eebdb09d994e2a0e5 /linden/indra/newview/lltexturecache.cpp
parentFixed login screen only allowing 16 chars per name. (diff)
downloadmeta-impy-d96e672c7fa0cb59ef0c30163326bb40220e745a.zip
meta-impy-d96e672c7fa0cb59ef0c30163326bb40220e745a.tar.gz
meta-impy-d96e672c7fa0cb59ef0c30163326bb40220e745a.tar.bz2
meta-impy-d96e672c7fa0cb59ef0c30163326bb40220e745a.tar.xz
Ported many APR changes from Snowglobe.
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lltexturecache.cpp73
1 files changed, 30 insertions, 43 deletions
diff --git a/linden/indra/newview/lltexturecache.cpp b/linden/indra/newview/lltexturecache.cpp
index 3b724e2..9c3bed2 100644
--- a/linden/indra/newview/lltexturecache.cpp
+++ b/linden/indra/newview/lltexturecache.cpp
@@ -175,7 +175,7 @@ private:
175 175
176bool LLTextureCacheLocalFileWorker::doRead() 176bool LLTextureCacheLocalFileWorker::doRead()
177{ 177{
178 S32 local_size = LLAPRFile::size(mFileName, mCache->getLocalAPRFilePool()); 178 S32 local_size = LLAPRFile::size(mFileName);
179 179
180 if (local_size > 0 && mFileName.size() > 4) 180 if (local_size > 0 && mFileName.size() > 4)
181 { 181 {
@@ -249,7 +249,7 @@ bool LLTextureCacheLocalFileWorker::doRead()
249 } 249 }
250 mReadData = new U8[mDataSize]; 250 mReadData = new U8[mDataSize];
251 251
252 S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool()); 252 S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize);
253 253
254 if (bytes_read != mDataSize) 254 if (bytes_read != mDataSize)
255 { 255 {
@@ -318,11 +318,11 @@ bool LLTextureCacheRemoteWorker::doRead()
318 { 318 {
319 std::string filename = mCache->getLocalFileName(mID); 319 std::string filename = mCache->getLocalFileName(mID);
320 local_filename = filename + ".j2c"; 320 local_filename = filename + ".j2c";
321 local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool()); 321 local_size = LLAPRFile::size(local_filename);
322 if (local_size == 0) 322 if (local_size == 0)
323 { 323 {
324 local_filename = filename + ".tga"; 324 local_filename = filename + ".tga";
325 local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool()); 325 local_size = LLAPRFile::size(local_filename);
326 if (local_size > 0) 326 if (local_size > 0)
327 { 327 {
328 mImageFormat = IMG_CODEC_TGA; 328 mImageFormat = IMG_CODEC_TGA;
@@ -390,8 +390,7 @@ bool LLTextureCacheRemoteWorker::doRead()
390 mDataSize = local_size; 390 mDataSize = local_size;
391 } 391 }
392 mReadData = new U8[mDataSize]; 392 mReadData = new U8[mDataSize];
393 S32 bytes_read = LLAPRFile::readEx(local_filename, 393 S32 bytes_read = LLAPRFile::readEx(local_filename, mReadData, mOffset, mDataSize);
394 mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool());
395 if (bytes_read != mDataSize) 394 if (bytes_read != mDataSize)
396 { 395 {
397// llwarns << "Error reading file from local cache: " << local_filename 396// llwarns << "Error reading file from local cache: " << local_filename
@@ -485,7 +484,7 @@ bool LLTextureCacheRemoteWorker::doRead()
485 S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset; 484 S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset;
486 mReadData = new U8[size]; 485 mReadData = new U8[size];
487 S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName, 486 S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName,
488 mReadData, offset, size, mCache->getLocalAPRFilePool()); 487 mReadData, offset, size);
489 if (bytes_read != size) 488 if (bytes_read != size)
490 { 489 {
491// llwarns << "LLTextureCacheWorker: " << mID 490// llwarns << "LLTextureCacheWorker: " << mID
@@ -511,7 +510,7 @@ bool LLTextureCacheRemoteWorker::doRead()
511 if (mFileHandle == LLLFSThread::nullHandle()) 510 if (mFileHandle == LLLFSThread::nullHandle())
512 { 511 {
513 std::string filename = mCache->getTextureFileName(mID); 512 std::string filename = mCache->getTextureFileName(mID);
514 S32 filesize = LLAPRFile::size(filename, mCache->getLocalAPRFilePool()); 513 S32 filesize = LLAPRFile::size(filename);
515 if (filesize > mOffset) 514 if (filesize > mOffset)
516 { 515 {
517 S32 datasize = TEXTURE_CACHE_ENTRY_SIZE + filesize; 516 S32 datasize = TEXTURE_CACHE_ENTRY_SIZE + filesize;
@@ -570,7 +569,7 @@ bool LLTextureCacheRemoteWorker::doRead()
570 } 569 }
571#else 570#else
572 std::string filename = mCache->getTextureFileName(mID); 571 std::string filename = mCache->getTextureFileName(mID);
573 S32 filesize = LLAPRFile::size(filename, mCache->getLocalAPRFilePool()); 572 S32 filesize = LLAPRFile::size(filename);
574 S32 bytes_read = 0; 573 S32 bytes_read = 0;
575 if (filesize > mOffset) 574 if (filesize > mOffset)
576 { 575 {
@@ -592,8 +591,7 @@ bool LLTextureCacheRemoteWorker::doRead()
592 mReadData = data; 591 mReadData = data;
593 bytes_read = LLAPRFile::readEx(filename, 592 bytes_read = LLAPRFile::readEx(filename,
594 mReadData + data_offset, 593 mReadData + data_offset,
595 file_offset, file_size, 594 file_offset, file_size);
596 mCache->getLocalAPRFilePool());
597 if (bytes_read != file_size) 595 if (bytes_read != file_size)
598 { 596 {
599// llwarns << "LLTextureCacheWorker: " << mID 597// llwarns << "LLTextureCacheWorker: " << mID
@@ -696,7 +694,7 @@ bool LLTextureCacheRemoteWorker::doWrite()
696 llassert_always(mOffset < TEXTURE_CACHE_ENTRY_SIZE); 694 llassert_always(mOffset < TEXTURE_CACHE_ENTRY_SIZE);
697 S32 offset = idx * TEXTURE_CACHE_ENTRY_SIZE + mOffset; 695 S32 offset = idx * TEXTURE_CACHE_ENTRY_SIZE + mOffset;
698 S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset; 696 S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset;
699 S32 bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size, mCache->getLocalAPRFilePool()); 697 S32 bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size);
700 698
701 if (bytes_written <= 0) 699 if (bytes_written <= 0)
702 { 700 {
@@ -774,8 +772,7 @@ bool LLTextureCacheRemoteWorker::doWrite()
774 772
775 bytes_written = LLAPRFile::writeEx(filename, 773 bytes_written = LLAPRFile::writeEx(filename,
776 mWriteData + data_offset, 774 mWriteData + data_offset,
777 file_offset, file_size, 775 file_offset, file_size);
778 mCache->getLocalAPRFilePool());
779 if (bytes_written <= 0) 776 if (bytes_written <= 0)
780 { 777 {
781 mDataSize = -1; // failed 778 mDataSize = -1; // failed
@@ -975,8 +972,7 @@ bool LLTextureCache::appendToTextureEntryList(const LLUUID& id, S32 bodysize)
975 Entry* entry = new Entry(id, bodysize, time(NULL)); 972 Entry* entry = new Entry(id, bodysize, time(NULL));
976 973
977 LLAPRFile::writeEx(mTexturesDirEntriesFileName, 974 LLAPRFile::writeEx(mTexturesDirEntriesFileName,
978 (U8*)entry, -1, 1*sizeof(Entry), 975 (U8*)entry, -1, 1*sizeof(Entry));
979 getLocalAPRFilePool());
980 delete entry; 976 delete entry;
981 if (iter != mTexturesSizeMap.end()) 977 if (iter != mTexturesSizeMap.end())
982 { 978 {
@@ -1024,8 +1020,8 @@ void LLTextureCache::purgeCache(ELLPath location)
1024 { 1020 {
1025 setDirNames(location); 1021 setDirNames(location);
1026 1022
1027 LLAPRFile::remove(mHeaderEntriesFileName, getLocalAPRFilePool()); 1023 LLAPRFile::remove(mHeaderEntriesFileName);
1028 LLAPRFile::remove(mHeaderDataFileName, getLocalAPRFilePool()); 1024 LLAPRFile::remove(mHeaderDataFileName);
1029 } 1025 }
1030 purgeAllTextures(true); 1026 purgeAllTextures(true);
1031} 1027}
@@ -1092,11 +1088,10 @@ void LLTextureCache::readHeaderCache()
1092 LLMutexLock lock(&mHeaderMutex); 1088 LLMutexLock lock(&mHeaderMutex);
1093 mHeaderEntriesInfo.mVersion = 0.f; 1089 mHeaderEntriesInfo.mVersion = 0.f;
1094 mHeaderEntriesInfo.mEntries = 0; 1090 mHeaderEntriesInfo.mEntries = 0;
1095 if (LLAPRFile::isExist(mHeaderEntriesFileName, getLocalAPRFilePool())) 1091 if (LLAPRFile::isExist(mHeaderEntriesFileName))
1096 { 1092 {
1097 LLAPRFile::readEx(mHeaderEntriesFileName, 1093 LLAPRFile::readEx(mHeaderEntriesFileName,
1098 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), 1094 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo));
1099 getLocalAPRFilePool());
1100 } 1095 }
1101 if (mHeaderEntriesInfo.mVersion != sHeaderCacheVersion) 1096 if (mHeaderEntriesInfo.mVersion != sHeaderCacheVersion)
1102 { 1097 {
@@ -1106,8 +1101,7 @@ void LLTextureCache::readHeaderCache()
1106 mHeaderEntriesInfo.mVersion = sHeaderCacheVersion; 1101 mHeaderEntriesInfo.mVersion = sHeaderCacheVersion;
1107 1102
1108 LLAPRFile::writeEx(mHeaderEntriesFileName, 1103 LLAPRFile::writeEx(mHeaderEntriesFileName,
1109 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), 1104 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo));
1110 getLocalAPRFilePool());
1111 } 1105 }
1112 } 1106 }
1113 else 1107 else
@@ -1118,8 +1112,7 @@ void LLTextureCache::readHeaderCache()
1118 Entry* entries = new Entry[num_entries]; 1112 Entry* entries = new Entry[num_entries];
1119 { 1113 {
1120 LLAPRFile::readEx(mHeaderEntriesFileName, 1114 LLAPRFile::readEx(mHeaderEntriesFileName,
1121 (U8*)entries, sizeof(EntriesInfo), num_entries*sizeof(Entry), 1115 (U8*)entries, sizeof(EntriesInfo), num_entries*sizeof(Entry));
1122 getLocalAPRFilePool());
1123 } 1116 }
1124 typedef std::set<lru_data*, lru_data::Compare> lru_set_t; 1117 typedef std::set<lru_data*, lru_data::Compare> lru_set_t;
1125 lru_set_t lru; 1118 lru_set_t lru;
@@ -1165,7 +1158,7 @@ void LLTextureCache::purgeAllTextures(bool purge_directories)
1165 LLFile::rmdir(dirname); 1158 LLFile::rmdir(dirname);
1166 } 1159 }
1167 } 1160 }
1168 LLAPRFile::remove(mTexturesDirEntriesFileName, getLocalAPRFilePool()); 1161 LLAPRFile::remove(mTexturesDirEntriesFileName);
1169 if (purge_directories) 1162 if (purge_directories)
1170 { 1163 {
1171 LLFile::rmdir(mTexturesDirName); 1164 LLFile::rmdir(mTexturesDirName);
@@ -1186,7 +1179,7 @@ void LLTextureCache::purgeTextures(bool validate)
1186 1179
1187 LLMutexLock lock(&mHeaderMutex); 1180 LLMutexLock lock(&mHeaderMutex);
1188 1181
1189 S32 filesize = LLAPRFile::size(mTexturesDirEntriesFileName, getLocalAPRFilePool()); 1182 S32 filesize = LLAPRFile::size(mTexturesDirEntriesFileName);
1190 S32 num_entries = filesize / sizeof(Entry); 1183 S32 num_entries = filesize / sizeof(Entry);
1191 if (num_entries * (S32)sizeof(Entry) != filesize) 1184 if (num_entries * (S32)sizeof(Entry) != filesize)
1192 { 1185 {
@@ -1201,8 +1194,7 @@ void LLTextureCache::purgeTextures(bool validate)
1201 1194
1202 Entry* entries = new Entry[num_entries]; 1195 Entry* entries = new Entry[num_entries];
1203 S32 bytes_read = LLAPRFile::readEx(mTexturesDirEntriesFileName, 1196 S32 bytes_read = LLAPRFile::readEx(mTexturesDirEntriesFileName,
1204 (U8*)entries, 0, num_entries*sizeof(Entry), 1197 (U8*)entries, 0, num_entries*sizeof(Entry));
1205 getLocalAPRFilePool());
1206 if (bytes_read != filesize) 1198 if (bytes_read != filesize)
1207 { 1199 {
1208 LL_WARNS("TextureCache") << "Bad cache file (2): " << mTexturesDirEntriesFileName << " Purging." << LL_ENDL; 1200 LL_WARNS("TextureCache") << "Bad cache file (2): " << mTexturesDirEntriesFileName << " Purging." << LL_ENDL;
@@ -1261,7 +1253,7 @@ void LLTextureCache::purgeTextures(bool validate)
1261 if (uuididx == validate_idx) 1253 if (uuididx == validate_idx)
1262 { 1254 {
1263 LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mSize << LL_ENDL; 1255 LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mSize << LL_ENDL;
1264 S32 bodysize = LLAPRFile::size(filename, getLocalAPRFilePool()); 1256 S32 bodysize = LLAPRFile::size(filename);
1265 if (bodysize != entries[idx].mSize) 1257 if (bodysize != entries[idx].mSize)
1266 { 1258 {
1267 LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mSize 1259 LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mSize
@@ -1295,10 +1287,9 @@ void LLTextureCache::purgeTextures(bool validate)
1295 << num_entries << " (" << num_entries*sizeof(Entry)/1024 << "KB)" 1287 << num_entries << " (" << num_entries*sizeof(Entry)/1024 << "KB)"
1296 << LL_ENDL; 1288 << LL_ENDL;
1297 1289
1298 LLAPRFile::remove(mTexturesDirEntriesFileName, getLocalAPRFilePool()); 1290 LLAPRFile::remove(mTexturesDirEntriesFileName);
1299 LLAPRFile::writeEx(mTexturesDirEntriesFileName, 1291 LLAPRFile::writeEx(mTexturesDirEntriesFileName,
1300 (U8*)&entries[0], 0, num_entries*sizeof(Entry), 1292 (U8*)&entries[0], 0, num_entries*sizeof(Entry));
1301 getLocalAPRFilePool());
1302 1293
1303 mTexturesSizeTotal = 0; 1294 mTexturesSizeTotal = 0;
1304 mTexturesSizeMap.clear(); 1295 mTexturesSizeMap.clear();
@@ -1345,7 +1336,7 @@ void LLTextureCache::purgeTextureFilesTimeSliced(BOOL force_all)
1345 for (LLTextureCache::filename_list_t::iterator iter = mFilesToDelete.begin(); iter!=mFilesToDelete.end(); ) 1336 for (LLTextureCache::filename_list_t::iterator iter = mFilesToDelete.begin(); iter!=mFilesToDelete.end(); )
1346 { 1337 {
1347 LLTextureCache::filename_list_t::iterator iter2 = iter++; 1338 LLTextureCache::filename_list_t::iterator iter2 = iter++;
1348 LLAPRFile::remove(*iter2, NULL); 1339 LLAPRFile::remove(*iter2);
1349 mFilesToDelete.erase(iter2); 1340 mFilesToDelete.erase(iter2);
1350 howmany++; 1341 howmany++;
1351 1342
@@ -1416,8 +1407,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image
1416 mHeaderIDMap[id] = idx; 1407 mHeaderIDMap[id] = idx;
1417 // Update Info 1408 // Update Info
1418 LLAPRFile::writeEx(mHeaderEntriesFileName, 1409 LLAPRFile::writeEx(mHeaderEntriesFileName,
1419 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo), 1410 (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo));
1420 getLocalAPRFilePool());
1421 } 1411 }
1422 else if (!mLRU.empty()) 1412 else if (!mLRU.empty())
1423 { 1413 {
@@ -1443,8 +1433,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image
1443 Entry* entry = new Entry(id, *imagesize, time(NULL)); 1433 Entry* entry = new Entry(id, *imagesize, time(NULL));
1444 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); 1434 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry);
1445 LLAPRFile::writeEx(mHeaderEntriesFileName, 1435 LLAPRFile::writeEx(mHeaderEntriesFileName,
1446 (U8*)entry, offset, sizeof(Entry), 1436 (U8*)entry, offset, sizeof(Entry));
1447 getLocalAPRFilePool());
1448 delete entry; 1437 delete entry;
1449 } 1438 }
1450 else if (imagesize) 1439 else if (imagesize)
@@ -1454,8 +1443,7 @@ S32 LLTextureCache::getHeaderCacheEntry(const LLUUID& id, bool touch, S32* image
1454 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); 1443 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry);
1455 1444
1456 LLAPRFile::readEx(mHeaderEntriesFileName, 1445 LLAPRFile::readEx(mHeaderEntriesFileName,
1457 (U8*)&entry, offset, sizeof(Entry), 1446 (U8*)&entry, offset, sizeof(Entry));
1458 getLocalAPRFilePool());
1459 *imagesize = entry.mSize; 1447 *imagesize = entry.mSize;
1460 } 1448 }
1461 } 1449 }
@@ -1608,8 +1596,7 @@ bool LLTextureCache::removeHeaderCacheEntry(const LLUUID& id)
1608 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry); 1596 S32 offset = sizeof(EntriesInfo) + idx * sizeof(Entry);
1609 1597
1610 LLAPRFile::writeEx(mHeaderEntriesFileName, 1598 LLAPRFile::writeEx(mHeaderEntriesFileName,
1611 (U8*)entry, offset, sizeof(Entry), 1599 (U8*)entry, offset, sizeof(Entry));
1612 getLocalAPRFilePool());
1613 delete entry; 1600 delete entry;
1614 mLRU[idx] = id; 1601 mLRU[idx] = id;
1615 mHeaderIDMap.erase(id); 1602 mHeaderIDMap.erase(id);
@@ -1626,7 +1613,7 @@ void LLTextureCache::removeFromCache(const LLUUID& id)
1626 if (!mReadOnly) 1613 if (!mReadOnly)
1627 { 1614 {
1628 removeHeaderCacheEntry(id); 1615 removeHeaderCacheEntry(id);
1629 LLAPRFile::remove(getTextureFileName(id), getLocalAPRFilePool()); 1616 LLAPRFile::remove(getTextureFileName(id));
1630 } 1617 }
1631} 1618}
1632 1619