1/*
2 * Copyright 2012 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 SkFilterShader_DEFINED
9#define SkFilterShader_DEFINED
10
11#include "SkShader.h"
12
13class SkColorFilter;
14
15class SkFilterShader : public SkShader {
16public:
17    SkFilterShader(SkShader* shader, SkColorFilter* filter);
18    virtual ~SkFilterShader();
19
20    size_t contextSize() const override;
21
22    class FilterShaderContext : public SkShader::Context {
23    public:
24        // Takes ownership of shaderContext and calls its destructor.
25        FilterShaderContext(const SkFilterShader&, SkShader::Context*, const ContextRec&);
26        virtual ~FilterShaderContext();
27
28        uint32_t getFlags() const override;
29
30        void shadeSpan(int x, int y, SkPMColor[], int count) override;
31
32        void set3DMask(const SkMask* mask) override {
33            // forward to our proxy
34            fShaderContext->set3DMask(mask);
35        }
36
37    private:
38        SkShader::Context* fShaderContext;
39
40        typedef SkShader::Context INHERITED;
41    };
42
43    SK_TO_STRING_OVERRIDE()
44    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFilterShader)
45
46protected:
47    void flatten(SkWriteBuffer&) const override;
48    Context* onCreateContext(const ContextRec&, void* storage) const override;
49
50
51private:
52    SkShader*       fShader;
53    SkColorFilter*  fFilter;
54
55    typedef SkShader INHERITED;
56};
57
58#endif
59