Skip to content

Commit

Permalink
chore: Re-enable full-screen Skia app render for GTK and WPF
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed May 16, 2022
1 parent 19906ce commit d6f9712
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 28 deletions.
14 changes: 7 additions & 7 deletions src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ public GLRenderSurfaceBase()
{
_displayInformation = DisplayInformation.GetForCurrentView();
_displayInformation.DpiChanged += OnDpiChanged;
WUX.Window.InvalidateRender
+= () =>
{
// TODO Uno: Make this invalidation less often if possible.
InvalidateOverlays();
QueueRender();
};

// Set some event handlers
Render += UnoGLDrawingArea_Render;
Expand All @@ -68,6 +61,13 @@ public GLRenderSurfaceBase()
AutoRender = true;
}

public void InvalidateRender()
{
// TODO Uno: Make this invalidation less often if possible.
InvalidateOverlays();
QueueRender();
}

private void GLRenderSurface_Realized(object? sender, EventArgs e)
{
Context.MakeCurrent();
Expand Down
74 changes: 60 additions & 14 deletions src/Uno.UI.Runtime.Skia.Gtk/GtkCoreWindowExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Device = Gtk.Device;
using Exception = System.Exception;
using Uno.Foundation.Logging;
using Windows.UI.Xaml;
using Uno.UI.Xaml.Core;

namespace Uno.UI.Runtime.Skia
{
Expand Down Expand Up @@ -104,7 +106,7 @@ private void OnWindowEnterEvent(object o, EnterNotifyEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerEntered(ptArgs);
RaisePointerEntered(ptArgs);
}
}
catch (Exception e)
Expand All @@ -125,7 +127,7 @@ private void OnWindowLeaveEvent(object o, LeaveNotifyEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerExited(ptArgs);
RaisePointerExited(ptArgs);
}
}
}
Expand All @@ -141,7 +143,7 @@ private void OnWindowButtonPressEvent(object o, ButtonPressEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerPressed(ptArgs);
RaisePointerPressed(ptArgs);
}
}
catch (Exception e)
Expand All @@ -156,7 +158,7 @@ private void OnWindowButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerReleased(ptArgs);
RaisePointerReleased(ptArgs);
}
}
catch (Exception e)
Expand All @@ -171,7 +173,7 @@ private void OnWindowMotionEvent(object o, MotionNotifyEventArgs args) // a.k.a.
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerMoved(ptArgs);
RaisePointerMoved(ptArgs);
}
}
catch (Exception e)
Expand All @@ -186,7 +188,7 @@ private void OnWindowScrollEvent(object o, ScrollEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerWheelChanged(ptArgs);
RaisePointerWheelChanged(ptArgs);
}
}
catch (Exception e)
Expand All @@ -206,21 +208,21 @@ private void OnWindowTouchEvent(object o, TouchEventArgs args)
switch (evt.Type)
{
case EventType.TouchBegin:
_ownerEvents.RaisePointerEntered(ptArgs);
_ownerEvents.RaisePointerPressed(ptArgs);
RaisePointerEntered(ptArgs);
RaisePointerPressed(ptArgs);
break;

case EventType.TouchEnd:
_ownerEvents.RaisePointerReleased(ptArgs);
_ownerEvents.RaisePointerExited(ptArgs);
RaisePointerReleased(ptArgs);
RaisePointerExited(ptArgs);
break;

case EventType.TouchCancel:
_ownerEvents.RaisePointerMoved(ptArgs);
RaisePointerMoved(ptArgs);
break;
}

_ownerEvents.RaisePointerMoved(ptArgs);
RaisePointerMoved(ptArgs);
}
}
catch (Exception e)
Expand All @@ -235,7 +237,7 @@ private void OnWindowProximityOutEvent(object o, ProximityOutEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerExited(ptArgs);
RaisePointerExited(ptArgs);
}
}
catch (Exception e)
Expand All @@ -250,7 +252,7 @@ private void OnWindowProximityInEvent(object o, ProximityInEventArgs args)
{
if (AsPointerArgs(args.Event) is { } ptArgs)
{
_ownerEvents.RaisePointerEntered(ptArgs);
RaisePointerEntered(ptArgs);
}
}
catch (Exception e)
Expand Down Expand Up @@ -448,5 +450,49 @@ private static PointerDevice ToPointerDevice(Gdk.Device sourceDevice)

private static bool IsPressed(ModifierType state, ModifierType mask, PointerUpdateKind update, PointerUpdateKind pressed, PointerUpdateKind released)
=> update == pressed || (state.HasFlag(mask) && update != released);

private void RaisePointerExited(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerExited(ptArgs);
InputManager?.RaisePointerExited(ptArgs);
}

private void RaisePointerPressed(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerPressed(ptArgs);
InputManager?.RaisePointerPressed(ptArgs);
}

private void RaisePointerReleased(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerReleased(ptArgs);
InputManager?.RaisePointerReleased(ptArgs);
}

