Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: src/core/SkNormalSource.cpp

Issue 2080993002: Added API for Bevel NormalSource. (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-diffuse-api-change
Patch Set: Style fixes, serialization fixes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 27
28 #if SK_SUPPORT_GPU 28 #if SK_SUPPORT_GPU
29 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, 29 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
30 const SkMatrix& viewM, 30 const SkMatrix& viewM,
31 const SkMatrix* localMatrix, 31 const SkMatrix* localMatrix,
32 SkFilterQuality, 32 SkFilterQuality,
33 SkSourceGammaTreatment) const override; 33 SkSourceGammaTreatment) const override;
34 #endif 34 #endif
35 35
36 SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, 36 SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec,
37 void* storage) const ov erride; 37 void* storage) const override;
38 size_t providerSize(const SkShader::ContextRec& rec) const override;
38 39
39 size_t providerSize(const SkShader::ContextRec& rec) const override;
40 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalMapSourceImpl) 40 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalMapSourceImpl)
41 41
42 protected: 42 protected:
43 void flatten(SkWriteBuffer& buf) const override; 43 void flatten(SkWriteBuffer& buf) const override;
44 44
45 bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* norm TotalInverse) const; 45 bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* norm TotalInverse) const;
46 46
47 private: 47 private:
48 class Provider : public SkNormalSource::Provider { 48 class Provider : public SkNormalSource::Provider {
49 public: 49 public:
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
egdaniel 2016/07/14 17:23:30 I feel like this should be in its own file. Same w
dvonbeck 2016/07/22 15:08:22 Done.
476 public:
477 NormalBevelSourceImpl(BevelType type, SkScalar width, SkScalar height)
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 friend class SkNormalSource;
519
520 typedef SkNormalSource INHERITED;
521 };
522
523 ////////////////////////////////////////////////////////////////////////////
524
525 #if SK_SUPPORT_GPU
526
527 class NormalBevelFP : public GrFragmentProcessor {
528 public:
529 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t)
530 : fType(type)
531 , fWidth(width)
532 , fHeight(height) {
533 this->initClassID<NormalBevelFP>();
534 }
535
536 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor {
537 public:
538 GLSLNormalBevelFP() {
539 fPrevType = SkNormalSource::BevelType::kLinear;
540 fPrevWidth = SkFloatToScalar(0.0f);
541 fPrevHeight = SkFloatToScalar(0.0f);
542 }
543
544 void emitCode(EmitArgs& args) override {
545 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
546
547 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor );
548 }
549
550 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
551 GrProcessorKeyBuilder* b) {
552 b->add32(0x0);
553 }
554
555 protected:
556 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
557 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>();
558
559 fPrevType = normalBevelFP.fType;
560 fPrevWidth = normalBevelFP.fWidth;
561 fPrevHeight = normalBevelFP.fHeight;
562 }
563
564 private:
565 SkNormalSource::BevelType fPrevType;
566 SkScalar fPrevWidth;
567 SkScalar fPrevHeight;
568 };
569
570 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {
571 GLSLNormalBevelFP::GenKey(*this, caps, b);
572 }
573
574 const char* name() const override { return "NormalBevelFP"; }
575
576 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
577 inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput);
578 }
579
580 private:
581 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalBevelFP; }
582
583 bool onIsEqual(const GrFragmentProcessor& proc) const override {
584 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>();
585 return fType == normalBevelFP.fType &&
586 fWidth == normalBevelFP.fWidth &&
587 fHeight == normalBevelFP.fHeight;
588 }
589
590 SkNormalSource::BevelType fType;
591 SkScalar fWidth;
592 SkScalar fHeight;
593 };
594
595 sk_sp<GrFragmentProcessor> NormalBevelSourceImpl::asFragmentProcessor(
596 GrContext *context,
597 const SkMatrix &viewM,
598 const SkMatrix *localMatrix,
599 SkFilterQuality filterQuality,
600 SkSourceGammaTreatment gammaTreatment) const {
601
602 return sk_make_sp<NormalBevelFP>(fType, fWidth, fHeight);
603 }
604
605 #endif // SK_SUPPORT_GPU
606
607 ////////////////////////////////////////////////////////////////////////////
608
609 NormalBevelSourceImpl::Provider::Provider(const NormalBevelSourceImpl& source)
610 : fSource(source) {}
611
612 NormalBevelSourceImpl::Provider::~Provider() {}
613
614 SkNormalSource::Provider* NormalBevelSourceImpl::asProvider(const SkShader::Cont extRec &rec,
615 void *storage) const {
616 return new (storage) Provider(*this);
617 }
618
619 size_t NormalBevelSourceImpl::providerSize(const SkShader::ContextRec&) const {
620 return sizeof(Provider);
621 }
622
623 void NormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output [],
624 int count) const {
625 for (int i = 0; i < count; i++) {
626 output[i] = {0, 0, 1.0};
627 }
628 }
629
630 ////////////////////////////////////////////////////////////////////////////////
631
632 sk_sp<SkFlattenable> NormalBevelSourceImpl::CreateProc(SkReadBuffer& buf) {
633
634 auto type = static_cast<SkNormalSource::BevelType>(buf.readInt());
635 SkScalar width = buf.readScalar();
636 SkScalar height = buf.readScalar();
637
638 return sk_make_sp<NormalBevelSourceImpl>(type, width, height);
639 }
640
641 void NormalBevelSourceImpl::flatten(SkWriteBuffer& buf) const {
642 this->INHERITED::flatten(buf);
643
644 buf.writeInt(static_cast<int>(fType));
645 buf.writeScalar(fWidth);
646 buf.writeScalar(fHeight);
647 }
648
649 ////////////////////////////////////////////////////////////////////////////
650
651 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) {
652 return sk_make_sp<NormalBevelSourceImpl>(type, width, height);
653 }
654
655 ////////////////////////////////////////////////////////////////////////////
656
475 //////////////////////////////////////////////////////////////////////////// 657 ////////////////////////////////////////////////////////////////////////////
476 658
477 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) 659 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource)
478 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) 660 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl)
479 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) 661 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl)
662 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl)
480 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 663 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
481 664
482 //////////////////////////////////////////////////////////////////////////// 665 ////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698