lltexturefetch.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * @file lltexturefetch.h
  3. * @brief Object for managing texture fetches.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2013, 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_LLTEXTUREFETCH_H
  33. #define LL_LLTEXTUREFETCH_H
  34. #include "llatomic.h"
  35. #include "llcorehttprequest.h"
  36. #include "lldir.h"
  37. #include "hbfastmap.h"
  38. #include "llimage.h"
  39. #include "llworkerthread.h"
  40. #include "llviewertexture.h"
  41. class LLHost;
  42. class LLTextureFetchWorker;
  43. // Interface class
  44. class LLTextureFetch final : public LLWorkerThread
  45. {
  46. protected:
  47. LOG_CLASS(LLTextureFetch);
  48. friend class LLTextureFetchWorker;
  49. public:
  50. LLTextureFetch();
  51. ~LLTextureFetch() override;
  52. size_t update() override;
  53. bool createRequest(FTType f_type, const std::string& url, const LLUUID& id,
  54. const LLHost& host, F32 priority, S32 w, S32 h, S32 c,
  55. S32 discard, bool needs_aux, bool can_use_http);
  56. bool deleteRequest(const LLUUID& id, bool force = true);
  57. uuid_list_t deleteAllRequests();
  58. bool getRequestFinished(const LLUUID& id, S32& discard_level,
  59. LLPointer<LLImageRaw>& raw,
  60. LLPointer<LLImageRaw>& aux,
  61. LLCore::HttpStatus& last_http_get_status);
  62. bool updateRequestPriority(const LLUUID& id, F32 priority);
  63. bool receiveImageHeader(const LLHost& host, const LLUUID& id, U8 codec,
  64. U16 packets, U32 totalbytes, U16 data_size,
  65. U8* data);
  66. bool receiveImagePacket(const LLHost& host, const LLUUID& id,
  67. U16 packet_num, U16 data_size, U8* data);
  68. LL_INLINE void setTextureBandwidth(F32 bandwidth) { mTextureBandwidth = bandwidth; }
  69. LL_INLINE F32 getTextureBandwidth() { return mTextureBandwidth; }
  70. // Debug
  71. bool isFromLocalCache(const LLUUID& id);
  72. S32 getFetchState(const LLUUID& id, F32& decode_progress_p,
  73. F32& requested_priority_p, U32& fetch_priority_p,
  74. F32& fetch_dtime_p, F32& request_dtime_p,
  75. bool& can_use_http);
  76. U32 getNumRequests();
  77. // Like getNumRequests() but without locking the queue and thus only an
  78. // approximative number (used for stats and soft limits). HB
  79. LL_INLINE U32 getApproxNumRequests() { return mApproxNumRequests; }
  80. // NOTE: mHTTPTextureQueue is only accessed by addToHTTPQueue() and
  81. // removeFromHTTPQueue() and not used beyond the simple counting of HTTP
  82. // requests among the total requests. mNumHTTPRequests is updated each time
  83. // (in both addToHTTPQueue() and removeFromHTTPQueue()) to reflect the
  84. // number of active requests, so that we can get that number without the
  85. // need to lock mNetworkQueueMutex... HB
  86. LL_INLINE U32 getNumHTTPRequests() { return mNumHTTPRequests; }
  87. // LLQueuedThread override
  88. size_t getPending() override;
  89. LLTextureFetchWorker* getWorker(const LLUUID& id);
  90. LLTextureFetchWorker* getWorkerAfterLock(const LLUUID& id);
  91. LL_INLINE LLCore::HttpRequest& getHttpRequest() { return *mHttpRequest; }
  92. LL_INLINE LLCore::HttpRequest::policy_t getPolicyClass() const
  93. {
  94. return mHttpPolicyClass;
  95. }
  96. // HTTP resource waiting methods
  97. void addHttpWaiter(const LLUUID& tid);
  98. void removeHttpWaiter(const LLUUID& tid);
  99. bool isHttpWaiter(const LLUUID& tid);
  100. // Requests from resource wait state (WAIT_HTTP_RESOURCE) to active
  101. // (SEND_HTTP_REQ).
  102. //
  103. // Because this will modify state of many workers, you may not hold any Mw
  104. // lock while calling. This makes it a little inconvenient to use but that
  105. // is the rule.
  106. void releaseHttpWaiters();
  107. LL_INLINE static S32 getMaxRequestsInQueue() { return sMaxRequestsInQueue; }
  108. protected:
  109. void addToNetworkQueue(LLTextureFetchWorker* worker);
  110. void removeFromNetworkQueue(LLTextureFetchWorker* worker, bool cancel);
  111. void addToHTTPQueue(const LLUUID& id);
  112. void removeFromHTTPQueue(const LLUUID& id, S32 received_size = 0);
  113. private:
  114. void sendRequestListToSimulators();
  115. // LLQueuedThread override
  116. void threadedUpdate() override;
  117. public:
  118. LLAtomicBool mDebugPause;
  119. private:
  120. // To protect mRequestMap only:
  121. LLMutex mQueueMutex;
  122. // To protect mNetworkQueue, mHTTPTextureQueue, mHTTPTextureQueue and
  123. // mCancelQueue:
  124. LLMutex mNetworkQueueMutex;
  125. // Map of all requests by UUID
  126. typedef fast_hmap<LLUUID, LLTextureFetchWorker*> map_t;
  127. map_t mRequestMap;
  128. // Set of requests that require network data
  129. uuid_list_t mNetworkQueue;
  130. uuid_list_t mHTTPTextureQueue;
  131. typedef std::map<LLHost, uuid_list_t> cancel_queue_t;
  132. cancel_queue_t mCancelQueue;
  133. LLAtomicU32 mApproxNumRequests;
  134. LLAtomicU32 mNumHTTPRequests;
  135. F32 mTextureBandwidth;
  136. U32 mHTTPTextureBits;
  137. // Interfaces and objects into the core http library used to make our HTTP
  138. // requests.
  139. LLCore::HttpRequest* mHttpRequest;
  140. LLCore::HttpOptions::ptr_t mHttpOptions;
  141. LLCore::HttpOptions::ptr_t mHttpOptionsWithHeaders;
  142. LLCore::HttpHeaders::ptr_t mHttpHeaders;
  143. LLCore::HttpRequest::policy_t mHttpPolicyClass;
  144. uuid_list_t mHttpWaitResource;
  145. // We use a resource semaphore to keep HTTP requests in WAIT_HTTP_RESOURCE2
  146. // if there are not sufficient slots in the transport. This keeps them near
  147. // where they can be cheaply reprioritized rather than dumping them all
  148. // across a thread where it's more expensive to get at them. Requests in
  149. // either SEND_HTTP_REQ or WAIT_HTTP_REQ charge against the semaphore and
  150. // tracking state transitions is critical to liveness.
  151. S32 mHttpLowWater;
  152. S32 mHttpHighWater;
  153. S32 mHttpSemaphore;
  154. static S32 sMinRequestsInQueue;
  155. static S32 sMaxRequestsInQueue;
  156. };
  157. // Global, initialized in llappviewer.cpp and used in newview/. Moved here so
  158. // that LLTextureFetch consumers do not need to include llappviewer.h to use
  159. // it. HB
  160. extern LLTextureFetch* gTextureFetchp;
  161. #endif // LL_LLTEXTUREFETCH_H