Annotation of /trunk/linden/indra/newview/lltexturecache.h
Parent Directory
|
Revision Log
Revision 103 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file lltexturecache.h | ||
| 3 : | * @brief Object for managing texture cachees. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 103 | * Copyright (c) 2000-2009, Linden Research, Inc. |
| 8 : | mjm | 57 | * |
| 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #ifndef LL_LLTEXTURECACHE_ | ||
| 33 : | #define LL_LLTEXTURECACHE_H | ||
| 34 : | |||
| 35 : | #include "lldir.h" | ||
| 36 : | #include "llstl.h" | ||
| 37 : | #include "llstring.h" | ||
| 38 : | #include "lluuid.h" | ||
| 39 : | |||
| 40 : | #include "llworkerthread.h" | ||
| 41 : | |||
| 42 : | class LLTextureCacheWorker; | ||
| 43 : | |||
| 44 : | class LLTextureCache : public LLWorkerThread | ||
| 45 : | { | ||
| 46 : | friend class LLTextureCacheWorker; | ||
| 47 : | friend class LLTextureCacheRemoteWorker; | ||
| 48 : | friend class LLTextureCacheLocalFileWorker; | ||
| 49 : | |||
| 50 : | public: | ||
| 51 : | |||
| 52 : | class Responder : public LLResponder | ||
| 53 : | { | ||
| 54 : | public: | ||
| 55 : | virtual void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal) = 0; | ||
| 56 : | }; | ||
| 57 : | |||
| 58 : | class ReadResponder : public Responder | ||
| 59 : | { | ||
| 60 : | public: | ||
| 61 : | ReadResponder(); | ||
| 62 : | void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal); | ||
| 63 : | void setImage(LLImageFormatted* image) { mFormattedImage = image; } | ||
| 64 : | protected: | ||
| 65 : | LLPointer<LLImageFormatted> mFormattedImage; | ||
| 66 : | S32 mImageSize; | ||
| 67 : | BOOL mImageLocal; | ||
| 68 : | }; | ||
| 69 : | |||
| 70 : | class WriteResponder : public Responder | ||
| 71 : | { | ||
| 72 : | void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal) | ||
| 73 : | { | ||
| 74 : | // not used | ||
| 75 : | } | ||
| 76 : | }; | ||
| 77 : | |||
| 78 : | LLTextureCache(bool threaded); | ||
| 79 : | ~LLTextureCache(); | ||
| 80 : | |||
| 81 : | /*virtual*/ S32 update(U32 max_time_ms); | ||
| 82 : | |||
| 83 : | void purgeCache(ELLPath location); | ||
| 84 : | S64 initCache(ELLPath location, S64 maxsize, BOOL read_only); | ||
| 85 : | |||
| 86 : | handle_t readFromCache(const std::string& local_filename, const LLUUID& id, U32 priority, S32 offset, S32 size, | ||
| 87 : | ReadResponder* responder); | ||
| 88 : | |||
| 89 : | handle_t readFromCache(const LLUUID& id, U32 priority, S32 offset, S32 size, | ||
| 90 : | ReadResponder* responder); | ||
| 91 : | bool readComplete(handle_t handle, bool abort); | ||
| 92 : | handle_t writeToCache(const LLUUID& id, U32 priority, U8* data, S32 datasize, S32 imagesize, | ||
| 93 : | WriteResponder* responder); | ||
| 94 : | bool writeComplete(handle_t handle, bool abort = false); | ||
| 95 : | void prioritizeWrite(handle_t handle); | ||
| 96 : | |||
| 97 : | void removeFromCache(const LLUUID& id); | ||
| 98 : | |||
| 99 : | // For LLTextureCacheWorker::Responder | ||
| 100 : | LLTextureCacheWorker* getReader(handle_t handle); | ||
| 101 : | LLTextureCacheWorker* getWriter(handle_t handle); | ||
| 102 : | void lockWorkers() { mWorkersMutex.lock(); } | ||
| 103 : | void unlockWorkers() { mWorkersMutex.unlock(); } | ||
| 104 : | |||
| 105 : | // debug | ||
| 106 : | S32 getNumReads() { return mReaders.size(); } | ||
| 107 : | S32 getNumWrites() { return mWriters.size(); } | ||
| 108 : | |||
| 109 : | protected: | ||
| 110 : | // Accessed by LLTextureCacheWorker | ||
| 111 : | apr_pool_t* getFileAPRPool() { return mFileAPRPool; } | ||
| 112 : | bool appendToTextureEntryList(const LLUUID& id, S32 size); | ||
| 113 : | std::string getLocalFileName(const LLUUID& id); | ||
| 114 : | std::string getTextureFileName(const LLUUID& id); | ||
| 115 : | void addCompleted(Responder* responder, bool success); | ||
| 116 : | |||
| 117 : | protected: | ||
| 118 : | void setFileAPRPool(apr_pool_t* pool) { mFileAPRPool = pool ; } | ||
| 119 : | |||
| 120 : | private: | ||
| 121 : | void setDirNames(ELLPath location); | ||
| 122 : | void readHeaderCache(apr_pool_t* poolp = NULL); | ||
| 123 : | void purgeAllTextures(bool purge_directories); | ||
| 124 : | void purgeTextures(bool validate); | ||
| 125 : | S32 getHeaderCacheEntry(const LLUUID& id, bool touch, S32* imagesize = NULL); | ||
| 126 : | bool removeHeaderCacheEntry(const LLUUID& id); | ||
| 127 : | void lockHeaders() { mHeaderMutex.lock(); } | ||
| 128 : | void unlockHeaders() { mHeaderMutex.unlock(); } | ||
| 129 : | |||
| 130 : | private: | ||
| 131 : | // Internal | ||
| 132 : | LLMutex mWorkersMutex; | ||
| 133 : | LLMutex mHeaderMutex; | ||
| 134 : | LLMutex mListMutex; | ||
| 135 : | apr_pool_t* mFileAPRPool; | ||
| 136 : | |||
| 137 : | typedef std::map<handle_t, LLTextureCacheWorker*> handle_map_t; | ||
| 138 : | handle_map_t mReaders; | ||
| 139 : | handle_map_t mWriters; | ||
| 140 : | |||
| 141 : | typedef std::vector<handle_t> handle_list_t; | ||
| 142 : | handle_list_t mPrioritizeWriteList; | ||
| 143 : | |||
| 144 : | typedef std::vector<std::pair<LLPointer<Responder>, bool> > responder_list_t; | ||
| 145 : | responder_list_t mCompletedList; | ||
| 146 : | |||
| 147 : | BOOL mReadOnly; | ||
| 148 : | |||
| 149 : | // Entries | ||
| 150 : | struct EntriesInfo | ||
| 151 : | { | ||
| 152 : | F32 mVersion; | ||
| 153 : | U32 mEntries; | ||
| 154 : | }; | ||
| 155 : | struct Entry | ||
| 156 : | { | ||
| 157 : | Entry() {} | ||
| 158 : | Entry(const LLUUID& id, S32 size, U32 time) : mID(id), mSize(size), mTime(time) {} | ||
| 159 : | LLUUID mID; // 128 bits | ||
| 160 : | S32 mSize; // total size of image if known (NOT size cached) | ||
| 161 : | U32 mTime; // seconds since 1/1/1970 | ||
| 162 : | }; | ||
| 163 : | |||
| 164 : | // HEADERS (Include first mip) | ||
| 165 : | std::string mHeaderEntriesFileName; | ||
| 166 : | std::string mHeaderDataFileName; | ||
| 167 : | EntriesInfo mHeaderEntriesInfo; | ||
| 168 : | typedef std::map<S32,LLUUID> index_map_t; | ||
| 169 : | index_map_t mLRU; // index, id; stored as a map for fast removal | ||
| 170 : | typedef std::map<LLUUID,S32> id_map_t; | ||
| 171 : | id_map_t mHeaderIDMap; | ||
| 172 : | |||
| 173 : | // BODIES (TEXTURES minus headers) | ||
| 174 : | std::string mTexturesDirName; | ||
| 175 : | std::string mTexturesDirEntriesFileName; | ||
| 176 : | typedef std::map<LLUUID,S32> size_map_t; | ||
| 177 : | size_map_t mTexturesSizeMap; | ||
| 178 : | S64 mTexturesSizeTotal; | ||
| 179 : | LLAtomic32<BOOL> mDoPurge; | ||
| 180 : | |||
| 181 : | // Statics | ||
| 182 : | static F32 sHeaderCacheVersion; | ||
| 183 : | static U32 sCacheMaxEntries; | ||
| 184 : | static S64 sCacheMaxTexturesSize; | ||
| 185 : | }; | ||
| 186 : | |||
| 187 : | #endif // LL_LLTEXTURECACHE_H |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

