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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
9 | 9 |
10 #include "builders/GrGLProgramBuilder.h" | 10 #include "builders/GrGLProgramBuilder.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ? | 70 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ? |
71 100.f * fCacheMisses / fTotalRequest
s : | 71 100.f * fCacheMisses / fTotalRequest
s : |
72 0.f); | 72 0.f); |
73 int cacheHits = fTotalRequests - fCacheMisses; | 73 int cacheHits = fTotalRequests - fCacheMisses; |
74 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / c
acheHits : 0.f); | 74 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / c
acheHits : 0.f); |
75 SkDebugf("---------------------\n"); | 75 SkDebugf("---------------------\n"); |
76 } | 76 } |
77 #endif | 77 #endif |
78 } | 78 } |
79 | 79 |
| 80 void GrGLGpu::ProgramCache::reset() { |
| 81 for (int i = 0; i < fCount; ++i) { |
| 82 SkASSERT(fEntries[i]->fProgram.get()); |
| 83 fEntries[i]->fProgram->abandon(); |
| 84 delete fEntries[i]; |
| 85 fEntries[i] = nullptr; |
| 86 } |
| 87 fCount = 0; |
| 88 |
| 89 // zero out hash table |
| 90 for (int i = 0; i < 1 << kHashBits; i++) { |
| 91 fHashTable[i] = nullptr; |
| 92 } |
| 93 |
| 94 fCurrLRUStamp = 0; |
| 95 #ifdef PROGRAM_CACHE_STATS |
| 96 fTotalRequests = 0; |
| 97 fCacheMisses = 0; |
| 98 fHashMisses = 0; |
| 99 #endif |
| 100 } |
| 101 |
80 void GrGLGpu::ProgramCache::abandon() { | 102 void GrGLGpu::ProgramCache::abandon() { |
81 for (int i = 0; i < fCount; ++i) { | 103 this->reset(); |
82 SkASSERT(fEntries[i]->fProgram.get()); | |
83 fEntries[i]->fProgram->abandon(); | |
84 delete fEntries[i]; | |
85 } | |
86 fCount = 0; | |
87 } | 104 } |
88 | 105 |
89 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { | 106 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { |
90 ProgDescLess less; | 107 ProgDescLess less; |
91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 108 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
92 } | 109 } |
93 | 110 |
94 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) { | 111 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) { |
95 #ifdef PROGRAM_CACHE_STATS | 112 #ifdef PROGRAM_CACHE_STATS |
96 ++fTotalRequests; | 113 ++fTotalRequests; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 206 |
190 if (SK_MaxU32 == fCurrLRUStamp) { | 207 if (SK_MaxU32 == fCurrLRUStamp) { |
191 // wrap around! just trash our LRU, one time hit. | 208 // wrap around! just trash our LRU, one time hit. |
192 for (int i = 0; i < fCount; ++i) { | 209 for (int i = 0; i < fCount; ++i) { |
193 fEntries[i]->fLRUStamp = 0; | 210 fEntries[i]->fLRUStamp = 0; |
194 } | 211 } |
195 } | 212 } |
196 ++fCurrLRUStamp; | 213 ++fCurrLRUStamp; |
197 return SkRef(entry->fProgram.get()); | 214 return SkRef(entry->fProgram.get()); |
198 } | 215 } |
OLD | NEW |