Skip to content

Commit

Permalink
SL-20735 Fix blury profile pictures #2 (#963)
Browse files Browse the repository at this point in the history
Scaling was added to thumbnail images as a measure of memory preservation and said scaling doesn't work well when larger images are needed so had to remake profile images to no longer use thumbnails.
  • Loading branch information
akleshchev authored Mar 12, 2024
1 parent 326055b commit 6ed3a16
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 283 deletions.
284 changes: 170 additions & 114 deletions indra/newview/llfloaterprofiletexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,173 @@
#include "llpreview.h" // fors constants
#include "lltrans.h"
#include "llviewercontrol.h"
#include "lltextureview.h"
#include "llviewertexture.h"
#include "llviewertexturelist.h"


//////////////////////////////////////////////////////////////////////////
// LLProfileImageCtrl
//////////////////////////////////////////////////////////////////////////

LLFloaterProfileTexture::LLFloaterProfileTexture(LLView* owner)
: LLFloater(LLSD())
, mUpdateDimensions(TRUE)
, mLastHeight(0)
, mLastWidth(0)
static LLDefaultChildRegistry::Register<LLProfileImageCtrl> r("profile_image");

LLProfileImageCtrl::LLProfileImageCtrl(const LLProfileImageCtrl::Params& p)
: LLIconCtrl(p)
, mImage(NULL)
, mImageOldBoostLevel(LLGLTexture::BOOST_NONE)
, mOwnerHandle(owner->getHandle())
, mWasNoDelete(false)
, mImageLoadedSignal(NULL)
{
buildFromFile("floater_profile_texture.xml");
}

LLFloaterProfileTexture::~LLFloaterProfileTexture()
LLProfileImageCtrl::~LLProfileImageCtrl()
{
LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList);
releaseTexture();

delete mImageLoadedSignal;
}

void LLProfileImageCtrl::releaseTexture()
{
if (mImage.notNull())
{
mImage->setBoostLevel(mImageOldBoostLevel);
if (!mWasNoDelete)
{
// In most cases setBoostLevel marks images as NO_DELETE
mImage->forceActive();
}
mImage = NULL;
}
}

void LLProfileImageCtrl::setValue(const LLSD& value)
{
LLUUID id = value.asUUID();
setImageAssetId(id);
if (id.isNull())
{
LLIconCtrl::setValue("Generic_Person_Large", LLGLTexture::BOOST_UI);
}
else
{
// called second to not change priority before it gets saved to mImageOldBoostLevel
LLIconCtrl::setValue(value, LLGLTexture::BOOST_PREVIEW);
}
}

void LLProfileImageCtrl::draw()
{
if (mImage.notNull())
{
// Pump the texture priority
mImage->addTextureStats(MAX_IMAGE_AREA);
mImage->setKnownDrawSize(LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT, LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT);
}
LLIconCtrl::draw();
}

boost::signals2::connection LLProfileImageCtrl::setImageLoadedCallback(const image_loaded_signal_t::slot_type& cb)
{
if (!mImageLoadedSignal) mImageLoadedSignal = new image_loaded_signal_t();

return mImageLoadedSignal->connect(cb);
}

void LLProfileImageCtrl::setImageAssetId(const LLUUID& asset_id)
{
if (mImageID == asset_id)
{
return;
}

releaseTexture();

mImageID = asset_id;
if (mImageID.notNull())
{
mImage = LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, MIPMAP_YES, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
mWasNoDelete = mImage->getTextureState() == LLGLTexture::NO_DELETE;
mImageOldBoostLevel = mImage->getBoostLevel();
mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
mImage->setKnownDrawSize(LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT, LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT);
mImage->forceToSaveRawImage(0);

if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
{
mImage->setLoadedCallback(LLProfileImageCtrl::onImageLoaded,
0, TRUE, FALSE, new LLHandle<LLUICtrl>(getHandle()), &mCallbackTextureList);
}
else
{
onImageLoaded(true, mImage);
}
}
}

void LLProfileImageCtrl::onImageLoaded(bool success, LLViewerFetchedTexture* img)
{
if (mImageLoadedSignal)
{
(*mImageLoadedSignal)(success, img);
}
}

// static
void LLProfileImageCtrl::onImageLoaded(BOOL success,
LLViewerFetchedTexture* src_vi,
LLImageRaw* src,
LLImageRaw* aux_src,
S32 discard_level,
BOOL final,
void* userdata)
{
if (!userdata) return;

LLHandle<LLUICtrl>* handle = (LLHandle<LLUICtrl>*)userdata;

if (!handle->isDead())
{
LLProfileImageCtrl* caller = static_cast<LLProfileImageCtrl*>(handle->get());
if (caller && caller->mImageLoadedSignal)
{
(*caller->mImageLoadedSignal)(success, src_vi);
}
}

if (final || !success)
{
delete handle;
}
}


//////////////////////////////////////////////////////////////////////////
// LLFloaterProfileTexture
//////////////////////////////////////////////////////////////////////////

LLFloaterProfileTexture::LLFloaterProfileTexture(LLView* owner)
: LLFloater(LLSD())
, mLastHeight(0)
, mLastWidth(0)
, mOwnerHandle(owner->getHandle())
, mContextConeOpacity(0.f)
, mCloseButton(NULL)
, mProfileIcon(NULL)
{
buildFromFile("floater_profile_texture.xml");
}

LLFloaterProfileTexture::~LLFloaterProfileTexture()
{
}

