Home | History | Annotate | Download | only in core
      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:
     15     SkNormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
     16             : fMapShader(std::move(mapShader))
     17             , fInvCTM(invCTM) {}
     18 
     19 #if SK_SUPPORT_GPU
     20     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs& args) const override;
     21 #endif
     22 
     23     SkNormalSource::Provider* asProvider(const SkShaderBase::ContextRec& rec,
     24                                          SkArenaAlloc* alloc) const override;
     25 
     26 protected:
     27     void flatten(SkWriteBuffer& buf) const override;
     28 
     29     bool computeNormTotalInverse(const SkShaderBase::ContextRec& rec,
     30                                  SkMatrix* normTotalInverse) const;
     31 
     32 private:
     33     SK_FLATTENABLE_HOOKS(SkNormalMapSourceImpl)
     34 
     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