18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2007 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkColorShader_DEFINED
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkColorShader_DEFINED
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkColorShader
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Shader that represents a single color. In general, this effect can be
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    accomplished by just using the color field on the paint, but if an
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    actual shader object is needed, this provides that feature.
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
187ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkColorShader : public SkShader {
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Create a ColorShader that ignores the color in the paint, and uses the
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified color. Note: like all shaders, at draw time the paint's alpha
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be respected, and is applied to the specified color.
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2476a3b2abd02841c4ae786ac4cf59c3a51c545f73commit-bot@chromium.org    explicit SkColorShader(SkColor c);
25f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
266e5671d8c9b2d9885e351b631b1dfbb4ed403789commit-bot@chromium.org    virtual bool isOpaque() const SK_OVERRIDE;
2787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
2887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    virtual size_t contextSize() const SK_OVERRIDE {
2987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        return sizeof(ColorShaderContext);
3087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    }
3187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
3287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    class ColorShaderContext : public SkShader::Context {
3387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    public:
34e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org        ColorShaderContext(const SkColorShader& shader, const ContextRec&);
3587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
3687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual uint32_t getFlags() const SK_OVERRIDE;
3787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
3887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
3987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
4087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
4187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    private:
4387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        SkPMColor   fPMColor;
4487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        uint32_t    fFlags;
4587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        uint16_t    fColor16;
4687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        typedef SkShader::Context INHERITED;
4887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    };
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
502be9e8b407624fa696854b78b407b97a01dbb703reed@google.com    // we return false for this, use asAGradient
518cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com    virtual BitmapType asABitmap(SkBitmap* outTexture,
52f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                                 SkMatrix* outMatrix,
5391f319c5dc4493384f0a52aaeef3dcc311ef6ed0rileya@google.com                                 TileMode xy[2]) const SK_OVERRIDE;
54d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
55cc9dbfb1d21098c267d8b398b51a1db95e5099b5skia.committer@gmail.com    virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
56d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
57b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix*, GrColor*,
58b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt                                     GrFragmentProcessor**) const SK_OVERRIDE;
599de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
600f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org    SK_TO_STRING_OVERRIDE()
61ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
62a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
648b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    SkColorShader(SkReadBuffer&);
658b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
66ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org    virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
678367b8cb7a6b2f163ee41365323cb219b7049b15reed    virtual bool onAsLuminanceColor(SkColor* lum) const SK_OVERRIDE {
688367b8cb7a6b2f163ee41365323cb219b7049b15reed        *lum = fColor;
698367b8cb7a6b2f163ee41365323cb219b7049b15reed        return true;
708367b8cb7a6b2f163ee41365323cb219b7049b15reed    }
7159ccef695cef28a74ab2ea13d5a6c9017af45402reed@google.com
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
738367b8cb7a6b2f163ee41365323cb219b7049b15reed    SkColor fColor;
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkShader INHERITED;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
79