summaryrefslogtreecommitdiff
path: root/indra/newview/llviewertexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rw-r--r--indra/newview/llviewertexture.cpp484
1 files changed, 361 insertions, 123 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 9b5b210bf7..0ad54f238e 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -2,31 +2,25 @@
* @file llviewertexture.cpp
* @brief Object which handles a received image (and associated texture(s))
*
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2000&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -112,13 +106,53 @@ const F64 log_2 = log(2.0);
LLLoadedCallbackEntry::LLLoadedCallbackEntry(loaded_callback_func cb,
S32 discard_level,
BOOL need_imageraw, // Needs image raw for the callback
- void* userdata )
+ void* userdata,
+ LLLoadedCallbackEntry::source_callback_list_t* src_callback_list,
+ LLViewerFetchedTexture* target,
+ BOOL pause)
: mCallback(cb),
mLastUsedDiscard(MAX_DISCARD_LEVEL+1),
mDesiredDiscard(discard_level),
mNeedsImageRaw(need_imageraw),
- mUserData(userdata)
+ mUserData(userdata),
+ mSourceCallbackList(src_callback_list),
+ mPaused(pause)
+{
+ if(mSourceCallbackList)
+ {
+ mSourceCallbackList->insert(target->getID());
+ }
+}
+
+LLLoadedCallbackEntry::~LLLoadedCallbackEntry()
+{
+}
+
+void LLLoadedCallbackEntry::removeTexture(LLViewerFetchedTexture* tex)
+{
+ if(mSourceCallbackList)
+ {
+ mSourceCallbackList->erase(tex->getID()) ;
+ }
+}
+
+//static
+void LLLoadedCallbackEntry::cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list)
{
+ //clear texture callbacks.
+ if(callback_list && !callback_list->empty())
+ {
+ for(LLLoadedCallbackEntry::source_callback_list_t::iterator iter = callback_list->begin();
+ iter != callback_list->end(); ++iter)
+ {
+ LLViewerFetchedTexture* tex = gTextureList.findImage(*iter) ;
+ if(tex)
+ {
+ tex->deleteCallbackEntry(callback_list) ;
+ }
+ }
+ callback_list->clear() ;
+ }
}
LLViewerMediaTexture* LLViewerTextureManager::createMediaTexture(const LLUUID &media_id, BOOL usemipmaps, LLImageGL* gl_image)
@@ -324,9 +358,7 @@ void LLViewerTextureManager::cleanup()
LLViewerFetchedTexture::sMissingAssetImagep = NULL;
LLViewerFetchedTexture::sWhiteImagep = NULL;
- LLViewerMediaTexture::cleanup() ;
-
- LLViewerTexture::cleanupClass() ;
+ LLViewerMediaTexture::cleanUpClass() ;
}
//----------------------------------------------------------------------------------------------
@@ -345,11 +377,6 @@ void LLViewerTexture::initClass()
}
// static
-void LLViewerTexture::cleanupClass()
-{
-}
-
-// static
S32 LLViewerTexture::getTotalNumOfCategories()
{
return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ;
@@ -460,6 +487,7 @@ LLViewerTexture::LLViewerTexture(const U32 width, const U32 height, const U8 com
mFullHeight = height ;
mUseMipMaps = usemipmaps ;
mComponents = components ;
+ setTexelsPerImage();
mID.generate();
sImageCount++;
@@ -478,6 +506,7 @@ LLViewerTexture::LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps)
LLViewerTexture::~LLViewerTexture()
{
+ cleanup();
sImageCount--;
}
@@ -487,15 +516,16 @@ void LLViewerTexture::init(bool firstinit)
mFullWidth = 0;
mFullHeight = 0;
+ mTexelsPerImage = 0 ;
mUseMipMaps = FALSE ;
mComponents = 0 ;
mTextureState = NO_DELETE ;
mDontDiscard = FALSE;
- mCanResetMaxVirtualSize = true ;
mMaxVirtualSize = 0.f;
mNeedsGLTexture = FALSE ;
- mNeedsResetMaxVirtualSize = FALSE ;
+ mMaxVirtualSizeResetInterval = 1;
+ mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval ;
mAdditionalDecodePriority = 0.f ;
mParcelMedia = NULL ;
mNumFaces = 0 ;
@@ -591,11 +621,6 @@ void LLViewerTexture::forceImmediateUpdate()
{
}
-void LLViewerTexture::setResetMaxVirtualSizeFlag(bool flag)
-{
- mCanResetMaxVirtualSize = flag ;
-}
-
void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) const
{
if(needs_gltexture)
@@ -603,10 +628,10 @@ void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) co
mNeedsGLTexture = TRUE ;
}
- if(mNeedsResetMaxVirtualSize)
+ if(!mMaxVirtualSizeResetCounter)
{
//flag to reset the values because the old values are used.
- mNeedsResetMaxVirtualSize = FALSE ;
+ resetMaxVirtualSizeResetCounter() ;
mMaxVirtualSize = virtual_size;
mAdditionalDecodePriority = 0.f ;
mNeedsGLTexture = needs_gltexture ;
@@ -621,7 +646,7 @@ void LLViewerTexture::resetTextureStats()
{
mMaxVirtualSize = 0.0f ;
mAdditionalDecodePriority = 0.f ;
- mNeedsResetMaxVirtualSize = FALSE ;
+ mMaxVirtualSizeResetCounter = 0 ;
}
//virtual
@@ -783,7 +808,7 @@ void LLViewerTexture::generateGLTexture()
LLImageGL* LLViewerTexture::getGLTexture() const
{
llassert(mGLTexturep.notNull()) ;
-
+
return mGLTexturep ;
}
@@ -807,7 +832,8 @@ BOOL LLViewerTexture::createGLTexture(S32 discard_level, const LLImageRaw* image
{
mFullWidth = mGLTexturep->getCurrentWidth() ;
mFullHeight = mGLTexturep->getCurrentHeight() ;
- mComponents = mGLTexturep->getComponents() ;
+ mComponents = mGLTexturep->getComponents() ;
+ setTexelsPerImage();
}
return ret ;
@@ -1025,9 +1051,16 @@ void LLViewerTexture::destroyGLTexture()
}
}
+void LLViewerTexture::setTexelsPerImage()
+{
+ S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT);
+ S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT);
+ mTexelsPerImage = (F32)fullwidth * fullheight;
+}
+
BOOL LLViewerTexture::isLargeImage()
{
- return mFullWidth * mFullHeight > LLViewerTexture::sMinLargeImageSize ;
+ return (S32)mTexelsPerImage > LLViewerTexture::sMinLargeImageSize ;
}
//virtual
@@ -1098,6 +1131,7 @@ void LLViewerFetchedTexture::init(bool firstinit)
mIsMissingAsset = FALSE;
mLoadedCallbackDesiredDiscardLevel = 0;
+ mPauseLoadedCallBacks = TRUE ;
mNeedsCreateTexture = FALSE;
@@ -1153,6 +1187,7 @@ void LLViewerFetchedTexture::cleanup()
// We never finished loading the image. Indicate failure.
// Note: this allows mLoadedCallbackUserData to be cleaned up.
entryp->mCallback( FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData );
+ entryp->removeTexture(this) ;
delete entryp;
}
mLoadedCallbackList.clear();
@@ -1379,6 +1414,7 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
mFullWidth = mRawImage->getWidth();
mFullHeight = mRawImage->getHeight();
+ setTexelsPerImage();
}
else
{
@@ -1448,53 +1484,62 @@ void LLViewerFetchedTexture::setKnownDrawSize(S32 width, S32 height)
void LLViewerFetchedTexture::processTextureStats()
{
if(mFullyLoaded)
- {
- if(mDesiredDiscardLevel <= mMinDesiredDiscardLevel)//already loaded
+ {
+ if(mDesiredDiscardLevel > mMinDesiredDiscardLevel)//need to load more
{
- return ;
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ;
+ mFullyLoaded = FALSE ;
}
- mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ;
- mFullyLoaded = FALSE ;
- return ;
- }
-
- updateVirtualSize() ;
-
- static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes");
-
- if (textures_fullres)
- {
- mDesiredDiscardLevel = 0;
- }
- else if(!mFullWidth || !mFullHeight)
- {
- mDesiredDiscardLevel = getMaxDiscardLevel() ;
}
else
- {
- if(!mKnownDrawWidth || !mKnownDrawHeight || mFullWidth <= mKnownDrawWidth || mFullHeight <= mKnownDrawHeight)
+ {
+ updateVirtualSize() ;
+
+ static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes");
+
+ if (textures_fullres)
+ {
+ mDesiredDiscardLevel = 0;
+ }
+ else if(!mFullWidth || !mFullHeight)
{
- if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
+ mDesiredDiscardLevel = getMaxDiscardLevel() ;
+ }
+ else
+ {
+ if(!mKnownDrawWidth || !mKnownDrawHeight || mFullWidth <= mKnownDrawWidth || mFullHeight <= mKnownDrawHeight)
{
- mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
+ {
+ mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 1024 and max size ever is 2048
+ }
+ else
+ {
+ mDesiredDiscardLevel = 0;
+ }
}
- else
+ else if(mKnownDrawSizeChanged)//known draw size is set
+ {
+ mDesiredDiscardLevel = (S8)llmin(log((F32)mFullWidth / mKnownDrawWidth) / log_2,
+ log((F32)mFullHeight / mKnownDrawHeight) / log_2) ;
+ mDesiredDiscardLevel = llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel()) ;
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ;
+ }
+ mKnownDrawSizeChanged = FALSE ;
+
+ if(getDiscardLevel() >= 0 && (getDiscardLevel() <= mDesiredDiscardLevel))
{
- mDesiredDiscardLevel = 0;
+ mFullyLoaded = TRUE ;
}
}
- else if(mKnownDrawSizeChanged)//known draw size is set
- {
- mDesiredDiscardLevel = (S8)llmin(log((F32)mFullWidth / mKnownDrawWidth) / log_2,
- log((F32)mFullHeight / mKnownDrawHeight) / log_2) ;
- mDesiredDiscardLevel = llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel()) ;
- mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ;
- }
- mKnownDrawSizeChanged = FALSE ;
-
- if(getDiscardLevel() >= 0 && (getDiscardLevel() <= mDesiredDiscardLevel))
+ }
+
+ if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0) //force to refetch the texture.
+ {
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel) ;
+ if(getDiscardLevel() < 0 || getDiscardLevel() > mDesiredDiscardLevel)
{
- mFullyLoaded = TRUE ;
+ mFullyLoaded = FALSE ;
}
}
}
@@ -1529,6 +1574,7 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
F32 pixel_priority = fsqrtf(mMaxVirtualSize);
F32 priority = 0.f;
+
if (mIsMissingAsset)
{
priority = 0.0f;
@@ -1550,7 +1596,7 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
{
priority = 1.f;
}
- else if (pixel_priority <= 0.f && !have_all_data)
+ else if (pixel_priority < 0.001f && !have_all_data)
{
// Not on screen but we might want some data
if (mBoostLevel > BOOST_HIGH)
@@ -1558,11 +1604,6 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
// Always want high boosted images
priority = 1.f;
}
- else if(mForceToSaveRawImage)
- {
- //force to fetch the raw image.
- priority = 1.f;
- }
else
{
priority = -5.f; //stop fetching
@@ -1577,6 +1618,7 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
S32 ddiscard = MAX_DISCARD_LEVEL - (S32)desired;
ddiscard = llclamp(ddiscard, 0, MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY);
priority = (ddiscard + 1) * PRIORITY_DELTA_DISCARD_LEVEL_FACTOR;
+ setAdditionalDecodePriority(1.0f) ;//boost the textures without any data so far.
}
else if ((mMinDiscardLevel > 0) && (cur_discard <= mMinDiscardLevel))
{
@@ -1587,11 +1629,7 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
{
// priority range = 100,000 - 500,000
S32 desired_discard = mDesiredDiscardLevel;
- if (getDontDiscard())
- {
- desired_discard -= 2;
- }
- else if (!isJustBound() && mCachedRawImageReady)
+ if (!isJustBound() && mCachedRawImageReady)
{
if(mBoostLevel < BOOST_HIGH)
{
@@ -1607,7 +1645,7 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
S32 ddiscard = cur_discard - desired_discard;
ddiscard = llclamp(ddiscard, -1, MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY);
- priority = (ddiscard + 1) * PRIORITY_DELTA_DISCARD_LEVEL_FACTOR;
+ priority = (ddiscard + 1) * PRIORITY_DELTA_DISCARD_LEVEL_FACTOR;
}
// Priority Formula:
@@ -1615,19 +1653,51 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
// [10,000,000] + [1,000,000-9,000,000] + [100,000-500,000] + [1-20,000] + [0-999]
if (priority > 0.0f)
{
+ bool large_enough = mCachedRawImageReady && ((S32)mTexelsPerImage > sMinLargeImageSize) ;
+ if(large_enough)
+ {
+ //Note:
+ //to give small, low-priority textures some chance to be fetched,
+ //cut the priority in half if the texture size is larger than 256 * 256 and has a 64*64 ready.
+ priority *= 0.5f ;
+ }
+
pixel_priority = llclamp(pixel_priority, 0.0f, MAX_PRIORITY_PIXEL);
priority += pixel_priority + PRIORITY_BOOST_LEVEL_FACTOR * mBoostLevel;
if ( mBoostLevel > BOOST_HIGH)
{
- priority += PRIORITY_BOOST_HIGH_FACTOR;
+ if(mBoostLevel > BOOST_SUPER_HIGH)
+ {
+ //for very important textures, always grant the highest priority.
+ priority += PRIORITY_BOOST_HIGH_FACTOR;
+ }
+ else if(mCachedRawImageReady)
+ {
+ //Note:
+ //to give small, low-priority textures some chance to be fetched,
+ //if high priority texture has a 64*64 ready, lower its fetching priority.
+ setAdditionalDecodePriority(0.5f) ;
+ }
+ else
+ {
+ priority += PRIORITY_BOOST_HIGH_FACTOR;
+ }
}
if(mAdditionalDecodePriority > 0.0f)
{
// priority range += 1,000,000.f-9,000,000.f
- priority += PRIORITY_ADDITIONAL_FACTOR * (1.0 + mAdditionalDecodePriority * MAX_ADDITIONAL_LEVEL_FOR_PRIORITY);
+ F32 additional = PRIORITY_ADDITIONAL_FACTOR * (1.0 + mAdditionalDecodePriority * MAX_ADDITIONAL_LEVEL_FOR_PRIORITY);
+ if(large_enough)
+ {
+ //Note:
+ //to give small, low-priority textures some chance to be fetched,
+ //cut the additional priority to a quarter if the texture size is larger than 256 * 256 and has a 64*64 ready.
+ additional *= 0.25f ;
+ }
+ priority += additional;
}
}
return priority;
@@ -1652,6 +1722,11 @@ void LLViewerFetchedTexture::setDecodePriority(F32 priority)
llassert(!mInImageList);
mDecodePriority = priority;
+
+ if(mDecodePriority < F_ALMOST_ZERO)
+ {
+ mStopFetchingTimer.reset() ;
+ }
}
void LLViewerFetchedTexture::setAdditionalDecodePriority(F32 priority)
@@ -1665,16 +1740,11 @@ void LLViewerFetchedTexture::setAdditionalDecodePriority(F32 priority)
void LLViewerFetchedTexture::updateVirtualSize()
{
- if(mNeedsResetMaxVirtualSize)
+ if(!mMaxVirtualSizeResetCounter)
{
addTextureStats(0.f, FALSE) ;//reset
}
- if(mForceToSaveRawImage)
- {
- setAdditionalDecodePriority(0.75f) ; //boost the fetching priority
- }
-
for(U32 i = 0 ; i < mNumFaces ; i++)
{
LLFace* facep = mFaceList[i] ;
@@ -1685,9 +1755,9 @@ void LLViewerFetchedTexture::updateVirtualSize()
}
}
- if(mCanResetMaxVirtualSize)
+ if(mMaxVirtualSizeResetCounter > 0)
{
- mNeedsResetMaxVirtualSize = TRUE ;
+ mMaxVirtualSizeResetCounter--;
}
reorganizeFaceList() ;
reorganizeVolumeList();
@@ -1765,6 +1835,7 @@ bool LLViewerFetchedTexture::updateFetch()
if (finished)
{
mIsFetching = FALSE;
+ mLastPacketTimer.reset() ;
}
else
{
@@ -1786,6 +1857,7 @@ bool LLViewerFetchedTexture::updateFetch()
{
mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
+ setTexelsPerImage();
if(mFullWidth > MAX_IMAGE_SIZE || mFullHeight > MAX_IMAGE_SIZE)
{
@@ -1794,6 +1866,7 @@ bool LLViewerFetchedTexture::updateFetch()
setIsMissingAsset();
mRawDiscardLevel = INVALID_DISCARD_LEVEL ;
mIsFetching = FALSE ;
+ mLastPacketTimer.reset();
}
else
{
@@ -1845,7 +1918,12 @@ bool LLViewerFetchedTexture::updateFetch()
// llinfos << "Calling updateRequestPriority() with decode_priority = 0.0f" << llendl;
// calcDecodePriority();
// }
- LLAppViewer::getTextureFetch()->updateRequestPriority(mID, decode_priority);
+ static const F32 MAX_HOLD_TIME = 5.0f ; //seconds to wait before canceling fecthing if decode_priority is 0.f.
+ if(decode_priority > 0.0f || mStopFetchingTimer.getElapsedTimeF32() > MAX_HOLD_TIME)
+ {
+ mStopFetchingTimer.reset() ;
+ LLAppViewer::getTextureFetch()->updateRequestPriority(mID, decode_priority);
+ }
}
}
@@ -1961,6 +2039,7 @@ void LLViewerFetchedTexture::setIsMissingAsset()
LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
mHasFetcher = FALSE;
mIsFetching = FALSE;
+ mLastPacketTimer.reset();
mFetchState = 0;
mFetchPriority = 0;
}
@@ -1968,7 +2047,8 @@ void LLViewerFetchedTexture::setIsMissingAsset()
}
void LLViewerFetchedTexture::setLoadedCallback( loaded_callback_func loaded_callback,
- S32 discard_level, BOOL keep_imageraw, BOOL needs_aux, void* userdata)
+ S32 discard_level, BOOL keep_imageraw, BOOL needs_aux, void* userdata,
+ LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause)
{
//
// Don't do ANYTHING here, just add it to the global callback list
@@ -1984,12 +2064,17 @@ void LLViewerFetchedTexture::setLoadedCallback( loaded_callback_func loaded_call
mLoadedCallbackDesiredDiscardLevel = llmin(mLoadedCallbackDesiredDiscardLevel, (S8)discard_level) ;
}
- LLLoadedCallbackEntry* entryp = new LLLoadedCallbackEntry(loaded_callback, discard_level, keep_imageraw, userdata);
- mLoadedCallbackList.push_back(entryp);
+ if(mPauseLoadedCallBacks && !pause)
+ {
+ unpauseLoadedCallbacks(src_callback_list) ;
+ }
+ LLLoadedCallbackEntry* entryp = new LLLoadedCallbackEntry(loaded_callback, discard_level, keep_imageraw, userdata, src_callback_list, this, pause);
+ mLoadedCallbackList.push_back(entryp);
+
mNeedsAux |= needs_aux;
if(keep_imageraw)
{
- forceToSaveRawImage(discard_level) ;
+ forceToSaveRawImage(discard_level, true) ;
}
if (mNeedsAux && mAuxRawImage.isNull() && getDiscardLevel() >= 0)
{
@@ -1998,6 +2083,154 @@ void LLViewerFetchedTexture::setLoadedCallback( loaded_callback_func loaded_call
}
}
+void LLViewerFetchedTexture::clearCallbackEntryList()
+{
+ if(mLoadedCallbackList.empty())
+ {
+ return ;
+ }
+
+ for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+ iter != mLoadedCallbackList.end(); )
+ {
+ LLLoadedCallbackEntry *entryp = *iter;
+
+ // We never finished loading the image. Indicate failure.
+ // Note: this allows mLoadedCallbackUserData to be cleaned up.
+ entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
+ iter = mLoadedCallbackList.erase(iter) ;
+ delete entryp;
+ }
+ gTextureList.mCallbackList.erase(this);
+
+ mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
+ mLoadedCallbackDesiredDiscardLevel = S8_MAX ;
+ if(mForceToSaveRawImage)
+ {
+ destroySavedRawImage() ;
+ }
+
+ return ;
+}
+
+void LLViewerFetchedTexture::deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
+{
+ if(mLoadedCallbackList.empty() || !callback_list)
+ {
+ return ;
+ }
+
+ S32 desired_discard = S8_MAX ;
+ S32 desired_raw_discard = INVALID_DISCARD_LEVEL ;
+ for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+ iter != mLoadedCallbackList.end(); )
+ {
+ LLLoadedCallbackEntry *entryp = *iter;
+ if(entryp->mSourceCallbackList == callback_list)
+ {
+ // We never finished loading the image. Indicate failure.
+ // Note: this allows mLoadedCallbackUserData to be cleaned up.
+ entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
+ iter = mLoadedCallbackList.erase(iter) ;
+ delete entryp;
+ }
+ else
+ {
+ ++iter;
+
+ desired_discard = llmin(desired_discard, entryp->mDesiredDiscard) ;
+ if(entryp->mNeedsImageRaw)
+ {
+ desired_raw_discard = llmin(desired_raw_discard, entryp->mDesiredDiscard) ;
+ }
+ }
+ }
+
+ mLoadedCallbackDesiredDiscardLevel = desired_discard;
+ if (mLoadedCallbackList.empty())
+ {
+ // If we have no callbacks, take us off of the image callback list.
+ gTextureList.mCallbackList.erase(this);
+ mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
+
+ if(mForceToSaveRawImage)
+ {
+ destroySavedRawImage() ;
+ }
+ }
+ else if(mForceToSaveRawImage && mBoostLevel != LLViewerTexture::BOOST_PREVIEW)
+ {
+ if(desired_raw_discard != INVALID_DISCARD_LEVEL)
+ {
+ mDesiredSavedRawDiscardLevel = desired_raw_discard ;
+ }
+ else
+ {
+ destroySavedRawImage() ;
+ }
+ }
+}
+
+void LLViewerFetchedTexture::unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
+{
+ if(!callback_list)
+{
+ mPauseLoadedCallBacks = FALSE ;
+ return ;
+ }
+
+ BOOL need_raw = FALSE ;
+ for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+ iter != mLoadedCallbackList.end(); )
+ {
+ LLLoadedCallbackEntry *entryp = *iter++;
+ if(entryp->mSourceCallbackList == callback_list)
+ {
+ entryp->mPaused = FALSE ;
+ if(entryp->mNeedsImageRaw)
+ {
+ need_raw = TRUE ;
+ }
+ }
+ }
+ mPauseLoadedCallBacks = FALSE ;
+ if(need_raw)
+ {
+ mForceToSaveRawImage = TRUE ;
+ }
+}
+
+void LLViewerFetchedTexture::pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
+{
+ if(!callback_list)
+{
+ return ;
+ }
+
+ bool paused = true ;
+
+ for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+ iter != mLoadedCallbackList.end(); )
+ {
+ LLLoadedCallbackEntry *entryp = *iter++;
+ if(entryp->mSourceCallbackList == callback_list)
+ {
+ entryp->mPaused = TRUE ;
+ }
+ else if(!entryp->mPaused)
+ {
+ paused = false ;
+ }
+ }
+
+ if(paused)
+ {
+ mPauseLoadedCallBacks = TRUE ;//when set, loaded callback is paused.
+ resetTextureStats();
+ mForceToSaveRawImage = FALSE ;
+ }
+}
+
bool LLViewerFetchedTexture::doLoadedCallbacks()
{
if (mNeedsCreateTexture)
@@ -2023,6 +2256,11 @@ bool LLViewerFetchedTexture::doLoadedCallbacks()
// Remove ourself from the global list of textures with callbacks
gTextureList.mCallbackList.erase(this);
}
+ if(mPauseLoadedCallBacks)
+ {
+ destroyRawImage();
+ return res; //paused
+ }
S32 gl_discard = getDiscardLevel();
@@ -2152,10 +2390,6 @@ bool LLViewerFetchedTexture::doLoadedCallbacks()
BOOL final = mRawDiscardLevel <= entryp->mDesiredDiscard ? TRUE : FALSE;
//llinfos << "Running callback for " << getID() << llendl;
//llinfos << mRawImage->getWidth() << "x" << mRawImage->getHeight() << llendl;
- if (final)
- {
- //llinfos << "Final!" << llendl;
- }
entryp->mLastUsedDiscard = mRawDiscardLevel;
entryp->mCallback(TRUE, this, mRawImage, mAuxRawImage, mRawDiscardLevel, final, entryp->mUserData);
if (final)
@@ -2432,10 +2666,12 @@ void LLViewerFetchedTexture::saveRawImage()
mLastReferencedSavedRawImageTime = sCurrentTime ;
}
-void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard)
+void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard, bool from_callback)
{
if(!mForceToSaveRawImage || mDesiredSavedRawDiscardLevel < 0 || mDesiredSavedRawDiscardLevel > desired_discard)
{
+ llassert_always(from_callback || mBoostLevel == LLViewerTexture::BOOST_PREVIEW) ;
+
mForceToSaveRawImage = TRUE ;
mDesiredSavedRawDiscardLevel = desired_discard ;
@@ -2454,6 +2690,12 @@ void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard)
}
void LLViewerFetchedTexture::destroySavedRawImage()
{
+ clearCallbackEntryList() ;
+ //if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0 && mDesiredSavedRawDiscardLevel < getDiscardLevel())
+ //{
+ // return ; //can not destroy the saved raw image before it is fully fetched, otherwise causing callbacks hanging there.
+ //}
+
mSavedRawImage = NULL ;
mForceToSaveRawImage = FALSE ;
mSavedRawDiscardLevel = -1 ;
@@ -2704,7 +2946,7 @@ BOOL LLViewerLODTexture::isUpdateFrozen()
void LLViewerLODTexture::processTextureStats()
{
updateVirtualSize() ;
-
+
static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes");
if (textures_fullres)
@@ -2732,10 +2974,6 @@ void LLViewerLODTexture::processTextureStats()
//static const F64 log_2 = log(2.0);
static const F64 log_4 = log(4.0);
- S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT);
- S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT);
- mTexelsPerImage = (F32)fullwidth * fullheight;
-
F32 discard_level = 0.f;
// If we know the output width and height, we can force the discard
@@ -2882,7 +3120,7 @@ void LLViewerMediaTexture::removeMediaImplFromTexture(const LLUUID& media_id)
}
//static
-void LLViewerMediaTexture::cleanup()
+void LLViewerMediaTexture::cleanUpClass()
{
sMediaMap.clear() ;
}
@@ -3291,7 +3529,7 @@ F32 LLViewerMediaTexture::getMaxVirtualSize()
}
mUpdateVirtualSizeTime = LLFrameTimer::getFrameCount() ;
- if(mNeedsResetMaxVirtualSize)
+ if(!mMaxVirtualSizeResetCounter)
{
addTextureStats(0.f, FALSE) ;//reset
}
@@ -3324,9 +3562,9 @@ F32 LLViewerMediaTexture::getMaxVirtualSize()
}
}
- if(mCanResetMaxVirtualSize)
+ if(mMaxVirtualSizeResetCounter > 0)
{
- mNeedsResetMaxVirtualSize = TRUE ;
+ mMaxVirtualSizeResetCounter--;
}
reorganizeFaceList() ;
reorganizeVolumeList();
@@ -3510,7 +3748,7 @@ void LLTexturePipelineTester::updateStablizingTime()
{
F32 t = mEndStablizingTime - mStartStablizingTime ;
- if(t > 0.0001f && (t - mTotalStablizingTime) < 0.0001f)
+ if(t > F_ALMOST_ZERO && (t - mTotalStablizingTime) < F_ALMOST_ZERO)
{
//already stablized
mTotalStablizingTime = LLImageGL::sLastFrameTime - mStartStablizingTime ;
@@ -3635,7 +3873,7 @@ LLMetricPerformanceTester::LLTestSession* LLTexturePipelineTester::loadTestSessi
//time
F32 start_time = (*log)[label]["StartFetchingTime"].asReal() ;
F32 cur_time = (*log)[label]["Time"].asReal() ;
- if(start_time - start_fetching_time > 0.0001f) //fetching has paused for a while
+ if(start_time - start_fetching_time > F_ALMOST_ZERO) //fetching has paused for a while
{
sessionp->mTotalFetchingTime += total_fetching_time ;
sessionp->mTotalGrayTime += total_gray_time ;