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     sk_sp<GrFragmentProcessor> asFragmentProcessor(const SkShader::AsFPArgs&) const override;
     21 #endif
     22 
     23     SkNormalSource::Provider* asProvider(const SkShader::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 SkShader::ContextRec& rec, SkMatrix* normTotalInverse) const;
     32 
     33 private:
     34     class Provider : public SkNormalSource::Provider {
     35     public:
     36         Provider(const SkNormalMapSourceImpl& source, SkShader::Context* mapContext);
     37 
     38         void fillScanLine(int x, int y, SkPoint3 output[], int count) const override;
     39 
     40     private:
     41         const SkNormalMapSourceImpl& fSource;
     42         SkShader::Context* fMapContext;
     43 
     44         typedef SkNormalSource::Provider INHERITED;
     45     };
     46 
     47     sk_sp<SkShader> fMapShader;
     48     SkMatrix        fInvCTM; // Inverse of the canvas total matrix, used for rotating normals.
     49 
     50     friend class SkNormalSource;
     51 
     52     typedef SkNormalSource INHERITED;
     53 };
     54 
     55 #endif
     56 
     57