• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkNormalMapSource_DEFINED
9 #define SkNormalMapSource_DEFINED
10 
11 #include "SkNormalSource.h"
12 
13 class SkNormalMapSourceImpl : public SkNormalSource {
14 public:
SkNormalMapSourceImpl(sk_sp<SkShader> mapShader,const SkMatrix & invCTM)15     SkNormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
16             : fMapShader(std::move(mapShader))
17             , fInvCTM(invCTM) {}
18 
19 #if SK_SUPPORT_GPU
20     sk_sp<GrFragmentProcessor> asFragmentProcessor(const SkShaderBase::AsFPArgs&) const override;
21 #endif
22 
23     SkNormalSource::Provider* asProvider(const SkShaderBase::ContextRec& rec,
24                                          SkArenaAlloc* alloc) const override;
25 
26     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkNormalMapSourceImpl)
27 
28 protected:
29     void flatten(SkWriteBuffer& buf) const override;
30 
31     bool computeNormTotalInverse(const SkShaderBase::ContextRec& rec,
32                                  SkMatrix* normTotalInverse) const;
33 
34 private:
35     class Provider : public SkNormalSource::Provider {
36     public:
37         Provider(const SkNormalMapSourceImpl& source, SkShaderBase::Context* mapContext);
38 
39         void fillScanLine(int x, int y, SkPoint3 output[], int count) const override;
40 
41     private:
42         const SkNormalMapSourceImpl& fSource;
43         SkShaderBase::Context*       fMapContext;
44 
45         typedef SkNormalSource::Provider INHERITED;
46     };
47 
48     sk_sp<SkShader> fMapShader;
49     SkMatrix        fInvCTM; // Inverse of the canvas total matrix, used for rotating normals.
50 
51     friend class SkNormalSource;
52 
53     typedef SkNormalSource INHERITED;
54 };
55 
56 #endif
57 
58