From dabbd7089d67f3c0e29ab6d074dc4c1d9c057800 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 30 Mar 2021 17:30:48 +0200 Subject: [PATCH 1/2] Swap the buffers after a resize (#1668) Swap the buffers after a resize to get the current buffer to be the new, correct size. Fixes #1377, #914, #722 --- native/uwp/build.cake | 10 ++++++---- .../SkiaSharp.Views.UWP/AngleSwapChainPanel.cs | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/native/uwp/build.cake b/native/uwp/build.cake index f56fc940..bb151ad1 100644 --- a/native/uwp/build.cake +++ b/native/uwp/build.cake @@ -114,14 +114,16 @@ Task("ANGLE") { if (Skip(arch)) return; + var d = CONFIGURATION.ToLower() == "release" ? "" : "debug/"; + RunProcess (vcpkg, $"install angle:{arch}-uwp"); var outDir = OUTPUT_PATH.Combine(arch); EnsureDirectoryExists(outDir); - CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/bin/libEGL.dll"), outDir); - CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/bin/libEGL.pdb"), outDir); - CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/bin/libGLESv2.dll"), outDir); - CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/bin/libGLESv2.pdb"), outDir); + CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/{d}bin/libEGL.dll"), outDir); + CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/{d}bin/libEGL.pdb"), outDir); + CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/{d}bin/libGLESv2.dll"), outDir); + CopyFileToDirectory(VCPKG_PATH.CombineWithFilePath ($"installed/{arch}-uwp/{d}bin/libGLESv2.pdb"), outDir); } }); diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs index 1afe7485..d33a4d34 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs @@ -33,6 +33,8 @@ namespace SkiaSharp.Views.UWP private bool enableRenderLoop; + private bool pendingSizeChange = false; + public AngleSwapChainPanel() { glesContext = null; @@ -148,6 +150,8 @@ namespace SkiaSharp.Views.UWP private void OnCompositionChanged(SwapChainPanel sender, object args) { + pendingSizeChange = true; + ContentsScale = CompositionScaleX; DestroyRenderSurface(); @@ -157,6 +161,8 @@ namespace SkiaSharp.Views.UWP private void OnSizeChanged(object sender, SizeChangedEventArgs e) { + pendingSizeChange = true; + EnsureRenderSurface(); Invalidate(); } @@ -189,6 +195,15 @@ namespace SkiaSharp.Views.UWP return; glesContext.MakeCurrent(); + + if (pendingSizeChange) + { + pendingSizeChange = false; + + if (!EnableRenderLoop) + glesContext.SwapBuffers(); + } + glesContext.GetSurfaceDimensions(out var panelWidth, out var panelHeight); glesContext.SetViewportSize(panelWidth, panelHeight); From 2ad29861d5a40d3bf78c28ab0a9cb02a8f0fe437 Mon Sep 17 00:00:00 2001 From: gmurray81 Date: Tue, 30 Mar 2021 11:50:52 -0400 Subject: [PATCH 2/2] avoid issues with failure to create gl surface (#1642) --- .../AngleSwapChainPanel.cs | 15 ++++++ .../GlesInterop/GlesContext.cs | 52 ++++++++++--------- .../SkiaSharp.Views.UWP/SKSwapChainPanel.cs | 2 +- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs index d33a4d34..77f5fad3 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs @@ -33,10 +33,16 @@ namespace SkiaSharp.Views.UWP private bool enableRenderLoop; + private double lastCompositionScaleX = 0.0; + private double lastCompositionScaleY = 0.0; + private bool pendingSizeChange = false; public AngleSwapChainPanel() { + lastCompositionScaleX = CompositionScaleX; + lastCompositionScaleY = CompositionScaleY; + glesContext = null; renderLoopWorker = null; @@ -150,6 +156,15 @@ namespace SkiaSharp.Views.UWP private void OnCompositionChanged(SwapChainPanel sender, object args) { + if (lastCompositionScaleX == CompositionScaleX && + lastCompositionScaleY == CompositionScaleY) + { + return; + } + + lastCompositionScaleX = CompositionScaleX; + lastCompositionScaleY = CompositionScaleY; + pendingSizeChange = true; ContentsScale = CompositionScaleX; diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/GlesInterop/GlesContext.cs b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/GlesInterop/GlesContext.cs index 0bbae5b3..45fb664b 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/GlesInterop/GlesContext.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/GlesInterop/GlesContext.cs @@ -2,6 +2,7 @@ using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml.Controls; +using System.Collections.Generic; using SkiaSharp.Views.UWP.Interop; @@ -14,9 +15,10 @@ namespace SkiaSharp.Views.GlesInterop { internal class GlesContext : IDisposable { + private static EGLDisplay eglDisplay = Egl.EGL_NO_DISPLAY; + private bool isDisposed = false; - private EGLDisplay eglDisplay; private EGLContext eglContext; private EGLSurface eglSurface; private EGLConfig eglConfig; @@ -24,10 +26,10 @@ namespace SkiaSharp.Views.GlesInterop public GlesContext() { eglConfig = Egl.EGL_NO_CONFIG; - eglDisplay = Egl.EGL_NO_DISPLAY; eglContext = Egl.EGL_NO_CONTEXT; eglSurface = Egl.EGL_NO_SURFACE; + InitializeDisplay(); Initialize(); } @@ -139,24 +141,10 @@ namespace SkiaSharp.Views.GlesInterop Initialize(); } - private void Initialize() + private void InitializeDisplay() { - int[] configAttributes = new[] - { - Egl.EGL_RED_SIZE, 8, - Egl.EGL_GREEN_SIZE, 8, - Egl.EGL_BLUE_SIZE, 8, - Egl.EGL_ALPHA_SIZE, 8, - Egl.EGL_DEPTH_SIZE, 8, - Egl.EGL_STENCIL_SIZE, 8, - Egl.EGL_NONE - }; - - int[] contextAttributes = new[] - { - Egl.EGL_CONTEXT_CLIENT_VERSION, 2, - Egl.EGL_NONE - }; + if (eglDisplay != Egl.EGL_NO_DISPLAY) + return; int[] defaultDisplayAttributes = new[] { @@ -242,6 +230,26 @@ namespace SkiaSharp.Views.GlesInterop } } } + } + + public void Initialize() + { + int[] configAttributes = new[] + { + Egl.EGL_RED_SIZE, 8, + Egl.EGL_GREEN_SIZE, 8, + Egl.EGL_BLUE_SIZE, 8, + Egl.EGL_ALPHA_SIZE, 8, + Egl.EGL_DEPTH_SIZE, 8, + Egl.EGL_STENCIL_SIZE, 8, + Egl.EGL_NONE + }; + + int[] contextAttributes = new[] + { + Egl.EGL_CONTEXT_CLIENT_VERSION, 2, + Egl.EGL_NONE + }; EGLDisplay[] configs = new EGLDisplay[1]; if ((Egl.eglChooseConfig(eglDisplay, configAttributes, configs, configs.Length, out int numConfigs) == Egl.EGL_FALSE) || (numConfigs == 0)) @@ -264,12 +272,6 @@ namespace SkiaSharp.Views.GlesInterop Egl.eglDestroyContext(eglDisplay, eglContext); eglContext = Egl.EGL_NO_CONTEXT; } - - if (eglDisplay != Egl.EGL_NO_DISPLAY) - { - Egl.eglTerminate(eglDisplay); - eglDisplay = Egl.EGL_NO_DISPLAY; - } } } } diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs index e4ad1e9d..213a0220 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs @@ -110,7 +110,7 @@ namespace SkiaSharp.Views.UWP glInfo = default; - context?.AbandonContext(true); + context?.AbandonContext(false); context?.Dispose(); context = null;