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

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

Issue 212753002: Use fixed function pipeline only when drawing paths (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 8 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/GrGLProgramEffects.h ('k') | src/gpu/gl/GrGLShaderBuilder.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 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 GrGLProgramEffects::EffectKey k ey, 462 GrGLProgramEffects::EffectKey k ey,
463 const char* outColor, 463 const char* outColor,
464 const char* inColor, 464 const char* inColor,
465 int stageIndex) { 465 int stageIndex) {
466 SkASSERT(NULL != fProgramEffects.get()); 466 SkASSERT(NULL != fProgramEffects.get());
467 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 467 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
468 } 468 }
469 469
470 //////////////////////////////////////////////////////////////////////////////// 470 ////////////////////////////////////////////////////////////////////////////////
471 471
472 void GrGLTexGenProgramEffects::emitEffect(GrGLFragmentOnlyShaderBuilder* builder , 472 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyShaderBuilder* bui lder,
473 const GrEffectStage& stage, 473 const GrEffectStage& stage,
474 EffectKey key, 474 EffectKey key,
475 const char* outColor, 475 const char* outColor,
476 const char* inColor, 476 const char* inColor,
477 int stageIndex) { 477 int stageIndex) {
478 GrDrawEffect drawEffect(stage, false); 478 GrDrawEffect drawEffect(stage, false);
479 const GrEffectRef& effect = *stage.getEffect(); 479 const GrEffectRef& effect = *stage.getEffect();
480 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); 480 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
481 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); 481 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
482 482
483 SkASSERT(0 == stage.getVertexAttribIndexCount()); 483 SkASSERT(0 == stage.getVertexAttribIndexCount());
484 this->setupTexGen(builder, effect, key, &coords); 484 this->setupPathTexGen(builder, effect, key, &coords);
485 this->emitSamplers(builder, effect, &samplers); 485 this->emitSamplers(builder, effect, &samplers);
486 486
487 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); 487 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
488 fGLEffects.push_back(glEffect); 488 fGLEffects.push_back(glEffect);
489 489
490 // Enclose custom code in a block to avoid namespace conflicts 490 // Enclose custom code in a block to avoid namespace conflicts
491 SkString openBrace; 491 SkString openBrace;
492 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); 492 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
493 builder->fsCodeAppend(openBrace.c_str()); 493 builder->fsCodeAppend(openBrace.c_str());
494 494
495 SkASSERT(!glEffect->isVertexEffect()); 495 SkASSERT(!glEffect->isVertexEffect());
496 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers); 496 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers);
497 497
498 builder->fsCodeAppend("\t}\n"); 498 builder->fsCodeAppend("\t}\n");
499 } 499 }
500 500
501 void GrGLTexGenProgramEffects::setupTexGen(GrGLFragmentOnlyShaderBuilder* builde r, 501 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder * builder,
502 const GrEffectRef& effect, 502 const GrEffectRef& effect,
503 EffectKey effectKey, 503 EffectKey effectKey,
504 TransformedCoordsArray* outCoords) { 504 TransformedCoordsArray* outCoords) {
505 int numTransforms = effect->numTransforms(); 505 int numTransforms = effect->numTransforms();
506 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); 506 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey);
507 int texCoordIndex = builder->addTexCoordSets(numTransforms); 507 int texCoordIndex = builder->addTexCoordSets(numTransforms);
508 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); 508 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex));
509 SkString name; 509 SkString name;
510 for (int t = 0; t < numTransforms; ++t) { 510 for (int t = 0; t < numTransforms; ++t) {
511 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? 511 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ?
512 kVec3f_GrSLType : 512 kVec3f_GrSLType :
513 kVec2f_GrSLType; 513 kVec2f_GrSLType;
514 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); 514 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++);
515 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); 515 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
516 } 516 }
517 } 517 }
518 518
519 void GrGLTexGenProgramEffects::setData(GrGpuGL* gpu, 519 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu,
520 const GrGLUniformManager& uniformManager, 520 const GrGLUniformManager& uniformManager,
521 const GrEffectStage* effectStages[]) { 521 const GrEffectStage* effectStages[]) {
522 int numEffects = fGLEffects.count(); 522 int numEffects = fGLEffects.count();
523 SkASSERT(numEffects == fTransforms.count()); 523 SkASSERT(numEffects == fTransforms.count());
524 SkASSERT(numEffects == fSamplers.count()); 524 SkASSERT(numEffects == fSamplers.count());
525 for (int e = 0; e < numEffects; ++e) { 525 for (int e = 0; e < numEffects; ++e) {
526 GrDrawEffect drawEffect(*effectStages[e], false); 526 GrDrawEffect drawEffect(*effectStages[e], false);
527 fGLEffects[e]->setData(uniformManager, drawEffect); 527 fGLEffects[e]->setData(uniformManager, drawEffect);
528 this->setTexGenState(gpu, drawEffect, e); 528 this->setPathTexGenState(gpu, drawEffect, e);
529 this->bindTextures(gpu, *drawEffect.effect(), e); 529 this->bindTextures(gpu, *drawEffect.effect(), e);
530 } 530 }
531 } 531 }
532 532
533 void GrGLTexGenProgramEffects::setTexGenState(GrGpuGL* gpu, 533 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
534 const GrDrawEffect& drawEffect, 534 const GrDrawEffect& drawEffect,
535 int effectIdx) { 535 int effectIdx) {
536 EffectKey totalKey = fTransforms[effectIdx].fTransformKey; 536 EffectKey totalKey = fTransforms[effectIdx].fTransformKey;
537 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; 537 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
538 int numTransforms = (*drawEffect.effect())->numTransforms(); 538 int numTransforms = (*drawEffect.effect())->numTransforms();
539 for (int t = 0; t < numTransforms; ++t) { 539 for (int t = 0; t < numTransforms; ++t) {
540 switch (get_matrix_type(totalKey, t)) { 540 switch (get_matrix_type(totalKey, t)) {
541 case kIdentity_MatrixType: { 541 case kIdentity_MatrixType: {
542 SkASSERT(get_transform_matrix(drawEffect, t).isIdentity()); 542 SkASSERT(get_transform_matrix(drawEffect, t).isIdentity());
543 GrGLfloat identity[] = {1, 0, 0, 543 GrGLfloat identity[] = {1, 0, 0,
544 0, 1, 0}; 544 0, 1, 0};
545 gpu->enableTexGen(texCoordIndex++, GrGpuGL::kST_TexGenComponents , identity); 545 gpu->enablePathTexGen(texCoordIndex++,
546 GrGpuGL::kST_PathTexGenComponents,
547 identity);
546 break; 548 break;
547 } 549 }
548 case kTrans_MatrixType: { 550 case kTrans_MatrixType: {
549 GrGLfloat tx, ty; 551 GrGLfloat tx, ty;
550 get_transform_translation(drawEffect, t, &tx, &ty); 552 get_transform_translation(drawEffect, t, &tx, &ty);
551 GrGLfloat translate[] = {1, 0, tx, 553 GrGLfloat translate[] = {1, 0, tx,
552 0, 1, ty}; 554 0, 1, ty};
553 gpu->enableTexGen(texCoordIndex++, GrGpuGL::kST_TexGenComponents , translate); 555 gpu->enablePathTexGen(texCoordIndex++,
556 GrGpuGL::kST_PathTexGenComponents,
557 translate);
554 break; 558 break;
555 } 559 }
556 case kNoPersp_MatrixType: { 560 case kNoPersp_MatrixType: {
557 const SkMatrix& transform = get_transform_matrix(drawEffect, t); 561 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
558 gpu->enableTexGen(texCoordIndex++, GrGpuGL::kST_TexGenComponents , transform); 562 gpu->enablePathTexGen(texCoordIndex++,
563 GrGpuGL::kST_PathTexGenComponents,
564 transform);
559 break; 565 break;
560 } 566 }
561 case kGeneral_MatrixType: { 567 case kGeneral_MatrixType: {
562 const SkMatrix& transform = get_transform_matrix(drawEffect, t); 568 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
563 gpu->enableTexGen(texCoordIndex++, GrGpuGL::kSTR_TexGenComponent s, transform); 569 gpu->enablePathTexGen(texCoordIndex++,
570 GrGpuGL::kSTR_PathTexGenComponents,
571 transform);
564 break; 572 break;
565 } 573 }
566 default: 574 default:
567 GrCrash("Unexpected matrixs type."); 575 GrCrash("Unexpected matrixs type.");
568 } 576 }
569 } 577 }
570 } 578 }
571 579
572 GrGLTexGenProgramEffectsBuilder::GrGLTexGenProgramEffectsBuilder( 580 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder(
573 GrGLFragmentOnlyShaderBuilder* builder, 581 GrGLFragmentOnlyShaderBuilder* builder,
574 int reserveCount) 582 int reserveCount)
575 : fBuilder(builder) 583 : fBuilder(builder)
576 , fProgramEffects(SkNEW_ARGS(GrGLTexGenProgramEffects, (reserveCount))) { 584 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount))) {
577 } 585 }
578 586
579 void GrGLTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 587 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
580 GrGLProgramEffects::EffectKey k ey, 588 GrGLProgramEffects::EffectK ey key,
581 const char* outColor, 589 const char* outColor,
582 const char* inColor, 590 const char* inColor,
583 int stageIndex) { 591 int stageIndex) {
584 SkASSERT(NULL != fProgramEffects.get()); 592 SkASSERT(NULL != fProgramEffects.get());
585 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 593 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
586 } 594 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.h ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698