| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 SkDELETE(fEntries[i]); | 84 SkDELETE(fEntries[i]); |
| 85 } | 85 } |
| 86 fCount = 0; | 86 fCount = 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { | 89 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const { |
| 90 ProgDescLess less; | 90 ProgDescLess less; |
| 91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
| 92 } | 92 } |
| 93 | 93 |
| 94 GrGLProgram* GrGLGpu::ProgramCache::getProgram(const GrOptDrawState& optState) { | 94 GrGLProgram* GrGLGpu::ProgramCache::getProgram(const DrawArgs& args) { |
| 95 #ifdef PROGRAM_CACHE_STATS | 95 #ifdef PROGRAM_CACHE_STATS |
| 96 ++fTotalRequests; | 96 ++fTotalRequests; |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 Entry* entry = NULL; | 99 Entry* entry = NULL; |
| 100 | 100 |
| 101 uint32_t hashIdx = optState.programDesc().getChecksum(); | 101 uint32_t hashIdx = args.fDesc->getChecksum(); |
| 102 hashIdx ^= hashIdx >> 16; | 102 hashIdx ^= hashIdx >> 16; |
| 103 if (kHashBits <= 8) { | 103 if (kHashBits <= 8) { |
| 104 hashIdx ^= hashIdx >> 8; | 104 hashIdx ^= hashIdx >> 8; |
| 105 } | 105 } |
| 106 hashIdx &=((1 << kHashBits) - 1); | 106 hashIdx &=((1 << kHashBits) - 1); |
| 107 Entry* hashedEntry = fHashTable[hashIdx]; | 107 Entry* hashedEntry = fHashTable[hashIdx]; |
| 108 if (hashedEntry && hashedEntry->fProgram->getDesc() == optState.programDesc(
)) { | 108 if (hashedEntry && hashedEntry->fProgram->getDesc() == *args.fDesc) { |
| 109 SkASSERT(hashedEntry->fProgram); | 109 SkASSERT(hashedEntry->fProgram); |
| 110 entry = hashedEntry; | 110 entry = hashedEntry; |
| 111 } | 111 } |
| 112 | 112 |
| 113 int entryIdx; | 113 int entryIdx; |
| 114 if (NULL == entry) { | 114 if (NULL == entry) { |
| 115 entryIdx = this->search(optState.programDesc()); | 115 entryIdx = this->search(*args.fDesc); |
| 116 if (entryIdx >= 0) { | 116 if (entryIdx >= 0) { |
| 117 entry = fEntries[entryIdx]; | 117 entry = fEntries[entryIdx]; |
| 118 #ifdef PROGRAM_CACHE_STATS | 118 #ifdef PROGRAM_CACHE_STATS |
| 119 ++fHashMisses; | 119 ++fHashMisses; |
| 120 #endif | 120 #endif |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (NULL == entry) { | 124 if (NULL == entry) { |
| 125 // We have a cache miss | 125 // We have a cache miss |
| 126 #ifdef PROGRAM_CACHE_STATS | 126 #ifdef PROGRAM_CACHE_STATS |
| 127 ++fCacheMisses; | 127 ++fCacheMisses; |
| 128 #endif | 128 #endif |
| 129 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, fGpu)
; | 129 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(args, fGpu); |
| 130 if (NULL == program) { | 130 if (NULL == program) { |
| 131 return NULL; | 131 return NULL; |
| 132 } | 132 } |
| 133 int purgeIdx = 0; | 133 int purgeIdx = 0; |
| 134 if (fCount < kMaxEntries) { | 134 if (fCount < kMaxEntries) { |
| 135 entry = SkNEW(Entry); | 135 entry = SkNEW(Entry); |
| 136 purgeIdx = fCount++; | 136 purgeIdx = fCount++; |
| 137 fEntries[purgeIdx] = entry; | 137 fEntries[purgeIdx] = entry; |
| 138 } else { | 138 } else { |
| 139 SkASSERT(fCount == kMaxEntries); | 139 SkASSERT(fCount == kMaxEntries); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 if (SK_MaxU32 == fCurrLRUStamp) { | 190 if (SK_MaxU32 == fCurrLRUStamp) { |
| 191 // wrap around! just trash our LRU, one time hit. | 191 // wrap around! just trash our LRU, one time hit. |
| 192 for (int i = 0; i < fCount; ++i) { | 192 for (int i = 0; i < fCount; ++i) { |
| 193 fEntries[i]->fLRUStamp = 0; | 193 fEntries[i]->fLRUStamp = 0; |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 ++fCurrLRUStamp; | 196 ++fCurrLRUStamp; |
| 197 return entry->fProgram; | 197 return entry->fProgram; |
| 198 } | 198 } |
| OLD | NEW |