commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
| 8 | #include "GrBezierEffect.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 9 | #include "GrShaderCaps.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 10 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 11 | #include "glsl/GrGLSLGeometryProcessor.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 12 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLUniformHandler.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLUtil.h" |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLVarying.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 16 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 17 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 18 | class GrGLConicEffect : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 19 | public: |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 20 | GrGLConicEffect(const GrGeometryProcessor&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 21 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 22 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 23 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 24 | static inline void GenKey(const GrGeometryProcessor&, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 25 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 26 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 27 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 28 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc, |
| 29 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 30 | const GrConicEffect& ce = primProc.cast<GrConicEffect>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 31 | |
| 32 | if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMatrix())) { |
| 33 | fViewMatrix = ce.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 34 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 35 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 36 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 37 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 38 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 39 | if (ce.color() != fColor) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 40 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 41 | GrColorToRGBAFloat(ce.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 42 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 43 | fColor = ce.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 44 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 45 | |
| 46 | if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale) { |
| 47 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverageScale())); |
| 48 | fCoverageScale = ce.coverageScale(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 49 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 50 | this->setTransformDataHelper(ce.localMatrix(), pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 51 | } |
| 52 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 53 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 54 | SkMatrix fViewMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 55 | GrColor fColor; |
| 56 | uint8_t fCoverageScale; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 58 | UniformHandle fColorUniform; |
| 59 | UniformHandle fCoverageScaleUniform; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 60 | UniformHandle fViewMatrixUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 61 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 62 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 63 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 64 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 65 | GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor) |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 66 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 67 | const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 68 | fEdgeType = ce.getEdgeType(); |
| 69 | } |
| 70 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 71 | void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 72 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 73 | const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 74 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 75 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 76 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 77 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 78 | varyingHandler->emitAttributes(gp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 79 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 80 | GrGLSLVertToFrag v(kHighFloat4_GrSLType); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 81 | varyingHandler->addVarying("ConicCoeffs", &v, kHigh_GrSLPrecision); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 82 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 83 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 84 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 85 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 86 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 87 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 88 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 89 | this->writeOutputPosition(vertBuilder, |
| 90 | uniformHandler, |
| 91 | gpArgs, |
| 92 | gp.inPosition()->fName, |
| 93 | gp.viewMatrix(), |
| 94 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 95 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 96 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 97 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 98 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 99 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 100 | gpArgs->fPositionVar, |
| 101 | gp.inPosition()->fName, |
| 102 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 103 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 104 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 105 | // TODO: we should check on the number of bits float and half provide and use the smallest one |
| 106 | // that suffices. Additionally we should assert that the upstream code only lets us get here if |
| 107 | // either float or half provides the required number of bits. |
robertphillips | 2eb1009 | 2015-12-11 04:59:36 -0800 | [diff] [blame] | 108 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 109 | GrShaderVar edgeAlpha("edgeAlpha", kHighFloat_GrSLType, 0); |
| 110 | GrShaderVar dklmdx("dklmdx", kHighFloat3_GrSLType, 0); |
| 111 | GrShaderVar dklmdy("dklmdy", kHighFloat3_GrSLType, 0); |
| 112 | GrShaderVar dfdx("dfdx", kHighFloat_GrSLType, 0); |
| 113 | GrShaderVar dfdy("dfdy", kHighFloat_GrSLType, 0); |
| 114 | GrShaderVar gF("gF", kHighFloat2_GrSLType, 0); |
| 115 | GrShaderVar gFM("gFM", kHighFloat_GrSLType, 0); |
| 116 | GrShaderVar func("func", kHighFloat_GrSLType, 0); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 117 | |
| 118 | fragBuilder->declAppend(edgeAlpha); |
| 119 | fragBuilder->declAppend(dklmdx); |
| 120 | fragBuilder->declAppend(dklmdy); |
| 121 | fragBuilder->declAppend(dfdx); |
| 122 | fragBuilder->declAppend(dfdy); |
| 123 | fragBuilder->declAppend(gF); |
| 124 | fragBuilder->declAppend(gFM); |
| 125 | fragBuilder->declAppend(func); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 126 | |
| 127 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 128 | case kHairlineAA_GrProcessorEdgeType: { |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 129 | fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 130 | fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
| 131 | fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 132 | dfdx.c_str(), |
| 133 | v.fsIn(), dklmdx.c_str(), |
| 134 | v.fsIn(), dklmdx.c_str(), |
| 135 | v.fsIn(), dklmdx.c_str()); |
| 136 | fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 137 | dfdy.c_str(), |
| 138 | v.fsIn(), dklmdy.c_str(), |
| 139 | v.fsIn(), dklmdy.c_str(), |
| 140 | v.fsIn(), dklmdy.c_str()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 141 | fragBuilder->codeAppendf("%s = highfloat2(%s, %s);", gF.c_str(), dfdx.c_str(), |
| 142 | dfdy.c_str()); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 143 | fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
| 144 | gFM.c_str(), gF.c_str(), gF.c_str()); |
| 145 | fragBuilder->codeAppendf("%s = %s.x*%s.x - %s.y*%s.z;", |
| 146 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
| 147 | fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()); |
| 148 | fragBuilder->codeAppendf("%s = %s / %s;", |
| 149 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
| 150 | fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
| 151 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 152 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 153 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 154 | break; |
| 155 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 156 | case kFillAA_GrProcessorEdgeType: { |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 157 | fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 158 | fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
| 159 | fragBuilder->codeAppendf("%s =" |
| 160 | "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 161 | dfdx.c_str(), |
| 162 | v.fsIn(), dklmdx.c_str(), |
| 163 | v.fsIn(), dklmdx.c_str(), |
| 164 | v.fsIn(), dklmdx.c_str()); |
| 165 | fragBuilder->codeAppendf("%s =" |
| 166 | "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 167 | dfdy.c_str(), |
| 168 | v.fsIn(), dklmdy.c_str(), |
| 169 | v.fsIn(), dklmdy.c_str(), |
| 170 | v.fsIn(), dklmdy.c_str()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 171 | fragBuilder->codeAppendf("%s = highfloat2(%s, %s);", gF.c_str(), dfdx.c_str(), |
| 172 | dfdy.c_str()); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 173 | fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
| 174 | gFM.c_str(), gF.c_str(), gF.c_str()); |
| 175 | fragBuilder->codeAppendf("%s = %s.x * %s.x - %s.y * %s.z;", |
| 176 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
| 177 | fragBuilder->codeAppendf("%s = %s / %s;", |
| 178 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 179 | fragBuilder->codeAppendf("%s = clamp(0.5 - %s, 0.0, 1.0);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 180 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 181 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 182 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 183 | break; |
| 184 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 185 | case kFillBW_GrProcessorEdgeType: { |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 186 | fragBuilder->codeAppendf("%s = %s.x * %s.x - %s.y * %s.z;", |
| 187 | edgeAlpha.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 188 | fragBuilder->codeAppendf("%s = highfloat(%s < 0.0);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 189 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 190 | break; |
| 191 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 192 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 193 | SK_ABORT("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 194 | } |
| 195 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 196 | // TODO should we really be doing this? |
| 197 | if (gp.coverageScale() != 0xff) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 198 | const char* coverageScale; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 199 | fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 200 | kHighFloat_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 201 | "Coverage", |
| 202 | &coverageScale); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 203 | fragBuilder->codeAppendf("%s = half4(%s * %s);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 204 | args.fOutputCoverage, coverageScale, edgeAlpha.c_str()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 205 | } else { |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 206 | fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, edgeAlpha.c_str()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 207 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 208 | } |
| 209 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 210 | void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 211 | const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 212 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 213 | const GrConicEffect& ce = gp.cast<GrConicEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 214 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 215 | key |= 0xff != ce.coverageScale() ? 0x8 : 0x0; |
| 216 | key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 217 | key |= ComputePosKey(ce.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 218 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | ////////////////////////////////////////////////////////////////////////////// |
| 222 | |
| 223 | GrConicEffect::~GrConicEffect() {} |
| 224 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 225 | void GrConicEffect::getGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 226 | GrProcessorKeyBuilder* b) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 227 | GrGLConicEffect::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 230 | GrGLSLPrimitiveProcessor* GrConicEffect::createGLSLInstance(const GrShaderCaps&) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 231 | return new GrGLConicEffect(*this); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 232 | } |
| 233 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 234 | GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 235 | GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix, |
| 236 | bool usesLocalCoords) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 237 | : fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 238 | , fViewMatrix(viewMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 239 | , fLocalMatrix(viewMatrix) |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 240 | , fUsesLocalCoords(usesLocalCoords) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 241 | , fCoverageScale(coverage) |
| 242 | , fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 243 | this->initClassID<GrConicEffect>(); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 244 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, |
| 245 | kHigh_GrSLPrecision); |
| 246 | fInConicCoeffs = &this->addVertexAttrib("inConicCoeffs", kVec4f_GrVertexAttribType); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 247 | } |
| 248 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 249 | ////////////////////////////////////////////////////////////////////////////// |
| 250 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 251 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 252 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 253 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 254 | sk_sp<GrGeometryProcessor> GrConicEffect::TestCreate(GrProcessorTestData* d) { |
| 255 | sk_sp<GrGeometryProcessor> gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 256 | do { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 257 | GrPrimitiveEdgeType edgeType = |
| 258 | static_cast<GrPrimitiveEdgeType>( |
| 259 | d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 260 | gp = GrConicEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom), |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 261 | edgeType, *d->caps(), GrTest::TestMatrix(d->fRandom), |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 262 | d->fRandom->nextBool()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 263 | } while (nullptr == gp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 264 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 265 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 266 | #endif |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 267 | |
| 268 | ////////////////////////////////////////////////////////////////////////////// |
| 269 | // Quad |
| 270 | ////////////////////////////////////////////////////////////////////////////// |
| 271 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 272 | class GrGLQuadEffect : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 273 | public: |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 274 | GrGLQuadEffect(const GrGeometryProcessor&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 275 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 276 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 277 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 278 | static inline void GenKey(const GrGeometryProcessor&, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 279 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 280 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 281 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 282 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc, |
| 283 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 284 | const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 285 | |
| 286 | if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMatrix())) { |
| 287 | fViewMatrix = qe.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 288 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 289 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 290 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 291 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 292 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 293 | if (qe.color() != fColor) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 294 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 295 | GrColorToRGBAFloat(qe.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 296 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 297 | fColor = qe.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 298 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 299 | |
| 300 | if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale) { |
| 301 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverageScale())); |
| 302 | fCoverageScale = qe.coverageScale(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 303 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 304 | this->setTransformDataHelper(qe.localMatrix(), pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 305 | } |
| 306 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 307 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 308 | SkMatrix fViewMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 309 | GrColor fColor; |
| 310 | uint8_t fCoverageScale; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 311 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 312 | UniformHandle fColorUniform; |
| 313 | UniformHandle fCoverageScaleUniform; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 314 | UniformHandle fViewMatrixUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 315 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 316 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 317 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 318 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 319 | GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor) |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 320 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 321 | const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 322 | fEdgeType = ce.getEdgeType(); |
| 323 | } |
| 324 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 325 | void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 326 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 327 | const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 328 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 329 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 330 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 331 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 332 | varyingHandler->emitAttributes(gp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 333 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 334 | GrGLSLVertToFrag v(kHalf4_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 335 | varyingHandler->addVarying("HairQuadEdge", &v); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 336 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 337 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 338 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 339 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 340 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 341 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 342 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 343 | this->writeOutputPosition(vertBuilder, |
| 344 | uniformHandler, |
| 345 | gpArgs, |
| 346 | gp.inPosition()->fName, |
| 347 | gp.viewMatrix(), |
| 348 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 349 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 350 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 351 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 352 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 353 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 354 | gpArgs->fPositionVar, |
| 355 | gp.inPosition()->fName, |
| 356 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 357 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 358 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 359 | fragBuilder->codeAppendf("half edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 360 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 361 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 362 | case kHairlineAA_GrProcessorEdgeType: { |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 363 | fragBuilder->codeAppendf("half2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 364 | fragBuilder->codeAppendf("half2 duvdy = dFdy(%s.xy);", v.fsIn()); |
| 365 | fragBuilder->codeAppendf("half2 gF = half2(2.0 * %s.x * duvdx.x - duvdx.y," |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 366 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
| 367 | v.fsIn(), v.fsIn()); |
| 368 | fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", |
| 369 | v.fsIn(), v.fsIn(), v.fsIn()); |
| 370 | fragBuilder->codeAppend("edgeAlpha = sqrt(edgeAlpha * edgeAlpha / dot(gF, gF));"); |
| 371 | fragBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 372 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 373 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 374 | break; |
| 375 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 376 | case kFillAA_GrProcessorEdgeType: { |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 377 | fragBuilder->codeAppendf("half2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 378 | fragBuilder->codeAppendf("half2 duvdy = dFdy(%s.xy);", v.fsIn()); |
| 379 | fragBuilder->codeAppendf("half2 gF = half2(2.0 * %s.x * duvdx.x - duvdx.y," |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 380 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
| 381 | v.fsIn(), v.fsIn()); |
| 382 | fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", |
| 383 | v.fsIn(), v.fsIn(), v.fsIn()); |
| 384 | fragBuilder->codeAppend("edgeAlpha = edgeAlpha / sqrt(dot(gF, gF));"); |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 385 | fragBuilder->codeAppend("edgeAlpha = clamp(0.5 - edgeAlpha, 0.0, 1.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 386 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 387 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 388 | break; |
| 389 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 390 | case kFillBW_GrProcessorEdgeType: { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 391 | fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", |
| 392 | v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 393 | fragBuilder->codeAppend("edgeAlpha = half(edgeAlpha < 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 394 | break; |
| 395 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 396 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 397 | SK_ABORT("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 398 | } |
| 399 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 400 | if (0xff != gp.coverageScale()) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 401 | const char* coverageScale; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 402 | fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 403 | kHalf_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 404 | "Coverage", |
| 405 | &coverageScale); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 406 | fragBuilder->codeAppendf("%s = half4(%s * edgeAlpha);", args.fOutputCoverage, |
| 407 | coverageScale); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 408 | } else { |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 409 | fragBuilder->codeAppendf("%s = half4(edgeAlpha);", args.fOutputCoverage); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 410 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 411 | } |
| 412 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 413 | void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 414 | const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 415 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 416 | const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 417 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 418 | key |= ce.coverageScale() != 0xff ? 0x8 : 0x0; |
| 419 | key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 420 | key |= ComputePosKey(ce.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 421 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | ////////////////////////////////////////////////////////////////////////////// |
| 425 | |
| 426 | GrQuadEffect::~GrQuadEffect() {} |
| 427 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 428 | void GrQuadEffect::getGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 429 | GrProcessorKeyBuilder* b) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 430 | GrGLQuadEffect::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 433 | GrGLSLPrimitiveProcessor* GrQuadEffect::createGLSLInstance(const GrShaderCaps&) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 434 | return new GrGLQuadEffect(*this); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 435 | } |
| 436 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 437 | GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 438 | GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix, |
| 439 | bool usesLocalCoords) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 440 | : fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 441 | , fViewMatrix(viewMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 442 | , fLocalMatrix(localMatrix) |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 443 | , fUsesLocalCoords(usesLocalCoords) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 444 | , fCoverageScale(coverage) |
| 445 | , fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 446 | this->initClassID<GrQuadEffect>(); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 447 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, |
| 448 | kHigh_GrSLPrecision); |
| 449 | fInHairQuadEdge = &this->addVertexAttrib("inHairQuadEdge", kVec4f_GrVertexAttribType); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 450 | } |
| 451 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 452 | ////////////////////////////////////////////////////////////////////////////// |
| 453 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 454 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 455 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 456 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 457 | sk_sp<GrGeometryProcessor> GrQuadEffect::TestCreate(GrProcessorTestData* d) { |
| 458 | sk_sp<GrGeometryProcessor> gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 459 | do { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 460 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 461 | d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 462 | gp = GrQuadEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom), edgeType, |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 463 | *d->caps(), GrTest::TestMatrix(d->fRandom), |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 464 | d->fRandom->nextBool()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 465 | } while (nullptr == gp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 466 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 467 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 468 | #endif |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 469 | |
| 470 | ////////////////////////////////////////////////////////////////////////////// |
| 471 | // Cubic |
| 472 | ////////////////////////////////////////////////////////////////////////////// |
| 473 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 474 | class GrGLCubicEffect : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 475 | public: |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 476 | GrGLCubicEffect(const GrGeometryProcessor&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 477 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 478 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 479 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 480 | static inline void GenKey(const GrGeometryProcessor&, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 481 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 482 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 483 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 484 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc, |
| 485 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 486 | const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 487 | |
| 488 | if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMatrix())) { |
| 489 | fViewMatrix = ce.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 490 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 491 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 492 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 493 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 494 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 495 | if (!fDevKLMMatrix.cheapEqualTo(ce.devKLMMatrix())) { |
| 496 | fDevKLMMatrix = ce.devKLMMatrix(); |
| 497 | float devKLMMatrix[3 * 3]; |
| 498 | GrGLSLGetMatrix<3>(devKLMMatrix, fDevKLMMatrix); |
| 499 | pdman.setMatrix3f(fDevKLMUniform, devKLMMatrix); |
| 500 | } |
| 501 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 502 | if (ce.color() != fColor) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 503 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 504 | GrColorToRGBAFloat(ce.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 505 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 506 | fColor = ce.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 507 | } |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 508 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 509 | this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 510 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 511 | |
| 512 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 513 | SkMatrix fViewMatrix; |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 514 | SkMatrix fDevKLMMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 515 | GrColor fColor; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 516 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 517 | UniformHandle fColorUniform; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 518 | UniformHandle fViewMatrixUniform; |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 519 | UniformHandle fDevKLMUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 520 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 521 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 522 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 523 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 524 | GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor) |
Robert Phillips | 888e9f2 | 2017-06-12 07:50:05 -0400 | [diff] [blame] | 525 | : fViewMatrix(SkMatrix::InvalidMatrix()) |
| 526 | , fDevKLMMatrix(SkMatrix::InvalidMatrix()) |
| 527 | , fColor(GrColor_ILLEGAL) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 528 | const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 529 | fEdgeType = ce.getEdgeType(); |
| 530 | } |
| 531 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 532 | void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 533 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 534 | const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 535 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 536 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 537 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 538 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 539 | varyingHandler->emitAttributes(gp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 540 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 541 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 542 | // Setup pass through color |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 543 | if (!gp.colorIgnored()) { |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 544 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 545 | } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 546 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 547 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 548 | this->writeOutputPosition(vertBuilder, |
| 549 | uniformHandler, |
| 550 | gpArgs, |
| 551 | gp.inPosition()->fName, |
| 552 | gp.viewMatrix(), |
| 553 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 554 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 555 | // Setup KLM |
| 556 | const char* devkLMMatrixName; |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 557 | fDevKLMUniform = uniformHandler->addUniform(kVertex_GrShaderFlag, kHighFloat3x3_GrSLType, "KLM", |
| 558 | &devkLMMatrixName); |
| 559 | GrGLSLVertToFrag v(kHighFloat3_GrSLType); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 560 | varyingHandler->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 561 | vertBuilder->codeAppendf("%s = %s * highfloat3(%s, 1);", |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 562 | v.vsOut(), devkLMMatrixName, gpArgs->fPositionVar.c_str()); |
| 563 | |
| 564 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 565 | GrGLSLVertToFrag gradCoeffs(kHighFloat4_GrSLType); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 566 | if (kFillAA_GrProcessorEdgeType == fEdgeType || kHairlineAA_GrProcessorEdgeType == fEdgeType) { |
| 567 | varyingHandler->addVarying("GradCoeffs", &gradCoeffs, kHigh_GrSLPrecision); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 568 | vertBuilder->codeAppendf("highfloat k = %s[0], l = %s[1], m = %s[2];", |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 569 | v.vsOut(), v.vsOut(), v.vsOut()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 570 | vertBuilder->codeAppendf("highfloat2 gk = highfloat2(%s[0][0], %s[1][0]), " |
| 571 | "gl = highfloat2(%s[0][1], %s[1][1]), " |
| 572 | "gm = highfloat2(%s[0][2], %s[1][2]);", |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 573 | devkLMMatrixName, devkLMMatrixName, devkLMMatrixName, |
| 574 | devkLMMatrixName, devkLMMatrixName, devkLMMatrixName); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 575 | vertBuilder->codeAppendf("%s = highfloat4(3 * k * gk, -m * gl - l * gm);", |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 576 | gradCoeffs.vsOut()); |
| 577 | } |
| 578 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 579 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 580 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 581 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 582 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 583 | gpArgs->fPositionVar, |
| 584 | gp.inPosition()->fName, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 585 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 586 | |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 587 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 588 | GrShaderVar edgeAlpha("edgeAlpha", kHighFloat_GrSLType, 0); |
| 589 | GrShaderVar gF("gF", kHighFloat2_GrSLType, 0); |
| 590 | GrShaderVar func("func", kHighFloat_GrSLType, 0); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 591 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 592 | fragBuilder->declAppend(edgeAlpha); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 593 | fragBuilder->declAppend(gF); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 594 | fragBuilder->declAppend(func); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 595 | |
| 596 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 597 | case kHairlineAA_GrProcessorEdgeType: { |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 598 | fragBuilder->codeAppendf("%s = %s.x * %s.xy + %s.zw;", |
| 599 | gF.c_str(), v.fsIn(), gradCoeffs.fsIn(), gradCoeffs.fsIn()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 600 | fragBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
| 601 | func.c_str(), v.fsIn(), v.fsIn(), |
| 602 | v.fsIn(), v.fsIn(), v.fsIn()); |
| 603 | fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 604 | fragBuilder->codeAppendf("%s = %s * inversesqrt(dot(%s, %s));", |
| 605 | edgeAlpha.c_str(), func.c_str(), gF.c_str(), gF.c_str()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 606 | fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
| 607 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 608 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 609 | // fragBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 610 | // edgeAlpha.c_str(), edgeAlpha.c_str(), edgeAlpha.c_str(), |
| 611 | // edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 612 | break; |
| 613 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 614 | case kFillAA_GrProcessorEdgeType: { |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 615 | fragBuilder->codeAppendf("%s = %s.x * %s.xy + %s.zw;", |
| 616 | gF.c_str(), v.fsIn(), gradCoeffs.fsIn(), gradCoeffs.fsIn()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 617 | fragBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 618 | func.c_str(), |
| 619 | v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 620 | fragBuilder->codeAppendf("%s = %s * inversesqrt(dot(%s, %s));", |
| 621 | edgeAlpha.c_str(), func.c_str(), gF.c_str(), gF.c_str()); |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 622 | fragBuilder->codeAppendf("%s = clamp(0.5 - %s, 0.0, 1.0);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 623 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 624 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 625 | // fragBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 626 | // edgeAlpha.c_str(), edgeAlpha.c_str(), edgeAlpha.c_str(), |
| 627 | // edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 628 | break; |
| 629 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 630 | case kFillBW_GrProcessorEdgeType: { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 631 | fragBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
| 632 | edgeAlpha.c_str(), v.fsIn(), v.fsIn(), |
| 633 | v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 634 | fragBuilder->codeAppendf("%s = half(%s < 0.0);", edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 635 | break; |
| 636 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 637 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 638 | SK_ABORT("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 639 | } |
| 640 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 641 | |
Ethan Nicholas | 05d5a13 | 2017-09-15 11:42:17 -0400 | [diff] [blame] | 642 | fragBuilder->codeAppendf("%s = highfloat4(%s);", args.fOutputCoverage, edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 643 | } |
| 644 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 645 | void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 646 | const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 647 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 648 | const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 649 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 650 | key |= ComputePosKey(ce.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 651 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | ////////////////////////////////////////////////////////////////////////////// |
| 655 | |
| 656 | GrCubicEffect::~GrCubicEffect() {} |
| 657 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 658 | void GrCubicEffect::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 659 | GrGLCubicEffect::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 660 | } |
| 661 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 662 | GrGLSLPrimitiveProcessor* GrCubicEffect::createGLSLInstance(const GrShaderCaps&) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 663 | return new GrGLCubicEffect(*this); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 666 | GrCubicEffect::GrCubicEffect(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& |
| 667 | devKLMMatrix, GrPrimitiveEdgeType edgeType) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 668 | : fColor(color) |
| 669 | , fViewMatrix(viewMatrix) |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 670 | , fDevKLMMatrix(devKLMMatrix) |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 671 | , fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 672 | this->initClassID<GrCubicEffect>(); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 673 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, |
| 674 | kHigh_GrSLPrecision); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 675 | } |
| 676 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 677 | ////////////////////////////////////////////////////////////////////////////// |
| 678 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 679 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 680 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 681 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 682 | sk_sp<GrGeometryProcessor> GrCubicEffect::TestCreate(GrProcessorTestData* d) { |
| 683 | sk_sp<GrGeometryProcessor> gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 684 | do { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 685 | GrPrimitiveEdgeType edgeType = |
| 686 | static_cast<GrPrimitiveEdgeType>( |
| 687 | d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
Brian Salomon | 9ae32a2 | 2017-01-25 14:58:24 -0500 | [diff] [blame] | 688 | gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom), |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 689 | GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool(), edgeType, |
| 690 | *d->caps()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 691 | } while (nullptr == gp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 692 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 693 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 694 | #endif |