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