reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame^] | 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 | */ |
| 32 | SkColorShader() : fInheritColor(true) {} |
| 33 | /** Create a ColorShader that ignores the color in the paint, and uses the |
| 34 | specified color. Note: like all shaders, at draw time the paint's alpha |
| 35 | will be respected, and is applied to the specified color. |
| 36 | */ |
| 37 | SkColorShader(SkColor c) : fColor(c), fInheritColor(false) {} |
| 38 | |
| 39 | virtual uint32_t getFlags(); |
| 40 | virtual uint8_t getSpan16Alpha() const; |
| 41 | virtual bool setContext(const SkBitmap& device, const SkPaint& paint, |
| 42 | const SkMatrix& matrix); |
| 43 | virtual void shadeSpan(int x, int y, SkPMColor span[], int count); |
| 44 | virtual void shadeSpan16(int x, int y, uint16_t span[], int count); |
| 45 | virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count); |
| 46 | |
| 47 | protected: |
| 48 | SkColorShader(SkFlattenableReadBuffer& ); |
| 49 | virtual void flatten(SkFlattenableWriteBuffer& ); |
| 50 | virtual Factory getFactory() { return CreateProc; } |
| 51 | private: |
| 52 | static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { |
| 53 | return SkNEW_ARGS(SkColorShader, (buffer)); |
| 54 | } |
| 55 | SkColor fColor; // ignored if fInheritColor is true |
| 56 | SkPMColor fPMColor; // cached after setContext() |
| 57 | uint16_t fColor16; // cached after setContext() |
| 58 | SkBool8 fInheritColor; |
| 59 | |
| 60 | typedef SkShader INHERITED; |
| 61 | }; |
| 62 | |
| 63 | #endif |