Skip to content

Commit

Permalink
feat: Various skia updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jul 30, 2020
1 parent 6b9bdb6 commit d7dd9ce
Show file tree
Hide file tree
Showing 84 changed files with 2,878 additions and 1,582 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

Expand All @@ -24,6 +24,10 @@
<ProjectReference Include="..\..\Uno.UWP\Uno.Skia.csproj" />
<ProjectReference Include="..\SamplesApp.Skia\SamplesApp.Skia.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Program.cs" />
</ItemGroup>

<Import Project="..\..\..\build\*.Skia.Gtk.props" />
<Import Project="..\..\..\build\*.Skia.Gtk.targets" />
Expand Down
4 changes: 4 additions & 0 deletions src/SamplesApp/SamplesApp.Skia/SamplesApp.Skia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@

<Import Project="..\SamplesApp.UnitTests.Shared\SamplesApp.UnitTests.Shared.projitems" Label="Shared" />

<ItemGroup>
<Content Update="@(Content)" CopyToOutputDirectory="Always" />
</ItemGroup>

</Project>
52 changes: 52 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/GTK/GtkApplicationExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;

namespace Uno.UI.Runtime.Skia
{
public class GtkApplicationExtension : IApplicationExtension
{
private readonly Windows.UI.Xaml.Application _owner;
private readonly Windows.UI.Xaml.IApplicationEvents _ownerEvents;

public GtkApplicationExtension(object owner)
{
_owner = (Application)owner;
_ownerEvents = (IApplicationEvents)owner;
}

public ApplicationTheme GetDefaultSystemTheme()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return GetWindowsTheme();
}
else
{
return Gtk.Settings.Default.ApplicationPreferDarkTheme ? ApplicationTheme.Dark : ApplicationTheme.Light;
}
}

private static ApplicationTheme GetWindowsTheme()
{
// Not yet working because of theme propagation issue. Uncomment to dynamically select the theme

//var subKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";

//if (Microsoft.Win32.Registry.CurrentUser.OpenSubKey(subKey) is RegistryKey key)
//{
// if (key.GetValue("AppsUseLightTheme") is int useLightTheme)
// {
// return useLightTheme != 0 ? ApplicationTheme.Light : ApplicationTheme.Dark;
// }
//}

return ApplicationTheme.Light;
}
}
}
37 changes: 37 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/GTK/GtkApplicationViewExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Text;
using Windows.UI.ViewManagement;

