Skip to content

Commit

Permalink
Fix Browser issues on .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed Feb 15, 2024
1 parent 29aa7fb commit 11d51fc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
15 changes: 9 additions & 6 deletions samples/ControlCatalog.Browser/EmbedSample.Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func
}
else
{
var defaultHandle = (JSObjectControlHandle)createDefault();
var parentContainer = (JSObjectControlHandle)createDefault();

_ = JSHost.ImportAsync("embed.js", "./embed.js").ContinueWith(_ =>
{
EmbedInterop.AddAppButton(defaultHandle.Object);
}, TaskScheduler.FromCurrentSynchronizationContext());
AddButton(parentContainer.Object);

return parentContainer;

return defaultHandle;
static async void AddButton(JSObject parent)
{
await JSHost.ImportAsync("embed.js", "./embed.js");
EmbedInterop.AddAppButton(parent);
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/Browser/Avalonia.Browser/Avalonia.Browser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<Pack>true</Pack>
<PackagePath>build/;buildTransitive/</PackagePath>
</Content>
<Content Include="build\interop.js">
<Pack>true</Pack>
<PackagePath>build/interop.js;buildTransitive/interop.js</PackagePath>
</Content>
<Content Include="staticwebassets/**/*.*">
<Pack>true</Pack>
<PackagePath>staticwebassets/</PackagePath>
Expand Down
6 changes: 0 additions & 6 deletions src/Browser/Avalonia.Browser/Interop/CanvasHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ internal record GLInfo(int ContextId, uint FboId, int Stencils, int Samples, int

internal static partial class CanvasHelper
{

[DllImport("libSkiaSharp", CallingConvention = CallingConvention.Cdecl)]
static extern JSObject InterceptGLObject();

public static GLInfo InitialiseGL(JSObject canvas, Action renderFrameCallback)
{
InterceptGLObject();

var info = InitGL(canvas, canvas.GetPropertyAsString("id")!, renderFrameCallback);

var glInfo = new GLInfo(
Expand Down
15 changes: 9 additions & 6 deletions src/Browser/Avalonia.Browser/build/Avalonia.Browser.targets
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project>
<PropertyGroup>
<EmccExtraLDFlags>$(EmccExtraLDFlags) --js-library="$(MSBuildThisFileDirectory)/interop.js"</EmccExtraLDFlags>
<EmccFlags>$(EmccFlags) -sERROR_ON_UNDEFINED_SYMBOLS=0</EmccFlags>
<EmccFlags Condition="'$(AvaloniaAllowWebGl2)' == 'true'">$(EmccFlags) -sUSE_WEBGL2=1 -sMAX_WEBGL_VERSION=2 -lGL </EmccFlags>
</PropertyGroup>

<ItemGroup>
<!-- So we can access Emscripten APIs -->
<EmccExportedRuntimeMethod Include="GL" />
</ItemGroup>

<!-- Fallback for applications without StaticWebAssetsEnabled (legacy WASM SDK) -->
<ItemGroup Condition="'$(ShouldIncludeAvaloniaLegacyAssets)' == 'True'">
<WasmExtraFilesToDeploy Condition="'$(WasmRuntimeAssetsLocation)' == ''" Include="$(MSBuildThisFileDirectory)/../staticwebassets/**/*.*" />
Expand All @@ -16,12 +19,12 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkVersion)' != '' and '$(ShouldIncludeNativeSkiaSharp)' == 'True'">
<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)/3.1.34/mt/*.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0')) and '$(WasmEnableThreads)' == 'True'" />
<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)/3.1.34/st/*.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0')) and '$(WasmEnableThreads)' != 'True'" />
<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)/3.1.34/mt/*.a" Condition="'$(WasmEnableThreads)' == 'True'" />
<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)/3.1.34/st/*.a" Condition="'$(WasmEnableThreads)' != 'True'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkVersion)' != '' and '$(ShouldIncludeNativeHarfBuzzSharp)' == 'True'">
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)/3.1.34/st/*.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0')) and '$(WasmEnableThreads)' != 'True'" />
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)/3.1.34/mt/*.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0')) and '$(WasmEnableThreads)' == 'True'" />
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)/3.1.34/st/*.a" Condition="'$(WasmEnableThreads)' != 'True'" />
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)/3.1.34/mt/*.a" Condition="'$(WasmEnableThreads)' == 'True'" />
</ItemGroup>
</Project>
13 changes: 0 additions & 13 deletions src/Browser/Avalonia.Browser/build/interop.js

This file was deleted.

10 changes: 8 additions & 2 deletions src/Browser/Avalonia.Browser/webapp/modules/avalonia/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ type CanvasElement = {
Canvas: Canvas | undefined;
} & HTMLCanvasElement;

function getGL(): any {
const self = globalThis as any;
const module = self.Module ?? self.getDotnetRuntime(0)?.Module;
return module?.GL ?? self.AvaloniaGL ?? self.SkiaSharpGL;
}

export class Canvas {
static elements: Map<string, HTMLCanvasElement>;

Expand Down Expand Up @@ -60,7 +66,7 @@ export class Canvas {
return;
}

const GL = (globalThis as any).AvaloniaGL;
const GL = getGL();

// make current
GL.makeContextCurrent(ctx);
Expand Down Expand Up @@ -179,7 +185,7 @@ export class Canvas {
renderViaOffscreenBackBuffer: 1
};

const GL = (globalThis as any).AvaloniaGL;
const GL = getGL();

let ctx: WebGLRenderingContext = GL.createContext(htmlCanvas, contextAttributes);

Expand Down

0 comments on commit 11d51fc

Please sign in to comment.