Replies: 4 comments 8 replies
-
@maxkatz6 @kekekeks Because I saw that you were designing a new Interop interface before, I apologize if I am disturbing you by this mentioning. |
Beta Was this translation helpful? Give feedback.
-
The interop mechanism used by Avalonia is needed to avoid airspace problems. As of WPF, it can only interop with externally provided DX9 texture which has various synchronization problems. Avalonia interop API is mostly the same as WPF one, but provides synchronization primitives (dxgi mutex / vulkan semaphore) and interop mechanism negotiation since Avalonia can run on top of 4 different graphics APIs depending on the platform and configuration. If you want to render into a native view like with maui, you can use NativeControlHost and provide your own native view, but you wont be able to have avalonia content on top of the interop area (the same problem as with WPF) |
Beta Was this translation helpful? Give feedback.
-
I found that the btw, related topic: https://learn.microsoft.com/en-us/windows/win32/directcomp/directcomposition-portal |
Beta Was this translation helpful? Give feedback.
-
Thanks for replying @kekekeks , I just combine my replies here. After I posted this, I thought about it and realized that yes, Avalonia indeed cannot solve the problem using this method. There are only two possible solutions:
This approach should be the most developer-friendly and compatible with the existing Avalonia backends, while also solving the problem of simulating the Swapchain. |
Beta Was this translation helpful? Give feedback.
-
According to the Evergine integration process with MAUI, you can use the built-in
View (ViewHandler)
base class provided by MAUI. Override itsCreatePlatformView
method and return theSurfaceView
required for different platforms. In this method, you can initialize your own 3D rendering logic by creating the hwnd or other platform-specific surface parameters needed for window creation. In this way, even the swapchain initialization is handled by developers themselfs, and there is no need for the UI framework to provide a base class and manage it.Windows:
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/Windows/EvergineViewHandler.Windows.cs#L38-L48
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/Windows/EvergineViewHandler.Windows.cs#L103
Android:
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/Android/EvergineViewHandler.Android.cs#L76-L79
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/Android/EvergineViewHandler.Android.cs#L50
iOS:
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/iOS/EvergineViewHandler.iOS.cs#L30-L33
https://github.com/EvergineTeam/EverSneaks/blob/612b950cc3cad05709b28771b4938fa3b98bd5e0/EverSneaks.MAUI/Platforms/iOS/EvergineViewHandler.iOS.cs#L65
In the underlying layers of MAUI, on Windows, the created Surface is actually a WinUI
SwapchainPanel
(https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.swapchainpanel?view=winrt-22621
and demos:
https://github.com/microsoftarchive/msdn-code-gallery-microsoft/tree/master/Official%20Windows%20Platform%20Sample/XAML%20SwapChainPanel%20DirectX%20interop%20sample).
On mobile platforms,
CreatePlatformView
itself can directly return the system-provided Surface, which is a surface supported by the system for composition, so no special handling is required. MAUI on Windows should also use Milcore (Windows) for composition, similar to how WPF uses it. I haven't delved into the specific details.Therefore, if you want to initialize your own 3D rendering, you just need to add in XAML, and then initialize and return the
SurfaceView
for different platforms in your MyViewHandler.I personally think this approach is elegant, and Avalonia doesn't need to provide mechanisms like swapchain, which greatly reduces the chances of introducing bugs.
According to this logic, it seems that
ServerCompositor
needs significant changes (or maybe the current architecture already has a similar mechanism that I haven't thoroughly studied). Additionally, Here is the rendering process for this mechanism in WPF:Milcore (MIL-Media Integration Layer) is responsible for communication between WPF and DirectX. It consists of two main components: the Composition Engine and the Render Engine. The Composition Engine is responsible for creating the Composition Tree, while the Render Engine converts the Composition Tree into triangles that DirectX can recognize and notifies DirectX to perform rendering.
Actually, the Swapchain provided by Avalonia currently resembles such a mechanism. However, the integration process described above is more flexible and elegant (as seen in the Evergine's MAUI integration link). The previous Interop mechanism was extremely complex and almost impossible for developers who are not familiar with rendering to integrate. The MAUI integration approach offered by Evergine simplifies the entire process, making it more accessible for developers.
Beta Was this translation helpful? Give feedback.
All reactions