Skip to content

Conversation

spicermicer
Copy link

What does the pull request do?

Added SkiaOptions.PerformGlSwapOnCpu, this causes the surface snapshot to be moved to the CPU which seems to increase stability although would cause a performance decrease

What is the current behavior?

AngleEGL is unable to render the OpenGL context. This has been reported as working on certain PC's but it seems to be a fairly common issue based on #18713

What is the updated/expected behavior with this PR?

On a PC where AngleEGL is unable to render, setting SkiaOptions.PerformGLSwapOnCpu = true, should fix the issue.

How was the solution implemented (if it's not obvious)?

ToRasterImage() on the snapshot will move the snapshot to the CPU, it's then drawn as expected

Breaking changes

None known of

Obsoletions / Deprecations

None

Fixed issues

#18713

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059296-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Oct 10, 2025

  • All contributors have signed the CLA.

throw new OpenGlException("Unable to consume provided texture");
var snapshot = surf.Snapshot();
var raster = skiaOptions?.PerformGlSwapOnCpu == true ? snapshot.ToRasterImage() : null;
var context = _gpu.GlContext;
Copy link
Member

Choose a reason for hiding this comment

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

Try doing GrContext.Flush() or reading back 1 (one) pixel from the snapshot instead. I suspect that the underlying cause is some synchronization issue.

Copy link
Author

Choose a reason for hiding this comment

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

@kekekeks I set the PerformGlSwapOnCpu to false. and added the following code

     var snapshot = surf.Snapshot();

+    _gpu.GrContext.Flush();
+    using var bitmap = new SKBitmap(1, 1, SKColorType.Rgba8888, SKAlphaType.Premul);
+    bool success = snapshot.ReadPixels(bitmap.Info, bitmap.GetPixels(), bitmap.RowBytes, 0, 0);

     var raster = skiaOptions?.PerformGlSwapOnCpu == true ? snapshot.ToRasterImage() : null;

While success is true, the image is still not displayed

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a repro we could try?

Copy link
Member

Choose a reason for hiding this comment

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

Also, there is a known issue with Skia 3.x and EGL. Are you experiencing the problem with 2.88?

Copy link
Author

Choose a reason for hiding this comment

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

For me, this issue is presenting on the Samples.ControlCatalog. However, from the bug referenced, I believe it may be a somewhat system dependant / intermittent issue, hence why I added it as a optional flag. If it's working on your system please let me know what data you require and I can hopefully provide it.

I'm using the default version of Skia on Avalonia which I believe is 3.119

Copy link
Author

Choose a reason for hiding this comment

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

@kekekeks I've just re-read your comment. I attempted to downgrade to Skia 2.88 but there was too many errors in the downgrade for me to fix.

@spicermicer
Copy link
Author

@cla-avalonia agree

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants