Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor WASM input and dom-callbacks to work with multithreading #15849

Merged
merged 13 commits into from
Jun 6, 2024

Conversation

maxkatz6
Copy link
Member

What does the pull request do?

Continuing #15709

Some points about WASM .NET multithreading and Avalonia after this PR:

  1. Pointer/keyboard input now works. For the most part we always assume that all events are handled.
  2. Drag/drop only works in single-threaded mode.
  3. Resizing works again, but very junky with multithreading.
  4. Browser IME is semi-working, but it's not a regression aparently.
  5. Various DOM callbacks are now working in multithreading with this PR.
  6. File dialogs are still broken with multithreading.

Additionally, input handling should be generally faster now on single threaded platform too.

@maxkatz6
Copy link
Member Author

Marking as DRAFT, as I need to double/triple check if anything was broken on .NET 8 single threaded. Will do it tomorrow/after tomorrow.

@@ -8,7 +8,7 @@ require("esbuild").build({
bundle: true,
minify: true,
format: "esm",
target: "es2018",
target: "es2019",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatMap usage requires es2019.
At this point we can bump it a little.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0048702-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 marked this pull request as ready for review May 30, 2024 09:16
@maxkatz6 maxkatz6 requested a review from kekekeks May 30, 2024 09:16
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0048724-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0048753-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@kekekeks kekekeks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general.

We probably need to auto-register options passed to the start method in the locator.

.SetupWithLifetime(lifetime);
});

if (BrowserWindowingPlatform.IsManagedDispatcherEnabled)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that AvaloniaLocator.Current.GetService<BrowserPlatformOptions>()?.PreferManagedThreadDispatcher != false; check will always succeed regardless of the options parameter passed to StartBrowserAppAsync. Only one registered with .With will be used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have AvaloniaLocator.CurrentMutable.Bind<BrowserPlatformOptions>().ToConstant(options); for that case. It's auto-registered.

// TODO: this callback should be <int, int, double>. Revert after next .NET 9 preview.
Action<double, double, double> onSizeChanged);
[JSExport]
public static Task OnSizeChanged(int topLevelId, double width, double height, double dpr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we are supposed to dispatch this synchronously in ST mode, maybe via Dispatcher.Invoke

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -8,6 +10,13 @@ internal static partial class NavigationHelper
[JSImport("NavigationHelper.addBackHandler", AvaloniaModule.MainModuleName)]
public static partial void AddBackHandler([JSMarshalAs<JSType.Function<JSType.Boolean>>] Func<bool> backHandlerCallback);

public static Task<bool> OnBackRequested()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to use dispatcher for managed dispatcher mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used down the lever here and in other services callbacks

Func<JSObject, bool> wheel);
public static Task RedirectInputAsync(int topLevelId, Action<BrowserTopLevelImpl> handler)
{
// TODO consider passing input events through dispatcher or something.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably an outdated comment, since InputHandler uses dispatcher internally when needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea

@maxkatz6 maxkatz6 merged commit f140033 into master Jun 6, 2024
2 of 10 checks passed
@maxkatz6 maxkatz6 deleted the wasm-threading-input branch June 6, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants