Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
SkPaint Class Reference

#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 ()
 
 SkPaint (const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
 
 SkPaint (const SkPaint &paint)
 
 SkPaint (SkPaint &&paint)
 
 ~SkPaint ()
 
SkPaintoperator= (const SkPaint &paint)
 
SkPaintoperator= (SkPaint &&paint)
 
void reset ()
 
bool isAntiAlias () const
 
void setAntiAlias (bool aa)
 
bool isDither () const
 
void setDither (bool dither)
 
Style getStyle () const
 
void setStyle (Style style)
 
void setStroke (bool)
 
SkColor getColor () const
 
SkColor4f getColor4f () const
 
void setColor (SkColor color)
 
void setColor (const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
 
void setColor4f (const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
 
float getAlphaf () const
 
uint8_t getAlpha () const
 
void setAlphaf (float a)
 
void setAlpha (U8CPU a)
 
void setARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 
SkScalar getStrokeWidth () const
 
void setStrokeWidth (SkScalar width)
 
SkScalar getStrokeMiter () const
 
void setStrokeMiter (SkScalar miter)
 
Cap getStrokeCap () const
 
void setStrokeCap (Cap cap)
 
Join getStrokeJoin () const
 
void setStrokeJoin (Join join)
 
SkShadergetShader () const
 
sk_sp< SkShaderrefShader () const
 
void setShader (sk_sp< SkShader > shader)
 
SkColorFiltergetColorFilter () const
 
sk_sp< SkColorFilterrefColorFilter () const
 
void setColorFilter (sk_sp< SkColorFilter > colorFilter)
 
std::optional< SkBlendModeasBlendMode () const
 
SkBlendMode getBlendMode_or (SkBlendMode defaultMode) const
 
bool isSrcOver () const
 
void setBlendMode (SkBlendMode mode)
 
SkBlendergetBlender () const
 
sk_sp< SkBlenderrefBlender () const
 
void setBlender (sk_sp< SkBlender > blender)
 
SkPathEffectgetPathEffect () const
 
sk_sp< SkPathEffectrefPathEffect () const
 
void setPathEffect (sk_sp< SkPathEffect > pathEffect)
 
SkMaskFiltergetMaskFilter () const
 
sk_sp< SkMaskFilterrefMaskFilter () const
 
void setMaskFilter (sk_sp< SkMaskFilter > maskFilter)
 
SkImageFiltergetImageFilter () const
 
sk_sp< SkImageFilterrefImageFilter () const
 
void setImageFilter (sk_sp< SkImageFilter > imageFilter)
 
bool nothingToDraw () const
 
bool canComputeFastBounds () const
 
const SkRectcomputeFastBounds (const SkRect &orig, SkRect *storage) const
 
const SkRectcomputeFastStrokeBounds (const SkRect &orig, SkRect *storage) const
 
const SkRectdoComputeFastBounds (const SkRect &orig, SkRect *storage, Style style) const
 

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)
 

Detailed Description

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.

Definition at line 44 of file SkPaint.h.

Member Typedef Documentation

◆ sk_is_trivially_relocatable

using SkPaint::sk_is_trivially_relocatable = std::true_type

Definition at line 658 of file SkPaint.h.

Member Enumeration Documentation

◆ Cap

Enumerator
kButt_Cap 

no stroke extension

kRound_Cap 

adds circle

kSquare_Cap 

adds square

kLast_Cap 

largest Cap value

kDefault_Cap 

equivalent to kButt_Cap

Definition at line 333 of file SkPaint.h.

333 {
334 kButt_Cap, //!< no stroke extension
335 kRound_Cap, //!< adds circle
336 kSquare_Cap, //!< adds square
337 kLast_Cap = kSquare_Cap, //!< largest Cap value
338 kDefault_Cap = kButt_Cap, //!< equivalent to kButt_Cap
339 };
@ kDefault_Cap
equivalent to kButt_Cap
Definition SkPaint.h:338
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition SkPaint.h:334
@ kLast_Cap
largest Cap value
Definition SkPaint.h:337
@ kSquare_Cap
adds square
Definition SkPaint.h:336

◆ Join

enum SkPaint::Join : uint8_t
Enumerator
kMiter_Join 

extends to miter limit

kRound_Join 

adds circle

kBevel_Join 

connects outside edges

kLast_Join 

equivalent to the largest value for Join

kDefault_Join 

equivalent to kMiter_Join

Definition at line 358 of file SkPaint.h.

358 : uint8_t {
359 kMiter_Join, //!< extends to miter limit
360 kRound_Join, //!< adds circle
361 kBevel_Join, //!< connects outside edges
362 kLast_Join = kBevel_Join, //!< equivalent to the largest value for Join
363 kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
364 };
@ kLast_Join
equivalent to the largest value for Join
Definition SkPaint.h:362
@ kDefault_Join
equivalent to kMiter_Join
Definition SkPaint.h:363
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361

◆ Style

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.

192 : uint8_t {
193 kFill_Style, //!< set to fill geometry
194 kStroke_Style, //!< set to stroke geometry
195 kStrokeAndFill_Style, //!< sets to stroke and fill geometry
196 };
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition SkPaint.h:195

Constructor & Destructor Documentation

◆ SkPaint() [1/4]

SkPaint::SkPaint ( )

Constructs SkPaint with default values.

Returns
default initialized SkPaint

example: https://fiddle.skia.org/c/@Paint_empty_constructor

Definition at line 38 of file SkPaint.cpp.

39 : fColor4f{0, 0, 0, 1} // opaque black
40 , fWidth{0}
41 , fMiterLimit{SkPaintDefaults_MiterLimit}
42 , fBitfields{(unsigned)false, // fAntiAlias
43 (unsigned)false, // fDither
44 (unsigned)SkPaint::kDefault_Cap, // fCapType
45 (unsigned)SkPaint::kDefault_Join, // fJoinType
46 (unsigned)SkPaint::kFill_Style, // fStyle
47 0} // fPadding
48{
49 static_assert(sizeof(fBitfields) == sizeof(fBitfieldsUInt), "");
50}
#define SkPaintDefaults_MiterLimit
struct SkPaint::@278::@280 fBitfields
uint32_t fBitfieldsUInt
Definition SkPaint.h:680

◆ SkPaint() [2/4]

SkPaint::SkPaint ( const SkColor4f color,
SkColorSpace colorSpace = nullptr 
)
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.

Parameters
colorunpremultiplied RGBA
colorSpaceSkColorSpace describing the encoding of color
Returns
SkPaint with the given color

Definition at line 52 of file SkPaint.cpp.

52 : SkPaint() {
53 this->setColor(color, colorSpace);
54}
void setColor(SkColor color)
Definition SkPaint.cpp:119
SkPaint()
Definition SkPaint.cpp:38

◆ SkPaint() [3/4]

SkPaint::SkPaint ( const SkPaint paint)
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.

Parameters
paintoriginal to copy
Returns
shallow copy of paint

example: https://fiddle.skia.org/c/@Paint_copy_const_SkPaint

◆ SkPaint() [4/4]

SkPaint::SkPaint ( SkPaint &&  paint)
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.

Parameters
paintoriginal to move
Returns
content of paint

example: https://fiddle.skia.org/c/@Paint_move_SkPaint

◆ ~SkPaint()

SkPaint::~SkPaint ( )
default

Decreases SkPaint SkRefCnt of owned objects: SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, and SkImageFilter. If the objects containing SkRefCnt go to zero, they are deleted.

Member Function Documentation

◆ asBlendMode()

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.

138 {
139 return fBlender ? as_BB(fBlender)->asBlendMode()
141}
@ kSrcOver
r = s + (1-sa)*d
SkBlenderBase * as_BB(SkBlender *blend)
virtual std::optional< SkBlendMode > asBlendMode() const

◆ canComputeFastBounds()

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.

Returns
true if SkPaint allows for fast computation of bounds

Definition at line 201 of file SkPaint.cpp.

201 {
202 if (this->getImageFilter() && !this->getImageFilter()->canComputeFastBounds()) {
203 return false;
204 }
205 // Pass nullptr for the bounds to determine if they can be computed
206 if (this->getPathEffect() &&
207 !as_PEB(this->getPathEffect())->computeFastBounds(nullptr)) {
208 return false;
209 }
210 return true;
211}
static SkPathEffectBase * as_PEB(SkPathEffect *effect)
SkPathEffect * getPathEffect() const
Definition SkPaint.h:506
const SkRect & computeFastBounds(const SkRect &orig, SkRect *storage) const
Definition SkPaint.cpp:213
SkImageFilter * getImageFilter() const
Definition SkPaint.h:564
bool canComputeFastBounds() const
Definition SkPaint.cpp:201

◆ computeFastBounds()

const SkRect & SkPaint::computeFastBounds ( const SkRect orig,
SkRect storage 
) const

(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.

213 {
214 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
215 SkASSERT(orig.isSorted());
216 SkPaint::Style style = this->getStyle();
217 // ultra fast-case: filling with no effects that affect geometry
218 if (kFill_Style == style) {
219 uintptr_t effects = 0;
220 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
221 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
222 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
223 if (!effects) {
224 return orig;
225 }
226 }
227
228 return this->doComputeFastBounds(orig, storage, style);
229}
#define SkASSERT(cond)
Definition SkAssert.h:116
const SkRect & doComputeFastBounds(const SkRect &orig, SkRect *storage, Style style) const
Definition SkPaint.cpp:231
Style getStyle() const
Definition SkPaint.h:204
SkMaskFilter * getMaskFilter() const
Definition SkPaint.h:534
bool isSorted() const
Definition SkRect.h:705

◆ computeFastStrokeBounds()

const SkRect & SkPaint::computeFastStrokeBounds ( const SkRect orig,
SkRect storage 
) const
inline

(to be made private)

Parameters
origgeometry modified by SkPaint when drawn
storagecomputed bounds of geometry
Returns
fast computed bounds

Definition at line 640 of file SkPaint.h.

641 {
642 return this->doComputeFastBounds(orig, storage, kStroke_Style);
643 }

◆ doComputeFastBounds()

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.

Parameters
origgeometry modified by SkPaint when drawn
storagecomputed bounds of geometry
styleoverrides SkPaint::Style
Returns
fast computed bounds

Definition at line 231 of file SkPaint.cpp.

233 {
234 SkASSERT(storage);
235
236 const SkRect* src = &origSrc;
237
238 SkRect tmpSrc;
239 if (this->getPathEffect()) {
240 tmpSrc = origSrc;
242 src = &tmpSrc;
243 }
244
245 SkScalar radius = SkStrokeRec::GetInflationRadius(*this, style);
246 *storage = src->makeOutset(radius, radius);
247
248 if (this->getMaskFilter()) {
249 as_MFB(this->getMaskFilter())->computeFastBounds(*storage, storage);
250 }
251
252 if (this->getImageFilter()) {
253 *storage = this->getImageFilter()->computeFastBounds(*storage);
254 }
255
256 return *storage;
257}
#define SkAssertResult(cond)
Definition SkAssert.h:123
SkMaskFilterBase * as_MFB(SkMaskFilter *mf)
virtual SkRect computeFastBounds(const SkRect &bounds) const
virtual void computeFastBounds(const SkRect &src, SkRect *dest) const
static SkScalar GetInflationRadius(const SkPaint &, SkPaint::Style)
float SkScalar
Definition extension.cpp:12

◆ getAlpha()

uint8_t SkPaint::getAlpha ( ) const
inline

Definition at line 264 of file SkPaint.h.

264 {
265 return static_cast<uint8_t>(sk_float_round2int(this->getAlphaf() * 255));
266 }
#define sk_float_round2int(x)
float getAlphaf() const
Definition SkPaint.h:261

◆ getAlphaf()

float SkPaint::getAlphaf ( ) const
inline

Retrieves alpha from the color used when stroking and filling.

Returns
alpha ranging from zero, fully transparent, to one, fully opaque

Definition at line 261 of file SkPaint.h.

261{ return fColor4f.fA; }

◆ getBlender()

SkBlender * SkPaint::getBlender ( ) const
inline

Returns the user-supplied blend function, if one has been set. Does not alter SkBlender's SkRefCnt.

A nullptr blender signifies the default SrcOver behavior.

Returns
the SkBlender assigned to this paint, otherwise nullptr

Definition at line 480 of file SkPaint.h.

480{ return fBlender.get(); }
T * get() const
Definition SkRefCnt.h:303

◆ getBlendMode_or()

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.

143 {
144 return this->asBlendMode().value_or(defaultMode);
145}
std::optional< SkBlendMode > asBlendMode() const
Definition SkPaint.cpp:138

◆ getColor()

SkColor SkPaint::getColor ( ) const
inline

Retrieves alpha and RGB, unpremultiplied, packed into 32 bits. Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract a color component.

Returns
unpremultiplied ARGB

Definition at line 225 of file SkPaint.h.

225{ return fColor4f.toSkColor(); }

◆ getColor4f()

SkColor4f SkPaint::getColor4f ( ) const
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).

Returns
unpremultiplied RGBA

Definition at line 232 of file SkPaint.h.

232{ return fColor4f; }

◆ getColorFilter()

SkColorFilter * SkPaint::getColorFilter ( ) const
inline

Returns SkColorFilter if set, or nullptr. Does not alter SkColorFilter SkRefCnt.

Returns
SkColorFilter if previously set, nullptr otherwise

Definition at line 426 of file SkPaint.h.

426{ return fColorFilter.get(); }

◆ getImageFilter()

SkImageFilter * SkPaint::getImageFilter ( ) const
inline

Returns SkImageFilter if set, or nullptr. Does not alter SkImageFilter SkRefCnt.

Returns
SkImageFilter if previously set, nullptr otherwise

Definition at line 564 of file SkPaint.h.

564{ return fImageFilter.get(); }

◆ getMaskFilter()

SkMaskFilter * SkPaint::getMaskFilter ( ) const
inline

Returns SkMaskFilter if set, or nullptr. Does not alter SkMaskFilter SkRefCnt.

Returns
SkMaskFilter if previously set, nullptr otherwise

Definition at line 534 of file SkPaint.h.

534{ return fMaskFilter.get(); }

◆ getPathEffect()

SkPathEffect * SkPaint::getPathEffect ( ) const
inline

Returns SkPathEffect if set, or nullptr. Does not alter SkPathEffect SkRefCnt.

Returns
SkPathEffect if previously set, nullptr otherwise

Definition at line 506 of file SkPaint.h.

506{ return fPathEffect.get(); }

◆ getShader()

SkShader * SkPaint::getShader ( ) const
inline

Returns optional colors used when filling a path, such as a gradient.

Does not alter SkShader SkRefCnt.

Returns
SkShader if previously set, nullptr otherwise

Definition at line 397 of file SkPaint.h.

397{ return fShader.get(); }

◆ getStrokeCap()

Cap SkPaint::getStrokeCap ( ) const
inline

Returns the geometry drawn at the beginning and end of strokes.

Definition at line 372 of file SkPaint.h.

372{ return (Cap)fBitfields.fCapType; }

◆ getStrokeJoin()

Join SkPaint::getStrokeJoin ( ) const
inline

Returns the geometry drawn at the corners of strokes.

Definition at line 383 of file SkPaint.h.

383{ return (Join)fBitfields.fJoinType; }

◆ getStrokeMiter()

SkScalar SkPaint::getStrokeMiter ( ) const
inline

Returns the limit at which a sharp corner is drawn beveled.

Returns
zero and greater miter limit

Definition at line 318 of file SkPaint.h.

318{ return fMiterLimit; }

◆ getStrokeWidth()

SkScalar SkPaint::getStrokeWidth ( ) const
inline

Returns the thickness of the pen used by SkPaint to outline the shape.

Returns
zero for hairline, greater than zero for pen thickness

Definition at line 300 of file SkPaint.h.

300{ return fWidth; }

◆ getStyle()

Style SkPaint::getStyle ( ) const
inline

Returns whether the geometry is filled, stroked, or filled and stroked.

Definition at line 204 of file SkPaint.h.

204{ return (Style)fBitfields.fStyle; }

◆ isAntiAlias()

bool SkPaint::isAntiAlias ( ) const
inline

Returns true if pixels on the active edges of SkPath may be drawn with partial transparency.

Returns
antialiasing state

Definition at line 162 of file SkPaint.h.

162 {
163 return SkToBool(fBitfields.fAntiAlias);
164 }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ isDither()

bool SkPaint::isDither ( ) const
inline

Returns true if color error may be distributed to smooth color transition.

Returns
dithering state

Definition at line 175 of file SkPaint.h.

175 {
176 return SkToBool(fBitfields.fDither);
177 }

◆ isSrcOver()

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.

147 {
148 return !fBlender || as_BB(fBlender)->asBlendMode() == SkBlendMode::kSrcOver;
149}

◆ nothingToDraw()

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.

Returns
true if SkPaint prevents all drawing

example: https://fiddle.skia.org/c/@Paint_nothingToDraw

Definition at line 273 of file SkPaint.cpp.

273 {
274 auto bm = this->asBlendMode();
275 if (!bm) {
276 return false;
277 }
278 switch (bm.value()) {
284 if (0 == this->getAlpha()) {
285 return !affects_alpha(fColorFilter.get()) && !affects_alpha(fImageFilter.get());
286 }
287 break;
289 return true;
290 default:
291 break;
292 }
293 return false;
294}
@ kPlus
r = min(s + d, 1)
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstOver
r = d + (1-da)*s
@ kDstOut
r = d * (1-sa)
static bool affects_alpha(const SkColorFilter *cf)
Definition SkPaint.cpp:262
uint8_t getAlpha() const
Definition SkPaint.h:264

◆ operator=() [1/2]

SkPaint & SkPaint::operator= ( const SkPaint paint)
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 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.

Parameters
paintoriginal to copy
Returns
content of paint

example: https://fiddle.skia.org/c/@Paint_copy_operator

◆ operator=() [2/2]

SkPaint & SkPaint::operator= ( SkPaint &&  paint)
default

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.

Parameters
paintoriginal to move
Returns
content of paint

example: https://fiddle.skia.org/c/@Paint_move_operator

◆ refBlender()

sk_sp< SkBlender > SkPaint::refBlender ( ) const

Returns the user-supplied blend function, if one has been set. Increments the SkBlender's SkRefCnt by one.

A nullptr blender signifies the default SrcOver behavior.

Returns
the SkBlender assigned to this paint, otherwise nullptr

◆ refColorFilter()

sk_sp< SkColorFilter > SkPaint::refColorFilter ( ) const

Returns SkColorFilter if set, or nullptr. Increases SkColorFilter SkRefCnt by one.

Returns
SkColorFilter if set, or nullptr

example: https://fiddle.skia.org/c/@Paint_refColorFilter

◆ refImageFilter()

sk_sp< SkImageFilter > SkPaint::refImageFilter ( ) const

Returns SkImageFilter if set, or nullptr. Increases SkImageFilter SkRefCnt by one.

Returns
SkImageFilter if previously set, nullptr otherwise

example: https://fiddle.skia.org/c/@Paint_refImageFilter

◆ refMaskFilter()

sk_sp< SkMaskFilter > SkPaint::refMaskFilter ( ) const

Returns SkMaskFilter if set, or nullptr.

Increases SkMaskFilter SkRefCnt by one.

Returns
SkMaskFilter if previously set, nullptr otherwise

example: https://fiddle.skia.org/c/@Paint_refMaskFilter

◆ refPathEffect()

sk_sp< SkPathEffect > SkPaint::refPathEffect ( ) const

Returns SkPathEffect if set, or nullptr. Increases SkPathEffect SkRefCnt by one.

Returns
SkPathEffect if previously set, nullptr otherwise

example: https://fiddle.skia.org/c/@Paint_refPathEffect

◆ refShader()

sk_sp< SkShader > SkPaint::refShader ( ) const

Returns optional colors used when filling a path, such as a gradient.

Increases SkShader SkRefCnt by one.

Returns
SkShader if previously set, nullptr otherwise

example: https://fiddle.skia.org/c/@Paint_refShader

◆ reset()

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.

103{ *this = SkPaint(); }

◆ setAlpha()

void SkPaint::setAlpha ( U8CPU  a)
inline

Definition at line 279 of file SkPaint.h.

279 {
280 this->setAlphaf(a * (1.0f / 255));
281 }
void setAlphaf(float a)
Definition SkPaint.cpp:130
struct MyStruct a[10]

◆ setAlphaf()

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.

Parameters
aalpha component of color

Definition at line 130 of file SkPaint.cpp.

130 {
131 fColor4f.fA = SkTPin(a, 0.0f, 1.0f);
132}
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition SkTPin.h:19

◆ setAntiAlias()

void SkPaint::setAntiAlias ( bool  aa)
inline

Requests, but does not require, that edge pixels draw opaque or with partial transparency.

Parameters
aasetting for antialiasing

Definition at line 170 of file SkPaint.h.

170{ fBitfields.fAntiAlias = static_cast<unsigned>(aa); }

◆ setARGB()

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.

Parameters
aamount of alpha, from fully transparent (0) to fully opaque (255)
ramount of red, from no red (0) to full red (255)
gamount of green, from no green (0) to full green (255)
bamount 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.

134 {
135 this->setColor(SkColorSetARGB(a, r, g, b));
136}
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
static bool b

◆ setBlender()

void SkPaint::setBlender ( sk_sp< SkBlender blender)

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.

155 {
156 fBlender = std::move(blender);
157}

◆ setBlendMode()

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.

151 {
152 this->setBlender(mode == SkBlendMode::kSrcOver ? nullptr : SkBlender::Mode(mode));
153}
void setBlender(sk_sp< SkBlender > blender)
Definition SkPaint.cpp:155
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228

◆ setColor() [1/2]

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.

Parameters
colorunpremultiplied RGBA
colorSpaceSkColorSpace describing the encoding of color

Definition at line 123 of file SkPaint.cpp.

123 {
126 fColor4f = {color.fR, color.fG, color.fB, SkTPin(color.fA, 0.0f, 1.0f)};
127 steps.apply(fColor4f.vec());
128}
SkColor4f color
kUnpremul_SkAlphaType
SkColorSpace * sk_srgb_singleton()

◆ setColor() [2/2]

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.

Parameters
colorunpremultiplied ARGB

example: https://fiddle.skia.org/c/@Paint_setColor

Definition at line 119 of file SkPaint.cpp.

119 {
120 fColor4f = SkColor4f::FromColor(color);
121}
static SkRGBA4f FromColor(SkColor color)

◆ setColor4f()

void SkPaint::setColor4f ( const SkColor4f color,
SkColorSpace colorSpace = nullptr 
)
inline

Definition at line 253 of file SkPaint.h.

253 {
254 this->setColor(color, colorSpace);
255 }

◆ setColorFilter()

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.

Parameters
colorFilterSkColorFilter to apply to subsequent draw

example: https://fiddle.skia.org/c/@Blend_Mode_Methods example: https://fiddle.skia.org/c/@Paint_setColorFilter

◆ setDither()

void SkPaint::setDither ( bool  dither)
inline

Requests, but does not require, to distribute color error.

Parameters
dithersetting for ditering

Definition at line 182 of file SkPaint.h.

182{ fBitfields.fDither = static_cast<unsigned>(dither); }

◆ setImageFilter()

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.

Parameters
imageFilterhow SkImage is sampled when transformed

example: https://fiddle.skia.org/c/@Paint_setImageFilter

◆ setMaskFilter()

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.

Parameters
maskFiltermodifies clipping mask generated from drawn geometry

example: https://fiddle.skia.org/c/@Paint_setMaskFilter example: https://fiddle.skia.org/c/@Typeface_Methods

◆ setPathEffect()

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.

Parameters
pathEffectreplace SkPath with a modification when drawn

example: https://fiddle.skia.org/c/@Mask_Filter_Methods example: https://fiddle.skia.org/c/@Paint_setPathEffect

◆ setShader()

void SkPaint::setShader ( sk_sp< SkShader shader)

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.

Parameters
shaderhow 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

◆ setStroke()

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.

115 {
116 fBitfields.fStyle = isStroke ? kStroke_Style : kFill_Style;
117}

◆ setStrokeCap()

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.

179 {
180 if ((unsigned)ct < kCapCount) {
181 fBitfields.fCapType = SkToU8(ct);
182 } else {
183#ifdef SK_REPORT_API_RANGE_CHECK
184 SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct);
185#endif
186 }
187}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
constexpr uint8_t SkToU8(S x)
Definition SkTo.h:22
static constexpr int kCapCount
Definition SkPaint.h:343

◆ setStrokeJoin()

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.

189 {
190 if ((unsigned)jt < kJoinCount) {
191 fBitfields.fJoinType = SkToU8(jt);
192 } else {
193#ifdef SK_REPORT_API_RANGE_CHECK
194 SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt);
195#endif
196 }
197}
static constexpr int kJoinCount
Definition SkPaint.h:368

