Skip to content

feat(apple): add WebGPU renderer - #41

Draft
tinyjin wants to merge 5 commits into
LottieFiles:mainfrom
tinyjin:jinny/wgpu-support
Draft

feat(apple): add WebGPU renderer#41
tinyjin wants to merge 5 commits into
LottieFiles:mainfrom
tinyjin:jinny/wgpu-support

Conversation

@tinyjin

@tinyjin tinyjin commented Aug 12, 2026

Copy link
Copy Markdown
Member

Overview

  • Enabled ThorVG's WebGPU (Metal) backend on iOS and macOS.
  • Introduced DotLottieFlutterRenderer (swift), the apple method-channel handler, is renderer-agnostic.
  • Introduced DotLottieViewController.renderer() to query current activated renderer.
  • Revised README.md with GPU rendering guidance & new APIs
  • Enhanced default example with CPU vs GPU test program

Metal/WebGPU Support

CPU (exsiting) WebGPU (new)
CleanShot 2026-08-13 at 05 16 23 CleanShot 2026-08-13 at 05 16 48

usage

DotLottieViewController? _controller;

DotLottieView(
  sourceType: 'asset',
  source: 'animation.lottie',
  autoplay: true,
  useWebGPU: true,                                    // iOS/macOS
  onViewCreated: (controller) => _controller = controller,
  onLoad: () async {
    final renderer = await _controller?.renderer();   // 'sw' | 'gl' | 'wg'
    debugPrint('renderer: $renderer');
  },
)

Note

The existing GPU option flag for android is useOpenGL, so the webgpu option parameter is also set to be useWebGPU. We may want to revise renderer option into a single, such as String rendrer = 'sw | gl | wg'. For now leaving as-is for consistency.

Example Enhancement

Monitor per-platform GPU rendering vs CPU (default). This example is built similar to dotlottie-ios' test example.

Android(OpenGL) Apple(WebGPU)
image simulator_screenshot_3E219D52-B30B-4140-BC19-F3ED430B4D14

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 35c5627

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

DotLottieView.useWebGPU opts into ThorVG's WebGPU (Metal) backend
on iOS and macOS, which rasterises straight into a CAMetalLayer instead of
building a CGImage and uploading it through Core Image
on the platform thread every frame. (Off by default)

Intorudce DotLottieFlutterRenderer, the method-channel handler, is renderer-agnostic.
It's implemented once per backend, so adding one does not touch the switch.

usage:
```
DotLottieView(
  sourceType: 'asset',
  source: 'animation.lottie',
  autoplay: true,
  useWebGPU: true,                // iOS/macOS only
)
```
renderer() answers with "sw", "gl" or "wg".
A fallback remounts the default renderer
to this result as well

usage:
```
DotLottieViewController? _controller;

DotLottieView(
  sourceType: 'asset',
  source: 'animation.lottie',
  onViewCreated: (controller) => _controller = controller,
  onLoad: () async {
    final renderer = await _controller?.renderer();   // 'sw' | 'gl' | 'wg'
    debugPrint('renderer: $renderer');
  },
)
```
GPU rendering option & sample
- android : toggle OpenGL
- iOS/macos : toggle WebGPU
- others: hidden

Live stats in test page
- FPS, memory usage (MEM)
cover experimental OpenGL/WebGPU rendering usage
@tinyjin
tinyjin force-pushed the jinny/wgpu-support branch from 35c5627 to 4c53cd1 Compare August 17, 2026 19:14
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.

1 participant