Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/ControlCatalog.NetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public static AppBuilder BuildAvaloniaApp()
{
UseRegionDirtyRectClipping = true
})
.With(new SkiaOptions()
{
PerformGlSwapOnCpu = true
})
.UseSkia()
.WithInterFont()
.AfterSetup(builder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,19 @@ IBitmapImpl TakeSnapshot()
var textureId = _image?.TextureId ?? _sharedTexture!.TextureId;
var topLeft = _image?.Properties.TopLeftOrigin ?? false;
var textureType = _image?.TextureType ?? GlConsts.GL_TEXTURE_2D;


var skiaOptions = AvaloniaLocator.Current.GetService<SkiaOptions>();


IBitmapImpl rv;
using (var surf = TryCreateSurface(textureType, textureId, internalFormat, width, height, topLeft))
{
if (surf == null)
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.


rv = new ImmutableBitmap(snapshot, () =>
rv = new ImmutableBitmap(raster ?? snapshot, () =>
{
IDisposable? restoreContext = null;
try
Expand All @@ -156,6 +158,7 @@ IBitmapImpl TakeSnapshot()

using (restoreContext)
{
raster?.Dispose();
snapshot.Dispose();
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/Skia/Avalonia.Skia/SkiaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public class SkiaOptions
/// Enabling this might have performance implications.
/// </remarks>
public bool UseOpacitySaveLayer { get; set; } = false;

/// <summary>
/// Perform the GL buffer swap on the CPU instead of the GPU. This can help with some rendering issues on certain PCs.
/// Note that this may have a performance hit. The default value is false.
/// </summary>
public bool PerformGlSwapOnCpu { get; set; } = false;
}
}