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

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

Issue 22850006: Replace uses of GrAssert by SkASSERT. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | src/gpu/gl/debug/GrDebugGL.h » ('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 "GrGpuGL.h" 8 #include "GrGpuGL.h"
9 9
10 #include "GrEffect.h" 10 #include "GrEffect.h"
11 #include "GrGLEffect.h" 11 #include "GrGLEffect.h"
12 #include "SkTSearch.h" 12 #include "SkTSearch.h"
13 13
14 typedef GrGLUniformManager::UniformHandle UniformHandle; 14 typedef GrGLUniformManager::UniformHandle UniformHandle;
15 15
16 struct GrGpuGL::ProgramCache::Entry { 16 struct GrGpuGL::ProgramCache::Entry {
17 SK_DECLARE_INST_COUNT_ROOT(Entry); 17 SK_DECLARE_INST_COUNT_ROOT(Entry);
18 Entry() : fProgram(NULL), fLRUStamp(0) {} 18 Entry() : fProgram(NULL), fLRUStamp(0) {}
19 19
20 SkAutoTUnref<GrGLProgram> fProgram; 20 SkAutoTUnref<GrGLProgram> fProgram;
21 unsigned int fLRUStamp; 21 unsigned int fLRUStamp;
22 }; 22 };
23 23
24 SK_DEFINE_INST_COUNT(GrGpuGL::ProgramCache::Entry); 24 SK_DEFINE_INST_COUNT(GrGpuGL::ProgramCache::Entry);
25 25
26 struct GrGpuGL::ProgramCache::ProgDescLess { 26 struct GrGpuGL::ProgramCache::ProgDescLess {
27 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) { 27 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) {
28 GrAssert(NULL != entry->fProgram.get()); 28 SkASSERT(NULL != entry->fProgram.get());
29 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc()); 29 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc());
30 } 30 }
31 31
32 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) { 32 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) {
33 GrAssert(NULL != entry->fProgram.get()); 33 SkASSERT(NULL != entry->fProgram.get());
34 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc); 34 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc);
35 } 35 }
36 }; 36 };
37 37
38 GrGpuGL::ProgramCache::ProgramCache(const GrGLContext& gl) 38 GrGpuGL::ProgramCache::ProgramCache(const GrGLContext& gl)
39 : fCount(0) 39 : fCount(0)
40 , fCurrLRUStamp(0) 40 , fCurrLRUStamp(0)
41 , fGL(gl) 41 , fGL(gl)
42 #ifdef PROGRAM_CACHE_STATS 42 #ifdef PROGRAM_CACHE_STATS
43 , fTotalRequests(0) 43 , fTotalRequests(0)
(...skipping 19 matching lines...) Expand all
63 100.f * fCacheMisses / fTotalRequests : 63 100.f * fCacheMisses / fTotalRequests :
64 0.f); 64 0.f);
65 int cacheHits = fTotalRequests - fCacheMisses; 65 int cacheHits = fTotalRequests - fCacheMisses;
66 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cache Hits : 0.f); 66 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cache Hits : 0.f);
67 SkDebugf("---------------------\n"); 67 SkDebugf("---------------------\n");
68 #endif 68 #endif
69 } 69 }
70 70
71 void GrGpuGL::ProgramCache::abandon() { 71 void GrGpuGL::ProgramCache::abandon() {
72 for (int i = 0; i < fCount; ++i) { 72 for (int i = 0; i < fCount; ++i) {
73 GrAssert(NULL != fEntries[i]->fProgram.get()); 73 SkASSERT(NULL != fEntries[i]->fProgram.get());
74 fEntries[i]->fProgram->abandon(); 74 fEntries[i]->fProgram->abandon();
75 fEntries[i]->fProgram.reset(NULL); 75 fEntries[i]->fProgram.reset(NULL);
76 } 76 }
77 fCount = 0; 77 fCount = 0;
78 } 78 }
79 79
80 int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const { 80 int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const {
81 ProgDescLess less; 81 ProgDescLess less;
82 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); 82 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
83 } 83 }
84 84
85 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc, 85 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc,
86 const GrEffectStage* colorStages[ ], 86 const GrEffectStage* colorStages[ ],
87 const GrEffectStage* coverageStag es[]) { 87 const GrEffectStage* coverageStag es[]) {
88 #ifdef PROGRAM_CACHE_STATS 88 #ifdef PROGRAM_CACHE_STATS
89 ++fTotalRequests; 89 ++fTotalRequests;
90 #endif 90 #endif
91 91
92 Entry* entry = NULL; 92 Entry* entry = NULL;
93 93
94 uint32_t hashIdx = desc.getChecksum(); 94 uint32_t hashIdx = desc.getChecksum();
95 hashIdx ^= hashIdx >> 16; 95 hashIdx ^= hashIdx >> 16;
96 if (kHashBits <= 8) { 96 if (kHashBits <= 8) {
97 hashIdx ^= hashIdx >> 8; 97 hashIdx ^= hashIdx >> 8;
98 } 98 }
99 hashIdx &=((1 << kHashBits) - 1); 99 hashIdx &=((1 << kHashBits) - 1);
100 Entry* hashedEntry = fHashTable[hashIdx]; 100 Entry* hashedEntry = fHashTable[hashIdx];
101 if (NULL != hashedEntry && hashedEntry->fProgram->getDesc() == desc) { 101 if (NULL != hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
102 GrAssert(NULL != hashedEntry->fProgram); 102 SkASSERT(NULL != hashedEntry->fProgram);
103 entry = hashedEntry; 103 entry = hashedEntry;
104 } 104 }
105 105
106 int entryIdx; 106 int entryIdx;
107 if (NULL == entry) { 107 if (NULL == entry) {
108 entryIdx = this->search(desc); 108 entryIdx = this->search(desc);
109 if (entryIdx >= 0) { 109 if (entryIdx >= 0) {
110 entry = fEntries[entryIdx]; 110 entry = fEntries[entryIdx];
111 #ifdef PROGRAM_CACHE_STATS 111 #ifdef PROGRAM_CACHE_STATS
112 ++fHashMisses; 112 ++fHashMisses;
113 #endif 113 #endif
114 } 114 }
115 } 115 }
116 116
117 if (NULL == entry) { 117 if (NULL == entry) {
118 // We have a cache miss 118 // We have a cache miss
119 #ifdef PROGRAM_CACHE_STATS 119 #ifdef PROGRAM_CACHE_STATS
120 ++fCacheMisses; 120 ++fCacheMisses;
121 #endif 121 #endif
122 GrGLProgram* program = GrGLProgram::Create(fGL, desc, colorStages, cover ageStages); 122 GrGLProgram* program = GrGLProgram::Create(fGL, desc, colorStages, cover ageStages);
123 if (NULL == program) { 123 if (NULL == program) {
124 return NULL; 124 return NULL;
125 } 125 }
126 int purgeIdx = 0; 126 int purgeIdx = 0;
127 if (fCount < kMaxEntries) { 127 if (fCount < kMaxEntries) {
128 entry = SkNEW(Entry); 128 entry = SkNEW(Entry);
129 purgeIdx = fCount++; 129 purgeIdx = fCount++;
130 fEntries[purgeIdx] = entry; 130 fEntries[purgeIdx] = entry;
131 } else { 131 } else {
132 GrAssert(fCount == kMaxEntries); 132 SkASSERT(fCount == kMaxEntries);
133 purgeIdx = 0; 133 purgeIdx = 0;
134 for (int i = 1; i < kMaxEntries; ++i) { 134 for (int i = 1; i < kMaxEntries; ++i) {
135 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) { 135 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) {
136 purgeIdx = i; 136 purgeIdx = i;
137 } 137 }
138 } 138 }
139 entry = fEntries[purgeIdx]; 139 entry = fEntries[purgeIdx];
140 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 < < kHashBits) - 1); 140 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 < < kHashBits) - 1);
141 if (fHashTable[purgedHashIdx] == entry) { 141 if (fHashTable[purgedHashIdx] == entry) {
142 fHashTable[purgedHashIdx] = NULL; 142 fHashTable[purgedHashIdx] = NULL;
143 } 143 }
144 } 144 }
145 GrAssert(fEntries[purgeIdx] == entry); 145 SkASSERT(fEntries[purgeIdx] == entry);
146 entry->fProgram.reset(program); 146 entry->fProgram.reset(program);
147 // We need to shift fEntries around so that the entry currently at purge Idx is placed 147 // We need to shift fEntries around so that the entry currently at purge Idx is placed
148 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor). 148 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
149 entryIdx = ~entryIdx; 149 entryIdx = ~entryIdx;
150 if (entryIdx < purgeIdx) { 150 if (entryIdx < purgeIdx) {
151 // Let E and P be the entries at index entryIdx and purgeIdx, respe ctively. 151 // Let E and P be the entries at index entryIdx and purgeIdx, respe ctively.
152 // If the entries array looks like this: 152 // If the entries array looks like this:
153 // aaaaEbbbbbPccccc 153 // aaaaEbbbbbPccccc
154 // we rearrange it to look like this: 154 // we rearrange it to look like this:
155 // aaaaPEbbbbbccccc 155 // aaaaPEbbbbbccccc
156 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*); 156 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*);
157 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize); 157 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize);
158 fEntries[entryIdx] = entry; 158 fEntries[entryIdx] = entry;
159 } else if (purgeIdx < entryIdx) { 159 } else if (purgeIdx < entryIdx) {
160 // If the entries array looks like this: 160 // If the entries array looks like this:
161 // aaaaPbbbbbEccccc 161 // aaaaPbbbbbEccccc
162 // we rearrange it to look like this: 162 // we rearrange it to look like this:
163 // aaaabbbbbPEccccc 163 // aaaabbbbbPEccccc
164 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*); 164 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*);
165 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize); 165 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize);
166 fEntries[entryIdx - 1] = entry; 166 fEntries[entryIdx - 1] = entry;
167 } 167 }
168 #if GR_DEBUG 168 #if GR_DEBUG
169 GrAssert(NULL != fEntries[0]->fProgram.get()); 169 SkASSERT(NULL != fEntries[0]->fProgram.get());
170 for (int i = 0; i < fCount - 1; ++i) { 170 for (int i = 0; i < fCount - 1; ++i) {
171 GrAssert(NULL != fEntries[i + 1]->fProgram.get()); 171 SkASSERT(NULL != fEntries[i + 1]->fProgram.get());
172 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc(); 172 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc();
173 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc(); 173 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc();
174 GrAssert(GrGLProgramDesc::Less(a, b)); 174 SkASSERT(GrGLProgramDesc::Less(a, b));
175 GrAssert(!GrGLProgramDesc::Less(b, a)); 175 SkASSERT(!GrGLProgramDesc::Less(b, a));
176 } 176 }
177 #endif 177 #endif
178 } 178 }
179 179
180 fHashTable[hashIdx] = entry; 180 fHashTable[hashIdx] = entry;
181 entry->fLRUStamp = fCurrLRUStamp; 181 entry->fLRUStamp = fCurrLRUStamp;
182 182
183 if (SK_MaxU32 == fCurrLRUStamp) { 183 if (SK_MaxU32 == fCurrLRUStamp) {
184 // wrap around! just trash our LRU, one time hit. 184 // wrap around! just trash our LRU, one time hit.
185 for (int i = 0; i < fCount; ++i) { 185 for (int i = 0; i < fCount; ++i) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 fHWPathStencilMatrixState.fViewMatrix = vm; 252 fHWPathStencilMatrixState.fViewMatrix = vm;
253 fHWPathStencilMatrixState.fRenderTargetSize = size; 253 fHWPathStencilMatrixState.fRenderTargetSize = size;
254 fHWPathStencilMatrixState.fRenderTargetOrigin = rt->origin(); 254 fHWPathStencilMatrixState.fRenderTargetOrigin = rt->origin();
255 } 255 }
256 } 256 }
257 257
258 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) { 258 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) {
259 const GrDrawState& drawState = this->getDrawState(); 259 const GrDrawState& drawState = this->getDrawState();
260 260
261 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. 261 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
262 GrAssert(NULL != drawState.getRenderTarget()); 262 SkASSERT(NULL != drawState.getRenderTarget());
263 263
264 if (kStencilPath_DrawType == type) { 264 if (kStencilPath_DrawType == type) {
265 this->flushPathStencilMatrix(); 265 this->flushPathStencilMatrix();
266 } else { 266 } else {
267 this->flushMiscFixedFunctionState(); 267 this->flushMiscFixedFunctionState();
268 268
269 GrBlendCoeff srcCoeff; 269 GrBlendCoeff srcCoeff;
270 GrBlendCoeff dstCoeff; 270 GrBlendCoeff dstCoeff;
271 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr cCoeff, &dstCoeff); 271 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr cCoeff, &dstCoeff);
272 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { 272 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) {
(...skipping 11 matching lines...) Expand all
284 this, 284 this,
285 dstCopy, 285 dstCopy,
286 &colorStages, 286 &colorStages,
287 &coverageStages, 287 &coverageStages,
288 &desc); 288 &desc);
289 289
290 fCurrentProgram.reset(fProgramCache->getProgram(desc, 290 fCurrentProgram.reset(fProgramCache->getProgram(desc,
291 colorStages.begin(), 291 colorStages.begin(),
292 coverageStages.begin())) ; 292 coverageStages.begin())) ;
293 if (NULL == fCurrentProgram.get()) { 293 if (NULL == fCurrentProgram.get()) {
294 GrAssert(!"Failed to create program!"); 294 SkASSERT(!"Failed to create program!");
295 return false; 295 return false;
296 } 296 }
297 fCurrentProgram.get()->ref(); 297 fCurrentProgram.get()->ref();
298 298
299 GrGLuint programID = fCurrentProgram->programID(); 299 GrGLuint programID = fCurrentProgram->programID();
300 if (fHWProgramID != programID) { 300 if (fHWProgramID != programID) {
301 GL_CALL(UseProgram(programID)); 301 GL_CALL(UseProgram(programID));
302 fHWProgramID = programID; 302 fHWProgramID = programID;
303 } 303 }
304 304
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 case kReserved_GeometrySrcType: 346 case kReserved_GeometrySrcType:
347 this->finalizeReservedVertices(); 347 this->finalizeReservedVertices();
348 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeom Src().fVertexSize; 348 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeom Src().fVertexSize;
349 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer; 349 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer;
350 break; 350 break;
351 default: 351 default:
352 vbuf = NULL; // suppress warning 352 vbuf = NULL; // suppress warning
353 GrCrash("Unknown geometry src type!"); 353 GrCrash("Unknown geometry src type!");
354 } 354 }
355 355
356 GrAssert(NULL != vbuf); 356 SkASSERT(NULL != vbuf);
357 GrAssert(!vbuf->isLocked()); 357 SkASSERT(!vbuf->isLocked());
358 vertexOffsetInBytes += vbuf->baseOffset(); 358 vertexOffsetInBytes += vbuf->baseOffset();
359 359
360 GrGLIndexBuffer* ibuf = NULL; 360 GrGLIndexBuffer* ibuf = NULL;
361 if (info.isIndexed()) { 361 if (info.isIndexed()) {
362 GrAssert(NULL != indexOffsetInBytes); 362 SkASSERT(NULL != indexOffsetInBytes);
363 363
364 switch (this->getGeomSrc().fIndexSrc) { 364 switch (this->getGeomSrc().fIndexSrc) {
365 case kBuffer_GeometrySrcType: 365 case kBuffer_GeometrySrcType:
366 *indexOffsetInBytes = 0; 366 *indexOffsetInBytes = 0;
367 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer; 367 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
368 break; 368 break;
369 case kArray_GeometrySrcType: 369 case kArray_GeometrySrcType:
370 case kReserved_GeometrySrcType: 370 case kReserved_GeometrySrcType:
371 this->finalizeReservedIndices(); 371 this->finalizeReservedIndices();
372 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLusho rt); 372 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLusho rt);
373 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer; 373 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer;
374 break; 374 break;
375 default: 375 default:
376 ibuf = NULL; // suppress warning 376 ibuf = NULL; // suppress warning
377 GrCrash("Unknown geometry src type!"); 377 GrCrash("Unknown geometry src type!");
378 } 378 }
379 379
380 GrAssert(NULL != ibuf); 380 SkASSERT(NULL != ibuf);
381 GrAssert(!ibuf->isLocked()); 381 SkASSERT(!ibuf->isLocked());
382 *indexOffsetInBytes += ibuf->baseOffset(); 382 *indexOffsetInBytes += ibuf->baseOffset();
383 } 383 }
384 GrGLAttribArrayState* attribState = 384 GrGLAttribArrayState* attribState =
385 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); 385 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
386 386
387 uint32_t usedAttribArraysMask = 0; 387 uint32_t usedAttribArraysMask = 0;
388 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs() ; 388 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs() ;
389 int vertexAttribCount = this->getDrawState().getVertexAttribCount(); 389 int vertexAttribCount = this->getDrawState().getVertexAttribCount();
390 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; 390 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
391 ++vertexAttribIndex, ++vertexAttrib) { 391 ++vertexAttribIndex, ++vertexAttrib) {
392 392
393 usedAttribArraysMask |= (1 << vertexAttribIndex); 393 usedAttribArraysMask |= (1 << vertexAttribIndex);
394 GrVertexAttribType attribType = vertexAttrib->fType; 394 GrVertexAttribType attribType = vertexAttrib->fType;
395 attribState->set(this, 395 attribState->set(this,
396 vertexAttribIndex, 396 vertexAttribIndex,
397 vbuf, 397 vbuf,
398 GrGLAttribTypeToLayout(attribType).fCount, 398 GrGLAttribTypeToLayout(attribType).fCount,
399 GrGLAttribTypeToLayout(attribType).fType, 399 GrGLAttribTypeToLayout(attribType).fType,
400 GrGLAttribTypeToLayout(attribType).fNormalized, 400 GrGLAttribTypeToLayout(attribType).fNormalized,
401 stride, 401 stride,
402 reinterpret_cast<GrGLvoid*>( 402 reinterpret_cast<GrGLvoid*>(
403 vertexOffsetInBytes + vertexAttrib->fOffset)); 403 vertexOffsetInBytes + vertexAttrib->fOffset));
404 } 404 }
405 405
406 attribState->disableUnusedAttribArrays(this, usedAttribArraysMask); 406 attribState->disableUnusedAttribArrays(this, usedAttribArraysMask);
407 } 407 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | src/gpu/gl/debug/GrDebugGL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698