Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkShader.h
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkShader_DEFINED
9 #define SkShader_DEFINED
10 
11 #include "SkBitmap.h"
12 #include "SkFilterQuality.h"
13 #include "SkFlattenable.h"
14 #include "SkImageInfo.h"
15 #include "SkMask.h"
16 #include "SkMatrix.h"
17 #include "SkPaint.h"
18 #include "../gpu/GrColor.h"
19 
20 class SkArenaAlloc;
21 class SkColorFilter;
22 class SkColorSpace;
23 class SkColorSpaceXformer;
24 class SkImage;
25 class SkPath;
26 class SkPicture;
27 class SkRasterPipeline;
28 class GrContext;
29 class GrFragmentProcessor;
30 
41 class SK_API SkShader : public SkFlattenable {
42 public:
43  enum TileMode {
48 
51 
56 
57 #if 0
58 
59  kDecal_TileMode,
60 #endif
61  };
62 
63  enum {
64  kTileModeCount = kMirror_TileMode + 1
65  };
66 
73  const SkMatrix& getLocalMatrix() const;
74 
81  virtual bool isOpaque() const { return false; }
82 
83 #ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP
84 
89  bool isABitmap(SkBitmap* outTexture, SkMatrix* outMatrix, TileMode xy[2]) const;
90 
91  bool isABitmap() const {
92  return this->isABitmap(nullptr, nullptr, nullptr);
93  }
94 #endif
95 
100  SkImage* isAImage(SkMatrix* localMatrix, TileMode xy[2]) const;
101 
102  bool isAImage() const {
103  return this->isAImage(nullptr, nullptr) != nullptr;
104  }
105 
136  kNone_GradientType,
137  kColor_GradientType,
138  kLinear_GradientType,
139  kRadial_GradientType,
140  kSweep_GradientType,
141  kConical_GradientType,
142  kLast_GradientType = kConical_GradientType
143  };
144 
145  struct GradientInfo {
147  // of fColors/fColorOffsets on input, and
148  // actual number of colors/offsets on
149  // output.
151  SkScalar* fColorOffsets;
152  SkPoint fPoint[2];
153  SkScalar fRadius[2];
155  uint32_t fGradientFlags;
156  };
157 
158  virtual GradientType asAGradient(GradientInfo* info) const;
159 
160 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
161  struct ComposeRec {
162  const SkShader* fShaderA;
163  const SkShader* fShaderB;
164  SkBlendMode fBlendMode;
165  };
166  virtual bool asACompose(ComposeRec*) const { return false; }
167 #endif
168 
170  // Methods to create combinations or variants of shaders
171 
176  sk_sp<SkShader> makeWithLocalMatrix(const SkMatrix&) const;
177 
182  sk_sp<SkShader> makeWithColorFilter(sk_sp<SkColorFilter>) const;
183 
185  // Factory methods for stock shaders
186 
190  static sk_sp<SkShader> MakeEmptyShader();
191 
196  static sk_sp<SkShader> MakeColorShader(SkColor);
197 
204  static sk_sp<SkShader> MakeColorShader(const SkColor4f&, sk_sp<SkColorSpace>);
205 
216  static sk_sp<SkShader> MakeCompose(sk_sp<SkShader> dst, sk_sp<SkShader> src,
217  SkBlendMode mode, float lerp = 1);
218 
219  /*
220  * DEPRECATED: call MakeCompose.
221  */
222  static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
223  SkBlendMode mode) {
224  return MakeCompose(std::move(dst), std::move(src), mode, 1);
225  }
226 
236  return MakeCompose(std::move(dst), std::move(src), SkBlendMode::kSrc, lerp);
237  }
238 
253  static sk_sp<SkShader> MakeBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy,
254  const SkMatrix* localMatrix = nullptr);
255 
256  // NOTE: You can create an SkImage Shader with SkImage::newShader().
257 
272  static sk_sp<SkShader> MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy,
273  const SkMatrix* localMatrix, const SkRect* tile);
274 
279  // TODO: clean up clients, move to SkShaderBase.
280  virtual sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const;
281 
282 private:
283  SkShader() = default;
284  friend class SkShaderBase;
285 
286  typedef SkFlattenable INHERITED;
287 };
288 
289 #endif
TileMode fTileMode
The tile mode used.
Definition: SkShader.h:154
Definition: SkColorSpace.h:59
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:25
Shaders specify the source color(s) for what is being drawn.
Definition: SkShader.h:41
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:32
static sk_sp< SkShader > MakeMixer(sk_sp< SkShader > dst, sk_sp< SkShader > src, float lerp)
Compose two shaders together using a weighted average.
Definition: SkShader.h:235
Definition: SkPoint.h:156
SkColor * fColors
The colors in the gradient.
Definition: SkShader.h:150
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:28
virtual bool isOpaque() const
Returns true if the shader is guaranteed to produce only opaque colors, subject to the SkPaint using ...
Definition: SkShader.h:81
uint32_t fGradientFlags
see SkGradientShader::Flags
Definition: SkShader.h:155
Definition: SkColor.h:179
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:37
Definition: GrContext.h:47
SkScalar * fColorOffsets
The unit offset for color transitions.
Definition: SkShader.h:151
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
int fColorCount
In-out parameter, specifies passed size.
Definition: SkShader.h:146
GradientType
If the shader subclass can be represented as a gradient, asAGradient returns the matching GradientTyp...
Definition: SkShader.h:135
Definition: SkRect.h:404
TileMode
Definition: SkShader.h:43
replicate the edge color if the shader draws outside of its original bounds
Definition: SkShader.h:47
Definition: SkShader.h:145
repeat the shader's image horizontally and vertically
Definition: SkShader.h:50
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:48
repeat the shader's image horizontally and vertically, alternating mirror images so that adjacent ima...
Definition: SkShader.h:55