blob: 76b86a6cfe9d9eee4281e855f44f671a332daf45 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkShader_DEFINED
9#define SkShader_DEFINED
10
11#include "SkBitmap.h"
12#include "SkFlattenable.h"
13#include "SkMask.h"
14#include "SkMatrix.h"
15#include "SkPaint.h"
bsalomon4beef912014-07-28 13:43:02 -070016#include "../gpu/GrColor.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017
18class SkPath;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000019class SkPicture;
commit-bot@chromium.org79590552014-05-13 18:14:45 +000020class SkXfermode;
rileya@google.com03c1c352012-07-20 20:02:43 +000021class GrContext;
joshualittb0a8a372014-09-23 09:50:21 -070022class GrFragmentProcessor;
joshualitt9cc17752015-07-09 06:28:14 -070023class GrProcessorDataManager;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
25/** \class SkShader
reed@google.comad917992011-04-11 19:01:12 +000026 *
reed@google.com880dc472012-05-11 14:47:03 +000027 * Shaders specify the source color(s) for what is being drawn. If a paint
28 * has no shader, then the paint's color is used. If the paint has a
29 * shader, then the shader's color(s) are use instead, but they are
30 * modulated by the paint's alpha. This makes it easy to create a shader
31 * once (e.g. bitmap tiling or gradient) and then change its transparency
32 * w/o having to modify the original shader... only the paint's alpha needs
33 * to be modified.
reed@google.comad917992011-04-11 19:01:12 +000034 */
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000035class SK_API SkShader : public SkFlattenable {
reed@android.com8a1c16f2008-12-17 15:59:43 +000036public:
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000037 SkShader(const SkMatrix* localMatrix = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 virtual ~SkShader();
39
reed@google.comad917992011-04-11 19:01:12 +000040 /**
commit-bot@chromium.orgd12de022014-05-09 15:42:07 +000041 * Returns the local matrix.
scroggoc870d492014-07-11 10:42:12 -070042 *
43 * FIXME: This can be incorrect for a Shader with its own local matrix
44 * that is also wrapped via CreateLocalMatrixShader.
commit-bot@chromium.orgd12de022014-05-09 15:42:07 +000045 */
46 const SkMatrix& getLocalMatrix() const { return fLocalMatrix; }
47
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 enum TileMode {
reed@google.com0beaba52012-03-16 14:38:06 +000049 /** replicate the edge color if the shader draws outside of its
50 * original bounds
51 */
52 kClamp_TileMode,
53
54 /** repeat the shader's image horizontally and vertically */
55 kRepeat_TileMode,
56
57 /** repeat the shader's image horizontally and vertically, alternating
58 * mirror images so that adjacent images always seam
59 */
60 kMirror_TileMode,
61
62#if 0
63 /** only draw within the original domain, return 0 everywhere else */
64 kDecal_TileMode,
65#endif
reed19c25f12015-03-15 14:01:21 -070066 };
reed@android.com8a1c16f2008-12-17 15:59:43 +000067
reed19c25f12015-03-15 14:01:21 -070068 enum {
69 kTileModeCount = kMirror_TileMode + 1
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 };
71
72 // override these in your subclass
73
74 enum Flags {
75 //!< set if all of the colors will be opaque
reed@android.com3c9b2a42009-08-27 19:28:37 +000076 kOpaqueAlpha_Flag = 0x01,
reed@android.com5119bdb2009-06-12 21:27:03 +000077
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 //! set if this shader's shadeSpan16() method can be called
reed@android.com3c9b2a42009-08-27 19:28:37 +000079 kHasSpan16_Flag = 0x02,
reed@android.com5119bdb2009-06-12 21:27:03 +000080
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 /** Set this bit if the shader's native data type is instrinsically 16
82 bit, meaning that calling the 32bit shadeSpan() entry point will
83 mean the the impl has to up-sample 16bit data into 32bit. Used as a
84 a means of clearing a dither request if the it will have no effect
85 */
reed@android.com5119bdb2009-06-12 21:27:03 +000086 kIntrinsicly16_Flag = 0x04,
87
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000088 /** set if the spans only vary in X (const in Y).
reed@android.com5119bdb2009-06-12 21:27:03 +000089 e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient
reed@android.com3c9b2a42009-08-27 19:28:37 +000090 that varies from left-to-right. This flag specifies this for
91 shadeSpan().
reed@android.com5119bdb2009-06-12 21:27:03 +000092 */
reed@android.com3c9b2a42009-08-27 19:28:37 +000093 kConstInY32_Flag = 0x08,
reed@google.com7c2f27d2011-03-07 19:29:00 +000094
reed@android.com3c9b2a42009-08-27 19:28:37 +000095 /** same as kConstInY32_Flag, but is set if this is true for shadeSpan16
96 which may not always be the case, since shadeSpan16 may be
97 predithered, which would mean it was not const in Y, even though
98 the 32bit shadeSpan() would be const.
99 */
100 kConstInY16_Flag = 0x10
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101 };
102
reed@google.comad917992011-04-11 19:01:12 +0000103 /**
junov@chromium.orgb6e16192011-12-09 15:48:03 +0000104 * Returns true if the shader is guaranteed to produce only opaque
105 * colors, subject to the SkPaint using the shader to apply an opaque
106 * alpha value. Subclasses should override this to allow some
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000107 * optimizations.
junov@chromium.orgb6e16192011-12-09 15:48:03 +0000108 */
109 virtual bool isOpaque() const { return false; }
110
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000111 /**
112 * ContextRec acts as a parameter bundle for creating Contexts.
113 */
114 struct ContextRec {
reed56263c72015-06-05 11:31:26 -0700115 ContextRec(const SkPaint& paint, const SkMatrix& matrix, const SkMatrix* localM)
116 : fPaint(&paint)
commit-bot@chromium.org80116dc2014-05-06 17:16:03 +0000117 , fMatrix(&matrix)
reed56263c72015-06-05 11:31:26 -0700118 , fLocalMatrix(localM) {}
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000119
commit-bot@chromium.org80116dc2014-05-06 17:16:03 +0000120 const SkPaint* fPaint; // the current paint associated with the draw
121 const SkMatrix* fMatrix; // the current matrix in the canvas
122 const SkMatrix* fLocalMatrix; // optional local matrix
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000123 };
124
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000125 class Context : public ::SkNoncopyable {
126 public:
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000127 Context(const SkShader& shader, const ContextRec&);
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000128
129 virtual ~Context();
130
131 /**
132 * Called sometimes before drawing with this shader. Return the type of
133 * alpha your shader will return. The default implementation returns 0.
134 * Your subclass should override if it can (even sometimes) report a
135 * non-zero value, since that will enable various blitters to perform
136 * faster.
137 */
138 virtual uint32_t getFlags() const { return 0; }
139
140 /**
141 * Return the alpha associated with the data returned by shadeSpan16(). If
142 * kHasSpan16_Flag is not set, this value is meaningless.
143 */
144 virtual uint8_t getSpan16Alpha() const { return fPaintAlpha; }
145
146 /**
147 * Called for each span of the object being drawn. Your subclass should
148 * set the appropriate colors (with premultiplied alpha) that correspond
149 * to the specified device coordinates.
150 */
151 virtual void shadeSpan(int x, int y, SkPMColor[], int count) = 0;
152
153 typedef void (*ShadeProc)(void* ctx, int x, int y, SkPMColor[], int count);
154 virtual ShadeProc asAShadeProc(void** ctx);
155
156 /**
157 * Called only for 16bit devices when getFlags() returns
158 * kOpaqueAlphaFlag | kHasSpan16_Flag
159 */
160 virtual void shadeSpan16(int x, int y, uint16_t[], int count);
161
162 /**
163 * Similar to shadeSpan, but only returns the alpha-channel for a span.
164 * The default implementation calls shadeSpan() and then extracts the alpha
165 * values from the returned colors.
166 */
167 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
168
169 /**
170 * Helper function that returns true if this shader's shadeSpan16() method
171 * can be called.
172 */
173 bool canCallShadeSpan16() {
174 return SkShader::CanCallShadeSpan16(this->getFlags());
175 }
176
reedcc0e3112014-09-10 10:20:24 -0700177 // Notification from blitter::blitMask in case we need to see the non-alpha channels
178 virtual void set3DMask(const SkMask*) {}
179
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000180 protected:
181 // Reference to shader, so we don't have to dupe information.
182 const SkShader& fShader;
183
184 enum MatrixClass {
185 kLinear_MatrixClass, // no perspective
186 kFixedStepInX_MatrixClass, // fast perspective, need to call fixedStepInX() each
187 // scanline
188 kPerspective_MatrixClass // slow perspective, need to mappoints each pixel
189 };
190 static MatrixClass ComputeMatrixClass(const SkMatrix&);
191
commit-bot@chromium.org80116dc2014-05-06 17:16:03 +0000192 uint8_t getPaintAlpha() const { return fPaintAlpha; }
193 const SkMatrix& getTotalInverse() const { return fTotalInverse; }
194 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInverseClass; }
195 const SkMatrix& getCTM() const { return fCTM; }
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000196 private:
commit-bot@chromium.org80116dc2014-05-06 17:16:03 +0000197 SkMatrix fCTM;
198 SkMatrix fTotalInverse;
199 uint8_t fPaintAlpha;
200 uint8_t fTotalInverseClass;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000201
202 typedef SkNoncopyable INHERITED;
203 };
reed@google.com7c2f27d2011-03-07 19:29:00 +0000204
reed@google.comad917992011-04-11 19:01:12 +0000205 /**
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000206 * Create the actual object that does the shading.
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000207 * Size of storage must be >= contextSize.
reed@google.coma641f3f2012-12-13 22:16:30 +0000208 */
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000209 Context* createContext(const ContextRec&, void* storage) const;
reed@google.coma641f3f2012-12-13 22:16:30 +0000210
211 /**
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000212 * Return the size of a Context returned by createContext.
commit-bot@chromium.orgf3e50592014-04-30 23:29:02 +0000213 *
214 * Override this if your subclass overrides createContext, to return the correct size of
215 * your subclass' context.
reed@google.comad917992011-04-11 19:01:12 +0000216 */
commit-bot@chromium.orgf3e50592014-04-30 23:29:02 +0000217 virtual size_t contextSize() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000218
reed@google.comad917992011-04-11 19:01:12 +0000219 /**
220 * Helper to check the flags to know if it is legal to call shadeSpan16()
221 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000222 static bool CanCallShadeSpan16(uint32_t flags) {
223 return (flags & kHasSpan16_Flag) != 0;
224 }
225
scroggoff390c92015-09-08 06:24:08 -0700226#ifdef SK_SUPPORT_LEGACY_SHADERBITMAPTYPE
227public:
228#else
229protected:
230#endif
reed@google.comad917992011-04-11 19:01:12 +0000231 /**
scroggoff390c92015-09-08 06:24:08 -0700232 Gives method bitmap should be read to implement a shader.
233 Also determines number and interpretation of "extra" parameters returned
234 by asABitmap
reed@android.comf2b98d62010-12-20 18:26:13 +0000235 */
scroggoff390c92015-09-08 06:24:08 -0700236 enum BitmapType {
237 kNone_BitmapType, //<! Shader is not represented as a bitmap
238 kDefault_BitmapType,//<! Access bitmap using local coords transformed
239 };
240 /** Optional methods for shaders that can pretend to be a bitmap/texture
241 to play along with opengl. Default just returns kNone_BitmapType and
242 ignores the out parameters.
reed2d126b52015-09-07 11:10:30 -0700243
scroggoff390c92015-09-08 06:24:08 -0700244 @param outTexture if non-NULL will be the bitmap representing the shader
245 after return.
246 @param outMatrix if non-NULL will be the matrix to apply to vertices
247 to access the bitmap after return.
248 @param xy if non-NULL will be the tile modes that should be
249 used to access the bitmap after return.
250 @param twoPointRadialParams Two extra return values needed for two point
251 radial bitmaps. The first is the x-offset of
252 the second point and the second is the radius
253 about the first point.
254 */
255 virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
256 TileMode xy[2]) const;
257
258public:
259 bool isABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode xy[2]) const {
260 return this->asABitmap(bitmap, matrix, xy) == kDefault_BitmapType;
261 }
reedf5822822015-08-19 11:46:38 -0700262 bool isABitmap() const {
263 return this->isABitmap(nullptr, nullptr, nullptr);
264 }
265
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +0000266 /**
267 * If the shader subclass can be represented as a gradient, asAGradient
268 * returns the matching GradientType enum (or kNone_GradientType if it
269 * cannot). Also, if info is not null, asAGradient populates info with
270 * the relevant (see below) parameters for the gradient. fColorCount
271 * is both an input and output parameter. On input, it indicates how
272 * many entries in fColors and fColorOffsets can be used, if they are
273 * non-NULL. After asAGradient has run, fColorCount indicates how
274 * many color-offset pairs there are in the gradient. If there is
275 * insufficient space to store all of the color-offset pairs, fColors
276 * and fColorOffsets will not be altered. fColorOffsets specifies
277 * where on the range of 0 to 1 to transition to the given color.
278 * The meaning of fPoint and fRadius is dependant on the type of gradient.
279 *
280 * None:
281 * info is ignored.
282 * Color:
283 * fColorOffsets[0] is meaningless.
284 * Linear:
285 * fPoint[0] and fPoint[1] are the end-points of the gradient
286 * Radial:
287 * fPoint[0] and fRadius[0] are the center and radius
reed71a6cbf2015-05-04 08:32:51 -0700288 * Conical:
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +0000289 * fPoint[0] and fRadius[0] are the center and radius of the 1st circle
290 * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle
291 * Sweep:
292 * fPoint[0] is the center of the sweep.
293 */
294
295 enum GradientType {
296 kNone_GradientType,
297 kColor_GradientType,
298 kLinear_GradientType,
299 kRadial_GradientType,
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +0000300 kSweep_GradientType,
reed@google.com83226972012-06-07 20:26:47 +0000301 kConical_GradientType,
302 kLast_GradientType = kConical_GradientType
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +0000303 };
304
305 struct GradientInfo {
306 int fColorCount; //!< In-out parameter, specifies passed size
307 // of fColors/fColorOffsets on input, and
308 // actual number of colors/offsets on
309 // output.
310 SkColor* fColors; //!< The colors in the gradient.
311 SkScalar* fColorOffsets; //!< The unit offset for color transitions.
312 SkPoint fPoint[2]; //!< Type specific, see above.
313 SkScalar fRadius[2]; //!< Type specific, see above.
314 TileMode fTileMode; //!< The tile mode used.
reed@google.com3d3a8602013-05-24 14:58:44 +0000315 uint32_t fGradientFlags; //!< see SkGradientShader::Flags
vandebo@chromium.orgd3ae7792011-02-24 00:21:06 +0000316 };
317
318 virtual GradientType asAGradient(GradientInfo* info) const;
319
rileya@google.com03c1c352012-07-20 20:02:43 +0000320 /**
commit-bot@chromium.org79590552014-05-13 18:14:45 +0000321 * If the shader subclass is composed of two shaders, return true, and if rec is not NULL,
322 * fill it out with info about the shader.
commit-bot@chromium.org30558792014-05-14 14:28:34 +0000323 *
324 * These are bare pointers; the ownership and reference count are unchanged.
commit-bot@chromium.org79590552014-05-13 18:14:45 +0000325 */
326
327 struct ComposeRec {
328 const SkShader* fShaderA;
329 const SkShader* fShaderB;
330 const SkXfermode* fMode;
331 };
332
djsollenc87dd2c2014-11-14 11:11:46 -0800333 virtual bool asACompose(ComposeRec*) const { return false; }
commit-bot@chromium.org79590552014-05-13 18:14:45 +0000334
335
336 /**
bsalomonc21b09e2015-08-28 18:46:56 -0700337 * Returns a GrFragmentProcessor that implements the shader for the GPU backend. NULL is
338 * returned if there is no GPU implementation.
bsalomon83d081a2014-07-08 09:56:10 -0700339 *
bsalomonc21b09e2015-08-28 18:46:56 -0700340 * The GPU device does not call SkShader::createContext(), instead we pass the view matrix,
341 * local matrix, and filter quality directly.
bsalomon83d081a2014-07-08 09:56:10 -0700342 *
bsalomonc21b09e2015-08-28 18:46:56 -0700343 * The GrContext may be used by the to create textures that are required by the returned
344 * processor.
rileya@google.com03c1c352012-07-20 20:02:43 +0000345 */
bsalomonc21b09e2015-08-28 18:46:56 -0700346 virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*,
347 const SkMatrix& viewMatrix,
348 const SkMatrix* localMatrix,
349 SkFilterQuality,
350 GrProcessorDataManager*) const;
rileya@google.com03c1c352012-07-20 20:02:43 +0000351
reed8367b8c2014-08-22 08:30:20 -0700352 /**
353 * If the shader can represent its "average" luminance in a single color, return true and
354 * if color is not NULL, return that color. If it cannot, return false and ignore the color
355 * parameter.
356 *
357 * Note: if this returns true, the returned color will always be opaque, as only the RGB
358 * components are used to compute luminance.
359 */
360 bool asLuminanceColor(SkColor*) const;
361
commit-bot@chromium.org79590552014-05-13 18:14:45 +0000362#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
363 /**
364 * If the shader is a custom shader which has data the caller might want, call this function
365 * to get that data.
366 */
scroggo01c412e2014-11-24 09:05:35 -0800367 virtual bool asACustomShader(void** /* customData */) const { return false; }
commit-bot@chromium.org79590552014-05-13 18:14:45 +0000368#endif
369
reed@android.com8a1c16f2008-12-17 15:59:43 +0000370 //////////////////////////////////////////////////////////////////////////
371 // Factory methods for stock shaders
372
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000373 /**
374 * Call this to create a new "empty" shader, that will not draw anything.
375 */
376 static SkShader* CreateEmptyShader();
377
reed8367b8c2014-08-22 08:30:20 -0700378 /**
379 * Call this to create a new shader that just draws the specified color. This should always
380 * draw the same as a paint with this color (and no shader).
381 */
382 static SkShader* CreateColorShader(SkColor);
383
reed@android.com8a1c16f2008-12-17 15:59:43 +0000384 /** Call this to create a new shader that will draw with the specified bitmap.
reed@google.com99c114e2012-05-03 20:14:26 +0000385 *
386 * If the bitmap cannot be used (e.g. has no pixels, or its dimensions
387 * exceed implementation limits (currently at 64K - 1)) then SkEmptyShader
388 * may be returned.
389 *
commit-bot@chromium.org91246b92013-12-05 15:43:19 +0000390 * If the src is kA8_Config then that mask will be colorized using the color on
391 * the paint.
392 *
reed@google.com99c114e2012-05-03 20:14:26 +0000393 * @param src The bitmap to use inside the shader
394 * @param tmx The tiling mode to use when sampling the bitmap in the x-direction.
395 * @param tmy The tiling mode to use when sampling the bitmap in the y-direction.
396 * @return Returns a new shader object. Note: this function never returns null.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000397 */
398 static SkShader* CreateBitmapShader(const SkBitmap& src,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000399 TileMode tmx, TileMode tmy,
400 const SkMatrix* localMatrix = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000401
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +0000402 /** Call this to create a new shader that will draw with the specified picture.
403 *
404 * @param src The picture to use inside the shader (if not NULL, its ref count
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +0000405 * is incremented). The SkPicture must not be changed after
406 * successfully creating a picture shader.
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +0000407 * @param tmx The tiling mode to use when sampling the bitmap in the x-direction.
408 * @param tmy The tiling mode to use when sampling the bitmap in the y-direction.
fmalitab5f78262014-08-06 13:07:15 -0700409 * @param tile The tile rectangle in picture coordinates: this represents the subset
410 * (or superset) of the picture used when building a tile. It is not
411 * affected by localMatrix and does not imply scaling (only translation
412 * and cropping). If null, the tile rect is considered equal to the picture
413 * bounds.
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +0000414 * @return Returns a new shader object. Note: this function never returns null.
415 */
fmalita2be0fd82014-12-08 09:04:05 -0800416 static SkShader* CreatePictureShader(const SkPicture* src,
fmalitab5f78262014-08-06 13:07:15 -0700417 TileMode tmx, TileMode tmy,
418 const SkMatrix* localMatrix,
419 const SkRect* tile);
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +0000420
commit-bot@chromium.org8fae2132014-05-07 22:26:37 +0000421 /**
422 * Return a shader that will apply the specified localMatrix to the proxy shader.
423 * The specified matrix will be applied before any matrix associated with the proxy.
424 *
425 * Note: ownership of the proxy is not transferred (though a ref is taken).
426 */
427 static SkShader* CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix);
428
429 /**
430 * If this shader can be represented by another shader + a localMatrix, return that shader
431 * and, if not NULL, the localMatrix. If not, return NULL and ignore the localMatrix parameter.
432 *
433 * Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility
434 * of the caller to balance that with unref() when they are done.
435 */
436 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
437
robertphillips0a482f42015-01-26 07:00:04 -0800438 SK_TO_STRING_VIRT()
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +0000439 SK_DEFINE_FLATTENABLE_TYPE(SkShader)
440
reed@android.com8a1c16f2008-12-17 15:59:43 +0000441protected:
mtklein36352bf2015-03-25 18:17:31 -0700442 void flatten(SkWriteBuffer&) const override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000443
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000444 bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000445
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000446 /**
447 * Your subclass must also override contextSize() if it overrides onCreateContext().
448 * Base class impl returns NULL.
449 */
450 virtual Context* onCreateContext(const ContextRec&, void* storage) const;
451
reed8367b8c2014-08-22 08:30:20 -0700452 virtual bool onAsLuminanceColor(SkColor*) const {
453 return false;
454 }
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000455private:
scroggoef0fd612014-07-11 11:33:52 -0700456 // This is essentially const, but not officially so it can be modified in
457 // constructors.
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000458 SkMatrix fLocalMatrix;
scroggoc870d492014-07-11 10:42:12 -0700459
460 // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer constructor.
461 friend class SkLocalMatrixShader;
462
reed@android.com8a1c16f2008-12-17 15:59:43 +0000463 typedef SkFlattenable INHERITED;
464};
465
466#endif