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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 , fHashMisses(0) | 51 , fHashMisses(0) |
52 #endif | 52 #endif |
53 { | 53 { |
54 for (int i = 0; i < 1 << kHashBits; ++i) { | 54 for (int i = 0; i < 1 << kHashBits; ++i) { |
55 fHashTable[i] = NULL; | 55 fHashTable[i] = NULL; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 GrGLGpu::ProgramCache::~ProgramCache() { | 59 GrGLGpu::ProgramCache::~ProgramCache() { |
60 for (int i = 0; i < fCount; ++i){ | 60 for (int i = 0; i < fCount; ++i){ |
61 SkDELETE(fEntries[i]); | 61 delete fEntries[i]; |
62 } | 62 } |
63 // dump stats | 63 // dump stats |
64 #ifdef PROGRAM_CACHE_STATS | 64 #ifdef PROGRAM_CACHE_STATS |
65 if (c_DisplayCache) { | 65 if (c_DisplayCache) { |
66 SkDebugf("--- Program Cache ---\n"); | 66 SkDebugf("--- Program Cache ---\n"); |
67 SkDebugf("Total requests: %d\n", fTotalRequests); | 67 SkDebugf("Total requests: %d\n", fTotalRequests); |
68 SkDebugf("Cache misses: %d\n", fCacheMisses); | 68 SkDebugf("Cache misses: %d\n", fCacheMisses); |
69 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ? | 69 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ? |
70 100.f * fCacheMisses / fTotalRequest
s : | 70 100.f * fCacheMisses / fTotalRequest
s : |
71 0.f); | 71 0.f); |
72 int cacheHits = fTotalRequests - fCacheMisses; | 72 int cacheHits = fTotalRequests - fCacheMisses; |
73 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / c
acheHits : 0.f); | 73 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / c
acheHits : 0.f); |
74 SkDebugf("---------------------\n"); | 74 SkDebugf("---------------------\n"); |
75 } | 75 } |
76 #endif | 76 #endif |
77 } | 77 } |
78 | 78 |
79 void GrGLGpu::ProgramCache::abandon() { | 79 void GrGLGpu::ProgramCache::abandon() { |
80 for (int i = 0; i < fCount; ++i) { | 80 for (int i = 0; i < fCount; ++i) { |
81 SkASSERT(fEntries[i]->fProgram.get()); | 81 SkASSERT(fEntries[i]->fProgram.get()); |
82 fEntries[i]->fProgram->abandon(); | 82 fEntries[i]->fProgram->abandon(); |
83 SkDELETE(fEntries[i]); | 83 delete fEntries[i]; |
84 } | 84 } |
85 fCount = 0; | 85 fCount = 0; |
86 } | 86 } |
87 | 87 |
88 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { | 88 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { |
89 ProgDescLess less; | 89 ProgDescLess less; |
90 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 90 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
91 } | 91 } |
92 | 92 |
93 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) { | 93 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) { |
(...skipping 30 matching lines...) Expand all Loading... |
124 // We have a cache miss | 124 // We have a cache miss |
125 #ifdef PROGRAM_CACHE_STATS | 125 #ifdef PROGRAM_CACHE_STATS |
126 ++fCacheMisses; | 126 ++fCacheMisses; |
127 #endif | 127 #endif |
128 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(args, fGpu); | 128 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(args, fGpu); |
129 if (NULL == program) { | 129 if (NULL == program) { |
130 return NULL; | 130 return NULL; |
131 } | 131 } |
132 int purgeIdx = 0; | 132 int purgeIdx = 0; |
133 if (fCount < kMaxEntries) { | 133 if (fCount < kMaxEntries) { |
134 entry = SkNEW(Entry); | 134 entry = new Entry; |
135 purgeIdx = fCount++; | 135 purgeIdx = fCount++; |
136 fEntries[purgeIdx] = entry; | 136 fEntries[purgeIdx] = entry; |
137 } else { | 137 } else { |
138 SkASSERT(fCount == kMaxEntries); | 138 SkASSERT(fCount == kMaxEntries); |
139 purgeIdx = 0; | 139 purgeIdx = 0; |
140 for (int i = 1; i < kMaxEntries; ++i) { | 140 for (int i = 1; i < kMaxEntries; ++i) { |
141 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) { | 141 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) { |
142 purgeIdx = i; | 142 purgeIdx = i; |
143 } | 143 } |
144 } | 144 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 188 |
189 if (SK_MaxU32 == fCurrLRUStamp) { | 189 if (SK_MaxU32 == fCurrLRUStamp) { |
190 // wrap around! just trash our LRU, one time hit. | 190 // wrap around! just trash our LRU, one time hit. |
191 for (int i = 0; i < fCount; ++i) { | 191 for (int i = 0; i < fCount; ++i) { |
192 fEntries[i]->fLRUStamp = 0; | 192 fEntries[i]->fLRUStamp = 0; |
193 } | 193 } |
194 } | 194 } |
195 ++fCurrLRUStamp; | 195 ++fCurrLRUStamp; |
196 return SkRef(entry->fProgram.get()); | 196 return SkRef(entry->fProgram.get()); |
197 } | 197 } |
OLD | NEW |