This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add avalonia support * only lock around skia flush * addressed review * cleanup * add fallback size if avalonia attempts to render but the window size is 0. read desktop scale after enabling dpi check * fix getting window handle on linux. skip render is size is 0
- Loading branch information
Showing
38 changed files
with
3,095 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Avalonia; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using static Ryujinx.Ava.Ui.Backend.Interop; | ||
|
||
namespace Ryujinx.Ava.Ui.Backend | ||
{ | ||
public abstract class BackendSurface : IDisposable | ||
{ | ||
protected IntPtr Display => _display; | ||
|
||
private IntPtr _display = IntPtr.Zero; | ||
|
||
[DllImport("libX11.so.6")] | ||
public static extern IntPtr XOpenDisplay(IntPtr display); | ||
|
||
[DllImport("libX11.so.6")] | ||
public static extern int XCloseDisplay(IntPtr display); | ||
|
||
private PixelSize _currentSize; | ||
public IntPtr Handle { get; protected set; } | ||
|
||
public bool IsDisposed { get; private set; } | ||
|
||
public BackendSurface(IntPtr handle) | ||
{ | ||
Handle = handle; | ||
|
||
if (OperatingSystem.IsLinux()) | ||
{ | ||
_display = XOpenDisplay(IntPtr.Zero); | ||
} | ||
} | ||
|
||
public PixelSize Size | ||
{ | ||
get | ||
{ | ||
PixelSize size = new PixelSize(); | ||
if (OperatingSystem.IsWindows()) | ||
{ | ||
GetClientRect(Handle, out var rect); | ||
size = new PixelSize(rect.right, rect.bottom); | ||
} | ||
else if (OperatingSystem.IsLinux()) | ||
{ | ||
XWindowAttributes attributes = new XWindowAttributes(); | ||
XGetWindowAttributes(Display, Handle, ref attributes); | ||
|
||
size = new PixelSize(attributes.width, attributes.height); | ||
} | ||
|
||
_currentSize = size; | ||
|
||
return size; | ||
} | ||
} | ||
|
||
public PixelSize CurrentSize => _currentSize; | ||
|
||
public virtual void Dispose() | ||
{ | ||
IsDisposed = true; | ||
|
||
if (_display != IntPtr.Zero) | ||
{ | ||
XCloseDisplay(_display); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using FluentAvalonia.Interop; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Ryujinx.Ava.Ui.Backend | ||
{ | ||
public static class Interop | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct XWindowAttributes | ||
{ | ||
public int x; | ||
public int y; | ||
public int width; | ||
public int height; | ||
public int border_width; | ||
public int depth; | ||
public IntPtr visual; | ||
public IntPtr root; | ||
public int c_class; | ||
public int bit_gravity; | ||
public int win_gravity; | ||
public int backing_store; | ||
public IntPtr backing_planes; | ||
public IntPtr backing_pixel; | ||
public int save_under; | ||
public IntPtr colormap; | ||
public int map_installed; | ||
public int map_state; | ||
public IntPtr all_event_masks; | ||
public IntPtr your_event_mask; | ||
public IntPtr do_not_propagate_mask; | ||
public int override_direct; | ||
public IntPtr screen; | ||
} | ||
|
||
[DllImport("user32.dll")] | ||
public static extern bool GetClientRect(IntPtr hwnd, out RECT lpRect); | ||
|
||
[DllImport("libX11.so.6")] | ||
public static extern int XCloseDisplay(IntPtr display); | ||
|
||
[DllImport("libX11.so.6")] | ||
public static extern int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes); | ||
|
||
[DllImport("libX11.so.6")] | ||
public static extern IntPtr XOpenDisplay(IntPtr display); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Avalonia; | ||
using Avalonia.Skia; | ||
using Ryujinx.Ava.Ui.Vulkan; | ||
using Ryujinx.Ava.Ui.Backend.Vulkan; | ||
|
||
namespace Ryujinx.Ava.Ui.Backend | ||
{ | ||
public static class SkiaGpuFactory | ||
{ | ||
public static ISkiaGpu CreateVulkanGpu() | ||
{ | ||
var skiaOptions = AvaloniaLocator.Current.GetService<SkiaOptions>() ?? new SkiaOptions(); | ||
var platformInterface = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>(); | ||
if (platformInterface == null) | ||
{ | ||
VulkanPlatformInterface.TryInitialize(); | ||
} | ||
var gpu = new VulkanSkiaGpu(skiaOptions.MaxGpuResourceSizeBytes); | ||
AvaloniaLocator.CurrentMutable.Bind<VulkanSkiaGpu>().ToConstant(gpu); | ||
return gpu; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using Silk.NET.Vulkan; | ||
|
||
namespace Ryujinx.Ava.Ui.Vulkan | ||
{ | ||
public static class ResultExtensions | ||
{ | ||
public static void ThrowOnError(this Result result) | ||
{ | ||
if (result != Result.Success) throw new Exception($"Unexpected API error \"{result}\"."); | ||
} | ||
} | ||
} |
Oops, something went wrong.