PageRenderTime 29ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/lltexturefetch.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 215 lines | 108 code | 36 blank | 71 comment | 0 complexity | 25682a1c322a87702a8bc5ca2a1ff317 MD5 | raw file
  1/** 
  2 * @file lltexturefetch.h
  3 * @brief Object for managing texture fetches.
  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_LLTEXTUREFETCH_H
 28#define LL_LLTEXTUREFETCH_H
 29
 30#include "lldir.h"
 31#include "llimage.h"
 32#include "lluuid.h"
 33#include "llworkerthread.h"
 34#include "llcurl.h"
 35#include "lltextureinfo.h"
 36#include "llapr.h"
 37
 38class LLViewerTexture;
 39class LLTextureFetchWorker;
 40class HTTPGetResponder;
 41class LLTextureCache;
 42class LLImageDecodeThread;
 43class LLHost;
 44class LLViewerAssetStats;
 45
 46// Interface class
 47class LLTextureFetch : public LLWorkerThread
 48{
 49	friend class LLTextureFetchWorker;
 50	friend class HTTPGetResponder;
 51	
 52public:
 53	LLTextureFetch(LLTextureCache* cache, LLImageDecodeThread* imagedecodethread, bool threaded, bool qa_mode);
 54	~LLTextureFetch();
 55
 56	class TFRequest;
 57	
 58	/*virtual*/ S32 update(F32 max_time_ms);	
 59	void shutDownTextureCacheThread() ; //called in the main thread after the TextureCacheThread shuts down.
 60	void shutDownImageDecodeThread() ;  //called in the main thread after the ImageDecodeThread shuts down.
 61
 62	bool createRequest(const std::string& url, const LLUUID& id, const LLHost& host, F32 priority,
 63					   S32 w, S32 h, S32 c, S32 discard, bool needs_aux, bool can_use_http);
 64	void deleteRequest(const LLUUID& id, bool cancel);
 65	bool getRequestFinished(const LLUUID& id, S32& discard_level,
 66							LLPointer<LLImageRaw>& raw, LLPointer<LLImageRaw>& aux);
 67	bool updateRequestPriority(const LLUUID& id, F32 priority);
 68
 69	bool receiveImageHeader(const LLHost& host, const LLUUID& id, U8 codec, U16 packets, U32 totalbytes, U16 data_size, U8* data);
 70	bool receiveImagePacket(const LLHost& host, const LLUUID& id, U16 packet_num, U16 data_size, U8* data);
 71
 72	void setTextureBandwidth(F32 bandwidth) { mTextureBandwidth = bandwidth; }
 73	F32 getTextureBandwidth() { return mTextureBandwidth; }
 74	
 75	// Debug
 76	BOOL isFromLocalCache(const LLUUID& id);
 77	S32 getFetchState(const LLUUID& id, F32& decode_progress_p, F32& requested_priority_p,
 78					  U32& fetch_priority_p, F32& fetch_dtime_p, F32& request_dtime_p, bool& can_use_http);
 79	void dump();
 80	S32 getNumRequests() ;
 81	S32 getNumHTTPRequests() ;
 82	U32 getTotalNumHTTPRequests() ;
 83	
 84	// Public for access by callbacks
 85    S32 getPending();
 86	void lockQueue() { mQueueMutex.lock(); }
 87	void unlockQueue() { mQueueMutex.unlock(); }
 88	LLTextureFetchWorker* getWorker(const LLUUID& id);
 89	LLTextureFetchWorker* getWorkerAfterLock(const LLUUID& id);
 90
 91	LLTextureInfo* getTextureInfo() { return &mTextureInfo; }
 92
 93	// Commands available to other threads to control metrics gathering operations.
 94	void commandSetRegion(U64 region_handle);
 95	void commandSendMetrics(const std::string & caps_url,
 96							const LLUUID & session_id,
 97							const LLUUID & agent_id,
 98							LLViewerAssetStats * main_stats);
 99	void commandDataBreak();
