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