Skia
2D Graphics Library
|
SkPaint controls options applied when drawing. More...
#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 |
Public Member Functions | |
SkPaint () | |
Constructs SkPaint with default values. More... | |
SkPaint (const SkColor4f &color, SkColorSpace *colorSpace=nullptr) | |
Constructs SkPaint with default values and the given color. More... | |
SkPaint (const SkPaint &paint) | |
Makes a shallow copy of SkPaint. More... | |
SkPaint (SkPaint &&paint) | |
Implements a move constructor to avoid increasing the reference counts of objects referenced by the paint. More... | |
~SkPaint () | |
Decreases SkPaint SkRefCnt of owned objects: SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter. More... | |
SkPaint & | operator= (const SkPaint &paint) |
Makes a shallow copy of SkPaint. More... | |
SkPaint & | operator= (SkPaint &&paint) |
Moves the paint to avoid increasing the reference counts of objects referenced by the paint parameter. More... | |
void | reset () |
Sets all SkPaint contents to their initial values. More... | |
bool | isAntiAlias () const |
Returns true if pixels on the active edges of SkPath may be drawn with partial transparency. More... | |
void | setAntiAlias (bool aa) |
Requests, but does not require, that edge pixels draw opaque or with partial transparency. More... | |
bool | isDither () const |
Returns true if color error may be distributed to smooth color transition. More... | |
void | setDither (bool dither) |
Requests, but does not require, to distribute color error. More... | |
Style | getStyle () const |
Returns whether the geometry is filled, stroked, or filled and stroked. More... | |
void | setStyle (Style style) |
Sets whether the geometry is filled, stroked, or filled and stroked. More... | |
void | setStroke (bool) |
Set paint's style to kStroke if true, or kFill if false. More... | |
SkColor | getColor () const |
Retrieves alpha and RGB, unpremultiplied, packed into 32 bits. More... | |
SkColor4f | getColor4f () const |
Retrieves alpha and RGB, unpremultiplied, as four floating point values. More... | |
void | setColor (SkColor color) |
Sets alpha and RGB used when stroking and filling. More... | |
void | setColor (const SkColor4f &color, SkColorSpace *colorSpace=nullptr) |
Sets alpha and RGB used when stroking and filling. More... | |
void | setColor4f (const SkColor4f &color, SkColorSpace *colorSpace=nullptr) |
float | getAlphaf () const |
Retrieves alpha from the color used when stroking and filling. More... | |
uint8_t | getAlpha () const |
void | setAlphaf (float a) |
Replaces alpha, leaving RGB unchanged. More... | |
void | setAlpha (U8CPU a) |
void | setARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b) |
Sets color used when drawing solid fills. More... | |
SkScalar | getStrokeWidth () const |
Returns the thickness of the pen used by SkPaint to outline the shape. More... | |
void | setStrokeWidth (SkScalar width) |
Sets the thickness of the pen used by the paint to outline the shape. More... | |
SkScalar | getStrokeMiter () const |
Returns the limit at which a sharp corner is drawn beveled. More... | |
void | setStrokeMiter (SkScalar miter) |
Sets the limit at which a sharp corner is drawn beveled. More... | |
Cap | getStrokeCap () const |
Returns the geometry drawn at the beginning and end of strokes. More... | |
void | setStrokeCap (Cap cap) |
Sets the geometry drawn at the beginning and end of strokes. More... | |
Join | getStrokeJoin () const |
Returns the geometry drawn at the corners of strokes. More... | |
void | setStrokeJoin (Join join) |
Sets the geometry drawn at the corners of strokes. More... | |
SkShader * | getShader () const |
Returns optional colors used when filling a path, such as a gradient. More... | |
sk_sp< SkShader > | refShader () const |
Returns optional colors used when filling a path, such as a gradient. More... | |
void | setShader (sk_sp< SkShader > shader) |
Sets optional colors used when filling a path, such as a gradient. More... | |
SkColorFilter * | getColorFilter () const |
Returns SkColorFilter if set, or nullptr. More... | |
sk_sp< SkColorFilter > | refColorFilter () const |
Returns SkColorFilter if set, or nullptr. More... | |
void | setColorFilter (sk_sp< SkColorFilter > colorFilter) |
Sets SkColorFilter to filter, decreasing SkRefCnt of the previous SkColorFilter. More... | |
std::optional< SkBlendMode > | asBlendMode () const |
If the current blender can be represented as a SkBlendMode enum, this returns that enum in the optional's value(). More... | |
SkBlendMode | 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. More... | |
bool | isSrcOver () const |
Returns true iff the current blender claims to be equivalent to SkBlendMode::kSrcOver. More... | |
void | setBlendMode (SkBlendMode mode) |
Helper method for calling setBlender(). More... | |
SkBlender * | getBlender () const |
Returns the user-supplied blend function, if one has been set. More... | |
sk_sp< SkBlender > | refBlender () const |
Returns the user-supplied blend function, if one has been set. More... | |
void | setBlender (sk_sp< SkBlender > blender) |
Sets the current blender, increasing its refcnt, and if a blender is already present, decreasing that object's refcnt. More... | |
SkPathEffect * | getPathEffect () const |
Returns SkPathEffect if set, or nullptr. More... | |
sk_sp< SkPathEffect > | refPathEffect () const |
Returns SkPathEffect if set, or nullptr. More... | |
void | setPathEffect (sk_sp< SkPathEffect > pathEffect) |
Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous SkPathEffect. More... | |
SkMaskFilter * | getMaskFilter () const |
Returns SkMaskFilter if set, or nullptr. More... | |
sk_sp< SkMaskFilter > | refMaskFilter () const |
Returns SkMaskFilter if set, or nullptr. More... | |
void | setMaskFilter (sk_sp< SkMaskFilter > maskFilter) |
Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous SkMaskFilter. More... | |
SkImageFilter * | getImageFilter () const |
Returns SkImageFilter if set, or nullptr. More... | |
sk_sp< SkImageFilter > | refImageFilter () const |
Returns SkImageFilter if set, or nullptr. More... | |
void | setImageFilter (sk_sp< SkImageFilter > imageFilter) |
Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous SkImageFilter. More... | |
bool | nothingToDraw () const |
Returns true if SkPaint prevents all drawing; otherwise, the SkPaint may or may not allow drawing. More... | |
bool | canComputeFastBounds () const |
(to be made private) Returns true if SkPaint does not include elements requiring extensive computation to compute device bounds of drawn geometry. More... | |
const SkRect & | computeFastBounds (const SkRect &orig, SkRect *storage) const |
(to be made private) Only call this if canComputeFastBounds() returned true. More... | |
const SkRect & | computeFastStrokeBounds (const SkRect &orig, SkRect *storage) const |
(to be made private) More... | |
const SkRect & | doComputeFastBounds (const SkRect &orig, SkRect *storage, Style style) const |
(to be made private) Computes the bounds, overriding the SkPaint SkPaint::Style. More... | |
Static Public Attributes | |
static constexpr int | kStyleCount = kStrokeAndFill_Style + 1 |
May be used to verify that SkPaint::Style is a legal value. More... | |
static constexpr int | kCapCount = kLast_Cap + 1 |
May be used to verify that SkPaint::Cap is a legal value. More... | |
static constexpr int | kJoinCount = kLast_Join + 1 |
May be used to verify that SkPaint::Join is a legal value. More... | |
Friends | |
class | SkPaintPriv |
SK_API friend bool | operator== (const SkPaint &a, const SkPaint &b) |
Compares a and b, and returns true if a and b are equivalent. More... | |
bool | operator!= (const SkPaint &a, const SkPaint &b) |
Compares a and b, and returns true if a and b are not equivalent. More... | |
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 |
|
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 |
SkPaint::SkPaint | ( | const SkPaint & | paint | ) |
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
SkPaint::SkPaint | ( | SkPaint && | paint | ) |
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 |
SkPaint::~SkPaint | ( | ) |
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.
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.
(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
|
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 |
|
inline |
|
inline |
Retrieves alpha from the color used when stroking and filling.
|
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.
|
inline |
Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract a color component.
|
inline |
Retrieves alpha and RGB, unpremultiplied, as four floating point values.
RGB are extended sRGB values (sRGB gamut, and encoded with the sRGB transfer function).
|
inline |
Returns SkColorFilter if set, or nullptr.
Does not alter SkColorFilter SkRefCnt.
|
inline |
Returns SkImageFilter if set, or nullptr.
Does not alter SkImageFilter SkRefCnt.
|
inline |
Returns SkMaskFilter if set, or nullptr.
Does not alter SkMaskFilter SkRefCnt.
|
inline |
Returns SkPathEffect if set, or nullptr.
Does not alter SkPathEffect SkRefCnt.
|
inline |
|
inline |
Returns the geometry drawn at the beginning and end of strokes.
|
inline |
Returns the geometry drawn at the corners of strokes.
|
inline |
Returns the limit at which a sharp corner is drawn beveled.
|
inline |
Returns the thickness of the pen used by SkPaint to outline the shape.
|
inline |
Returns whether the geometry is filled, stroked, or filled and stroked.
|
inline |
Returns true if pixels on the active edges of SkPath may be drawn with partial transparency.
|
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.
bool SkPaint::nothingToDraw | ( | ) | const |
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 | ( | ) |
|
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 |
|
inline |
Requests, but does not require, that edge pixels draw opaque or with partial transparency.
aa | setting for antialiasing |
void SkPaint::setARGB | ( | U8CPU | a, |
U8CPU | r, | ||
U8CPU | g, | ||
U8CPU | b | ||
) |
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) |
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.
void SkPaint::setBlendMode | ( | SkBlendMode | mode | ) |
Helper method for calling setBlender().
This sets a blender that implements the specified blendmode enum.
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 |
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 |
|
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 |
Requests, but does not require, to distribute color error.
dither | setting for ditering |
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 | ) |
Set paint's style to kStroke if true, or kFill if false.
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
void SkPaint::setStrokeJoin | ( | Join | join | ) |
Sets the geometry drawn at the corners of strokes.
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 |
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
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
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.
|
friend |
unsigned SkPaint::fAntiAlias |
struct { ... } SkPaint::fBitfields |
uint32_t SkPaint::fBitfieldsUInt |
unsigned SkPaint::fCapType |
unsigned SkPaint::fDither |
unsigned SkPaint::fJoinType |
unsigned SkPaint::fPadding |
unsigned SkPaint::fStyle |
|
staticconstexpr |
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.