private void RaisePointerMoved(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerMoved(ptArgs);
InputManager?.RaisePointerMoved(ptArgs);
}

private void RaisePointerWheelChanged(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerWheelChanged(ptArgs);
InputManager?.RaisePointerWheelChanged(ptArgs);
}

private void RaisePointerEntered(PointerEventArgs ptArgs)
{
_ownerEvents.RaisePointerEntered(ptArgs);
InputManager?.RaisePointerEntered(ptArgs);
}



internal InputManager InputManager =>
CoreServices.Instance
.ContentRootCoordinator?
.CoreWindowContentRoot?
.InputManager;
}
}
28 changes: 27 additions & 1 deletion src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using Uno.UI.Runtime.Skia.Helpers;
using Uno.UI.Runtime.Skia.Helpers.Dpi;
using System.Runtime.InteropServices;
using Uno.UI.Xaml.Core;
using Windows.UI.Core;

namespace Uno.UI.Runtime.Skia
{
Expand All @@ -42,6 +44,7 @@ public class GtkHost : ISkiaHost
private static bool _isDispatcherThread = false;

private readonly Func<WUX.Application> _appBuilder;
private IRenderSurface _renderSurface;
private static Gtk.Window _window;
private static Gtk.EventBox _eventBox;
private Widget _area;
Expand Down Expand Up @@ -147,7 +150,9 @@ void Dispatch(System.Action d)
var overlay = new Overlay();

_eventBox = new EventBox();
_area = BuildRenderSurfaceType();

_renderSurface = BuildRenderSurfaceType();
_area = (Widget)_renderSurface;
_fix = new Fixed();
overlay.Add(_area);
overlay.AddOverlay(_fix);
Expand Down Expand Up @@ -182,11 +187,32 @@ void CreateApp(ApplicationInitializationCallbackParams _)

WUX.Application.StartWithArguments(CreateApp);

WUX.Window.Current.Activated += Current_Activated;

UpdateWindowPropertiesFromPackage();

Gtk.Application.Run();
}

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 += _renderSurface.InvalidateRender;

// Force initial render
_renderSurface.InvalidateRender();
WUX.Window.Current.Activated -= Current_Activated;
}

private void WindowClosing(object sender, DeleteEventArgs args)
{
var manager = SystemNavigationManagerPreview.GetForCurrentView();
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
internal interface IRenderSurface
{
void TakeScreenshot(string filePath);

void InvalidateRender();
}
}
8 changes: 8 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ 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
+= () =>
{
Expand Down
38 changes: 32 additions & 6 deletions src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
using Uno.UI.Core.Preview;
using Uno.UI.Runtime.Skia.Wpf;
using Uno.UI.Runtime.Skia.Wpf.Extensions.UI.Xaml.Input;
using Uno.UI.Runtime.Skia.Wpf.Hosting;
using Uno.UI.Runtime.Skia.Wpf.WPF.Extensions.Helper.Theming;
using Uno.UI.Runtime.Skia.WPF.Extensions.UI.Xaml.Controls;
using Uno.UI.Xaml;
using Uno.UI.Xaml.Controls.Extensions;
using Uno.UI.Xaml.Core;
using Uno.UI.Xaml.Input;
using Uno.UI.XamlHost.Skia.Wpf;
using Windows.Devices.Input;
using Windows.Graphics.Display;
using Windows.Networking.Connectivity;
using Windows.Storage.Pickers;
using Windows.System.Profile.Internal;
using Windows.UI.Core;
using Windows.UI.Core.Preview;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -68,6 +71,7 @@ static WpfHost()
}

private static bool _extensionsRegistered;
private HostPointerHandler _hostPointerHandler;

internal static void RegisterExtensions()
{
Expand Down Expand Up @@ -126,12 +130,8 @@ void CreateApp(WinUI.ApplicationInitializationCallbackParams _)

WinUI.Application.StartWithArguments(CreateApp);

//TODO:MZ:
//WinUI.Window.InvalidateRender += () =>
//{
// InvalidateOverlays();
// InvalidateVisual();
//};
_hostPointerHandler = new HostPointerHandler(this);
WinUI.Window.Current.Activated += Current_Activated;

WpfApplication.Current.Activated += Current_Activated;
WpfApplication.Current.Deactivated += Current_Deactivated;
Expand All @@ -149,6 +149,32 @@ void CreateApp(WinUI.ApplicationInitializationCallbackParams _)
Loaded += WpfHost_Loaded;
}

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 += InvalidateRender;
XamlRootMap.Register(xamlRoot, this);

// Force initial render
InvalidateRender();
WinUI.Window.Current.Activated -= Current_Activated;
}

private void InvalidateRender()
{
InvalidateOverlays();
InvalidateVisual();
}

private void MainWindow_Closing(object sender, CancelEventArgs e)
{
var manager = SystemNavigationManagerPreview.GetForCurrentView();
Expand Down

0 comments on commit d6f9712

Please sign in to comment.