SkColorShader.h revision 7ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2007 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License");
58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *      http://www.apache.org/licenses/LICENSE-2.0
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS,
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License.
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkColorShader_DEFINED
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkColorShader_DEFINED
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkColorShader
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Shader that represents a single color. In general, this effect can be
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    accomplished by just using the color field on the paint, but if an
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    actual shader object is needed, this provides that feature.
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
277ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkColorShader : public SkShader {
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Create a ColorShader that will inherit its color from the Paint
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        at draw time.
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
32f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkColorShader();
335119bdb952025a30f115b9c6a187173956e55097reed@android.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Create a ColorShader that ignores the color in the paint, and uses the
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified color. Note: like all shaders, at draw time the paint's alpha
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be respected, and is applied to the specified color.
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
38f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkColorShader(SkColor c);
39f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
40f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual ~SkColorShader();
41f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
425119bdb952025a30f115b9c6a187173956e55097reed@android.com    virtual uint32_t getFlags() { return fFlags; }
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual uint8_t getSpan16Alpha() const;
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkMatrix& matrix);
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
508cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com    virtual BitmapType asABitmap(SkBitmap* outTexture,
51f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                                 SkMatrix* outMatrix,
528cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com                                 TileMode xy[2],
538cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com                                 SkScalar* twoPointRadialParams) const;
54d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
55d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org    virtual GradientType asAGradient(GradientInfo* info) const;
56d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkColorShader(SkFlattenableReadBuffer& );
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void flatten(SkFlattenableWriteBuffer& );
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual Factory getFactory() { return CreateProc; }
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
628cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com    static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
638cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com        return SkNEW_ARGS(SkColorShader, (buffer));
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkColor     fColor;         // ignored if fInheritColor is true
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPMColor   fPMColor;       // cached after setContext()
675119bdb952025a30f115b9c6a187173956e55097reed@android.com    uint32_t    fFlags;         // cached after setContext()
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint16_t    fColor16;       // cached after setContext()
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8     fInheritColor;
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
71f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    // deferred allocation, used for asABitmap()
728cad58624bc194390b14a21d0578dfcdd6fbad6freed@google.com    mutable SkPixelRef* fAsABitmapPixelRef;
73f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkShader INHERITED;
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
78