Repository navigation
Add native Apple Graphite views to SkiaSharp.Views - #4745
mattleibow wants to merge 6 commits into
Conversation
📦 Try the packages from this PRWarning Do not run these scripts without first reviewing the code in this PR. Step 1 — Download the packages bash / macOS / Linux: curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 4745PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 4745"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-4745/packages --name skiasharp-pr-4745More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-4745 |
|
Parallel dependency track: Graphite presentation/multi-recorder interop remains in #4729 and mono/skia#345. This Apple-native PR intentionally has no dependency on either. After both foundations land, Apple MAUI and Android native work will proceed independently. |
|
📖 Documentation Preview The documentation for this PR has been deployed and is available at: 🔗 View Staging Site This preview will be updated automatically when you push new commits to this PR. This comment is automatically updated by the documentation staging workflow. |
📊 SkiaSharp benchmarks — PR #4745No ⭐ source-build ( |
📦 Artifact size reportPackages from this PR (build Total Packages
+39 package(s) unchanged (< 50.0 KB). Per-file changes
|
| File | Size |
|---|---|
runtimes/win-arm64/native/libGLESv2.pdb |
64.5 MB → 64.4 MB (🟢 −96.0 KB) |
runtimes/win-x64/native/libGLESv2.pdb |
66.6 MB → 66.6 MB (🟢 −80.0 KB) |
runtimes/win-x86/native/libGLESv2.pdb |
67.3 MB → 67.2 MB (🟢 −80.0 KB) |
Informational only — this never blocks the PR. Native binaries are labelled by os/arch.
7afc5b3 to
512f530
Compare
Introduce the Apple-only SkiaSharp.Views.Graphite package with Metal-backed iOS, Mac Catalyst, macOS, and tvOS controls and native Basic sample pages. Keep the layer independent from the pending Graphite presentation interop, Android, MAUI, and mono/skia changes. Co-authored-by: Copilot App <[email protected]>
Ship the Apple Graphite control in the existing platform view assemblies instead of creating a separate package. Make initialization transactional, contain unhandled render failures inside MetalKit callbacks, and use the bound Metal capability API. Co-authored-by: Copilot App <[email protected]>
Make the Apple Graphite sample pipeline independent visual roots through worker-owned Recorders while the view presents the last completed update. Add event-args helpers that create correctly cached Recorders and insert recordings through the view's context bookkeeping. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 705e7540-cc61-4a7d-b4ae-2c93138c031b
512f530 to
791aa94
Compare
Let the event args call the Context directly and report unrecoverable insertion state back to the view after painting, avoiding a per-frame delegate while preserving safe disposal behavior. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 705e7540-cc61-4a7d-b4ae-2c93138c031b
Preserve Apple's long-lived Metal queue while rebuilding Graphite state after fatal insertion or submission failures. Discard an abandoned presentation Recorder before retrying, notify before recreation, and let the samples dispose worker state before an explicit retry. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 705e7540-cc61-4a7d-b4ae-2c93138c031b
Follow Apple Metal guidance for drawable release, application suspension, command-buffer error reporting, and long-lived device/queue ownership. Follow Skia recovery semantics for partial recording insertion, abandoned presentation work, and Graphite Context recreation. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 705e7540-cc61-4a7d-b4ae-2c93138c031b
|
Superseded for iOS/Mac Catalyst by #5329, which adds engine-named native SKGraphiteView/SKGaneshView containers plus MAUI controls, typed contexts, tracked producer recordings, lifecycle/readback coverage, and Android presentation. Its prerequisite interop remains separately reviewable in #4729 and mono/skia#345. The replacement is intentionally draft pending Windows/producing-build acceptance and the independently reproduced main GL golden blocker. Its iOS/Mac Catalyst device suites pass with real pixels and zero skips. This closure does not discard the unported macOS/tvOS native implementation in this PR. The source and branch |
Description
Adds
SKGraphiteMetalViewto the existingSkiaSharp.Viewspackage as an Apple-native alternative toSKMetalView, plus native Basic sample tabs for iOS, Mac Catalyst, macOS, and tvOS.The view uses Graphite APIs already available on
main: it wraps the current Metal drawable, creates a Graphite surface, inserts recordings, submits, and presents through one Metal queue.SKPaintGraphiteSurfaceEventArgs.CreateRecorder(...)andInsertRecording(...)expose Graphite's multi-recorder model without new native interop.The sample demonstrates that model rather than benchmarking it. Four worker threads exclusively own independent Recorders and offscreen surfaces. They prepare content update N+1 while the view/context thread composes and presents the last complete update N. Producer Recordings are inserted before the presentation Recording.
flowchart LR W1[Worker Recorder 1] --> R1[Recording 1] W2[Worker Recorder 2] --> R2[Recording 2] W3[Worker Recorder 3] --> R3[Recording 3] W4[Worker Recorder 4] --> R4[Recording 4] R1 --> C[View / Context thread] R2 --> C R3 --> C R4 --> C C --> P[Compose latest images] P --> S[Snap, insert, submit] S --> M[One ordered Metal queue]This parallelizes CPU command preparation, analogous to Metal parallel command encoding; it does not claim multiple Metal queues or unordered GPU execution. The view owns drawable presentation while applications choose how to partition independent visual roots.
Recovery follows Apple and Skia guidance:
MTLDeviceandMTLCommandQueueas long-lived, thread-safe objects. A failed command buffer is terminal to that buffer, not automatically to its queue/device. Nil drawables are skipped. See MTLCommandQueue, MTLCommandBuffer status, completion handlers, and MTKView currentDrawable.InvalidRecordingandPromiseInstantiationFailedas making no command-buffer changes.AddCommandsFailedandAsyncShaderCompilesFailedleave Graphite state unrecoverable/unknown; submission failure is conservatively treated the same.OutOfOrderRecordingremains visible so callers can repair known ordering mistakes.CAMetalDrawablecannot leak into a later frame. If external Recordings were already inserted, the Context is also recreated because pending work cannot be rolled back.preferredDeviceon macOS when available.notPermittederrors are not surfaced as renderer failures.This PR remains independent of #4729 and mono/skia#345. It adds no Android or MAUI implementation, native Skia change, C API, generated binding, or deferred-canvas API.
Related issues
Related to #4734 and informed by #4885. API documentation is tracked by mono/SkiaSharp-API-docs#214.
Required skia PR
None. This PR uses Graphite APIs already present on
main.Areas affected
binding/)externals/skia/src/c,include/c)Changes
Public API
Added to
SkiaSharp.Views.iOSfor iOS/Mac Catalyst,SkiaSharp.Views.Macfor macOS, andSkiaSharp.Views.tvOSfor tvOS:Behavior
Testing
origin/mainf74bd9adb82a77fd4a423db03c1077ea9d3be7e7; validated with .NET SDK 10.0.400.SkiaSharp.Viewsbuilt for all eight net9/net10 Apple TFMs.SkiaSharp.Viewspack passed; new APIs are present in all eight Apple assemblies and absent from Android assemblies.api-tools api-infopassed for all eight Apple assemblies, including both failure constructors andRequiresContextRecreation.iossimulator-arm64,maccatalyst-arm64,osx-arm64, andtvossimulator-arm64.ValidateXcodeVersion=falsewas needed because the pinned workload requests Xcode 26.0 while the host has Xcode 26.6.samples-generatepassed and retained the sharedGraphiteSceneRendererlink in all four generated Apple projects.Blacklistedvalue.ganesh-gl/DiagonalLinesmacOS golden mismatch (1,832 pixels versus 1,310 allowed), unchanged from the main baseline.git diff --checkpassed. The final diff contains no Android, MAUI,externals/skia, generated binding, standalone package, or Add Graphite presentation interop #4729-only content.iOS simulator: pipelined Graphite Recorders
Checklist
Changesabove lists all public API and behavioral changes (or "None.")mono/skiaPR, or binding regeneration is required