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