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

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

Issue 2114993002: GrFP can express distance vector field req., program builder declares variable for it (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-bevel-api-change
Patch Set: Removed DVF from prog builder key, not necessary 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"
11 #include "SkMatrix.h" 11 #include "SkMatrix.h"
12 #include "SkNormalSource.h" 12 #include "SkNormalSource.h"
13 #include "SkPM4f.h" 13 #include "SkPM4f.h"
14 #include "SkReadBuffer.h" 14 #include "SkReadBuffer.h"
15 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
16 16
17 // Genretating vtable 17 #if SK_SUPPORT_GPU
18 #include "GrCoordTransform.h"
19 #include "GrInvariantOutput.h"
20 #include "GrTextureParams.h"
21 #include "glsl/GrGLSLFragmentProcessor.h"
22 #include "glsl/GrGLSLFragmentShaderBuilder.h"
23 #include "SkGr.h"
24 #endif
25
26 // Generating vtable
18 SkNormalSource::~SkNormalSource() {} 27 SkNormalSource::~SkNormalSource() {}
19 28
29 #if SK_SUPPORT_GPU
30
31 // GLSLFragmentProcessors for NormalSourceImpls must sub-class this class and ov erride onEmitCode.
32 // This class exists to intercept emitCode calls and emit <0, 0, 1> if the FP re quires a distance
33 // vector but the GP doesn't provide it.
egdaniel 2016/07/13 19:27:26 Add to this comment that we don't need to adjust t
dvonbeck 2016/07/13 21:28:14 Done.
34 class GLSLNormalFP : public GrGLSLFragmentProcessor {
35 public:
36 void emitCode(EmitArgs& args) override {
37 if (args.fFp.usesDistanceVectorField() && !args.fGpImplementsDistanceVec tor) {
38 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
39 fragBuilder->codeAppendf("// GLSLNormalFP intercepted emitCode call, GP does not "
40 "implement required distance vector feature \n");
41 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor );
42 } else {
43 this->onEmitCode(args);
44 }
45 }
46 protected:
47 virtual void onEmitCode(EmitArgs& args) = 0;
48 };
49
50 #endif
51
20 /////////////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////////////
21 53
22 class NormalMapSourceImpl : public SkNormalSource { 54 class NormalMapSourceImpl : public SkNormalSource {
23 public: 55 public:
24 NormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM) 56 NormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
25 : fMapShader(std::move(mapShader)) 57 : fMapShader(std::move(mapShader))
26 , fInvCTM(invCTM) {} 58 , fInvCTM(invCTM) {}
27 59
28 #if SK_SUPPORT_GPU 60 #if SK_SUPPORT_GPU
29 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, 61 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 100
69 friend class SkNormalSource; 101 friend class SkNormalSource;
70 102
71 typedef SkNormalSource INHERITED; 103 typedef SkNormalSource INHERITED;
72 }; 104 };
73 105
74 //////////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////////
75 107
76 #if SK_SUPPORT_GPU 108 #if SK_SUPPORT_GPU
77 109
78 #include "GrCoordTransform.h"
79 #include "GrInvariantOutput.h"
80 #include "GrTextureParams.h"
81 #include "glsl/GrGLSLFragmentProcessor.h"
82 #include "glsl/GrGLSLFragmentShaderBuilder.h"
83 #include "SkGr.h"
84
85 class NormalMapFP : public GrFragmentProcessor { 110 class NormalMapFP : public GrFragmentProcessor {
86 public: 111 public:
87 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) 112 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM)
88 : fInvCTM(invCTM) { 113 : fInvCTM(invCTM) {
89 this->registerChildProcessor(mapFP); 114 this->registerChildProcessor(mapFP);
90 115
91 this->initClassID<NormalMapFP>(); 116 this->initClassID<NormalMapFP>();
92 } 117 }
93 118
94 class GLSLNormalMapFP : public GrGLSLFragmentProcessor { 119 class GLSLNormalMapFP : public GLSLNormalFP {
95 public: 120 public:
96 GLSLNormalMapFP() 121 GLSLNormalMapFP()
97 : fColumnMajorInvCTM22{0.0f} {} 122 : fColumnMajorInvCTM22{0.0f} {}
98 123
99 void emitCode(EmitArgs& args) override { 124 void onEmitCode(EmitArgs& args) override {
100 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 125 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
101 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 126 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
102 127
103 // add uniform 128 // add uniform
104 const char* xformUniName = nullptr; 129 const char* xformUniName = nullptr;
105 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2 2f_GrSLType, 130 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2 2f_GrSLType,
106 kDefault_GrSLPrecision, "Xfor m", &xformUniName); 131 kDefault_GrSLPrecision, "Xfor m", &xformUniName);
107 132
108 SkString dstNormalColorName("dstNormalColor"); 133 SkString dstNormalColorName("dstNormalColor");
109 this->emitChild(0, nullptr, &dstNormalColorName, args); 134 this->emitChild(0, nullptr, &dstNormalColorName, args);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 //////////////////////////////////////////////////////////////////////////// 400 ////////////////////////////////////////////////////////////////////////////
376 401
377 #if SK_SUPPORT_GPU 402 #if SK_SUPPORT_GPU
378 403
379 class NormalFlatFP : public GrFragmentProcessor { 404 class NormalFlatFP : public GrFragmentProcessor {
380 public: 405 public:
381 NormalFlatFP() { 406 NormalFlatFP() {
382 this->initClassID<NormalFlatFP>(); 407 this->initClassID<NormalFlatFP>();
383 } 408 }
384 409
385 class GLSLNormalFlatFP : public GrGLSLFragmentProcessor { 410 class GLSLNormalFlatFP : public GLSLNormalFP {
386 public: 411 public:
387 GLSLNormalFlatFP() {} 412 GLSLNormalFlatFP() {}
388 413
389 void emitCode(EmitArgs& args) override { 414 void onEmitCode(EmitArgs& args) override {
390 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 415 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
391
392 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); 416 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor );
393 } 417 }
394 418
395 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 419 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
396 GrProcessorKeyBuilder* b) { 420 GrProcessorKeyBuilder* b) {
397 b->add32(0x0); 421 b->add32(0x0);
398 } 422 }
399 423
400 protected: 424 protected:
401 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} 425 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 //////////////////////////////////////////////////////////////////////////// 547 ////////////////////////////////////////////////////////////////////////////
524 548
525 #if SK_SUPPORT_GPU 549 #if SK_SUPPORT_GPU
526 550
527 class NormalBevelFP : public GrFragmentProcessor { 551 class NormalBevelFP : public GrFragmentProcessor {
528 public: 552 public:
529 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t) 553 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t)
530 : fType(type) 554 : fType(type)
531 , fWidth(width) 555 , fWidth(width)
532 , fHeight(height) { 556 , fHeight(height) {
557 fUsesDistanceVectorField = true;
558
533 this->initClassID<NormalBevelFP>(); 559 this->initClassID<NormalBevelFP>();
534 } 560 }
535 561
536 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { 562 class GLSLNormalBevelFP : public GLSLNormalFP {
537 public: 563 public:
538 GLSLNormalBevelFP() { 564 GLSLNormalBevelFP() {
539 fPrevType = SkNormalSource::BevelType::kLinear; 565 fPrevType = SkNormalSource::BevelType::kLinear;
540 fPrevWidth = SkFloatToScalar(0.0f); 566 fPrevWidth = SkFloatToScalar(0.0f);
541 fPrevHeight = SkFloatToScalar(0.0f); 567 fPrevHeight = SkFloatToScalar(0.0f);
542 } 568 }
543 569
544 void emitCode(EmitArgs& args) override { 570 void onEmitCode(EmitArgs& args) override {
545 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 571 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
546 572 fragBuilder->codeAppendf("%s = normalize(vec4(0.0, 0.0, 1.0, 0.0));" ,
547 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); 573 args.fOutputColor);
548 } 574 }
549 575
550 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 576 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
551 GrProcessorKeyBuilder* b) { 577 GrProcessorKeyBuilder* b) {
552 b->add32(0x0); 578 b->add32(0x0);
553 } 579 }
554 580
555 protected: 581 protected:
556 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { 582 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
557 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); 583 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 682
657 //////////////////////////////////////////////////////////////////////////// 683 ////////////////////////////////////////////////////////////////////////////
658 684
659 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) 685 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource)
660 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) 686 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl)
661 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) 687 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl)
662 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl) 688 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl)
663 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 689 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
664 690
665 //////////////////////////////////////////////////////////////////////////// 691 ////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698