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 | #ifndef GrBezierEffect_DEFINED |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 9 | #define GrBezierEffect_DEFINED |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 10 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 12 | #include "GrProcessor.h" |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 13 | #include "GrGeometryProcessor.h" |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 14 | #include "GrTypesPriv.h" |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * Shader is based off of Loop-Blinn Quadratic GPU Rendering |
| 18 | * The output of this effect is a hairline edge for conics. |
| 19 | * Conics specified by implicit equation K^2 - LM. |
| 20 | * K, L, and M, are the first three values of the vertex attribute, |
| 21 | * the fourth value is not used. Distance is calculated using a |
| 22 | * first order approximation from the taylor series. |
| 23 | * Coverage for AA is max(0, 1-distance). |
| 24 | * |
| 25 | * Test were also run using a second order distance approximation. |
| 26 | * There were two versions of the second order approx. The first version |
| 27 | * is of roughly the form: |
| 28 | * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2. |
| 29 | * The second is similar: |
| 30 | * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2. |
| 31 | * The exact version of the equations can be found in the paper |
| 32 | * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin |
| 33 | * |
| 34 | * In both versions we solve the quadratic for ||q-p||. |
| 35 | * Version 1: |
| 36 | * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper) |
| 37 | * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2.0*gF2M);\n"); |
| 38 | * Version 2: |
| 39 | * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2.0*gF2M);\n"); |
| 40 | * |
| 41 | * Also note that 2nd partials of k,l,m are zero |
| 42 | * |
| 43 | * When comparing the two second order approximations to the first order approximations, |
| 44 | * the following results were found. Version 1 tends to underestimate the distances, thus it |
| 45 | * basically increases all the error that we were already seeing in the first order |
| 46 | * approx. So this version is not the one to use. Version 2 has the opposite effect |
| 47 | * and tends to overestimate the distances. This is much closer to what we are |
| 48 | * looking for. It is able to render ellipses (even thin ones) without the need to chop. |
| 49 | * However, it can not handle thin hyperbolas well and thus would still rely on |
| 50 | * chopping to tighten the clipping. Another side effect of the overestimating is |
| 51 | * that the curves become much thinner and "ropey". If all that was ever rendered |
| 52 | * were "not too thin" curves and ellipses then 2nd order may have an advantage since |
| 53 | * only one geometry would need to be rendered. However no benches were run comparing |
| 54 | * chopped first order and non chopped 2nd order. |
| 55 | */ |
| 56 | class GrGLConicEffect; |
| 57 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 58 | class GrConicEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 59 | public: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 60 | static sk_sp<GrGeometryProcessor> Make(GrColor color, |
| 61 | const SkMatrix& viewMatrix, |
| 62 | const GrPrimitiveEdgeType edgeType, |
| 63 | const GrCaps& caps, |
| 64 | const SkMatrix& localMatrix, |
| 65 | bool usesLocalCoords, |
| 66 | uint8_t coverage = 0xff) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 67 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 68 | case kFillAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 69 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 70 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 71 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 72 | return sk_sp<GrGeometryProcessor>( |
| 73 | new GrConicEffect(color, viewMatrix, coverage, kFillAA_GrProcessorEdgeType, |
| 74 | localMatrix, usesLocalCoords)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 75 | case kHairlineAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 76 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 77 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 78 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 79 | return sk_sp<GrGeometryProcessor>( |
| 80 | new GrConicEffect(color, viewMatrix, coverage, |
| 81 | kHairlineAA_GrProcessorEdgeType, localMatrix, |
| 82 | usesLocalCoords)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 83 | case kFillBW_GrProcessorEdgeType: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 84 | return sk_sp<GrGeometryProcessor>( |
| 85 | new GrConicEffect(color, viewMatrix, coverage, kFillBW_GrProcessorEdgeType, |
| 86 | localMatrix, usesLocalCoords)); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 87 | default: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 88 | return nullptr; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | virtual ~GrConicEffect(); |
| 93 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 94 | const char* name() const override { return "Conic"; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 95 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 96 | inline const Attribute* inPosition() const { return fInPosition; } |
| 97 | inline const Attribute* inConicCoeffs() const { return fInConicCoeffs; } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 98 | inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType); } |
| 99 | inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType); } |
| 100 | inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 101 | GrColor color() const { return fColor; } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 102 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 103 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 104 | bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 105 | uint8_t coverageScale() const { return fCoverageScale; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 106 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 107 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 108 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 109 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 110 | |
| 111 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 112 | GrConicEffect(GrColor, const SkMatrix& viewMatrix, uint8_t coverage, GrPrimitiveEdgeType, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 113 | const SkMatrix& localMatrix, bool usesLocalCoords); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 114 | |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 115 | GrColor fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 116 | SkMatrix fViewMatrix; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 117 | SkMatrix fLocalMatrix; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 118 | bool fUsesLocalCoords; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 119 | uint8_t fCoverageScale; |
| 120 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 121 | const Attribute* fInPosition; |
| 122 | const Attribute* fInConicCoeffs; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 123 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 124 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 125 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 126 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /////////////////////////////////////////////////////////////////////////////// |
| 130 | /** |
| 131 | * The output of this effect is a hairline edge for quadratics. |
| 132 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 133 | * two components of the vertex attribute. At the three control points that define |
| 134 | * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. |
| 135 | * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. |
| 136 | * Requires shader derivative instruction support. |
| 137 | */ |
| 138 | class GrGLQuadEffect; |
| 139 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 140 | class GrQuadEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 141 | public: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 142 | static sk_sp<GrGeometryProcessor> Make(GrColor color, |
| 143 | const SkMatrix& viewMatrix, |
| 144 | const GrPrimitiveEdgeType edgeType, |
| 145 | const GrCaps& caps, |
| 146 | const SkMatrix& localMatrix, |
| 147 | bool usesLocalCoords, |
| 148 | uint8_t coverage = 0xff) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 149 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 150 | case kFillAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 151 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 152 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 153 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 154 | return sk_sp<GrGeometryProcessor>( |
| 155 | new GrQuadEffect(color, viewMatrix, coverage, kFillAA_GrProcessorEdgeType, |
| 156 | localMatrix, usesLocalCoords)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 157 | case kHairlineAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 158 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 159 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 160 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 161 | return sk_sp<GrGeometryProcessor>( |
| 162 | new GrQuadEffect(color, viewMatrix, coverage, |
| 163 | kHairlineAA_GrProcessorEdgeType, localMatrix, |
| 164 | usesLocalCoords)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 165 | case kFillBW_GrProcessorEdgeType: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 166 | return sk_sp<GrGeometryProcessor>( |
| 167 | new GrQuadEffect(color, viewMatrix, coverage, kFillBW_GrProcessorEdgeType, |
| 168 | localMatrix, usesLocalCoords)); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 169 | default: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 170 | return nullptr; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| 174 | virtual ~GrQuadEffect(); |
| 175 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 176 | const char* name() const override { return "Quad"; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 177 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 178 | inline const Attribute* inPosition() const { return fInPosition; } |
| 179 | inline const Attribute* inHairQuadEdge() const { return fInHairQuadEdge; } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 180 | inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType); } |
| 181 | inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType); } |
| 182 | inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 183 | GrColor color() const { return fColor; } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 184 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 185 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 186 | bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 187 | uint8_t coverageScale() const { return fCoverageScale; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 188 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 189 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 190 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 191 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 192 | |
| 193 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 194 | GrQuadEffect(GrColor, const SkMatrix& viewMatrix, uint8_t coverage, GrPrimitiveEdgeType, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 195 | const SkMatrix& localMatrix, bool usesLocalCoords); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 196 | |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 197 | GrColor fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 198 | SkMatrix fViewMatrix; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 199 | SkMatrix fLocalMatrix; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 200 | bool fUsesLocalCoords; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 201 | uint8_t fCoverageScale; |
| 202 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 203 | const Attribute* fInPosition; |
| 204 | const Attribute* fInHairQuadEdge; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 205 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 206 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 207 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 208 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | ////////////////////////////////////////////////////////////////////////////// |
| 212 | /** |
| 213 | * Shader is based off of "Resolution Independent Curve Rendering using |
| 214 | * Programmable Graphics Hardware" by Loop and Blinn. |
| 215 | * The output of this effect is a hairline edge for non rational cubics. |
| 216 | * Cubics are specified by implicit equation K^3 - LM. |
| 217 | * K, L, and M, are the first three values of the vertex attribute, |
| 218 | * the fourth value is not used. Distance is calculated using a |
| 219 | * first order approximation from the taylor series. |
| 220 | * Coverage for AA is max(0, 1-distance). |
| 221 | */ |
| 222 | class GrGLCubicEffect; |
| 223 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 224 | class GrCubicEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 225 | public: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 226 | static sk_sp<GrGeometryProcessor> Make(GrColor color, |
| 227 | const SkMatrix& viewMatrix, |
| 228 | const GrPrimitiveEdgeType edgeType, |
| 229 | const GrCaps& caps) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 230 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 231 | case kFillAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 232 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 233 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 234 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 235 | return sk_sp<GrGeometryProcessor>( |
| 236 | new GrCubicEffect(color, viewMatrix, kFillAA_GrProcessorEdgeType)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 237 | case kHairlineAA_GrProcessorEdgeType: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 238 | if (!caps.shaderCaps()->shaderDerivativeSupport()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 239 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 240 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 241 | return sk_sp<GrGeometryProcessor>( |
| 242 | new GrCubicEffect(color, viewMatrix, kHairlineAA_GrProcessorEdgeType)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 243 | case kFillBW_GrProcessorEdgeType: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 244 | return sk_sp<GrGeometryProcessor>( |
| 245 | new GrCubicEffect(color, viewMatrix, kFillBW_GrProcessorEdgeType)); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 246 | default: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 247 | return nullptr; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | virtual ~GrCubicEffect(); |
| 252 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 253 | const char* name() const override { return "Cubic"; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 254 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 255 | inline const Attribute* inPosition() const { return fInPosition; } |
| 256 | inline const Attribute* inCubicCoeffs() const { return fInCubicCoeffs; } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 257 | inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType); } |
| 258 | inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType); } |
| 259 | inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 260 | GrColor color() const { return fColor; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 261 | bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 262 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 263 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 264 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 265 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 266 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 267 | |
| 268 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 269 | GrCubicEffect(GrColor, const SkMatrix& viewMatrix, GrPrimitiveEdgeType); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 270 | |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 271 | GrColor fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 272 | SkMatrix fViewMatrix; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 273 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 274 | const Attribute* fInPosition; |
| 275 | const Attribute* fInCubicCoeffs; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 276 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 277 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 278 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 279 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | #endif |