◆ setStrokeMiter()

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.

Parameters
miterzero and greater miter limit

example: https://fiddle.skia.org/c/@Paint_setStrokeMiter

Definition at line 169 of file SkPaint.cpp.

169 {
170 if (limit >= 0) {
171 fMiterLimit = limit;
172 } else {
173#ifdef SK_REPORT_API_RANGE_CHECK
174 SkDebugf("SkPaint::setStrokeMiter() called with negative value\n");
175#endif
176 }
177}

◆ setStrokeWidth()

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.

Parameters
widthzero 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.

159 {
160 if (width >= 0) {
161 fWidth = width;
162 } else {
163#ifdef SK_REPORT_API_RANGE_CHECK
164 SkDebugf("SkPaint::setStrokeWidth() called with negative value\n");
165#endif
166 }
167}
int32_t width

◆ setStyle()

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.

105 {
106 if ((unsigned)style < kStyleCount) {
107 fBitfields.fStyle = style;
108 } else {
109#ifdef SK_REPORT_API_RANGE_CHECK
110 SkDebugf("SkPaint::setStyle(%d) out of range\n", style);
111#endif
112 }
113}
static constexpr int kStyleCount
Definition SkPaint.h:200

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const SkPaint a,
const SkPaint b 
)
friend

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.

