GraphicsContext的接口定义

GraphicsContext的接口定义
GraphicsContext 定义了绘图操作环境。
A。基本功能是绘图操作:
   1. 简单几何图形:drawRect,drawLine,drawEllipse,drawConvexPolygon
                                         ,strokeArc,fillRect,fillRoundedRect,strokeRect,clearRect。
   2. 路径:drawPath,fillPath,strokePath。
   3. 图像:drawImage,drawTiledImage,drawImageBuffer。
   4. 文本:drawText,drawBidiText,drawHighlightForText,drawLineForText。
B。路径操作:
C。剪切操作:
D。绘图参数状态配置:
   1. 线条:strokeThickness,strokeStyle,strokeColor,strokeColorSpace,strokePattern,strokeGradient;
   2. 填充:fillRule,fillColor,fillColorSpace,fillPattern,fillGradient;
   3. 品质:shouldAntialias,imageInterpolationQuality,textDrawingMode;
   4. 状态:paintingDisabled;
E。绘图参数状态堆栈操作:

我们可以看出,绘图操作的大部分属性参数都是通过GraphicsContext的状态传递的。
那么,从性能的角度考虑,这样做好么,还是直接通过函数参数传递更好呢?

通过参数传递会带来一次参数出入堆栈操作;
通过GraphicsContext的状态传递,则会在每次参数变更时,进行一次参数出入堆栈操作和保存参数到状态的操作。
因此,当大多数绘图操作共用相同参数时,GraphicsContext的状态传递更加高效。

当然,还要考虑到GraphicsContext的状态栈操作会在每次场景切换是带来的额外开销。

你可能感兴趣的:(GraphicsContext的接口定义)