joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 8 | #include "GrGLSLPrimitiveProcessor.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 9 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 10 | #include "glsl/GrGLSLProgramBuilder.h" |
| 11 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 12 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 13 | SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix, |
| 14 | const GrCoordTransform& coordTransform) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | SkMatrix combined; |
| 16 | // We only apply the localmatrix to localcoords |
| 17 | if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 18 | combined.setConcat(coordTransform.getMatrix(), localMatrix); |
| 19 | } else { |
| 20 | combined = coordTransform.getMatrix(); |
| 21 | } |
| 22 | if (coordTransform.reverseY()) { |
| 23 | // combined.postScale(1,-1); |
| 24 | // combined.postTranslate(0,1); |
| 25 | combined.set(SkMatrix::kMSkewY, |
| 26 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 27 | combined.set(SkMatrix::kMScaleY, |
| 28 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 29 | combined.set(SkMatrix::kMTransY, |
| 30 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 31 | } |
| 32 | return combined; |
| 33 | } |
| 34 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 35 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLGPBuilder* pb, |
| 36 | const char* outputName, |
| 37 | UniformHandle* colorUniform) { |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 38 | GrGLSLFragmentBuilder* fs = pb->getFragmentShaderBuilder(); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 39 | SkASSERT(colorUniform); |
| 40 | const char* stagedLocalVarName; |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 41 | *colorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 42 | kVec4f_GrSLType, |
| 43 | kDefault_GrSLPrecision, |
| 44 | "Color", |
| 45 | &stagedLocalVarName); |
| 46 | fs->codeAppendf("%s = %s;", outputName, stagedLocalVarName); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 47 | } |