Repository navigation
Add a modern shared pixel-comparison API for tests - #5293
Conversation
|
📖 Documentation Preview Add the Removing the label removes the preview. While the label is present, each new commit updates it. This comment is automatically updated by the documentation staging workflow. |
📦 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 -- 5293PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 5293"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-5293/packages --name skiasharp-pr-5293More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-5293 |
📊 SkiaSharp benchmarks — PR #5293⭐ this PR (full source build) vs 🌙 nightly · Linux · Windows · macOS
Highlights⏱️ Time — 🔴 20 slower · 🟢 70 faster
Full per-OS benchmark deltasLinux⏱️ Time (vs 🌙 nightly
Windows⏱️ Time (vs 🌙 nightly
macOS⏱️ Time (vs 🌙 nightly
|
de4ce13 to
9824725
Compare
There was a problem hiding this comment.
🟡 Changes recommended
CI runner registration and reusable generated-mask dimensions need correction before approval.
2 open findings
What changed in this PR
Introduces experimental SkiaSharp.Testing as the shared image-comparison package for rendering tests, replacing copied and Extended comparers.
Changes:
- Adds channel tolerances, mismatch budgets, error metrics, masks, and diagnostic images.
- Migrates test consumers and integrates package versioning, signing, and solutions.
- Adds focused regression tests and illustrated testing guides.
| File | Description |
|---|---|
| tests/Tests/Utils/SKPixelComparer.cs | Removes the copied comparer. |
| tests/Tests/SkiaSharp/Visual/Tests/VisualMatrixTestsBase.cs | Migrates golden-image comparisons. |
| tests/Tests/SkiaSharp/SKTest.cs | Migrates bitmap assertions. |
| tests/SkiaSharp.Tests/SkiaSharp.Tests.csproj | References the testing library. |
| tests/SkiaSharp.Tests.Samples/Utils/SampleImage.cs | Migrates sample comparisons and diagnostics. |
| tests/SkiaSharp.Tests.Samples/SkiaSharp.Tests.Samples.csproj | Replaces linked comparer source. |
| tests/SkiaSharp.Tests.Samples/SampleInfrastructureTests.cs | Tests error-gate boundaries. |
| tests/SkiaSharp.Tests.Integration/Tests/PlatformTestBase.cs | Migrates integration comparisons. |
| tests/SkiaSharp.Tests.Integration/SkiaSharp.Tests.Integration.csproj | Uses the matching testing package. |
| tests/SkiaSharp.Tests.Console/SkiaSharp.Tests.Console.csproj | References the testing library. |
| tests/SkiaSharp.Tests.Console.slnx | Includes library and regression tests. |
| tests/SkiaSharp.Testing.Tests/SKPixelValidationTest.cs | Tests validation and experimental metadata. |
| tests/SkiaSharp.Testing.Tests/SKPixelToleranceTest.cs | Tests channel and mask tolerances. |
| tests/SkiaSharp.Testing.Tests/SKPixelNormalizationTest.cs | Tests normalization across input types. |
| tests/SkiaSharp.Testing.Tests/SKPixelIgnoreCoverageTest.cs | Tests ignored coverage semantics. |
| tests/SkiaSharp.Testing.Tests/SKPixelDifferenceImageTest.cs | Tests diagnostic pixels and ownership. |
| tests/SkiaSharp.Testing.Tests/SKPixelComparisonMetricsTest.cs | Tests statistics and overflow boundaries. |
| tests/SkiaSharp.Testing.Tests/SKPixelComparisonAcceptanceTest.cs | Tests budgets and combined gates. |
| tests/SkiaSharp.Testing.Tests/SKPixelComparerTestBase.cs | Adds shared test helpers. |
| tests/SkiaSharp.Testing.Tests/SkiaSharp.Testing.Tests.csproj | Defines the regression test host. |
| source/SkiaSharpSource.Windows.slnf | Includes the library on Windows. |
| source/SkiaSharpSource.slnx | Registers the library project. |
| source/SkiaSharpSource.Mac.slnf | Includes the library on macOS. |
| source/SkiaSharpSource.Linux.slnf | Includes the library on Linux. |
| source/SkiaSharp.Testing/SKPixelTolerance.cs | Defines channel allowances. |
| source/SkiaSharp.Testing/SKPixelMismatchBudget.cs | Defines count and percentage budgets. |
| source/SkiaSharp.Testing/SKPixelDifferenceStyle.cs | Defines diagnostic styles. |
| source/SkiaSharp.Testing/SKPixelComparisonResult.cs | Exposes immutable comparison outcomes. |
| source/SkiaSharp.Testing/SKPixelComparisonMetrics.cs | Computes error statistics. |
| source/SkiaSharp.Testing/SKPixelComparerOptions.cs | Defines comparison configuration. |
| source/SkiaSharp.Testing/SKPixelComparer.cs | Implements comparisons and diagnostics. |
| source/SkiaSharp.Testing/SkiaSharp.Testing.csproj | Defines the shipping package. |
| source/SkiaSharp.Testing/Properties/AssemblyInfo.cs | Marks the API experimental. |
| source/SkiaSharp.Testing/Compatibility/ExperimentalAttribute.cs | Supports older target frameworks. |
| scripts/VERSIONS.txt | Registers package versioning. |
| scripts/infra/shared/shared.cake | Registers package support. |
| eng/Signing.props | Registers assembly signing. |
| documentation/docfx/guides/TOC.yml | Adds testing navigation. |
| documentation/docfx/guides/testing/index.md | Introduces rendering-test guidance. |
| documentation/docfx/guides/testing/image-comparison.md | Explains comparison features and examples. |
| documentation/docfx/guides/testing/generate-images.cs | Generates illustrated comparison assets. |
| documentation/dev/README.md | Links experimental API guidance. |
| documentation/dev/golden-image-tests.md | Documents the migrated comparer. |
| documentation/dev/experimental-apis.md | Defines experimental policy and registry. |
| documentation/dev/api-design.md | Links experimental API policy. |
🧠 Review effort: Balanced
440d7c3 to
99ac8cc
Compare
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
The experimental comparison API preserves existing consumer acceptance policies, and the earlier raw-image and test-runner integration findings are fixed.
Reviewed source/static integration only. The Windows source-benchmark check still reports missing matching Spectre libraries; the existing job-level non-blocking policy is unchanged, and no pre-existing/transient or safe-to-retry classification is claimed.
4619c9b to
43ef01b
Compare
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all 77 changed files, the committed diagnostic images, existing consumers and the static build/package/test integration, including a separate final blocker search.
One blocking project-evaluation issue remains: tests/SkiaSharp.Tests.Samples/SkiaSharp.Tests.Samples.csproj:51 unconditionally imports tests/TestUtilities/PixelComparison/PixelComparison.projitems, but both that exact file and its directory are absent at this head. MSBuild therefore fails with MSB4019 before restore/build/test of the sample host. The current sample helper already uses SkiaSharp.Tests.Shared; remove the stale import rather than restoring the removed comparer.
This is a deterministic static import-resolution finding, not an executed build or runtime reproduction. The experimental API and previously accepted comparison policies are not being re-blocked.
Fixed in |
dalexsoto
left a comment
There was a problem hiding this comment.
The prior missing-import blocker is fixed: the complete current Samples project no longer imports the deleted PixelComparison.projitems, and its Shared-to-Testing reference chain remains intact. This is a static source verification, not an executed MSBuild evaluation.
Reviewed all 76 changed paths, the committed diagnostic images, existing consumers and static API/build/package/test/documentation integration, including a separate final blocker search. The experimental pixel-comparison API, diagnostics and build/package/test consumers preserve the accepted comparison and ownership policies. The experimental API and previously accepted comparison and ownership policies are not being re-blocked. No independent high-confidence blocker remains in this bounded static review; no executed runtime or whole-pipeline certification is claimed.
75883d8 to
e9f7883
Compare
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all 76 changed paths, the committed diagnostic images, existing consumers and static API/build/package/test/documentation integration, including a separate final blocker search. The experimental pixel-comparison API, diagnostics and build/package/test consumers preserve the accepted comparison and ownership policies. The experimental API and previously accepted comparison and ownership policies are not being re-blocked. No independent high-confidence blocker remains in this bounded static review; no executed runtime or whole-pipeline certification is claimed.
e9f7883 to
b85536a
Compare
|
In response to @mattleibow's request: I am deferring a formal review of rebased head |
b85536a to
b1f35c7
Compare
Port the current Extended comparison logic into an unpublished shared-source test utility so core, golden-image, and exact-package integration tests no longer maintain different comparers or depend on Extended. Preserve existing premultiplied comparison gates and transparent-pixel normalization, add wide error metrics and explicit diagnostic styles, and document small future API improvements. Keep native sources, goldens, tolerances, and skip policy unchanged. Co-authored-by: Copilot App <[email protected]>
Replace the 808-line developer report with a short public DocFX guide and one compact experimental registry. Remove competitor/roadmap/migration analysis and duplicate policy/API listings. Restore existing package and publishing test scripts rather than adding configuration-validation harnesses. Keep real comparison and consumer regressions plus required normal production wiring. Remove historical-name and documentation-URL proxy assertions, simplify the golden-test note, and use repository-standard source license headers without repeated Extended provenance. Co-authored-by: Copilot App <[email protected]>
Separate Testing from the drawing tutorials with its own overview and navigation. Move image comparison there, add input/diagnostic/ignore-coverage illustrations, and update documentation and diagnostic links. Keep screenshots, baselines and assertions scoped to their owning test layer; do not add speculative feature pages or migrate unrelated Extended APIs. Co-authored-by: Copilot App <[email protected]>
Keep Testing as a dedicated subsection with its overview, comparison guide and illustrations while removing the top-level navigation tab. Update feature and diagnostic documentation links. Co-authored-by: Copilot App <[email protected]>
Remove decode/encode exception boilerplate from the conceptual sample. Co-authored-by: Copilot App <[email protected]>
Label exact source RGB values, show equivalent regional tolerance and ignore masks with their different metric coverage, and illustrate alpha-only changes that raw RGB diagnostics cannot show. Keep visuals explicitly illustrative and avoid adding generation or validation scripts. Co-authored-by: Copilot App <[email protected]>
Order the conceptual guide as introduction, installation/opt-in, then the illustrated comparison. Update the diagnostic help anchor. Co-authored-by: Copilot App <[email protected]>
Save diagnostics without exception boilerplate and pair each comparison step with its output illustration. Pass the comparison options to tolerant difference generation so the visual matches the classification. Co-authored-by: Copilot App <[email protected]>
Preserve opaque classification as ThresholdMap and make ThresholdOverlay blend highlights at50percent over white-flattened actual pixels. Keep comparison metrics/gates unchanged and cover both styles with exact-pixel tests. Correct hidden-RGB mask fixtures to distinguish transparent white from transparent black. Add a file-based documentation generator using one800x600scene with color, alpha and added-content differences. Save only raw PNG inputs, masks and real comparer outputs; keep all labels/layout in Markdown. Split budget guidance and show the same scene in every example. Validation: dedicated comparison48passed; generator and DocFX build passed. Full unfiltered desktop suite still hits varying stream/document GC failures and the known macOSGL DiagonalLines1832-pixel divergence; no tests, tolerances or GPU policies relaxed. Co-authored-by: Copilot App <[email protected]>
Use identical RGB tolerance2 and exact alpha for all four style examples. Display a separate tolerant overlay next to the opaque amber/red map, retain the alpha-only circle and RGB-only raw diagnostic, and explain mixed overlay colors. Co-authored-by: Copilot App <[email protected]>
Render a rounded blue panel, emerald alpha-only circle and added rounded rose square over a subtle gradient. Keep shared mask geometry and all comparison features intact, regenerate the raw800x600PNGs and rebuild DocFX. Co-authored-by: Copilot App <[email protected]>
Keep source artwork distinct from red mismatch and amber tolerance indicators, and regenerate the documentation images. Co-authored-by: Copilot App <[email protected]>
Save separate display copies over a checkerboard while retaining the original RGBA inputs for actual comparisons. Keep source artwork, measurements, masks and opaque diagnostic outputs unchanged. Co-authored-by: Copilot App <[email protected]>
Center every800x600 display image in a900x700 checkerboard preview with50-pixel padding. Apply the same presentation to masks and all diagnostics without changing in-memory comparison data or original RGBA inputs. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Remove border/dimension/display-production commentary and the maintainer regeneration section. Keep the regeneration command beside the generator and let visuals illustrate the comparison features without palette-specific narration. Co-authored-by: Copilot App <[email protected]>
Cover decoded image, bitmap and pixmap inputs, tolerance/ignore masks, all diagnostic styles, and percentage-budget arithmetic with reusable BenchmarkDotNet fixtures. Include the cases in PR source tracking without requiring the unpublished Testing package for historical release baselines. Co-authored-by: Copilot App <[email protected]>
Cache the normalized image width instead of invoking native lookups for each mismatched pixel. Count identical pixels as compared, but skip their zero-error channel evaluation. Cover sparse, dense, identical and narrow image cases, and track identical-image performance. Make pixel benchmarks unconditional in source tracking and reduce the benchmark README addition to a two-line note. Co-authored-by: Copilot App <[email protected]>
BuildingInsideVisualStudio causes MSBuild to strip parent configuration from project references by default. Disable that behavior for the Testing build so it consumes the Release SkiaSharp assembly already built by the workflow, instead of a nonexistent Debug reference on clean CI runners. Co-authored-by: Copilot App <[email protected]>
Color the largest raw enabled-channel difference from blue through cyan and yellow to red, keeping exact matches black and ignored coverage gray. Reuse the existing pixel evaluation and a lazily initialized color table without changing comparison acceptance or existing diagnostic styles. Cover palette boundaries, tolerances, masks, alpha, input families and ownership; include the diagnostic in benchmark tracking and the illustrated guide. Co-authored-by: Copilot App <[email protected]>
Group the heatmap with the other styles, remove duplicated example images, and keep the guide focused on using the library rather than explaining individual implementation decisions. Co-authored-by: Copilot App <[email protected]>
Add an ellipse shared by both inputs, changing its teal-to-cream gradient to a solid fill. Regenerate the diagnostic gallery so raw differences and the heatmap show progressively larger errors across the shape. Co-authored-by: Copilot App <[email protected]>
Rename the experimental entry point to SKImageComparison and supporting types to SKComparisonOptions, SKComparisonResult, SKComparisonMetrics, and SKDifferenceStyle. Keep SKPixelTolerance, SKPixelMismatchBudget, and the SkiaSharp.Testing namespace and package unchanged. Update source filenames, consumers, tests, benchmarks, and guide examples without altering comparison behavior or benchmark tracking identifiers. Co-authored-by: Copilot App <[email protected]>
Register the Testing host with .NET and .NET Framework Cake runners, using Framework-compatible enum enumeration. Save reusable masks and diagnostic outputs at the input dimensions and retain decorated gallery images under explicit preview filenames. Co-authored-by: Copilot App <[email protected]>
Preserve the unified golden lookup, retry, attachment, and reference workflow added on main while replacing its copied pixel comparer with the experimental shared package. Keep existing visual, sample, and core assertion policies unchanged. Co-authored-by: Copilot App <[email protected]>
The sample host now uses the shared golden harness, so the deleted PixelComparison project import prevented project evaluation after the main-branch conflict resolution. Co-authored-by: Copilot App <[email protected]>
b1f35c7 to
504c141
Compare
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed at 504c1416 (static, read-only review).
The stale PixelComparison.projitems import from my earlier review was removed in 75883d85, and the rebased head keeps that fix. I re-read the full current boundary:
- Testing library: the
SkiaSharp.Testingsources (the comparison, options, tolerance, mismatch budget, result and metrics types, plus theExperimentalAttributepolyfill for targets below .NET 8) are consistent with the six test files and the docs (image-comparison.md,experimental-apis.md,api-design.md, the testing index and TOC). - SKIA4001 suppression: every project that compiles code calling the experimental API suppresses the diagnostic: SkiaSharp.Tests, Tests.Console, Tests.Shared, Tests.Integration, Testing.Tests, Benchmarks and Benchmarks.Tracking.Source. The Devices/Wasm, Direct3D/Vulkan, Gallery, SingletonInit, Gtk4, Fuzzing, MSBuild, Samples.Analyzers and Native projects either don't reference
SkiaSharp.Testingor only reference it through aProjectReference. No globalTreatWarningsAsErrorsis set. - Packaging, signing and test runs:
VERSIONS.txt,SUPPORTED_NUGETSinshared.cake,Signing.props, the three.slnffilters andSkiaSharpSource.slnx, the netcore/netfx cake test lists andtrack-benchmarks.ymlall wire in the new package and test project consistently. - Leftover references: a code search found no remaining references to the removed comparer outside files this PR changes, and none in those files at this head.
- Target: current
main(46d73186) only touches release-notes docs and an issue template since the merge base, so there's no overlap.
This is static review only; I didn't run builds or tests.
LGTM.

Description
Add experimental SkiaSharp.Testing, a separately packaged image-comparison library, and replace the copied/Extended pixel comparer in existing rendering-test consumers. It supports channel tolerances, mismatch budgets, raw/thresholded error metrics, MAE/RMS acceptance limits, tolerance/ignore masks, and five diagnostic styles.
The package uses normal SkiaSharp family versioning and
SKIA4001experimental opt-in. Existing native APIs, reviewed baselines and consumer acceptance policies are unchanged. Exact-package integration uses the matching Testing package rather than a locally built substitute.Guides → Testing includes generated examples. Inputs, masks and diagnostic outputs are saved at 800×600; separate
*-preview.pngcopies preserve the checkerboard gallery presentation. The scene covers a subtle RGB change, an alpha-only change, an added square and a gradient-to-solid fill change.Related issues
None.
Required skia PR
None.
Areas affected
binding/)externals/skia/src/c,include/c)Changes
Public API
All types below are in
SkiaSharp.Testing. This is a new, unpublished experimental API; existing SkiaSharp and Extended public types are not renamed or removed.Complete public declarations
Implicit constructors are listed above for completeness; results and metrics are library-constructed. The compatibility experimental attribute is internal.
Behavior
Default comparison is exact RGBA after normalization to unpremultiplied BGRA8888. Null channel tolerances exclude channels. Tolerance percentages use the channel range; mismatch percentages use nonignored compared pixels, with inclusive whole-pixel limits floored from the round-trip decimal percentage. Configured mismatch/MAE/RMS gates combine with AND; magnitude-only gates impose no implicit zero-mismatch requirement.
Tolerance masks widen enabled-channel allowances without reducing raw measurements. Ignore masks exclude pixels from errors, bounds and sample denominators; ignoring every pixel throws. Inputs and masks are borrowed for each synchronous call. Results retain no native inputs; returned diagnostics are independently owned by the caller.
Diagnostics are opaque:
BinaryMaskshows mismatch status,ChannelDifferenceshows raw RGB differences (including disabled RGB channels, without alpha),ThresholdMapshows solid red/amber/gray classifications, defaultThresholdOverlayblends classifications at 50% over actual pixels flattened onto white, andHeatmapmaps the largest raw enabled-channel error to a fixed blue-to-red scale, with black exact matches and gray ignored coverage. Heatmap includes tolerated and enabled alpha differences.No native/C API or generated-binding changes, automatic baseline acceptance, or relaxed consumer thresholds. Comparison avoids repeated native width lookups and skips zero-error arithmetic for identical normalized pixels; timing and managed-allocation benchmarks are included in source tracking.
Testing
Latest local review-fix validation on macOS ARM64:
dotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0— comparison host 69 passed, 0 failed, 0 skipped; full solution still fails only the previously observedganesh-gl/DiagonalLinesgolden comparison. Main host: 6,407 total, 6,383 passed, 23 policy skips, 1 failure. Other hosts passed. No baselines or skip policies changed.dotnet build tests/SkiaSharp.Testing.Tests/SkiaSharp.Testing.Tests.csproj -p:TargetFramework=net48 -p:TargetFrameworks=net48 -p:AllTargetFrameworks=net48 -p:BasicTargetFrameworks=net48 -p:AutomaticallyUseReferenceAssemblyPackages=true -v:q— passed, 0 warnings/errors. Windows .NET Framework execution remains CI validation; no Windows runtime execution was performed locally.dotnet run --file documentation/docfx/guides/testing/generate-images.cs -p:TargetFrameworks=net10.0— passed; regenerated raw outputs and separately named previews. Raw files are 800×600; previews are 850×650 and byte-identical to the previous gallery presentation.The test host is now registered in both Cake CI runner lists (.NET and Windows .NET Framework x86/x64). The previously green AzDO build 1639386 predates these runner-registration fixes. Matching native assets from that build were used locally; no compatibility checks were bypassed. No package published.
Checklist
Changesabove lists all public API and behavioral changes (or "None.")///documentation and regenerated bindings when applicablemono/skiaPR linked above and bindings regeneratedNative regeneration is not applicable.