From 8c0aa31536c447edb6ef4fbee43f99debf593a20 Mon Sep 17 00:00:00 2001
From: Don Kjer <don@lindenlab.com>
Date: Thu, 4 Oct 2012 00:42:31 +0000
Subject: [PATCH] Adding optimization to skip alpha image analysis when it
 isn't needed.

---
 indra/llappearance/lltexlayerparams.cpp |  2 +-
 indra/llimage/llimagetga.cpp            | 12 ++++++------
 indra/llrender/llimagegl.cpp            | 14 ++++++++++++--
 indra/llrender/llimagegl.h              |  5 +++--
 indra/newview/llviewerwindow.cpp        |  3 ++-
 5 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp
index 32bdba4e1c9..8f1551353f2 100755
--- a/indra/llappearance/lltexlayerparams.cpp
+++ b/indra/llappearance/lltexlayerparams.cpp
@@ -288,7 +288,6 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height)
 			(mCachedProcessedTexture->getHeight() != image_tga_height) ||
 			(weight_changed))
 		{
-//			llinfos << "Building Cached Alpha: " << mName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << effective_weight << llendl;
 			mCachedEffectiveWeight = effective_weight;
 
 			if (!mCachedProcessedTexture)
@@ -307,6 +306,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height)
 			mStaticImageRaw = new LLImageRaw;
 			mStaticImageTGA->decodeAndProcess(mStaticImageRaw, info->mDomain, effective_weight);
 			mNeedsCreateTexture = TRUE;			
+			lldebugs << "Built Cached Alpha: " << info->mStaticImageFileName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << "Domain: " << info->mDomain << " Weight: " << effective_weight << llendl;
 		}
 
 		if (mCachedProcessedTexture)
diff --git a/indra/llimage/llimagetga.cpp b/indra/llimage/llimagetga.cpp
index 58426d31fa6..920ae2891f6 100644
--- a/indra/llimage/llimagetga.cpp
+++ b/indra/llimage/llimagetga.cpp
@@ -132,12 +132,12 @@ BOOL LLImageTGA::updateData()
 	**	  FIELD 2 :	COLOR MAP TYPE (1 BYTES)			
 	**	  FIELD 3 :	IMAGE TYPE CODE (1 BYTES)			
 	**					= 0	NO IMAGE DATA INCLUDED		
-	**					= 1	UNCOMPRESSED, COLOR-MAPPED IMAGE
-	**					= 2	UNCOMPRESSED, TRUE-COLOR IMAGE	
-	**					= 3	UNCOMPRESSED, BLACK AND WHITE IMAGE
-	**					= 9	RUN-LENGTH ENCODED COLOR-MAPPED IMAGE
-	**					= 10 RUN-LENGTH ENCODED TRUE-COLOR IMAGE
-	**					= 11 RUN-LENGTH ENCODED BLACK AND WHITE IMAGE
+	**					= (0001) 1	UNCOMPRESSED, COLOR-MAPPED IMAGE
+	**					= (0010) 2	UNCOMPRESSED, TRUE-COLOR IMAGE	
+	**					= (0011) 3	UNCOMPRESSED, BLACK AND WHITE IMAGE
+	**					= (1001) 9	RUN-LENGTH ENCODED COLOR-MAPPED IMAGE
+	**					= (1010) 10 RUN-LENGTH ENCODED TRUE-COLOR IMAGE
+	**					= (1011) 11 RUN-LENGTH ENCODED BLACK AND WHITE IMAGE
 	**	  FIELD 4 :	COLOR MAP SPECIFICATION	(5 BYTES)		
 	**				4.1 : COLOR MAP ORIGIN (2 BYTES)	
 	**				4.2 : COLOR MAP LENGTH (2 BYTES)	
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index d561f63544b..44224ba72f3 100755
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -74,6 +74,9 @@ S32 LLImageGL::sCurTexSizeBar = -1 ;
 S32 LLImageGL::sCurTexPickSize = -1 ;
 S32 LLImageGL::sMaxCategories = 1 ;
 
+//optimization for when we don't need to calculate mIsMask
+BOOL LLImageGL::sSkipAnalyzeAlpha;
+
 //------------------------
 //****************************************************************************************************
 //End for texture auditing use only
@@ -169,8 +172,9 @@ BOOL is_little_endian()
 	return (*c == 0x78) ;
 }
 //static 
-void LLImageGL::initClass(S32 num_catagories) 
+void LLImageGL::initClass(S32 num_catagories, BOOL skip_analyze_alpha /* = false */)
 {
+	sSkipAnalyzeAlpha = skip_analyze_alpha;
 }
 
 //static 
@@ -1700,6 +1704,12 @@ BOOL LLImageGL::getBoundRecently() const
 	return (BOOL)(sLastFrameTime - mLastBindTime < MIN_TEXTURE_LIFETIME);
 }
 
+BOOL LLImageGL::getIsAlphaMask() const
+{
+	llassert_always(!sSkipAnalyzeAlpha);
+	return mIsMask;
+}
+
 void LLImageGL::setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target)
 {
 	mTarget = target;
@@ -1797,7 +1807,7 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
 
 void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
 {
-	if(!mNeedsAlphaAndPickMask)
+	if(sSkipAnalyzeAlpha || !mNeedsAlphaAndPickMask)
 	{
 		return ;
 	}
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h
index cf3c484c79d..57a052b2588 100755
--- a/indra/llrender/llimagegl.h
+++ b/indra/llrender/llimagegl.h
@@ -142,7 +142,7 @@ class LLImageGL : public LLRefCount
 	BOOL getHasGLTexture() const { return mTexName != 0; }
 	LLGLuint getTexName() const { return mTexName; }
 
-	BOOL getIsAlphaMask() const { return mIsMask; }
+	BOOL getIsAlphaMask() const;
 
 	BOOL getIsResident(BOOL test_now = FALSE); // not const
 
@@ -262,11 +262,12 @@ class LLImageGL : public LLRefCount
 #endif
 
 public:
-	static void initClass(S32 num_catagories) ;
+	static void initClass(S32 num_catagories, BOOL skip_analyze_alpha = false); 
 	static void cleanupClass() ;
 
 private:
 	static S32 sMaxCategories;
+	static BOOL sSkipAnalyzeAlpha;
 	
 	//the flag to allow to call readBackRaw(...).
 	//can be removed if we do not use that function at all.
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 63fe9312dfe..4f66b32c1f9 100755
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -1641,7 +1641,8 @@ LLViewerWindow::LLViewerWindow(const Params& p)
 		
 	// Init the image list.  Must happen after GL is initialized and before the images that
 	// LLViewerWindow needs are requested.
-	LLImageGL::initClass(LLGLTexture::MAX_GL_IMAGE_CATEGORY) ;
+	const BOOL SKIP_ANALYZE_ALPHA=FALSE;
+	LLImageGL::initClass(LLGLTexture::MAX_GL_IMAGE_CATEGORY, SKIP_ANALYZE_ALPHA) ;
 	gTextureList.init();
 	LLViewerTextureManager::init() ;
 	gBumpImageList.init();
-- 
GitLab