diff options
Diffstat (limited to 'indra/newview/llviewertexturelist.cpp')
-rw-r--r-- | indra/newview/llviewertexturelist.cpp | 259 |
1 files changed, 149 insertions, 110 deletions
diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index f8825fe7e1..c812504f9b 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -91,14 +91,14 @@ LLTextureKey::LLTextureKey(LLUUID id, ETexListType tex_type) /////////////////////////////////////////////////////////////////////////////// LLViewerTextureList::LLViewerTextureList() - : mForceResetTextureStats(FALSE), - mInitialized(FALSE) + : mForceResetTextureStats(false), + mInitialized(false) { } void LLViewerTextureList::init() { - mInitialized = TRUE ; + mInitialized = true ; sNumImages = 0; doPreloadImages(); } @@ -139,12 +139,12 @@ void LLViewerTextureList::doPreloadImages() image_list->initFromFile(); // turn off clamping and bilinear filtering for uv picking images - //LLViewerFetchedTexture* uv_test = preloadUIImage("uv_test1.tga", LLUUID::null, FALSE); - //uv_test->setClamp(FALSE, FALSE); - //uv_test->setMipFilterNearest(TRUE, TRUE); - //uv_test = preloadUIImage("uv_test2.tga", LLUUID::null, FALSE); - //uv_test->setClamp(FALSE, FALSE); - //uv_test->setMipFilterNearest(TRUE, TRUE); + //LLViewerFetchedTexture* uv_test = preloadUIImage("uv_test1.tga", LLUUID::null, false); + //uv_test->setClamp(false, false); + //uv_test->setMipFilterNearest(true, true); + //uv_test = preloadUIImage("uv_test2.tga", LLUUID::null, false); + //uv_test->setClamp(false, false); + //uv_test->setMipFilterNearest(true, true); LLViewerFetchedTexture* image = LLViewerTextureManager::getFetchedTextureFromFile("silhouette.j2c", FTT_LOCAL_FILE, MIPMAP_YES, LLViewerFetchedTexture::BOOST_UI); if (image) @@ -198,9 +198,9 @@ void LLViewerTextureList::doPreloadImages() LLPointer<LLImageRaw> img_blak_square_tex(new LLImageRaw(2, 2, 3)); memset(img_blak_square_tex->getData(), 0, img_blak_square_tex->getDataSize()); - LLPointer<LLViewerFetchedTexture> img_blak_square(new LLViewerFetchedTexture(img_blak_square_tex, FTT_DEFAULT, FALSE)); + LLPointer<LLViewerFetchedTexture> img_blak_square(new LLViewerFetchedTexture(img_blak_square_tex, FTT_DEFAULT, false)); gBlackSquareID = img_blak_square->getID(); - img_blak_square->setUnremovable(TRUE); + img_blak_square->setUnremovable(true); addImage(img_blak_square, TEX_LIST_STANDARD); } @@ -241,7 +241,7 @@ void LLViewerTextureList::doPrefetchImages() LLViewerTextureManager::getFetchedTexture(IMG_SHOT); LLViewerTextureManager::getFetchedTexture(IMG_SMOKE_POOF); - LLViewerFetchedTexture::sSmokeImagep = LLViewerTextureManager::getFetchedTexture(IMG_SMOKE, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + LLViewerFetchedTexture::sSmokeImagep = LLViewerTextureManager::getFetchedTexture(IMG_SMOKE, FTT_DEFAULT, true, LLGLTexture::BOOST_UI); LLViewerFetchedTexture::sSmokeImagep->setNoDelete(); LLStandardBumpmap::addstandard(); @@ -370,7 +370,7 @@ void LLViewerTextureList::shutdown() mImageList.clear(); - mInitialized = FALSE ; //prevent loading textures again. + mInitialized = false ; //prevent loading textures again. } void LLViewerTextureList::dump() @@ -391,7 +391,7 @@ void LLViewerTextureList::dump() } } -void LLViewerTextureList::destroyGL(BOOL save_state) +void LLViewerTextureList::destroyGL(bool save_state) { LLImageGL::destroyGL(save_state); } @@ -413,7 +413,7 @@ void LLViewerTextureList::restoreGL() LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& filename, FTType f_type, - BOOL usemipmaps, + bool usemipmaps, LLViewerTexture::EBoostLevel boost_priority, S8 texture_type, LLGLint internal_format, @@ -431,7 +431,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& { LL_WARNS() << "Failed to find local image file: " << filename << LL_ENDL; LLViewerTexture::EBoostLevel priority = LLGLTexture::BOOST_UI; - return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, TRUE, priority); + return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, true, priority); } std::string url = "file://" + full_path; @@ -441,7 +441,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromFile(const std::string& LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& url, FTType f_type, - BOOL usemipmaps, + bool usemipmaps, LLViewerTexture::EBoostLevel boost_priority, S8 texture_type, LLGLint internal_format, @@ -528,10 +528,43 @@ LLViewerFetchedTexture* LLViewerTextureList::getImageFromUrl(const std::string& return imagep; } +LLImageRaw* LLViewerTextureList::getRawImageFromMemory(const U8* data, U32 size, std::string_view mimetype) +{ + LLPointer<LLImageFormatted> image = LLImageFormatted::loadFromMemory(data, size, mimetype); + + if (image) + { + LLImageRaw* raw_image = new LLImageRaw(); + image->decode(raw_image, 0.f); + return raw_image; + } + else + { + return nullptr; + } +} + +LLViewerFetchedTexture* LLViewerTextureList::getImageFromMemory(const U8* data, U32 size, std::string_view mimetype) +{ + LLPointer<LLImageRaw> raw_image = getRawImageFromMemory(data, size, mimetype); + if (raw_image.notNull()) + { + LLViewerFetchedTexture* imagep = new LLViewerFetchedTexture(raw_image, FTT_LOCAL_FILE, true); + addImage(imagep, TEX_LIST_STANDARD); + + imagep->dontDiscard(); + imagep->setBoostLevel(LLViewerFetchedTexture::BOOST_PREVIEW); + return imagep; + } + else + { + return nullptr; + } +} LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, FTType f_type, - BOOL usemipmaps, + bool usemipmaps, LLViewerTexture::EBoostLevel boost_priority, S8 texture_type, LLGLint internal_format, @@ -550,7 +583,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, if (image_id.isNull()) { - return (LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI)); + return (LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, true, LLGLTexture::BOOST_UI)); } LLPointer<LLViewerFetchedTexture> imagep = findImage(image_id, get_element_type(boost_priority)); @@ -588,7 +621,7 @@ LLViewerFetchedTexture* LLViewerTextureList::getImage(const LLUUID &image_id, //when this function is called, there is no such texture in the gTextureList with image_id. LLViewerFetchedTexture* LLViewerTextureList::createImage(const LLUUID &image_id, FTType f_type, - BOOL usemipmaps, + bool usemipmaps, LLViewerTexture::EBoostLevel boost_priority, S8 texture_type, LLGLint internal_format, @@ -641,8 +674,8 @@ LLViewerFetchedTexture* LLViewerTextureList::createImage(const LLUUID &image_id, imagep->forceActive() ; } - mFastCacheList.insert(imagep); - imagep->setInFastCacheList(true); + mFastCacheList.insert(imagep); + imagep->setInFastCacheList(true); return imagep ; } @@ -685,12 +718,12 @@ void LLViewerTextureList::addImageToList(LLViewerFetchedTexture *image) } else { - if((mImageList.insert(image)).second != true) - { + if (!(mImageList.insert(image)).second) + { LL_WARNS() << "Error happens when insert image " << image->getID() << " into mImageList!" << LL_ENDL ; + } + image->setInImageList(true); } - image->setInImageList(TRUE) ; -} } void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) @@ -700,7 +733,7 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) llassert_always(mInitialized) ; llassert(image); - S32 count = 0; + size_t count = 0; if (image->isInImageList()) { count = mImageList.erase(image) ; @@ -740,7 +773,7 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) } } - image->setInImageList(FALSE) ; + image->setInImageList(false) ; } void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image, ETexListType tex_type) @@ -798,18 +831,18 @@ void LLViewerTextureList::dirtyImage(LLViewerFetchedTexture *image) void LLViewerTextureList::updateImages(F32 max_time) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; - static BOOL cleared = FALSE; + static bool cleared = false; if(gTeleportDisplay) { if(!cleared) { clearFetchingRequests(); gPipeline.clearRebuildGroups(); - cleared = TRUE; + cleared = true; } return; } - cleared = FALSE; + cleared = false; LLAppViewer::getTextureFetch()->setTextureBandwidth(LLTrace::get_frame_recording().getPeriodMeanPerSec(LLStatViewer::TEXTURE_NETWORK_DATA_RECEIVED).value()); @@ -888,7 +921,7 @@ static void touch_texture(LLViewerFetchedTexture* tex, F32 vsize) } } -extern BOOL gCubeSnapshot; +extern bool gCubeSnapshot; void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imagep) { @@ -901,12 +934,14 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag llassert(!gCubeSnapshot); static LLCachedControl<F32> bias_distance_scale(gSavedSettings, "TextureBiasDistanceScale", 1.f); + static LLCachedControl<F32> texture_scale_min(gSavedSettings, "TextureScaleMinAreaFactor", 0.04f); + static LLCachedControl<F32> texture_scale_max(gSavedSettings, "TextureScaleMaxAreaFactor", 25.f); LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE { for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) { - for (U32 fi = 0; fi < imagep->getNumFaces(i); ++fi) + for (S32 fi = 0; fi < imagep->getNumFaces(i); ++fi) { LLFace* face = (*(imagep->getFaceList(i)))[fi]; @@ -914,27 +949,27 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag { F32 vsize = face->getPixelArea(); - // scale desired texture resolution higher or lower depending on texture scale + // Scale desired texture resolution higher or lower depending on texture scale + // + // Minimum usage examples: a 1024x1024 texture with aplhabet, runing string + // shows one letter at a time + // + // Maximum usage examples: huge chunk of terrain repeats texture const LLTextureEntry* te = face->getTextureEntry(); F32 min_scale = te ? llmin(fabsf(te->getScaleS()), fabsf(te->getScaleT())) : 1.f; - min_scale = llmax(min_scale*min_scale, 0.1f); + min_scale = llclamp(min_scale*min_scale, texture_scale_min(), texture_scale_max()); vsize /= min_scale; - -//#if LL_DARWIN -// vsize /= 1.f + LLViewerTexture::sDesiredDiscardBias*(1.f+face->getDrawable()->mDistanceWRTCamera*bias_distance_scale); -//#else vsize /= LLViewerTexture::sDesiredDiscardBias; vsize /= llmax(1.f, (LLViewerTexture::sDesiredDiscardBias-1.f) * (1.f + face->getDrawable()->mDistanceWRTCamera * bias_distance_scale)); F32 radius; F32 cos_angle_to_view_dir; - BOOL in_frustum = face->calcPixelArea(cos_angle_to_view_dir, radius); + bool in_frustum = face->calcPixelArea(cos_angle_to_view_dir, radius); if (!in_frustum || !face->getDrawable()->isVisible()) { // further reduce by discard bias when off screen or occluded vsize /= LLViewerTexture::sDesiredDiscardBias; } -//#endif // if a GLTF material is present, ignore that face // as far as this texture stats go, but update the GLTF material // stats @@ -1189,7 +1224,7 @@ void LLViewerTextureList::updateImagesUpdateStats() LLViewerFetchedTexture* imagep = *iter++; imagep->resetTextureStats(); } - mForceResetTextureStats = FALSE; + mForceResetTextureStats = false; } } @@ -1208,7 +1243,7 @@ void LLViewerTextureList::decodeAllImages(F32 max_time) { LLViewerFetchedTexture* imagep = *iter++; image_list.push_back(imagep); - imagep->setInImageList(FALSE) ; + imagep->setInImageList(false) ; } llassert_always(image_list.size() == mImageList.size()) ; @@ -1231,7 +1266,7 @@ void LLViewerTextureList::decodeAllImages(F32 max_time) } std::shared_ptr<LL::WorkQueue> main_queue = LLImageGLThread::sEnabledTextures ? LL::WorkQueue::getInstance("mainloop") : NULL; // Run threads - S32 fetch_pending = 0; + size_t fetch_pending = 0; while (1) { LLAppViewer::instance()->getTextureCache()->update(1); // unpauses the texture cache thread @@ -1273,6 +1308,8 @@ bool LLViewerTextureList::createUploadFile(LLPointer<LLImageRaw> raw_image, { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + LLImageDataSharedLock lock(raw_image); + // make a copy, since convertToUploadFile scales raw image LLPointer<LLImageRaw> scale_image = new LLImageRaw( raw_image->getData(), @@ -1316,63 +1353,63 @@ bool LLViewerTextureList::createUploadFile(const std::string& filename, LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; try { - // Load the image - LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec); - if (image.isNull()) - { - LL_WARNS() << "Couldn't open the image to be uploaded." << LL_ENDL; - return false; - } - if (!image->load(filename)) - { - image->setLastError("Couldn't load the image to be uploaded."); - return false; - } - // Decompress or expand it in a raw image structure - LLPointer<LLImageRaw> raw_image = new LLImageRaw; - if (!image->decode(raw_image, 0.0f)) - { - image->setLastError("Couldn't decode the image to be uploaded."); - return false; - } - // Check the image constraints - if ((image->getComponents() != 3) && (image->getComponents() != 4)) - { - image->setLastError("Image files with less than 3 or more than 4 components are not supported."); - return false; - } - if (image->getWidth() < min_image_dimentions || image->getHeight() < min_image_dimentions) - { - std::string reason = llformat("Images below %d x %d pixels are not allowed. Actual size: %d x %dpx", - min_image_dimentions, - min_image_dimentions, - image->getWidth(), - image->getHeight()); - image->setLastError(reason); - return false; - } - // Convert to j2c (JPEG2000) and save the file locally - LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image, max_image_dimentions, force_square); - if (compressedImage.isNull()) - { - image->setLastError("Couldn't convert the image to jpeg2000."); - LL_INFOS() << "Couldn't convert to j2c, file : " << filename << LL_ENDL; - return false; - } - if (!compressedImage->save(out_filename)) - { - image->setLastError("Couldn't create the jpeg2000 image for upload."); - LL_INFOS() << "Couldn't create output file : " << out_filename << LL_ENDL; - return false; - } - // Test to see if the encode and save worked - LLPointer<LLImageJ2C> integrity_test = new LLImageJ2C; - if (!integrity_test->loadAndValidate(out_filename)) - { - image->setLastError("The created jpeg2000 image is corrupt."); - LL_INFOS() << "Image file : " << out_filename << " is corrupt" << LL_ENDL; - return false; - } + // Load the image + LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec); + if (image.isNull()) + { + LL_WARNS() << "Couldn't open the image to be uploaded." << LL_ENDL; + return false; + } + if (!image->load(filename)) + { + image->setLastError("Couldn't load the image to be uploaded."); + return false; + } + // Decompress or expand it in a raw image structure + LLPointer<LLImageRaw> raw_image = new LLImageRaw; + if (!image->decode(raw_image, 0.0f)) + { + image->setLastError("Couldn't decode the image to be uploaded."); + return false; + } + // Check the image constraints + if ((image->getComponents() != 3) && (image->getComponents() != 4)) + { + image->setLastError("Image files with less than 3 or more than 4 components are not supported."); + return false; + } + if (image->getWidth() < min_image_dimentions || image->getHeight() < min_image_dimentions) + { + std::string reason = llformat("Images below %d x %d pixels are not allowed. Actual size: %d x %dpx", + min_image_dimentions, + min_image_dimentions, + image->getWidth(), + image->getHeight()); + image->setLastError(reason); + return false; + } + // Convert to j2c (JPEG2000) and save the file locally + LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image, max_image_dimentions, force_square); + if (compressedImage.isNull()) + { + image->setLastError("Couldn't convert the image to jpeg2000."); + LL_INFOS() << "Couldn't convert to j2c, file : " << filename << LL_ENDL; + return false; + } + if (!compressedImage->save(out_filename)) + { + image->setLastError("Couldn't create the jpeg2000 image for upload."); + LL_INFOS() << "Couldn't create output file : " << out_filename << LL_ENDL; + return false; + } + // Test to see if the encode and save worked + LLPointer<LLImageJ2C> integrity_test = new LLImageJ2C; + if (!integrity_test->loadAndValidate( out_filename )) + { + image->setLastError("The created jpeg2000 image is corrupt."); + LL_INFOS() << "Image file : " << out_filename << " is corrupt" << LL_ENDL; + return false; + } } catch (...) { @@ -1386,6 +1423,8 @@ bool LLViewerTextureList::createUploadFile(const std::string& filename, LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImageRaw> raw_image, const S32 max_image_dimentions, bool force_square, bool force_lossless) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + LLImageDataLock lock(raw_image); + if (force_square) { S32 biggest_side = llmax(raw_image->getWidth(), raw_image->getHeight()); @@ -1403,7 +1442,7 @@ LLPointer<LLImageJ2C> LLViewerTextureList::convertToUploadFile(LLPointer<LLImage (gSavedSettings.getBOOL("LosslessJ2CUpload") && (raw_image->getWidth() * raw_image->getHeight() <= LL_IMAGE_REZ_LOSSLESS_CUTOFF * LL_IMAGE_REZ_LOSSLESS_CUTOFF))) { - compressedImage->setReversible(TRUE); + compressedImage->setReversible(true); } @@ -1479,7 +1518,7 @@ LLUIImagePtr LLUIImageList::getUIImageByID(const LLUUID& image_id, S32 priority) return found_it->second; } - const BOOL use_mips = FALSE; + const bool use_mips = false; const LLRect scale_rect = LLRect::null; const LLRect clip_rect = LLRect::null; return loadUIImageByID(image_id, use_mips, scale_rect, clip_rect, (LLViewerTexture::EBoostLevel)priority); @@ -1495,14 +1534,14 @@ LLUIImagePtr LLUIImageList::getUIImage(const std::string& image_name, S32 priori return found_it->second; } - const BOOL use_mips = FALSE; + const bool use_mips = false; const LLRect scale_rect = LLRect::null; const LLRect clip_rect = LLRect::null; return loadUIImageByName(image_name, image_name, use_mips, scale_rect, clip_rect, (LLViewerTexture::EBoostLevel)priority); } LLUIImagePtr LLUIImageList::loadUIImageByName(const std::string& name, const std::string& filename, - BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, + bool use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, LLUIImage::EScaleStyle scale_style) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; @@ -1515,7 +1554,7 @@ LLUIImagePtr LLUIImageList::loadUIImageByName(const std::string& name, const std } LLUIImagePtr LLUIImageList::loadUIImageByID(const LLUUID& id, - BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, + bool use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLViewerTexture::EBoostLevel boost_priority, LLUIImage::EScaleStyle scale_style) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; @@ -1527,7 +1566,7 @@ LLUIImagePtr LLUIImageList::loadUIImageByID(const LLUUID& id, return loadUIImage(imagep, id.asString(), use_mips, scale_rect, clip_rect, scale_style); } -LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, +LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, bool use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLUIImage::EScaleStyle scale_style) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; @@ -1562,12 +1601,12 @@ LLUIImagePtr LLUIImageList::loadUIImage(LLViewerFetchedTexture* imagep, const st datap->mImageScaleRegion = scale_rect; datap->mImageClipRegion = clip_rect; - imagep->setLoadedCallback(onUIImageLoaded, 0, FALSE, FALSE, datap, NULL); + imagep->setLoadedCallback(onUIImageLoaded, 0, false, false, datap, NULL); } return new_imagep; } -LLUIImagePtr LLUIImageList::preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLUIImage::EScaleStyle scale_style) +LLUIImagePtr LLUIImageList::preloadUIImage(const std::string& name, const std::string& filename, bool use_mips, const LLRect& scale_rect, const LLRect& clip_rect, LLUIImage::EScaleStyle scale_style) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; // look for existing image @@ -1582,7 +1621,7 @@ LLUIImagePtr LLUIImageList::preloadUIImage(const std::string& name, const std::s } //static -void LLUIImageList::onUIImageLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* user_data ) +void LLUIImageList::onUIImageLoaded( bool success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, bool final, void* user_data ) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; if(!success || !user_data) |