Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: src/gpu/gl/GrGLGpuProgramCache.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | src/gpu/gl/GrGLIndexBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrProcessor.h" 11 #include "GrProcessor.h"
12 #include "GrGLFragmentProcessor.h" 12 #include "GrGLFragmentProcessor.h"
13 #include "GrGLPathRendering.h" 13 #include "GrGLPathRendering.h"
14 #include "SkRTConf.h" 14 #include "SkRTConf.h"
15 #include "SkTSearch.h" 15 #include "SkTSearch.h"
16 16
17 #ifdef PROGRAM_CACHE_STATS 17 #ifdef PROGRAM_CACHE_STATS
18 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, 18 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
19 "Display program cache usage."); 19 "Display program cache usage.");
20 #endif 20 #endif
21 21
22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
23 23
24 struct GrGLGpu::ProgramCache::Entry { 24 struct GrGLGpu::ProgramCache::Entry {
25 25
26 Entry() : fProgram(NULL), fLRUStamp(0) {} 26 Entry() : fProgram(nullptr), fLRUStamp(0) {}
27 27
28 SkAutoTUnref<GrGLProgram> fProgram; 28 SkAutoTUnref<GrGLProgram> fProgram;
29 unsigned int fLRUStamp; 29 unsigned int fLRUStamp;
30 }; 30 };
31 31
32 struct GrGLGpu::ProgramCache::ProgDescLess { 32 struct GrGLGpu::ProgramCache::ProgDescLess {
33 bool operator() (const GrProgramDesc& desc, const Entry* entry) { 33 bool operator() (const GrProgramDesc& desc, const Entry* entry) {
34 SkASSERT(entry->fProgram.get()); 34 SkASSERT(entry->fProgram.get());
35 return GrProgramDesc::Less(desc, entry->fProgram->getDesc()); 35 return GrProgramDesc::Less(desc, entry->fProgram->getDesc());
36 } 36 }
37 37
38 bool operator() (const Entry* entry, const GrProgramDesc& desc) { 38 bool operator() (const Entry* entry, const GrProgramDesc& desc) {
39 SkASSERT(entry->fProgram.get()); 39 SkASSERT(entry->fProgram.get());
40 return GrProgramDesc::Less(entry->fProgram->getDesc(), desc); 40 return GrProgramDesc::Less(entry->fProgram->getDesc(), desc);
41 } 41 }
42 }; 42 };
43 43
44 GrGLGpu::ProgramCache::ProgramCache(GrGLGpu* gpu) 44 GrGLGpu::ProgramCache::ProgramCache(GrGLGpu* gpu)
45 : fCount(0) 45 : fCount(0)
46 , fCurrLRUStamp(0) 46 , fCurrLRUStamp(0)
47 , fGpu(gpu) 47 , fGpu(gpu)
48 #ifdef PROGRAM_CACHE_STATS 48 #ifdef PROGRAM_CACHE_STATS
49 , fTotalRequests(0) 49 , fTotalRequests(0)
50 , fCacheMisses(0) 50 , fCacheMisses(0)
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] = nullptr;
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 delete 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) {
(...skipping 22 matching lines...) Expand all
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) {
94 #ifdef PROGRAM_CACHE_STATS 94 #ifdef PROGRAM_CACHE_STATS
95 ++fTotalRequests; 95 ++fTotalRequests;
96 #endif 96 #endif
97 97
98 Entry* entry = NULL; 98 Entry* entry = nullptr;
99 99
100 uint32_t hashIdx = args.fDesc->getChecksum(); 100 uint32_t hashIdx = args.fDesc->getChecksum();
101 hashIdx ^= hashIdx >> 16; 101 hashIdx ^= hashIdx >> 16;
102 if (kHashBits <= 8) { 102 if (kHashBits <= 8) {
103 hashIdx ^= hashIdx >> 8; 103 hashIdx ^= hashIdx >> 8;
104 } 104 }
105 hashIdx &=((1 << kHashBits) - 1); 105 hashIdx &=((1 << kHashBits) - 1);
106 Entry* hashedEntry = fHashTable[hashIdx]; 106 Entry* hashedEntry = fHashTable[hashIdx];
107 if (hashedEntry && hashedEntry->fProgram->getDesc() == *args.fDesc) { 107 if (hashedEntry && hashedEntry->fProgram->getDesc() == *args.fDesc) {
108 SkASSERT(hashedEntry->fProgram); 108 SkASSERT(hashedEntry->fProgram);
109 entry = hashedEntry; 109 entry = hashedEntry;
110 } 110 }
111 111
112 int entryIdx; 112 int entryIdx;
113 if (NULL == entry) { 113 if (nullptr == entry) {
114 entryIdx = this->search(*args.fDesc); 114 entryIdx = this->search(*args.fDesc);
115 if (entryIdx >= 0) { 115 if (entryIdx >= 0) {
116 entry = fEntries[entryIdx]; 116 entry = fEntries[entryIdx];
117 #ifdef PROGRAM_CACHE_STATS 117 #ifdef PROGRAM_CACHE_STATS
118 ++fHashMisses; 118 ++fHashMisses;
119 #endif 119 #endif
120 } 120 }
121 } 121 }
122 122
123 if (NULL == entry) { 123 if (nullptr == entry) {
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 (nullptr == program) {
130 return NULL; 130 return nullptr;
131 } 131 }
132 int purgeIdx = 0; 132 int purgeIdx = 0;
133 if (fCount < kMaxEntries) { 133 if (fCount < kMaxEntries) {
134 entry = new 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 }
145 entry = fEntries[purgeIdx]; 145 entry = fEntries[purgeIdx];
146 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 < < kHashBits) - 1); 146 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 < < kHashBits) - 1);
147 if (fHashTable[purgedHashIdx] == entry) { 147 if (fHashTable[purgedHashIdx] == entry) {
148 fHashTable[purgedHashIdx] = NULL; 148 fHashTable[purgedHashIdx] = nullptr;
149 } 149 }
150 } 150 }
151 SkASSERT(fEntries[purgeIdx] == entry); 151 SkASSERT(fEntries[purgeIdx] == entry);
152 entry->fProgram.reset(program); 152 entry->fProgram.reset(program);
153 // We need to shift fEntries around so that the entry currently at purge Idx is placed 153 // We need to shift fEntries around so that the entry currently at purge Idx is placed
154 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor). 154 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
155 entryIdx = ~entryIdx; 155 entryIdx = ~entryIdx;
156 if (entryIdx < purgeIdx) { 156 if (entryIdx < purgeIdx) {
157 // Let E and P be the entries at index entryIdx and purgeIdx, respe ctively. 157 // Let E and P be the entries at index entryIdx and purgeIdx, respe ctively.
158 // If the entries array looks like this: 158 // If the entries array looks like this:
(...skipping 29 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | src/gpu/gl/GrGLIndexBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698