aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorFilterShader.h
blob: 0f41a43c49d72890f59b2f1544bea0288621362b (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
58
59
60
61
62
/*
 * 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 SkColorFilterShader_DEFINED
#define SkColorFilterShader_DEFINED

#include "SkColorFilter.h"
#include "SkShader.h"

class SkColorFilterShader : public SkShader {
public:
    SkColorFilterShader(SkShader* shader, SkColorFilter* filter);

#if SK_SUPPORT_GPU
    const GrFragmentProcessor* asFragmentProcessor(GrContext*,
                                                   const SkMatrix& viewM,
                                                   const SkMatrix* localMatrix,
                                                   SkFilterQuality) const override;
#endif

    class FilterShaderContext : public SkShader::Context {
    public:
        // Takes ownership of shaderContext and calls its destructor.
        FilterShaderContext(const SkColorFilterShader&, SkShader::Context*, const ContextRec&);
        virtual ~FilterShaderContext();
        
        uint32_t getFlags() const override;
        
        void shadeSpan(int x, int y, SkPMColor[], int count) override;
        void shadeSpan4f(int x, int y, SkPM4f[], int count) override;

        void set3DMask(const SkMask* mask) override {
            // forward to our proxy
            fShaderContext->set3DMask(mask);
        }
        
    private:
        SkShader::Context* fShaderContext;
        
        typedef SkShader::Context INHERITED;
    };
    
    SK_TO_STRING_OVERRIDE()
    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorFilterShader)
    
protected:
    void flatten(SkWriteBuffer&) const override;
    size_t onContextSize(const ContextRec&) const override;
    Context* onCreateContext(const ContextRec&, void* storage) const override;
    
private:
    SkAutoTUnref<SkShader>      fShader;
    SkAutoTUnref<SkColorFilter> fFilter;
    
    typedef SkShader INHERITED;
};

#endif