From 81192236ac44ea500ea6ec6f8de32be11e9165ca Mon Sep 17 00:00:00 2001
From: Monroe Linden <monroe@lindenlab.com>
Date: Thu, 5 Nov 2009 16:08:04 -0800
Subject: Fix for DEV-39258.

When the amount of the texture that's being drawn by the plugin shrinks in either width or height, reallocate the texture (which clears it).
---
 indra/newview/llviewermedia.cpp | 14 ++++++++++++--
 indra/newview/llviewermedia.h   |  2 ++
 2 files changed, 14 insertions(+), 2 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index 55e4f28e75..40bf9fb1fe 100644
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -658,6 +658,8 @@ LLViewerMediaImpl::LLViewerMediaImpl(	  const LLUUID& texture_id,
 	mMediaAutoScale(media_auto_scale),
 	mMediaLoop(media_loop),
 	mNeedsNewTexture(true),
+	mTextureUsedWidth(0),
+	mTextureUsedHeight(0),
 	mSuspendUpdates(false),
 	mVisible(true),
 	mLastSetCursor( UI_CURSOR_ARROW ),
@@ -1568,8 +1570,11 @@ LLViewerMediaTexture* LLViewerMediaImpl::updatePlaceholderImage()
 	
 	if (mNeedsNewTexture 
 		|| placeholder_image->getUseMipMaps()
-		|| placeholder_image->getWidth() != mMediaSource->getTextureWidth()
-		|| placeholder_image->getHeight() != mMediaSource->getTextureHeight())
+		|| (placeholder_image->getWidth() != mMediaSource->getTextureWidth())
+		|| (placeholder_image->getHeight() != mMediaSource->getTextureHeight())
+		|| (mTextureUsedWidth > mMediaSource->getWidth())
+		|| (mTextureUsedHeight > mMediaSource->getHeight())
+		)
 	{
 		LL_DEBUGS("Media") << "initializing media placeholder" << LL_ENDL;
 		LL_DEBUGS("Media") << "movie image id " << mTextureId << LL_ENDL;
@@ -1601,6 +1606,11 @@ LLViewerMediaTexture* LLViewerMediaImpl::updatePlaceholderImage()
 		// FIXME
 //		placeholder_image->mIsMediaTexture = true;
 		mNeedsNewTexture = false;
+				
+		// If the amount of the texture being drawn by the media goes down in either width or height, 
+		// recreate the texture to avoid leaving parts of the old image behind.
+		mTextureUsedWidth = mMediaSource->getWidth();
+		mTextureUsedHeight = mMediaSource->getHeight();
 	}
 	
 	return placeholder_image;
diff --git a/indra/newview/llviewermedia.h b/indra/newview/llviewermedia.h
index d6dde0c93e..4cb0817735 100644
--- a/indra/newview/llviewermedia.h
+++ b/indra/newview/llviewermedia.h
@@ -306,6 +306,8 @@ public:
 	bool mMediaAutoScale;
 	bool mMediaLoop;
 	bool mNeedsNewTexture;
+	S32 mTextureUsedWidth;
+	S32 mTextureUsedHeight;
 	bool mSuspendUpdates;
 	bool mVisible;
 	ECursorType mLastSetCursor;
-- 
cgit v1.2.3