Chromium Code Reviews| 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
| 9 | 9 |
| 10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: | 108 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: |
| 109 // We should only have set this if the blend was specified as (1, 0) | 109 // We should only have set this if the blend was specified as (1, 0) |
| 110 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); | 110 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); |
| 111 break; | 111 break; |
| 112 default: | 112 default: |
| 113 GrCrash("Unexpected coverage output"); | 113 GrCrash("Unexpected coverage output"); |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 namespace { | |
| 119 // given two blend coefficients determine whether the src | |
| 120 // and/or dst computation can be omitted. | |
| 121 inline void need_blend_inputs(SkXfermode::Coeff srcCoeff, | |
| 122 SkXfermode::Coeff dstCoeff, | |
| 123 bool* needSrcValue, | |
| 124 bool* needDstValue) { | |
| 125 if (SkXfermode::kZero_Coeff == srcCoeff) { | |
| 126 switch (dstCoeff) { | |
| 127 // these all read the src | |
| 128 case SkXfermode::kSC_Coeff: | |
| 129 case SkXfermode::kISC_Coeff: | |
| 130 case SkXfermode::kSA_Coeff: | |
| 131 case SkXfermode::kISA_Coeff: | |
| 132 *needSrcValue = true; | |
| 133 break; | |
| 134 default: | |
| 135 *needSrcValue = false; | |
| 136 break; | |
| 137 } | |
| 138 } else { | |
| 139 *needSrcValue = true; | |
| 140 } | |
| 141 if (SkXfermode::kZero_Coeff == dstCoeff) { | |
| 142 switch (srcCoeff) { | |
| 143 // these all read the dst | |
| 144 case SkXfermode::kDC_Coeff: | |
| 145 case SkXfermode::kIDC_Coeff: | |
| 146 case SkXfermode::kDA_Coeff: | |
| 147 case SkXfermode::kIDA_Coeff: | |
| 148 *needDstValue = true; | |
| 149 break; | |
| 150 default: | |
| 151 *needDstValue = false; | |
| 152 break; | |
| 153 } | |
| 154 } else { | |
| 155 *needDstValue = true; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 /** | |
| 160 * Create a blend_coeff * value string to be used in shader code. Sets empty | |
| 161 * string if result is trivially zero. | |
| 162 */ | |
| 163 inline void blend_term_string(SkString* str, SkXfermode::Coeff coeff, | |
| 164 const char* src, const char* dst, | |
| 165 const char* value) { | |
| 166 switch (coeff) { | |
| 167 case SkXfermode::kZero_Coeff: /** 0 */ | |
| 168 *str = ""; | |
| 169 break; | |
| 170 case SkXfermode::kOne_Coeff: /** 1 */ | |
| 171 *str = value; | |
| 172 break; | |
| 173 case SkXfermode::kSC_Coeff: | |
| 174 str->printf("(%s * %s)", src, value); | |
| 175 break; | |
| 176 case SkXfermode::kISC_Coeff: | |
| 177 str->printf("((%s - %s) * %s)", GrGLSLExpr<4>::onesStr(), src, value); | |
| 178 break; | |
| 179 case SkXfermode::kDC_Coeff: | |
| 180 str->printf("(%s * %s)", dst, value); | |
| 181 break; | |
| 182 case SkXfermode::kIDC_Coeff: | |
| 183 str->printf("((%s - %s) * %s)", GrGLSLExpr<4>::onesStr(), dst, value); | |
| 184 break; | |
| 185 case SkXfermode::kSA_Coeff: /** src alpha */ | |
| 186 str->printf("(%s.a * %s)", src, value); | |
| 187 break; | |
| 188 case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */ | |
| 189 str->printf("((1.0 - %s.a) * %s)", src, value); | |
| 190 break; | |
| 191 case SkXfermode::kDA_Coeff: /** dst alpha */ | |
| 192 str->printf("(%s.a * %s)", dst, value); | |
| 193 break; | |
| 194 case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */ | |
| 195 str->printf("((1.0 - %s.a) * %s)", dst, value); | |
| 196 break; | |
| 197 default: | |
| 198 GrCrash("Unexpected xfer coeff."); | |
| 199 break; | |
| 200 } | |
| 201 } | |
| 202 /** | |
| 203 * Adds a line to the fragment shader code which modifies the color by | |
| 204 * the specified color filter. | |
| 205 */ | |
| 206 void add_color_filter(GrGLShaderBuilder* builder, | |
| 207 const char * outputVar, | |
| 208 SkXfermode::Coeff uniformCoeff, | |
| 209 SkXfermode::Coeff colorCoeff, | |
| 210 const char* filterColor, | |
| 211 const char* inColor) { | |
| 212 SkString colorStr, constStr; | |
| 213 blend_term_string(&colorStr, colorCoeff, filterColor, inColor, inColor); | |
| 214 blend_term_string(&constStr, uniformCoeff, filterColor, inColor, filterColor ); | |
| 215 SkASSERT(!(colorStr.isEmpty() && constStr.isEmpty())); | |
| 216 | |
| 217 GrGLSLExpr<4> result; | |
| 218 if (colorStr.isEmpty()) { | |
| 219 result = constStr; | |
| 220 } else if (constStr.isEmpty()) { | |
| 221 result = colorStr; | |
| 222 } else { | |
| 223 result = GrGLSLAddf<4,4>(colorStr, constStr); | |
| 224 } | |
| 225 | |
| 226 builder->fsCodeAppendf("\t%s = %s;\n", outputVar, result.c_str()); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 GrGLSLExpr<4> GrGLProgram::genInputColor(GrGLShaderBuilder* builder) { | 118 GrGLSLExpr<4> GrGLProgram::genInputColor(GrGLShaderBuilder* builder) { |
| 231 switch (fDesc.getHeader().fColorInput) { | 119 switch (fDesc.getHeader().fColorInput) { |
| 232 case GrGLProgramDesc::kAttribute_ColorInput: { | 120 case GrGLProgramDesc::kAttribute_ColorInput: { |
| 233 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder(); | 121 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder(); |
| 234 SkASSERT(NULL != vertexBuilder); | 122 SkASSERT(NULL != vertexBuilder); |
| 235 vertexBuilder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); | 123 vertexBuilder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); |
| 236 const char *vsName, *fsName; | 124 const char *vsName, *fsName; |
| 237 vertexBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName ); | 125 vertexBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName ); |
| 238 vertexBuilder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); | 126 vertexBuilder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
| 239 return fsName; | 127 return fsName; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 return true; | 303 return true; |
| 416 } | 304 } |
| 417 | 305 |
| 418 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], | 306 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], |
| 419 const GrEffectStage* coverageStages[]) { | 307 const GrEffectStage* coverageStages[]) { |
| 420 SkASSERT(0 == fProgramID); | 308 SkASSERT(0 == fProgramID); |
| 421 | 309 |
| 422 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 310 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 423 bool hasExplicitLocalCoords = -1 != header.fLocalCoordAttributeIndex; | 311 bool hasExplicitLocalCoords = -1 != header.fLocalCoordAttributeIndex; |
| 424 | 312 |
| 425 // Get the coeffs for the Mode-based color filter, determine if color is nee ded. | |
| 426 SkXfermode::Coeff colorCoeff; | |
| 427 SkXfermode::Coeff filterColorCoeff; | |
| 428 SkAssertResult( | |
| 429 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte rXfermode), | |
| 430 &filterColorCoeff, | |
| 431 &colorCoeff)); | |
| 432 bool needColor, needFilterColor; | |
| 433 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor ); | |
| 434 | |
| 435 // Create the GL effects. | 313 // Create the GL effects. |
| 436 bool hasVertexShaderEffects = false; | 314 bool hasVertexShaderEffects = false; |
| 437 | 315 bool willUseInputColor = false; |
| 438 SkTArray<GrDrawEffect> colorDrawEffects(needColor ? fDesc.numColorEffects() : 0); | 316 SkTArray<GrDrawEffect> colorDrawEffects(fDesc.numColorEffects()); |
| 439 if (needColor) { | 317 if (fDesc.numColorEffects() > 0) { |
| 440 this->buildGLEffects(&GrGLProgram::fColorEffects, colorStages, fDesc.num ColorEffects(), | 318 this->buildGLEffects(&GrGLProgram::fColorEffects, colorStages, fDesc.num ColorEffects(), |
| 441 hasExplicitLocalCoords, &colorDrawEffects, &hasVert exShaderEffects); | 319 hasExplicitLocalCoords, &colorDrawEffects, &hasVert exShaderEffects, &willUseInputColor); |
| 442 } | 320 } |
| 443 | 321 |
| 444 SkTArray<GrDrawEffect> coverageDrawEffects(fDesc.numCoverageEffects()); | 322 SkTArray<GrDrawEffect> coverageDrawEffects(fDesc.numCoverageEffects()); |
| 445 this->buildGLEffects(&GrGLProgram::fCoverageEffects, coverageStages, fDesc.n umCoverageEffects(), | 323 this->buildGLEffects(&GrGLProgram::fCoverageEffects, coverageStages, fDesc.n umCoverageEffects(), |
| 446 hasExplicitLocalCoords, &coverageDrawEffects, &hasVerte xShaderEffects); | 324 hasExplicitLocalCoords, &coverageDrawEffects, &hasVerte xShaderEffects, &willUseInputColor); |
| 447 | 325 |
| 448 GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, hasVertex ShaderEffects); | 326 GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, hasVertex ShaderEffects); |
| 449 | 327 |
| 450 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild er()) { | 328 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild er()) { |
| 451 const char* viewMName; | 329 const char* viewMName; |
| 452 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::k Vertex_Visibility, | 330 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::k Vertex_Visibility, |
| 453 kMat33f_GrSLType, "V iewM", &viewMName); | 331 kMat33f_GrSLType, "V iewM", &viewMName); |
| 454 | 332 |
| 455 vertexBuilder->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" | 333 vertexBuilder->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" |
| 456 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\ n", | 334 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\ n", |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 472 | 350 |
| 473 GrGLShaderVar colorOutput; | 351 GrGLShaderVar colorOutput; |
| 474 bool isColorDeclared = GrGLSLSetupFSColorOuput(fGpu->glslGeneration(), | 352 bool isColorDeclared = GrGLSLSetupFSColorOuput(fGpu->glslGeneration(), |
| 475 declared_color_output_name(), | 353 declared_color_output_name(), |
| 476 &colorOutput); | 354 &colorOutput); |
| 477 if (isColorDeclared) { | 355 if (isColorDeclared) { |
| 478 builder.fsOutputAppend(colorOutput); | 356 builder.fsOutputAppend(colorOutput); |
| 479 } | 357 } |
| 480 | 358 |
| 481 // incoming color to current stage being processed. | 359 // incoming color to current stage being processed. |
| 482 GrGLSLExpr<4> inColor = this->genInputColor(&builder); | 360 GrGLSLExpr<4> inColor; |
| 361 if (willUseInputColor || (0 == fDesc.numColorEffects() && 0 == fDesc.numCove rageEffects())) { | |
| 362 inColor = this->genInputColor(&builder); | |
| 363 } else { | |
| 364 inColor = GrGLSLExpr<4>::Ones(); | |
| 365 } | |
| 483 | 366 |
| 484 // used in order for builder to return the per-stage uniform handles. | 367 // used in order for builder to return the per-stage uniform handles. |
| 485 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr ; | 368 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr ; |
| 486 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag eEffects()); | 369 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag eEffects()); |
| 487 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); | 370 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); |
| 488 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); | 371 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); |
| 489 | 372 |
| 490 if (needColor) { | 373 if (fDesc.numColorEffects()) { |
| 491 for (int e = 0; e < fDesc.numColorEffects(); ++e) { | 374 for (int e = 0; e < fDesc.numColorEffects(); ++e) { |
| 492 glEffects[e] = fColorEffects[e].fGLEffect; | 375 glEffects[e] = fColorEffects[e].fGLEffect; |
| 493 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; | 376 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; |
| 494 } | 377 } |
| 495 | 378 |
| 496 builder.emitEffects(glEffects.get(), | 379 builder.emitEffects(glEffects.get(), |
| 497 colorDrawEffects.begin(), | 380 colorDrawEffects.begin(), |
| 498 fDesc.effectKeys(), | 381 fDesc.effectKeys(), |
| 499 fDesc.numColorEffects(), | 382 fDesc.numColorEffects(), |
| 500 &inColor, | 383 &inColor, |
| 501 effectUniformArrays.get()); | 384 effectUniformArrays.get()); |
| 502 } | 385 } |
| 503 | 386 |
| 504 // Insert the color filter. This will soon be replaced by a color effect. | |
| 505 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { | |
| 506 const char* colorFilterColorUniName = NULL; | |
| 507 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_Visibility, | |
| 508 kVec4f_GrSLType, "F ilterColor", | |
| 509 &colorFilterColorUn iName); | |
| 510 | |
| 511 builder.fsCodeAppend("\tvec4 filteredColor;\n"); | |
| 512 | |
| 513 add_color_filter(&builder, "filteredColor", filterColorCoeff, | |
| 514 colorCoeff, colorFilterColorUniName, inColor.c_str()); | |
| 515 inColor = "filteredColor"; | |
| 516 } | |
| 517 | |
| 518 /////////////////////////////////////////////////////////////////////////// | 387 /////////////////////////////////////////////////////////////////////////// |
| 519 // compute the partial coverage | 388 // compute the partial coverage |
| 520 GrGLSLExpr<4> inCoverage = this->genInputCoverage(&builder); | 389 GrGLSLExpr<4> inCoverage = this->genInputCoverage(&builder); |
| 521 | 390 |
| 522 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { | 391 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { |
| 523 glEffects[e] = fCoverageEffects[e].fGLEffect; | 392 glEffects[e] = fCoverageEffects[e].fGLEffect; |
| 524 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; | 393 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; |
| 525 } | 394 } |
| 526 | 395 |
| 527 builder.emitEffects(glEffects.get(), | 396 builder.emitEffects(glEffects.get(), |
| 528 coverageDrawEffects.begin(), | 397 coverageDrawEffects.begin(), |
| 529 fDesc.getEffectKeys() + fDesc.numColorEffects(), | 398 fDesc.getEffectKeys() + fDesc.numColorEffects(), |
| 530 fDesc.numCoverageEffects(), | 399 fDesc.numCoverageEffects(), |
| 531 &inCoverage, | 400 &inCoverage, |
| 532 effectUniformArrays.get()); | 401 effectUniformArrays.get()); |
| 533 | 402 |
| 403 if (!inColor.isValid()) { | |
|
bsalomon
2013/09/27 13:59:39
What's this about?
| |
| 404 | |
| 405 } | |
| 406 | |
| 534 // discard if coverage is zero | 407 // discard if coverage is zero |
| 535 if (header.fDiscardIfZeroCoverage && !inCoverage.isOnes()) { | 408 if (header.fDiscardIfZeroCoverage && !inCoverage.isOnes()) { |
| 536 if (inCoverage.isZeros()) { | 409 if (inCoverage.isZeros()) { |
| 537 // This is unfortunate. | 410 // This is unfortunate. |
| 538 builder.fsCodeAppend("\tdiscard;\n"); | 411 builder.fsCodeAppend("\tdiscard;\n"); |
| 539 } else { | 412 } else { |
| 540 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", | 413 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", |
| 541 inCoverage.c_str()); | 414 inCoverage.c_str()); |
| 542 } | 415 } |
| 543 } | 416 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 this->initSamplerUniforms(); | 487 this->initSamplerUniforms(); |
| 615 | 488 |
| 616 return true; | 489 return true; |
| 617 } | 490 } |
| 618 | 491 |
| 619 void GrGLProgram::buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effe ctSet, | 492 void GrGLProgram::buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effe ctSet, |
| 620 const GrEffectStage* stages[], | 493 const GrEffectStage* stages[], |
| 621 int count, | 494 int count, |
| 622 bool hasExplicitLocalCoords, | 495 bool hasExplicitLocalCoords, |
| 623 SkTArray<GrDrawEffect>* drawEffects, | 496 SkTArray<GrDrawEffect>* drawEffects, |
| 624 bool* hasVertexShaderEffects) { | 497 bool* hasVertexShaderEffects, |
| 498 bool* willUseInputColor) { | |
| 625 for (int e = 0; e < count; ++e) { | 499 for (int e = 0; e < count; ++e) { |
| 626 SkASSERT(NULL != stages[e] && NULL != stages[e]->getEffect()); | 500 SkASSERT(NULL != stages[e] && NULL != stages[e]->getEffect()); |
| 627 | 501 |
| 628 const GrEffectStage& stage = *stages[e]; | 502 const GrEffectStage& stage = *stages[e]; |
| 629 SkNEW_APPEND_TO_TARRAY(drawEffects, GrDrawEffect, (stage, hasExplicitLoc alCoords)); | 503 SkNEW_APPEND_TO_TARRAY(drawEffects, GrDrawEffect, (stage, hasExplicitLoc alCoords)); |
| 630 | 504 |
| 631 const GrDrawEffect& drawEffect = (*drawEffects)[e]; | 505 const GrDrawEffect& drawEffect = (*drawEffects)[e]; |
| 632 GrGLEffect* effect = (this->*effectSet)[e].fGLEffect = | 506 GrGLEffect* effect = (this->*effectSet)[e].fGLEffect = |
| 633 (*stage.getEffect())->getFactory().createGLInstance(drawEffect); | 507 (*stage.getEffect())->getFactory().createGLInstance(drawEffect); |
| 634 | 508 |
| 635 if (!*hasVertexShaderEffects && effect->requiresVertexShader(drawEffect) ) { | 509 if (!*hasVertexShaderEffects && effect->requiresVertexShader(drawEffect) ) { |
| 636 *hasVertexShaderEffects = true; | 510 *hasVertexShaderEffects = true; |
| 637 } | 511 } |
| 638 } | 512 } |
| 513 | |
| 514 if (count > 0 && (*stages[0]->getEffect())->getWillUseInputColor()) { | |
| 515 *willUseInputColor = true; | |
| 516 } | |
| 639 } | 517 } |
| 640 | 518 |
| 641 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil der, | 519 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil der, |
| 642 bool bindColorOut, | 520 bool bindColorOut, |
| 643 bool bindDualSrcOut) { | 521 bool bindDualSrcOut) { |
| 644 GL_CALL_RET(fProgramID, CreateProgram()); | 522 GL_CALL_RET(fProgramID, CreateProgram()); |
| 645 if (!fProgramID) { | 523 if (!fProgramID) { |
| 646 return false; | 524 return false; |
| 647 } | 525 } |
| 648 | 526 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 coverage = drawState.getCoverage(); | 662 coverage = drawState.getCoverage(); |
| 785 } else { | 663 } else { |
| 786 color = drawState.getColor(); | 664 color = drawState.getColor(); |
| 787 coverage = drawState.getCoverage(); | 665 coverage = drawState.getCoverage(); |
| 788 } | 666 } |
| 789 | 667 |
| 790 this->setColor(drawState, color, sharedState); | 668 this->setColor(drawState, color, sharedState); |
| 791 this->setCoverage(drawState, coverage, sharedState); | 669 this->setCoverage(drawState, coverage, sharedState); |
| 792 this->setMatrixAndRenderTargetHeight(drawState); | 670 this->setMatrixAndRenderTargetHeight(drawState); |
| 793 | 671 |
| 794 // Setup the SkXfermode::Mode-based colorfilter uniform if necessary | |
| 795 if (fUniformHandles.fColorFilterUni.isValid() && | |
| 796 fColorFilterColor != drawState.getColorFilterColor()) { | |
| 797 GrGLfloat c[4]; | |
| 798 GrColorToRGBAFloat(drawState.getColorFilterColor(), c); | |
| 799 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); | |
| 800 fColorFilterColor = drawState.getColorFilterColor(); | |
| 801 } | |
| 802 | |
| 803 if (NULL != dstCopy) { | 672 if (NULL != dstCopy) { |
| 804 if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { | 673 if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| 805 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, | 674 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, |
| 806 static_cast<GrGLfloat>(dstCopy->offset().fX), | 675 static_cast<GrGLfloat>(dstCopy->offset().fX), |
| 807 static_cast<GrGLfloat>(dstCopy->offset().fY)); | 676 static_cast<GrGLfloat>(dstCopy->offset().fY)); |
| 808 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, | 677 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, |
| 809 1.f / dstCopy->texture()->width(), | 678 1.f / dstCopy->texture()->width(), |
| 810 1.f / dstCopy->texture()->height()); | 679 1.f / dstCopy->texture()->height()); |
| 811 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; | 680 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; |
| 812 static GrTextureParams kParams; // the default is clamp, nearest fil tering. | 681 static GrTextureParams kParams; // the default is clamp, nearest fil tering. |
| 813 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 682 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
| 814 } else { | 683 } else { |
| 815 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); | 684 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 816 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); | 685 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
| 817 } | 686 } |
| 818 } else { | 687 } else { |
| 819 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); | 688 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 820 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); | 689 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 821 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); | 690 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
| 822 } | 691 } |
| 823 | 692 |
| 824 for (int e = 0; e < fColorEffects.count(); ++e) { | 693 for (int e = 0; e < fColorEffects.count(); ++e) { |
| 825 // We may have omitted the GrGLEffect because of the color filter logic in genProgram. | 694 SkASSERT(NULL != fColorEffects[e].fGLEffect); |
| 826 // This can be removed when the color filter is an effect. | 695 this->setEffectData(*colorStages[e], fColorEffects[e]); |
| 827 if (NULL != fColorEffects[e].fGLEffect) { | |
| 828 this->setEffectData(*colorStages[e], fColorEffects[e]); | |
| 829 } | |
| 830 } | 696 } |
| 831 | 697 |
| 832 for (int e = 0; e < fCoverageEffects.count(); ++e) { | 698 for (int e = 0; e < fCoverageEffects.count(); ++e) { |
| 833 if (NULL != fCoverageEffects[e].fGLEffect) { | 699 SkASSERT(NULL != fCoverageEffects[e].fGLEffect); |
| 834 this->setEffectData(*coverageStages[e], fCoverageEffects[e]); | 700 this->setEffectData(*coverageStages[e], fCoverageEffects[e]); |
| 835 } | |
| 836 } | 701 } |
| 837 } | 702 } |
| 838 | 703 |
| 839 void GrGLProgram::setColor(const GrDrawState& drawState, | 704 void GrGLProgram::setColor(const GrDrawState& drawState, |
| 840 GrColor color, | 705 GrColor color, |
| 841 SharedGLState* sharedState) { | 706 SharedGLState* sharedState) { |
| 842 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 707 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 843 if (!drawState.hasColorVertexAttribute()) { | 708 if (!drawState.hasColorVertexAttribute()) { |
| 844 switch (header.fColorInput) { | 709 switch (header.fColorInput) { |
| 845 case GrGLProgramDesc::kAttribute_ColorInput: | 710 case GrGLProgramDesc::kAttribute_ColorInput: |
| 846 SkASSERT(-1 != header.fColorAttributeIndex); | 711 SkASSERT(-1 != header.fColorAttributeIndex); |
| 847 if (sharedState->fConstAttribColor != color || | 712 if (sharedState->fConstAttribColor != color || |
| 848 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { | 713 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { |
| 849 // OpenGL ES only supports the float varieties of glVertexAt trib | 714 // OpenGL ES only supports the float varieties of glVertexAt trib |
| 850 GrGLfloat c[4]; | 715 GrGLfloat c[4]; |
| 851 GrColorToRGBAFloat(color, c); | 716 GrColorToRGBAFloat(color, c); |
| 852 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 717 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
| 853 sharedState->fConstAttribColor = color; | 718 sharedState->fConstAttribColor = color; |
| 854 sharedState->fConstAttribColorIndex = header.fColorAttribute Index; | 719 sharedState->fConstAttribColorIndex = header.fColorAttribute Index; |
| 855 } | 720 } |
| 856 break; | 721 break; |
| 857 case GrGLProgramDesc::kUniform_ColorInput: | 722 case GrGLProgramDesc::kUniform_ColorInput: |
| 858 if (fColor != color) { | 723 if (fColor != color && fUniformHandles.fColorUni.isValid()) { |
| 859 // OpenGL ES doesn't support unsigned byte varieties of glUn iform | 724 // OpenGL ES doesn't support unsigned byte varieties of glUn iform |
| 860 GrGLfloat c[4]; | 725 GrGLfloat c[4]; |
| 861 GrColorToRGBAFloat(color, c); | 726 GrColorToRGBAFloat(color, c); |
| 862 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | 727 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |
| 863 fColor = color; | 728 fColor = color; |
| 864 } | 729 } |
| 865 sharedState->fConstAttribColorIndex = -1; | 730 sharedState->fConstAttribColorIndex = -1; |
| 866 break; | 731 break; |
| 867 case GrGLProgramDesc::kSolidWhite_ColorInput: | 732 case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 868 case GrGLProgramDesc::kTransBlack_ColorInput: | 733 case GrGLProgramDesc::kTransBlack_ColorInput: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 | 797 |
| 933 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 798 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 934 fMatrixState.fRenderTargetSize = size; | 799 fMatrixState.fRenderTargetSize = size; |
| 935 fMatrixState.fRenderTargetOrigin = rt->origin(); | 800 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 936 | 801 |
| 937 GrGLfloat viewMatrix[3 * 3]; | 802 GrGLfloat viewMatrix[3 * 3]; |
| 938 fMatrixState.getGLMatrix<3>(viewMatrix); | 803 fMatrixState.getGLMatrix<3>(viewMatrix); |
| 939 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); | 804 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
| 940 } | 805 } |
| 941 } | 806 } |
| OLD | NEW |