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

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: rebse Created 6 years, 3 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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrGLProgramEffects.h" 9 #include "GrGLProgramEffects.h"
10 #include "GrDrawEffect.h" 10 #include "GrDrawEffect.h"
11 #include "gl/GrGLEffect.h" 11 #include "gl/GrGLEffect.h"
12 #include "gl/GrGLPathRendering.h"
13 #include "gl/builders/GrGLProgramBuilder.h"
12 #include "gl/GrGLVertexEffect.h" 14 #include "gl/GrGLVertexEffect.h"
13 #include "gl/GrGpuGL.h" 15 #include "gl/GrGpuGL.h"
14 16
15 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; 17 typedef GrGLProgramEffects::TransformedCoords TransformedCoords;
16 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; 18 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
17 typedef GrGLProgramEffects::TextureSampler TextureSampler; 19 typedef GrGLProgramEffects::TextureSampler TextureSampler;
18 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; 20 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
19 21
20 /** 22 /**
21 * We specialize the vertex code for each of these matrix types. 23 * We specialize the vertex code for each of these matrix types.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 fsBuilder->codeAppend("\t}\n"); 289 fsBuilder->codeAppend("\t}\n");
288 } 290 }
289 291
290 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, 292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder,
291 const GrDrawEffect& drawEffect, 293 const GrDrawEffect& drawEffect,
292 TransformedCoordsArray* outCoords) { 294 TransformedCoordsArray* outCoords) {
293 SkTArray<Transform, true>& transforms = fTransforms.push_back(); 295 SkTArray<Transform, true>& transforms = fTransforms.push_back();
294 uint32_t totalKey = GenTransformKey(drawEffect); 296 uint32_t totalKey = GenTransformKey(drawEffect);
295 int numTransforms = drawEffect.effect()->numTransforms(); 297 int numTransforms = drawEffect.effect()->numTransforms();
296 transforms.push_back_n(numTransforms); 298 transforms.push_back_n(numTransforms);
299
300 SkTArray<PathTransform, true>* pathTransforms = NULL;
301 const GrGLCaps* glCaps = builder->ctxInfo().caps();
302 if (glCaps->pathRenderingSupport() &&
303 builder->gpu()->glPathRendering()->texturingMode() ==
304 GrGLPathRendering::SeparableShaders_TexturingMode) {
305 pathTransforms = &fPathTransforms.push_back();
306 pathTransforms->push_back_n(numTransforms);
307 }
308
297 for (int t = 0; t < numTransforms; t++) { 309 for (int t = 0; t < numTransforms; t++) {
298 GrSLType varyingType = kVoid_GrSLType; 310 GrSLType varyingType = kVoid_GrSLType;
299 const char* uniName; 311 const char* uniName;
300 switch (get_matrix_type(totalKey, t)) { 312 switch (get_matrix_type(totalKey, t)) {
301 case kNoPersp_MatrixType: 313 case kNoPersp_MatrixType:
302 uniName = "StageMatrix"; 314 uniName = "StageMatrix";
303 varyingType = kVec2f_GrSLType; 315 varyingType = kVec2f_GrSLType;
304 break; 316 break;
305 case kGeneral_MatrixType: 317 case kGeneral_MatrixType:
306 uniName = "StageMatrix"; 318 uniName = "StageMatrix";
(...skipping 16 matching lines...) Expand all
323 const char* varyingName = "MatrixCoord"; 335 const char* varyingName = "MatrixCoord";
324 SkString suffixedVaryingName; 336 SkString suffixedVaryingName;
325 if (0 != t) { 337 if (0 != t) {
326 suffixedVaryingName.append(varyingName); 338 suffixedVaryingName.append(varyingName);
327 suffixedVaryingName.appendf("_%i", t); 339 suffixedVaryingName.appendf("_%i", t);
328 varyingName = suffixedVaryingName.c_str(); 340 varyingName = suffixedVaryingName.c_str();
329 } 341 }
330 const char* vsVaryingName; 342 const char* vsVaryingName;
331 const char* fsVaryingName; 343 const char* fsVaryingName;
332 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); 344 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
333 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVarying Name); 345 if (pathTransforms) {
346 (*pathTransforms)[t].fHandle =
347 builder->addSeparableVarying(varyingType, varyingName, &vsVaryin gName, &fsVaryingName);
348 (*pathTransforms)[t].fType = varyingType;
349 } else {
350 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVar yingName);
351 }
334 352
335 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ? 353 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ?
336 vsBuilder->positionAttribute() : 354 vsBuilder->positionAttribute() :
337 vsBuilder->localCoordsAttribute(); 355 vsBuilder->localCoordsAttribute();
338 // varying = matrix * coords (logically) 356 // varying = matrix * coords (logically)
339 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e); 357 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e);
340 if (kVec2f_GrSLType == varyingType) { 358 if (kVec2f_GrSLType == varyingType) {
341 vsBuilder->codeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", 359 vsBuilder->codeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n",
342 vsVaryingName, uniName, coords.c_str()); 360 vsVaryingName, uniName, coords.c_str());
343 } else { 361 } else {
344 vsBuilder->codeAppendf("\t%s = %s * vec3(%s, 1);\n", 362 vsBuilder->codeAppendf("\t%s = %s * vec3(%s, 1);\n",
345 vsVaryingName, uniName, coords.c_str()); 363 vsVaryingName, uniName, coords.c_str());
346 } 364 }
347 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, 365 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords,
348 (SkString(fsVaryingName), varyingType)); 366 (SkString(fsVaryingName), varyingType));
349 } 367 }
350 } 368 }
351 369
352 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, 370 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu,
353 const GrGLProgramDataManager& programReso urceManager, 371 GrGpu::DrawType drawType,
372 const GrGLProgramDataManager& programData Manager,
354 const GrEffectStage* effectStages[]) { 373 const GrEffectStage* effectStages[]) {
355 int numEffects = fGLEffects.count(); 374 int numEffects = fGLEffects.count();
356 SkASSERT(numEffects == fTransforms.count()); 375 SkASSERT(numEffects == fTransforms.count());
357 SkASSERT(numEffects == fSamplers.count()); 376 SkASSERT(numEffects == fSamplers.count());
358 for (int e = 0; e < numEffects; ++e) { 377 for (int e = 0; e < numEffects; ++e) {
359 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); 378 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords);
360 fGLEffects[e]->setData(programResourceManager, drawEffect); 379 fGLEffects[e]->setData(programDataManager, drawEffect);
361 this->setTransformData(programResourceManager, drawEffect, e); 380 if (GrGpu::IsPathRenderingDrawType(drawType)) {
381 this->setPathTransformData(gpu, programDataManager, drawEffect, e);
382 } else {
383 this->setTransformData(gpu, programDataManager, drawEffect, e);
384 }
385
362 this->bindTextures(gpu, drawEffect.effect(), e); 386 this->bindTextures(gpu, drawEffect.effect(), e);
363 } 387 }
364 } 388 }
365 389
366 void GrGLVertexProgramEffects::setTransformData(const GrGLProgramDataManager& pr ogramResourceManager, 390 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu,
391 const GrGLProgramDataManager& pd man,
367 const GrDrawEffect& drawEffect, 392 const GrDrawEffect& drawEffect,
368 int effectIdx) { 393 int effectIdx) {
369 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; 394 SkTArray<Transform, true>& transforms = fTransforms[effectIdx];
370 int numTransforms = transforms.count(); 395 int numTransforms = transforms.count();
371 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); 396 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
372 for (int t = 0; t < numTransforms; ++t) { 397 for (int t = 0; t < numTransforms; ++t) {
373 SkASSERT(transforms[t].fHandle.isValid()); 398 SkASSERT(transforms[t].fHandle.isValid());
374 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); 399 const SkMatrix& matrix = get_transform_matrix(drawEffect, t);
375 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { 400 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
376 programResourceManager.setSkMatrix(transforms[t].fHandle, matrix); 401 pdman.setSkMatrix(transforms[t].fHandle, matrix);
377 transforms[t].fCurrentValue = matrix; 402 transforms[t].fCurrentValue = matrix;
378 } 403 }
379 } 404 }
380 } 405 }
381 406
407 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu,
408 const GrGLProgramDataManager & pdman,
409 const GrDrawEffect& drawEffe ct,
410 int effectIdx) {
411 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx];
412 int numTransforms = transforms.count();
413 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
414 for (int t = 0; t < numTransforms; ++t) {
415 SkASSERT(transforms[t].fHandle.isValid());
416 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
417 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
418 continue;
419 }
420 transforms[t].fCurrentValue = transform;
421 switch (transforms[t].fType) {
422 case kVec2f_GrSLType:
423 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform);
424 break;
425 case kVec3f_GrSLType:
426 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform);
427 break;
428 default:
429 SkFAIL("Unexpected matrix type.");
430 }
431 }
432 }
433
382 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullProgram Builder* builder, 434 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullProgram Builder* builder,
383 int reserveCoun t) 435 int reserveCoun t)
384 : fBuilder(builder) 436 : fBuilder(builder)
385 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, 437 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects,
386 (reserveCount, 438 (reserveCount,
387 fBuilder->getVertexShaderBuilder()->hasExplici tLocalCoords()))) { 439 fBuilder->getVertexShaderBuilder()->hasExplici tLocalCoords()))) {
388 } 440 }
389 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 441 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
390 const GrEffectKey& key, 442 const GrEffectKey& key,
391 const char* outColor, 443 const char* outColor,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 for (int t = 0; t < numTransforms; ++t) { 490 for (int t = 0; t < numTransforms; ++t) {
439 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? 491 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ?
440 kVec3f_GrSLType : 492 kVec3f_GrSLType :
441 kVec2f_GrSLType; 493 kVec2f_GrSLType;
442 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); 494 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++);
443 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); 495 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
444 } 496 }
445 } 497 }
446 498
447 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, 499 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu,
448 const GrGLProgramDataManager& programReso urceManager, 500 GrGpu::DrawType,
449 const GrEffectStage* effectStages[]) { 501 const GrGLProgramDataManager& pdman,
502 const GrEffectStage* effectStages[]) {
450 int numEffects = fGLEffects.count(); 503 int numEffects = fGLEffects.count();
451 SkASSERT(numEffects == fTransforms.count()); 504 SkASSERT(numEffects == fTransforms.count());
452 SkASSERT(numEffects == fSamplers.count()); 505 SkASSERT(numEffects == fSamplers.count());
453 for (int e = 0; e < numEffects; ++e) { 506 for (int e = 0; e < numEffects; ++e) {
454 GrDrawEffect drawEffect(*effectStages[e], false); 507 GrDrawEffect drawEffect(*effectStages[e], false);
455 fGLEffects[e]->setData(programResourceManager, drawEffect); 508 fGLEffects[e]->setData(pdman, drawEffect);
456 this->setPathTexGenState(gpu, drawEffect, e); 509 this->setPathTexGenState(gpu, drawEffect, e);
457 this->bindTextures(gpu, drawEffect.effect(), e); 510 this->bindTextures(gpu, drawEffect.effect(), e);
458 } 511 }
459 } 512 }
460 513
461 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, 514 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
462 const GrDrawEffect& drawEffect, 515 const GrDrawEffect& drawEffect,
463 int effectIdx) { 516 int effectIdx) {
464 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; 517 uint32_t totalKey = fTransforms[effectIdx].fTransformKey;
465 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; 518 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
(...skipping 30 matching lines...) Expand all
496 } 549 }
497 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 550 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
498 const GrEffectKey& key, 551 const GrEffectKey& key,
499 const char* outColor, 552 const char* outColor,
500 const char* inColor, 553 const char* inColor,
501 int stageIndex) { 554 int stageIndex) {
502 SkASSERT(NULL != fProgramEffects.get()); 555 SkASSERT(NULL != fProgramEffects.get());
503 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 556 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
504 } 557 }
505 558
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698