• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkColorShader_DEFINED
18 #define SkColorShader_DEFINED
19 
20 #include "SkShader.h"
21 
22 /** \class SkColorShader
23     A Shader that represents a single color. In general, this effect can be
24     accomplished by just using the color field on the paint, but if an
25     actual shader object is needed, this provides that feature.
26 */
27 class SkColorShader : public SkShader {
28 public:
29     /** Create a ColorShader that will inherit its color from the Paint
30         at draw time.
31     */
SkColorShader()32     SkColorShader() : fFlags(0), fInheritColor(true) {}
33 
34     /** Create a ColorShader that ignores the color in the paint, and uses the
35         specified color. Note: like all shaders, at draw time the paint's alpha
36         will be respected, and is applied to the specified color.
37     */
SkColorShader(SkColor c)38     SkColorShader(SkColor c) : fColor(c), fFlags(0), fInheritColor(false) {}
39 
getFlags()40     virtual uint32_t getFlags() { return fFlags; }
41     virtual uint8_t getSpan16Alpha() const;
42     virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
43                             const SkMatrix& matrix);
44     virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
45     virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
46     virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
47 
48 protected:
49     SkColorShader(SkFlattenableReadBuffer& );
50     virtual void flatten(SkFlattenableWriteBuffer& );
getFactory()51     virtual Factory getFactory() { return CreateProc; }
52 private:
CreateProc(SkFlattenableReadBuffer & buffer)53     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
54         return SkNEW_ARGS(SkColorShader, (buffer));
55     }
56     SkColor     fColor;         // ignored if fInheritColor is true
57     SkPMColor   fPMColor;       // cached after setContext()
58     uint32_t    fFlags;         // cached after setContext()
59     uint16_t    fColor16;       // cached after setContext()
60     SkBool8     fInheritColor;
61 
62     typedef SkShader INHERITED;
63 };
64 
65 #endif
66