Skip to content

fix(SvgImageSource): Draw SetSourceAsync streams (6.8, backport of #25166) - #25555

Open
mikernet wants to merge 2 commits into
unoplatform:servicing/6.8from
mikernet:dev/mikernet/svg-stream-source-6.8
Open

mikernet wants to merge 2 commits into
unoplatform:servicing/6.8from
mikernet:dev/mikernet/svg-stream-source-6.8

Conversation

@mikernet

@mikernet mikernet commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25554

PR Type:

🐞 Bugfix

What changed? 🚀

This backports #25166 to servicing/6.8, adapted to 6.8's ISvgProvider layout. It is the bug fix only. The differences from WinUI that I found while testing this are present on master too, so they go to master in #25558.

On Skia, SvgImageSource.SetSourceAsync(stream) returned Other and drew nothing, and neither Opened nor OpenFailed was raised. It failed whether Image.Source was set before or after the call.

SetSourceAsync subscribes to the source, which opens it, and then calls InvalidateSource(), which opens it again and cancels the first open's token. The load cached in _currentOpenTask was bound to that first token, so the second open reused a load whose stream read had been cancelled. An ImageBrush that subscribes to an SvgImageSource while its UriSource is still loading re-opens it the same way and stayed empty.

As in #25166, the load now has its own CancellationTokenSource. Only UnloadImageSourceData, called when the source itself changes, cancels it. This matches WinUI, where only DisconnectImageOperation aborts a decode. A load aborted that way returns empty without publishing. The native Android and Apple partials share the provider, so I only updated their calls to the new signature.

Tests:

  • Given_Image.When_SVGImageSource_SetSourceAsync_File_Stream, with Image.Source set before and after the call: the status is Success, Opened is raised and the SVG is drawn. The stream comes from a file, so its read is still pending when the source is opened again.
  • Given_Image.When_SVGImageSource_SetSourceAsync_Twice: two SetSourceAsync calls on the same source, red and then blue, and each color is drawn.
  • Given_ImageBrush.When_SvgImageSource_Assigned_While_Opening: a loopback server answers after 200 ms, so the brush subscribes while the source is still opening. It is excluded on WebAssembly, where the browser has no sockets, and on the native Android and iOS renderers, like the stream tests. It runs on WinUI, as master's Given_Image version does.
  • The two Given_Image tests are excluded on the native renderers, which load SVG through their own pipeline.

Results:

  • Without the fix, on Skia WebAssembly all three stream test cases fail with Other. On Skia desktop, the source-after row and the twice test failed in all 3 runs, the source-first row in 1 of 3 (the file read races the second open), and the brush test in 2 of 2.
  • With the fix, Given_Image, Given_ImageSource, Given_ImageBrush and Given_BitmapSource pass on Skia desktop (61/61, Win32). On Skia WebAssembly, Given_Image, Given_ImageBrush and Given_BitmapSource pass 60/60, plus 1 inconclusive (When_Transitive_Asset_With_Link_Loaded).
  • The same two Given_Image tests pass on WinUI (WinAppSDK).
  • Uno.UI compiles for net10.0-android and net10.0-ios26.0.

PR Checklist ✅

@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Oct 17, 2026
mikernet added a commit to Singulink/uno that referenced this pull request Oct 17, 2026
Port of unoplatform#25555 (43b47f5), the 6.8 backport of
unoplatform#25166.

On Skia, SetSourceAsync(stream) returned Other and drew nothing, and
neither Opened nor OpenFailed fired, whether Image.Source was set before
or after the call. SetSourceAsync subscribes to the source, which opens
it, then calls InvalidateSource, which opens it again and cancels the
first open's token, and the cached load was bound to that token. An
ImageBrush that subscribes while a UriSource is still loading re-opens
it the same way.
- The load has its own cancellation, cancelled only when the source
  itself changes (UnloadImageSourceData), as on master and as in WinUI,
  where only DisconnectImageOperation aborts a decode.
- Tests: When_SVGImageSource_SetSourceAsync_File_Stream,
  When_SVGImageSource_SetSourceAsync_Twice (Given_Image) and
  When_SvgImageSource_Assigned_While_Opening (Given_ImageBrush).

6.8 differences:
- None: unoplatform#25555 targets servicing/6.8 and cherry-picks clean, also on top
  of the unoplatform#25124 port. That port leaves an SvgImageSource's data alone
  while nothing subscribes, so the load this keeps alive is not released
  under it.
On Skia, SetSourceAsync(stream) returned Other and drew nothing, and
neither Opened nor OpenFailed fired, whether Image.Source was set
before or after the call.

SetSourceAsync subscribes to the source, which opens it, then calls
InvalidateSource, which opens it again and cancels the first open's
token. The load is cached in _currentOpenTask and was bound to that
first token, so the second open reused a load whose stream read had
been cancelled. An ImageBrush that subscribes to an SvgImageSource
whose UriSource is still loading re-opens it the same way.

The load now has its own cancellation, cancelled only when the source
itself changes (UnloadImageSourceData), as on master since unoplatform#25166 and
as in WinUI, where only DisconnectImageOperation aborts a decode.
@Xiaoy312
Xiaoy312 force-pushed the dev/mikernet/svg-stream-source-6.8 branch from 43b47f5 to 2201a6c Compare November 6, 2026 15:56
@Xiaoy312

Xiaoy312 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@mikernet heads-up: I rebased this branch onto the current servicing/6.8 to clear a merge conflict, and force-pushed it (43b47f5 → 2201a6c). Please reset your local branch before pushing again (git fetch + git reset --hard origin/dev/mikernet/svg-stream-source-6.8, or the equivalent for your fork's remote).

The only conflict was in Given_ImageBrush.cs: #25597 added When_Source_Outlives_Brushes at the same spot as your When_SvgImageSource_Assigned_While_Opening. I kept both as-is. Your commit is otherwise unchanged (same author, same 148/−5 diff).

After the rebase, Given_Image + Given_ImageBrush pass on Skia desktop (Win32): 46/46, including your new tests.

@agneszitte

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 244747 did not find any UI Test snapshots differences.

@mergify

mergify Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@MartinZikmund MartinZikmund left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @mikernet! I checked this against #25166: the provider change is the same fix, adapted correctly to 6.8's layout (provider + .skia.cs, with the Android/Apple partials only picking up the new signature), and it doesn't use anything that's master-only. The CI failures (Given_InputInjector, Given_TextBox touch, Given_CommandBar) aren't in the SVG/image area, so they're unrelated.

One optional nit: When_SvgImageSource_Assigned_While_Opening uses Include SkiaDesktop | SkiaMobile, which also skips it on WinAppSDK. Excluding only SkiaWasm, as the master test does, would keep the WinUI parity run.

The test only needs sockets, so it now excludes the browser (and the native renderers, like its siblings) instead of including only Skia desktop and mobile, which also skipped WinAppSDK.
@mikernet

Copy link
Copy Markdown
Contributor Author

Done in 0be5cf9: When_SvgImageSource_Assigned_While_Opening now excludes Wasm | NativeMobile instead of including only SkiaDesktop | SkiaMobile, so it runs on WinAppSDK as master's version does. The browser has no sockets, and the native mobile renderers are excluded for the same reason as the two stream tests in this PR: they load SVG through their own pipeline.

@MartinZikmund

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 249303 did not find any UI Test snapshots differences.

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

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants