PageRenderTime 32ms CodeModel.GetById 15ms app.highlight 14ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLVIEWERTEXTURELIST_H					
 28#define LL_LLVIEWERTEXTURELIST_H
 29
 30#include "lluuid.h"
 31//#include "message.h"
 32#include "llgl.h"
 33#include "llstat.h"
 34#include "llviewertexture.h"
 35#include "llui.h"
 36#include <list>
 37#include <set>
 38
 39const U32 LL_IMAGE_REZ_LOSSLESS_CUTOFF = 128;
 40
 41const BOOL MIPMAP_YES = TRUE;
 42const BOOL MIPMAP_NO = FALSE;
 43
 44const BOOL GL_TEXTURE_YES = TRUE;
 45const BOOL GL_TEXTURE_NO = FALSE;
 46
 47const BOOL IMMEDIATE_YES = TRUE;
 48const BOOL IMMEDIATE_NO = FALSE;
 49
 50class LLImageJ2C;
 51class LLMessageSystem;
 52class LLTextureView;
 53
 54typedef	void (*LLImageCallback)(BOOL success,
 55								LLViewerFetchedTexture *src_vi,
 56								LLImageRaw* src,
 57								LLImageRaw* src_aux,
 58								S32 discard_level,
 59								BOOL final,
 60								void* userdata);
 61
 62class LLViewerTextureList
 63{
 64    LOG_CLASS(LLViewerTextureList);
 65
 66	friend class LLTextureView;
 67	friend class LLViewerTextureManager;
 68	
 69public:
 70	static BOOL createUploadFile(const std::string& filename, const std::string& out_filename, const U8 codec);
 71	static LLPointer<LLImageJ2C> convertToUploadFile(LLPointer<LLImageRaw> raw_image);
 72	static void processImageNotInDatabase( LLMessageSystem *msg, void **user_data );
 73	static S32 calcMaxTextureRAM();
 74	static void receiveImageHeader(LLMessageSystem *msg, void **user_data);
 75	static void receiveImagePacket(LLMessageSystem *msg, void **user_data);
 76
 77public:
 78	LLViewerTextureList();
 79	~LLViewerTextureList();
 80
 81	void init();
 82	void shutdown();
 83	void dump();
 84	void destroyGL(BOOL save_state = TRUE);
 85	void restoreGL();
 86	BOOL isInitialized() const {return mInitialized;}
 87
 88	LLViewerFetchedTexture *findImage(const LLUUID &image_id);
 89
 90	void dirtyImage(LLViewerFetchedTexture *image);
 91	
 92	// Using image stats, determine what images are necessary, and perform image updates.
 93	void updateImages(F32 max_time);
 94	void forceImmediateUpdate(LLViewerFetchedTexture* imagep) ;
 95
 96	// Decode and create textures for all images currently in list.
 97	void decodeAllImages(F32 max_decode_time); 
 98
 99	void handleIRCallback(void **data, const S32 number);
100
101	void setUpdateStats(BOOL b)			{ mUpdateStats = b; }
102
103	S32	getMaxResidentTexMem() const	{ return mMaxResidentTexMemInMegaBytes; }
104	S32 getMaxTotalTextureMem() const   { return mMaxTotalTextureMemInMegaBytes;}
105	S32 getNumImages()					{ return mImageList.size(); }
106
107	void updateMaxResidentTexMem(S32 mem);
108	
109	void doPreloadImages();
110	void doPrefetchImages();
111
112	static S32 getMinVideoRamSetting();
113	static S32 getMaxVideoRamSetting(bool get_recommended = false);
114	
115private:
116	void updateImagesDecodePriorities();
117	F32  updateImagesCreateTextures(F32 max_time);
118	F32  updateImagesFetchTextures(F32 max_time);
119	void updateImagesUpdateStats();
120
121	void addImage(LLViewerFetchedTexture *image);
122	void deleteImage(LLViewerFetchedTexture *image);
123
124	void addImageToList(LLViewerFetchedTexture *image);
125	void removeImageFromList(LLViewerFetchedTexture *image);
126
127	LLViewerFetchedTexture * getImage(const LLUUID &image_id,									 
128									 BOOL usemipmap = TRUE,
129									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
130									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
131									 LLGLint internal_format = 0,
132									 LLGLenum primary_format = 0,
133									 LLHost request_from_host = LLHost()
134									 );
135	
136	LLViewerFetchedTexture * getImageFromFile(const std::string& filename,									 
137									 BOOL usemipmap = TRUE,
138									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
139									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
140									 LLGLint internal_format = 0,
141									 LLGLenum primary_format = 0,
142									 const LLUUID& force_id = LLUUID::null
143									 );
144	
145	LLViewerFetchedTexture* getImageFromUrl(const std::string& url,
146									 BOOL usemipmap = TRUE,
147									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
148									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
149									 LLGLint internal_format = 0,
150									 LLGLenum primary_format = 0,
151									 const LLUUID& force_id = LLUUID::null
152									 );
153
154	LLViewerFetchedTexture* createImage(const LLUUID &image_id,
155									 BOOL usemipmap = TRUE,
156									 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
157									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
158									 LLGLint internal_format = 0,
159									 LLGLenum primary_format = 0,
160									 LLHost request_from_host = LLHost()
161									 );
162	
163	// Request image from a specific host, used for baked avatar textures.
164	// Implemented in header in case someone changes default params above. JC
165	LLViewerFetchedTexture* getImageFromHost(const LLUUID& image_id, LLHost host)
166	{ return getImage(image_id, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, host); }
167
168public:
169	typedef std::set<LLPointer<LLViewerFetchedTexture> > image_list_t;	
170	image_list_t mLoadingStreamList;
171	image_list_t mCreateTextureList;
172	image_list_t mCallbackList;
173
174	// Note: just raw pointers because they are never referenced, just compared against
175	std::set<LLViewerFetchedTexture*> mDirtyTextureList;
176	
177	BOOL mForceResetTextureStats;
178    
179private:
180	typedef std::map< LLUUID, LLPointer<LLViewerFetchedTexture> > uuid_map_t;
181	uuid_map_t mUUIDMap;
182	LLUUID mLastUpdateUUID;
183	LLUUID mLastFetchUUID;
184	
185	typedef std::set<LLPointer<LLViewerFetchedTexture>, LLViewerFetchedTexture::Compare> image_priority_list_t;	
186	image_priority_list_t mImageList;
187
188	// simply holds on to LLViewerFetchedTexture references to stop them from being purged too soon
189	std::set<LLPointer<LLViewerFetchedTexture> > mImagePreloads;
190
191	BOOL mInitialized ;
192	BOOL mUpdateStats;
193	S32	mMaxResidentTexMemInMegaBytes;
194	S32 mMaxTotalTextureMemInMegaBytes;
195	LLFrameTimer mForceDecodeTimer;
196	
197public:
198	static U32 sTextureBits;
199	static U32 sTexturePackets;
200
201	static LLStat sNumImagesStat;
202	static LLStat sNumRawImagesStat;
203	static LLStat sGLTexMemStat;
204	static LLStat sGLBoundMemStat;
205	static LLStat sRawMemStat;
206	static LLStat sFormattedMemStat;
207
208private:
209	static S32 sNumImages;
210	static void (*sUUIDCallback)(void**, const LLUUID &);
211};
212
213class LLUIImageList : public LLImageProviderInterface, public LLSingleton<LLUIImageList>
214{
215public:
216	// LLImageProviderInterface
217	/*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority);
218	/*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority);
219	void cleanUp();
220
221	bool initFromFile();
222
223	LLPointer<LLUIImage> preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect, const LLRect& clip_rect);
224	
225	static void onUIImageLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
226private:
227	LLPointer<LLUIImage> loadUIImageByName(const std::string& name, const std::string& filename,
228		                           BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null, 
229								   const LLRect& clip_rect = LLRect::null,
230		                           LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
231	LLPointer<LLUIImage> loadUIImageByID(const LLUUID& id,
232								 BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null, 
233								 const LLRect& clip_rect = LLRect::null,
234								 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
235
236	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);
237
238
239	struct LLUIImageLoadData
240	{
241		std::string mImageName;
242		LLRect mImageScaleRegion;
243		LLRect mImageClipRegion;
244	};
245
246	typedef std::map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t;
247	uuid_ui_image_map_t mUIImages;
248
249	//
250	//keep a copy of UI textures to prevent them to be deleted.
251	//mGLTexturep of each UI texture equals to some LLUIImage.mImage.
252	std::list< LLPointer<LLViewerFetchedTexture> > mUITextureList ;
253};
254
255const BOOL GLTEXTURE_TRUE = TRUE;
256const BOOL GLTEXTURE_FALSE = FALSE;
257const BOOL MIPMAP_TRUE = TRUE;
258const BOOL MIPMAP_FALSE = FALSE;
259
260extern LLViewerTextureList gTextureList;
261
262#endif