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 "GrGpuGL.h" | 8 #include "GrGpuGL.h" |
9 | 9 |
10 #include "GrEffect.h" | 10 #include "GrEffect.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 fCount = 0; | 84 fCount = 0; |
85 } | 85 } |
86 | 86 |
87 int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const { | 87 int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const { |
88 ProgDescLess less; | 88 ProgDescLess less; |
89 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 89 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
90 } | 90 } |
91 | 91 |
92 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc, | 92 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc, |
| 93 const GrEffectStage* geometryProc
essor, |
93 const GrEffectStage* colorStages[
], | 94 const GrEffectStage* colorStages[
], |
94 const GrEffectStage* coverageStag
es[]) { | 95 const GrEffectStage* coverageStag
es[]) { |
95 #ifdef PROGRAM_CACHE_STATS | 96 #ifdef PROGRAM_CACHE_STATS |
96 ++fTotalRequests; | 97 ++fTotalRequests; |
97 #endif | 98 #endif |
98 | 99 |
99 Entry* entry = NULL; | 100 Entry* entry = NULL; |
100 | 101 |
101 uint32_t hashIdx = desc.getChecksum(); | 102 uint32_t hashIdx = desc.getChecksum(); |
102 hashIdx ^= hashIdx >> 16; | 103 hashIdx ^= hashIdx >> 16; |
(...skipping 16 matching lines...) Expand all Loading... |
119 ++fHashMisses; | 120 ++fHashMisses; |
120 #endif | 121 #endif |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 if (NULL == entry) { | 125 if (NULL == entry) { |
125 // We have a cache miss | 126 // We have a cache miss |
126 #ifdef PROGRAM_CACHE_STATS | 127 #ifdef PROGRAM_CACHE_STATS |
127 ++fCacheMisses; | 128 ++fCacheMisses; |
128 #endif | 129 #endif |
129 GrGLProgram* program = GrGLProgram::Create(fGpu, desc, colorStages, cove
rageStages); | 130 GrGLProgram* program = GrGLProgram::Create(fGpu, desc, geometryProcessor
, |
| 131 colorStages, coverageStages); |
130 if (NULL == program) { | 132 if (NULL == program) { |
131 return NULL; | 133 return NULL; |
132 } | 134 } |
133 int purgeIdx = 0; | 135 int purgeIdx = 0; |
134 if (fCount < kMaxEntries) { | 136 if (fCount < kMaxEntries) { |
135 entry = SkNEW(Entry); | 137 entry = SkNEW(Entry); |
136 purgeIdx = fCount++; | 138 purgeIdx = fCount++; |
137 fEntries[purgeIdx] = entry; | 139 fEntries[purgeIdx] = entry; |
138 } else { | 140 } else { |
139 SkASSERT(fCount == kMaxEntries); | 141 SkASSERT(fCount == kMaxEntries); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } else { | 217 } else { |
216 this->flushMiscFixedFunctionState(); | 218 this->flushMiscFixedFunctionState(); |
217 | 219 |
218 GrBlendCoeff srcCoeff; | 220 GrBlendCoeff srcCoeff; |
219 GrBlendCoeff dstCoeff; | 221 GrBlendCoeff dstCoeff; |
220 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr
cCoeff, &dstCoeff); | 222 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr
cCoeff, &dstCoeff); |
221 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { | 223 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { |
222 return false; | 224 return false; |
223 } | 225 } |
224 | 226 |
| 227 const GrEffectStage* geometryProcessor = NULL; |
225 SkSTArray<8, const GrEffectStage*, true> colorStages; | 228 SkSTArray<8, const GrEffectStage*, true> colorStages; |
226 SkSTArray<8, const GrEffectStage*, true> coverageStages; | 229 SkSTArray<8, const GrEffectStage*, true> coverageStages; |
227 GrGLProgramDesc desc; | 230 GrGLProgramDesc desc; |
228 if (!GrGLProgramDesc::Build(this->getDrawState(), | 231 if (!GrGLProgramDesc::Build(this->getDrawState(), |
229 type, | 232 type, |
230 blendOpts, | 233 blendOpts, |
231 srcCoeff, | 234 srcCoeff, |
232 dstCoeff, | 235 dstCoeff, |
233 this, | 236 this, |
234 dstCopy, | 237 dstCopy, |
| 238 &geometryProcessor, |
235 &colorStages, | 239 &colorStages, |
236 &coverageStages, | 240 &coverageStages, |
237 &desc)) { | 241 &desc)) { |
238 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 242 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
239 return false; | 243 return false; |
240 } | 244 } |
241 | 245 |
242 fCurrentProgram.reset(fProgramCache->getProgram(desc, | 246 fCurrentProgram.reset(fProgramCache->getProgram(desc, |
| 247 geometryProcessor, |
243 colorStages.begin(), | 248 colorStages.begin(), |
244 coverageStages.begin()))
; | 249 coverageStages.begin()))
; |
245 if (NULL == fCurrentProgram.get()) { | 250 if (NULL == fCurrentProgram.get()) { |
246 SkDEBUGFAIL("Failed to create program!"); | 251 SkDEBUGFAIL("Failed to create program!"); |
247 return false; | 252 return false; |
248 } | 253 } |
249 | 254 |
250 fCurrentProgram.get()->ref(); | 255 fCurrentProgram.get()->ref(); |
251 | 256 |
252 GrGLuint programID = fCurrentProgram->programID(); | 257 GrGLuint programID = fCurrentProgram->programID(); |
253 if (fHWProgramID != programID) { | 258 if (fHWProgramID != programID) { |
254 GL_CALL(UseProgram(programID)); | 259 GL_CALL(UseProgram(programID)); |
255 fHWProgramID = programID; | 260 fHWProgramID = programID; |
256 } | 261 } |
257 | 262 |
258 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); | 263 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); |
259 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); | 264 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); |
260 | 265 |
261 fCurrentProgram->setData(type, | 266 fCurrentProgram->setData(type, |
262 blendOpts, | 267 blendOpts, |
| 268 geometryProcessor, |
263 colorStages.begin(), | 269 colorStages.begin(), |
264 coverageStages.begin(), | 270 coverageStages.begin(), |
265 dstCopy, | 271 dstCopy, |
266 &fSharedGLProgramState); | 272 &fSharedGLProgramState); |
267 } | 273 } |
268 | 274 |
269 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(drawState.getRenderT
arget()); | 275 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(drawState.getRenderT
arget()); |
270 this->flushStencil(type); | 276 this->flushStencil(type); |
271 this->flushScissor(glRT->getViewport(), glRT->origin()); | 277 this->flushScissor(glRT->getViewport(), glRT->origin()); |
272 this->flushAAState(type); | 278 this->flushAAState(type); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 GrGLAttribTypeToLayout(attribType).fType, | 365 GrGLAttribTypeToLayout(attribType).fType, |
360 GrGLAttribTypeToLayout(attribType).fNormalized, | 366 GrGLAttribTypeToLayout(attribType).fNormalized, |
361 stride, | 367 stride, |
362 reinterpret_cast<GrGLvoid*>( | 368 reinterpret_cast<GrGLvoid*>( |
363 vertexOffsetInBytes + vertexAttrib->fOffset)); | 369 vertexOffsetInBytes + vertexAttrib->fOffset)); |
364 } | 370 } |
365 } | 371 } |
366 attribState->disableUnusedArrays(this, usedAttribArraysMask); | 372 attribState->disableUnusedArrays(this, usedAttribArraysMask); |
367 } | 373 } |
368 } | 374 } |
OLD | NEW |