summaryrefslogtreecommitdiff
path: root/indra/newview/lltexturecache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/lltexturecache.cpp')
-rw-r--r--indra/newview/lltexturecache.cpp91
1 files changed, 42 insertions, 49 deletions
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index 9b417307fd..87b6304f9d 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -113,7 +113,7 @@ public:
~LLTextureCacheWorker()
{
llassert_always(!haveWork());
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
}
// override this interface
@@ -176,7 +176,7 @@ private:
bool LLTextureCacheLocalFileWorker::doRead()
{
- S32 local_size = LLAPRFile::size(mFileName, mCache->getLocalAPRFilePool());
+ S32 local_size = LLAPRFile::size(mFileName);
if (local_size > 0 && mFileName.size() > 4)
{
@@ -215,7 +215,7 @@ bool LLTextureCacheLocalFileWorker::doRead()
mDataSize = 0;
return true;
}
- mReadData = new U8[mDataSize];
+ mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), mDataSize);
mBytesRead = -1;
mBytesToRead = mDataSize;
setPriority(LLWorkerThread::PRIORITY_LOW | mPriority);
@@ -233,7 +233,7 @@ bool LLTextureCacheLocalFileWorker::doRead()
// << " Bytes: " << mDataSize << " Offset: " << mOffset
// << " / " << mDataSize << llendl;
mDataSize = 0; // failed
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
}
return true;
@@ -248,9 +248,9 @@ bool LLTextureCacheLocalFileWorker::doRead()
{
mDataSize = local_size;
}
- mReadData = new U8[mDataSize];
+ mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), mDataSize);
- S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool());
+ S32 bytes_read = LLAPRFile::readEx(mFileName, mReadData, mOffset, mDataSize);
if (bytes_read != mDataSize)
{
@@ -258,7 +258,7 @@ bool LLTextureCacheLocalFileWorker::doRead()
// << " Bytes: " << mDataSize << " Offset: " << mOffset
// << " / " << mDataSize << llendl;
mDataSize = 0;
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
}
else
@@ -331,7 +331,7 @@ bool LLTextureCacheRemoteWorker::doRead()
// Is it a JPEG2000 file?
{
local_filename = filename + ".j2c";
- local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
mImageFormat = IMG_CODEC_J2C;
@@ -341,7 +341,7 @@ bool LLTextureCacheRemoteWorker::doRead()
if (local_size == 0)
{
local_filename = filename + ".jpg";
- local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
mImageFormat = IMG_CODEC_JPEG;
@@ -352,7 +352,7 @@ bool LLTextureCacheRemoteWorker::doRead()
if (local_size == 0)
{
local_filename = filename + ".tga";
- local_size = LLAPRFile::size(local_filename, mCache->getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
mImageFormat = IMG_CODEC_TGA;
@@ -377,16 +377,15 @@ bool LLTextureCacheRemoteWorker::doRead()
mDataSize = local_size;
}
// Allocate read buffer
- mReadData = new U8[mDataSize];
- S32 bytes_read = LLAPRFile::readEx(local_filename,
- mReadData, mOffset, mDataSize, mCache->getLocalAPRFilePool());
+ mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), mDataSize);
+ S32 bytes_read = LLAPRFile::readEx(local_filename, mReadData, mOffset, mDataSize);
if (bytes_read != mDataSize)
{
llwarns << "Error reading file from local cache: " << local_filename
<< " Bytes: " << mDataSize << " Offset: " << mOffset
<< " / " << mDataSize << llendl;
mDataSize = 0;
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
}
else
@@ -429,15 +428,14 @@ bool LLTextureCacheRemoteWorker::doRead()
S32 size = TEXTURE_CACHE_ENTRY_SIZE - mOffset;
size = llmin(size, mDataSize);
// Allocate the read buffer
- mReadData = new U8[size];
- S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName,
- mReadData, offset, size, mCache->getLocalAPRFilePool());
+ mReadData = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), size);
+ S32 bytes_read = LLAPRFile::readEx(mCache->mHeaderDataFileName, mReadData, offset, size);
if (bytes_read != size)
{
llwarns << "LLTextureCacheWorker: " << mID
<< " incorrect number of bytes read from header: " << bytes_read
<< " / " << size << llendl;
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
mDataSize = -1; // failed
done = true;
@@ -457,7 +455,7 @@ bool LLTextureCacheRemoteWorker::doRead()
if (!done && (mState == BODY))
{
std::string filename = mCache->getTextureFileName(mID);
- S32 filesize = LLAPRFile::size(filename, mCache->getLocalAPRFilePool());
+ S32 filesize = LLAPRFile::size(filename);
if (filesize && (filesize + TEXTURE_CACHE_ENTRY_SIZE) > mOffset)
{
@@ -467,7 +465,7 @@ bool LLTextureCacheRemoteWorker::doRead()
S32 data_offset, file_size, file_offset;
// Reserve the whole data buffer first
- U8* data = new U8[mDataSize];
+ U8* data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), mDataSize);
// Set the data file pointers taking the read offset into account. 2 cases:
if (mOffset < TEXTURE_CACHE_ENTRY_SIZE)
@@ -480,7 +478,7 @@ bool LLTextureCacheRemoteWorker::doRead()
// Copy the raw data we've been holding from the header cache into the new sized buffer
llassert_always(mReadData);
memcpy(data, mReadData, data_offset);
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
}
else
@@ -499,14 +497,13 @@ bool LLTextureCacheRemoteWorker::doRead()
// Read the data at last
S32 bytes_read = LLAPRFile::readEx(filename,
mReadData + data_offset,
- file_offset, file_size,
- mCache->getLocalAPRFilePool());
+ file_offset, file_size);
if (bytes_read != file_size)
{
llwarns << "LLTextureCacheWorker: " << mID
<< " incorrect number of bytes read from body: " << bytes_read
<< " / " << file_size << llendl;
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
mDataSize = -1; // failed
done = true;
@@ -598,16 +595,16 @@ bool LLTextureCacheRemoteWorker::doWrite()
{
// We need to write a full record in the header cache so, if the amount of data is smaller
// than a record, we need to transfer the data to a buffer padded with 0 and write that
- U8* padBuffer = new U8[TEXTURE_CACHE_ENTRY_SIZE];
+ U8* padBuffer = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), TEXTURE_CACHE_ENTRY_SIZE);
memset(padBuffer, 0, TEXTURE_CACHE_ENTRY_SIZE); // Init with zeros
memcpy(padBuffer, mWriteData, mDataSize); // Copy the write buffer
- bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, padBuffer, offset, size, mCache->getLocalAPRFilePool());
- delete [] padBuffer;
+ bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, padBuffer, offset, size);
+ FREE_MEM(LLImageBase::getPrivatePool(), padBuffer);
}
else
{
// Write the header record (== first TEXTURE_CACHE_ENTRY_SIZE bytes of the raw file) in the header file
- bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size, mCache->getLocalAPRFilePool());
+ bytes_written = LLAPRFile::writeEx(mCache->mHeaderDataFileName, mWriteData, offset, size);
}
if (bytes_written <= 0)
@@ -642,8 +639,7 @@ bool LLTextureCacheRemoteWorker::doWrite()
// llinfos << "Writing Body: " << filename << " Bytes: " << file_offset+file_size << llendl;
S32 bytes_written = LLAPRFile::writeEx( filename,
mWriteData + TEXTURE_CACHE_ENTRY_SIZE,
- 0, file_size,
- mCache->getLocalAPRFilePool());
+ 0, file_size);
if (bytes_written <= 0)
{
llwarns << "LLTextureCacheWorker: " << mID
@@ -698,7 +694,7 @@ void LLTextureCacheWorker::finishWork(S32 param, bool completed)
}
else
{
- delete[] mReadData;
+ FREE_MEM(LLImageBase::getPrivatePool(), mReadData);
mReadData = NULL;
}
}
@@ -740,9 +736,6 @@ void LLTextureCacheWorker::endWork(S32 param, bool aborted)
LLTextureCache::LLTextureCache(bool threaded)
: LLWorkerThread("TextureCache", threaded),
- mWorkersMutex(NULL),
- mHeaderMutex(NULL),
- mListMutex(NULL),
mHeaderAPRFile(NULL),
mReadOnly(TRUE), //do not allow to change the texture cache until setReadOnly() is called.
mTexturesSizeTotal(0),
@@ -846,7 +839,7 @@ BOOL LLTextureCache::isInLocal(const LLUUID& id)
// Is it a JPEG2000 file?
{
local_filename = filename + ".j2c";
- local_size = LLAPRFile::size(local_filename, getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
return TRUE ;
@@ -856,7 +849,7 @@ BOOL LLTextureCache::isInLocal(const LLUUID& id)
// If not, is it a jpeg file?
{
local_filename = filename + ".jpg";
- local_size = LLAPRFile::size(local_filename, getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
return TRUE ;
@@ -866,7 +859,7 @@ BOOL LLTextureCache::isInLocal(const LLUUID& id)
// Hmm... What about a targa file? (used for UI texture mostly)
{
local_filename = filename + ".tga";
- local_size = LLAPRFile::size(local_filename, getLocalAPRFilePool());
+ local_size = LLAPRFile::size(local_filename);
if (local_size > 0)
{
return TRUE ;
@@ -912,10 +905,10 @@ void LLTextureCache::purgeCache(ELLPath location)
if(LLFile::isdir(mTexturesDirName))
{
std::string file_name = gDirUtilp->getExpandedFilename(location, entries_filename);
- LLAPRFile::remove(file_name, getLocalAPRFilePool());
+ LLAPRFile::remove(file_name);
file_name = gDirUtilp->getExpandedFilename(location, cache_filename);
- LLAPRFile::remove(file_name, getLocalAPRFilePool());
+ LLAPRFile::remove(file_name);
purgeAllTextures(true);
}
@@ -991,7 +984,9 @@ LLAPRFile* LLTextureCache::openHeaderEntriesFile(bool readonly, S32 offset)
{
llassert_always(mHeaderAPRFile == NULL);
apr_int32_t flags = readonly ? APR_READ|APR_BINARY : APR_READ|APR_WRITE|APR_BINARY;
- mHeaderAPRFile = new LLAPRFile(mHeaderEntriesFileName, flags, getLocalAPRFilePool());
+ // All code calling openHeaderEntriesFile, immediately calls closeHeaderEntriesFile,
+ // so this file is very short-lived.
+ mHeaderAPRFile = new LLAPRFile(mHeaderEntriesFileName, flags);
if(offset > 0)
{
mHeaderAPRFile->seek(APR_SET, offset);
@@ -1014,10 +1009,9 @@ void LLTextureCache::readEntriesHeader()
{
// mHeaderEntriesInfo initializes to default values so safe not to read it
llassert_always(mHeaderAPRFile == NULL);
- if (LLAPRFile::isExist(mHeaderEntriesFileName, getLocalAPRFilePool()))
+ if (LLAPRFile::isExist(mHeaderEntriesFileName))
{
- LLAPRFile::readEx(mHeaderEntriesFileName, (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo),
- getLocalAPRFilePool());
+ LLAPRFile::readEx(mHeaderEntriesFileName, (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo));
}
else //create an empty entries header.
{
@@ -1032,8 +1026,7 @@ void LLTextureCache::writeEntriesHeader()
llassert_always(mHeaderAPRFile == NULL);
if (!mReadOnly)
{
- LLAPRFile::writeEx(mHeaderEntriesFileName, (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo),
- getLocalAPRFilePool());
+ LLAPRFile::writeEx(mHeaderEntriesFileName, (U8*)&mHeaderEntriesInfo, 0, sizeof(EntriesInfo));
}
}
@@ -1622,7 +1615,7 @@ void LLTextureCache::purgeTextures(bool validate)
if (uuididx == validate_idx)
{
LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mBodySize << LL_ENDL;
- S32 bodysize = LLAPRFile::size(filename, getLocalAPRFilePool());
+ S32 bodysize = LLAPRFile::size(filename);
if (bodysize != entries[idx].mBodySize)
{
LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mBodySize
@@ -1857,7 +1850,7 @@ void LLTextureCache::removeCachedTexture(const LLUUID& id)
mTexturesSizeMap.erase(id);
}
mHeaderIDMap.erase(id);
- LLAPRFile::remove(getTextureFileName(id), getLocalAPRFilePool());
+ LLAPRFile::remove(getTextureFileName(id));
}
//called after mHeaderMutex is locked.
@@ -1869,7 +1862,7 @@ void LLTextureCache::removeEntry(S32 idx, Entry& entry, std::string& filename)
{
if (entry.mBodySize == 0) // Always attempt to remove when mBodySize > 0.
{
- if (LLAPRFile::isExist(filename, getLocalAPRFilePool())) // Sanity check. Shouldn't exist when body size is 0.
+ if (LLAPRFile::isExist(filename)) // Sanity check. Shouldn't exist when body size is 0.
{
LL_WARNS("TextureCache") << "Entry has body size of zero but file " << filename << " exists. Deleting this file, too." << LL_ENDL;
}
@@ -1890,7 +1883,7 @@ void LLTextureCache::removeEntry(S32 idx, Entry& entry, std::string& filename)
if (file_maybe_exists)
{
- LLAPRFile::remove(filename, getLocalAPRFilePool());
+ LLAPRFile::remove(filename);
}
}