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 | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 10 | #include "GrCoordTransform.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 11 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLUniformHandler.h" |
| 13 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 15 | SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix, |
| 16 | const GrCoordTransform& coordTransform) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 17 | SkMatrix combined; |
| 18 | // We only apply the localmatrix to localcoords |
| 19 | if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 20 | combined.setConcat(coordTransform.getMatrix(), localMatrix); |
| 21 | } else { |
| 22 | combined = coordTransform.getMatrix(); |
| 23 | } |
| 24 | if (coordTransform.reverseY()) { |
| 25 | // combined.postScale(1,-1); |
| 26 | // combined.postTranslate(0,1); |
| 27 | combined.set(SkMatrix::kMSkewY, |
| 28 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 29 | combined.set(SkMatrix::kMScaleY, |
| 30 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 31 | combined.set(SkMatrix::kMTransY, |
| 32 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 33 | } |
| 34 | return combined; |
| 35 | } |
| 36 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame^] | 37 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 38 | GrGLSLUniformHandler* uniformHandler, |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 39 | const char* outputName, |
| 40 | UniformHandle* colorUniform) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 41 | SkASSERT(colorUniform); |
| 42 | const char* stagedLocalVarName; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 43 | *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 44 | kVec4f_GrSLType, |
| 45 | kDefault_GrSLPrecision, |
| 46 | "Color", |
| 47 | &stagedLocalVarName); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 48 | fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 49 | } |