Parameters
aSkPaint to compare
bSkPaint to compare
Returns
true if SkPaint pair are not equivalent

Definition at line 148 of file SkPaint.h.

148 {
149 return !(a == b);
150 }

◆ operator==

SK_API friend bool operator== ( const SkPaint a,
const SkPaint b 
)
friend

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.

Parameters
aSkPaint to compare
bSkPaint to compare
Returns
true if SkPaint pair are equivalent

Definition at line 66 of file SkPaint.cpp.

66 {
67#define EQUAL(field) (a.field == b.field)
68 return EQUAL(fPathEffect)
69 && EQUAL(fShader)
70 && EQUAL(fMaskFilter)
71 && EQUAL(fColorFilter)
72 && EQUAL(fBlender)
73 && EQUAL(fImageFilter)
74 && EQUAL(fColor4f)
75 && EQUAL(fWidth)
76 && EQUAL(fMiterLimit)
78 ;
79#undef EQUAL
80}
#define EQUAL(field)

◆ SkPaintPriv

friend class SkPaintPriv
friend

Definition at line 692 of file SkPaint.h.

Member Data Documentation

◆ fAntiAlias

unsigned SkPaint::fAntiAlias

Definition at line 673 of file SkPaint.h.

◆ [struct]

struct { ... } SkPaint::fBitfields

