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 "SkNormalMapSource.h" | 8 #include "SkNormalMapSource.h" |
9 | 9 |
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 "SkNormalSourcePriv.h" |
13 #include "SkPM4f.h" | 14 #include "SkPM4f.h" |
14 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
15 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
16 | 17 |
17 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
18 #include "GrCoordTransform.h" | 19 #include "GrCoordTransform.h" |
19 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
20 #include "GrTextureParams.h" | 21 #include "GrTextureParams.h" |
21 #include "glsl/GrGLSLFragmentProcessor.h" | 22 #include "glsl/GrGLSLFragmentProcessor.h" |
22 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 23 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
23 #include "SkGr.h" | 24 #include "SkGr.h" |
24 | 25 |
25 class NormalMapFP : public GrFragmentProcessor { | 26 class NormalMapFP : public GrFragmentProcessor { |
26 public: | 27 public: |
27 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) | 28 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) |
28 : fInvCTM(invCTM) { | 29 : fInvCTM(invCTM) { |
29 this->registerChildProcessor(mapFP); | 30 this->registerChildProcessor(mapFP); |
30 | 31 |
31 this->initClassID<NormalMapFP>(); | 32 this->initClassID<NormalMapFP>(); |
32 } | 33 } |
33 | 34 |
34 class GLSLNormalMapFP : public GrGLSLFragmentProcessor { | 35 class GLSLNormalMapFP : public GLSLNormalFP { |
35 public: | 36 public: |
36 GLSLNormalMapFP() | 37 GLSLNormalMapFP() |
37 : fColumnMajorInvCTM22{0.0f} {} | 38 : fColumnMajorInvCTM22{0.0f} {} |
38 | 39 |
39 void emitCode(EmitArgs& args) override { | 40 void onEmitCode(EmitArgs& args) override { |
40 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 41 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
41 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 42 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
42 | 43 |
43 // add uniform | 44 // add uniform |
44 const char* xformUniName = nullptr; | 45 const char* xformUniName = nullptr; |
45 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, | 46 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, |
46 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); | 47 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); |
47 | 48 |
48 SkString dstNormalColorName("dstNormalColor"); | 49 SkString dstNormalColorName("dstNormalColor"); |
49 this->emitChild(0, nullptr, &dstNormalColorName, args); | 50 this->emitChild(0, nullptr, &dstNormalColorName, args); |
50 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", | 51 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", |
(...skipping 20 matching lines...) Expand all Loading... |
71 args.fOutputColor); | 72 args.fOutputColor); |
72 fragBuilder->codeAppend( "}"); | 73 fragBuilder->codeAppend( "}"); |
73 } | 74 } |
74 | 75 |
75 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 76 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
76 GrProcessorKeyBuilder* b) { | 77 GrProcessorKeyBuilder* b) { |
77 b->add32(0x0); | 78 b->add32(0x0); |
78 } | 79 } |
79 | 80 |
80 protected: | 81 protected: |
81 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { | 82 void setNormalData(const GrGLSLProgramDataManager& pdman, |
| 83 const GrProcessor& proc) override { |
82 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); | 84 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); |
83 | 85 |
84 const SkMatrix& invCTM = normalMapFP.invCTM(); | 86 const SkMatrix& invCTM = normalMapFP.invCTM(); |
85 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); | 87 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); |
86 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); | 88 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); |
87 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); | 89 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); |
88 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); | 90 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); |
89 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); | 91 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); |
90 } | 92 } |
91 | 93 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 258 |
257 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { | 259 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { |
258 SkMatrix invCTM; | 260 SkMatrix invCTM; |
259 | 261 |
260 if (!ctm.invert(&invCTM) || !map) { | 262 if (!ctm.invert(&invCTM) || !map) { |
261 return nullptr; | 263 return nullptr; |
262 } | 264 } |
263 | 265 |
264 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); | 266 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); |
265 } | 267 } |
OLD | NEW |