summaryrefslogtreecommitdiff
path: root/indra/llimage
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llimage')
-rw-r--r--indra/llimage/llimage.cpp50
-rw-r--r--indra/llimage/llimage.h14
-rw-r--r--indra/llimage/llimagedimensionsinfo.cpp2
-rw-r--r--indra/llimage/llimagedxt.cpp2
-rw-r--r--indra/llimage/llimagej2c.cpp7
-rw-r--r--indra/llimage/llimageworker.cpp8
-rw-r--r--indra/llimage/llimageworker.h2
7 files changed, 58 insertions, 27 deletions
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index f0d15d9607..23adbf68c8 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,11 +48,14 @@
//static
std::string LLImage::sLastErrorMessage;
LLMutex* LLImage::sMutex = NULL;
+LLPrivateMemoryPool* LLImageBase::sPrivatePoolp = NULL ;
//static
void LLImage::initClass()
{
- sMutex = new LLMutex(NULL);
+ sMutex = new LLMutex;
+
+ LLImageBase::createPrivatePool() ;
}
//static
@@ -59,6 +63,8 @@ void LLImage::cleanupClass()
{
delete sMutex;
sMutex = NULL;
+
+ LLImageBase::destroyPrivatePool() ;
}
//static
@@ -97,6 +103,25 @@ LLImageBase::~LLImageBase()
deleteData(); // virtual
}
+//static
+void LLImageBase::createPrivatePool()
+{
+ if(!sPrivatePoolp)
+ {
+ sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC_THREADED) ;
+ }
+}
+
+//static
+void LLImageBase::destroyPrivatePool()
+{
+ if(sPrivatePoolp)
+ {
+ LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp) ;
+ sPrivatePoolp = NULL ;
+ }
+}
+
// virtual
void LLImageBase::dump()
{
@@ -130,7 +155,7 @@ void LLImageBase::sanityCheck()
// virtual
void LLImageBase::deleteData()
{
- delete[] mData;
+ FREE_MEM(sPrivatePoolp, mData) ;
mData = NULL;
mDataSize = 0;
}
@@ -167,7 +192,7 @@ U8* LLImageBase::allocateData(S32 size)
{
deleteData(); // virtual
mBadBufferAllocation = false ;
- mData = new U8[size];
+ mData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size);
if (!mData)
{
llwarns << "allocate image data: " << size << llendl;
@@ -185,7 +210,7 @@ U8* LLImageBase::allocateData(S32 size)
U8* LLImageBase::reallocateData(S32 size)
{
LLMemType mt1(mMemType);
- U8 *new_datap = new U8[size];
+ U8 *new_datap = (U8*)ALLOCATE_MEM(sPrivatePoolp, size);
if (!new_datap)
{
llwarns << "Out of memory in LLImageBase::reallocateData" << llendl;
@@ -195,7 +220,7 @@ U8* LLImageBase::reallocateData(S32 size)
{
S32 bytes = llmin(mDataSize, size);
memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */
- delete[] mData;
+ FREE_MEM(sPrivatePoolp, mData) ;
}
mData = new_datap;
mDataSize = size;
@@ -341,6 +366,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);
@@ -361,6 +387,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)
@@ -830,6 +857,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)
{
@@ -853,7 +881,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() ;
@@ -875,6 +903,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 )
{
@@ -1506,6 +1535,7 @@ void LLImageFormatted::setData(U8 *data, S32 size)
{
deleteData();
setDataAndSize(data, size); // Access private LLImageBase members
+
sGlobalFormattedMemory += getDataSize();
}
}
@@ -1524,7 +1554,7 @@ void LLImageFormatted::appendData(U8 *data, S32 size)
S32 newsize = cursize + size;
reallocateData(newsize);
memcpy(getData() + cursize, data, size);
- delete[] data;
+ FREE_MEM(LLImageBase::getPrivatePool(), data);
}
}
}
@@ -1536,8 +1566,7 @@ BOOL LLImageFormatted::load(const std::string &filename)
resetLastError();
S32 file_size = 0;
- LLAPRFile infile ;
- infile.open(filename, LL_APR_RB, NULL, &file_size);
+ LLAPRFile infile(filename, LL_APR_RB, &file_size);
apr_file_t* apr_file = infile.getFileHandle();
if (!apr_file)
{
@@ -1572,8 +1601,7 @@ BOOL LLImageFormatted::save(const std::string &filename)
{
resetLastError();
- LLAPRFile outfile ;
- outfile.open(filename, LL_APR_WB);
+ LLAPRFile outfile(filename, LL_APR_WB);
if (!outfile.getFileHandle())
{
setLastError("Unable to open file for writing", filename);
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index c464c3b2b6..4469c9e860 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -29,7 +29,6 @@
#include "lluuid.h"
#include "llstring.h"
-//#include "llmemory.h"
#include "llthread.h"
#include "llmemtype.h"
@@ -69,6 +68,7 @@ const S32 MAX_IMG_PACKET_SIZE = 1000;
class LLImageFormatted;
class LLImageRaw;
class LLColor4U;
+class LLPrivateMemoryPool;
typedef enum e_image_codec
{
@@ -140,7 +140,7 @@ public:
protected:
// special accessor to allow direct setting of mData and mDataSize by LLImageFormatted
- void setDataAndSize(U8 *data, S32 size) { mData = data; mDataSize = size; }
+ void setDataAndSize(U8 *data, S32 size) { mData = data; mDataSize = size; }
public:
static void generateMip(const U8 *indata, U8* mipdata, int width, int height, S32 nchannels);
@@ -151,6 +151,10 @@ public:
static EImageCodec getCodecFromExtension(const std::string& exten);
+ static void createPrivatePool() ;
+ static void destroyPrivatePool() ;
+ static LLPrivateMemoryPool* getPrivatePool() {return sPrivatePoolp;}
+
private:
U8 *mData;
S32 mDataSize;
@@ -162,6 +166,8 @@ private:
bool mBadBufferAllocation ;
bool mAllowOverSize ;
+
+ static LLPrivateMemoryPool* sPrivatePoolp ;
public:
LLMemType::DeclareMemType& mMemType; // debug
};
@@ -185,7 +191,7 @@ public:
BOOL resize(U16 width, U16 height, S8 components);
- U8 * getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const;
+ //U8 * getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const;
BOOL setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height,
const U8 *data, U32 stride = 0, BOOL reverse_y = FALSE);
@@ -197,7 +203,7 @@ public:
void contractToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE, BOOL scale_image = TRUE);
void biasedScaleToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE);
BOOL scale( S32 new_width, S32 new_height, BOOL scale_image = TRUE );
- BOOL scaleDownWithoutBlending( S32 new_width, S32 new_height) ;
+ //BOOL scaleDownWithoutBlending( S32 new_width, S32 new_height) ;
// Fill the buffer with a constant color
void fill( const LLColor4U& color );
diff --git a/indra/llimage/llimagedimensionsinfo.cpp b/indra/llimage/llimagedimensionsinfo.cpp
index c6bfa50b40..926c749145 100644
--- a/indra/llimage/llimagedimensionsinfo.cpp
+++ b/indra/llimage/llimagedimensionsinfo.cpp
@@ -40,7 +40,7 @@ bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec)
mSrcFilename = src_filename;
S32 file_size = 0;
- apr_status_t s = mInfile.open(src_filename, LL_APR_RB, NULL, &file_size);
+ apr_status_t s = mInfile.open(src_filename, LL_APR_RB, LLAPRFile::long_lived, &file_size);
if (s != APR_SUCCESS)
{
diff --git a/indra/llimage/llimagedxt.cpp b/indra/llimage/llimagedxt.cpp
index 4bd3efddaa..2867f5e6f0 100644
--- a/indra/llimage/llimagedxt.cpp
+++ b/indra/llimage/llimagedxt.cpp
@@ -429,7 +429,7 @@ bool LLImageDXT::convertToDXR()
S32 nmips = calcNumMips(width,height);
S32 total_bytes = getDataSize();
U8* olddata = getData();
- U8* newdata = new U8[total_bytes];
+ U8* newdata = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), total_bytes);
if (!newdata)
{
llerrs << "Out of memory in LLImageDXT::convertToDXR()" << llendl;
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index 44e6b89dd3..8c5dc63e9d 100644
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -370,8 +370,7 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
resetLastError();
S32 file_size = 0;
- LLAPRFile infile ;
- infile.open(filename, LL_APR_RB, NULL, &file_size);
+ LLAPRFile infile(filename, LL_APR_RB, &file_size);
apr_file_t* apr_file = infile.getFileHandle() ;
if (!apr_file)
{
@@ -385,14 +384,14 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
}
else
{
- U8 *data = new U8[file_size];
+ U8 *data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), file_size);
apr_size_t bytes_read = file_size;
apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
infile.close() ;
if (s != APR_SUCCESS || (S32)bytes_read != file_size)
{
- delete[] data;
+ FREE_MEM(LLImageBase::getPrivatePool(), data);
setLastError("Unable to read entire file");
res = FALSE;
}
diff --git a/indra/llimage/llimageworker.cpp b/indra/llimage/llimageworker.cpp
index 28dc3bd313..2c6d6f31ea 100644
--- a/indra/llimage/llimageworker.cpp
+++ b/indra/llimage/llimageworker.cpp
@@ -35,20 +35,18 @@
LLImageDecodeThread::LLImageDecodeThread(bool threaded)
: LLQueuedThread("imagedecode", threaded)
{
- mCreationMutex = new LLMutex(getAPRPool());
}
//virtual
LLImageDecodeThread::~LLImageDecodeThread()
{
- delete mCreationMutex ;
}
// MAIN THREAD
// virtual
S32 LLImageDecodeThread::update(U32 max_time_ms)
{
- LLMutexLock lock(mCreationMutex);
+ LLMutexLock lock(&mCreationMutex);
for (creation_list_t::iterator iter = mCreationList.begin();
iter != mCreationList.end(); ++iter)
{
@@ -71,7 +69,7 @@ S32 LLImageDecodeThread::update(U32 max_time_ms)
LLImageDecodeThread::handle_t LLImageDecodeThread::decodeImage(LLImageFormatted* image,
U32 priority, S32 discard, BOOL needs_aux, Responder* responder)
{
- LLMutexLock lock(mCreationMutex);
+ LLMutexLock lock(&mCreationMutex);
handle_t handle = generateHandle();
mCreationList.push_back(creation_info(handle, image, priority, discard, needs_aux, responder));
return handle;
@@ -81,7 +79,7 @@ LLImageDecodeThread::handle_t LLImageDecodeThread::decodeImage(LLImageFormatted*
// Returns the size of the mutex guarded list as an indication of sanity
S32 LLImageDecodeThread::tut_size()
{
- LLMutexLock lock(mCreationMutex);
+ LLMutexLock lock(&mCreationMutex);
S32 res = mCreationList.size();
return res;
}
diff --git a/indra/llimage/llimageworker.h b/indra/llimage/llimageworker.h
index c684222fa5..6a24b7522a 100644
--- a/indra/llimage/llimageworker.h
+++ b/indra/llimage/llimageworker.h
@@ -98,7 +98,7 @@ private:
};
typedef std::list<creation_info> creation_list_t;
creation_list_t mCreationList;
- LLMutex* mCreationMutex;
+ LLMutex mCreationMutex;
};
#endif