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" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 11 | #include "GrTexture.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 13 | #include "glsl/GrGLSLProgramBuilder.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLUniformHandler.h" |
| 15 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 16 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 17 | SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix, |
| 18 | const GrCoordTransform& coordTransform) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 19 | SkMatrix combined; |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 20 | combined.setConcat(coordTransform.getMatrix(), localMatrix); |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 21 | if (coordTransform.normalize()) { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 22 | combined.postIDiv(coordTransform.peekTexture()->width(), |
| 23 | coordTransform.peekTexture()->height()); |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 24 | } |
| 25 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 26 | if (coordTransform.reverseY()) { |
| 27 | // combined.postScale(1,-1); |
| 28 | // combined.postTranslate(0,1); |
| 29 | combined.set(SkMatrix::kMSkewY, |
| 30 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 31 | combined.set(SkMatrix::kMScaleY, |
| 32 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 33 | combined.set(SkMatrix::kMTransY, |
| 34 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 35 | } |
| 36 | return combined; |
| 37 | } |
| 38 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 39 | void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 40 | GrGLSLUniformHandler* uniformHandler, |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 41 | const char* outputName, |
| 42 | UniformHandle* colorUniform) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 43 | SkASSERT(colorUniform); |
| 44 | const char* stagedLocalVarName; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 45 | *colorUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | 88d99c6 | 2017-08-16 16:41:30 -0400 | [diff] [blame] | 46 | kHalf4_GrSLType, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 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()) { |
Ethan Nicholas | 88d99c6 | 2017-08-16 16:41:30 -0400 | [diff] [blame] | 51 | fragBuilder->codeAppendf("%s = max(%s, half4(0, 0, 0, 0));", outputName, outputName); |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 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 | } |