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

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

Issue 356513003: Step towards variable length effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak comment Created 6 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "GrGLProgramEffects.h" 8 #include "GrGLProgramEffects.h"
9 #include "GrDrawEffect.h" 9 #include "GrDrawEffect.h"
10 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 EffectKey key, 232 EffectKey key,
233 const char* outColor, 233 const char* outColor,
234 const char* inColor, 234 const char* inColor,
235 int stageIndex) { 235 int stageIndex) {
236 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords); 236 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords);
237 const GrEffect* effect = stage.getEffect(); 237 const GrEffect* effect = stage.getEffect();
238 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); 238 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
239 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); 239 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
240 240
241 this->emitAttributes(builder, stage); 241 this->emitAttributes(builder, stage);
242 this->emitTransforms(builder, effect, key, &coords); 242 this->emitTransforms(builder, drawEffect, &coords);
243 this->emitSamplers(builder, effect, &samplers); 243 this->emitSamplers(builder, effect, &samplers);
244 244
245 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); 245 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
246 fGLEffects.push_back(glEffect); 246 fGLEffects.push_back(glEffect);
247 247
248 // Enclose custom code in a block to avoid namespace conflicts 248 // Enclose custom code in a block to avoid namespace conflicts
249 SkString openBrace; 249 SkString openBrace;
250 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); 250 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
251 builder->vsCodeAppend(openBrace.c_str()); 251 builder->vsCodeAppend(openBrace.c_str());
252 builder->fsCodeAppend(openBrace.c_str()); 252 builder->fsCodeAppend(openBrace.c_str());
(...skipping 17 matching lines...) Expand all
270 // TODO: Make addAttribute mangle the name. 270 // TODO: Make addAttribute mangle the name.
271 SkString attributeName("aAttr"); 271 SkString attributeName("aAttr");
272 attributeName.appendS32(attributeIndices[a]); 272 attributeName.appendS32(attributeIndices[a]);
273 builder->addEffectAttribute(attributeIndices[a], 273 builder->addEffectAttribute(attributeIndices[a],
274 stage.getEffect()->vertexAttribType(a), 274 stage.getEffect()->vertexAttribType(a),
275 attributeName); 275 attributeName);
276 } 276 }
277 } 277 }
278 278
279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, 279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder,
280 const GrEffect* effect, 280 const GrDrawEffect& drawEffect,
281 EffectKey effectKey,
282 TransformedCoordsArray* outCoords) { 281 TransformedCoordsArray* outCoords) {
283 SkTArray<Transform, true>& transforms = fTransforms.push_back(); 282 SkTArray<Transform, true>& transforms = fTransforms.push_back();
284 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); 283 EffectKey totalKey = GenTransformKey(drawEffect);
285 int numTransforms = effect->numTransforms(); 284 int numTransforms = drawEffect.effect()->numTransforms();
286 transforms.push_back_n(numTransforms); 285 transforms.push_back_n(numTransforms);
287 for (int t = 0; t < numTransforms; t++) { 286 for (int t = 0; t < numTransforms; t++) {
288 GrSLType varyingType = kVoid_GrSLType; 287 GrSLType varyingType = kVoid_GrSLType;
289 const char* uniName; 288 const char* uniName;
290 switch (get_matrix_type(totalKey, t)) { 289 switch (get_matrix_type(totalKey, t)) {
291 case kNoPersp_MatrixType: 290 case kNoPersp_MatrixType:
292 uniName = "StageMatrix"; 291 uniName = "StageMatrix";
293 varyingType = kVec2f_GrSLType; 292 varyingType = kVec2f_GrSLType;
294 break; 293 break;
295 case kGeneral_MatrixType: 294 case kGeneral_MatrixType:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 EffectKey key, 390 EffectKey key,
392 const char* outColor, 391 const char* outColor,
393 const char* inColor, 392 const char* inColor,
394 int stageIndex) { 393 int stageIndex) {
395 GrDrawEffect drawEffect(stage, false); 394 GrDrawEffect drawEffect(stage, false);
396 const GrEffect* effect = stage.getEffect(); 395 const GrEffect* effect = stage.getEffect();
397 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); 396 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
398 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); 397 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
399 398
400 SkASSERT(0 == stage.getVertexAttribIndexCount()); 399 SkASSERT(0 == stage.getVertexAttribIndexCount());
401 this->setupPathTexGen(builder, effect, key, &coords); 400 this->setupPathTexGen(builder, drawEffect, &coords);
402 this->emitSamplers(builder, effect, &samplers); 401 this->emitSamplers(builder, effect, &samplers);
403 402
404 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); 403 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
405 fGLEffects.push_back(glEffect); 404 fGLEffects.push_back(glEffect);
406 405
407 // Enclose custom code in a block to avoid namespace conflicts 406 // Enclose custom code in a block to avoid namespace conflicts
408 SkString openBrace; 407 SkString openBrace;
409 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); 408 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
410 builder->fsCodeAppend(openBrace.c_str()); 409 builder->fsCodeAppend(openBrace.c_str());
411 410
412 SkASSERT(!glEffect->isVertexEffect()); 411 SkASSERT(!glEffect->isVertexEffect());
413 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers); 412 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers);
414 413
415 builder->fsCodeAppend("\t}\n"); 414 builder->fsCodeAppend("\t}\n");
416 } 415 }
417 416
418 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder * builder, 417 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder * builder,
419 const GrEffect* effect, 418 const GrDrawEffect& drawEffect,
420 EffectKey effectKey,
421 TransformedCoordsArray* outCoords) { 419 TransformedCoordsArray* outCoords) {
422 int numTransforms = effect->numTransforms(); 420 int numTransforms = drawEffect.effect()->numTransforms();
423 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); 421 EffectKey totalKey = GenTransformKey(drawEffect);
424 int texCoordIndex = builder->addTexCoordSets(numTransforms); 422 int texCoordIndex = builder->addTexCoordSets(numTransforms);
425 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); 423 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex));
426 SkString name; 424 SkString name;
427 for (int t = 0; t < numTransforms; ++t) { 425 for (int t = 0; t < numTransforms; ++t) {
428 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? 426 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ?
429 kVec3f_GrSLType : 427 kVec3f_GrSLType :
430 kVec2f_GrSLType; 428 kVec2f_GrSLType;
431 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); 429 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++);
432 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); 430 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
433 } 431 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 481 }
484 482
485 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 483 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
486 GrGLProgramEffects::EffectK ey key, 484 GrGLProgramEffects::EffectK ey key,
487 const char* outColor, 485 const char* outColor,
488 const char* inColor, 486 const char* inColor,
489 int stageIndex) { 487 int stageIndex) {
490 SkASSERT(NULL != fProgramEffects.get()); 488 SkASSERT(NULL != fProgramEffects.get());
491 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 489 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
492 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698