From 03d92012debfb45a7840dfc74ef18241f7cb102a Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 2 Jun 2022 23:07:10 +0200 Subject: [PATCH] chore: Cleanup conflicts in host rendering --- .../GLRenderSurfaceBase.cs | 2 ++ src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs | 4 ++-- src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs | 6 ++++- .../SoftwareRenderSurface.cs | 24 ++++++++----------- .../FramebufferHost.cs | 22 +++++++++++++++++ .../Renderer.cs | 8 ++----- src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs | 2 -- src/Uno.UI/UI/Xaml/XamlRoot.cs | 1 + 8 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs b/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs index 94660cf559ff..af6dda48a805 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs @@ -61,6 +61,8 @@ public GLRenderSurfaceBase() AutoRender = true; } + public Widget Widget => this; + public void InvalidateRender() { // TODO Uno: Make this invalidation less often if possible. diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs index c694cb1827e5..83c60a528aff 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs @@ -240,9 +240,9 @@ private void WindowClosing(object sender, DeleteEventArgs args) Gtk.Main.Quit(); } - private Widget BuildRenderSurfaceType() + private IRenderSurface BuildRenderSurfaceType() { - if(RenderSurfaceType == null) + if (RenderSurfaceType == null) { if (OpenGLESRenderSurface.IsSupported) { diff --git a/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs b/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs index 21ea4f91a9a8..1fcd09999dfb 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs @@ -1,7 +1,11 @@ -namespace Uno.UI.Runtime.Skia +using Gtk; + +namespace Uno.UI.Runtime.Skia { internal interface IRenderSurface { + Widget Widget { get; } + void TakeScreenshot(string filePath); void InvalidateRender(); diff --git a/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs b/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs index 52f085093529..5c39613d2b2b 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs @@ -15,6 +15,7 @@ using Uno.UI.Runtime.Skia.Helpers.Windows; using Uno.UI.Runtime.Skia.Helpers.Dpi; using Windows.Graphics.Display; +using Gtk; namespace Uno.UI.Runtime.Skia { @@ -36,21 +37,7 @@ public SoftwareRenderSurface() { _displayInformation = DisplayInformation.GetForCurrentView(); _displayInformation.DpiChanged += OnDpiChanged; - } - public void InvalidateRender() - { - //TODO:MZ: Fix below conflict! - // TODO Uno: Make this invalidation less often if possible. - InvalidateOverlays(); - Invalidate(); - WUX.Window.InvalidateRender - += () => - { - // TODO Uno: Make this invalidation less often if possible. - InvalidateOverlays(); - Invalidate(); - }; _colorType = SKImageInfo.PlatformColorType; // R and B channels are inverted on macOS running on arm64 CPU and this is not detected by Skia if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -62,6 +49,15 @@ public void InvalidateRender() } } + public Widget Widget => this; + + public void InvalidateRender() + { + // TODO Uno: Make this invalidation less often if possible. + InvalidateOverlays(); + Invalidate(); + } + private void OnDpiChanged(DisplayInformation sender, object args) => UpdateDpi(); diff --git a/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/FramebufferHost.cs b/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/FramebufferHost.cs index 5eac682efd18..23bb95f9188d 100644 --- a/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/FramebufferHost.cs +++ b/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/FramebufferHost.cs @@ -6,6 +6,7 @@ using Windows.UI.Core; using Uno.Foundation.Extensibility; using System.ComponentModel; +using Uno.UI.Xaml.Core; namespace Uno.UI.Runtime.Skia { @@ -69,6 +70,27 @@ void CreateApp(ApplicationInitializationCallbackParams _) _displayInformationExtension!.Renderer = _renderer; WUX.Application.StartWithArguments(CreateApp); + + WUX.Window.Current.Activated += Current_Activated; + } + + private void Current_Activated(object sender, WindowActivatedEventArgs e) + { + var xamlRoot = CoreServices.Instance + .ContentRootCoordinator? + .CoreWindowContentRoot? + .XamlRoot; + + if (xamlRoot is null) + { + throw new InvalidOperationException("XamlRoot was not properly initialized"); + } + + xamlRoot.InvalidateRender += _renderer!.InvalidateRender; + + // Force initial render + _renderer.InvalidateRender(); + WUX.Window.Current.Activated -= Current_Activated; } } } diff --git a/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/Renderer.cs b/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/Renderer.cs index 0187cf33e1b9..47950a30ee62 100644 --- a/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/Renderer.cs +++ b/src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/Renderer.cs @@ -22,18 +22,14 @@ public Renderer() _fbDev.Init(); var resolution = _fbDev.ScreenSize; - - WUX.Window.InvalidateRender - += () => - { - Invalidate(); - }; WUX.Window.Current.OnNativeSizeChanged(new Windows.Foundation.Size(resolution.Width, resolution.Height)); } public Size PixelSize => _fbDev.ScreenSize; + internal void InvalidateRender() => Invalidate(); + void Invalidate() { int width, height; diff --git a/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs b/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs index c89611e0dae8..89966031cd49 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs @@ -131,8 +131,6 @@ public WpfHost(global::System.Windows.Threading.Dispatcher dispatcher, Func dispatcher.BeginInvoke(d); Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = dispatcher.CheckAccess; - WinUI.Application.StartWithArguments(CreateApp); - _hostPointerHandler = new HostPointerHandler(this); WinUI.Window.Current.Activated += Current_Activated; diff --git a/src/Uno.UI/UI/Xaml/XamlRoot.cs b/src/Uno.UI/UI/Xaml/XamlRoot.cs index 384127e2a6b9..07769a5af2c4 100644 --- a/src/Uno.UI/UI/Xaml/XamlRoot.cs +++ b/src/Uno.UI/UI/Xaml/XamlRoot.cs @@ -3,6 +3,7 @@ using Uno.UI.Xaml.Core; using Uno.UI.Xaml.Islands; using Windows.Foundation; +using Windows.Graphics.Display; namespace Windows.UI.Xaml;