SkiaSharp Windows Forms 视图指南:深入解析 SKControl 与 SKGLControl 的 API 设计与实战用法
SkiaSharp Windows Forms 视图指南:深入解析 SKControl 与 SKGLControl 的 API 设计与实战用法
SkiaSharp 是基于 Google Skia 图形库的跨平台 2D 图形 API,而 SkiaSharp.Views.WindowsForms 程序集则是它在 Windows Forms 桌面应用中的官方视图适配层。本文围绕该程序集在 1.68.1 版本 API diff 中新增的两个核心类型——CPU 软件渲染的 SKControl 与 GPU 硬件加速的 SKGLControl——展开讲解,结合仓库源码剖析其构造、事件、属性与方法,并给出可直接复制的完整绘制代码。读完本文,你将掌握如何在 WinForms 项目里引用并配置这两个控件、通过 PaintSurface/OnPaintSurface 两种方式绘制 SkiaSharp 内容、理解 CanvasSize 与 GRContext 的含义,以及 CPU 与 GPU 渲染路径的底层差异。
一、关联文档与版本背景
本文对应仓库中的 API 差异文档 SkiaSharp.Views.WindowsForms.md,该文档记录了 1.68.1 版本中 SkiaSharp.Views.WindowsForms.dll 的程序集版本由 0.0.0.0 变更为 1.68.0.0,并首次引入命名空间 SkiaSharp.Views.Desktop,其中包含两个新公开类型:
SkiaSharp.Views.Desktop.SKControl—— 基于System.Windows.Forms.Control的软件渲染控件;SkiaSharp.Views.Desktop.SKGLControl—— 基于 OpenTKGLControl的 OpenGL 硬件加速控件。
这两个类型的实际实现位于仓库 SKControl.cs 与 SKGLControl.cs,它们共同构成 WinForms 平台上 SkiaSharp 的两种渲染后端。程序集的项目配置(目标框架、OpenTK 依赖、命名空间等)可参见 SkiaSharp.Views.WindowsForms.csproj。
二、程序集与命名空间概览
2.1 程序集基本信息
SkiaSharp.Views.WindowsForms 程序集的根命名空间为 SkiaSharp.Views.Desktop,这一点在 csproj 的 <RootNamespace> 中直接声明。该程序集同时面向 .NET Framework(net4x)与现代 .NET 桌面框架(netX-windows),并设置 <UseWindowsForms>true</UseWindowsForms>,因此只有 Windows 平台可用。
<RootNamespace>SkiaSharp.Views.Desktop</RootNamespace>
<AssemblyName>SkiaSharp.Views.WindowsForms</AssemblyName>
<UseWindowsForms>true</UseWindowsForms>
2.2 OpenTK 依赖
SKGLControl 继承自 OpenTK 的 GLControl,因此程序集对 OpenTK 有硬性依赖,并且根据目标框架选择不同版本:
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<PackageReference Include="OpenTK" Version="3.1.0" NoWarn="NU1701" />
<PackageReference Include="OpenTK.GLControl" Version="3.1.0" NoWarn="NU1701" />
</ItemGroup>
<ItemGroup Condition="!$(TargetFramework.StartsWith('net4'))">
<PackageReference Include="OpenTK" Version="4.8.2" />
<PackageReference Include="OpenTK.GLControl" Version="4.0.1" />
</ItemGroup>
即 .NET Framework 目标使用 OpenTK 3.1.0,现代 .NET 目标使用 OpenTK 4.x。若你的项目只使用 SKControl(纯 CPU 路径),OpenTK 依赖依然会随程序集引入,但这属于程序集级依赖,不影响 CPU 渲染功能的正常使用。
2.3 类型签名速览
以下是关联文档给出的两个新类型的完整公开 API 签名:
public class SKControl : System.Windows.Forms.Control, System.ComponentModel.IComponent,
System.ComponentModel.ISynchronizeInvoke, System.IDisposable,
System.Windows.Forms.IBindableComponent, System.Windows.Forms.IDropTarget,
System.Windows.Forms.IWin32Window {
public SKControl ();
public SkiaSharp.SKSize CanvasSize { get; }
public event System.EventHandler<SKPaintSurfaceEventArgs> PaintSurface;
protected override void Dispose (bool disposing);
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e);
protected virtual void OnPaintSurface (SKPaintSurfaceEventArgs e);
}
public class SKGLControl : OpenTK.GLControl {
public SKGLControl ();
public SKGLControl (OpenTK.Graphics.GraphicsMode mode);
public SKGLControl (OpenTK.Graphics.GraphicsMode mode, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags);
public SkiaSharp.SKSize CanvasSize { get; }
public SkiaSharp.GRContext GRContext { get; }
public event System.EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
protected override void Dispose (bool disposing);
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e);
protected virtual void OnPaintSurface (SKPaintGLSurfaceEventArgs e);
}
两者都实现了 [DefaultEvent("PaintSurface")] 特性,意味着在 WinForms 设计器中双击控件,默认生成的就是 PaintSurface 事件处理器。
三、SKControl:CPU 软件渲染控件
SKControl 是最简单、最通用的选择:它不依赖 OpenGL,在任何 Windows 环境(包括虚拟机、远程桌面、无 GPU 环境)下都能工作,绘制工作全部由 CPU 完成。
3.1 构造与初始化
源码中的构造函数做了两件关键事情:
public SKControl()
{
DoubleBuffered = true;
SetStyle(ControlStyles.ResizeRedraw, true);
}
DoubleBuffered = true:启用 WinForms 自带的双缓冲,避免绘制时的闪烁;SetStyle(ControlStyles.ResizeRedraw, true):控件尺寸变化时自动触发重绘,保证画布始终与控件大小同步。
3.2 CanvasSize 属性
public SKSize CanvasSize => bitmap == null ? SKSize.Empty : new SKSize(bitmap.Width, bitmap.Height);
CanvasSize 返回当前画布的逻辑尺寸(SKSize)。文档注释特别提醒:画布尺寸可能不同于视图尺寸,因为它受当前设备的像素密度影响。当控件尚未分配位图时,它返回 SKSize.Empty。
3.3 PaintSurface 事件与两种绘制方式
PaintSurface 事件在画布需要重绘时触发,事件参数为 SKPaintSurfaceEventArgs,其核心成员(见 SKPaintSurfaceEventArgs.cs)为:
| 成员 | 类型 | 说明 |
|---|---|---|
Surface |
SKSurface |
当前正在绘制的 SkiaSharp 表面 |
Info |
SKImageInfo |
表面的图像信息(尺寸、颜色类型等) |
RawInfo |
SKImageInfo |
底层表面的原始图像信息 |
该事件参数还提供 Info(供逻辑绘制使用)与 RawInfo(底层真实格式)的区分,在涉及缩放(如高 DPI)场景时尤为有用。
仓库官方注释给出了两种绘制方式:
方式一:订阅 PaintSurface 事件
myView.PaintSurface += (sender, e) =>
{
var surface = e.Surface;
var surfaceWidth = e.Info.Width;
var surfaceHeight = e.Info.Height;
var canvas = surface.Canvas;
// draw on the canvas
canvas.Flush();
};
方式二:重写 OnPaintSurface 虚方法
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
// call the base method
base.OnPaintSurface(e);
var surface = e.Surface;
var surfaceWidth = e.Info.Width;
var surfaceHeight = e.Info.Height;
var canvas = surface.Canvas;
// draw on the canvas
canvas.Flush();
}
重要提醒:如果重写
OnPaintSurface,必须调用基类方法,否则PaintSurface事件将不会被触发。原因见源码 SKControl.cs:基类实现就是负责触发事件的:
protected virtual void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
// invoke the event
PaintSurface?.Invoke(this, e);
}
3.4 内部渲染管线
从源码可以梳理出 SKControl 的完整渲染流程(OnPaint → CreateBitmap → SKSurface.Create → OnPaintSurface → Flush → DrawImage):
- 在
OnPaint中根据控件尺寸构建SKImageInfo:new SKImageInfo(Width, Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul); - 按需创建或复用
Bitmap(使用PixelFormat.Format32bppPArgb,即预乘 Alpha 的 32 位 ARGB 格式); - 通过
bitmap.LockBits锁定像素缓冲区,得到Scan0指针与Stride行跨度; - 调用
SKSurface.Create(info, data.Scan0, data.Stride)直接在托管位图的内存上构建 SkiaSharp 表面,零拷贝地让 Skia 直接写入位图像素; - 触发
OnPaintSurface,执行用户绘制逻辑; surface.Canvas.Flush()确保绘制命令刷入像素缓冲;bitmap.UnlockBits(data)解锁,最后由e.Graphics.DrawImage(bitmap, 0, 0)把位图绘制到控件表面。
这正是 SKControl 被称为“软件渲染控件”的原因——Skia 的 CPU 后端直接把像素画进一张 WinForms Bitmap。
3.5 Dispose 资源释放
SKControl 重写了 Dispose(bool disposing),在释放基类资源后调用 FreeBitmap() 释放内部位图。官方注释强调:应在释放对控件的最后一个引用之前显式调用 Dispose,否则其中的资源要等垃圾回收器执行终结器时才会被释放。
四、SKGLControl:OpenGL 硬件加速控件
SKGLControl 面向对性能有更高要求的场景(游戏、实时动画、大规模图形处理),它把 Skia 的 GPU 后端与 OpenGL(经 OpenTK 封装)绑定,渲染工作由显卡完成。
4.1 三种构造函数
源码在不同平台分支提供了三组构造函数(#if WINDOWS 分支使用 OpenTK 4 的 GLControlSettings,其他平台使用 OpenTK 3 风格的 GraphicsMode):
public SKGLControl()
: base(new GLControlSettings { AlphaBits = 8, RedBits = 8, GreenBits = 8, BlueBits = 8, DepthBits = 24, StencilBits = 8 })
{
Initialize();
}
public SKGLControl(GraphicsMode mode)
: base(mode)
{
Initialize();
}
public SKGLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
: base(mode, major, minor, flags)
{
Initialize();
}
其中:
- 无参构造使用 8 位 RGBA 颜色缓冲、24 位深度缓冲、8 位模板缓冲的默认配置;
mode定义颜色、深度、模板与累积缓冲的格式;major/minor指定要创建的 OpenGL 上下文版本号;flags是GraphicsContextFlags值的按位组合,控制上下文创建行为(如 ForwardCompatible、Debug 等)。
Initialize() 内部设置 ResizeRedraw = true,保证尺寸变化时自动重绘。
4.2 CanvasSize 与 GRContext 属性
public SKSize CanvasSize => lastSize;
public GRContext GRContext => grContext;
CanvasSize:当前画布尺寸(SKSizeI隐式转换为SKSize),同样可能因设备像素密度与视图尺寸不同;GRContext:当前 GPU 上下文(SkiaSharp.GRContext),它封装了 Skia 的 Ganesh GPU 后端。该上下文在首次绘制时惰性创建(见下节),可供需要在控件外创建 GPU 资源(如纹理、图像)的代码复用。
4.3 PaintSurface 事件与 SKPaintGLSurfaceEventArgs
SKGLControl 的绘制事件参数为 SKPaintGLSurfaceEventArgs(定义见 SKPaintGLSurfaceEventArgs.cs),除 Surface 外还提供:
| 成员 | 类型 | 说明 |
|---|---|---|
BackendRenderTarget |
GRBackendRenderTarget |
当前正在绘制的 GPU 后端渲染目标 |
ColorType |
SKColorType |
渲染目标的颜色类型(默认为 Rgba8888) |
Origin |
GRSurfaceOrigin |
渲染目标的表面原点(默认为 BottomLeft) |
Info / RawInfo |
SKImageInfo |
表面图像信息与底层原始信息 |
事件订阅方式:
myView.PaintSurface += (sender, e) =>
{
var surface = e.Surface;
var surfaceWidth = e.BackendRenderTarget.Width;
var surfaceHeight = e.BackendRenderTarget.Height;
var canvas = surface.Canvas;
// draw on the canvas
canvas.Flush();
};
重写方式(同样必须调用基类以保证事件触发):
protected override void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
{
// call the base method
base.OnPaintSurface(e);
var surface = e.Surface;
var surfaceWidth = e.BackendRenderTarget.Width;
var surfaceHeight = e.BackendRenderTarget.Height;
var canvas = surface.Canvas;
// draw on the canvas
canvas.Flush();
}
与 CPU 版本不同,这里获取画布尺寸使用的是 e.BackendRenderTarget.Width/Height 而非 e.Info。
4.4 内部 GPU 渲染管线
SKGLControl 的 OnPaint 是理解其工作原理的关键,完整流程如下(见 SKGLControl.cs):
- 设计模式下仅清空背景色并返回;
- 调用
MakeCurrent()使 OpenTK 上下文成为当前线程的 OpenGL 上下文; - 惰性创建 GPU 上下文:若
grContext == null,通过GRGlInterface.Create()获取 OpenGL 接口,再GRContext.CreateGl(glInterface)创建 Ganesh GPU 上下文; - 管理渲染目标:当渲染目标为空、尺寸变化或失效时,查询 OpenGL 当前帧缓冲(
GL.GetInteger(FramebufferBinding))、模板位数与采样数(GL.GetInteger(StencilBits)、GL.GetInteger(Samples)),并用grContext.GetMaxSurfaceSampleCount(colorType)将采样数限制在硬件支持的最大值内; - 构造
GRGlFramebufferInfo与GRBackendRenderTarget,重用旧的SKSurface销毁重建; - 通过
SKSurface.Create(grContext, renderTarget, surfaceOrigin, colorType)创建 GPU 表面(颜色类型固定为SKColorType.Rgba8888,表面原点为GRSurfaceOrigin.BottomLeft); - 在
SKAutoCanvasRestore作用域内触发OnPaintSurface,保证画布状态自动保存与恢复; canvas.Flush()将绘制命令提交到 GPU,最后SwapBuffers()交换前后缓冲完成一帧显示。
可以看到,SKGLControl 会按需复用 GRContext、GRBackendRenderTarget 与 SKSurface 三个 GPU 资源,尺寸不变时不会重复创建,这是它适合高频动画的重要原因。
4.5 Dispose 资源释放
SKGLControl.Dispose 的清理顺序体现了 GPU 资源的依赖关系(先销毁依赖方、再销毁基础资源):
canvas = null;
surface?.Dispose();
surface = null;
renderTarget?.Dispose();
renderTarget = null;
grContext?.Dispose();
grContext = null;
即依次释放 SKCanvas、SKSurface、GRBackendRenderTarget、GRContext。与 SKControl 一样,官方建议在释放最后一个引用前显式调用 Dispose。
五、实战示例:在 WinForms 中使用两种控件
仓库的 WindowsForms 示例 演示了如何将 SKControl 与 SKGLControl 通过 Visual Studio 设计器拖放集成到窗体中(布局定义在 .Designer.cs 的 InitializeComponent() 中),并展示了 CPU 与 GPU 两种典型用法。
5.1 设计器中的控件放置
在 .Designer.cs 中,控件与事件绑定的典型写法如下(摘自 CpuPage.Designer.cs):
this.skiaView = new SkiaSharp.Views.Desktop.SKControl();
this.skiaView.Dock = System.Windows.Forms.DockStyle.Fill;
this.skiaView.Location = new System.Drawing.Point(0, 0);
this.skiaView.Name = "skiaView";
this.skiaView.Size = new System.Drawing.Size(800, 600);
this.skiaView.PaintSurface += new System.EventHandler<SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs>(this.OnPaintSurface);
GPU 版本(摘自 GpuPage.Designer.cs):
this.glControl = new SkiaSharp.Views.Desktop.SKGLControl();
this.glControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.glControl.Size = new System.Drawing.Size(800, 600);
this.glControl.PaintSurface += new System.EventHandler<SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs>(this.OnPaintSurface);
this.glControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
this.glControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.glControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);
在 Visual Studio 中,你也可以直接从工具箱拖拽这两个控件到窗体上,再在设计器中绑定事件。
5.2 CPU 示例:绘制渐变背景与圆形
下面的处理器来自 CpuPage.cs,展示了 SKControl 事件处理器中从 e.Surface.Canvas 与 e.Info 取画布和尺寸的标准用法:
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
var width = e.Info.Width;
var height = e.Info.Height;
var center = new SKPoint(width / 2f, height / 2f);
var radius = Math.Max(width, height) / 2f;
canvas.Clear(SKColors.White);
// Background gradient
using var shader = SKShader.CreateRadialGradient(center, radius, gradientColors, SKShaderTileMode.Clamp);
using var bgPaint = new SKPaint
{
IsAntialias = true,
Shader = shader,
};
canvas.DrawRect(0, 0, width, height, bgPaint);
// Semi-transparent circles
using var circlePaint = new SKPaint
{
IsAntialias = true,
Style = SKPaintStyle.Fill,
};
foreach (var (x, y, r, color) in circles)
{
circlePaint.Color = color;
canvas.DrawCircle(x * width, y * height, r * Math.Min(width, height), circlePaint);
}
// Centered text
using var textPaint = new SKPaint
{
Color = SKColors.White,
IsAntialias = true,
};
using var font = new SKFont { Size = width * 0.12f };
canvas.DrawText("SkiaSharp", center.X, center.Y + font.Size / 3f, SKTextAlign.Center, font, textPaint);
}
其中 gradientColors 为双色数组(#4488FF → #8833CC),六个圆形使用带 Alpha 的半透明颜色叠加在渐变之上,形成柔和的光影层次。
5.3 GPU 示例:实时 SkSL 着色器动画
GPU 页面演示了 SKGLControl 的典型高性能场景:以 Timer 驱动 Invalidate() 形成持续渲染循环,每一帧通过 SKRuntimeEffect 编译的 SkSL 着色器绘制(见 GpuPage.cs):
private void OnAnimationTick(object sender, EventArgs e)
{
glControl.Invalidate();
}
private void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
var width = e.BackendRenderTarget.Width;
var height = e.BackendRenderTarget.Height;
var builder = shaderBuilder!.Value;
builder.Uniforms["iTime"] = fpsCounter.ElapsedSeconds;
builder.Uniforms["iResolution"] = new float[] { (float)width, (float)height };
builder.Uniforms["iTouchPos"] = new float[] { touchPos.X, touchPos.Y };
builder.Uniforms["iTouchActive"] = touchActive ? 1f : 0f;
builder.Uniforms["iColors"] = blobColors;
using var shader = builder.Build();
using var paint = new SKPaint { Shader = shader };
canvas.DrawRect(0, 0, width, height, paint);
}
注意这里尺寸取的是 e.BackendRenderTarget.Width/Height,与 CPU 版本的 e.Info 形成对比。示例还通过 MouseDown/MouseMove/MouseUp 把鼠标归一化坐标写入着色器 uniform,实现交互式 metaball 动画。动画循环的关键在于:Timer 以约 16ms(约 60FPS)间隔触发 glControl.Invalidate(),从而不断驱动 OnPaint → GPU 渲染 → SwapBuffers 的完整管线。
5.4 一个最小可运行的完整示例
综合以上,一个最小可用的窗体代码如下:
using System;
using System.Windows.Forms;
using SkiaSharp;
using SkiaSharp.Views.Desktop;
public sealed class SkiaForm : Form
{
public SkiaForm()
{
var cpuView = new SKControl { Dock = DockStyle.Fill };
cpuView.PaintSurface += OnCpuPaint;
Controls.Add(cpuView);
}
private void OnCpuPaint(object sender, SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
canvas.Clear(SKColors.White);
using var paint = new SKPaint
{
Color = SKColors.CornflowerBlue,
IsAntialias = true,
};
canvas.DrawCircle(e.Info.Width / 2f, e.Info.Height / 2f, 100f, paint);
}
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.Run(new SkiaForm());
}
}
将 SKControl 换成 SKGLControl 并改用 SKPaintGLSurfaceEventArgs(e.BackendRenderTarget.Width/Height)即可切换到 GPU 渲染。
六、SKControl 与 SKGLControl 的选择建议
| 维度 | SKControl | SKGLControl |
|---|---|---|
| 渲染后端 | Skia CPU 软件渲染 | Skia GPU 后端 + OpenGL(OpenTK) |
| 事件参数 | SKPaintSurfaceEventArgs(e.Info 取尺寸) |
SKPaintGLSurfaceEventArgs(e.BackendRenderTarget 取尺寸) |
| 依赖 | 仅 .NET + SkiaSharp | OpenTK 3/4 包 |
| 适用场景 | 静态画面、低复杂度绘制、无 GPU 环境 | 实时动画、高频重绘、大型场景 |
| 构造灵活性 | 单一无参构造 | 无参 / GraphicsMode / 版本+Flags 三种构造 |
| 资源管理 | 内部 Bitmap + SKSurface | GRContext + GRBackendRenderTarget + SKSurface |
选择建议(基于源码结构可以推断的结论):如果绘制内容相对静态、复杂度不高,或者应用需要运行在远程桌面/虚拟机等可能没有可用 OpenGL 环境的地方,SKControl 更稳妥;如果需要全帧率实时渲染(如示例中的 SkSL 着色器动画),SKGLControl 配合 OpenTK 是更合适的选择。值得注意的是,SKControl 内部渲染时也会创建 SKSurface 并执行 Flush,因此两种控件在“事件驱动的绘制模型”上是完全一致的,切换成本很低。
七、扩展:类型互转扩展方法
SkiaSharp.Views.WindowsForms 程序集还随附了 Extensions 静态类(见 Extensions.Desktop.cs),提供 System.Drawing 与 SkiaSharp 类型之间的双向转换,便于在 WinForms 的既有绘图代码与 SkiaSharp 之间迁移:
- 点:
PointF.ToSKPoint()/Point.ToSKPoint()与SKPoint.ToDrawingPoint()/SKPointI.ToDrawingPoint(); - 矩形:
RectangleF.ToSKRect()/Rectangle.ToSKRect()与SKRect.ToDrawingRect()/SKRectI.ToDrawingRect(); - 尺寸:
SizeF.ToSKSize()/Size.ToSKSize()与SKSize.ToDrawingSize()/SKSizeI.ToDrawingSize(); - 位图:
SKBitmap.ToBitmap()、SKImage.ToBitmap()、SKPixmap.ToBitmap()、SKPicture.ToBitmap(SKSizeI)以及反向的Bitmap.ToSKBitmap()、Bitmap.ToSKImage()、Bitmap.ToSKPixmap(); - 颜色:
Color.ToSKColor()与SKColor.ToDrawingColor()。
这些方法内部通过 SKPixmap/SKImage 完成像素级拷贝(如 SKImage.ToBitmap 先构造 Format32bppPArgb 位图,再以 SKPixmap 包住 Scan0/Stride 调用 ReadPixels),与 SKControl 的渲染管线一脉相承。
八、小结
SkiaSharp.Views.WindowsForms 在 1.68.1 引入的 SKControl 与 SKGLControl 补齐了 SkiaSharp 在 Windows Forms 平台上的官方视图层:
SKControl以Bitmap+SKSurface.Create实现零拷贝的 CPU 软件渲染,接口简单、环境兼容性好;SKGLControl以GRContext+GRBackendRenderTarget+ OpenGL 实现 GPU 加速渲染,适合高性能实时场景;- 两者共享同一套“事件驱动绘制”模型:通过订阅
PaintSurface或重写OnPaintSurface(必须调用基类)绘制,绘制结束后canvas.Flush()提交结果。
官方示例 WindowsForms 提供了 CPU(渐变+圆形)、GPU(SkSL 着色器动画)与自由绘画(路径+鼠标交互)三类完整参考实现,可进一步查阅验证本文所述 API 的实际用法。