| 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 GPInput fInputColorType; |
| 17 GrColor fColor; |
| 18 }; |
| 19 |
| 15 class GrGLConicEffect : public GrGLGeometryProcessor { | 20 class GrGLConicEffect : public GrGLGeometryProcessor { |
| 16 public: | 21 public: |
| 17 GrGLConicEffect(const GrGeometryProcessor&, | 22 GrGLConicEffect(const GrGeometryProcessor&, |
| 18 const GrBatchTracker&); | 23 const GrBatchTracker&); |
| 19 | 24 |
| 20 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 25 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 21 | 26 |
| 22 static inline void GenKey(const GrGeometryProcessor&, | 27 static inline void GenKey(const GrGeometryProcessor&, |
| 23 const GrBatchTracker&, | 28 const GrBatchTracker&, |
| 24 const GrGLCaps&, | 29 const GrGLCaps&, |
| 25 GrProcessorKeyBuilder*); | 30 GrProcessorKeyBuilder*); |
| 26 | 31 |
| 27 virtual void setData(const GrGLProgramDataManager&, | 32 virtual void setData(const GrGLProgramDataManager& pdman, |
| 28 const GrGeometryProcessor&, | 33 const GrGeometryProcessor&, |
| 29 const GrBatchTracker&) SK_OVERRIDE {} | 34 const GrBatchTracker& bt) SK_OVERRIDE { |
| 35 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 36 this->setUniformColorIfRequired(pdman, local.fInputColorType, local.fCol
or, fColorUniform); |
| 37 } |
| 30 | 38 |
| 31 private: | 39 private: |
| 32 GrPrimitiveEdgeType fEdgeType; | 40 GrPrimitiveEdgeType fEdgeType; |
| 41 UniformHandle fColorUniform; |
| 33 | 42 |
| 34 typedef GrGLGeometryProcessor INHERITED; | 43 typedef GrGLGeometryProcessor INHERITED; |
| 35 }; | 44 }; |
| 36 | 45 |
| 37 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, | 46 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
| 38 const GrBatchTracker& bt) { | 47 const GrBatchTracker& bt) { |
| 39 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 48 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 40 fEdgeType = ce.getEdgeType(); | 49 fEdgeType = ce.getEdgeType(); |
| 41 } | 50 } |
| 42 | 51 |
| 43 void GrGLConicEffect::emitCode(const EmitArgs& args) { | 52 void GrGLConicEffect::emitCode(const EmitArgs& args) { |
| 44 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 53 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 45 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 54 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
| 55 const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>(); |
| 46 | 56 |
| 47 GrGLVertToFrag v(kVec4f_GrSLType); | 57 GrGLVertToFrag v(kVec4f_GrSLType); |
| 48 args.fPB->addVarying("ConicCoeffs", &v); | 58 args.fPB->addVarying("ConicCoeffs", &v); |
| 49 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); | 59 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
| 50 | 60 |
| 61 // Setup pass through color |
| 62 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 63 |
| 51 // setup coord outputs | 64 // setup coord outputs |
| 52 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 65 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 53 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 66 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 54 | 67 |
| 55 // setup position varying | 68 // setup position varying |
| 56 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 69 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 57 gp.inPosition()->fName); | 70 gp.inPosition()->fName); |
| 58 | 71 |
| 59 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 72 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 60 fsBuilder->codeAppend("float edgeAlpha;"); | 73 fsBuilder->codeAppend("float edgeAlpha;"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 break; | 123 break; |
| 111 } | 124 } |
| 112 default: | 125 default: |
| 113 SkFAIL("Shouldn't get here"); | 126 SkFAIL("Shouldn't get here"); |
| 114 } | 127 } |
| 115 | 128 |
| 116 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 129 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 117 } | 130 } |
| 118 | 131 |
| 119 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, | 132 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, |
| 120 const GrBatchTracker&, | 133 const GrBatchTracker& bt, |
| 121 const GrGLCaps&, | 134 const GrGLCaps&, |
| 122 GrProcessorKeyBuilder* b) { | 135 GrProcessorKeyBuilder* b) { |
| 123 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 136 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 137 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 124 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 138 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 139 key |= kUniform_GPInput == local.fInputColorType ? 0x4 : 0x8; |
| 125 b->add32(key); | 140 b->add32(key); |
| 126 } | 141 } |
| 127 | 142 |
| 128 ////////////////////////////////////////////////////////////////////////////// | 143 ////////////////////////////////////////////////////////////////////////////// |
| 129 | 144 |
| 130 GrConicEffect::~GrConicEffect() {} | 145 GrConicEffect::~GrConicEffect() {} |
| 131 | 146 |
| 132 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 147 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 133 const GrGLCaps& caps, | 148 const GrGLCaps& caps, |
| 134 GrProcessorKeyBuilder* b) const { | 149 GrProcessorKeyBuilder* b) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 145 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 160 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 146 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", | 161 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", |
| 147 kVec4f_GrVertexAttribTyp
e)); | 162 kVec4f_GrVertexAttribTyp
e)); |
| 148 } | 163 } |
| 149 | 164 |
| 150 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 165 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 151 const GrConicEffect& ce = other.cast<GrConicEffect>(); | 166 const GrConicEffect& ce = other.cast<GrConicEffect>(); |
| 152 return (ce.fEdgeType == fEdgeType); | 167 return (ce.fEdgeType == fEdgeType); |
| 153 } | 168 } |
| 154 | 169 |
| 170 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 171 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
| 172 |
| 173 local->fColor = init.fColor; |
| 174 local->fInputColorType = GetColorInputType(init, false); |
| 175 } |
| 176 |
| 177 bool GrConicEffect::onCanBatch(const GrBatchTracker& l, const GrBatchTracker& r)
const { |
| 178 const ConicBatchTracker& left = l.cast<ConicBatchTracker>(); |
| 179 const ConicBatchTracker& right = r.cast<ConicBatchTracker>(); |
| 180 return CanCombineOutput(left.fInputColorType, left.fColor, |
| 181 right.fInputColorType, right.fColor); |
| 182 } |
| 183 |
| 155 ////////////////////////////////////////////////////////////////////////////// | 184 ////////////////////////////////////////////////////////////////////////////// |
| 156 | 185 |
| 157 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); | 186 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
| 158 | 187 |
| 159 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, | 188 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
| 160 GrContext*, | 189 GrContext*, |
| 161 const GrDrawTargetCaps& caps, | 190 const GrDrawTargetCaps& caps, |
| 162 GrTexture*[]) { | 191 GrTexture*[]) { |
| 163 GrGeometryProcessor* gp; | 192 GrGeometryProcessor* gp; |
| 164 do { | 193 do { |
| 165 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 194 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 166 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 195 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
| 167 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); | 196 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); |
| 168 } while (NULL == gp); | 197 } while (NULL == gp); |
| 169 return gp; | 198 return gp; |
| 170 } | 199 } |
| 171 | 200 |
| 172 ////////////////////////////////////////////////////////////////////////////// | 201 ////////////////////////////////////////////////////////////////////////////// |
| 173 // Quad | 202 // Quad |
| 174 ////////////////////////////////////////////////////////////////////////////// | 203 ////////////////////////////////////////////////////////////////////////////// |
| 175 | 204 |
| 205 struct QuadBatchTracker { |
| 206 GPInput fInputColorType; |
| 207 GrColor fColor; |
| 208 }; |
| 209 |
| 176 class GrGLQuadEffect : public GrGLGeometryProcessor { | 210 class GrGLQuadEffect : public GrGLGeometryProcessor { |
| 177 public: | 211 public: |
| 178 GrGLQuadEffect(const GrGeometryProcessor&, | 212 GrGLQuadEffect(const GrGeometryProcessor&, |
| 179 const GrBatchTracker&); | 213 const GrBatchTracker&); |
| 180 | 214 |
| 181 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 215 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 182 | 216 |
| 183 static inline void GenKey(const GrGeometryProcessor&, | 217 static inline void GenKey(const GrGeometryProcessor&, |
| 184 const GrBatchTracker&, | 218 const GrBatchTracker&, |
| 185 const GrGLCaps&, | 219 const GrGLCaps&, |
| 186 GrProcessorKeyBuilder*); | 220 GrProcessorKeyBuilder*); |
| 187 | 221 |
| 188 virtual void setData(const GrGLProgramDataManager&, | 222 virtual void setData(const GrGLProgramDataManager& pdman, |
| 189 const GrGeometryProcessor&, | 223 const GrGeometryProcessor&, |
| 190 const GrBatchTracker&) SK_OVERRIDE {} | 224 const GrBatchTracker& bt) SK_OVERRIDE { |
| 225 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 226 this->setUniformColorIfRequired(pdman, local.fInputColorType, local.fCol
or, fColorUniform); |
| 227 } |
| 191 | 228 |
| 192 private: | 229 private: |
| 193 GrPrimitiveEdgeType fEdgeType; | 230 GrPrimitiveEdgeType fEdgeType; |
| 231 UniformHandle fColorUniform; |
| 232 |
| 194 | 233 |
| 195 typedef GrGLGeometryProcessor INHERITED; | 234 typedef GrGLGeometryProcessor INHERITED; |
| 196 }; | 235 }; |
| 197 | 236 |
| 198 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, | 237 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
| 199 const GrBatchTracker& bt) { | 238 const GrBatchTracker& bt) { |
| 200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 239 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 201 fEdgeType = ce.getEdgeType(); | 240 fEdgeType = ce.getEdgeType(); |
| 202 } | 241 } |
| 203 | 242 |
| 204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { | 243 void GrGLQuadEffect::emitCode(const EmitArgs& args) { |
| 205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 244 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 245 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
| 246 const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>(); |
| 207 | 247 |
| 208 GrGLVertToFrag v(kVec4f_GrSLType); | 248 GrGLVertToFrag v(kVec4f_GrSLType); |
| 209 args.fPB->addVarying("HairQuadEdge", &v); | 249 args.fPB->addVarying("HairQuadEdge", &v); |
| 210 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); | 250 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
| 211 | 251 |
| 252 // Setup pass through color |
| 253 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 254 |
| 212 // setup coord outputs | 255 // setup coord outputs |
| 213 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 256 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 214 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 257 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 215 | 258 |
| 216 // setup position varying | 259 // setup position varying |
| 217 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 260 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 218 gp.inPosition()->fName); | 261 gp.inPosition()->fName); |
| 219 | 262 |
| 220 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 263 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 221 fsBuilder->codeAppendf("float edgeAlpha;"); | 264 fsBuilder->codeAppendf("float edgeAlpha;"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 break; | 300 break; |
| 258 } | 301 } |
| 259 default: | 302 default: |
| 260 SkFAIL("Shouldn't get here"); | 303 SkFAIL("Shouldn't get here"); |
| 261 } | 304 } |
| 262 | 305 |
| 263 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 306 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 264 } | 307 } |
| 265 | 308 |
| 266 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, | 309 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, |
| 267 const GrBatchTracker&, | 310 const GrBatchTracker& bt, |
| 268 const GrGLCaps&, | 311 const GrGLCaps&, |
| 269 GrProcessorKeyBuilder* b) { | 312 GrProcessorKeyBuilder* b) { |
| 270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 313 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 314 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 315 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 316 key |= kUniform_GPInput == local.fInputColorType ? 0x4 : 0x8; |
| 272 b->add32(key); | 317 b->add32(key); |
| 273 } | 318 } |
| 274 | 319 |
| 275 ////////////////////////////////////////////////////////////////////////////// | 320 ////////////////////////////////////////////////////////////////////////////// |
| 276 | 321 |
| 277 GrQuadEffect::~GrQuadEffect() {} | 322 GrQuadEffect::~GrQuadEffect() {} |
| 278 | 323 |
| 279 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, | 324 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 280 const GrGLCaps& caps, | 325 const GrGLCaps& caps, |
| 281 GrProcessorKeyBuilder* b) const { | 326 GrProcessorKeyBuilder* b) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 292 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 337 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 293 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", | 338 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", |
| 294 kVec4f_GrVertexAttribTyp
e)); | 339 kVec4f_GrVertexAttribTyp
e)); |
| 295 } | 340 } |
| 296 | 341 |
| 297 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 342 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 298 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); | 343 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
| 299 return (ce.fEdgeType == fEdgeType); | 344 return (ce.fEdgeType == fEdgeType); |
| 300 } | 345 } |
| 301 | 346 |
| 347 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) cons
t { |
| 348 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
| 349 |
| 350 local->fColor = init.fColor; |
| 351 local->fInputColorType = GetColorInputType(init, false); |
| 352 } |
| 353 |
| 354 bool GrQuadEffect::onCanBatch(const GrBatchTracker& l, const GrBatchTracker& r)
const { |
| 355 const QuadBatchTracker& left = l.cast<QuadBatchTracker>(); |
| 356 const QuadBatchTracker& right = r.cast<QuadBatchTracker>(); |
| 357 return CanCombineOutput(left.fInputColorType, left.fColor, |
| 358 right.fInputColorType, right.fColor); |
| 359 } |
| 360 |
| 302 ////////////////////////////////////////////////////////////////////////////// | 361 ////////////////////////////////////////////////////////////////////////////// |
| 303 | 362 |
| 304 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); | 363 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
| 305 | 364 |
| 306 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, | 365 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
| 307 GrContext*, | 366 GrContext*, |
| 308 const GrDrawTargetCaps& caps, | 367 const GrDrawTargetCaps& caps, |
| 309 GrTexture*[]) { | 368 GrTexture*[]) { |
| 310 GrGeometryProcessor* gp; | 369 GrGeometryProcessor* gp; |
| 311 do { | 370 do { |
| 312 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 371 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 313 random->nextULessThan(kGrProcessorEdgeTypeCnt)); | 372 random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 314 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); | 373 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); |
| 315 } while (NULL == gp); | 374 } while (NULL == gp); |
| 316 return gp; | 375 return gp; |
| 317 } | 376 } |
| 318 | 377 |
| 319 ////////////////////////////////////////////////////////////////////////////// | 378 ////////////////////////////////////////////////////////////////////////////// |
| 320 // Cubic | 379 // Cubic |
| 321 ////////////////////////////////////////////////////////////////////////////// | 380 ////////////////////////////////////////////////////////////////////////////// |
| 322 | 381 |
| 382 struct CubicBatchTracker { |
| 383 GPInput fInputColorType; |
| 384 GrColor fColor; |
| 385 }; |
| 386 |
| 323 class GrGLCubicEffect : public GrGLGeometryProcessor { | 387 class GrGLCubicEffect : public GrGLGeometryProcessor { |
| 324 public: | 388 public: |
| 325 GrGLCubicEffect(const GrGeometryProcessor&, | 389 GrGLCubicEffect(const GrGeometryProcessor&, |
| 326 const GrBatchTracker&); | 390 const GrBatchTracker&); |
| 327 | 391 |
| 328 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 392 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 329 | 393 |
| 330 static inline void GenKey(const GrGeometryProcessor&, | 394 static inline void GenKey(const GrGeometryProcessor&, |
| 331 const GrBatchTracker&, | 395 const GrBatchTracker&, |
| 332 const GrGLCaps&, | 396 const GrGLCaps&, |
| 333 GrProcessorKeyBuilder*); | 397 GrProcessorKeyBuilder*); |
| 334 | 398 |
| 335 virtual void setData(const GrGLProgramDataManager&, | 399 virtual void setData(const GrGLProgramDataManager& pdman, |
| 336 const GrGeometryProcessor&, | 400 const GrGeometryProcessor&, |
| 337 const GrBatchTracker&) SK_OVERRIDE {} | 401 const GrBatchTracker& bt) SK_OVERRIDE { |
| 402 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 403 this->setUniformColorIfRequired(pdman, local.fInputColorType, local.fCol
or, fColorUniform); |
| 404 } |
| 338 | 405 |
| 339 private: | 406 private: |
| 340 GrPrimitiveEdgeType fEdgeType; | 407 GrPrimitiveEdgeType fEdgeType; |
| 408 UniformHandle fColorUniform; |
| 341 | 409 |
| 342 typedef GrGLGeometryProcessor INHERITED; | 410 typedef GrGLGeometryProcessor INHERITED; |
| 343 }; | 411 }; |
| 344 | 412 |
| 345 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, | 413 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
| 346 const GrBatchTracker&) { | 414 const GrBatchTracker&) { |
| 347 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 415 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 348 fEdgeType = ce.getEdgeType(); | 416 fEdgeType = ce.getEdgeType(); |
| 349 } | 417 } |
| 350 | 418 |
| 351 void GrGLCubicEffect::emitCode(const EmitArgs& args) { | 419 void GrGLCubicEffect::emitCode(const EmitArgs& args) { |
| 352 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 420 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 353 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 421 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
| 422 const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>(); |
| 354 | 423 |
| 355 GrGLVertToFrag v(kVec4f_GrSLType); | 424 GrGLVertToFrag v(kVec4f_GrSLType); |
| 356 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); | 425 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
| 357 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); | 426 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); |
| 358 | 427 |
| 428 // Setup pass through color |
| 429 this->setupColor(args.fPB, local.fInputColorType, args.fOutputColor, NULL, &
fColorUniform); |
| 430 |
| 359 // setup coord outputs | 431 // setup coord outputs |
| 360 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 432 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
| 361 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 433 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
| 362 | 434 |
| 363 // setup position varying | 435 // setup position varying |
| 364 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 436 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
| 365 gp.inPosition()->fName); | 437 gp.inPosition()->fName); |
| 366 | 438 |
| 367 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 439 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 368 | 440 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 517 } |
| 446 default: | 518 default: |
| 447 SkFAIL("Shouldn't get here"); | 519 SkFAIL("Shouldn't get here"); |
| 448 } | 520 } |
| 449 | 521 |
| 450 | 522 |
| 451 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); | 523 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); |
| 452 } | 524 } |
| 453 | 525 |
| 454 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, | 526 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, |
| 455 const GrBatchTracker&, | 527 const GrBatchTracker& bt, |
| 456 const GrGLCaps&, | 528 const GrGLCaps&, |
| 457 GrProcessorKeyBuilder* b) { | 529 GrProcessorKeyBuilder* b) { |
| 458 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 530 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 531 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 459 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 532 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 533 key |= kUniform_GPInput == local.fInputColorType ? 0x4 : 0x8; |
| 460 b->add32(key); | 534 b->add32(key); |
| 461 } | 535 } |
| 462 | 536 |
| 463 ////////////////////////////////////////////////////////////////////////////// | 537 ////////////////////////////////////////////////////////////////////////////// |
| 464 | 538 |
| 465 GrCubicEffect::~GrCubicEffect() {} | 539 GrCubicEffect::~GrCubicEffect() {} |
| 466 | 540 |
| 467 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 541 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 468 const GrGLCaps& caps, | 542 const GrGLCaps& caps, |
| 469 GrProcessorKeyBuilder* b) const { | 543 GrProcessorKeyBuilder* b) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 480 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 554 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 481 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", | 555 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", |
| 482 kVec4f_GrVertexAttribTyp
e)); | 556 kVec4f_GrVertexAttribTyp
e)); |
| 483 } | 557 } |
| 484 | 558 |
| 485 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 559 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 486 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); | 560 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
| 487 return (ce.fEdgeType == fEdgeType); | 561 return (ce.fEdgeType == fEdgeType); |
| 488 } | 562 } |
| 489 | 563 |
| 564 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 565 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
| 566 |
| 567 local->fColor = init.fColor; |
| 568 local->fInputColorType = GetColorInputType(init, false); |
| 569 } |
| 570 |
| 571 bool GrCubicEffect::onCanBatch(const GrBatchTracker& l, const GrBatchTracker& r)
const { |
| 572 const CubicBatchTracker& left = l.cast<CubicBatchTracker>(); |
| 573 const CubicBatchTracker& right = r.cast<CubicBatchTracker>(); |
| 574 return CanCombineOutput(left.fInputColorType, left.fColor, |
| 575 right.fInputColorType, right.fColor); |
| 576 } |
| 577 |
| 490 ////////////////////////////////////////////////////////////////////////////// | 578 ////////////////////////////////////////////////////////////////////////////// |
| 491 | 579 |
| 492 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 580 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
| 493 | 581 |
| 494 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 582 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
| 495 GrContext*, | 583 GrContext*, |
| 496 const GrDrawTargetCaps& caps, | 584 const GrDrawTargetCaps& caps, |
| 497 GrTexture*[]) { | 585 GrTexture*[]) { |
| 498 GrGeometryProcessor* gp; | 586 GrGeometryProcessor* gp; |
| 499 do { | 587 do { |
| 500 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 588 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 501 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 589 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
| 502 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); | 590 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); |
| 503 } while (NULL == gp); | 591 } while (NULL == gp); |
| 504 return gp; | 592 return gp; |
| 505 } | 593 } |
| 506 | 594 |
| OLD | NEW |