Skip to content

Commit

Permalink
chore: Cleanup conflicts in host rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jun 2, 2022
1 parent 6771870 commit 03d9201
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public GLRenderSurfaceBase()
AutoRender = true;
}

public Widget Widget => this;

public void InvalidateRender()
{
// TODO Uno: Make this invalidation less often if possible.
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
24 changes: 10 additions & 14 deletions src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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))
Expand All @@ -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();

Expand Down
22 changes: 22 additions & 0 deletions src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/FramebufferHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 2 additions & 6 deletions src/Uno.UI.Runtime.Skia.Linux.FrameBuffer/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public WpfHost(global::System.Windows.Threading.Dispatcher dispatcher, Func<WinU
Windows.UI.Core.CoreDispatcher.DispatchOverride = d => dispatcher.BeginInvoke(d);
Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = dispatcher.CheckAccess;

WinUI.Application.StartWithArguments(CreateApp);

_hostPointerHandler = new HostPointerHandler(this);
WinUI.Window.Current.Activated += Current_Activated;

Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/XamlRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 03d9201

Please sign in to comment.