llviewertexturelist.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * @file llviewertexturelist.h
  3. * @brief Object for managing the list of images within a region
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERTEXTURELIST_H
  33. #define LL_LLVIEWERTEXTURELIST_H
  34. #include <set>
  35. #include <map>
  36. #include "hbfastset.h"
  37. #include "llstat.h"
  38. #include "llstring.h" // For hash_value(const std::string&)
  39. #include "llui.h"
  40. #include "llworkqueue.h"
  41. #include "llviewertexture.h"
  42. constexpr U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128;
  43. constexpr bool MIPMAP_YES = true;
  44. constexpr bool MIPMAP_NO = false;
  45. constexpr bool GL_TEXTURE_YES = true;
  46. constexpr bool GL_TEXTURE_NO = false;
  47. constexpr bool IMMEDIATE_YES = true;
  48. constexpr bool IMMEDIATE_NO = false;
  49. class LLImageJ2C;
  50. class LLMessageSystem;
  51. typedef void (*LLImageCallback)(bool success, LLViewerFetchedTexture* texp,
  52. LLImageRaw* imagep, LLImageRaw* aux_imagep,
  53. S32 discard_level, bool is_final,
  54. void* userdata);
  55. class LLViewerTextureList
  56. {
  57. friend class LLLocalBitmap;
  58. friend class LLTextureView;
  59. friend class LLViewerTextureManager;
  60. protected:
  61. LOG_CLASS(LLViewerTextureList);
  62. public:
  63. static bool createUploadFile(const std::string& filename,
  64. const std::string& out_filename, U8 codec,
  65. bool* is_2k_texturep = NULL);
  66. // WARNING: this method modifies the rawp image !
  67. static LLPointer<LLImageJ2C> convertToUploadFile(LLPointer<LLImageRaw> rawp,
  68. S32 max_dimentions = -1,
  69. bool force_lossless = false);
  70. static void processImageNotInDatabase(LLMessageSystem* msg, void** datap);
  71. static void receiveImageHeader(LLMessageSystem* msg, void** datap);
  72. static void receiveImagePacket(LLMessageSystem* msg, void** datap);
  73. public:
  74. LLViewerTextureList();
  75. void init();
  76. void shutdown();
  77. void dump();
  78. LL_INLINE bool isInitialized() const { return mInitialized; }
  79. static void destroyGL(bool save_state = true);
  80. static void restoreGL();
  81. LLViewerFetchedTexture* findImage(const LLUUID& image_id);
  82. void dirtyImage(LLViewerFetchedTexture* image);
  83. // Using image stats, determine what images are necessary, and perform
  84. // image updates.
  85. void updateImages(F32 max_time);
  86. void forceImmediateUpdate(LLViewerFetchedTexture* imagep);
  87. // Decode and create textures for all images currently in list.
  88. S32 decodeAllImages(F32 max_decode_time);
  89. LL_INLINE S32 getMaxResidentTexMem() const { return mMaxResidentTexMemInMegaBytes; }
  90. LL_INLINE S32 getMaxTotalTextureMem() const { return mMaxTotalTextureMemInMegaBytes; }
  91. LL_INLINE S32 getNumImages() { return mImageList.size(); }
  92. void updateMaxResidentTexMem(S32 mem);
  93. void doPrefetchImages();
  94. void clearFetchingRequests();
  95. static S32 getMinVideoRamSetting();
  96. static S32 getMaxVideoRamSetting(bool get_recommended = false);
  97. static void resetFrameStats();
  98. LL_INLINE void flushOldImages() { mFlushOldImages = true; }
  99. void addImage(LLViewerFetchedTexture* image);
  100. void deleteImage(LLViewerFetchedTexture* image);
  101. private:
  102. void updateImagesDecodePriorities();
  103. F32 updateImagesCreateTextures(F32 max_time);
  104. F32 updateImagesFetchTextures(F32 max_time);
  105. void updateImagesUpdateStats();
  106. void addImageToList(LLViewerFetchedTexture* image);
  107. void removeImageFromList(LLViewerFetchedTexture* image);
  108. LLViewerFetchedTexture* getImage(const LLUUID& image_id,
  109. FTType f_type = FTT_DEFAULT,
  110. bool usemipmap = true,
  111. // Get the requested level immediately upon creation:
  112. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  113. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  114. S32 internal_format = 0,
  115. U32 primary_format = 0,
  116. LLHost from_host = LLHost());
  117. LLViewerFetchedTexture* getImageFromFile(const std::string& filename,
  118. bool usemipmap = true,
  119. // Get the requested level immediately upon creation:
  120. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  121. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  122. S32 internal_format = 0,
  123. U32 primary_format = 0,
  124. const LLUUID& force_id = LLUUID::null);
  125. LLViewerFetchedTexture* getImageFromUrl(const std::string& url,
  126. FTType f_type,
  127. bool usemipmap = true,
  128. // Get the requested level immediately upon creation:
  129. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  130. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  131. S32 internal_format = 0,
  132. U32 primary_format = 0,
  133. const LLUUID& force_id = LLUUID::null);
  134. LLViewerFetchedTexture* createImage(const LLUUID& image_id,
  135. FTType f_type, bool usemipmap = true,
  136. // Get the requested level immediately upon creation.
  137. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  138. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  139. S32 internal_format = 0,
  140. U32 primary_format = 0,
  141. LLHost from_host = LLHost());
  142. // Request image from a specific host, used for baked avatar textures.
  143. // Implemented in header in case someone changes default params above. JC
  144. LLViewerFetchedTexture* getImageFromHost(const LLUUID& image_id,
  145. FTType f_type, LLHost host)
  146. {
  147. return getImage(image_id, f_type, true, LLGLTexture::BOOST_NONE,
  148. LLViewerTexture::LOD_TEXTURE, 0, 0, host);
  149. }
  150. private:
  151. static S32 sNumImages;
  152. static S32 sUpdatedThisFrame;
  153. static void (*sUUIDCallback)(void**, const LLUUID&);
  154. typedef std::map<LLUUID, LLPointer<LLViewerFetchedTexture> > uuid_map_t;
  155. uuid_map_t mUUIDMap;
  156. // Simply holds on to LLViewerFetchedTexture references to stop them from
  157. // being purged too soon
  158. std::vector<LLPointer<LLViewerFetchedTexture> > mImagePreloads;
  159. typedef std::set<LLPointer<LLViewerFetchedTexture>,
  160. LLViewerFetchedTexture::Compare> priority_list_t;
  161. priority_list_t mImageList;
  162. LLUUID mLastUpdateUUID;
  163. LLUUID mLastFetchUUID;
  164. S32 mMaxResidentTexMemInMegaBytes;
  165. S32 mMaxTotalTextureMemInMegaBytes;
  166. // Texture fetching parameters, based on debug settings and possibly on
  167. // last TP/login time and camera speed.
  168. F32 mUpdateHighPriority;
  169. F32 mUpdateMaxMediumPriority;
  170. F32 mUpdateMinMediumPriority;
  171. F32 mLastGLImageCleaning;
  172. bool mFlushOldImages;
  173. bool mInitialized;
  174. public:
  175. bool mForceResetTextureStats;
  176. typedef safe_hset<LLPointer<LLViewerFetchedTexture> > image_list_t;
  177. image_list_t mCreateTextureList;
  178. typedef safe_hset<LLPointer<LLViewerFetchedTexture> > callback_list_t;
  179. callback_list_t mCallbackList;
  180. // Note: just raw pointers because they are never referenced, just compared
  181. // against
  182. typedef fast_hset<LLViewerFetchedTexture*> dirty_list_t;
  183. dirty_list_t mDirtyTextureList;
  184. static LLStat sNumImagesStat;
  185. static LLStat sNumUpdatesStat;
  186. static LLStat sNumRawImagesStat;
  187. static LLStat sGLTexMemStat;
  188. static LLStat sGLBoundMemStat;
  189. static U32 sTextureBits;
  190. static U32 sTexturePackets;
  191. static F32 sLastTeleportTime; // In gFrameTimeSeconds seconds
  192. static F32 sFetchingBoostFactor;
  193. };
  194. class LLUIImageList : public LLImageProviderInterface,
  195. public LLSingleton<LLUIImageList>
  196. {
  197. friend class LLSingleton<LLUIImageList>;
  198. protected:
  199. LOG_CLASS(LLUIImageList);
  200. public:
  201. // LLImageProviderInterface
  202. LLUIImagePtr getUIImageByID(const LLUUID& id) override;
  203. LLUIImagePtr getUIImage(const std::string& name) override;
  204. void cleanUp() override;
  205. bool initFromFile();
  206. LLUIImagePtr preloadUIImage(const std::string& name,
  207. const std::string& filename, bool use_mips,
  208. const LLRect& scale_rect);
  209. static void onUIImageLoaded(bool success, LLViewerFetchedTexture* texp,
  210. LLImageRaw* imagep, LLImageRaw* aux_imagep,
  211. S32 discard_level, bool is_final,
  212. void* userdata);
  213. private:
  214. LLUIImagePtr loadUIImageByName(const std::string& name,
  215. const std::string& filename,
  216. bool use_mips = MIPMAP_NO,
  217. const LLRect& scale_rect = LLRect::null);
  218. LLUIImagePtr loadUIImageByID(const LLUUID& id, bool use_mips = MIPMAP_NO,
  219. const LLRect& scale_rect = LLRect::null);
  220. LLUIImagePtr loadUIImage(LLViewerFetchedTexture* imagep,
  221. const std::string& name,
  222. bool use_mips = MIPMAP_NO,
  223. const LLRect& scale_rect = LLRect::null);
  224. private:
  225. struct LLUIImageLoadData
  226. {
  227. std::string mImageName;
  228. LLRect mImageScaleRegion;
  229. };
  230. typedef fast_hmap<std::string, LLUIImagePtr> uuid_ui_image_map_t;
  231. uuid_ui_image_map_t mUIImages;
  232. // Keep a copy of UI textures to prevent them to be deleted.
  233. // mImageGLp of each UI texture equals to some LLUIImage.mImage.
  234. typedef std::list<LLPointer<LLViewerFetchedTexture> > tex_list_t;
  235. tex_list_t mUITextureList;
  236. };
  237. extern LLViewerTextureList gTextureList;
  238. extern LLViewerTexture* gImgPixieSmall;
  239. #endif