Skip to content

Batch canvas drawPath calls when possible #33849

@cmkweber

Description

@cmkweber

When performing many calls to drawPath, the performance suffers. This is especially evident on lower end devices. The attached example demonstrates:

  1. Looping through paths and drawing using Canvas.drawPath
  2. Looping through paths and drawing using Canvas.drawVertices
  3. One batched draw using Canvas.drawVertices

It should be noted this demonstration creates almost the maximum amount of paths that could be drawn with one batch call (max vertex index 65,535). One could expand this demonstration to perform numerous drawVertices calls when the vertex index overflows.

Another thing to keep in mind is a facility to draw many paths in one call should allow the user to provide n paints so each path can still be drawn with its own style - this may require creating a texture atlas that drawVertices can reference.

Finally, this optimization may only benefit an immutable collection of paths. For dynamically changing paths, the allocation and upload to the GPU of large vertex data each frame may become non-performant, but this could be verified through tests.

main.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)dependency: skiaSkia team may need to help usengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions