| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrFragmentProcessor.h" | 8 #include "GrFragmentProcessor.h" |
| 9 #include "GrCoordTransform.h" | 9 #include "GrCoordTransform.h" |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 }; | 252 }; |
| 253 if (!fp) { | 253 if (!fp) { |
| 254 return nullptr; | 254 return nullptr; |
| 255 } | 255 } |
| 256 return sk_sp<GrFragmentProcessor>(new PremulFragmentProcessor(std::move(fp))
); | 256 return sk_sp<GrFragmentProcessor>(new PremulFragmentProcessor(std::move(fp))
); |
| 257 } | 257 } |
| 258 | 258 |
| 259 ////////////////////////////////////////////////////////////////////////////// | 259 ////////////////////////////////////////////////////////////////////////////// |
| 260 | 260 |
| 261 sk_sp<GrFragmentProcessor> GrFragmentProcessor::OverrideInput(sk_sp<GrFragmentPr
ocessor> fp, | 261 sk_sp<GrFragmentProcessor> GrFragmentProcessor::OverrideInput(sk_sp<GrFragmentPr
ocessor> fp, |
| 262 GrColor color) { | 262 GrColor4f color) { |
| 263 class ReplaceInputFragmentProcessor : public GrFragmentProcessor { | 263 class ReplaceInputFragmentProcessor : public GrFragmentProcessor { |
| 264 public: | 264 public: |
| 265 ReplaceInputFragmentProcessor(sk_sp<GrFragmentProcessor> child, GrColor
color) | 265 ReplaceInputFragmentProcessor(sk_sp<GrFragmentProcessor> child, GrColor4
f color) |
| 266 : fColor(color) { | 266 : fColor(color) { |
| 267 this->initClassID<ReplaceInputFragmentProcessor>(); | 267 this->initClassID<ReplaceInputFragmentProcessor>(); |
| 268 this->registerChildProcessor(std::move(child)); | 268 this->registerChildProcessor(std::move(child)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 const char* name() const override { return "Replace Color"; } | 271 const char* name() const override { return "Replace Color"; } |
| 272 | 272 |
| 273 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { | 273 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 274 class GLFP : public GrGLSLFragmentProcessor { | 274 class GLFP : public GrGLSLFragmentProcessor { |
| 275 public: | 275 public: |
| 276 GLFP() : fHaveSetColor(false) {} | 276 GLFP() : fHaveSetColor(false) {} |
| 277 void emitCode(EmitArgs& args) override { | 277 void emitCode(EmitArgs& args) override { |
| 278 const char* colorName; | 278 const char* colorName; |
| 279 fColorUni = args.fUniformHandler->addUniform(kFragment_GrSha
derFlag, | 279 fColorUni = args.fUniformHandler->addUniform(kFragment_GrSha
derFlag, |
| 280 kVec4f_GrSLType
, | 280 kVec4f_GrSLType
, |
| 281 kDefault_GrSLPr
ecision, | 281 kDefault_GrSLPr
ecision, |
| 282 "Color", &color
Name); | 282 "Color", &color
Name); |
| 283 this->emitChild(0, colorName, args); | 283 this->emitChild(0, colorName, args); |
| 284 } | 284 } |
| 285 | 285 |
| 286 private: | 286 private: |
| 287 void onSetData(const GrGLSLProgramDataManager& pdman, | 287 void onSetData(const GrGLSLProgramDataManager& pdman, |
| 288 const GrProcessor& fp) override { | 288 const GrProcessor& fp) override { |
| 289 GrColor color = fp.cast<ReplaceInputFragmentProcessor>().fCo
lor; | 289 GrColor4f color = fp.cast<ReplaceInputFragmentProcessor>().f
Color; |
| 290 if (!fHaveSetColor || color != fPreviousColor) { | 290 if (!fHaveSetColor || color != fPreviousColor) { |
| 291 static const float scale = 1.f / 255.f; | 291 pdman.set4fv(fColorUni, 1, color.fRGBA); |
| 292 float floatColor[4] = { | |
| 293 GrColorUnpackR(color) * scale, | |
| 294 GrColorUnpackG(color) * scale, | |
| 295 GrColorUnpackB(color) * scale, | |
| 296 GrColorUnpackA(color) * scale, | |
| 297 }; | |
| 298 pdman.set4fv(fColorUni, 1, floatColor); | |
| 299 fPreviousColor = color; | 292 fPreviousColor = color; |
| 300 fHaveSetColor = true; | 293 fHaveSetColor = true; |
| 301 } | 294 } |
| 302 } | 295 } |
| 303 | 296 |
| 304 GrGLSLProgramDataManager::UniformHandle fColorUni; | 297 GrGLSLProgramDataManager::UniformHandle fColorUni; |
| 305 bool fHaveSetColor; | 298 bool fHaveSetColor; |
| 306 GrColor fPreviousColor; | 299 GrColor4f fPreviousColor; |
| 307 }; | 300 }; |
| 308 | 301 |
| 309 return new GLFP; | 302 return new GLFP; |
| 310 } | 303 } |
| 311 | 304 |
| 312 private: | 305 private: |
| 313 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder
* b) const override | 306 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder
* b) const override |
| 314 {} | 307 {} |
| 315 | 308 |
| 316 bool onIsEqual(const GrFragmentProcessor& that) const override { | 309 bool onIsEqual(const GrFragmentProcessor& that) const override { |
| 317 return fColor == that.cast<ReplaceInputFragmentProcessor>().fColor; | 310 return fColor == that.cast<ReplaceInputFragmentProcessor>().fColor; |
| 318 } | 311 } |
| 319 | 312 |
| 320 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 313 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 321 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, | 314 inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor(), |
| 322 GrInvariantOutput::kWillNot_ReadInput); | 315 GrInvariantOutput::kWillNot_ReadInput); |
| 323 this->childProcessor(0).computeInvariantOutput(inout); | 316 this->childProcessor(0).computeInvariantOutput(inout); |
| 324 } | 317 } |
| 325 | 318 |
| 326 GrColor fColor; | 319 GrColor4f fColor; |
| 327 }; | 320 }; |
| 328 | 321 |
| 329 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); | 322 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); |
| 330 fp->computeInvariantOutput(&childOut); | 323 fp->computeInvariantOutput(&childOut); |
| 331 if (childOut.willUseInputColor()) { | 324 if (childOut.willUseInputColor()) { |
| 332 return sk_sp<GrFragmentProcessor>(new ReplaceInputFragmentProcessor(std:
:move(fp), color)); | 325 return sk_sp<GrFragmentProcessor>(new ReplaceInputFragmentProcessor(std:
:move(fp), color)); |
| 333 } else { | 326 } else { |
| 334 return fp; | 327 return fp; |
| 335 } | 328 } |
| 336 } | 329 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } else { | 406 } else { |
| 414 series += firstIdx; | 407 series += firstIdx; |
| 415 cnt -= firstIdx; | 408 cnt -= firstIdx; |
| 416 } | 409 } |
| 417 | 410 |
| 418 if (1 == cnt) { | 411 if (1 == cnt) { |
| 419 return series[0]; | 412 return series[0]; |
| 420 } | 413 } |
| 421 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); | 414 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); |
| 422 } | 415 } |
| OLD | NEW |