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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 void GrGLGpu::ProgramCache::abandon() { | 102 void GrGLGpu::ProgramCache::abandon() { |
103 this->reset(); | 103 this->reset(); |
104 } | 104 } |
105 | 105 |
106 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { | 106 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { |
107 ProgDescLess less; | 107 ProgDescLess less; |
108 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 108 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
109 } | 109 } |
110 | 110 |
111 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) { | 111 GrGLProgram* GrGLGpu::ProgramCache::refProgram(const GrGLGpu* gpu, |
| 112 const GrPipeline& pipeline, |
| 113 const GrPrimitiveProcessor& primP
roc) { |
112 #ifdef PROGRAM_CACHE_STATS | 114 #ifdef PROGRAM_CACHE_STATS |
113 ++fTotalRequests; | 115 ++fTotalRequests; |
114 #endif | 116 #endif |
115 | 117 |
| 118 // Get GrGLProgramDesc |
| 119 GrGLProgramDesc desc; |
| 120 if (!GrGLProgramDescBuilder::Build(&desc, primProc, pipeline, *gpu->glCaps()
.glslCaps())) { |
| 121 GrCapsDebugf(gpu->caps(), "Failed to gl program descriptor!\n"); |
| 122 return nullptr; |
| 123 } |
| 124 |
116 Entry* entry = nullptr; | 125 Entry* entry = nullptr; |
117 | 126 |
118 uint32_t hashIdx = args.fDesc->getChecksum(); | 127 uint32_t hashIdx = desc.getChecksum(); |
119 hashIdx ^= hashIdx >> 16; | 128 hashIdx ^= hashIdx >> 16; |
120 if (kHashBits <= 8) { | 129 if (kHashBits <= 8) { |
121 hashIdx ^= hashIdx >> 8; | 130 hashIdx ^= hashIdx >> 8; |
122 } | 131 } |
123 hashIdx &=((1 << kHashBits) - 1); | 132 hashIdx &=((1 << kHashBits) - 1); |
124 Entry* hashedEntry = fHashTable[hashIdx]; | 133 Entry* hashedEntry = fHashTable[hashIdx]; |
125 if (hashedEntry && hashedEntry->fProgram->getDesc() == *args.fDesc) { | 134 if (hashedEntry && hashedEntry->fProgram->getDesc() == desc) { |
126 SkASSERT(hashedEntry->fProgram); | 135 SkASSERT(hashedEntry->fProgram); |
127 entry = hashedEntry; | 136 entry = hashedEntry; |
128 } | 137 } |
129 | 138 |
130 int entryIdx; | 139 int entryIdx; |
131 if (nullptr == entry) { | 140 if (nullptr == entry) { |
132 entryIdx = this->search(*args.fDesc); | 141 entryIdx = this->search(desc); |
133 if (entryIdx >= 0) { | 142 if (entryIdx >= 0) { |
134 entry = fEntries[entryIdx]; | 143 entry = fEntries[entryIdx]; |
135 #ifdef PROGRAM_CACHE_STATS | 144 #ifdef PROGRAM_CACHE_STATS |
136 ++fHashMisses; | 145 ++fHashMisses; |
137 #endif | 146 #endif |
138 } | 147 } |
139 } | 148 } |
140 | 149 |
141 if (nullptr == entry) { | 150 if (nullptr == entry) { |
142 // We have a cache miss | 151 // We have a cache miss |
143 #ifdef PROGRAM_CACHE_STATS | 152 #ifdef PROGRAM_CACHE_STATS |
144 ++fCacheMisses; | 153 ++fCacheMisses; |
145 #endif | 154 #endif |
146 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(args, fGpu); | 155 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(pipeline, primP
roc, desc, fGpu); |
147 if (nullptr == program) { | 156 if (nullptr == program) { |
148 return nullptr; | 157 return nullptr; |
149 } | 158 } |
150 int purgeIdx = 0; | 159 int purgeIdx = 0; |
151 if (fCount < kMaxEntries) { | 160 if (fCount < kMaxEntries) { |
152 entry = new Entry; | 161 entry = new Entry; |
153 purgeIdx = fCount++; | 162 purgeIdx = fCount++; |
154 fEntries[purgeIdx] = entry; | 163 fEntries[purgeIdx] = entry; |
155 } else { | 164 } else { |
156 SkASSERT(fCount == kMaxEntries); | 165 SkASSERT(fCount == kMaxEntries); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 215 |
207 if (SK_MaxU32 == fCurrLRUStamp) { | 216 if (SK_MaxU32 == fCurrLRUStamp) { |
208 // wrap around! just trash our LRU, one time hit. | 217 // wrap around! just trash our LRU, one time hit. |
209 for (int i = 0; i < fCount; ++i) { | 218 for (int i = 0; i < fCount; ++i) { |
210 fEntries[i]->fLRUStamp = 0; | 219 fEntries[i]->fLRUStamp = 0; |
211 } | 220 } |
212 } | 221 } |
213 ++fCurrLRUStamp; | 222 ++fCurrLRUStamp; |
214 return SkRef(entry->fProgram.get()); | 223 return SkRef(entry->fProgram.get()); |
215 } | 224 } |
OLD | NEW |