◆ fBitfieldsUInt

uint32_t SkPaint::fBitfieldsUInt

Definition at line 680 of file SkPaint.h.

◆ fCapType

unsigned SkPaint::fCapType

Definition at line 675 of file SkPaint.h.

◆ fDither

unsigned SkPaint::fDither

Definition at line 674 of file SkPaint.h.

◆ fJoinType

unsigned SkPaint::fJoinType

Definition at line 676 of file SkPaint.h.

◆ fPadding

unsigned SkPaint::fPadding

Definition at line 678 of file SkPaint.h.

◆ fStyle

unsigned SkPaint::fStyle

Definition at line 677 of file SkPaint.h.

◆ kCapCount

constexpr int SkPaint::kCapCount = kLast_Cap + 1
staticconstexpr

May be used to verify that SkPaint::Cap is a legal value.

Definition at line 343 of file SkPaint.h.

◆ kJoinCount

constexpr int SkPaint::kJoinCount = kLast_Join + 1
staticconstexpr

May be used to verify that SkPaint::Join is a legal value.

Definition at line 368 of file SkPaint.h.

◆ kStyleCount

constexpr int SkPaint::kStyleCount = kStrokeAndFill_Style + 1
staticconstexpr

May be used to verify that SkPaint::Style is a legal value.

Definition at line 200 of file SkPaint.h.


The documentation for this class was generated from the following files: