diff options
author | Xiaohong Bao <bao@lindenlab.com> | 2011-01-06 16:20:21 -0700 |
---|---|---|
committer | Xiaohong Bao <bao@lindenlab.com> | 2011-01-06 16:20:21 -0700 |
commit | 611d8bdf6155f6c7b440ab745f197d278a74b209 (patch) | |
tree | 15664a307f5a269671c209759e5a64580b386be4 /indra/llimage/llimage.cpp | |
parent | 4de6759cd9d566ab92f0d9efa0c0338359dfa85c (diff) |
use the private pool in the texture pipeline
Diffstat (limited to 'indra/llimage/llimage.cpp')
-rw-r--r-- | indra/llimage/llimage.cpp | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 5c33b675ca..c99313f0ea 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -39,6 +39,7 @@ #include "llimagepng.h" #include "llimagedxt.h" #include "llimageworker.h" +#include "llmemory.h" //--------------------------------------------------------------------------- // LLImage @@ -47,12 +48,15 @@ //static std::string LLImage::sLastErrorMessage; LLMutex* LLImage::sMutex = NULL; +LLPrivateMemoryPool* LLImageBase::sPrivatePoolp = NULL ; //static void LLImage::initClass() { sMutex = new LLMutex(NULL); LLImageJ2C::openDSO(); + + LLImageBase::createPrivatePool() ; } //static @@ -61,6 +65,8 @@ void LLImage::cleanupClass() LLImageJ2C::closeDSO(); delete sMutex; sMutex = NULL; + + LLImageBase::destroyPrivatePool() ; } //static @@ -99,6 +105,53 @@ LLImageBase::~LLImageBase() deleteData(); // virtual } +//static +void LLImageBase::createPrivatePool() +{ + const U32 MAX_POOL_SIZE = 512 * 1024 * 1024 ; //512 MB + + if(!sPrivatePoolp) + { + sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(MAX_POOL_SIZE, true) ; + } +} + +//static +void LLImageBase::destroyPrivatePool() +{ + if(sPrivatePoolp) + { + LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp) ; + sPrivatePoolp = NULL ; + } +} + +//static +char* LLImageBase::allocateMemory(S32 size) +{ + if(sPrivatePoolp) + { + return sPrivatePoolp->allocate(size) ; + } + else + { + return new char[size]; + } +} + +//static +void LLImageBase::deleteMemory(void* p) +{ + if(sPrivatePoolp) + { + sPrivatePoolp->free(p) ; + } + else + { + delete[] p ; + } +} + // virtual void LLImageBase::dump() { @@ -132,7 +185,7 @@ void LLImageBase::sanityCheck() // virtual void LLImageBase::deleteData() { - delete[] mData; + deleteMemory(mData) ; mData = NULL; mDataSize = 0; } @@ -169,7 +222,7 @@ U8* LLImageBase::allocateData(S32 size) { deleteData(); // virtual mBadBufferAllocation = false ; - mData = new U8[size]; + mData = (U8*)allocateMemory(size); if (!mData) { llwarns << "allocate image data: " << size << llendl; @@ -187,7 +240,7 @@ U8* LLImageBase::allocateData(S32 size) U8* LLImageBase::reallocateData(S32 size) { LLMemType mt1(mMemType); - U8 *new_datap = new U8[size]; + U8 *new_datap = (U8*)allocateMemory(size); if (!new_datap) { llwarns << "Out of memory in LLImageBase::reallocateData" << llendl; @@ -197,7 +250,7 @@ U8* LLImageBase::reallocateData(S32 size) { S32 bytes = llmin(mDataSize, size); memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */ - delete[] mData; + deleteMemory(mData) ; } mData = new_datap; mDataSize = size; @@ -343,6 +396,7 @@ BOOL LLImageRaw::resize(U16 width, U16 height, S8 components) return TRUE; } +#if 0 U8 * LLImageRaw::getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const { LLMemType mt1(mMemType); @@ -363,6 +417,7 @@ U8 * LLImageRaw::getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const } return data; } +#endif BOOL LLImageRaw::setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height, const U8 *data, U32 stride, BOOL reverse_y) @@ -832,6 +887,7 @@ void LLImageRaw::copyScaled( LLImageRaw* src ) } } +#if 0 //scale down image by not blending a pixel with its neighbors. BOOL LLImageRaw::scaleDownWithoutBlending( S32 new_width, S32 new_height) { @@ -855,7 +911,7 @@ BOOL LLImageRaw::scaleDownWithoutBlending( S32 new_width, S32 new_height) ratio_x -= 1.0f ; ratio_y -= 1.0f ; - U8* new_data = new U8[new_data_size] ; + U8* new_data = allocateMemory(new_data_size) ; llassert_always(new_data != NULL) ; U8* old_data = getData() ; @@ -877,6 +933,7 @@ BOOL LLImageRaw::scaleDownWithoutBlending( S32 new_width, S32 new_height) return TRUE ; } +#endif BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data ) { @@ -1529,6 +1586,7 @@ void LLImageFormatted::setData(U8 *data, S32 size) { deleteData(); setDataAndSize(data, size); // Access private LLImageBase members + sGlobalFormattedMemory += getDataSize(); } } @@ -1547,7 +1605,7 @@ void LLImageFormatted::appendData(U8 *data, S32 size) S32 newsize = cursize + size; reallocateData(newsize); memcpy(getData() + cursize, data, size); - delete[] data; + deleteMemory(data); } } } |