-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multi-thread and/or SIMD WebAssembly (#2620)
* Add support for multi-thread wasm blazor * Order the folder name parts (#2774) * this * handle the matrix of st/mt and /simd/non-simd * Merge remote-tracking branch 'origin/main' into dev/mt-main # Conflicts: # scripts/azure-templates-stages.yml * wasm things * Added a sample
- Loading branch information
1 parent
44d6780
commit 9bea7b2
Showing
13 changed files
with
217 additions
and
29 deletions.
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