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

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

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: address review comments (rebase to separated patches) Created 6 years, 4 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.h » ('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"
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
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()->glPathRendering()->texturingMode() ==
315 GrGLPathRendering::SeparableShaders_TexturingMode) {
316 pathTransforms = &fPathTransforms.push_back();
317 pathTransforms->push_back_n(numTransforms);
318 }
319
309 for (int t = 0; t < numTransforms; t++) { 320 for (int t = 0; t < numTransforms; t++) {
310 GrSLType varyingType = kVoid_GrSLType; 321 GrSLType varyingType = kVoid_GrSLType;
311 const char* uniName; 322 const char* uniName;
312 switch (get_matrix_type(totalKey, t)) { 323 switch (get_matrix_type(totalKey, t)) {
313 case kNoPersp_MatrixType: 324 case kNoPersp_MatrixType:
314 uniName = "StageMatrix"; 325 uniName = "StageMatrix";
315 varyingType = kVec2f_GrSLType; 326 varyingType = kVec2f_GrSLType;
316 break; 327 break;
317 case kGeneral_MatrixType: 328 case kGeneral_MatrixType:
318 uniName = "StageMatrix"; 329 uniName = "StageMatrix";
(...skipping 15 matching lines...) Expand all
334 345
335 const char* varyingName = "MatrixCoord"; 346 const char* varyingName = "MatrixCoord";
336 SkString suffixedVaryingName; 347 SkString suffixedVaryingName;
337 if (0 != t) { 348 if (0 != t) {
338 suffixedVaryingName.append(varyingName); 349 suffixedVaryingName.append(varyingName);
339 suffixedVaryingName.appendf("_%i", t); 350 suffixedVaryingName.appendf("_%i", t);
340 varyingName = suffixedVaryingName.c_str(); 351 varyingName = suffixedVaryingName.c_str();
341 } 352 }
342 const char* vsVaryingName; 353 const char* vsVaryingName;
343 const char* fsVaryingName; 354 const char* fsVaryingName;
344 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVarying Name); 355
356 if (pathTransforms) {
357 (*pathTransforms)[t].fHandle =
358 builder->addSeparableVarying(varyingType, varyingName, &vsVaryin gName, &fsVaryingName);
359 (*pathTransforms)[t].fType = varyingType;
360 } else {
361 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVar yingName);
362 }
363
345 364
346 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ? 365 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ?
347 builder->positionAttribute() : 366 builder->positionAttribute() :
348 builder->localCoordsAttribute(); 367 builder->localCoordsAttribute();
349 // varying = matrix * coords (logically) 368 // varying = matrix * coords (logically)
350 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e); 369 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e);
351 if (kVec2f_GrSLType == varyingType) { 370 if (kVec2f_GrSLType == varyingType) {
352 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", 371 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n",
353 vsVaryingName, uniName, coords.c_str()); 372 vsVaryingName, uniName, coords.c_str());
354 } else { 373 } else {
355 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", 374 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n",
356 vsVaryingName, uniName, coords.c_str()); 375 vsVaryingName, uniName, coords.c_str());
357 } 376 }
358 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, 377 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords,
359 (SkString(fsVaryingName), varyingType)); 378 (SkString(fsVaryingName), varyingType));
360 } 379 }
361 } 380 }
362 381
363 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, 382 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu,
364 const GrGLProgramDataManager& programReso urceManager, 383 GrGpu::DrawType drawType,
384 const GrGLProgramDataManager& programData Manager,
365 const GrEffectStage* effectStages[]) { 385 const GrEffectStage* effectStages[]) {
366 int numEffects = fGLEffects.count(); 386 int numEffects = fGLEffects.count();
367 SkASSERT(numEffects == fTransforms.count()); 387 SkASSERT(numEffects == fTransforms.count());
368 SkASSERT(numEffects == fSamplers.count()); 388 SkASSERT(numEffects == fSamplers.count());
369 for (int e = 0; e < numEffects; ++e) { 389 for (int e = 0; e < numEffects; ++e) {
370 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); 390 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords);
371 fGLEffects[e]->setData(programResourceManager, drawEffect); 391 fGLEffects[e]->setData(programDataManager, drawEffect);
372 this->setTransformData(programResourceManager, drawEffect, e); 392 if (GrGpu::IsPathRenderingDrawType(drawType)) {
393 this->setPathTransformData(gpu, programDataManager, drawEffect, e);
394 } else {
395 this->setTransformData(gpu, programDataManager, drawEffect, e);
396 }
397
373 this->bindTextures(gpu, drawEffect.effect(), e); 398 this->bindTextures(gpu, drawEffect.effect(), e);
374 } 399 }
375 } 400 }
376 401
377 void GrGLVertexProgramEffects::setTransformData(const GrGLProgramDataManager& pr ogramResourceManager, 402 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu,
403 const GrGLProgramDataManager& pd man,
378 const GrDrawEffect& drawEffect, 404 const GrDrawEffect& drawEffect,
379 int effectIdx) { 405 int effectIdx) {
380 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; 406 SkTArray<Transform, true>& transforms = fTransforms[effectIdx];
381 int numTransforms = transforms.count(); 407 int numTransforms = transforms.count();
382 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); 408 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
383 for (int t = 0; t < numTransforms; ++t) { 409 for (int t = 0; t < numTransforms; ++t) {
384 SkASSERT(transforms[t].fHandle.isValid()); 410 SkASSERT(transforms[t].fHandle.isValid());
385 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); 411 const SkMatrix& matrix = get_transform_matrix(drawEffect, t);
386 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { 412 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
387 programResourceManager.setSkMatrix(transforms[t].fHandle, matrix); 413 pdman.setSkMatrix(transforms[t].fHandle, matrix);
388 transforms[t].fCurrentValue = matrix; 414 transforms[t].fCurrentValue = matrix;
389 } 415 }
390 } 416 }
391 } 417 }
392 418
419 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu,
420 const GrGLProgramDataManager & pdman,
421 const GrDrawEffect& drawEffe ct,
422 int effectIdx) {
423 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx];
424 int numTransforms = transforms.count();
425 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
426 for (int t = 0; t < numTransforms; ++t) {
427 SkASSERT(transforms[t].fHandle.isValid());
428 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
429 if (transforms[t].fCurrentValue.cheapEqualTo(transform))
bsalomon 2014/08/22 13:31:13 minor nit: we always use {} for if
Kimmo Kinnunen 2014/08/25 12:43:28 Done.
430 continue;
431 transforms[t].fCurrentValue = transform;
432 switch (transforms[t].fType) {
433 case kVec2f_GrSLType: {
bsalomon 2014/08/22 13:31:12 optional: {} only required if a var is declared in
Kimmo Kinnunen 2014/08/25 12:43:28 Done.
434 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform);
435 break;
436 }
437 case kVec3f_GrSLType: {
438 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform);
439 break;
440 }
441 default:
442 SkFAIL("Unexpected matrixs type.");
bsalomon 2014/08/22 13:31:12 typo, s on matrix
Kimmo Kinnunen 2014/08/25 12:43:28 Done.
443 }
444 }
445 }
446
393 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB uilder* builder, 447 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB uilder* builder,
394 int reserveCoun t) 448 int reserveCoun t)
395 : fBuilder(builder) 449 : fBuilder(builder)
396 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, 450 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects,
397 (reserveCount, fBuilder->hasExplicitLocalCoords ()))) { 451 (reserveCount, fBuilder->hasExplicitLocalCoords ()))) {
398 } 452 }
399 453
400 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 454 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
401 const GrEffectKey& key, 455 const GrEffectKey& key,
402 const char* outColor, 456 const char* outColor,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 for (int t = 0; t < numTransforms; ++t) { 502 for (int t = 0; t < numTransforms; ++t) {
449 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? 503 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ?
450 kVec3f_GrSLType : 504 kVec3f_GrSLType :
451 kVec2f_GrSLType; 505 kVec2f_GrSLType;
452 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); 506 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++);
453 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); 507 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
454 } 508 }
455 } 509 }
456 510
457 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, 511 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu,
458 const GrGLProgramDataManager& programReso urceManager, 512 GrGpu::DrawType,
459 const GrEffectStage* effectStages[]) { 513 const GrGLProgramDataManager& pdman,
514 const GrEffectStage* effectStages[]) {
460 int numEffects = fGLEffects.count(); 515 int numEffects = fGLEffects.count();
461 SkASSERT(numEffects == fTransforms.count()); 516 SkASSERT(numEffects == fTransforms.count());
462 SkASSERT(numEffects == fSamplers.count()); 517 SkASSERT(numEffects == fSamplers.count());
463 for (int e = 0; e < numEffects; ++e) { 518 for (int e = 0; e < numEffects; ++e) {
464 GrDrawEffect drawEffect(*effectStages[e], false); 519 GrDrawEffect drawEffect(*effectStages[e], false);
465 fGLEffects[e]->setData(programResourceManager, drawEffect); 520 fGLEffects[e]->setData(pdman, drawEffect);
466 this->setPathTexGenState(gpu, drawEffect, e); 521 this->setPathTexGenState(gpu, drawEffect, e);
467 this->bindTextures(gpu, drawEffect.effect(), e); 522 this->bindTextures(gpu, drawEffect.effect(), e);
468 } 523 }
469 } 524 }
470 525
471 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, 526 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
472 const GrDrawEffect& drawEffect, 527 const GrDrawEffect& drawEffect,
473 int effectIdx) { 528 int effectIdx) {
474 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; 529 uint32_t totalKey = fTransforms[effectIdx].fTransformKey;
475 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; 530 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
(...skipping 30 matching lines...) Expand all
506 } 561 }
507 562
508 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 563 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
509 const GrEffectKey& key, 564 const GrEffectKey& key,
510 const char* outColor, 565 const char* outColor,
511 const char* inColor, 566 const char* inColor,
512 int stageIndex) { 567 int stageIndex) {
513 SkASSERT(NULL != fProgramEffects.get()); 568 SkASSERT(NULL != fProgramEffects.get());
514 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 569 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
515 } 570 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.h ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698