aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkNormalMapSource.h
blob: dfedfd35d532c85c40900d1877f90399c30fc8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkNormalMapSource_DEFINED
#define SkNormalMapSource_DEFINED

#include "SkNormalSource.h"

class SkNormalMapSourceImpl : public SkNormalSource {
public:
    SkNormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
            : fMapShader(std::move(mapShader))
            , fInvCTM(invCTM) {}

#if SK_SUPPORT_GPU
    std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs& args) const override;
#endif

    SkNormalSource::Provider* asProvider(const SkShaderBase::ContextRec& rec,
                                         SkArenaAlloc* alloc) const override;

    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkNormalMapSourceImpl)

protected:
    void flatten(SkWriteBuffer& buf) const override;

    bool computeNormTotalInverse(const SkShaderBase::ContextRec& rec,
                                 SkMatrix* normTotalInverse) const;

private:
    class Provider : public SkNormalSource::Provider {
    public:
        Provider(const SkNormalMapSourceImpl& source, SkShaderBase::Context* mapContext);

        void fillScanLine(int x, int y, SkPoint3 output[], int count) const override;

    private:
        const SkNormalMapSourceImpl& fSource;
        SkShaderBase::Context*       fMapContext;

        typedef SkNormalSource::Provider INHERITED;
    };

    sk_sp<SkShader> fMapShader;
    SkMatrix        fInvCTM; // Inverse of the canvas total matrix, used for rotating normals.

    friend class SkNormalSource;

    typedef SkNormalSource INHERITED;
};

#endif