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" |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 12 | #include "glsl/GrGLSLProgramBuilder.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLUniformHandler.h" |
| 14 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 16 | SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix, |
| 17 | const GrCoordTransform& coordTransform) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 18 | SkMatrix combined; |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 19 | combined.setConcat(coordTransform.getMatrix(), localMatrix); |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 20 | if (coordTransform.normalize()) { |
| 21 | SkASSERT(coordTransform.texture()); |
| 22 | combined.postIDiv(coordTransform.texture()->width(), coordTransform.texture()->height()); |
| 23 | } |
| 24 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 25 | if (coordTransform.reverseY()) { |
| 26 | // combined.postScale(1,-1); |
| 27 | // combined.postTranslate(0,1); |
| 28 | combined.set(SkMatrix::kMSkewY, |
| 29 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 30 | combined.set(SkMatrix::kMScaleY, |
| 31 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 32 | combined.set(SkMatrix::kMTransY, |
| 33 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 34 | } |
| 35 | return combined; |
| 36 | } |
| 37 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 38 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 39 | GrGLSLUniformHandler* uniformHandler, |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 40 | const char* outputName, |
| 41 | UniformHandle* colorUniform) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 42 | SkASSERT(colorUniform); |
| 43 | const char* stagedLocalVarName; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 44 | *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 45 | kVec4f_GrSLType, |
| 46 | kDefault_GrSLPrecision, |
| 47 | "Color", |
| 48 | &stagedLocalVarName); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 49 | fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName); |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 50 | if (fragBuilder->getProgramBuilder()->shaderCaps()->mustObfuscateUniformColor()) { |
| 51 | fragBuilder->codeAppendf("%s = max(%s, vec4(0, 0, 0, 0));", outputName, outputName); |
| 52 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 53 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 54 | |
| 55 | ////////////////////////////////////////////////////////////////////////////// |
| 56 | |
| 57 | const GrCoordTransform* GrGLSLPrimitiveProcessor::FPCoordTransformHandler::nextCoordTransform() { |
| 58 | #ifdef SK_DEBUG |
| 59 | SkASSERT(nullptr == fCurr || fAddedCoord); |
| 60 | fAddedCoord = false; |
| 61 | fCurr = fIter.next(); |
| 62 | return fCurr; |
| 63 | #else |
| 64 | return fIter.next(); |
| 65 | #endif |
| 66 | } |