100
101	LLCurlRequest & getCurlRequest()	{ return *mCurlGetRequest; }
102
103	bool isQAMode() const				{ return mQAMode; }
104
105	// Curl POST counter maintenance
106	inline void incrCurlPOSTCount()		{ mCurlPOSTRequestCount++; }
107	inline void decrCurlPOSTCount()		{ mCurlPOSTRequestCount--; }
108
109protected:
110	void addToNetworkQueue(LLTextureFetchWorker* worker);
111	void removeFromNetworkQueue(LLTextureFetchWorker* worker, bool cancel);
112	void addToHTTPQueue(const LLUUID& id);
113	void removeFromHTTPQueue(const LLUUID& id, S32 received_size = 0);
114	void removeRequest(LLTextureFetchWorker* worker, bool cancel);
115
116	// Overrides from the LLThread tree
117	bool runCondition();
118
119private:
120	void sendRequestListToSimulators();
121	/*virtual*/ void startThread(void);
122	/*virtual*/ void endThread(void);
123	/*virtual*/ void threadedUpdate(void);
124	void commonUpdate();
125
126	// Metrics command helpers
127	/**
128	 * Enqueues a command request at the end of the command queue
129	 * and wakes up the thread as needed.
130	 *
131	 * Takes ownership of the TFRequest object.
132	 *
133	 * Method locks the command queue.
134	 */
135	void cmdEnqueue(TFRequest *);
136
137	/**
138	 * Returns the first TFRequest object in the command queue or
139	 * NULL if none is present.
140	 *
141	 * Caller acquires ownership of the object and must dispose of it.
142	 *
143	 * Method locks the command queue.
144	 */
145	TFRequest * cmdDequeue();
146
147	/**
148	 * Processes the first command in the queue disposing of the
149	 * request on completion.  Successive calls are needed to perform
150	 * additional commands.
151	 *
152	 * Method locks the command queue.
153	 */
154	void cmdDoWork();
155	
156public:
157	LLUUID mDebugID;
158	S32 mDebugCount;
159	BOOL mDebugPause;
160	S32 mPacketCount;
161	S32 mBadPacketCount;
162	
163private:
164	LLMutex mQueueMutex;        //to protect mRequestMap and mCommands only
165	LLMutex mNetworkQueueMutex; //to protect mNetworkQueue, mHTTPTextureQueue and mCancelQueue.
166
167	LLTextureCache* mTextureCache;
168	LLImageDecodeThread* mImageDecodeThread;
169	LLCurlRequest* mCurlGetRequest;
170	
171	// Map of all requests by UUID
172	typedef std::map<LLUUID,LLTextureFetchWorker*> map_t;
173	map_t mRequestMap;
174
175	// Set of requests that require network data
176	typedef std::set<LLUUID> queue_t;
177	queue_t mNetworkQueue;
178	queue_t mHTTPTextureQueue;
179	typedef std::map<LLHost,std::set<LLUUID> > cancel_queue_t;
180	cancel_queue_t mCancelQueue;
181	F32 mTextureBandwidth;
182	F32 mMaxBandwidth;
183	LLTextureInfo mTextureInfo;
184
185	U32 mHTTPTextureBits;
186
187	//debug use
188	U32 mTotalHTTPRequests ;
189
190	// Out-of-band cross-thread command queue.  This command queue
191	// is logically tied to LLQueuedThread's list of
192	// QueuedRequest instances and so must be covered by the
193	// same locks.
194	typedef std::vector<TFRequest *> command_queue_t;
195	command_queue_t mCommands;
196
197	// If true, modifies some behaviors that help with QA tasks.
198	const bool mQAMode;
199
200	// Count of POST requests outstanding.  We maintain the count
201	// indirectly in the CURL request responder's ctor and dtor and
202	// use it when determining whether or not to sleep the thread.  Can't
203	// use the LLCurl module's request counter as it isn't thread compatible.
204	// *NOTE:  Don't mix Atomic and static, apr_initialize must be called first.
205	LLAtomic32<S32> mCurlPOSTRequestCount;
206	
207public:
208	// A probabilistically-correct indicator that the current
209	// attempt to log metrics follows a break in the metrics stream
210	// reporting due to either startup or a problem POSTing data.
211	static volatile bool svMetricsDataBreak;
212};
213
214#endif // LL_LLTEXTUREFETCH_H
215