1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2007 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkColorShader_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkColorShader_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkColorShader
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Shader that represents a single color. In general, this effect can be
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    accomplished by just using the color field on the paint, but if an
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    actual shader object is needed, this provides that feature.
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
207ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkColorShader : public SkShader {
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Create a ColorShader that ignores the color in the paint, and uses the
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified color. Note: like all shaders, at draw time the paint's alpha
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be respected, and is applied to the specified color.
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2676a3b2abd02841c4ae786ac4cf59c3a51c545f73commit-bot@chromium.org    explicit SkColorShader(SkColor c);
27f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
286e5671d8c9b2d9885e351b631b1dfbb4ed403789commit-bot@chromium.org    virtual bool isOpaque() const SK_OVERRIDE;
2987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
3087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    virtual size_t contextSize() const SK_OVERRIDE {
3187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        return sizeof(ColorShaderContext);
3287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    }
3387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
3487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    class ColorShaderContext : public SkShader::Context {
3587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    public:
36e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org        ColorShaderContext(const SkColorShader& shader, const ContextRec&);
3787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
3887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual uint32_t getFlags() const SK_OVERRIDE;
3987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
4087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
4187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
4287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
4387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    private:
4587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        SkPMColor   fPMColor;
4687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        uint32_t    fFlags;
4787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        uint16_t    fColor16;
4887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        typedef SkShader::Context INHERITED;
5087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    };
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
522be9e8b407624fa696854b78b407b97a01dbb703reed@google.com    // we return false for this, use asAGradient
538cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com    virtual BitmapType asABitmap(SkBitmap* outTexture,
54f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                                 SkMatrix* outMatrix,
5591f319c5dc4493384f0a52aaeef3dcc311ef6ed0rileya@google.com                                 TileMode xy[2]) const SK_OVERRIDE;
56d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
57cc9dbfb1d21098c267d8b398b51a1db95e5099b5skia.committer@gmail.com    virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
58d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
599de5b514d38c5b36066bcdc14fba2f7e5196d372dandov    virtual bool asNewEffect(GrContext* context, const SkPaint& paint,
609de5b514d38c5b36066bcdc14fba2f7e5196d372dandov                             const SkMatrix* localMatrix, GrColor* grColor,
619de5b514d38c5b36066bcdc14fba2f7e5196d372dandov                             GrEffectRef** grEffect) const SK_OVERRIDE;
629de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
630f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org    SK_TO_STRING_OVERRIDE()
64ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
65a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
678b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    SkColorShader(SkReadBuffer&);
688b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
69ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org    virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
7059ccef695cef28a74ab2ea13d5a6c9017af45402reed@google.com
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkColor     fColor;         // ignored if fInheritColor is true
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkShader INHERITED;
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
78