Flutter Engine
The Flutter Engine
|
#include <SkPaint.h>
Public Types | |
enum | Style : uint8_t { kFill_Style , kStroke_Style , kStrokeAndFill_Style } |
enum | Cap { kButt_Cap , kRound_Cap , kSquare_Cap , kLast_Cap = kSquare_Cap , kDefault_Cap = kButt_Cap } |
enum | Join : uint8_t { kMiter_Join , kRound_Join , kBevel_Join , kLast_Join = kBevel_Join , kDefault_Join = kMiter_Join } |
using | sk_is_trivially_relocatable = std::true_type |
Static Public Attributes | |
static constexpr int | kStyleCount = kStrokeAndFill_Style + 1 |
static constexpr int | kCapCount = kLast_Cap + 1 |
static constexpr int | kJoinCount = kLast_Join + 1 |
Friends | |
class | SkPaintPriv |
SK_API friend bool | operator== (const SkPaint &a, const SkPaint &b) |
bool | operator!= (const SkPaint &a, const SkPaint &b) |
SkPaint controls options applied when drawing. SkPaint collects all options outside of the SkCanvas clip and SkCanvas matrix.
Various options apply to strokes and fills, and images.
SkPaint collects effects and filters that describe single-pass and multiple-pass algorithms that alter the drawing geometry, color, and transparency. For instance, SkPaint does not directly implement dashing or blur, but contains the objects that do so.
using SkPaint::sk_is_trivially_relocatable = std::true_type |
enum SkPaint::Cap |
enum SkPaint::Join : uint8_t |
enum SkPaint::Style : uint8_t |
Enumerator | |
---|---|
kFill_Style | set to fill geometry |
kStroke_Style | set to stroke geometry |
kStrokeAndFill_Style | sets to stroke and fill geometry |
Definition at line 192 of file SkPaint.h.
SkPaint::SkPaint | ( | ) |
Constructs SkPaint with default values.
example: https://fiddle.skia.org/c/@Paint_empty_constructor
Definition at line 38 of file SkPaint.cpp.
|
explicit |
Constructs SkPaint with default values and the given color.
Sets alpha and RGB used when stroking and filling. The color is four floating point values, unpremultiplied. The color values are interpreted as being in the colorSpace. If colorSpace is nullptr, then color is assumed to be in the sRGB color space.
color | unpremultiplied RGBA |
colorSpace | SkColorSpace describing the encoding of color |
Definition at line 52 of file SkPaint.cpp.
|
default |
Makes a shallow copy of SkPaint. SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter are shared between the original paint and the copy. Objects containing SkRefCnt increment their references by one.
The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter cannot be modified after they are created. This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
paint | original to copy |
example: https://fiddle.skia.org/c/@Paint_copy_const_SkPaint
|
default |
Implements a move constructor to avoid increasing the reference counts of objects referenced by the paint.
After the call, paint is undefined, and can be safely destructed.
paint | original to move |
|
default |
Decreases SkPaint SkRefCnt of owned objects: SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter. If the objects containing SkRefCnt go to zero, they are deleted.
std::optional< SkBlendMode > SkPaint::asBlendMode | ( | ) | const |
If the current blender can be represented as a SkBlendMode enum, this returns that enum in the optional's value(). If it cannot, then the returned optional does not contain a value.
Definition at line 138 of file SkPaint.cpp.
bool SkPaint::canComputeFastBounds | ( | ) | const |
(to be made private) Returns true if SkPaint does not include elements requiring extensive computation to compute device bounds of drawn geometry. For instance, SkPaint with SkPathEffect always returns false.
Definition at line 201 of file SkPaint.cpp.
(to be made private) Only call this if canComputeFastBounds() returned true. This takes a raw rectangle (the raw bounds of a shape), and adjusts it for stylistic effects in the paint (e.g. stroking). If needed, it uses the storage parameter. It returns the adjusted bounds that can then be used for SkCanvas::quickReject tests.
The returned SkRect will either be orig or storage, thus the caller should not rely on storage being set to the result, but should always use the returned value. It is legal for orig and storage to be the same SkRect. For example: if (!path.isInverseFillType() && paint.canComputeFastBounds()) { SkRect storage; if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) { return; // do not draw the path } } draw the path
@param orig geometry modified by SkPaint when drawn @param storage computed bounds of geometry; may not be nullptr @return fast computed bounds
Definition at line 213 of file SkPaint.cpp.
|
inline |
(to be made private)
orig | geometry modified by SkPaint when drawn |
storage | computed bounds of geometry |
const SkRect & SkPaint::doComputeFastBounds | ( | const SkRect & | orig, |
SkRect * | storage, | ||
Style | style | ||
) | const |
(to be made private) Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to account for additional width required by stroking orig, without altering SkPaint::Style set to fill.
orig | geometry modified by SkPaint when drawn |
storage | computed bounds of geometry |
style | overrides SkPaint::Style |
Definition at line 231 of file SkPaint.cpp.
|
inline |
|
inline |
SkBlendMode SkPaint::getBlendMode_or | ( | SkBlendMode | defaultMode | ) | const |
Queries the blender, and if it can be represented as a SkBlendMode, return that mode, else return the defaultMode provided.
Definition at line 143 of file SkPaint.cpp.
|
inline |
Retrieves alpha and RGB, unpremultiplied, packed into 32 bits. Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract a color component.
Definition at line 225 of file SkPaint.h.
|
inline |
|
inline |
Returns SkColorFilter if set, or nullptr. Does not alter SkColorFilter SkRefCnt.
Definition at line 426 of file SkPaint.h.
|
inline |
Returns SkImageFilter if set, or nullptr. Does not alter SkImageFilter SkRefCnt.
Definition at line 564 of file SkPaint.h.
|
inline |
Returns SkMaskFilter if set, or nullptr. Does not alter SkMaskFilter SkRefCnt.
Definition at line 534 of file SkPaint.h.
|
inline |
Returns SkPathEffect if set, or nullptr. Does not alter SkPathEffect SkRefCnt.
Definition at line 506 of file SkPaint.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns true if color error may be distributed to smooth color transition.
bool SkPaint::isSrcOver | ( | ) | const |
Returns true iff the current blender claims to be equivalent to SkBlendMode::kSrcOver.
Also returns true of the current blender is nullptr.
Definition at line 147 of file SkPaint.cpp.
bool SkPaint::nothingToDraw | ( | ) | const |
Returns true if SkPaint prevents all drawing; otherwise, the SkPaint may or may not allow drawing.
Returns true if, for example, SkBlendMode combined with alpha computes a new alpha of zero.
example: https://fiddle.skia.org/c/@Paint_nothingToDraw
Definition at line 273 of file SkPaint.cpp.
Makes a shallow copy of SkPaint. SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter are shared between the original paint and the copy. Objects containing SkRefCnt in the prior destination are decreased by one, and the referenced objects are deleted if the resulting count is zero. Objects containing SkRefCnt in the parameter paint are increased by one. paint is unmodified.
paint | original to copy |
Moves the paint to avoid increasing the reference counts of objects referenced by the paint parameter. Objects containing SkRefCnt in the prior destination are decreased by one; those objects are deleted if the resulting count is zero.
After the call, paint is undefined, and can be safely destructed.
paint | original to move |
sk_sp< SkColorFilter > SkPaint::refColorFilter | ( | ) | const |
Returns SkColorFilter if set, or nullptr. Increases SkColorFilter SkRefCnt by one.
sk_sp< SkImageFilter > SkPaint::refImageFilter | ( | ) | const |
Returns SkImageFilter if set, or nullptr. Increases SkImageFilter SkRefCnt by one.
sk_sp< SkMaskFilter > SkPaint::refMaskFilter | ( | ) | const |
Returns SkMaskFilter if set, or nullptr.
Increases SkMaskFilter SkRefCnt by one.
sk_sp< SkPathEffect > SkPaint::refPathEffect | ( | ) | const |
Returns SkPathEffect if set, or nullptr. Increases SkPathEffect SkRefCnt by one.
void SkPaint::reset | ( | ) |
Sets all SkPaint contents to their initial values. This is equivalent to replacing SkPaint with the result of SkPaint().
example: https://fiddle.skia.org/c/@Paint_reset
Definition at line 103 of file SkPaint.cpp.
|
inline |
void SkPaint::setAlphaf | ( | float | a | ) |
Replaces alpha, leaving RGB unchanged. An out of range value triggers an assert in the debug build. a is a value from 0.0 to 1.0. a set to zero makes color fully transparent; a set to 1.0 makes color fully opaque.
a | alpha component of color |
Definition at line 130 of file SkPaint.cpp.
|
inline |
Sets color used when drawing solid fills. The color components range from 0 to 255. The color is unpremultiplied; alpha sets the transparency independent of RGB.
a | amount of alpha, from fully transparent (0) to fully opaque (255) |
r | amount of red, from no red (0) to full red (255) |
g | amount of green, from no green (0) to full green (255) |
b | amount of blue, from no blue (0) to full blue (255) |
example: https://fiddle.skia.org/c/@Paint_setARGB
Definition at line 134 of file SkPaint.cpp.
Sets the current blender, increasing its refcnt, and if a blender is already present, decreasing that object's refcnt.
A nullptr blender signifies the default SrcOver behavior.
For convenience, you can call setBlendMode() if the blend effect can be expressed as one of those values.
Definition at line 155 of file SkPaint.cpp.
void SkPaint::setBlendMode | ( | SkBlendMode | mode | ) |
Helper method for calling setBlender().
This sets a blender that implements the specified blendmode enum.
Definition at line 151 of file SkPaint.cpp.
void SkPaint::setColor | ( | const SkColor4f & | color, |
SkColorSpace * | colorSpace = nullptr |
||
) |
Sets alpha and RGB used when stroking and filling. The color is four floating point values, unpremultiplied. The color values are interpreted as being in the colorSpace. If colorSpace is nullptr, then color is assumed to be in the sRGB color space.
color | unpremultiplied RGBA |
colorSpace | SkColorSpace describing the encoding of color |
Definition at line 123 of file SkPaint.cpp.
void SkPaint::setColor | ( | SkColor | color | ) |
Sets alpha and RGB used when stroking and filling. The color is a 32-bit value, unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
color | unpremultiplied ARGB |
example: https://fiddle.skia.org/c/@Paint_setColor
Definition at line 119 of file SkPaint.cpp.
|
inline |
void SkPaint::setColorFilter | ( | sk_sp< SkColorFilter > | colorFilter | ) |
Sets SkColorFilter to filter, decreasing SkRefCnt of the previous SkColorFilter. Pass nullptr to clear SkColorFilter.
Increments filter SkRefCnt by one.
colorFilter | SkColorFilter to apply to subsequent draw |
example: https://fiddle.skia.org/c/@Blend_Mode_Methods example: https://fiddle.skia.org/c/@Paint_setColorFilter
|
inline |
void SkPaint::setImageFilter | ( | sk_sp< SkImageFilter > | imageFilter | ) |
Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect on drawing.
Increments imageFilter SkRefCnt by one.
imageFilter | how SkImage is sampled when transformed |
void SkPaint::setMaskFilter | ( | sk_sp< SkMaskFilter > | maskFilter | ) |
Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on mask alpha unaltered.
Increments maskFilter SkRefCnt by one.
maskFilter | modifies clipping mask generated from drawn geometry |
example: https://fiddle.skia.org/c/@Paint_setMaskFilter example: https://fiddle.skia.org/c/@Typeface_Methods
void SkPaint::setPathEffect | ( | sk_sp< SkPathEffect > | pathEffect | ) |
Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous SkPathEffect. Pass nullptr to leave the path geometry unaltered.
Increments pathEffect SkRefCnt by one.
pathEffect | replace SkPath with a modification when drawn |
example: https://fiddle.skia.org/c/@Mask_Filter_Methods example: https://fiddle.skia.org/c/@Paint_setPathEffect
Sets optional colors used when filling a path, such as a gradient.
Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader. Increments shader SkRefCnt by one.
shader | how geometry is filled with color; if nullptr, color is used instead |
example: https://fiddle.skia.org/c/@Color_Filter_Methods example: https://fiddle.skia.org/c/@Paint_setShader
void SkPaint::setStroke | ( | bool | isStroke | ) |
Set paint's style to kStroke if true, or kFill if false.
Definition at line 115 of file SkPaint.cpp.
void SkPaint::setStrokeCap | ( | Cap | cap | ) |
Sets the geometry drawn at the beginning and end of strokes.
example: https://fiddle.skia.org/c/@Paint_setStrokeCap_a example: https://fiddle.skia.org/c/@Paint_setStrokeCap_b
Definition at line 179 of file SkPaint.cpp.
void SkPaint::setStrokeJoin | ( | Join | join | ) |
Sets the geometry drawn at the corners of strokes.
example: https://fiddle.skia.org/c/@Paint_setStrokeJoin
Definition at line 189 of file SkPaint.cpp.
void SkPaint::setStrokeMiter | ( | SkScalar | miter | ) |
Sets the limit at which a sharp corner is drawn beveled. Valid values are zero and greater. Has no effect if miter is less than zero.
miter | zero and greater miter limit |
example: https://fiddle.skia.org/c/@Paint_setStrokeMiter
Definition at line 169 of file SkPaint.cpp.
void SkPaint::setStrokeWidth | ( | SkScalar | width | ) |
Sets the thickness of the pen used by the paint to outline the shape. A stroke-width of zero is treated as "hairline" width. Hairlines are always exactly one pixel wide in device space (their thickness does not change as the canvas is scaled). Negative stroke-widths are invalid; setting a negative width will have no effect.
width | zero thickness for hairline; greater than zero for pen thickness |
example: https://fiddle.skia.org/c/@Miter_Limit example: https://fiddle.skia.org/c/@Paint_setStrokeWidth
Definition at line 159 of file SkPaint.cpp.
void SkPaint::setStyle | ( | Style | style | ) |
Sets whether the geometry is filled, stroked, or filled and stroked. Has no effect if style is not a legal SkPaint::Style value.
example: https://fiddle.skia.org/c/@Paint_setStyle example: https://fiddle.skia.org/c/@Stroke_Width
Definition at line 105 of file SkPaint.cpp.
Compares a and b, and returns true if a and b are not equivalent. May return true if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, or SkImageFilter have identical contents but different pointers.
Compares a and b, and returns true if a and b are equivalent. May return false if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, or SkImageFilter have identical contents but different pointers.
Definition at line 66 of file SkPaint.cpp.
|
friend |
struct { ... } SkPaint::fBitfields |
May be used to verify that SkPaint::Cap is a legal value.
|
staticconstexpr |
May be used to verify that SkPaint::Join is a legal value.
|
staticconstexpr |
May be used to verify that SkPaint::Style is a legal value.