• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Generated by tools/bookmaker from include/core/SkPaint.h and docs/SkPaint_Reference.bmh
9    on 2018-08-28 10:32:58. Additional documentation and examples can be found at:
10    https://skia.org/user/api/SkPaint_Reference
11 
12    You may edit either file directly. Structural changes to public interfaces require
13    editing both files. After editing docs/SkPaint_Reference.bmh, run:
14        bookmaker -b docs -i include/core/SkPaint.h -p
15    to create an updated version of this file.
16  */
17 
18 #ifndef SkPaint_DEFINED
19 #define SkPaint_DEFINED
20 
21 #include "../private/SkTo.h"
22 #include "SkBlendMode.h"
23 #include "SkColor.h"
24 #include "SkFilterQuality.h"
25 #include "SkRefCnt.h"
26 
27 class SkColorFilter;
28 class SkColorSpace;
29 class SkDrawLooper;
30 struct SkRect;
31 class SkImageFilter;
32 class SkMaskFilter;
33 class SkPath;
34 class SkPathEffect;
35 struct SkPoint;
36 class SkShader;
37 
38 #ifdef SK_SUPPORT_LEGACY_INCLUDEFONTMETRICS
39 #include "SkFontMetrics.h"
40 class SkSurfaceProps;
41 #endif
42 
43 /** \class SkPaint
44     SkPaint controls options applied when drawing. SkPaint collects all
45     options outside of the SkCanvas clip and SkCanvas matrix.
46 
47     Various options apply to strokes and fills, and images.
48 
49     SkPaint collects effects and filters that describe single-pass and multiple-pass
50     algorithms that alter the drawing geometry, color, and transparency. For instance,
51     SkPaint does not directly implement dashing or blur, but contains the objects that do so.
52 */
53 class SK_API SkPaint {
54 public:
55 
56     /** Constructs SkPaint with default values.
57 
58         @return  default initialized SkPaint
59     */
60     SkPaint();
61 
62     /** Makes a shallow copy of SkPaint. SkPathEffect, SkShader,
63         SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
64         between the original paint and the copy. Objects containing SkRefCnt increment
65         their references by one.
66 
67         The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
68         SkDrawLooper, and SkImageFilter cannot be modified after they are created.
69         This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
70 
71         @param paint  original to copy
72         @return       shallow copy of paint
73     */
74     SkPaint(const SkPaint& paint);
75 
76     /** Implements a move constructor to avoid increasing the reference counts
77         of objects referenced by the paint.
78 
79         After the call, paint is undefined, and can be safely destructed.
80 
81         @param paint  original to move
82         @return       content of paint
83     */
84     SkPaint(SkPaint&& paint);
85 
86     /** Decreases SkPaint SkRefCnt of owned objects: SkPathEffect, SkShader,
87         SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
88         objects containing SkRefCnt go to zero, they are deleted.
89     */
90     ~SkPaint();
91 
92     /** Makes a shallow copy of SkPaint. SkPathEffect, SkShader,
93         SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
94         between the original paint and the copy. Objects containing SkRefCnt in the
95         prior destination are decreased by one, and the referenced objects are deleted if the
96         resulting count is zero. Objects containing SkRefCnt in the parameter paint
97         are increased by one. paint is unmodified.
98 
99         @param paint  original to copy
100         @return       content of paint
101     */
102     SkPaint& operator=(const SkPaint& paint);
103 
104     /** Moves the paint to avoid increasing the reference counts
105         of objects referenced by the paint parameter. Objects containing SkRefCnt in the
106         prior destination are decreased by one; those objects are deleted if the resulting count
107         is zero.
108 
109         After the call, paint is undefined, and can be safely destructed.
110 
111         @param paint  original to move
112         @return       content of paint
113     */
114     SkPaint& operator=(SkPaint&& paint);
115 
116     /** Compares a and b, and returns true if a and b are equivalent. May return false
117         if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
118         SkDrawLooper, or SkImageFilter have identical contents but different pointers.
119 
120         @param a  SkPaint to compare
121         @param b  SkPaint to compare
122         @return   true if SkPaint pair are equivalent
123     */
124     SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
125 
126     /** Compares a and b, and returns true if a and b are not equivalent. May return true
127         if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
128         SkDrawLooper, or SkImageFilter have identical contents but different pointers.
129 
130         @param a  SkPaint to compare
131         @param b  SkPaint to compare
132         @return   true if SkPaint pair are not equivalent
133     */
134     friend bool operator!=(const SkPaint& a, const SkPaint& b) {
135         return !(a == b);
136     }
137 
138     /** Returns a hash generated from SkPaint values and pointers.
139         Identical hashes guarantee that the paints are
140         equivalent, but differing hashes do not guarantee that the paints have differing
141         contents.
142 
143         If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
144         their hashes are also equal.
145 
146         The hash returned is platform and implementation specific.
147 
148         @return  a shallow hash
149     */
150     uint32_t getHash() const;
151 
152     /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
153         SkPaint with the result of SkPaint().
154     */
155     void reset();
156 
157     /** Returns true if pixels on the active edges of SkPath may be drawn with partial transparency.
158         @return  antialiasing state
159     */
isAntiAlias()160     bool isAntiAlias() const {
161         return SkToBool(fBitfields.fAntiAlias);
162     }
163 
164     /** Requests, but does not require, that edge pixels draw opaque or with
165         partial transparency.
166         @param aa  setting for antialiasing
167     */
setAntiAlias(bool aa)168     void setAntiAlias(bool aa) { fBitfields.fAntiAlias = static_cast<unsigned>(aa); }
169 
170     /** Returns true if color error may be distributed to smooth color transition.
171         @return  dithering state
172     */
isDither()173     bool isDither() const {
174         return SkToBool(fBitfields.fDither);
175     }
176 
177     /** Requests, but does not require, to distribute color error.
178         @param dither  setting for ditering
179     */
setDither(bool dither)180     void setDither(bool dither) { fBitfields.fDither = static_cast<unsigned>(dither); }
181 
182     /** Returns SkFilterQuality, the image filtering level. A lower setting
183         draws faster; a higher setting looks better when the image is scaled.
184 
185         @return  one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
186                  kMedium_SkFilterQuality, kHigh_SkFilterQuality
187     */
getFilterQuality()188     SkFilterQuality getFilterQuality() const {
189         return (SkFilterQuality)fBitfields.fFilterQuality;
190     }
191 
192     /** Sets SkFilterQuality, the image filtering level. A lower setting
193         draws faster; a higher setting looks better when the image is scaled.
194         Does not check to see if quality is valid.
195 
196         @param quality  one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
197                         kMedium_SkFilterQuality, kHigh_SkFilterQuality
198     */
199     void setFilterQuality(SkFilterQuality quality);
200 
201     /** \enum SkPaint::Style
202         Set Style to fill, stroke, or both fill and stroke geometry.
203         The stroke and fill
204         share all paint attributes; for instance, they are drawn with the same color.
205 
206         Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
207         a fill draw.
208     */
209     enum Style : uint8_t {
210         kFill_Style,          //!< set to fill geometry
211         kStroke_Style,        //!< set to stroke geometry
212         kStrokeAndFill_Style, //!< sets to stroke and fill geometry
213     };
214 
215     /** May be used to verify that SkPaint::Style is a legal value.
216     */
217     static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
218 
219     /** Returns whether the geometry is filled, stroked, or filled and stroked.
220 
221         @return  one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
222     */
getStyle()223     Style getStyle() const { return (Style)fBitfields.fStyle; }
224 
225     /** Sets whether the geometry is filled, stroked, or filled and stroked.
226         Has no effect if style is not a legal SkPaint::Style value.
227 
228         @param style  one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
229     */
230     void setStyle(Style style);
231 
232     /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
233         Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
234         a color component.
235 
236         @return  unpremultiplied ARGB
237     */
getColor()238     SkColor getColor() const { return fColor4f.toSkColor(); }
239 
240     /** Retrieves alpha and RGB, unpremultiplied, as four floating point values. RGB are
241         are extended sRGB values (sRGB gamut, and encoded with the sRGB transfer function).
242 
243         @return  unpremultiplied RGBA
244     */
getColor4f()245     SkColor4f getColor4f() const { return fColor4f; }
246 
247     /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
248         unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
249 
250         @param color  unpremultiplied ARGB
251     */
252     void setColor(SkColor color);
253 
254     /** Sets alpha and RGB used when stroking and filling. The color is four floating
255         point values, unpremultiplied. The color values are interpreted as being in
256         the colorSpace. If colorSpace is nullptr, then color is assumed to be in the
257         sRGB color space.
258 
259         @param color       unpremultiplied RGBA
260         @param colorSpace  SkColorSpace describing the encoding of color
261     */
262     void setColor4f(const SkColor4f& color, SkColorSpace* colorSpace);
263 
264     /** Retrieves alpha from the color used when stroking and filling.
265 
266         @return  alpha ranging from zero, fully transparent, to 255, fully opaque
267     */
getAlpha()268     uint8_t getAlpha() const { return sk_float_round2int(fColor4f.fA * 255); }
269 
270     /** Replaces alpha, leaving RGB
271         unchanged. An out of range value triggers an assert in the debug
272         build. a is a value from zero to 255.
273         a set to zero makes color fully transparent; a set to 255 makes color
274         fully opaque.
275 
276         @param a  alpha component of color
277     */
278     void setAlpha(U8CPU a);
279 
280     /** Sets color used when drawing solid fills. The color components range from 0 to 255.
281         The color is unpremultiplied; alpha sets the transparency independent of RGB.
282 
283         @param a  amount of alpha, from fully transparent (0) to fully opaque (255)
284         @param r  amount of red, from no red (0) to full red (255)
285         @param g  amount of green, from no green (0) to full green (255)
286         @param b  amount of blue, from no blue (0) to full blue (255)
287     */
288     void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
289 
290     /** Returns the thickness of the pen used by SkPaint to
291         outline the shape.
292 
293         @return  zero for hairline, greater than zero for pen thickness
294     */
getStrokeWidth()295     SkScalar getStrokeWidth() const { return fWidth; }
296 
297     /** Sets the thickness of the pen used by the paint to
298         outline the shape.
299         Has no effect if width is less than zero.
300 
301         @param width  zero thickness for hairline; greater than zero for pen thickness
302     */
303     void setStrokeWidth(SkScalar width);
304 
305     /** Returns the limit at which a sharp corner is drawn beveled.
306 
307         @return  zero and greater miter limit
308     */
getStrokeMiter()309     SkScalar getStrokeMiter() const { return fMiterLimit; }
310 
311     /** Sets the limit at which a sharp corner is drawn beveled.
312         Valid values are zero and greater.
313         Has no effect if miter is less than zero.
314 
315         @param miter  zero and greater miter limit
316     */
317     void setStrokeMiter(SkScalar miter);
318 
319     /** \enum SkPaint::Cap
320         Cap draws at the beginning and end of an open path contour.
321     */
322     enum Cap {
323         kButt_Cap,                  //!< no stroke extension
324         kRound_Cap,                 //!< adds circle
325         kSquare_Cap,                //!< adds square
326         kLast_Cap    = kSquare_Cap, //!< largest Cap value
327         kDefault_Cap = kButt_Cap,   //!< equivalent to kButt_Cap
328     };
329 
330     /** May be used to verify that SkPaint::Cap is a legal value.
331     */
332     static constexpr int kCapCount = kLast_Cap + 1;
333 
334     /** \enum SkPaint::Join
335         Join specifies how corners are drawn when a shape is stroked. Join
336         affects the four corners of a stroked rectangle, and the connected segments in a
337         stroked path.
338 
339         Choose miter join to draw sharp corners. Choose round join to draw a circle with a
340         radius equal to the stroke width on top of the corner. Choose bevel join to minimally
341         connect the thick strokes.
342 
343         The fill path constructed to describe the stroked path respects the join setting but may
344         not contain the actual join. For instance, a fill path constructed with round joins does
345         not necessarily include circles at each connected segment.
346     */
347     enum Join : uint8_t {
348         kMiter_Join,                 //!< extends to miter limit
349         kRound_Join,                 //!< adds circle
350         kBevel_Join,                 //!< connects outside edges
351         kLast_Join    = kBevel_Join, //!< equivalent to the largest value for Join
352         kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
353     };
354 
355     /** May be used to verify that SkPaint::Join is a legal value.
356     */
357     static constexpr int kJoinCount = kLast_Join + 1;
358 
359     /** Returns the geometry drawn at the beginning and end of strokes.
360 
361         @return  one of: kButt_Cap, kRound_Cap, kSquare_Cap
362     */
getStrokeCap()363     Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
364 
365     /** Sets the geometry drawn at the beginning and end of strokes.
366 
367         @param cap  one of: kButt_Cap, kRound_Cap, kSquare_Cap;
368                     has no effect if cap is not valid
369     */
370     void setStrokeCap(Cap cap);
371 
372     /** Returns the geometry drawn at the corners of strokes.
373 
374         @return  one of: kMiter_Join, kRound_Join, kBevel_Join
375     */
getStrokeJoin()376     Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
377 
378     /** Sets the geometry drawn at the corners of strokes.
379 
380         @param join  one of: kMiter_Join, kRound_Join, kBevel_Join;
381                      otherwise, has no effect
382     */
383     void setStrokeJoin(Join join);
384 
385     /** Returns the filled equivalent of the stroked path.
386 
387         @param src       SkPath read to create a filled version
388         @param dst       resulting SkPath; may be the same as src, but may not be nullptr
389         @param cullRect  optional limit passed to SkPathEffect
390         @param resScale  if > 1, increase precision, else if (0 < resScale < 1) reduce precision
391                          to favor speed and size
392         @return          true if the path represents style fill, or false if it represents hairline
393     */
394     bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
395                      SkScalar resScale = 1) const;
396 
397     /** Returns the filled equivalent of the stroked path.
398 
399         Replaces dst with the src path modified by SkPathEffect and style stroke.
400         SkPathEffect, if any, is not culled. stroke width is created with default precision.
401 
402         @param src  SkPath read to create a filled version
403         @param dst  resulting SkPath dst may be the same as src, but may not be nullptr
404         @return     true if the path represents style fill, or false if it represents hairline
405     */
getFillPath(const SkPath & src,SkPath * dst)406     bool getFillPath(const SkPath& src, SkPath* dst) const {
407         return this->getFillPath(src, dst, nullptr, 1);
408     }
409 
410     /** Returns optional colors used when filling a path, such as a gradient.
411 
412         Does not alter SkShader SkRefCnt.
413 
414         @return  SkShader if previously set, nullptr otherwise
415     */
getShader()416     SkShader* getShader() const { return fShader.get(); }
417 
418     /** Returns optional colors used when filling a path, such as a gradient.
419 
420         Increases SkShader SkRefCnt by one.
421 
422         @return  SkShader if previously set, nullptr otherwise
423     */
424     sk_sp<SkShader> refShader() const;
425 
426     /** Sets optional colors used when filling a path, such as a gradient.
427 
428         Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
429         Increments shader SkRefCnt by one.
430 
431         @param shader  how geometry is filled with color; if nullptr, color is used instead
432     */
433     void setShader(sk_sp<SkShader> shader);
434 
435     /** Returns SkColorFilter if set, or nullptr.
436         Does not alter SkColorFilter SkRefCnt.
437 
438         @return  SkColorFilter if previously set, nullptr otherwise
439     */
getColorFilter()440     SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
441 
442     /** Returns SkColorFilter if set, or nullptr.
443         Increases SkColorFilter SkRefCnt by one.
444 
445         @return  SkColorFilter if set, or nullptr
446     */
447     sk_sp<SkColorFilter> refColorFilter() const;
448 
449     /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
450         SkColorFilter. Pass nullptr to clear SkColorFilter.
451 
452         Increments filter SkRefCnt by one.
453 
454         @param colorFilter  SkColorFilter to apply to subsequent draw
455     */
456     void setColorFilter(sk_sp<SkColorFilter> colorFilter);
457 
458     /** Returns SkBlendMode.
459         By default, returns SkBlendMode::kSrcOver.
460 
461         @return  mode used to combine source color with destination color
462     */
getBlendMode()463     SkBlendMode getBlendMode() const { return (SkBlendMode)fBitfields.fBlendMode; }
464 
465     /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
466 
467         @return  true if SkBlendMode is SkBlendMode::kSrcOver
468     */
isSrcOver()469     bool isSrcOver() const { return (SkBlendMode)fBitfields.fBlendMode == SkBlendMode::kSrcOver; }
470 
471     /** Sets SkBlendMode to mode.
472         Does not check for valid input.
473 
474         @param mode  SkBlendMode used to combine source color and destination
475     */
setBlendMode(SkBlendMode mode)476     void setBlendMode(SkBlendMode mode) { fBitfields.fBlendMode = (unsigned)mode; }
477 
478     /** Returns SkPathEffect if set, or nullptr.
479         Does not alter SkPathEffect SkRefCnt.
480 
481         @return  SkPathEffect if previously set, nullptr otherwise
482     */
getPathEffect()483     SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
484 
485     /** Returns SkPathEffect if set, or nullptr.
486         Increases SkPathEffect SkRefCnt by one.
487 
488         @return  SkPathEffect if previously set, nullptr otherwise
489     */
490     sk_sp<SkPathEffect> refPathEffect() const;
491 
492     /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
493         SkPathEffect. Pass nullptr to leave the path geometry unaltered.
494 
495         Increments pathEffect SkRefCnt by one.
496 
497         @param pathEffect  replace SkPath with a modification when drawn
498     */
499     void setPathEffect(sk_sp<SkPathEffect> pathEffect);
500 
501     /** Returns SkMaskFilter if set, or nullptr.
502         Does not alter SkMaskFilter SkRefCnt.
503 
504         @return  SkMaskFilter if previously set, nullptr otherwise
505     */
getMaskFilter()506     SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
507 
508     /** Returns SkMaskFilter if set, or nullptr.
509 
510         Increases SkMaskFilter SkRefCnt by one.
511 
512         @return  SkMaskFilter if previously set, nullptr otherwise
513     */
514     sk_sp<SkMaskFilter> refMaskFilter() const;
515 
516     /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
517         SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
518         mask alpha unaltered.
519 
520         Increments maskFilter SkRefCnt by one.
521 
522         @param maskFilter  modifies clipping mask generated from drawn geometry
523     */
524     void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
525 
526     /** Returns SkImageFilter if set, or nullptr.
527         Does not alter SkImageFilter SkRefCnt.
528 
529         @return  SkImageFilter if previously set, nullptr otherwise
530     */
getImageFilter()531     SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
532 
533     /** Returns SkImageFilter if set, or nullptr.
534         Increases SkImageFilter SkRefCnt by one.
535 
536         @return  SkImageFilter if previously set, nullptr otherwise
537     */
538     sk_sp<SkImageFilter> refImageFilter() const;
539 
540     /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
541         SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
542         on drawing.
543 
544         Increments imageFilter SkRefCnt by one.
545 
546         @param imageFilter  how SkImage is sampled when transformed
547     */
548     void setImageFilter(sk_sp<SkImageFilter> imageFilter);
549 
550     /** Returns SkDrawLooper if set, or nullptr.
551         Does not alter SkDrawLooper SkRefCnt.
552 
553         @return  SkDrawLooper if previously set, nullptr otherwise
554     */
getDrawLooper()555     SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
556 
557     /** Returns SkDrawLooper if set, or nullptr.
558         Increases SkDrawLooper SkRefCnt by one.
559 
560         @return  SkDrawLooper if previously set, nullptr otherwise
561     */
562     sk_sp<SkDrawLooper> refDrawLooper() const;
563 
564     /** Deprecated.
565         (see skbug.com/6259)
566     */
getLooper()567     SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
568 
569     /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
570         drawLooper.  Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
571         drawing unaltered.
572 
573         Increments drawLooper SkRefCnt by one.
574 
575         @param drawLooper  iterates through drawing one or more time, altering SkPaint
576     */
577     void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
578 
579     /** Deprecated.
580         (see skbug.com/6259)
581     */
582     void setLooper(sk_sp<SkDrawLooper> drawLooper);
583 
584     /** Returns true if SkPaint prevents all drawing;
585         otherwise, the SkPaint may or may not allow drawing.
586 
587         Returns true if, for example, SkBlendMode combined with alpha computes a
588         new alpha of zero.
589 
590         @return  true if SkPaint prevents all drawing
591     */
592     bool nothingToDraw() const;
593 
594     /**     (to be made private)
595         Returns true if SkPaint does not include elements requiring extensive computation
596         to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
597         always returns false.
598 
599         @return  true if SkPaint allows for fast computation of bounds
600     */
601     bool canComputeFastBounds() const;
602 
603     /**     (to be made private)
604         Only call this if canComputeFastBounds() returned true. This takes a
605         raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
606         effects in the paint (e.g. stroking). If needed, it uses the storage
607         parameter. It returns the adjusted bounds that can then be used
608         for SkCanvas::quickReject tests.
609 
610         The returned SkRect will either be orig or storage, thus the caller
611         should not rely on storage being set to the result, but should always
612         use the returned value. It is legal for orig and storage to be the same
613         SkRect.
614             For example:
615             if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
616                 SkRect storage;
617                 if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) {
618                     return; // do not draw the path
619                 }
620             }
621             // draw the path
622 
623         @param orig     geometry modified by SkPaint when drawn
624         @param storage  computed bounds of geometry; may not be nullptr
625         @return         fast computed bounds
626     */
computeFastBounds(const SkRect & orig,SkRect * storage)627     const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
628         // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
629         SkASSERT(orig.isSorted());
630         SkPaint::Style style = this->getStyle();
631         // ultra fast-case: filling with no effects that affect geometry
632         if (kFill_Style == style) {
633             uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
634             effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
635             effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
636             effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
637             if (!effects) {
638                 return orig;
639             }
640         }
641 
642         return this->doComputeFastBounds(orig, storage, style);
643     }
644 
645     /**     (to be made private)
646 
647         @param orig     geometry modified by SkPaint when drawn
648         @param storage  computed bounds of geometry
649         @return         fast computed bounds
650     */
computeFastStrokeBounds(const SkRect & orig,SkRect * storage)651     const SkRect& computeFastStrokeBounds(const SkRect& orig,
652                                           SkRect* storage) const {
653         return this->doComputeFastBounds(orig, storage, kStroke_Style);
654     }
655 
656     /**     (to be made private)
657         Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
658         account for additional width required by stroking orig, without
659         altering SkPaint::Style set to fill.
660 
661         @param orig     geometry modified by SkPaint when drawn
662         @param storage  computed bounds of geometry
663         @param style    overrides SkPaint::Style
664         @return         fast computed bounds
665     */
666     const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
667                                       Style style) const;
668 
669 private:
670     sk_sp<SkPathEffect>   fPathEffect;
671     sk_sp<SkShader>       fShader;
672     sk_sp<SkMaskFilter>   fMaskFilter;
673     sk_sp<SkColorFilter>  fColorFilter;
674     sk_sp<SkDrawLooper>   fDrawLooper;
675     sk_sp<SkImageFilter>  fImageFilter;
676 
677     SkColor4f       fColor4f;
678     SkScalar        fWidth;
679     SkScalar        fMiterLimit;
680     union {
681         struct {
682             unsigned    fAntiAlias : 1;
683             unsigned    fDither : 1;
684             unsigned    fCapType : 2;
685             unsigned    fJoinType : 2;
686             unsigned    fStyle : 2;
687             unsigned    fFilterQuality : 2;
688             unsigned    fBlendMode : 8; // only need 5-6?
689         } fBitfields;
690         uint32_t fBitfieldsUInt;
691     };
692 };
693 
694 #endif
695