PageRenderTime 52ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewertexturelist.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 262 lines | 173 code | 53 blank | 36 comment | 0 complexity | d755d56e2f3dbd0480430ddd3ad01eab MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewertexturelist.h
  3. * @brief Object for managing the list of images within a region
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVIEWERTEXTURELIST_H
  27. #define LL_LLVIEWERTEXTURELIST_H
  28. #include "lluuid.h"
  29. //#include "message.h"
  30. #include "llgl.h"
  31. #include "llstat.h"
  32. #include "llviewertexture.h"
  33. #include "llui.h"
  34. #include <list>
  35. #include <set>
  36. const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128;
  37. const BOOL MIPMAP_YES = TRUE;
  38. const BOOL MIPMAP_NO = FALSE;
  39. const BOOL GL_TEXTURE_YES = TRUE;
  40. const BOOL GL_TEXTURE_NO = FALSE;
  41. const BOOL IMMEDIATE_YES = TRUE;
  42. const BOOL IMMEDIATE_NO = FALSE;
  43. class LLImageJ2C;
  44. class LLMessageSystem;
  45. class LLTextureView;
  46. typedef void (*LLImageCallback)(BOOL success,
  47. LLViewerFetchedTexture *src_vi,
  48. LLImageRaw* src,
  49. LLImageRaw* src_aux,
  50. S32 discard_level,
  51. BOOL final,
  52. void* userdata);
  53. class LLViewerTextureList
  54. {
  55. LOG_CLASS(LLViewerTextureList);
  56. friend class LLTextureView;
  57. friend class LLViewerTextureManager;
  58. public:
  59. static BOOL createUploadFile(const std::string& filename, const std::string& out_filename, const U8 codec);
  60. static LLPointer<LLImageJ2C> convertToUploadFile(LLPointer<LLImageRaw> raw_image);
  61. static void processImageNotInDatabase( LLMessageSystem *msg, void **user_data );
  62. static S32 calcMaxTextureRAM();
  63. static void receiveImageHeader(LLMessageSystem *msg, void **user_data);
  64. static void receiveImagePacket(LLMessageSystem *msg, void **user_data);
  65. public:
  66. LLViewerTextureList();
  67. ~LLViewerTextureList();
  68. void init();
  69. void shutdown();
  70. void dump();
  71. void destroyGL(BOOL save_state = TRUE);
  72. void restoreGL();
  73. BOOL isInitialized() const {return mInitialized;}
  74. LLViewerFetchedTexture *findImage(const LLUUID &image_id);
  75. void dirtyImage(LLViewerFetchedTexture *image);
  76. // Using image stats, determine what images are necessary, and perform image updates.
  77. void updateImages(F32 max_time);
  78. void forceImmediateUpdate(LLViewerFetchedTexture* imagep) ;
  79. // Decode and create textures for all images currently in list.
  80. void decodeAllImages(F32 max_decode_time);
  81. void handleIRCallback(void **data, const S32 number);
  82. void setUpdateStats(BOOL b) { mUpdateStats = b; }
  83. S32 getMaxResidentTexMem() const { return mMaxResidentTexMemInMegaBytes; }
  84. S32 getMaxTotalTextureMem() const { return mMaxTotalTextureMemInMegaBytes;}
  85. S32 getNumImages() { return mImageList.size(); }
  86. void updateMaxResidentTexMem(S32 mem);
  87. void doPreloadImages();
  88. void doPrefetchImages();
  89. static S32 getMinVideoRamSetting();
  90. static S32 getMaxVideoRamSetting(bool get_recommended = false);
  91. private:
  92. void updateImagesDecodePriorities();
  93. F32 updateImagesCreateTextures(F32 max_time);
  94. F32 updateImagesFetchTextures(F32 max_time);
  95. void updateImagesUpdateStats();
  96. void addImage(LLViewerFetchedTexture *image);
  97. void deleteImage(LLViewerFetchedTexture *image);
  98. void addImageToList(LLViewerFetchedTexture *image);
  99. void removeImageFromList(LLViewerFetchedTexture *image);
  100. LLViewerFetchedTexture * getImage(const LLUUID &image_id,
  101. BOOL usemipmap = TRUE,
  102. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE, // Get the requested level immediately upon creation.
  103. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  104. LLGLint internal_format = 0,
  105. LLGLenum primary_format = 0,
  106. LLHost request_from_host = LLHost()
  107. );
  108. LLViewerFetchedTexture * getImageFromFile(const std::string& filename,
  109. BOOL usemipmap = TRUE,
  110. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE, // Get the requested level immediately upon creation.
  111. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  112. LLGLint internal_format = 0,
  113. LLGLenum primary_format = 0,
  114. const LLUUID& force_id = LLUUID::null
  115. );
  116. LLViewerFetchedTexture* getImageFromUrl(const std::string& url,
  117. BOOL usemipmap = TRUE,
  118. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE, // Get the requested level immediately upon creation.
  119. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  120. LLGLint internal_format = 0,
  121. LLGLenum primary_format = 0,
  122. const LLUUID& force_id = LLUUID::null
  123. );
  124. LLViewerFetchedTexture* createImage(const LLUUID &image_id,
  125. BOOL usemipmap = TRUE,
  126. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE, // Get the requested level immediately upon creation.
  127. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  128. LLGLint internal_format = 0,
  129. LLGLenum primary_format = 0,
  130. LLHost request_from_host = LLHost()
  131. );
  132. // Request image from a specific host, used for baked avatar textures.
  133. // Implemented in header in case someone changes default params above. JC
  134. LLViewerFetchedTexture* getImageFromHost(const LLUUID& image_id, LLHost host)
  135. { return getImage(image_id, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, host); }
  136. public:
  137. typedef std::set<LLPointer<LLViewerFetchedTexture> > image_list_t;
  138. image_list_t mLoadingStreamList;
  139. image_list_t mCreateTextureList;
  140. image_list_t mCallbackList;
  141. // Note: just raw pointers because they are never referenced, just compared against
  142. std::set<LLViewerFetchedTexture*> mDirtyTextureList;
  143. BOOL mForceResetTextureStats;
  144. private:
  145. typedef std::map< LLUUID, LLPointer<LLViewerFetchedTexture> > uuid_map_t;
  146. uuid_map_t mUUIDMap;
  147. LLUUID mLastUpdateUUID;
  148. LLUUID mLastFetchUUID;
  149. typedef std::set<LLPointer<LLViewerFetchedTexture>, LLViewerFetchedTexture::Compare> image_priority_list_t;
  150. image_priority_list_t mImageList;
  151. // simply holds on to LLViewerFetchedTexture references to stop them from being purged too soon
  152. std::set<LLPointer<LLViewerFetchedTexture> > mImagePreloads;
  153. BOOL mInitialized ;
  154. BOOL mUpdateStats;
  155. S32 mMaxResidentTexMemInMegaBytes;
  156. S32 mMaxTotalTextureMemInMegaBytes;
  157. LLFrameTimer mForceDecodeTimer;
  158. public:
  159. static U32 sTextureBits;
  160. static U32 sTexturePackets;
  161. static LLStat sNumImagesStat;
  162. static LLStat sNumRawImagesStat;
  163. static LLStat sGLTexMemStat;
  164. static LLStat sGLBoundMemStat;
  165. static LLStat sRawMemStat;
  166. static LLStat sFormattedMemStat;
  167. private:
  168. static S32 sNumImages;
  169. static void (*sUUIDCallback)(void**, const LLUUID &);
  170. };
  171. class LLUIImageList : public LLImageProviderInterface, public LLSingleton<LLUIImageList>
  172. {
  173. public:
  174. // LLImageProviderInterface
  175. /*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority);
  176. /*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority);
  177. void cleanUp();
  178. bool initFromFile();
  179. LLPointer<LLUIImage> preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect);
  180. static void onUIImageLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
  181. private:
  182. LLPointer<LLUIImage> loadUIImageByName(const std::string& name, const std::string& filename,
  183. BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null,
  184. const LLRect& clip_rect = LLRect::null,
  185. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
  186. LLPointer<LLUIImage> loadUIImageByID(const LLUUID& id,
  187. BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null,
  188. const LLRect& clip_rect = LLRect::null,
  189. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
  190. LLPointer<LLUIImage> loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null, const LLRect& clip_rect = LLRect::null);
  191. struct LLUIImageLoadData
  192. {
  193. std::string mImageName;
  194. LLRect mImageScaleRegion;
  195. LLRect mImageClipRegion;
  196. };
  197. typedef std::map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t;
  198. uuid_ui_image_map_t mUIImages;
  199. //
  200. //keep a copy of UI textures to prevent them to be deleted.
  201. //mGLTexturep of each UI texture equals to some LLUIImage.mImage.
  202. std::list< LLPointer<LLViewerFetchedTexture> > mUITextureList ;
  203. };
  204. const BOOL GLTEXTURE_TRUE = TRUE;
  205. const BOOL GLTEXTURE_FALSE = FALSE;
  206. const BOOL MIPMAP_TRUE = TRUE;
  207. const BOOL MIPMAP_FALSE = FALSE;
  208. extern LLViewerTextureList gTextureList;
  209. #endif