namespace Uno.UI.Runtime.Skia
{
public class GtkApplicationViewExtension : IApplicationViewExtension
{
private readonly ApplicationView _owner;
private readonly IApplicationViewEvents _ownerEvents;

public GtkApplicationViewExtension(object owner)
{
_owner = (ApplicationView)owner;
_ownerEvents = (IApplicationViewEvents)owner;
}

public string Title
{
get => GtkHost.Window.Title;
set => GtkHost.Window.Title = value;
}

public void ExitFullScreenMode()
{
GtkHost.Window.Unfullscreen();
}

public bool TryEnterFullScreenMode()
{
GtkHost.Window.Fullscreen();
return true;
}
}
}
45 changes: 26 additions & 19 deletions src/Uno.UI.Runtime.Skia.Gtk/GTK/GtkCoreWindowExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Gdk;
using Gtk;
Expand All @@ -21,6 +22,7 @@ public class GtkUIElementPointersSupport : ICoreWindowExtension
{
private readonly CoreWindow _owner;
private ICoreWindowEvents _ownerEvents;
private static int _currentFrameId;

public GtkUIElementPointersSupport(object owner)
{
Expand All @@ -30,7 +32,6 @@ public GtkUIElementPointersSupport(object owner)
GtkHost.Window.AddEvents((int)(
Gdk.EventMask.PointerMotionMask
| EventMask.ButtonPressMask
| EventMask.ScrollMask
| EventMask.SmoothScrollMask
));
GtkHost.Window.MotionNotifyEvent += OnMotionEvent;
Expand All @@ -40,24 +41,30 @@ public GtkUIElementPointersSupport(object owner)
GtkHost.Window.LeaveNotifyEvent += Window_LeaveEvent;
GtkHost.Window.ScrollEvent += Window_ScrollEvent;
}

private static uint GetNextFrameId() => (uint)Interlocked.Increment(ref _currentFrameId);

private void Window_ScrollEvent(object o, ScrollEventArgs args)
{
try
{
_ownerEvents.RaisePointerWheelChanged(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
rawPosition: new Windows.Foundation.Point(args.Event.X, args.Event.Y),
position: new Windows.Foundation.Point(args.Event.X, args.Event.Y),
isInContact: false,
properties: BuildProperties(args.Event)
if (args.Event.Direction == ScrollDirection.Smooth)
{
_ownerEvents.RaisePointerWheelChanged(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
rawPosition: new Windows.Foundation.Point(args.Event.X, args.Event.Y),
position: new Windows.Foundation.Point(args.Event.X, args.Event.Y),
isInContact: false,
properties: BuildProperties(args.Event)
)
)
)
);
);
}
}
catch (Exception e)
{
Expand All @@ -79,7 +86,7 @@ private void Window_LeaveEvent(object o, LeaveNotifyEventArgs args)
_ownerEvents.RaisePointerExited(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
Expand All @@ -104,7 +111,7 @@ private void Window_EnterEvent(object o, EnterNotifyEventArgs args)
_ownerEvents.RaisePointerEntered(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
Expand All @@ -129,7 +136,7 @@ private void Window_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
_ownerEvents.RaisePointerReleased(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
Expand All @@ -154,7 +161,7 @@ private void Window_ButtonPressEvent(object o, ButtonPressEventArgs args)
_ownerEvents.RaisePointerPressed(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
Expand Down Expand Up @@ -196,7 +203,7 @@ private void OnMotionEvent(object o, MotionNotifyEventArgs args)
_ownerEvents.RaisePointerMoved(
new PointerEventArgs(
new Windows.UI.Input.PointerPoint(
frameId: 0,
frameId: GetNextFrameId(),
timestamp: args.Event.Time,
device: PointerDevice.For(PointerDeviceType.Mouse),
pointerId: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/GTK/GtkHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public void Run()
Gtk.Application.Init();

ApiExtensibility.Register(typeof(Windows.UI.Core.ICoreWindowExtension), o => new GtkUIElementPointersSupport(o));
ApiExtensibility.Register(typeof(Windows.UI.ViewManagement.IApplicationViewExtension), o => new GtkApplicationViewExtension(o));
ApiExtensibility.Register(typeof(IApplicationExtension), o => new GtkApplicationExtension(o));

_window = new Gtk.Window("Uno Host");
_window.SetDefaultSize(1024, 800);
Expand Down
34 changes: 28 additions & 6 deletions src/Uno.UI.Runtime.Skia.Gtk/GTK/UnoDrawingArea.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using SkiaSharp;
using Uno.Extensions;
using Uno.Logging;
using WUX = Windows.UI.Xaml;

namespace Uno.UI.Runtime.Skia
Expand All @@ -8,35 +10,55 @@ internal class UnoDrawingArea : Gtk.DrawingArea
{
private SKBitmap bitmap;
private int renderCount;
private int InvalidateRenderCount;

public UnoDrawingArea()
{
WUX.Window.Current.InvalidateRender
+= () =>
{
QueueDrawArea(0, 0, 10000, 1000);
Invalidate();
};
}

private void Invalidate()
=> QueueDrawArea(0, 0, 10000, 10000);

private void Screen_MonitorsChanged(object sender, EventArgs e)
{
UpdateDpi();
Invalidate();
}

private void UpdateDpi()
{
}

protected override bool OnDrawn(Cairo.Context cr)
{
int width, height;

Console.WriteLine($"Render {renderCount++}");
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace))
{
this.Log().Trace($"Render {renderCount++}");
}

var dpi = (Window.Screen?.Resolution ?? 1) / 96.0;

width = (int)AllocatedWidth;
height = (int)AllocatedHeight;

var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
var scaledWidth = (int)(width * dpi);
var scaledHeight = (int)(height * dpi);

var info = new SKImageInfo(scaledWidth, scaledHeight, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

// reset the bitmap if the size has changed
if (bitmap == null || info.Width != bitmap.Width || info.Height != bitmap.Height)
{
bitmap = new SKBitmap(width, height, SKColorType.Rgba8888, SKAlphaType.Premul);
bitmap = new SKBitmap(scaledWidth, scaledHeight, SKColorType.Rgba8888, SKAlphaType.Premul);
}

using (var surface = SKSurface.Create(info, bitmap.GetPixels(out var len)))
using (var surface = SKSurface.Create(info, bitmap.GetPixels(out _)))
{
surface.Canvas.Clear(SKColors.White);

Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/Uno.UI.Runtime.Skia.Gtk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<Copyright>Copyright (C) 2015-2020 nventive inc. - all rights reserved</Copyright>

<PackageId Condition="'$(UNO_UWP_BUILD)'!='true'">Uno.WinUI.Runtime.Skia.Gtk</PackageId>

<RootNamespace>Uno.UI.Runtime.Skia</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,6 +26,7 @@
<Import Project="..\Uno.CrossTargetting.props" />

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="SkiaSharp.Views" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public static class Font
/// Defines the default font to be used when displaying symbols, such as in SymbolIcon.
/// </summary>
public static string SymbolsFont { get; set; } =
#if !__ANDROID__
#if __SKIA__
"ms-appx:///Assets/Fonts/winjs-symbols.ttf#Symbols";
#elif !__ANDROID__
"Symbols";
#else
"ms-appx:///Assets/Fonts/winjs-symbols.ttf#Symbols";
Expand Down
16 changes: 8 additions & 8 deletions src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Windows.UI.Xaml.Controls
#endif
public partial class Image
{
#if false || false || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
#if false || false || NET461 || false || false || false || false
[global::Uno.NotImplemented("NET461")]
public global::Windows.UI.Xaml.Media.Stretch Stretch
{
get
Expand All @@ -21,8 +21,8 @@ public partial class Image
}
}
#endif
#if false || false || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
#if false || false || NET461 || false || false || false
[global::Uno.NotImplemented("NET461")]
public global::Windows.UI.Xaml.Media.ImageSource Source
{
get
Expand Down Expand Up @@ -75,16 +75,16 @@ public partial class Image
typeof(global::Windows.UI.Xaml.Controls.Image),
new FrameworkPropertyMetadata(default(global::Windows.Media.PlayTo.PlayToSource)));
#endif
#if false || false || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
#if false || false || NET461 || false || false || false
[global::Uno.NotImplemented("NET461")]
public static global::Windows.UI.Xaml.DependencyProperty SourceProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Source), typeof(global::Windows.UI.Xaml.Media.ImageSource),
typeof(global::Windows.UI.Xaml.Controls.Image),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Media.ImageSource)));
#endif
#if false || false || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
#if false || false || NET461 || false || false
[global::Uno.NotImplemented("NET461")]
public static global::Windows.UI.Xaml.DependencyProperty StretchProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Stretch), typeof(global::Windows.UI.Xaml.Media.Stretch),
Expand Down
Loading

0 comments on commit d7dd9ce

Please sign in to comment.