Skip to content

Conversation

@YGaurora
Copy link
Collaborator

@YGaurora YGaurora commented Jan 7, 2026

本 PR 为 Hairline(极细线,宽度 ≤ 1 像素的描边)实现了 GPU 光栅化渲染路径,主要包含以下内容:

核心功能

  • 新增 ShapeBezierTriangulator 类,将 Path 分解为直线段和二次贝塞尔曲线,并生成带 AA 覆盖率的三角形顶点数据
  • 新增 HairlineLineDrawOp 和 HairlineQuadDrawOp 两个绘制操作,分别处理直线和曲线的 GPU 渲染
  • 新增 HairlineLineGeometryProcessor 和 HairlineQuadGeometryProcessor 几何处理器
  • 实现了 Hairline 缓冲区的缓存复用机制(GPUHairlineProxy)

基础工具扩展

  • Point 类新增 normalize()、DotProduct()、CrossProduct() 方法
  • PathUtils 新增 ConvertCubicToQuads() 函数,将三次贝塞尔曲线转换为二次贝塞尔曲线

测试覆盖

  • 新增多个测试用例验证 Hairline 渲染效果、Canvas 变换、裁剪、缓存复用、Shader 程序缓存等场景

技术方案

直线段渲染为 6 顶点的菱形区域(带 AA 边缘),二次曲线渲染为 5 顶点的多边形区域,通过 GPU Shader
计算覆盖率实现抗锯齿效果。缓冲区按 Shape 的 UniqueKey 缓存,支持异步生成。

下图是一个基础的渲染,分别是 Hairline、stroke width = 0.5;和是否开启抗锯齿
HairlineBasicRendering_base

@YGaurora YGaurora changed the title Implement GPU-accelerated rasterization for hairline rendering. Add GPU accelerated hairline rendering for stroke paths. Jan 7, 2026
/**
* Returns the dot product of a and b.
*/
static float DotProduct(const Point& a, const Point& b) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些接口是Skia里有的吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都有一样的,在include/private/base/SkPoint_impl.h
只是有cross(SkVector),dot(SkVector)是成员函数,没有同步实现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants