summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorDave Houlton <euclid@lindenlab.com>2022-01-11 17:29:04 -0700
committerDave Houlton <euclid@lindenlab.com>2022-01-27 15:44:35 -0700
commitc8926630af2b80c7db817b78df3a90378f0ecbbb (patch)
tree1a0708a71be09e7ac459b328715255ea0abd0285 /indra
parentaf830e5fc5840194be95140f644a27011b9b7e06 (diff)
SL-16418 optimize imageraw clear
Diffstat (limited to 'indra')
-rw-r--r--indra/llimage/llimage.cpp88
-rw-r--r--indra/newview/llviewermedia.cpp41
2 files changed, 77 insertions, 52 deletions
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index 15b07e5318..2855612158 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -925,47 +925,65 @@ bool LLImageRaw::setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height,
void LLImageRaw::clear(U8 r, U8 g, U8 b, U8 a)
{
- llassert( getComponents() <= 4 );
- // This is fairly bogus, but it'll do for now.
- if (isBufferInvalid())
- {
- LL_WARNS() << "Invalid image buffer" << LL_ENDL;
- return;
- }
+ LL_PROFILE_ZONE_NAMED("djh imageraw clear")
+ S8 components = getComponents();
+ llassert( components > 0 && components <= 4 );
- U8 *pos = getData();
- U32 x, y;
- for (x = 0; x < getWidth(); x++)
- {
- for (y = 0; y < getHeight(); y++)
- {
- *pos = r;
- pos++;
- if (getComponents() == 1)
- {
- continue;
- }
- *pos = g;
- pos++;
- if (getComponents() == 2)
- {
- continue;
- }
- *pos = b;
- pos++;
- if (getComponents() == 3)
- {
- continue;
- }
- *pos = a;
- pos++;
- }
- }
+ // This is fairly bogus, but it'll do for now.
+ if (isBufferInvalid())
+ {
+ LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+ return;
+ }
+
+ switch (components)
+ {
+ case 1:
+ {
+ U8 *dst = getData();
+ S32 count = getWidth() * getHeight();
+ llassert(count == getDataSize());
+ std::fill_n(dst, count, r);
+ break;
+ }
+ case 2:
+ {
+ U16 *dst = (U16 *)getData();
+ S32 count = getWidth() * getHeight();
+ llassert(count == getDataSize() / 2);
+ U16 val = (U16)(r | g << 8);
+ std::fill_n(dst, count, val);
+ break;
+ }
+ case 3:
+ {
+ U8 *dst = getData();
+ S32 count = getWidth() * getHeight();
+ llassert(count == getDataSize() / 3);
+ for (S32 i = 0; i < count; i++)
+ {
+ *dst++ = r;
+ *dst++ = g;
+ *dst++ = b;
+ }
+ break;
+ }
+ case 4:
+ {
+ U32 *dst = (U32 *)getData();
+ S32 count = getWidth() * getHeight();
+ llassert(count == getDataSize() / 4);
+ U32 val = (U32)(r | g << 8 | b << 16 | a << 24);
+ std::fill_n(dst, count, val);
+ break;
+ }
+ }
}
// Reverses the order of the rows in the image
void LLImageRaw::verticalFlip()
{
+ LL_PROFILE_ZONE_SCOPED;
S32 row_bytes = getWidth() * getComponents();
llassert(row_bytes > 0);
std::vector<U8> line_buffer(row_bytes);
diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index 63f57e81cc..ba9bbcc57e 100644
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -635,6 +635,7 @@ static bool proximity_comparitor(const LLViewerMediaImpl* i1, const LLViewerMedi
static LLTrace::BlockTimerStatHandle FTM_MEDIA_UPDATE("Update Media");
static LLTrace::BlockTimerStatHandle FTM_MEDIA_SPARE_IDLE("Spare Idle");
static LLTrace::BlockTimerStatHandle FTM_MEDIA_UPDATE_INTEREST("Update/Interest");
+static LLTrace::BlockTimerStatHandle FTM_MEDIA_UPDATE_VOLUME("Update/Volume");
static LLTrace::BlockTimerStatHandle FTM_MEDIA_SORT("Media Sort");
static LLTrace::BlockTimerStatHandle FTM_MEDIA_SORT2("Media Sort 2");
static LLTrace::BlockTimerStatHandle FTM_MEDIA_MISC("Misc");
@@ -2087,6 +2088,7 @@ void LLViewerMediaImpl::setMute(bool mute)
//////////////////////////////////////////////////////////////////////////////////////////
void LLViewerMediaImpl::updateVolume()
{
+ LL_RECORD_BLOCK_TIME(FTM_MEDIA_UPDATE_VOLUME);
if(mMediaSource)
{
// always scale the volume by the global media volume
@@ -2943,7 +2945,7 @@ LLViewerMediaTexture* LLViewerMediaImpl::updatePlaceholderImage()
}
LLViewerMediaTexture* placeholder_image = LLViewerTextureManager::getMediaTexture( mTextureId );
-
+
if (mNeedsNewTexture
|| placeholder_image->getUseMipMaps()
|| (placeholder_image->getWidth() != mMediaSource->getTextureWidth())
@@ -2960,25 +2962,30 @@ LLViewerMediaTexture* LLViewerMediaImpl::updatePlaceholderImage()
int texture_depth = mMediaSource->getTextureDepth();
// MEDIAOPT: check to see if size actually changed before doing work
- placeholder_image->destroyGLTexture();
+ placeholder_image->destroyGLTexture();
// MEDIAOPT: apparently just calling setUseMipMaps(FALSE) doesn't work?
placeholder_image->reinit(FALSE); // probably not needed
- // MEDIAOPT: seems insane that we actually have to make an imageraw then
- // immediately discard it
- LLPointer<LLImageRaw> raw = new LLImageRaw(texture_width, texture_height, texture_depth);
- // Clear the texture to the background color, ignoring alpha.
- // convert background color channels from [0.0, 1.0] to [0, 255];
- raw->clear(int(mBackgroundColor.mV[VX] * 255.0f), int(mBackgroundColor.mV[VY] * 255.0f), int(mBackgroundColor.mV[VZ] * 255.0f), 0xff);
- int discard_level = 0;
-
- // ask media source for correct GL image format constants
- placeholder_image->setExplicitFormat(mMediaSource->getTextureFormatInternal(),
- mMediaSource->getTextureFormatPrimary(),
- mMediaSource->getTextureFormatType(),
- mMediaSource->getTextureFormatSwapBytes());
-
- placeholder_image->createGLTexture(discard_level, raw);
+ // MEDIAOPT: seems insane that we actually have to make an imageraw then
+ // immediately discard it
+ LLPointer<LLImageRaw> raw = new LLImageRaw(texture_width, texture_height, texture_depth);
+ // Clear the texture to the background color, ignoring alpha.
+ // convert background color channels from [0.0, 1.0] to [0, 255];
+ {LL_PROFILE_ZONE_NAMED("djh clear raw");
+ raw->clear(int(mBackgroundColor.mV[VX] * 255.0f), int(mBackgroundColor.mV[VY] * 255.0f), int(mBackgroundColor.mV[VZ] * 255.0f), 0xff);
+ }
+ // ask media source for correct GL image format constants
+ {LL_PROFILE_ZONE_NAMED("djh setformat raw");
+ placeholder_image->setExplicitFormat(mMediaSource->getTextureFormatInternal(),
+ mMediaSource->getTextureFormatPrimary(),
+ mMediaSource->getTextureFormatType(),
+ mMediaSource->getTextureFormatSwapBytes());
+ }
+ {
+ LL_PROFILE_ZONE_NAMED("djh create ph");
+ int discard_level = 0;
+ placeholder_image->createGLTexture(discard_level, raw);
+ }
// MEDIAOPT: set this dynamically on play/stop
// FIXME