blob: 356e87a90ca6f171b3a0c7c891f153c98bb8edc6 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2007 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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.org7ffb1b22011-03-15 21:27:08 +000020class SK_API SkColorShader : public SkShader {
reed@android.com8a1c16f2008-12-17 15:59:43 +000021public:
22 /** Create a ColorShader that will inherit its color from the Paint
23 at draw time.
24 */
reed@android.comf2b98d62010-12-20 18:26:13 +000025 SkColorShader();
reed@android.com5119bdb2009-06-12 21:27:03 +000026
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 /** 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.comf2b98d62010-12-20 18:26:13 +000031 SkColorShader(SkColor c);
32
33 virtual ~SkColorShader();
34
reed@google.com59ccef62011-12-07 14:59:50 +000035 virtual uint32_t getFlags() SK_OVERRIDE;
36 virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
junov@chromium.orgb6e16192011-12-09 15:48:03 +000037 virtual bool isOpaque() const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
reed@google.com59ccef62011-12-07 14:59:50 +000039 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.com8a1c16f2008-12-17 15:59:43 +000043
reed@google.com2be9e8b2011-07-06 21:18:09 +000044 // we return false for this, use asAGradient
reed@google.com8cad5862011-03-08 14:51:44 +000045 virtual BitmapType asABitmap(SkBitmap* outTexture,
reed@android.comf2b98d62010-12-20 18:26:13 +000046 SkMatrix* outMatrix,
reed@google.com8cad5862011-03-08 14:51:44 +000047 TileMode xy[2],
reed@google.com59ccef62011-12-07 14:59:50 +000048 SkScalar* twoPointRadialParams) const SK_OVERRIDE;
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +000049
reed@google.com59ccef62011-12-07 14:59:50 +000050 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +000051
djsollen@google.comba28d032012-03-26 17:57:35 +000052 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
djsollen@google.coma2ca41e2012-03-23 19:00:34 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054protected:
reed@google.com59ccef62011-12-07 14:59:50 +000055 SkColorShader(SkFlattenableReadBuffer&);
reed@google.com59ccef62011-12-07 14:59:50 +000056 virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
reed@google.com59ccef62011-12-07 14:59:50 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058private:
reed@google.com59ccef62011-12-07 14:59:50 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 SkColor fColor; // ignored if fInheritColor is true
61 SkPMColor fPMColor; // cached after setContext()
reed@android.com5119bdb2009-06-12 21:27:03 +000062 uint32_t fFlags; // cached after setContext()
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 uint16_t fColor16; // cached after setContext()
64 SkBool8 fInheritColor;
65
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 typedef SkShader INHERITED;
67};
68
69#endif