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" |
| 9 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 10 | #include "gl/GrGLProcessor.h" |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 11 | #include "gl/GrGLSL.h" |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 12 | #include "gl/GrGLGeometryProcessor.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 13 | #include "gl/builders/GrGLProgramBuilder.h" |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 14 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 15 | struct ConicBatchTracker { |
| 16 | GrGPInput fInputColorType; |
| 17 | GrColor fColor; |
| 18 | uint8_t fCoverageScale; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 19 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 20 | }; |
| 21 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 22 | class GrGLConicEffect : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 23 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 24 | GrGLConicEffect(const GrGeometryProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 25 | const GrBatchTracker&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 28 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 29 | static inline void GenKey(const GrGeometryProcessor&, |
| 30 | const GrBatchTracker&, |
| 31 | const GrGLCaps&, |
| 32 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 33 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 34 | virtual void setData(const GrGLProgramDataManager& pdman, |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 35 | const GrPrimitiveProcessor& primProc, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 37 | this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
| 38 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 39 | const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 40 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 41 | GrGLfloat c[4]; |
| 42 | GrColorToRGBAFloat(local.fColor, c); |
| 43 | pdman.set4fv(fColorUniform, 1, c); |
| 44 | fColor = local.fColor; |
| 45 | } |
| 46 | if (0xff != local.fCoverageScale && fCoverageScale != local.fCoverageScale) { |
| 47 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCoverageScale)); |
| 48 | fCoverageScale = local.fCoverageScale; |
| 49 | } |
| 50 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 51 | |
| 52 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 53 | GrColor fColor; |
| 54 | uint8_t fCoverageScale; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 55 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 56 | UniformHandle fColorUniform; |
| 57 | UniformHandle fCoverageScaleUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 58 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 59 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 60 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 61 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 62 | GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 63 | const GrBatchTracker& bt) |
| 64 | : fColor(GrColor_ILLEGAL), 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) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 70 | GrGLGPBuilder* pb = args.fPB; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 71 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 72 | const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 73 | const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>(); |
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 |
| 76 | vsBuilder->emitAttributes(gp); |
| 77 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 78 | GrGLVertToFrag v(kVec4f_GrSLType); |
| 79 | args.fPB->addVarying("ConicCoeffs", &v); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 80 | vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 81 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 82 | // Setup pass through color |
| 83 | this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputColor, NULL, |
| 84 | &fColorUniform); |
| 85 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 86 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 87 | this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 88 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 89 | // emit transforms with position |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 90 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(), |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 91 | args.fTransformsIn, args.fTransformsOut); |
| 92 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 93 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 94 | fsBuilder->codeAppend("float edgeAlpha;"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 95 | |
| 96 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 97 | case kHairlineAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 98 | SkAssertResult(fsBuilder->enableFeature( |
| 99 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 100 | fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", v.fsIn()); |
| 101 | fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 102 | fsBuilder->codeAppendf("float dfdx =" |
| 103 | "2.0 * %s.x * dklmdx.x - %s.y * dklmdx.z - %s.z * dklmdx.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 104 | v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 105 | fsBuilder->codeAppendf("float dfdy =" |
| 106 | "2.0 * %s.x * dklmdy.x - %s.y * dklmdy.z - %s.z * dklmdy.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 107 | v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 108 | fsBuilder->codeAppend("vec2 gF = vec2(dfdx, dfdy);"); |
| 109 | fsBuilder->codeAppend("float gFM = sqrt(dot(gF, gF));"); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 110 | fsBuilder->codeAppendf("float func = %s.x*%s.x - %s.y*%s.z;", v.fsIn(), v.fsIn(), |
| 111 | v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 112 | fsBuilder->codeAppend("func = abs(func);"); |
| 113 | fsBuilder->codeAppend("edgeAlpha = func / gFM;"); |
| 114 | fsBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 115 | // Add line below for smooth cubic ramp |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 116 | // fsBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 117 | break; |
| 118 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 119 | case kFillAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 120 | SkAssertResult(fsBuilder->enableFeature( |
| 121 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 122 | fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", v.fsIn()); |
| 123 | fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 124 | fsBuilder->codeAppendf("float dfdx =" |
| 125 | "2.0 * %s.x * dklmdx.x - %s.y * dklmdx.z - %s.z * dklmdx.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 126 | v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 127 | fsBuilder->codeAppendf("float dfdy =" |
| 128 | "2.0 * %s.x * dklmdy.x - %s.y * dklmdy.z - %s.z * dklmdy.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 129 | v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 130 | fsBuilder->codeAppend("vec2 gF = vec2(dfdx, dfdy);"); |
| 131 | fsBuilder->codeAppend("float gFM = sqrt(dot(gF, gF));"); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 132 | fsBuilder->codeAppendf("float func = %s.x * %s.x - %s.y * %s.z;", v.fsIn(), v.fsIn(), |
| 133 | v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 134 | fsBuilder->codeAppend("edgeAlpha = func / gFM;"); |
| 135 | fsBuilder->codeAppend("edgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 136 | // Add line below for smooth cubic ramp |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 137 | // fsBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 138 | break; |
| 139 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 140 | case kFillBW_GrProcessorEdgeType: { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 141 | fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.fsIn(), v.fsIn(), |
| 142 | v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 143 | fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 144 | break; |
| 145 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 146 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 147 | SkFAIL("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 148 | } |
| 149 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 150 | if (0xff != local.fCoverageScale) { |
| 151 | const char* coverageScale; |
| 152 | fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 153 | kFloat_GrSLType, |
| 154 | kDefault_GrSLPrecision, |
| 155 | "Coverage", |
| 156 | &coverageScale); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 157 | fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverage, coverageScale); |
| 158 | } else { |
| 159 | fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 160 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 161 | } |
| 162 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 163 | void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 164 | const GrBatchTracker& bt, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 165 | const GrGLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 166 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 167 | const GrConicEffect& ce = gp.cast<GrConicEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 168 | const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 169 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 170 | key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 171 | key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 172 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0; |
| 173 | key |= ComputePosKey(gp.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 174 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | ////////////////////////////////////////////////////////////////////////////// |
| 178 | |
| 179 | GrConicEffect::~GrConicEffect() {} |
| 180 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 181 | void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 182 | const GrGLCaps& caps, |
| 183 | GrProcessorKeyBuilder* b) const { |
| 184 | GrGLConicEffect::GenKey(*this, bt, caps, b); |
| 185 | } |
| 186 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 187 | GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt, |
| 188 | const GrGLCaps&) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 189 | return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 190 | } |
| 191 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 192 | GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage, |
| 193 | GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix) |
| 194 | : INHERITED(color, viewMatrix, localMatrix) |
| 195 | , fCoverageScale(coverage) |
| 196 | , fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 197 | this->initClassID<GrConicEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 198 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 199 | fInConicCoeffs = &this->addVertexAttrib(Attribute("inConicCoeffs", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 200 | kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 201 | } |
| 202 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 203 | bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 204 | const GrConicEffect& ce = other.cast<GrConicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 205 | return (ce.fEdgeType == fEdgeType); |
| 206 | } |
| 207 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 208 | void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 209 | ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
| 210 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
| 211 | local->fCoverageScale = fCoverageScale; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 212 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 213 | } |
| 214 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 215 | bool GrConicEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 216 | const GrGeometryProcessor& that, |
| 217 | const GrBatchTracker& t) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 218 | const ConicBatchTracker& mine = m.cast<ConicBatchTracker>(); |
| 219 | const ConicBatchTracker& theirs = t.cast<ConicBatchTracker>(); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 220 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 221 | that, theirs.fUsesLocalCoords) && |
| 222 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 223 | theirs.fInputColorType, theirs.fColor) && |
| 224 | mine.fCoverageScale == theirs.fCoverageScale; |
| 225 | } |
| 226 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 227 | ////////////////////////////////////////////////////////////////////////////// |
| 228 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 229 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 230 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 231 | GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
| 232 | GrContext*, |
| 233 | const GrDrawTargetCaps& caps, |
| 234 | GrTexture*[]) { |
| 235 | GrGeometryProcessor* gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 236 | do { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 237 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 238 | random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 239 | gp = GrConicEffect::Create(GrRandomColor(random), GrProcessorUnitTest::TestMatrix(random), |
| 240 | edgeType, caps, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 241 | GrProcessorUnitTest::TestMatrix(random)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 242 | } while (NULL == gp); |
| 243 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | ////////////////////////////////////////////////////////////////////////////// |
| 247 | // Quad |
| 248 | ////////////////////////////////////////////////////////////////////////////// |
| 249 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 250 | struct QuadBatchTracker { |
| 251 | GrGPInput fInputColorType; |
| 252 | GrColor fColor; |
| 253 | uint8_t fCoverageScale; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 254 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 257 | class GrGLQuadEffect : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 258 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 259 | GrGLQuadEffect(const GrGeometryProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 260 | const GrBatchTracker&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 261 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 262 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 263 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 264 | static inline void GenKey(const GrGeometryProcessor&, |
| 265 | const GrBatchTracker&, |
| 266 | const GrGLCaps&, |
| 267 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 268 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 269 | virtual void setData(const GrGLProgramDataManager& pdman, |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 270 | const GrPrimitiveProcessor& primProc, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 271 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 272 | this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
| 273 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 274 | const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 275 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 276 | GrGLfloat c[4]; |
| 277 | GrColorToRGBAFloat(local.fColor, c); |
| 278 | pdman.set4fv(fColorUniform, 1, c); |
| 279 | fColor = local.fColor; |
| 280 | } |
| 281 | if (0xff != local.fCoverageScale && local.fCoverageScale != fCoverageScale) { |
| 282 | pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCoverageScale)); |
| 283 | fCoverageScale = local.fCoverageScale; |
| 284 | } |
| 285 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 286 | |
| 287 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 288 | GrColor fColor; |
| 289 | uint8_t fCoverageScale; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 290 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 291 | UniformHandle fColorUniform; |
| 292 | UniformHandle fCoverageScaleUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 293 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 294 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 295 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 296 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 297 | GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 298 | const GrBatchTracker& bt) |
| 299 | : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 300 | const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 301 | fEdgeType = ce.getEdgeType(); |
| 302 | } |
| 303 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 304 | void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 305 | GrGLGPBuilder* pb = args.fPB; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 306 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 307 | const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 308 | const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 309 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 310 | // emit attributes |
| 311 | vsBuilder->emitAttributes(gp); |
| 312 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 313 | GrGLVertToFrag v(kVec4f_GrSLType); |
| 314 | args.fPB->addVarying("HairQuadEdge", &v); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 315 | vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 316 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 317 | // Setup pass through color |
| 318 | this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputColor, NULL, |
| 319 | &fColorUniform); |
| 320 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 321 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 322 | this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 323 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 324 | // emit transforms with position |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 325 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(), |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 326 | args.fTransformsIn, args.fTransformsOut); |
| 327 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 328 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 329 | fsBuilder->codeAppendf("float edgeAlpha;"); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 330 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 331 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 332 | case kHairlineAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 333 | SkAssertResult(fsBuilder->enableFeature( |
| 334 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 335 | fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 336 | fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 337 | fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx.y," |
| 338 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 339 | v.fsIn(), v.fsIn()); |
| 340 | fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 341 | fsBuilder->codeAppend("edgeAlpha = sqrt(edgeAlpha * edgeAlpha / dot(gF, gF));"); |
| 342 | fsBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 343 | // Add line below for smooth cubic ramp |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 344 | // fsBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 345 | break; |
| 346 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 347 | case kFillAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 348 | SkAssertResult(fsBuilder->enableFeature( |
| 349 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 350 | fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 351 | fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 352 | fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx.y," |
| 353 | " 2.0 * %s.x * duvdy.x - duvdy.y);", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 354 | v.fsIn(), v.fsIn()); |
| 355 | fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 356 | fsBuilder->codeAppend("edgeAlpha = edgeAlpha / sqrt(dot(gF, gF));"); |
| 357 | fsBuilder->codeAppend("edgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 358 | // Add line below for smooth cubic ramp |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 359 | // fsBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 360 | break; |
| 361 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 362 | case kFillBW_GrProcessorEdgeType: { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 363 | fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | b2f94d1 | 2014-08-29 10:08:36 -0700 | [diff] [blame] | 364 | fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 365 | break; |
| 366 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 367 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 368 | SkFAIL("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 369 | } |
| 370 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 371 | if (0xff != local.fCoverageScale) { |
| 372 | const char* coverageScale; |
| 373 | fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 374 | kFloat_GrSLType, |
| 375 | kDefault_GrSLPrecision, |
| 376 | "Coverage", |
| 377 | &coverageScale); |
| 378 | fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverage, coverageScale); |
| 379 | } else { |
| 380 | fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 381 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 382 | } |
| 383 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 384 | void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 385 | const GrBatchTracker& bt, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 386 | const GrGLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 387 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 388 | const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 389 | const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 390 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 391 | key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 392 | key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 393 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0; |
| 394 | key |= ComputePosKey(gp.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 395 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | ////////////////////////////////////////////////////////////////////////////// |
| 399 | |
| 400 | GrQuadEffect::~GrQuadEffect() {} |
| 401 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 402 | void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 403 | const GrGLCaps& caps, |
| 404 | GrProcessorKeyBuilder* b) const { |
| 405 | GrGLQuadEffect::GenKey(*this, bt, caps, b); |
| 406 | } |
| 407 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 408 | GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, |
| 409 | const GrGLCaps&) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 410 | return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 411 | } |
| 412 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 413 | GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage, |
| 414 | GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix) |
| 415 | : INHERITED(color, viewMatrix, localMatrix) |
| 416 | , fCoverageScale(coverage) |
| 417 | , fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 418 | this->initClassID<GrQuadEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 419 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 420 | fInHairQuadEdge = &this->addVertexAttrib(Attribute("inHairQuadEdge", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 421 | kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 422 | } |
| 423 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 424 | bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 425 | const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 426 | return (ce.fEdgeType == fEdgeType); |
| 427 | } |
| 428 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 429 | void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 430 | QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
| 431 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
| 432 | local->fCoverageScale = fCoverageScale; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 433 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 434 | } |
| 435 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 436 | bool GrQuadEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 437 | const GrGeometryProcessor& that, |
| 438 | const GrBatchTracker& t) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 439 | const QuadBatchTracker& mine = m.cast<QuadBatchTracker>(); |
| 440 | const QuadBatchTracker& theirs = t.cast<QuadBatchTracker>(); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 441 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 442 | that, theirs.fUsesLocalCoords) && |
| 443 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 444 | theirs.fInputColorType, theirs.fColor) && |
| 445 | mine.fCoverageScale == theirs.fCoverageScale; |
| 446 | } |
| 447 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 448 | ////////////////////////////////////////////////////////////////////////////// |
| 449 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 450 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 451 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 452 | GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
| 453 | GrContext*, |
| 454 | const GrDrawTargetCaps& caps, |
| 455 | GrTexture*[]) { |
| 456 | GrGeometryProcessor* gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 457 | do { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 458 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 459 | random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 460 | gp = GrQuadEffect::Create(GrRandomColor(random), |
| 461 | GrProcessorUnitTest::TestMatrix(random), |
| 462 | edgeType, caps, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 463 | GrProcessorUnitTest::TestMatrix(random)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 464 | } while (NULL == gp); |
| 465 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | ////////////////////////////////////////////////////////////////////////////// |
| 469 | // Cubic |
| 470 | ////////////////////////////////////////////////////////////////////////////// |
| 471 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 472 | struct CubicBatchTracker { |
| 473 | GrGPInput fInputColorType; |
| 474 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 475 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 476 | }; |
| 477 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 478 | class GrGLCubicEffect : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 479 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 480 | GrGLCubicEffect(const GrGeometryProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 481 | const GrBatchTracker&); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 482 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 483 | void onEmitCode(EmitArgs&, GrGPArgs*) override; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 484 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 485 | static inline void GenKey(const GrGeometryProcessor&, |
| 486 | const GrBatchTracker&, |
| 487 | const GrGLCaps&, |
| 488 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 489 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 490 | virtual void setData(const GrGLProgramDataManager& pdman, |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 491 | const GrPrimitiveProcessor& primProc, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 492 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 493 | this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
| 494 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 495 | const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 496 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 497 | GrGLfloat c[4]; |
| 498 | GrColorToRGBAFloat(local.fColor, c); |
| 499 | pdman.set4fv(fColorUniform, 1, c); |
| 500 | fColor = local.fColor; |
| 501 | } |
| 502 | } |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 503 | |
| 504 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 505 | GrColor fColor; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 506 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 507 | UniformHandle fColorUniform; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 508 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 509 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 510 | }; |
skia.committer@gmail.com | 44a77c8 | 2013-08-23 07:01:29 +0000 | [diff] [blame] | 511 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 512 | GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 513 | const GrBatchTracker&) |
| 514 | : fColor(GrColor_ILLEGAL) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 515 | const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 516 | fEdgeType = ce.getEdgeType(); |
| 517 | } |
| 518 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 519 | void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 520 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 521 | const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 522 | const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 523 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 524 | // emit attributes |
| 525 | vsBuilder->emitAttributes(gp); |
| 526 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 527 | GrGLVertToFrag v(kVec4f_GrSLType); |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 528 | args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 529 | vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); |
| 530 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 531 | // Setup pass through color |
| 532 | this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputColor, NULL, |
| 533 | &fColorUniform); |
| 534 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 535 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 536 | this->setupPosition(args.fPB, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 537 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 538 | // emit transforms with position |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 539 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(), |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 540 | args.fTransformsIn, args.fTransformsOut); |
| 541 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 542 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 543 | |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 544 | GrGLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 545 | GrGLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
| 546 | GrGLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
| 547 | GrGLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 548 | GrGLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 549 | GrGLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision); |
| 550 | GrGLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 551 | GrGLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 552 | |
| 553 | fsBuilder->declAppend(edgeAlpha); |
| 554 | fsBuilder->declAppend(dklmdx); |
| 555 | fsBuilder->declAppend(dklmdy); |
| 556 | fsBuilder->declAppend(dfdx); |
| 557 | fsBuilder->declAppend(dfdy); |
| 558 | fsBuilder->declAppend(gF); |
| 559 | fsBuilder->declAppend(gFM); |
| 560 | fsBuilder->declAppend(func); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 561 | |
| 562 | switch (fEdgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 563 | case kHairlineAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 564 | SkAssertResult(fsBuilder->enableFeature( |
| 565 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 566 | fsBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 567 | fsBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 568 | fsBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 569 | dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_str(), v.fsIn(), |
| 570 | dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 571 | fsBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 572 | dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_str(), v.fsIn(), |
| 573 | dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 574 | fsBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_str(), dfdy.c_str()); |
| 575 | fsBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", gFM.c_str(), gF.c_str(), gF.c_str()); |
| 576 | fsBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 577 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 578 | fsBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()); |
| 579 | fsBuilder->codeAppendf("%s = %s / %s;", |
| 580 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
| 581 | fsBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
| 582 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 583 | // Add line below for smooth cubic ramp |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 584 | // fsBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", |
| 585 | // edgeAlpha.c_str(), edgeAlpha.c_str(), edgeAlpha.c_str(), |
| 586 | // edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 587 | break; |
| 588 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 589 | case kFillAA_GrProcessorEdgeType: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 590 | SkAssertResult(fsBuilder->enableFeature( |
| 591 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 592 | fsBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn()); |
| 593 | fsBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 594 | fsBuilder->codeAppendf("%s =" |
| 595 | "3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 596 | dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_str(), v.fsIn(), |
| 597 | dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 598 | fsBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 599 | dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_str(), v.fsIn(), |
| 600 | dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 601 | fsBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_str(), dfdy.c_str()); |
| 602 | fsBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", gFM.c_str(), gF.c_str(), gF.c_str()); |
| 603 | fsBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 604 | func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 605 | fsBuilder->codeAppendf("%s = %s / %s;", |
| 606 | edgeAlpha.c_str(), func.c_str(), gFM.c_str()); |
| 607 | fsBuilder->codeAppendf("%s = clamp(1.0 - %s, 0.0, 1.0);", |
| 608 | edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 609 | // Add line below for smooth cubic ramp |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 610 | // fsBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", |
| 611 | // edgeAlpha.c_str(), edgeAlpha.c_str(), edgeAlpha.c_str(), |
| 612 | // edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 613 | break; |
| 614 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 615 | case kFillBW_GrProcessorEdgeType: { |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 616 | fsBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 617 | edgeAlpha.c_str(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn(), v.fsIn()); |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 618 | fsBuilder->codeAppendf("%s = float(%s < 0.0);", edgeAlpha.c_str(), edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 619 | break; |
| 620 | } |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 621 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 622 | SkFAIL("Shouldn't get here"); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 623 | } |
| 624 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 625 | |
| 626 | fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_str()); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 627 | } |
| 628 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 629 | void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 630 | const GrBatchTracker& bt, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 631 | const GrGLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 632 | GrProcessorKeyBuilder* b) { |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 633 | const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 634 | const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 635 | uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 636 | key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 637 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0; |
| 638 | key |= ComputePosKey(gp.viewMatrix()) << 5; |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 639 | b->add32(key); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | ////////////////////////////////////////////////////////////////////////////// |
| 643 | |
| 644 | GrCubicEffect::~GrCubicEffect() {} |
| 645 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 646 | void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 647 | const GrGLCaps& caps, |
| 648 | GrProcessorKeyBuilder* b) const { |
| 649 | GrGLCubicEffect::GenKey(*this, bt, caps, b); |
| 650 | } |
| 651 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 652 | GrGLPrimitiveProcessor* GrCubicEffect::createGLInstance(const GrBatchTracker& bt, |
| 653 | const GrGLCaps&) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 654 | return SkNEW_ARGS(GrGLCubicEffect, (*this, bt)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 655 | } |
| 656 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 657 | GrCubicEffect::GrCubicEffect(GrColor color, const SkMatrix& viewMatrix, |
| 658 | GrPrimitiveEdgeType edgeType) |
| 659 | : INHERITED(color, viewMatrix), fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 660 | this->initClassID<GrCubicEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 661 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 662 | fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 663 | kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 664 | } |
| 665 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 666 | bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 667 | const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 668 | return (ce.fEdgeType == fEdgeType); |
| 669 | } |
| 670 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 671 | void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 672 | CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
| 673 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 674 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 675 | } |
| 676 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 677 | bool GrCubicEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 678 | const GrGeometryProcessor& that, |
| 679 | const GrBatchTracker& t) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 680 | const CubicBatchTracker& mine = m.cast<CubicBatchTracker>(); |
| 681 | const CubicBatchTracker& theirs = t.cast<CubicBatchTracker>(); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 682 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 683 | that, theirs.fUsesLocalCoords) && |
| 684 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 685 | theirs.fInputColorType, theirs.fColor); |
| 686 | } |
| 687 | |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 688 | ////////////////////////////////////////////////////////////////////////////// |
| 689 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 690 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 691 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 692 | GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
| 693 | GrContext*, |
| 694 | const GrDrawTargetCaps& caps, |
| 695 | GrTexture*[]) { |
| 696 | GrGeometryProcessor* gp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 697 | do { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 698 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 699 | random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 700 | gp = GrCubicEffect::Create(GrRandomColor(random), |
| 701 | GrProcessorUnitTest::TestMatrix(random), edgeType, caps); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 702 | } while (NULL == gp); |
| 703 | return gp; |
commit-bot@chromium.org | 07e1c3f | 2013-08-22 20:41:15 +0000 | [diff] [blame] | 704 | } |
egdaniel | 9bd5bbf | 2014-08-29 11:12:30 -0700 | [diff] [blame] | 705 | |