-
Notifications
You must be signed in to change notification settings - Fork 548
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
Add support for multi-thread and/or SIMD WebAssembly #2620
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
af82561
Add support for multi-thread wasm blazor
mattleibow 911fe98
Order the folder name parts (#2774)
mattleibow 68ca253
this
mattleibow 1268755
handle the matrix of st/mt and /simd/non-simd
mattleibow 4f0bd19
Merge branch 'main' into dev/mt-main
mattleibow 917c987
Merge remote-tracking branch 'origin/main' into dev/mt-main
mattleibow 15897ac
Merge remote-tracking branch 'origin/main' into dev/mt-main
mattleibow cad4cb1
wasm things
mattleibow 5d4d9f4
Added a sample
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 22 additions & 7 deletions
29
binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets
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 |
---|---|---|
@@ -1,19 +1,34 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<!-- if ShouldIncludeNativeHarfBuzzSharp == False then don't include the native libHarfBuzzSharp --> | ||
<PropertyGroup> | ||
<ShouldIncludeNativeHarfBuzzSharp Condition=" '$(ShouldIncludeNativeHarfBuzzSharp)' == '' ">True</ShouldIncludeNativeHarfBuzzSharp> | ||
</PropertyGroup> | ||
|
||
<!-- If this is an UNO Platform app --> | ||
<ItemGroup Condition="'$(IsUnoHead)' == 'True' and '$(UnoRuntimeIdentifier)' == 'WebAssembly'"> | ||
<ItemGroup Condition="'$(IsUnoHead)' == 'True' and '$(UnoRuntimeIdentifier)' == 'WebAssembly' and '$(ShouldIncludeNativeHarfBuzzSharp)' == 'True'"> | ||
<Content Include="@(HarfBuzzSharpStaticLibrary)" Visible="false" /> | ||
</ItemGroup> | ||
|
||
<!-- If this is a ASP.NET Blazor web assembly app --> | ||
<PropertyGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'"> | ||
<!-- If this is a .NET web assembly app --> | ||
<PropertyGroup Condition="('$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' or '$(UsingMicrosoftNETSdkWebAssembly)' == 'true') and '$(ShouldIncludeNativeHarfBuzzSharp)' == 'True'"> | ||
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">true</WasmBuildNative> | ||
<!-- Pick the threading type: 'mt' for multi-threading or 'st' for single-threading --> | ||
<_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt</_HarfBuzzSharpNativeBinaryType> | ||
<_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st</_HarfBuzzSharpNativeBinaryType> | ||
<!-- Pick the SIMD support: 'simd' for supported or '' for not-supported --> | ||
<_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_HarfBuzzSharpNativeBinaryType),simd</_HarfBuzzSharpNativeBinaryType> | ||
<_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_HarfBuzzSharpNativeBinaryType)</_HarfBuzzSharpNativeBinaryType> | ||
</PropertyGroup> | ||
<ItemGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' and '$(TargetFrameworkVersion)' != ''"> | ||
<ItemGroup Condition="('$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' or '$(UsingMicrosoftNETSdkWebAssembly)' == 'true') and '$(TargetFrameworkVersion)' != '' and '$(ShouldIncludeNativeHarfBuzzSharp)' == 'True'"> | ||
<!-- net6.0 (only has st and non-simd) --> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\2.0.23\*.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0'))" /> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.12\st\*.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0'))" /> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.34\st\*.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '8.0'))" /> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.34\st\*.a" Condition="$([MSBuild]::VersionGreaterThan($(TargetFrameworkVersion), '8.0'))" /> | ||
<!-- net7.0 --> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.12\$(_HarfBuzzSharpNativeBinaryType)\*.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0'))" /> | ||
<!-- net8.0 --> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.34\$(_HarfBuzzSharpNativeBinaryType)\*.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '8.0'))" /> | ||
<!-- net9.0+ --> | ||
<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\3.1.56\$(_HarfBuzzSharpNativeBinaryType)\*.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0'))" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,31 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31717.149 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharpSample", "SkiaSharpSample\SkiaSharpSample.csproj", "{DB5BC6AE-C110-4CA0-9E1E-0328E29989EB}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp", "..\..\..\binding\SkiaSharp\SkiaSharp.csproj", "{8073311E-E158-4608-8479-512B711C0812}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DB5BC6AE-C110-4CA0-9E1E-0328E29989EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DB5BC6AE-C110-4CA0-9E1E-0328E29989EB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DB5BC6AE-C110-4CA0-9E1E-0328E29989EB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DB5BC6AE-C110-4CA0-9E1E-0328E29989EB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8073311E-E158-4608-8479-512B711C0812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8073311E-E158-4608-8479-512B711C0812}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8073311E-E158-4608-8479-512B711C0812}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8073311E-E158-4608-8479-512B711C0812}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {66F81B5B-452E-48B0-A360-017D6840BBD2} | ||
EndGlobalSection | ||
EndGlobal |
38 changes: 38 additions & 0 deletions
38
samples/Basic/BrowserWebAssembly/SkiaSharpSample/Program.cs
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,38 @@ | ||
using System.Runtime.InteropServices.JavaScript; | ||
using SkiaSharp; | ||
|
||
Console.WriteLine("Hello, Browser!"); | ||
Console.WriteLine("Your platform color type is " + SKImageInfo.PlatformColorType); | ||
|
||
// crate a surface | ||
var info = new SKImageInfo(256, 256); | ||
using var bitmap = new SKBitmap(info); | ||
|
||
// the the canvas and properties | ||
using var canvas = new SKCanvas(bitmap); | ||
|
||
// make sure the canvas is blank | ||
canvas.Clear(SKColors.White); | ||
|
||
// draw some text | ||
using var paint = new SKPaint | ||
{ | ||
Color = SKColors.Black, | ||
IsAntialias = true, | ||
Style = SKPaintStyle.Fill | ||
}; | ||
using var font = new SKFont | ||
{ | ||
Size = 24 | ||
}; | ||
var coord = new SKPoint(info.Width / 2, (info.Height + font.Size) / 2); | ||
canvas.DrawText("SkiaSharp", coord, SKTextAlign.Center, font, paint); | ||
|
||
// render the image | ||
Renderer.Render(info.Width, info.Height, bitmap.GetPixelSpan()); | ||
|
||
partial class Renderer | ||
{ | ||
[JSImport("renderer.render", "main.js")] | ||
internal static partial void Render(int width, int height, [JSMarshalAs<JSType.MemoryView>] Span<byte> buffer); | ||
} |
4 changes: 4 additions & 0 deletions
4
samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/AssemblyInfo.cs
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,4 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] |
13 changes: 13 additions & 0 deletions
13
samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/launchSettings.json
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 @@ | ||
{ | ||
"profiles": { | ||
"SkiaSharpSample": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:7184;http://localhost:5264", | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
samples/Basic/BrowserWebAssembly/SkiaSharpSample/SkiaSharpSample.csproj
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\binding\SkiaSharp\SkiaSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\..\..\binding\IncludeNativeAssets.SkiaSharp.targets" /> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
samples/Basic/BrowserWebAssembly/SkiaSharpSample/runtimeconfig.template.json
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,10 @@ | ||
{ | ||
"wasmHostProperties": { | ||
"perHostConfig": [ | ||
{ | ||
"name": "browser", | ||
"host": "browser" | ||
} | ||
] | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/index.html
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,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>SkiaSharpSample</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h1>SkiaSharpSample</h1> | ||
<canvas id="surface" width="256" height="256"></canvas> | ||
</body> | ||
|
||
</html> |
22 changes: 22 additions & 0 deletions
22
samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/main.js
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,22 @@ | ||
import { dotnet } from './_framework/dotnet.js' | ||
|
||
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet | ||
.create(); | ||
|
||
setModuleImports('main.js', { | ||
renderer: { | ||
render: (width, height, buffer) => { | ||
const surface = document.getElementById("surface"); | ||
const ctx = surface.getContext('2d'); | ||
const clamped = new Uint8ClampedArray(buffer.slice()); | ||
const image = new ImageData(clamped, width, height); | ||
ctx.putImageData(image, 0, 0); | ||
surface.style = ""; | ||
} | ||
} | ||
}); | ||
|
||
const config = getConfig(); | ||
const exports = await getAssemblyExports(config.mainAssemblyName); | ||
|
||
await dotnet.run(); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to me: I see Uno has
-s OFFSCREEN_FRAMEBUFFER=1
in the flags, so I am wondering if we need that too for Blazor (I was not able to test before since this feature did not exist yet). However, this probably means it is actually needed so maybe I need to check that as well.