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    virtual size_t contextSize() const SK_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        virtual uint32_t getFlags() const SK_OVERRIDE;
29
30        virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
31        virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE;
32
33        virtual void set3DMask(const SkMask* mask) SK_OVERRIDE {
34            // forward to our proxy
35            fShaderContext->set3DMask(mask);
36        }
37
38    private:
39        SkShader::Context* fShaderContext;
40
41        typedef SkShader::Context INHERITED;
42    };
43
44    SK_TO_STRING_OVERRIDE()
45    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFilterShader)
46
47protected:
48#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
49    SkFilterShader(SkReadBuffer&);
50#endif
51    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
52    virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
53
54
55private:
56    SkShader*       fShader;
57    SkColorFilter*  fFilter;
58
59    typedef SkShader INHERITED;
60};
61
62#endif
63