| OLD | NEW |
| 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" |
| 11 #include "gl/GrGLPathRendering.h" |
| 11 #include "gl/GrGLShaderBuilder.h" | 12 #include "gl/GrGLShaderBuilder.h" |
| 12 #include "gl/GrGLVertexEffect.h" | 13 #include "gl/GrGLVertexEffect.h" |
| 13 #include "gl/GrGpuGL.h" | 14 #include "gl/GrGpuGL.h" |
| 14 | 15 |
| 15 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; | 16 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; |
| 16 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 17 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
| 17 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 18 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
| 18 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; | 19 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; |
| 19 | 20 |
| 20 /** | 21 /** |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, | 303 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, |
| 303 const GrDrawEffect& drawEffect, | 304 const GrDrawEffect& drawEffect, |
| 304 TransformedCoordsArray* outCoords)
{ | 305 TransformedCoordsArray* outCoords)
{ |
| 305 SkTArray<Transform, true>& transforms = fTransforms.push_back(); | 306 SkTArray<Transform, true>& transforms = fTransforms.push_back(); |
| 306 uint32_t totalKey = GenTransformKey(drawEffect); | 307 uint32_t totalKey = GenTransformKey(drawEffect); |
| 307 int numTransforms = drawEffect.effect()->numTransforms(); | 308 int numTransforms = drawEffect.effect()->numTransforms(); |
| 308 transforms.push_back_n(numTransforms); | 309 transforms.push_back_n(numTransforms); |
| 310 |
| 311 SkTArray<PathTransform, true>* pathTransforms = NULL; |
| 312 const GrGLCaps* glCaps = builder->ctxInfo().caps(); |
| 313 if (glCaps->pathRenderingSupport() && |
| 314 builder->gpu()->pathRendering()->caps().fragmentInputGenSupport) { |
| 315 pathTransforms = &fPathTransforms.push_back(); |
| 316 pathTransforms->push_back_n(numTransforms); |
| 317 } |
| 318 |
| 309 for (int t = 0; t < numTransforms; t++) { | 319 for (int t = 0; t < numTransforms; t++) { |
| 310 GrSLType varyingType = kVoid_GrSLType; | 320 GrSLType varyingType = kVoid_GrSLType; |
| 311 const char* uniName; | 321 const char* uniName; |
| 312 switch (get_matrix_type(totalKey, t)) { | 322 switch (get_matrix_type(totalKey, t)) { |
| 313 case kNoPersp_MatrixType: | 323 case kNoPersp_MatrixType: |
| 314 uniName = "StageMatrix"; | 324 uniName = "StageMatrix"; |
| 315 varyingType = kVec2f_GrSLType; | 325 varyingType = kVec2f_GrSLType; |
| 316 break; | 326 break; |
| 317 case kGeneral_MatrixType: | 327 case kGeneral_MatrixType: |
| 318 uniName = "StageMatrix"; | 328 uniName = "StageMatrix"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 334 | 344 |
| 335 const char* varyingName = "MatrixCoord"; | 345 const char* varyingName = "MatrixCoord"; |
| 336 SkString suffixedVaryingName; | 346 SkString suffixedVaryingName; |
| 337 if (0 != t) { | 347 if (0 != t) { |
| 338 suffixedVaryingName.append(varyingName); | 348 suffixedVaryingName.append(varyingName); |
| 339 suffixedVaryingName.appendf("_%i", t); | 349 suffixedVaryingName.appendf("_%i", t); |
| 340 varyingName = suffixedVaryingName.c_str(); | 350 varyingName = suffixedVaryingName.c_str(); |
| 341 } | 351 } |
| 342 const char* vsVaryingName; | 352 const char* vsVaryingName; |
| 343 const char* fsVaryingName; | 353 const char* fsVaryingName; |
| 344 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVarying
Name); | 354 |
| 355 if (pathTransforms) { |
| 356 (*pathTransforms)[t].fHandle = |
| 357 builder->addSeparableVarying(varyingType, varyingName, &vsVaryin
gName, &fsVaryingName); |
| 358 (*pathTransforms)[t].fType = varyingType; |
| 359 } else { |
| 360 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVar
yingName); |
| 361 } |
| 362 |
| 345 | 363 |
| 346 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords(
totalKey, t) ? | 364 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords(
totalKey, t) ? |
| 347 builder->positionAttribute() : | 365 builder->positionAttribute() : |
| 348 builder->localCoordsAttribute(); | 366 builder->localCoordsAttribute(); |
| 349 // varying = matrix * coords (logically) | 367 // varying = matrix * coords (logically) |
| 350 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); | 368 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); |
| 351 if (kVec2f_GrSLType == varyingType) { | 369 if (kVec2f_GrSLType == varyingType) { |
| 352 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", | 370 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", |
| 353 vsVaryingName, uniName, coords.c_str()); | 371 vsVaryingName, uniName, coords.c_str()); |
| 354 } else { | 372 } else { |
| 355 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", | 373 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", |
| 356 vsVaryingName, uniName, coords.c_str()); | 374 vsVaryingName, uniName, coords.c_str()); |
| 357 } | 375 } |
| 358 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, | 376 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, |
| 359 (SkString(fsVaryingName), varyingType)); | 377 (SkString(fsVaryingName), varyingType)); |
| 360 } | 378 } |
| 361 } | 379 } |
| 362 | 380 |
| 363 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 381 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
| 364 const GrGLProgramDataManager& programReso
urceManager, | 382 GrGpu::DrawType drawType, |
| 383 const GrGLProgramDataManager& programData
Manager, |
| 365 const GrEffectStage* effectStages[]) { | 384 const GrEffectStage* effectStages[]) { |
| 366 int numEffects = fGLEffects.count(); | 385 int numEffects = fGLEffects.count(); |
| 367 SkASSERT(numEffects == fTransforms.count()); | 386 SkASSERT(numEffects == fTransforms.count()); |
| 368 SkASSERT(numEffects == fSamplers.count()); | 387 SkASSERT(numEffects == fSamplers.count()); |
| 369 for (int e = 0; e < numEffects; ++e) { | 388 for (int e = 0; e < numEffects; ++e) { |
| 370 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); | 389 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); |
| 371 fGLEffects[e]->setData(programResourceManager, drawEffect); | 390 fGLEffects[e]->setData(programDataManager, drawEffect); |
| 372 this->setTransformData(programResourceManager, drawEffect, e); | 391 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
| 392 this->setPathTransformData(gpu, programDataManager, drawEffect, e); |
| 393 } else { |
| 394 this->setTransformData(gpu, programDataManager, drawEffect, e); |
| 395 } |
| 396 |
| 373 this->bindTextures(gpu, drawEffect.effect(), e); | 397 this->bindTextures(gpu, drawEffect.effect(), e); |
| 374 } | 398 } |
| 375 } | 399 } |
| 376 | 400 |
| 377 void GrGLVertexProgramEffects::setTransformData(const GrGLProgramDataManager& pr
ogramResourceManager, | 401 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, |
| 402 const GrGLProgramDataManager& pd
man, |
| 378 const GrDrawEffect& drawEffect, | 403 const GrDrawEffect& drawEffect, |
| 379 int effectIdx) { | 404 int effectIdx) { |
| 380 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 405 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
| 381 int numTransforms = transforms.count(); | 406 int numTransforms = transforms.count(); |
| 382 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); | 407 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); |
| 383 for (int t = 0; t < numTransforms; ++t) { | 408 for (int t = 0; t < numTransforms; ++t) { |
| 384 SkASSERT(transforms[t].fHandle.isValid()); | 409 SkASSERT(transforms[t].fHandle.isValid()); |
| 385 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); | 410 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); |
| 386 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 411 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| 387 programResourceManager.setSkMatrix(transforms[t].fHandle, matrix); | 412 pdman.setSkMatrix(transforms[t].fHandle, matrix); |
| 388 transforms[t].fCurrentValue = matrix; | 413 transforms[t].fCurrentValue = matrix; |
| 389 } | 414 } |
| 390 } | 415 } |
| 391 } | 416 } |
| 392 | 417 |
| 418 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, |
| 419 const GrGLProgramDataManager
& pdman, |
| 420 const GrDrawEffect& drawEffe
ct, |
| 421 int effectIdx) { |
| 422 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; |
| 423 int numTransforms = transforms.count(); |
| 424 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); |
| 425 for (int t = 0; t < numTransforms; ++t) { |
| 426 SkASSERT(transforms[t].fHandle.isValid()); |
| 427 const SkMatrix& transform = get_transform_matrix(drawEffect, t); |
| 428 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) |
| 429 continue; |
| 430 transforms[t].fCurrentValue = transform; |
| 431 switch (transforms[t].fType) { |
| 432 case kVec2f_GrSLType: { |
| 433 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 2, transform); |
| 434 break; |
| 435 } |
| 436 case kVec3f_GrSLType: { |
| 437 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 3, transform); |
| 438 break; |
| 439 } |
| 440 default: |
| 441 SkFAIL("Unexpected matrixs type."); |
| 442 } |
| 443 } |
| 444 } |
| 445 |
| 393 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB
uilder* builder, | 446 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB
uilder* builder, |
| 394 int reserveCoun
t) | 447 int reserveCoun
t) |
| 395 : fBuilder(builder) | 448 : fBuilder(builder) |
| 396 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, | 449 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, |
| 397 (reserveCount, fBuilder->hasExplicitLocalCoords
()))) { | 450 (reserveCount, fBuilder->hasExplicitLocalCoords
()))) { |
| 398 } | 451 } |
| 399 | 452 |
| 400 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 453 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
| 401 const GrEffectKey& key, | 454 const GrEffectKey& key, |
| 402 const char* outColor, | 455 const char* outColor, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 for (int t = 0; t < numTransforms; ++t) { | 501 for (int t = 0; t < numTransforms; ++t) { |
| 449 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? | 502 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? |
| 450 kVec3f_GrSLType : | 503 kVec3f_GrSLType : |
| 451 kVec2f_GrSLType; | 504 kVec2f_GrSLType; |
| 452 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); | 505 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); |
| 453 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); | 506 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); |
| 454 } | 507 } |
| 455 } | 508 } |
| 456 | 509 |
| 457 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 510 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
| 458 const GrGLProgramDataManager& programReso
urceManager, | 511 GrGpu::DrawType, |
| 459 const GrEffectStage* effectStages[]) { | 512 const GrGLProgramDataManager& pdman, |
| 513 const GrEffectStage* effectStages[])
{ |
| 460 int numEffects = fGLEffects.count(); | 514 int numEffects = fGLEffects.count(); |
| 461 SkASSERT(numEffects == fTransforms.count()); | 515 SkASSERT(numEffects == fTransforms.count()); |
| 462 SkASSERT(numEffects == fSamplers.count()); | 516 SkASSERT(numEffects == fSamplers.count()); |
| 463 for (int e = 0; e < numEffects; ++e) { | 517 for (int e = 0; e < numEffects; ++e) { |
| 464 GrDrawEffect drawEffect(*effectStages[e], false); | 518 GrDrawEffect drawEffect(*effectStages[e], false); |
| 465 fGLEffects[e]->setData(programResourceManager, drawEffect); | 519 fGLEffects[e]->setData(pdman, drawEffect); |
| 466 this->setPathTexGenState(gpu, drawEffect, e); | 520 this->setPathTexGenState(gpu, drawEffect, e); |
| 467 this->bindTextures(gpu, drawEffect.effect(), e); | 521 this->bindTextures(gpu, drawEffect.effect(), e); |
| 468 } | 522 } |
| 469 } | 523 } |
| 470 | 524 |
| 471 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, | 525 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, |
| 472 const GrDrawEffect& drawEffect, | 526 const GrDrawEffect& drawEffect, |
| 473 int effectIdx) { | 527 int effectIdx) { |
| 474 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; | 528 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; |
| 475 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; | 529 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 504 } | 558 } |
| 505 | 559 |
| 506 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 560 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
| 507 const GrEffectKey& key, | 561 const GrEffectKey& key, |
| 508 const char* outColor, | 562 const char* outColor, |
| 509 const char* inColor, | 563 const char* inColor, |
| 510 int stageIndex) { | 564 int stageIndex) { |
| 511 SkASSERT(NULL != fProgramEffects.get()); | 565 SkASSERT(NULL != fProgramEffects.get()); |
| 512 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); | 566 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); |
| 513 } | 567 } |
| OLD | NEW |