android cpu part,Android Study -- 5.4 Paint Part1

//SkPaint.h

/** \class SkPaint

The SkPaint class holds the style and color information about how to draw

geometries, text and bitmaps.

*/

//SkPaint包含有绘画图形,字符,图像时的风格,颜色等信息。

classSkPaint{

public:

SkPaint();

SkPaint(constSkPaint&paint);

~SkPaint();

SkPaint&operator=(constSkPaint&);

friendintoperator==(constSkPaint&a,constSkPaint&b);

friendintoperator!=(constSkPaint&a,constSkPaint&b)

{

return!(a==b);

}

voidflatten(SkFlattenableWriteBuffer&)const;

voidunflatten(SkFlattenableReadBuffer&);

/** Restores the paint to its initial settings.

*/

//重新初始化

voidreset();

/** Specifies the bit values that are stored in the paint's flags.

*/

//paint的flag

enum Flags {

kAntiAlias_Flag= 0x01,//!< mask to enable antialiasing

kFilterBitmap_Flag= 0x02,//!< mask to enable bitmap filtering

kDither_Flag= 0x04,//!< mask to enable dithering

kUnderlineText_Flag= 0x08,//!< mask to enable underline text

kStrikeThruText_Flag= 0x10,//!< mask to enable strike-thru text

kFakeBoldText_Flag= 0x20,//!< mask to enable fake-bold text

kLinearText_Flag= 0x40,//!< mask to enable linear-text

kSubpixelText_Flag= 0x80,//!< mask to enable subpixel-text

kDevKernText_Flag= 0x100,//!< mask to enable device kerning text

kAllFlags = 0x1FF

};

//下面是关于获得和设置flag的相关函数

/** Return the paint's flags. Use the Flag enum to test flag values.

@return the paint's flags (see enums ending in _Flag for bit masks)

*/

uint32_tgetFlags()const{returnfFlags; }

/** Set the paint's flags. Use the Flag enum to specific flag values.

@param flagsThe new flag bits for the paint (see Flags enum)

*/

voidsetFlags(uint32_tflags);

/** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set

@return true if the antialias bit is set in the paint's flags.

*/

boolisAntiAlias()const

{

returnSkToBool(this->getFlags() & kAntiAlias_Flag);

}

/** Helper for setFlags(), setting or clearing the kAntiAlias_Flag bit

@param aatrue to enable antialiasing, false to disable it

*/

voidsetAntiAlias(boolaa);

/** Helper for getFlags(), returning true if kDither_Flag bit is set

@return true if the dithering bit is set in the paint's flags.

*/

boolisDither()const

{

returnSkToBool(this->getFlags() & kDither_Flag);

}

/** Helper for setFlags(), setting or clearing the kDither_Flag bit

@param dithertrue to enable dithering, false to disable it

*/

voidsetDither(booldither);

/** Helper for getFlags(), returning true if kLinearText_Flag bit is set

@return true if the lineartext bit is set in the paint's flags

*/

boolisLinearText()const

{

returnSkToBool(this->getFlags() & kLinearText_Flag);

}

/** Helper for setFlags(), setting or clearing the kLinearText_Flag bit

@param linearText true to set the linearText bit in the paint's flags,

false to clear it.

*/

voidsetLinearText(boollinearText);

/** Helper for getFlags(), returning true if kSubpixelText_Flag bit is set

@return true if the lineartext bit is set in the paint's flags

*/

boolisSubpixelText()const

{

returnSkToBool(this->getFlags() & kSubpixelText_Flag);

}

/** Helper for setFlags(), setting or clearing the kSubpixelText_Flag bit

@param subpixelText true to set the subpixelText bit in the paint's

flags, false to clear it.

*/

voidsetSubpixelText(boolsubpixelText);

/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set

@return true if the underlineText bit is set in the paint's flags.

*/

boolisUnderlineText()const

{

returnSkToBool(this->getFlags() & kUnderlineText_Flag);

}

/** Helper for setFlags(), setting or clearing the kUnderlineText_Flag bit

@param underlineText true to set the underlineText bit in the paint's

flags, false to clear it.

*/

voidsetUnderlineText(boolunderlineText);

/** Helper for getFlags(), returns true if kStrikeThruText_Flag bit is set

@return true if the strikeThruText bit is set in the paint's flags.

*/

boolisStrikeThruText()const

{

returnSkToBool(this->getFlags() & kStrikeThruText_Flag);

}

/** Helper for setFlags(), setting or clearing the kStrikeThruText_Flag bit

@param strikeThruTexttrue to set the strikeThruText bit in the

paint's flags, false to clear it.

*/

voidsetStrikeThruText(boolstrikeThruText);

/** Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set

@return true if the kFakeBoldText_Flag bit is set in the paint's flags.

*/

boolisFakeBoldText()const

{

returnSkToBool(this->getFlags() & kFakeBoldText_Flag);

}

/** Helper for setFlags(), setting or clearing the kFakeBoldText_Flag bit

@param fakeBoldText true to set the kFakeBoldText_Flag bit in the paint's

flags, false to clear it.

*/

voidsetFakeBoldText(boolfakeBoldText);

/** Helper for getFlags(), returns true if kDevKernText_Flag bit is set

@return true if the kernText bit is set in the paint's flags.

*/

boolisDevKernText()const

{

returnSkToBool(this->getFlags() & kDevKernText_Flag);

}

/** Helper for setFlags(), setting or clearing the kKernText_Flag bit

@param kernText true to set the kKernText_Flag bit in the paint's

flags, false to clear it.

*/

voidsetDevKernText(booldevKernText);

boolisFilterBitmap()const

{

returnSkToBool(this->getFlags() & kFilterBitmap_Flag);

}

voidsetFilterBitmap(boolfilterBitmap);

/** Styles apply to rect, oval, path, and text.

Bitmaps are always drawn in "fill", and lines are always drawn in

"stroke".

*/

//图形图像的填充类型,适用于rect, oval, path, and text.

//Bitmaps使用kFill_Style;lines使用kStroke_Style。

enum Style {

kFill_Style,//!< fill with the paint's color

kStroke_Style,//!< stroke with the paint's color

kStrokeAndFill_Style,//!< fill and stroke with the paint's color

kStyleCount,

};

/** Return the paint's style, used for controlling how primitives'

geometries are interpreted (except for drawBitmap, which always assumes

kFill_Style).

@return the paint's Style

*/

StylegetStyle()const{return(Style)fStyle; }

/** Set the paint's style, used for controlling how primitives'

geometries are interpreted (except for drawBitmap, which always assumes

Fill).

@param styleThe new style to set in the paint

*/

voidsetStyle(Stylestyle);

/** Return the paint's color. Note that the color is a 32bit value

containing alpha as well as r,g,b. This 32bit value is not

premultiplied, meaning that its alpha can be any value, regardless of

the values of r,g,b.

@return the paint's color (and alpha).

*/

//当前paint的颜色值

SkColorgetColor()const{returnfColor; }

/** Set the paint's color. Note that the color is a 32bit value containing

alpha as well as r,g,b. This 32bit value is not premultiplied, meaning

that its alpha can be any value, regardless of the values of r,g,b.

@param colorThe new color (including alpha) to set in the paint.

*/

voidsetColor(SkColorcolor);

/** Helper to getColor() that just returns the color's alpha value.

@return the alpha component of the paint's color.

*/

uint8_tgetAlpha()const{returnSkToU8(SkColorGetA(fColor)); }

/** Helper to setColor(), that only assigns the color's alpha value,

leaving its r,g,b values unchanged.

@param aset the alpha component (0..255) of the paint's color.

*/

voidsetAlpha(U8CPUa);

/** Helper to setColor(), that takes a,r,g,b and constructs the color value

using SkColorSetARGB()

@param aThe new alpha component (0..255) of the paint's color.

@param rThe new red component (0..255) of the paint's color.

@param gThe new green component (0..255) of the paint's color.

@param bThe new blue component (0..255) of the paint's color.

*/

voidsetARGB(U8CPUa,U8CPUr,U8CPUg,U8CPUb);

/** Return the width for stroking.

A value of 0 strokes in hairline mode.

Hairlines always draw 1-pixel wide, regardless of the matrix.

@return the paint's stroke width, used whenever the paint's style is

Stroke or StrokeAndFill.

*/

//画笔宽度。如果fWidth为0,则会使用宽度为1的画笔

SkScalargetStrokeWidth()const{returnfWidth; }

/** Set the width for stroking.

Pass 0 to stroke in hairline mode.

Hairlines always draw 1-pixel wide, regardless of the matrix.

@param width set the paint's stroke width, used whenever the paint's

style is Stroke or StrokeAndFill.

*/

//可以传入0为参数

voidsetStrokeWidth(SkScalarwidth);

/** Return the paint's stroke miter value. This is used to control the

behavior of miter joins when the joins angle is sharp.

@return the paint's miter limit, used whenever the paint's style is

Stroke or StrokeAndFill.

*/

//画笔相交的斜角缝大小。这个参数会影响交接的效果。优先级高于paint's style

SkScalargetStrokeMiter()const{returnfMiterLimit; }

/** Set the paint's stroke miter value. This is used to control the

behavior of miter joins when the joins angle is sharp. This value must

be >= 0.

@param miterset the miter limit on the paint, used whenever the

paint's style is Stroke or StrokeAndFill.

*/

//传入参数必须>0

voidsetStrokeMiter(SkScalarmiter);

/** Cap enum specifies the settings for the paint's strokecap. This is the

treatment that is applied to the beginning and end of each non-closed

contour (e.g. lines).

*/

enum Cap {

kButt_Cap,//!< begin/end contours with no extension

kRound_Cap,//!< begin/end contours with a semi-circle extension

kSquare_Cap,//!< begin/end contours with a half square extension

kCapCount,

kDefault_Cap = kButt_Cap

};

/** Join enum specifies the settings for the paint's strokejoin. This is

the treatment that is applied to corners in paths and rectangles.

*/

enum Join {

kMiter_Join,//!< connect path segments with a sharp join

kRound_Join,//!< connect path segments with a round join

kBevel_Join,//!< connect path segments with a flat bevel join

kJoinCount,

kDefault_Join = kMiter_Join

};

//下面是cap style, join style的函数

/** Return the paint's stroke cap type, controlling how the start and end

of stroked lines and paths are treated.

@return the line cap style for the paint, used whenever the paint's

style is Stroke or StrokeAndFill.

*/

CapgetStrokeCap()const{return(Cap)fCapType; }

/** Set the paint's stroke cap type.

@param capset the paint's line cap style, used whenever the paint's

style is Stroke or StrokeAndFill.

*/

voidsetStrokeCap(Capcap);

/** Return the paint's stroke join type.

@return the paint's line join style, used whenever the paint's style is

Stroke or StrokeAndFill.

*/

JoingetStrokeJoin()const{return(Join)fJoinType; }

/** Set the paint's stroke join type.

@param join set the paint's line join style, used whenever the paint's

style is Stroke or StrokeAndFill.

*/

voidsetStrokeJoin(Joinjoin);

/** Applies any/all effects (patheffect, stroking) to src, returning the

result in dst. The result is that drawing src with this paint will be

the same as drawing dst with a default paint (at least from the

geometric perspective).

@param srcinput path

@param dstoutput path (may be the same as src)

@returntrue if the path should be filled, or false if it should be

drawn with a hairline (width == 0)

*/

//使用当前paint的设置绘画src SkPath。结果有dst传出

boolgetFillPath(constSkPath&src, SkPath*dst)const;

/** Returns true if the current paint settings allow for fast computation of

bounds (i.e. there is nothing complex like a patheffect that would make

the bounds computation expensive.

*/

//根据paint的设置判断是否可以快速计算绘画的边界。如果使用像patheffect类似的设置,则会话费较长的时间,也就不能快速计算。

boolcanComputeFastBounds()const;

/** 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

rect parameter. It returns the adjusted bounds that can then be used

for quickReject tests.

The returned rect will either be orig or storage, thus the caller

should not rely on storage being set to the result, but should always

use the retured value. It is legal for orig and storage to be the same

rect.

e.g.

if (paint.canComputeFastBounds()) {

SkRect r, storage;

path.computeBounds(&r, SkPath::kFast_BoundsType);

const SkRect& fastR = paint.computeFastBounds(r, &storage);

if (canvas->quickReject(fastR, ...)) {

// don't draw the path

}

}

*/

constSkRect&computeFastBounds(constSkRect&orig, SkRect*storage)const;

/** Get the paint's shader object.

The shader's reference count is not affected.

@return the paint's shader (or NULL)

*/

//paint的阴影效果

SkShader*getShader()const{returnfShader; }

/** Set or clear the shader object.

Pass NULL to clear any previous shader.

As a convenience, the parameter passed is also returned.

If a previous shader exists, its reference count is decremented.

If shader is not NULL, its reference count is incremented.

@param shaderMay be NULL. The shader to be installed in the paint

@returnshader

*/

//如果传入NULL,则清除以前的阴影效果

SkShader*setShader(SkShader*shader);

/** Get the paint's colorfilter. If there is a colorfilter, its reference

count is not changed.

@return the paint's colorfilter (or NULL)

*/

//颜色过滤器

SkColorFilter*getColorFilter()const{returnfColorFilter; }

/** Set or clear the paint's colorfilter, returning the parameter.

If the paint already has a filter, its reference count is decremented.

If filter is not NULL, its reference count is incremented.

@param filterMay be NULL. The filter to be installed in the paint

@returnfilter

*/

SkColorFilter*setColorFilter(SkColorFilter*filter);

/** Get the paint's xfermode object.

The xfermode's reference count is not affected.

@return the paint's xfermode (or NULL)

*/

//坐标转换模式

SkXfermode*getXfermode()const{returnfXfermode; }

/** Set or clear the xfermode object.

Pass NULL to clear any previous xfermode.

As a convenience, the parameter passed is also returned.

If a previous xfermode exists, its reference count is decremented.

If xfermode is not NULL, its reference count is incremented.

@param xfermode May be NULL. The new xfermode to be installed in the

paint

@returnxfermode

*/

SkXfermode*setXfermode(SkXfermode*xfermode);

/** Helper for setXfermode, passing the corresponding xfermode object

returned from the PorterDuff factory.

@param mode The porter-duff mode used to create an xfermode for the

paint.

@returnthe resulting xfermode object (or NULL if the mode is

SrcOver)

*/

//设置PorterDuff绘画模式

SkXfermode*setPorterDuffXfermode(SkPorterDuff::Modemode);

/** Get the paint's patheffect object.

The patheffect reference count is not affected.

@return the paint's patheffect (or NULL)

*/

//可以作为paint的绘画效果来看待

SkPathEffect*getPathEffect()const{returnfPathEffect; }

/** Set or clear the patheffect object.

Pass NULL to clear any previous patheffect.

As a convenience, the parameter passed is also returned.

If a previous patheffect exists, its reference count is decremented.

If patheffect is not NULL, its reference count is incremented.

@param effectMay be NULL. The new patheffect to be installed in the

paint

@returneffect

*/

SkPathEffect*setPathEffect(SkPathEffect*effect);

/** Get the paint's maskfilter object.

The maskfilter reference count is not affected.

@return the paint's maskfilter (or NULL)

*/

//主要用来控制paint的alpha通道

SkMaskFilter*getMaskFilter()const{returnfMaskFilter; }

/** Set or clear the maskfilter object.

Pass NULL to clear any previous maskfilter.

As a convenience, the parameter passed is also returned.

If a previous maskfilter exists, its reference count is decremented.

If maskfilter is not NULL, its reference count is incremented.

@param maskfilterMay be NULL. The new maskfilter to be installed in

the paint

@returnmaskfilter

*/

SkMaskFilter*setMaskFilter(SkMaskFilter*maskfilter);

// These attributes are for text/fonts

/** Get the paint's typeface object.

The typeface object identifies which font to use when drawing or

measuring text. The typeface reference count is not affected.

@return the paint's typeface (or NULL)

*/

//获得字体,可以设定字体大小,倾斜,缩放,粗体等等。

SkTypeface*getTypeface()const{returnfTypeface; }

/** Set or clear the typeface object.

Pass NULL to clear any previous typeface.

As a convenience, the parameter passed is also returned.

If a previous typeface exists, its reference count is decremented.

If typeface is not NULL, its reference count is incremented.

@param typeface May be NULL. The new typeface to be installed in the

paint

@returntypeface

*/

SkTypeface*setTypeface(SkTypeface*typeface);

/** Get the paint's rasterizer (or NULL).

The raster controls how paths/text are turned into alpha masks.

@return the paint's rasterizer (or NULL)

*/

//这个光栅不是我们通常意义上的光栅,这里只是为了获得alpha masks的一个效果类。

SkRasterizer*getRasterizer()const{returnfRasterizer; }

/** Set or clear the rasterizer object.

Pass NULL to clear any previous rasterizer.

As a convenience, the parameter passed is also returned.

If a previous rasterizer exists in the paint, its reference count is

decremented. If rasterizer is not NULL, its reference count is

incremented.

@param rasterizer May be NULL. The new rasterizer to be installed in

the paint.

@returnrasterizer

*/

SkRasterizer*setRasterizer(SkRasterizer*rasterizer);

//这里可以作为一种线环的显示效果

SkDrawLooper*getLooper()const{returnfLooper; }

SkDrawLooper*setLooper(SkDrawLooper*);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值