// virtual
BOOL LLFloaterProfileTexture::postBuild()
{
mProfileIcon = getChild<LLIconCtrl>("profile_pic");
mProfileIcon = getChild<LLProfileImageCtrl>("profile_pic");
mProfileIcon->setImageLoadedCallback([this](BOOL success, LLViewerFetchedTexture* imagep) {onImageLoaded(success, imagep); });

mCloseButton = getChild<LLButton>("close_btn");
mCloseButton->setCommitCallback([this](LLUICtrl*, void*) { closeFloater(); }, nullptr);
Expand All @@ -81,55 +217,41 @@ void LLFloaterProfileTexture::reshape(S32 width, S32 height, BOOL called_from_pa
// When we receive it, reshape the window accordingly.
void LLFloaterProfileTexture::updateDimensions()
{
if (mImage.isNull())
LLPointer<LLViewerFetchedTexture> image = mProfileIcon->getImage();
if (image.isNull())
{
return;
}
if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
if ((image->getFullWidth() * image->getFullHeight()) == 0)
{
return;
}

S32 img_width = mImage->getFullWidth();
S32 img_height = mImage->getFullHeight();

if (mAssetStatus != LLPreview::PREVIEW_ASSET_LOADED
|| mLastWidth != img_width
|| mLastHeight != img_height)
{
mAssetStatus = LLPreview::PREVIEW_ASSET_LOADED;
// Asset has been fully loaded
mUpdateDimensions = TRUE;
}
S32 img_width = image->getFullWidth();
S32 img_height = image->getFullHeight();

mLastHeight = img_height;
mLastWidth = img_width;

// Reshape the floater only when required
if (mUpdateDimensions)
{
mUpdateDimensions = FALSE;
LLRect old_floater_rect = getRect();
LLRect old_image_rect = mProfileIcon->getRect();
S32 width = old_floater_rect.getWidth() - old_image_rect.getWidth() + mLastWidth;
S32 height = old_floater_rect.getHeight() - old_image_rect.getHeight() + mLastHeight;

LLRect old_floater_rect = getRect();
LLRect old_image_rect = mProfileIcon->getRect();
S32 width = old_floater_rect.getWidth() - old_image_rect.getWidth() + mLastWidth;
S32 height = old_floater_rect.getHeight() - old_image_rect.getHeight() + mLastHeight;
const F32 MAX_DIMENTIONS = 512; // most profiles are supposed to be 256x256

const F32 MAX_DIMENTIONS = 512; // most profiles are supposed to be 256x256

S32 biggest_dim = llmax(width, height);
if (biggest_dim > MAX_DIMENTIONS)
{
F32 scale_down = MAX_DIMENTIONS / (F32)biggest_dim;
width *= scale_down;
height *= scale_down;
}
S32 biggest_dim = llmax(width, height);
if (biggest_dim > MAX_DIMENTIONS)
{
F32 scale_down = MAX_DIMENTIONS / (F32)biggest_dim;
width *= scale_down;
height *= scale_down;
}

//reshape floater
reshape(width, height);
//reshape floater
reshape(width, height);

gFloaterView->adjustToFitScreen(this, FALSE);
}
gFloaterView->adjustToFitScreen(this, FALSE);
}

void LLFloaterProfileTexture::draw()
Expand All @@ -139,13 +261,6 @@ void LLFloaterProfileTexture::draw()
static LLCachedControl<F32> max_opacity(gSavedSettings, "PickerContextOpacity", 0.4f);
drawConeToOwner(mContextConeOpacity, max_opacity, owner);

if (mImage.notNull())
{
// Pump the texture priority
mImage->addTextureStats(MAX_IMAGE_AREA);
mImage->setKnownDrawSize(LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT, LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT);
}

LLFloater::draw();
}

Expand All @@ -156,77 +271,18 @@ void LLFloaterProfileTexture::onOpen(const LLSD& key)

void LLFloaterProfileTexture::resetAsset()
{
mProfileIcon->setValue("Generic_Person_Large");
mImageID = LLUUID::null;
if (mImage.notNull())
{
mImage->setBoostLevel(mImageOldBoostLevel);
mImage = NULL;
}
mProfileIcon->setValue(LLUUID::null);
}
void LLFloaterProfileTexture::loadAsset(const LLUUID &image_id)
{
if (mImageID != image_id)
{
if (mImage.notNull())
{
mImage->setBoostLevel(mImageOldBoostLevel);
mImage = NULL;
}
}
else
{
return;
}

mProfileIcon->setValue(image_id);
mImageID = image_id;
mImage = LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, MIPMAP_TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
mImageOldBoostLevel = mImage->getBoostLevel();
mImage->setKnownDrawSize(LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT, LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT);
mImage->forceToSaveRawImage(0);

if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
{
mImage->setLoadedCallback(LLFloaterProfileTexture::onTextureLoaded,
0, TRUE, FALSE, new LLHandle<LLFloater>(getHandle()), &mCallbackTextureList);

mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
mAssetStatus = LLPreview::PREVIEW_ASSET_LOADING;
}
else
{
mAssetStatus = LLPreview::PREVIEW_ASSET_LOADED;
}

mUpdateDimensions = TRUE;
updateDimensions();
}

// static
void LLFloaterProfileTexture::onTextureLoaded(
BOOL success,
LLViewerFetchedTexture *src_vi,
LLImageRaw* src,
LLImageRaw* aux_src,
S32 discard_level,
BOOL final,
void* userdata)
void LLFloaterProfileTexture::onImageLoaded(BOOL success, LLViewerFetchedTexture* imagep)
{
LLHandle<LLFloater>* handle = (LLHandle<LLFloater>*)userdata;

if (!handle->isDead())
{
LLFloaterProfileTexture* floater = static_cast<LLFloaterProfileTexture*>(handle->get());
if (floater && success)
{
floater->mUpdateDimensions = TRUE;
floater->updateDimensions();
}
}

if (final || !success)
if (success)
{
delete handle;
updateDimensions();
}
}
Loading

0 comments on commit 6ed3a16

Please sign in to comment.