| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
| 9 | 9 |
| 10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
| 13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 | 14 |
| 15 struct ConicBatchTracker { |
| 16 GrGPInput fInputColorType; |
| 17 GrColor fColor; |
| 18 uint8_t fCoverageScale; |
| 19 }; |
| 20 |
| 15 class GrGLConicEffect : public GrGLGeometryProcessor { | 21 class GrGLConicEffect : public GrGLGeometryProcessor { |
| 16 public: | 22 public: |
| 17 GrGLConicEffect(const GrGeometryProcessor&, | 23 GrGLConicEffect(const GrGeometryProcessor&, |
| 18 const GrBatchTracker&); | 24 const GrBatchTracker&); |
| 19 | 25 |
| 20 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 26 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 21 | 27 |
| 22 static inline void GenKey(const GrGeometryProcessor&, | 28 static inline void GenKey(const GrGeometryProcessor&, |
| 23 const GrBatchTracker&, | 29 const GrBatchTracker&, |
| 24 const GrGLCaps&, | 30 const GrGLCaps&, |
| 25 GrProcessorKeyBuilder*); | 31 GrProcessorKeyBuilder*); |
| 26 | 32 |
| 27 virtual void setData(const GrGLProgramDataManager&, | 33 virtual void setData(const GrGLProgramDataManager& pdman, |
| 28 const GrGeometryProcessor&, | 34 const GrGeometryProcessor&, |
| 29 const GrBatchTracker&) SK_OVERRIDE {} | 35 const GrBatchTracker& bt) SK_OVERRIDE { |
| 36 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 37 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 38 GrGLfloat c[4]; |
| 39 GrColorToRGBAFloat(local.fColor, c); |
| 40 pdman.set4fv(fColorUniform, 1, c); |
| 41 fColor = local.fColor; |
| 42 } |
| 43 if (0xff != local.fCoverageScale && fCoverageScale != local.fCoverageSca
le) { |
| 44 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
| 45 fCoverageScale = local.fCoverageScale; |
| 46 } |
| 47 } |
| 30 | 48 |
| 31 private: | 49 private: |
| 50 GrColor fColor; |
| 51 uint8_t fCoverageScale; |
| 32 GrPrimitiveEdgeType fEdgeType; | 52 GrPrimitiveEdgeType fEdgeType; |
| 53 UniformHandle fColorUniform; |
| 54 UniformHandle fCoverageScaleUniform; |
| 33 | 55 |
| 34 typedef GrGLGeometryProcessor INHERITED; | 56 typedef GrGLGeometryProcessor INHERITED; |
| 35 }; | 57 }; |
| 36 | 58 |
| 37 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, | 59 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
| 38 const GrBatchTracker& bt) { | 60 const GrBatchTracker& bt) |
| 61 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
| 39 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 62 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 40 fEdgeType = ce.getEdgeType(); | 63 fEdgeType = ce.getEdgeType(); |
| 41 } | 64 } |
| 42 | 65 |
| 43 void GrGLConicEffect::emitCode(const EmitArgs& args) { | 66 void GrGLConicEffect::emitCode(const EmitArgs& args) { |
| 67 GrGLGPBuilder* pb = args.fPB; |
| 44 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 68 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 45 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 69 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
| 70 const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>(); |
| 46 | 71 |
| 47 GrGLVertToFrag v(kVec4f_GrSLType); | 72 GrGLVertToFrag v(kVec4f_GrSLType); |
| 48 args.fPB->addVarying("ConicCoeffs", &v); | 73 args.fPB->addVarying("ConicCoeffs", &v); |
| 49 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); | 74 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
| 50 | 75 |
| 76 // Setup pass through color |
| 77 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 78 |
| 51 // setup coord outputs | 79 // setup coord outputs |
| 52 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 80 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 53 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 81 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 54 | 82 |
| 55 // setup position varying | 83 // setup position varying |
| 56 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 84 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 57 gp.inPosition()->fName); | 85 gp.inPosition()->fName); |
| 58 | 86 |
| 59 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 87 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 60 fsBuilder->codeAppend("float edgeAlpha;"); | 88 fsBuilder->codeAppend("float edgeAlpha;"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 case kFillBW_GrProcessorEdgeType: { | 134 case kFillBW_GrProcessorEdgeType: { |
| 107 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), | 135 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), |
| 108 v.fsIn(), v.fsIn()); | 136 v.fsIn(), v.fsIn()); |
| 109 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 137 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
| 110 break; | 138 break; |
| 111 } | 139 } |
| 112 default: | 140 default: |
| 113 SkFAIL("Shouldn't get here"); | 141 SkFAIL("Shouldn't get here"); |
| 114 } | 142 } |
| 115 | 143 |
| 116 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 144 if (0xff != local.fCoverageScale) { |
| 145 const char* coverageScale; |
| 146 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
| 147 kFloat_GrSLType, |
| 148 kDefault_GrSLPrecision, |
| 149 "Coverage", |
| 150 &coverageScale); |
| 151 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
| 152 } else { |
| 153 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 154 } |
| 117 } | 155 } |
| 118 | 156 |
| 119 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, | 157 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, |
| 120 const GrBatchTracker&, | 158 const GrBatchTracker& bt, |
| 121 const GrGLCaps&, | 159 const GrGLCaps&, |
| 122 GrProcessorKeyBuilder* b) { | 160 GrProcessorKeyBuilder* b) { |
| 123 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 161 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 162 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 124 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 163 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 164 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 165 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
| 125 b->add32(key); | 166 b->add32(key); |
| 126 } | 167 } |
| 127 | 168 |
| 128 ////////////////////////////////////////////////////////////////////////////// | 169 ////////////////////////////////////////////////////////////////////////////// |
| 129 | 170 |
| 130 GrConicEffect::~GrConicEffect() {} | 171 GrConicEffect::~GrConicEffect() {} |
| 131 | 172 |
| 132 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 173 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 133 const GrGLCaps& caps, | 174 const GrGLCaps& caps, |
| 134 GrProcessorKeyBuilder* b) const { | 175 GrProcessorKeyBuilder* b) const { |
| 135 GrGLConicEffect::GenKey(*this, bt, caps, b); | 176 GrGLConicEffect::GenKey(*this, bt, caps, b); |
| 136 } | 177 } |
| 137 | 178 |
| 138 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const { | 179 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const { |
| 139 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); | 180 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
| 140 } | 181 } |
| 141 | 182 |
| 142 GrConicEffect::GrConicEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeTyp
e edgeType) | 183 GrConicEffect::GrConicEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeTyp
e edgeType) |
| 143 : INHERITED(color, false, coverage), fEdgeType(edgeType) { | 184 : INHERITED(color, false), fCoverageScale(coverage), fEdgeType(edgeType) { |
| 144 this->initClassID<GrConicEffect>(); | 185 this->initClassID<GrConicEffect>(); |
| 145 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 186 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 146 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", | 187 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", |
| 147 kVec4f_GrVertexAttribTyp
e)); | 188 kVec4f_GrVertexAttribTyp
e)); |
| 148 } | 189 } |
| 149 | 190 |
| 150 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 191 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 151 const GrConicEffect& ce = other.cast<GrConicEffect>(); | 192 const GrConicEffect& ce = other.cast<GrConicEffect>(); |
| 152 return (ce.fEdgeType == fEdgeType); | 193 return (ce.fEdgeType == fEdgeType); |
| 153 } | 194 } |
| 154 | 195 |
| 196 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 197 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
| 198 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 199 local->fCoverageScale = fCoverageScale; |
| 200 } |
| 201 |
| 202 bool GrConicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { |
| 203 const ConicBatchTracker& mine = m.cast<ConicBatchTracker>(); |
| 204 const ConicBatchTracker& theirs = t.cast<ConicBatchTracker>(); |
| 205 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 206 theirs.fInputColorType, theirs.fColor) && |
| 207 mine.fCoverageScale == theirs.fCoverageScale; |
| 208 } |
| 209 |
| 155 ////////////////////////////////////////////////////////////////////////////// | 210 ////////////////////////////////////////////////////////////////////////////// |
| 156 | 211 |
| 157 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); | 212 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
| 158 | 213 |
| 159 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, | 214 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
| 160 GrContext*, | 215 GrContext*, |
| 161 const GrDrawTargetCaps& caps, | 216 const GrDrawTargetCaps& caps, |
| 162 GrTexture*[]) { | 217 GrTexture*[]) { |
| 163 GrGeometryProcessor* gp; | 218 GrGeometryProcessor* gp; |
| 164 do { | 219 do { |
| 165 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 220 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 166 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 221 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
| 167 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); | 222 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); |
| 168 } while (NULL == gp); | 223 } while (NULL == gp); |
| 169 return gp; | 224 return gp; |
| 170 } | 225 } |
| 171 | 226 |
| 172 ////////////////////////////////////////////////////////////////////////////// | 227 ////////////////////////////////////////////////////////////////////////////// |
| 173 // Quad | 228 // Quad |
| 174 ////////////////////////////////////////////////////////////////////////////// | 229 ////////////////////////////////////////////////////////////////////////////// |
| 175 | 230 |
| 231 struct QuadBatchTracker { |
| 232 GrGPInput fInputColorType; |
| 233 GrColor fColor; |
| 234 uint8_t fCoverageScale; |
| 235 }; |
| 236 |
| 176 class GrGLQuadEffect : public GrGLGeometryProcessor { | 237 class GrGLQuadEffect : public GrGLGeometryProcessor { |
| 177 public: | 238 public: |
| 178 GrGLQuadEffect(const GrGeometryProcessor&, | 239 GrGLQuadEffect(const GrGeometryProcessor&, |
| 179 const GrBatchTracker&); | 240 const GrBatchTracker&); |
| 180 | 241 |
| 181 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 242 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 182 | 243 |
| 183 static inline void GenKey(const GrGeometryProcessor&, | 244 static inline void GenKey(const GrGeometryProcessor&, |
| 184 const GrBatchTracker&, | 245 const GrBatchTracker&, |
| 185 const GrGLCaps&, | 246 const GrGLCaps&, |
| 186 GrProcessorKeyBuilder*); | 247 GrProcessorKeyBuilder*); |
| 187 | 248 |
| 188 virtual void setData(const GrGLProgramDataManager&, | 249 virtual void setData(const GrGLProgramDataManager& pdman, |
| 189 const GrGeometryProcessor&, | 250 const GrGeometryProcessor&, |
| 190 const GrBatchTracker&) SK_OVERRIDE {} | 251 const GrBatchTracker& bt) SK_OVERRIDE { |
| 252 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 253 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 254 GrGLfloat c[4]; |
| 255 GrColorToRGBAFloat(local.fColor, c); |
| 256 pdman.set4fv(fColorUniform, 1, c); |
| 257 fColor = local.fColor; |
| 258 } |
| 259 if (0xff != local.fCoverageScale && local.fCoverageScale != fCoverageSca
le) { |
| 260 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
| 261 fCoverageScale = local.fCoverageScale; |
| 262 } |
| 263 } |
| 191 | 264 |
| 192 private: | 265 private: |
| 266 GrColor fColor; |
| 267 uint8_t fCoverageScale; |
| 193 GrPrimitiveEdgeType fEdgeType; | 268 GrPrimitiveEdgeType fEdgeType; |
| 269 UniformHandle fColorUniform; |
| 270 UniformHandle fCoverageScaleUniform; |
| 194 | 271 |
| 195 typedef GrGLGeometryProcessor INHERITED; | 272 typedef GrGLGeometryProcessor INHERITED; |
| 196 }; | 273 }; |
| 197 | 274 |
| 198 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, | 275 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
| 199 const GrBatchTracker& bt) { | 276 const GrBatchTracker& bt) |
| 277 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
| 200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 278 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 201 fEdgeType = ce.getEdgeType(); | 279 fEdgeType = ce.getEdgeType(); |
| 202 } | 280 } |
| 203 | 281 |
| 204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { | 282 void GrGLQuadEffect::emitCode(const EmitArgs& args) { |
| 283 GrGLGPBuilder* pb = args.fPB; |
| 205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 284 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 285 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
| 286 const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>(); |
| 207 | 287 |
| 208 GrGLVertToFrag v(kVec4f_GrSLType); | 288 GrGLVertToFrag v(kVec4f_GrSLType); |
| 209 args.fPB->addVarying("HairQuadEdge", &v); | 289 args.fPB->addVarying("HairQuadEdge", &v); |
| 210 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); | 290 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
| 211 | 291 |
| 292 // Setup pass through color |
| 293 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 294 |
| 212 // setup coord outputs | 295 // setup coord outputs |
| 213 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 296 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 214 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 297 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 215 | 298 |
| 216 // setup position varying | 299 // setup position varying |
| 217 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 300 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 218 gp.inPosition()->fName); | 301 gp.inPosition()->fName); |
| 219 | 302 |
| 220 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 303 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 221 fsBuilder->codeAppendf("float edgeAlpha;"); | 304 fsBuilder->codeAppendf("float edgeAlpha;"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 336 } |
| 254 case kFillBW_GrProcessorEdgeType: { | 337 case kFillBW_GrProcessorEdgeType: { |
| 255 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); | 338 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); |
| 256 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 339 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
| 257 break; | 340 break; |
| 258 } | 341 } |
| 259 default: | 342 default: |
| 260 SkFAIL("Shouldn't get here"); | 343 SkFAIL("Shouldn't get here"); |
| 261 } | 344 } |
| 262 | 345 |
| 263 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 346 if (0xff != local.fCoverageScale) { |
| 347 const char* coverageScale; |
| 348 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
| 349 kFloat_GrSLType, |
| 350 kDefault_GrSLPrecision, |
| 351 "Coverage", |
| 352 &coverageScale); |
| 353 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
| 354 } else { |
| 355 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 356 } |
| 264 } | 357 } |
| 265 | 358 |
| 266 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, | 359 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, |
| 267 const GrBatchTracker&, | 360 const GrBatchTracker& bt, |
| 268 const GrGLCaps&, | 361 const GrGLCaps&, |
| 269 GrProcessorKeyBuilder* b) { | 362 GrProcessorKeyBuilder* b) { |
| 270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 363 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 364 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 365 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 366 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 367 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
| 272 b->add32(key); | 368 b->add32(key); |
| 273 } | 369 } |
| 274 | 370 |
| 275 ////////////////////////////////////////////////////////////////////////////// | 371 ////////////////////////////////////////////////////////////////////////////// |
| 276 | 372 |
| 277 GrQuadEffect::~GrQuadEffect() {} | 373 GrQuadEffect::~GrQuadEffect() {} |
| 278 | 374 |
| 279 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, | 375 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 280 const GrGLCaps& caps, | 376 const GrGLCaps& caps, |
| 281 GrProcessorKeyBuilder* b) const { | 377 GrProcessorKeyBuilder* b) const { |
| 282 GrGLQuadEffect::GenKey(*this, bt, caps, b); | 378 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
| 283 } | 379 } |
| 284 | 380 |
| 285 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const { | 381 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const { |
| 286 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); | 382 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
| 287 } | 383 } |
| 288 | 384 |
| 289 GrQuadEffect::GrQuadEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeType
edgeType) | 385 GrQuadEffect::GrQuadEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeType
edgeType) |
| 290 : INHERITED(color, false, coverage), fEdgeType(edgeType) { | 386 : INHERITED(color, false), fCoverageScale(coverage), fEdgeType(edgeType) { |
| 291 this->initClassID<GrQuadEffect>(); | 387 this->initClassID<GrQuadEffect>(); |
| 292 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 388 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 293 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", | 389 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", |
| 294 kVec4f_GrVertexAttribTyp
e)); | 390 kVec4f_GrVertexAttribTyp
e)); |
| 295 } | 391 } |
| 296 | 392 |
| 297 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 393 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 298 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); | 394 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
| 299 return (ce.fEdgeType == fEdgeType); | 395 return (ce.fEdgeType == fEdgeType); |
| 300 } | 396 } |
| 301 | 397 |
| 398 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) cons
t { |
| 399 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
| 400 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 401 local->fCoverageScale = fCoverageScale; |
| 402 } |
| 403 |
| 404 bool GrQuadEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker&
t) const { |
| 405 const QuadBatchTracker& mine = m.cast<QuadBatchTracker>(); |
| 406 const QuadBatchTracker& theirs = t.cast<QuadBatchTracker>(); |
| 407 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 408 theirs.fInputColorType, theirs.fColor) && |
| 409 mine.fCoverageScale == theirs.fCoverageScale; |
| 410 } |
| 411 |
| 302 ////////////////////////////////////////////////////////////////////////////// | 412 ////////////////////////////////////////////////////////////////////////////// |
| 303 | 413 |
| 304 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); | 414 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
| 305 | 415 |
| 306 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, | 416 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
| 307 GrContext*, | 417 GrContext*, |
| 308 const GrDrawTargetCaps& caps, | 418 const GrDrawTargetCaps& caps, |
| 309 GrTexture*[]) { | 419 GrTexture*[]) { |
| 310 GrGeometryProcessor* gp; | 420 GrGeometryProcessor* gp; |
| 311 do { | 421 do { |
| 312 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 422 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 313 random->nextULessThan(kGrProcessorEdgeTypeCnt)); | 423 random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 314 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); | 424 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); |
| 315 } while (NULL == gp); | 425 } while (NULL == gp); |
| 316 return gp; | 426 return gp; |
| 317 } | 427 } |
| 318 | 428 |
| 319 ////////////////////////////////////////////////////////////////////////////// | 429 ////////////////////////////////////////////////////////////////////////////// |
| 320 // Cubic | 430 // Cubic |
| 321 ////////////////////////////////////////////////////////////////////////////// | 431 ////////////////////////////////////////////////////////////////////////////// |
| 322 | 432 |
| 433 struct CubicBatchTracker { |
| 434 GrGPInput fInputColorType; |
| 435 GrColor fColor; |
| 436 }; |
| 437 |
| 323 class GrGLCubicEffect : public GrGLGeometryProcessor { | 438 class GrGLCubicEffect : public GrGLGeometryProcessor { |
| 324 public: | 439 public: |
| 325 GrGLCubicEffect(const GrGeometryProcessor&, | 440 GrGLCubicEffect(const GrGeometryProcessor&, |
| 326 const GrBatchTracker&); | 441 const GrBatchTracker&); |
| 327 | 442 |
| 328 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 443 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 329 | 444 |
| 330 static inline void GenKey(const GrGeometryProcessor&, | 445 static inline void GenKey(const GrGeometryProcessor&, |
| 331 const GrBatchTracker&, | 446 const GrBatchTracker&, |
| 332 const GrGLCaps&, | 447 const GrGLCaps&, |
| 333 GrProcessorKeyBuilder*); | 448 GrProcessorKeyBuilder*); |
| 334 | 449 |
| 335 virtual void setData(const GrGLProgramDataManager&, | 450 virtual void setData(const GrGLProgramDataManager& pdman, |
| 336 const GrGeometryProcessor&, | 451 const GrGeometryProcessor&, |
| 337 const GrBatchTracker&) SK_OVERRIDE {} | 452 const GrBatchTracker& bt) SK_OVERRIDE { |
| 453 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 454 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 455 GrGLfloat c[4]; |
| 456 GrColorToRGBAFloat(local.fColor, c); |
| 457 pdman.set4fv(fColorUniform, 1, c); |
| 458 fColor = local.fColor; |
| 459 } |
| 460 } |
| 338 | 461 |
| 339 private: | 462 private: |
| 463 GrColor fColor; |
| 340 GrPrimitiveEdgeType fEdgeType; | 464 GrPrimitiveEdgeType fEdgeType; |
| 465 UniformHandle fColorUniform; |
| 341 | 466 |
| 342 typedef GrGLGeometryProcessor INHERITED; | 467 typedef GrGLGeometryProcessor INHERITED; |
| 343 }; | 468 }; |
| 344 | 469 |
| 345 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, | 470 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
| 346 const GrBatchTracker&) { | 471 const GrBatchTracker&) |
| 472 : fColor(GrColor_ILLEGAL) { |
| 347 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 473 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 348 fEdgeType = ce.getEdgeType(); | 474 fEdgeType = ce.getEdgeType(); |
| 349 } | 475 } |
| 350 | 476 |
| 351 void GrGLCubicEffect::emitCode(const EmitArgs& args) { | 477 void GrGLCubicEffect::emitCode(const EmitArgs& args) { |
| 352 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 478 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 353 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 479 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
| 480 const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>(); |
| 354 | 481 |
| 355 GrGLVertToFrag v(kVec4f_GrSLType); | 482 GrGLVertToFrag v(kVec4f_GrSLType); |
| 356 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); | 483 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
| 357 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); | 484 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); |
| 358 | 485 |
| 486 // Setup pass through color |
| 487 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 488 |
| 359 // setup coord outputs | 489 // setup coord outputs |
| 360 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 490 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 361 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 491 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 362 | 492 |
| 363 // setup position varying | 493 // setup position varying |
| 364 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 494 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 365 gp.inPosition()->fName); | 495 gp.inPosition()->fName); |
| 366 | 496 |
| 367 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 497 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 368 | 498 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 575 } |
| 446 default: | 576 default: |
| 447 SkFAIL("Shouldn't get here"); | 577 SkFAIL("Shouldn't get here"); |
| 448 } | 578 } |
| 449 | 579 |
| 450 | 580 |
| 451 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); | 581 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); |
| 452 } | 582 } |
| 453 | 583 |
| 454 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, | 584 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, |
| 455 const GrBatchTracker&, | 585 const GrBatchTracker& bt, |
| 456 const GrGLCaps&, | 586 const GrGLCaps&, |
| 457 GrProcessorKeyBuilder* b) { | 587 GrProcessorKeyBuilder* b) { |
| 458 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 588 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 589 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 459 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 590 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 591 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; |
| 460 b->add32(key); | 592 b->add32(key); |
| 461 } | 593 } |
| 462 | 594 |
| 463 ////////////////////////////////////////////////////////////////////////////// | 595 ////////////////////////////////////////////////////////////////////////////// |
| 464 | 596 |
| 465 GrCubicEffect::~GrCubicEffect() {} | 597 GrCubicEffect::~GrCubicEffect() {} |
| 466 | 598 |
| 467 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 599 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 468 const GrGLCaps& caps, | 600 const GrGLCaps& caps, |
| 469 GrProcessorKeyBuilder* b) const { | 601 GrProcessorKeyBuilder* b) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 480 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 612 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 481 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", | 613 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", |
| 482 kVec4f_GrVertexAttribTyp
e)); | 614 kVec4f_GrVertexAttribTyp
e)); |
| 483 } | 615 } |
| 484 | 616 |
| 485 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 617 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 486 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); | 618 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
| 487 return (ce.fEdgeType == fEdgeType); | 619 return (ce.fEdgeType == fEdgeType); |
| 488 } | 620 } |
| 489 | 621 |
| 622 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 623 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
| 624 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 625 } |
| 626 |
| 627 bool GrCubicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { |
| 628 const CubicBatchTracker& mine = m.cast<CubicBatchTracker>(); |
| 629 const CubicBatchTracker& theirs = t.cast<CubicBatchTracker>(); |
| 630 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 631 theirs.fInputColorType, theirs.fColor); |
| 632 } |
| 633 |
| 490 ////////////////////////////////////////////////////////////////////////////// | 634 ////////////////////////////////////////////////////////////////////////////// |
| 491 | 635 |
| 492 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 636 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
| 493 | 637 |
| 494 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 638 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
| 495 GrContext*, | 639 GrContext*, |
| 496 const GrDrawTargetCaps& caps, | 640 const GrDrawTargetCaps& caps, |
| 497 GrTexture*[]) { | 641 GrTexture*[]) { |
| 498 GrGeometryProcessor* gp; | 642 GrGeometryProcessor* gp; |
| 499 do { | 643 do { |
| 500 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 644 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 501 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 645 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
| 502 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); | 646 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); |
| 503 } while (NULL == gp); | 647 } while (NULL == gp); |
| 504 return gp; | 648 return gp; |
| 505 } | 649 } |
| 506 | 650 |
| OLD | NEW |