Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkError.h" | 8 #include "SkError.h" |
| 9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
| 10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } | 465 } |
| 466 | 466 |
| 467 //////////////////////////////////////////////////////////////////////////// | 467 //////////////////////////////////////////////////////////////////////////// |
| 468 | 468 |
| 469 sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { | 469 sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { |
| 470 return sk_make_sp<NormalFlatSourceImpl>(); | 470 return sk_make_sp<NormalFlatSourceImpl>(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 //////////////////////////////////////////////////////////////////////////// | 473 //////////////////////////////////////////////////////////////////////////// |
| 474 | 474 |
| 475 class SK_API NormalBevelSourceImpl : public SkNormalSource { | |
| 476 public: | |
| 477 NormalBevelSourceImpl(BevelType type, SkScalar width, SkScalar height) | |
|
robertphillips
2016/07/13 14:39:02
These seem over tabbed
dvonbeck
2016/07/13 16:09:17
Done.
| |
| 478 : fType(type) | |
| 479 , fWidth(width) | |
| 480 , fHeight(height) {} | |
| 481 | |
| 482 #if SK_SUPPORT_GPU | |
| 483 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, | |
| 484 const SkMatrix& viewM, | |
| 485 const SkMatrix* localMatrix, | |
| 486 SkFilterQuality, | |
| 487 SkSourceGammaTreatment) const override; | |
| 488 #endif | |
| 489 | |
| 490 SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, | |
| 491 void* storage) const override; | |
| 492 size_t providerSize(const SkShader::ContextRec& rec) const override; | |
| 493 | |
| 494 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalBevelSourceImpl) | |
| 495 | |
| 496 protected: | |
| 497 void flatten(SkWriteBuffer& buf) const override; | |
| 498 | |
| 499 private: | |
| 500 class Provider : public SkNormalSource::Provider { | |
| 501 public: | |
| 502 Provider(const NormalBevelSourceImpl& source); | |
| 503 | |
| 504 virtual ~Provider(); | |
| 505 | |
| 506 void fillScanLine(int x, int y, SkPoint3 output[], int count) const over ride; | |
| 507 | |
| 508 private: | |
| 509 const NormalBevelSourceImpl& fSource; | |
| 510 | |
| 511 typedef SkNormalSource::Provider INHERITED; | |
| 512 }; | |
| 513 | |
| 514 SkNormalSource::BevelType fType; | |
| 515 SkScalar fWidth; | |
| 516 SkScalar fHeight; | |
| 517 | |
| 518 typedef SkNormalSource INHERITED; | |
| 519 }; | |
| 520 | |
| 521 //////////////////////////////////////////////////////////////////////////// | |
| 522 | |
| 523 #if SK_SUPPORT_GPU | |
| 524 | |
| 525 class NormalBevelFP : public GrFragmentProcessor { | |
| 526 public: | |
| 527 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t) | |
| 528 : fType(type) | |
| 529 , fWidth(width) | |
| 530 , fHeight(height) { | |
| 531 this->initClassID<NormalBevelFP>(); | |
| 532 } | |
| 533 | |
| 534 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { | |
| 535 public: | |
|
robertphillips
2016/07/13 14:39:02
Need to init your member variables to something he
dvonbeck
2016/07/13 16:09:16
Done. Why?
robertphillips
2016/07/13 16:16:55
Normally, in onSetData you have some code like:
i
| |
| 536 GLSLNormalBevelFP() {} | |
| 537 | |
| 538 void emitCode(EmitArgs& args) override { | |
| 539 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | |
| 540 | |
| 541 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); | |
| 542 } | |
| 543 | |
| 544 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | |
| 545 GrProcessorKeyBuilder* b) { | |
| 546 b->add32(0x0); | |
| 547 } | |
| 548 | |
| 549 protected: | |
| 550 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { | |
| 551 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | |
| 552 | |
| 553 fType = normalBevelFP.fType; | |
| 554 fWidth = normalBevelFP.fWidth; | |
| 555 fHeight = normalBevelFP.fHeight; | |
| 556 } | |
| 557 | |
| 558 private: | |
|
robertphillips
2016/07/13 14:39:02
Usually these would be named fPrevType, fPrevWidth
dvonbeck
2016/07/13 16:09:17
Done.
| |
| 559 SkNormalSource::BevelType fType; | |
| 560 SkScalar fWidth; | |
| 561 SkScalar fHeight; | |
| 562 }; | |
| 563 | |
| 564 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { | |
| 565 GLSLNormalBevelFP::GenKey(*this, caps, b); | |
| 566 } | |
| 567 | |
| 568 const char* name() const override { return "NormalBevelFP"; } | |
| 569 | |
| 570 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | |
| 571 inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); | |
| 572 } | |
| 573 | |
| 574 private: | |
| 575 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalBevelFP; } | |
| 576 | |
| 577 bool onIsEqual(const GrFragmentProcessor& proc) const override { | |
| 578 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | |
| 579 return fType == normalBevelFP.fType && | |
| 580 fWidth == normalBevelFP.fWidth && | |
| 581 fHeight == normalBevelFP.fHeight; | |
| 582 } | |
| 583 | |
| 584 SkNormalSource::BevelType fType; | |
| 585 SkScalar fWidth; | |
| 586 SkScalar fHeight; | |
| 587 }; | |
| 588 | |
| 589 sk_sp<GrFragmentProcessor> NormalBevelSourceImpl::asFragmentProcessor( | |
| 590 GrContext *context, | |
| 591 const SkMatrix &viewM, | |
| 592 const SkMatrix *localMatrix, | |
| 593 SkFilterQuality filterQuality, | |
| 594 SkSourceGammaTreatment gammaTreatment) const { | |
| 595 | |
| 596 return sk_make_sp<NormalBevelFP>(fType, fWidth, fHeight); | |
| 597 } | |
| 598 | |
| 599 #endif // SK_SUPPORT_GPU | |
| 600 | |
| 601 //////////////////////////////////////////////////////////////////////////// | |
| 602 | |
| 603 NormalBevelSourceImpl::Provider::Provider(const NormalBevelSourceImpl& source) | |
|
robertphillips
2016/07/13 14:39:02
Over tabbed
dvonbeck
2016/07/13 16:09:16
Done.
| |
| 604 : fSource(source) {} | |
| 605 | |
| 606 NormalBevelSourceImpl::Provider::~Provider() {} | |
| 607 | |
| 608 SkNormalSource::Provider* NormalBevelSourceImpl::asProvider(const SkShader::Cont extRec &rec, | |
| 609 void *storage) const { | |
| 610 return new (storage) Provider(*this); | |
| 611 } | |
| 612 | |
| 613 size_t NormalBevelSourceImpl::providerSize(const SkShader::ContextRec&) const { | |
| 614 return sizeof(Provider); | |
| 615 } | |
| 616 | |
| 617 void NormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output [], | |
| 618 int count) const { | |
|
robertphillips
2016/07/13 14:39:02
I think we're leaning to always having auto as the
dvonbeck
2016/07/13 16:09:16
I don't feel like it's appropriate here, being an
| |
| 619 for (int i = 0; i < count; i++) { | |
| 620 output[i] = {0, 0, 1.0}; | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 //////////////////////////////////////////////////////////////////////////////// | |
| 625 | |
| 626 sk_sp<SkFlattenable> NormalBevelSourceImpl::CreateProc(SkReadBuffer& buf) { | |
| 627 | |
| 628 auto type = static_cast<SkNormalSource::BevelType>(buf.readInt()); | |
| 629 SkScalar width = buf.readScalar(); | |
| 630 SkScalar height = buf.readScalar(); | |
| 631 | |
| 632 return sk_make_sp<NormalBevelSourceImpl>(type, width, height); | |
| 633 } | |
| 634 | |
| 635 void NormalBevelSourceImpl::flatten(SkWriteBuffer& buf) const { | |
| 636 this->INHERITED::flatten(buf); | |
| 637 | |
| 638 buf.writeInt(static_cast<int>(fType)); | |
| 639 buf.writeScalar(fWidth); | |
| 640 buf.writeScalar(fHeight); | |
| 641 } | |
| 642 | |
| 643 //////////////////////////////////////////////////////////////////////////// | |
| 644 | |
| 645 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) { | |
| 646 return sk_make_sp<NormalBevelSourceImpl>(type, width, height); | |
| 647 } | |
| 648 | |
| 649 //////////////////////////////////////////////////////////////////////////// | |
| 650 | |
| 475 //////////////////////////////////////////////////////////////////////////// | 651 //////////////////////////////////////////////////////////////////////////// |
| 476 | 652 |
| 477 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) | 653 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
| 478 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) | 654 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
| 479 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) | 655 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) |
| 480 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 656 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 481 | 657 |
| 482 //////////////////////////////////////////////////////////////////////////// | 658 //////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |