epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2007 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkColorShader_DEFINED |
| 11 | #define SkColorShader_DEFINED |
| 12 | |
| 13 | #include "SkShader.h" |
| 14 | |
| 15 | /** \class SkColorShader |
| 16 | A Shader that represents a single color. In general, this effect can be |
| 17 | accomplished by just using the color field on the paint, but if an |
| 18 | actual shader object is needed, this provides that feature. |
| 19 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 20 | class SK_API SkColorShader : public SkShader { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | public: |
| 22 | /** Create a ColorShader that will inherit its color from the Paint |
| 23 | at draw time. |
| 24 | */ |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 25 | SkColorShader(); |
reed@android.com | 5119bdb | 2009-06-12 21:27:03 +0000 | [diff] [blame] | 26 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | /** Create a ColorShader that ignores the color in the paint, and uses the |
| 28 | specified color. Note: like all shaders, at draw time the paint's alpha |
| 29 | will be respected, and is applied to the specified color. |
| 30 | */ |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 31 | SkColorShader(SkColor c); |
| 32 | |
| 33 | virtual ~SkColorShader(); |
| 34 | |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 35 | virtual uint32_t getFlags() SK_OVERRIDE; |
| 36 | virtual uint8_t getSpan16Alpha() const SK_OVERRIDE; |
junov@chromium.org | b6e1619 | 2011-12-09 15:48:03 +0000 | [diff] [blame] | 37 | virtual bool isOpaque() const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | virtual bool setContext(const SkBitmap& device, const SkPaint& paint, |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 39 | const SkMatrix& matrix) SK_OVERRIDE; |
| 40 | virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE; |
| 41 | virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE; |
| 42 | virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | |
reed@google.com | 2be9e8b | 2011-07-06 21:18:09 +0000 | [diff] [blame] | 44 | // we return false for this, use asAGradient |
reed@google.com | 8cad586 | 2011-03-08 14:51:44 +0000 | [diff] [blame] | 45 | virtual BitmapType asABitmap(SkBitmap* outTexture, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 46 | SkMatrix* outMatrix, |
reed@google.com | 8cad586 | 2011-03-08 14:51:44 +0000 | [diff] [blame] | 47 | TileMode xy[2], |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 48 | SkScalar* twoPointRadialParams) const SK_OVERRIDE; |
vandebo@chromium.org | d3ae779 | 2011-02-24 00:21:06 +0000 | [diff] [blame] | 49 | |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 50 | virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; |
vandebo@chromium.org | d3ae779 | 2011-02-24 00:21:06 +0000 | [diff] [blame] | 51 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 52 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 53 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | protected: |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 55 | SkColorShader(SkFlattenableReadBuffer&); |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 56 | virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE; |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 57 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | private: |
reed@google.com | 59ccef6 | 2011-12-07 14:59:50 +0000 | [diff] [blame] | 59 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | SkColor fColor; // ignored if fInheritColor is true |
| 61 | SkPMColor fPMColor; // cached after setContext() |
reed@android.com | 5119bdb | 2009-06-12 21:27:03 +0000 | [diff] [blame] | 62 | uint32_t fFlags; // cached after setContext() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | uint16_t fColor16; // cached after setContext() |
| 64 | SkBool8 fInheritColor; |
| 65 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | typedef SkShader INHERITED; |
| 67 | }; |
| 68 | |
| 69 | #endif |