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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrShaderCaps.h" |
| 9 | #include "src/gpu/effects/GrBezierEffect.h" |
| 10 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 11 | #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" |
| 12 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 13 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 14 | #include "src/gpu/glsl/GrGLSLUtil.h" |
| 15 | #include "src/gpu/glsl/GrGLSLVarying.h" |
| 16 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.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) { |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 40 | pdman.set4fv(fColorUniform, 1, ce.color().vec()); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 41 | fColor = ce.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 42 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 43 | |
| 44 | if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale) { |
| 45 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverageScale())); |
| 46 | fCoverageScale = ce.coverageScale(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 47 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 48 | this->setTransformDataHelper(ce.localMatrix(), pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 49 | } |
| 50 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 51 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 52 | SkMatrix fViewMatrix; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 53 | SkPMColor4f fColor; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 54 | uint8_t fCoverageScale; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 55 | GrClipEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 56 | UniformHandle fColorUniform; |
| 57 | UniformHandle fCoverageScaleUniform; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 58 | UniformHandle fViewMatrixUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 59 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 60 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 61 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 62 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 63 | GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 64 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(SK_PMColor4fILLEGAL), fCoverageScale(0xff) { |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 65 | const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 66 | fEdgeType = ce.getEdgeType(); |
| 67 | } |
| 68 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 69 | void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 70 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 71 | const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 72 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 73 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 74 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 75 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 76 | varyingHandler->emitAttributes(gp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 77 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame] | 78 | GrGLSLVarying v(kFloat4_GrSLType); |
Chris Dalton | fdde34e | 2017-10-16 14:15:26 -0600 | [diff] [blame] | 79 | varyingHandler->addVarying("ConicCoeffs", &v); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 80 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs().name()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 81 | |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 82 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 83 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 84 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 85 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 86 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 87 | this->writeOutputPosition(vertBuilder, |
| 88 | uniformHandler, |
| 89 | gpArgs, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 90 | gp.inPosition().name(), |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 91 | gp.viewMatrix(), |
| 92 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 93 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 94 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 95 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 96 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 97 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 98 | gp.inPosition().asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 99 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 100 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 101 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 102 | // TODO: we should check on the number of bits float and half provide and use the smallest one |
| 103 | // that suffices. Additionally we should assert that the upstream code only lets us get here if |
| 104 | // either float or half provides the required number of bits. |
robertphillips | 2eb1009 | 2015-12-11 04:59:36 -0800 | [diff] [blame] | 105 | |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 106 | GrShaderVar edgeAlpha("edgeAlpha", kHalf_GrSLType, 0); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 107 | GrShaderVar dklmdx("dklmdx", kFloat3_GrSLType, 0); |
| 108 | GrShaderVar dklmdy("dklmdy", kFloat3_GrSLType, 0); |
| 109 | GrShaderVar dfdx("dfdx", kFloat_GrSLType, 0); |
| 110 | GrShaderVar dfdy("dfdy", kFloat_GrSLType, 0); |
| 111 | GrShaderVar gF("gF", kFloat2_GrSLType, 0); |
| 112 | GrShaderVar gFM("gFM", kFloat_GrSLType, 0); |
| 113 | GrShaderVar func("func", kFloat_GrSLType, 0); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 114 | |
| 115 | fragBuilder->declAppend(edgeAlpha); |
| 116 | fragBuilder->declAppend(dklmdx); |
| 117 | fragBuilder->declAppend(dklmdy); |
| 118 | fragBuilder->declAppend(dfdx); |
| 119 | fragBuilder->declAppend(dfdy); |
| 120 | fragBuilder->declAppend(gF); |
| 121 | fragBuilder->declAppend(gFM); |
| 122 | fragBuilder->declAppend(func); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 123 | |
| 124 | switch (fEdgeType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 125 | case GrClipEdgeType::kHairlineAA: { |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 126 | fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 127 | fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
| 128 | fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 129 | dfdx.c_str(), |
| 130 | v.fsIn(), dklmdx.c_str(), |
| 131 | v.fsIn(), dklmdx.c_str(), |
| 132 | v.fsIn(), dklmdx.c_str()); |
| 133 | fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 134 | dfdy.c_str(), |
| 135 | v.fsIn(), dklmdy.c_str(), |
| 136 | v.fsIn(), dklmdy.c_str(), |
| 137 | v.fsIn(), dklmdy.c_str()); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 138 | fragBuilder->codeAppendf("%s = float2(%s, %s);", gF.c_str(), dfdx.c_str(), |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 139 | dfdy.c_str()); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 140 | fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
| 141 | gFM.c_str(), gF.c_str(), gF.c_str()); |
| 142 | fragBuilder->codeAppendf("%s = %s.x*%s.x - %s.y*%s.z;", |
| 143 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
| 144 | fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 145 | fragBuilder->codeAppendf("%s = half(%s / %s);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 146 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
| 147 | fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
| 148 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 149 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 150 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 151 | break; |
| 152 | } |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 153 | case GrClipEdgeType::kFillAA: { |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 154 | fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 155 | fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
| 156 | fragBuilder->codeAppendf("%s =" |
| 157 | "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 158 | dfdx.c_str(), |
| 159 | v.fsIn(), dklmdx.c_str(), |
| 160 | v.fsIn(), dklmdx.c_str(), |
| 161 | v.fsIn(), dklmdx.c_str()); |
| 162 | fragBuilder->codeAppendf("%s =" |
| 163 | "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
| 164 | dfdy.c_str(), |
| 165 | v.fsIn(), dklmdy.c_str(), |
| 166 | v.fsIn(), dklmdy.c_str(), |
| 167 | v.fsIn(), dklmdy.c_str()); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 168 | fragBuilder->codeAppendf("%s = float2(%s, %s);", gF.c_str(), dfdx.c_str(), |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 169 | dfdy.c_str()); |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 170 | fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
| 171 | gFM.c_str(), gF.c_str(), gF.c_str()); |
| 172 | fragBuilder->codeAppendf("%s = %s.x * %s.x - %s.y * %s.z;", |
| 173 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 174 | fragBuilder->codeAppendf("%s = half(%s / %s);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 175 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
Ethan Nicholas | 12fb9cf | 2018-08-03 16:16:57 -0400 | [diff] [blame] | 176 | fragBuilder->codeAppendf("%s = saturate(0.5 - %s);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 177 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 178 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 179 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 180 | break; |
| 181 | } |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 182 | case GrClipEdgeType::kFillBW: { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 183 | fragBuilder->codeAppendf("%s = half(%s.x * %s.x - %s.y * %s.z);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 184 | edgeAlpha.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 185 | fragBuilder->codeAppendf("%s = half(%s < 0.0);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 186 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 187 | break; |
| 188 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 189 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 190 | SK_ABORT("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 191 | } |
| 192 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 193 | // TODO should we really be doing this? |
| 194 | if (gp.coverageScale() != 0xff) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 195 | const char* coverageScale; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 196 | fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 197 | kFloat_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 198 | "Coverage", |
| 199 | &coverageScale); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 200 | fragBuilder->codeAppendf("%s = half4(half(%s) * %s);", |
robertphillips | 96afa52 | 2015-12-09 07:54:24 -0800 | [diff] [blame] | 201 | args.fOutputCoverage, coverageScale, edgeAlpha.c_str()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 202 | } else { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 203 | fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, edgeAlpha.c_str()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 204 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 205 | } |
| 206 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 207 | void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 208 | const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 209 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 210 | const GrConicEffect& ce = gp.cast<GrConicEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 211 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 212 | key |= 0xff != ce.coverageScale() ? 0x8 : 0x0; |
| 213 | key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 214 | key |= ComputePosKey(ce.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 215 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | ////////////////////////////////////////////////////////////////////////////// |
| 219 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 220 | constexpr GrPrimitiveProcessor::Attribute GrConicEffect::kAttributes[]; |
| 221 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 222 | GrConicEffect::~GrConicEffect() {} |
| 223 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 224 | void GrConicEffect::getGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 225 | GrProcessorKeyBuilder* b) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 226 | GrGLConicEffect::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 229 | GrGLSLPrimitiveProcessor* GrConicEffect::createGLSLInstance(const GrShaderCaps&) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 230 | return new GrGLConicEffect(*this); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 233 | GrConicEffect::GrConicEffect(const SkPMColor4f& color, const SkMatrix& viewMatrix, uint8_t coverage, |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 234 | GrClipEdgeType edgeType, const SkMatrix& localMatrix, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 235 | bool usesLocalCoords) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 236 | : INHERITED(kGrConicEffect_ClassID) |
| 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) { |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 243 | this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes)); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 244 | } |
| 245 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 246 | ////////////////////////////////////////////////////////////////////////////// |
| 247 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 248 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 249 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 250 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 251 | sk_sp<GrGeometryProcessor> GrConicEffect::TestCreate(GrProcessorTestData* d) { |
| 252 | sk_sp<GrGeometryProcessor> gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 253 | do { |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 254 | GrClipEdgeType edgeType = |
| 255 | static_cast<GrClipEdgeType>( |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 256 | d->fRandom->nextULessThan(kGrClipEdgeTypeCnt)); |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 257 | gp = GrConicEffect::Make(SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)), |
Brian Osman | 1be2b7c | 2018-10-29 16:07:15 -0400 | [diff] [blame] | 258 | GrTest::TestMatrix(d->fRandom), edgeType, *d->caps(), |
| 259 | GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 260 | } while (nullptr == gp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 261 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 262 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 263 | #endif |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 264 | |
| 265 | ////////////////////////////////////////////////////////////////////////////// |
| 266 | // Quad |
| 267 | ////////////////////////////////////////////////////////////////////////////// |
| 268 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 269 | class GrGLQuadEffect : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 270 | public: |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 271 | GrGLQuadEffect(const GrGeometryProcessor&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 272 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 273 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 274 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 275 | static inline void GenKey(const GrGeometryProcessor&, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 276 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 277 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 278 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 279 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc, |
| 280 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 281 | const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 282 | |
| 283 | if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMatrix())) { |
| 284 | fViewMatrix = qe.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 285 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 286 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 287 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 288 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 289 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 290 | if (qe.color() != fColor) { |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 291 | pdman.set4fv(fColorUniform, 1, qe.color().vec()); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 292 | fColor = qe.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 293 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 294 | |
| 295 | if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale) { |
| 296 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverageScale())); |
| 297 | fCoverageScale = qe.coverageScale(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 298 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 299 | this->setTransformDataHelper(qe.localMatrix(), pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 300 | } |
| 301 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 302 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 303 | SkMatrix fViewMatrix; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 304 | SkPMColor4f fColor; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 305 | uint8_t fCoverageScale; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 306 | GrClipEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 307 | UniformHandle fColorUniform; |
| 308 | UniformHandle fCoverageScaleUniform; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 309 | UniformHandle fViewMatrixUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 310 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 311 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 312 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 313 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 314 | GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 315 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(SK_PMColor4fILLEGAL), fCoverageScale(0xff) { |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 316 | const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 317 | fEdgeType = ce.getEdgeType(); |
| 318 | } |
| 319 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 320 | void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 321 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 322 | const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 323 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 324 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 325 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 326 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 327 | varyingHandler->emitAttributes(gp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 328 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame] | 329 | GrGLSLVarying v(kHalf4_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 330 | varyingHandler->addVarying("HairQuadEdge", &v); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 331 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge().name()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 332 | |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 333 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 334 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 335 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 336 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 337 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 338 | this->writeOutputPosition(vertBuilder, |
| 339 | uniformHandler, |
| 340 | gpArgs, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 341 | gp.inPosition().name(), |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 342 | gp.viewMatrix(), |
| 343 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 344 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 345 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 346 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 347 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 348 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 349 | gp.inPosition().asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 350 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 351 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 352 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 353 | fragBuilder->codeAppendf("half edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 354 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 355 | switch (fEdgeType) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 356 | case GrClipEdgeType::kHairlineAA: { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 357 | fragBuilder->codeAppendf("half2 duvdx = half2(dFdx(%s.xy));", v.fsIn()); |
| 358 | fragBuilder->codeAppendf("half2 duvdy = half2(dFdy(%s.xy));", v.fsIn()); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 359 | fragBuilder->codeAppendf("half2 gF = half2(2.0 * %s.x * duvdx.x - duvdx.y," |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 360 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
| 361 | v.fsIn(), v.fsIn()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 362 | fragBuilder->codeAppendf("edgeAlpha = half(%s.x * %s.x - %s.y);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 363 | v.fsIn(), v.fsIn(), v.fsIn()); |
| 364 | fragBuilder->codeAppend("edgeAlpha = sqrt(edgeAlpha * edgeAlpha / dot(gF, gF));"); |
| 365 | fragBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 366 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 367 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 368 | break; |
| 369 | } |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 370 | case GrClipEdgeType::kFillAA: { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 371 | fragBuilder->codeAppendf("half2 duvdx = half2(dFdx(%s.xy));", v.fsIn()); |
| 372 | fragBuilder->codeAppendf("half2 duvdy = half2(dFdy(%s.xy));", v.fsIn()); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 373 | fragBuilder->codeAppendf("half2 gF = half2(2.0 * %s.x * duvdx.x - duvdx.y," |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 374 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
| 375 | v.fsIn(), v.fsIn()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 376 | fragBuilder->codeAppendf("edgeAlpha = half(%s.x * %s.x - %s.y);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 377 | v.fsIn(), v.fsIn(), v.fsIn()); |
| 378 | fragBuilder->codeAppend("edgeAlpha = edgeAlpha / sqrt(dot(gF, gF));"); |
Ethan Nicholas | 12fb9cf | 2018-08-03 16:16:57 -0400 | [diff] [blame] | 379 | fragBuilder->codeAppend("edgeAlpha = saturate(0.5 - edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 380 | // Add line below for smooth cubic ramp |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 381 | // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 382 | break; |
| 383 | } |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 384 | case GrClipEdgeType::kFillBW: { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 385 | fragBuilder->codeAppendf("edgeAlpha = half(%s.x * %s.x - %s.y);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 386 | v.fsIn(), v.fsIn(), v.fsIn()); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 387 | fragBuilder->codeAppend("edgeAlpha = half(edgeAlpha < 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 388 | break; |
| 389 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 390 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 391 | SK_ABORT("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 392 | } |
| 393 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 394 | if (0xff != gp.coverageScale()) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 395 | const char* coverageScale; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 396 | fCoverageScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 397 | kHalf_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 398 | "Coverage", |
| 399 | &coverageScale); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 400 | fragBuilder->codeAppendf("%s = half4(%s * edgeAlpha);", args.fOutputCoverage, |
| 401 | coverageScale); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 402 | } else { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 403 | fragBuilder->codeAppendf("%s = half4(edgeAlpha);", args.fOutputCoverage); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 404 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 405 | } |
| 406 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 407 | void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 408 | const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 409 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 410 | const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 411 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 412 | key |= ce.coverageScale() != 0xff ? 0x8 : 0x0; |
| 413 | key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 414 | key |= ComputePosKey(ce.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 415 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | ////////////////////////////////////////////////////////////////////////////// |
| 419 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 420 | constexpr GrPrimitiveProcessor::Attribute GrQuadEffect::kAttributes[]; |
| 421 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 422 | GrQuadEffect::~GrQuadEffect() {} |
| 423 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 424 | void GrQuadEffect::getGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 425 | GrProcessorKeyBuilder* b) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 426 | GrGLQuadEffect::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 429 | GrGLSLPrimitiveProcessor* GrQuadEffect::createGLSLInstance(const GrShaderCaps&) const { |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 430 | return new GrGLQuadEffect(*this); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 433 | GrQuadEffect::GrQuadEffect(const SkPMColor4f& color, const SkMatrix& viewMatrix, uint8_t coverage, |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 434 | GrClipEdgeType edgeType, const SkMatrix& localMatrix, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 435 | bool usesLocalCoords) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 436 | : INHERITED(kGrQuadEffect_ClassID) |
| 437 | , fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 438 | , fViewMatrix(viewMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 439 | , fLocalMatrix(localMatrix) |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 440 | , fUsesLocalCoords(usesLocalCoords) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 441 | , fCoverageScale(coverage) |
| 442 | , fEdgeType(edgeType) { |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 443 | this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 444 | } |
| 445 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 446 | ////////////////////////////////////////////////////////////////////////////// |
| 447 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 448 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 449 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 450 | #if GR_TEST_UTILS |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 451 | sk_sp<GrGeometryProcessor> GrQuadEffect::TestCreate(GrProcessorTestData* d) { |
| 452 | sk_sp<GrGeometryProcessor> gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 453 | do { |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 454 | GrClipEdgeType edgeType = static_cast<GrClipEdgeType>( |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 455 | d->fRandom->nextULessThan(kGrClipEdgeTypeCnt)); |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 456 | gp = GrQuadEffect::Make(SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)), |
Brian Osman | 1be2b7c | 2018-10-29 16:07:15 -0400 | [diff] [blame] | 457 | GrTest::TestMatrix(d->fRandom), edgeType, *d->caps(), |
| 458 | GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 459 | } while (nullptr == gp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 460 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 461 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 462 | #endif |