diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/lltexturecache.h | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/newview/lltexturecache.h')
-rw-r--r-- | linden/indra/newview/lltexturecache.h | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/linden/indra/newview/lltexturecache.h b/linden/indra/newview/lltexturecache.h new file mode 100644 index 0000000..ec20066 --- /dev/null +++ b/linden/indra/newview/lltexturecache.h | |||
@@ -0,0 +1,175 @@ | |||
1 | /** | ||
2 | * @file lltexturecache.h | ||
3 | * @brief Object for managing texture cachees. | ||
4 | * | ||
5 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLTEXTURECACHE_ | ||
29 | #define LL_LLTEXTURECACHE_H | ||
30 | |||
31 | #include "lldir.h" | ||
32 | #include "llstl.h" | ||
33 | #include "llstring.h" | ||
34 | #include "lluuid.h" | ||
35 | |||
36 | #include "llworkerthread.h" | ||
37 | |||
38 | class LLTextureCacheWorker; | ||
39 | |||
40 | class LLTextureCache : public LLWorkerThread | ||
41 | { | ||
42 | friend class LLTextureCacheWorker; | ||
43 | |||
44 | public: | ||
45 | |||
46 | class Responder : public LLResponder | ||
47 | { | ||
48 | public: | ||
49 | virtual void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal) = 0; | ||
50 | }; | ||
51 | |||
52 | class ReadResponder : public Responder | ||
53 | { | ||
54 | public: | ||
55 | ReadResponder(); | ||
56 | void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal); | ||
57 | void setImage(LLImageFormatted* image) { mFormattedImage = image; } | ||
58 | protected: | ||
59 | LLPointer<LLImageFormatted> mFormattedImage; | ||
60 | S32 mImageSize; | ||
61 | BOOL mImageLocal; | ||
62 | }; | ||
63 | |||
64 | class WriteResponder : public Responder | ||
65 | { | ||
66 | void setData(U8* data, S32 datasize, S32 imagesize, S32 imageformat, BOOL imagelocal) | ||
67 | { | ||
68 | // not used | ||
69 | } | ||
70 | }; | ||
71 | |||
72 | LLTextureCache(bool threaded); | ||
73 | ~LLTextureCache(); | ||
74 | |||
75 | /*virtual*/ S32 update(U32 max_time_ms); | ||
76 | |||
77 | void purgeCache(ELLPath location); | ||
78 | S64 initCache(ELLPath location, S64 maxsize, BOOL read_only); | ||
79 | |||
80 | handle_t readFromCache(const LLUUID& id, U32 priority, S32 offset, S32 size, | ||
81 | ReadResponder* responder); | ||
82 | bool readComplete(handle_t handle, bool abort); | ||
83 | handle_t writeToCache(const LLUUID& id, U32 priority, U8* data, S32 datasize, S32 imagesize, | ||
84 | WriteResponder* responder); | ||
85 | bool writeComplete(handle_t handle, bool abort = false); | ||
86 | void prioritizeWrite(handle_t handle); | ||
87 | |||
88 | void removeFromCache(const LLUUID& id); | ||
89 | |||
90 | // For LLTextureCacheWorker::Responder | ||
91 | LLTextureCacheWorker* getReader(handle_t handle); | ||
92 | LLTextureCacheWorker* getWriter(handle_t handle); | ||
93 | void lockWorkers() { mWorkersMutex.lock(); } | ||
94 | void unlockWorkers() { mWorkersMutex.unlock(); } | ||
95 | |||
96 | // debug | ||
97 | S32 getNumReads() { return mReaders.size(); } | ||
98 | S32 getNumWrites() { return mWriters.size(); } | ||
99 | |||
100 | protected: | ||
101 | // Accessed by LLTextureCacheWorker | ||
102 | apr_pool_t* getFileAPRPool() { return mFileAPRPool; } | ||
103 | bool appendToTextureEntryList(const LLUUID& id, S32 size); | ||
104 | std::string getLocalFileName(const LLUUID& id); | ||
105 | std::string getTextureFileName(const LLUUID& id); | ||
106 | void addCompleted(Responder* responder, bool success); | ||
107 | |||
108 | private: | ||
109 | void setDirNames(ELLPath location); | ||
110 | void readHeaderCache(apr_pool_t* poolp = NULL); | ||
111 | void purgeAllTextures(bool purge_directories); | ||
112 | void purgeTextures(bool validate); | ||
113 | S32 getHeaderCacheEntry(const LLUUID& id, bool touch, S32* imagesize = NULL); | ||
114 | bool removeHeaderCacheEntry(const LLUUID& id); | ||
115 | void lockHeaders() { mHeaderMutex.lock(); } | ||
116 | void unlockHeaders() { mHeaderMutex.unlock(); } | ||
117 | |||
118 | private: | ||
119 | // Internal | ||
120 | LLMutex mWorkersMutex; | ||
121 | LLMutex mHeaderMutex; | ||
122 | LLMutex mListMutex; | ||
123 | apr_pool_t* mFileAPRPool; | ||
124 | |||
125 | typedef std::map<handle_t, LLTextureCacheWorker*> handle_map_t; | ||
126 | handle_map_t mReaders; | ||
127 | handle_map_t mWriters; | ||
128 | |||
129 | typedef std::vector<handle_t> handle_list_t; | ||
130 | handle_list_t mPrioritizeWriteList; | ||
131 | |||
132 | typedef std::vector<std::pair<LLPointer<Responder>, bool> > responder_list_t; | ||
133 | responder_list_t mCompletedList; | ||
134 | |||
135 | BOOL mReadOnly; | ||
136 | |||
137 | // Entries | ||
138 | struct EntriesInfo | ||
139 | { | ||
140 | F32 mVersion; | ||
141 | U32 mEntries; | ||
142 | }; | ||
143 | struct Entry | ||
144 | { | ||
145 | Entry() {} | ||
146 | Entry(const LLUUID& id, S32 size, U32 time) : mID(id), mSize(size), mTime(time) {} | ||
147 | LLUUID mID; // 128 bits | ||
148 | S32 mSize; // total size of image if known (NOT size cached) | ||
149 | U32 mTime; // seconds since 1/1/1970 | ||
150 | }; | ||
151 | |||
152 | // HEADERS (Include first mip) | ||
153 | std::string mHeaderEntriesFileName; | ||
154 | std::string mHeaderDataFileName; | ||
155 | EntriesInfo mHeaderEntriesInfo; | ||
156 | typedef std::map<S32,LLUUID> index_map_t; | ||
157 | index_map_t mLRU; // index, id; stored as a map for fast removal | ||
158 | typedef std::map<LLUUID,S32> id_map_t; | ||
159 | id_map_t mHeaderIDMap; | ||
160 | |||
161 | // BODIES (TEXTURES minus headers) | ||
162 | std::string mTexturesDirName; | ||
163 | std::string mTexturesDirEntriesFileName; | ||
164 | typedef std::map<LLUUID,S32> size_map_t; | ||
165 | size_map_t mTexturesSizeMap; | ||
166 | S64 mTexturesSizeTotal; | ||
167 | LLAtomic32<BOOL> mDoPurge; | ||
168 | |||
169 | // Statics | ||
170 | static F32 sHeaderCacheVersion; | ||
171 | static U32 sCacheMaxEntries; | ||
172 | static S64 sCacheMaxTexturesSize; | ||
173 | }; | ||
174 | |||
175 | #endif // LL_LLTEXTURECACHE_H | ||