OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 | 9 |
10 #ifndef GrGpuGL_DEFINED | 10 #ifndef GrGpuGL_DEFINED |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 | 170 |
171 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); | 171 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
172 | 172 |
173 class ProgramCache : public ::GrNoncopyable { | 173 class ProgramCache : public ::GrNoncopyable { |
174 public: | 174 public: |
175 ProgramCache(const GrGLContext& gl); | 175 ProgramCache(const GrGLContext& gl); |
176 ~ProgramCache(); | 176 ~ProgramCache(); |
177 | 177 |
178 void abandon(); | 178 void abandon(); |
179 GrGLProgram* getProgram(const GrGLProgramDesc& desc, const GrEffectStage * stages[]); | 179 GrGLProgram* getProgram(const GrGLProgramDesc& desc, const GrEffectStage * stages[]); |
180 | |
180 private: | 181 private: |
181 enum { | 182 enum { |
182 kKeySize = sizeof(GrGLProgramDesc), | |
183 // We may actually have kMaxEntries+1 shaders in the GL context beca use we create a new | 183 // We may actually have kMaxEntries+1 shaders in the GL context beca use we create a new |
184 // shader before evicting from the cache. | 184 // shader before evicting from the cache. |
185 kMaxEntries = 32 | 185 kMaxEntries = 32, |
186 kHashBits = 6, | |
186 }; | 187 }; |
187 | 188 |
188 class Entry; | 189 struct Entry; |
189 // The value of the hash key is based on the ProgramDesc. | |
190 typedef GrTBinHashKey<Entry, kKeySize> ProgramHashKey; | |
191 | 190 |
robertphillips
2013/05/21 19:22:37
Do we need this pre-declare?
bsalomon
2013/05/22 14:11:25
It has to have access to GrGpuGL::ProgramCache::En
| |
192 class Entry : public ::GrNoncopyable { | 191 struct ProgDescLess; |
193 public: | |
194 Entry() : fProgram(NULL), fLRUStamp(0) {} | |
195 Entry& operator = (const Entry& entry) { | |
196 GrSafeRef(entry.fProgram.get()); | |
197 fProgram.reset(entry.fProgram.get()); | |
198 fKey = entry.fKey; | |
199 fLRUStamp = entry.fLRUStamp; | |
200 return *this; | |
201 } | |
202 int compare(const ProgramHashKey& key) const { | |
203 return fKey.compare(key); | |
204 } | |
205 | 192 |
robertphillips
2013/05/21 19:22:37
of -> for?
bsalomon
2013/05/22 14:11:25
Done.
| |
206 public: | 193 // binary search of entry matching desc. returns index into fEntries tha t matches desc or ~ |
207 SkAutoTUnref<GrGLProgram> fProgram; | 194 // of the index of where it should be inserted. |
208 ProgramHashKey fKey; | 195 int search(const GrGLProgramDesc& desc) const; |
209 unsigned int fLRUStamp; // Move outside entry? | |
210 }; | |
211 | 196 |
212 GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; | 197 // sorted array of all the entries |
198 Entry* fEntries[kMaxEntries]; | |
199 // hash table based on lowest kHashBits bits of the program key. Used to avoid binary | |
200 // searching fEntries. | |
201 Entry* fHashTable[1 << kHashBits]; | |
213 | 202 |
214 Entry fEntries[kMaxEntries]; | |
215 int fCount; | 203 int fCount; |
216 unsigned int fCurrLRUStamp; | 204 unsigned int fCurrLRUStamp; |
217 const GrGLContext& fGL; | 205 const GrGLContext& fGL; |
218 #ifdef PROGRAM_CACHE_STATS | 206 #ifdef PROGRAM_CACHE_STATS |
219 int fTotalRequests; | 207 int fTotalRequests; |
220 int fCacheMisses; | 208 int fCacheMisses; |
209 int fHashMisses; // cache hit but hash table mis sed | |
221 #endif | 210 #endif |
222 }; | 211 }; |
223 | 212 |
224 // sets the matrix for path stenciling (uses the GL fixed pipe matrices) | 213 // sets the matrix for path stenciling (uses the GL fixed pipe matrices) |
225 void flushPathStencilMatrix(); | 214 void flushPathStencilMatrix(); |
226 | 215 |
227 // flushes dithering, color-mask, and face culling stat | 216 // flushes dithering, color-mask, and face culling stat |
228 void flushMiscFixedFunctionState(); | 217 void flushMiscFixedFunctionState(); |
229 | 218 |
230 // flushes the scissor. see the note on flushBoundTextureAndParams about | 219 // flushes the scissor. see the note on flushBoundTextureAndParams about |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 ///@} | 427 ///@} |
439 | 428 |
440 // we record what stencil format worked last time to hopefully exit early | 429 // we record what stencil format worked last time to hopefully exit early |
441 // from our loop that tries stencil formats and calls check fb status. | 430 // from our loop that tries stencil formats and calls check fb status. |
442 int fLastSuccessfulStencilFmtIdx; | 431 int fLastSuccessfulStencilFmtIdx; |
443 | 432 |
444 typedef GrGpu INHERITED; | 433 typedef GrGpu INHERITED; |
445 }; | 434 }; |
446 | 435 |
447 #endif | 436 #endif |
OLD | NEW |