From af825611b4f9b7f68bd7ed9eb2c132b39df98d0b Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 18 Sep 2023 23:07:39 +0200 Subject: [PATCH 1/7] Add support for multi-thread wasm blazor --- .../buildTransitive/HarfBuzzSharp.targets | 20 ++++++++++++----- .../buildTransitive/SkiaSharp.targets | 22 ++++++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets index 475d803e14..bc83cea8db 100644 --- a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets +++ b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets @@ -1,18 +1,28 @@ + + + True + + - + - + true - + + - - + + + + + + \ No newline at end of file diff --git a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets index 8e40600058..000a29d989 100644 --- a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets +++ b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets @@ -1,10 +1,15 @@ + + + True + + - + - + @@ -12,14 +17,19 @@ - + true $(EmccExtraLDFlags) -s USE_WEBGL2=1 - + + - - + + + + + + \ No newline at end of file From 911fe98463435ecf403437970eaab588f6d77a0a Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 1 Mar 2024 21:31:55 +0200 Subject: [PATCH 2/7] Order the folder name parts (#2774) --- scripts/azure-templates-stages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/azure-templates-stages.yml b/scripts/azure-templates-stages.yml index b39f34db49..12bc4f670c 100644 --- a/scripts/azure-templates-stages.yml +++ b/scripts/azure-templates-stages.yml @@ -404,11 +404,11 @@ stages: - 3.1.34: displayName: '3.1.34_SIMD' version: 3.1.34 - features: _wasmeh,simd,st + features: _wasmeh,st,simd - 3.1.34: displayName: '3.1.34_SIMD_Threading' version: 3.1.34 - features: _wasmeh,simd,mt + features: _wasmeh,mt,simd - ${{ if ne(parameters.buildPipelineType, 'tests') }}: - stage: native From 68ca253e77afaa49f9cc2fa161d3aaca28ad1674 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 1 Mar 2024 21:59:54 +0200 Subject: [PATCH 3/7] this --- scripts/azure-templates-stages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/azure-templates-stages.yml b/scripts/azure-templates-stages.yml index 12bc4f670c..392b3e4f86 100644 --- a/scripts/azure-templates-stages.yml +++ b/scripts/azure-templates-stages.yml @@ -382,7 +382,7 @@ stages: - 3.1.12: displayName: '3.1.12_SIMD' version: 3.1.12 - features: simd + features: st,simd - 3.1.12: displayName: '3.1.12_Threading' version: 3.1.12 From 1268755d8243f3b2a97fba6aea7336451ce9a658 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 1 Mar 2024 22:34:45 +0200 Subject: [PATCH 4/7] handle the matrix of st/mt and /simd/non-simd --- .../buildTransitive/HarfBuzzSharp.targets | 14 +++++++++----- .../buildTransitive/SkiaSharp.targets | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets index bc83cea8db..a1571f3341 100644 --- a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets +++ b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets @@ -13,16 +13,20 @@ true + + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st + + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_HarfBuzzSharpNativeBinaryType),simd + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_HarfBuzzSharpNativeBinaryType) - + - - + - - + \ No newline at end of file diff --git a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets index 000a29d989..aeb99ccb2e 100644 --- a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets +++ b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets @@ -20,16 +20,20 @@ true $(EmccExtraLDFlags) -s USE_WEBGL2=1 + + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st + + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_SkiaSharpNativeBinaryType),simd + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_SkiaSharpNativeBinaryType) - + - - + - - + \ No newline at end of file From 15897ac4df6e70b8f7ff9ac606381acfdaceb55f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Oct 2024 19:58:15 +0800 Subject: [PATCH 5/7] Merge remote-tracking branch 'origin/main' into dev/mt-main # Conflicts: # scripts/azure-templates-stages.yml --- .../buildTransitive/HarfBuzzSharp.targets | 2 +- binding/IncludeNativeAssets.HarfBuzzSharp.targets | 2 +- binding/IncludeNativeAssets.SkiaSharp.targets | 2 +- .../buildTransitive/SkiaSharp.targets | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets index 65059aefd6..320dc7b89b 100644 --- a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets +++ b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets @@ -28,7 +28,7 @@ - + \ No newline at end of file diff --git a/binding/IncludeNativeAssets.HarfBuzzSharp.targets b/binding/IncludeNativeAssets.HarfBuzzSharp.targets index 97bb5c7fd1..d28d04fd51 100644 --- a/binding/IncludeNativeAssets.HarfBuzzSharp.targets +++ b/binding/IncludeNativeAssets.HarfBuzzSharp.targets @@ -69,7 +69,7 @@ - + \ No newline at end of file diff --git a/binding/IncludeNativeAssets.SkiaSharp.targets b/binding/IncludeNativeAssets.SkiaSharp.targets index 4e5706fdcf..0a692080ce 100644 --- a/binding/IncludeNativeAssets.SkiaSharp.targets +++ b/binding/IncludeNativeAssets.SkiaSharp.targets @@ -74,7 +74,7 @@ - + \ No newline at end of file diff --git a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets index b72702eafc..9ab1495212 100644 --- a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets +++ b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets @@ -37,7 +37,7 @@ - + \ No newline at end of file From cad4cb1f7ddaafecd7ae529c5b0fa9a42195dd9f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Oct 2024 21:21:28 +0800 Subject: [PATCH 6/7] wasm things --- .../buildTransitive/HarfBuzzSharp.targets | 6 +++--- .../buildTransitive/SkiaSharp.targets | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets index 320dc7b89b..7198786ae6 100644 --- a/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets +++ b/binding/HarfBuzzSharp.NativeAssets.WebAssembly/buildTransitive/HarfBuzzSharp.targets @@ -10,8 +10,8 @@ - - + + true <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt @@ -20,7 +20,7 @@ <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_HarfBuzzSharpNativeBinaryType),simd <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_HarfBuzzSharpNativeBinaryType) - + diff --git a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets index 9ab1495212..62e8baacb5 100644 --- a/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets +++ b/binding/SkiaSharp.NativeAssets.WebAssembly/buildTransitive/SkiaSharp.targets @@ -18,8 +18,8 @@ - - + + true $(EmccExtraLDFlags) -s USE_WEBGL2=1 @@ -29,7 +29,7 @@ <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_SkiaSharpNativeBinaryType),simd <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_SkiaSharpNativeBinaryType) - + From 5d4d9f42d5fa7695eef2e4b36dd8605cabf857fd Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Oct 2024 23:39:45 +0800 Subject: [PATCH 7/7] Added a sample --- .../IncludeNativeAssets.HarfBuzzSharp.targets | 14 ++++--- binding/IncludeNativeAssets.SkiaSharp.targets | 15 +++++--- .../BrowserWebAssembly/SkiaSharpSample.sln | 31 +++++++++++++++ .../SkiaSharpSample/Program.cs | 38 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 4 ++ .../Properties/launchSettings.json | 13 +++++++ .../SkiaSharpSample/SkiaSharpSample.csproj | 15 ++++++++ .../runtimeconfig.template.json | 10 +++++ .../SkiaSharpSample/wwwroot/index.html | 16 ++++++++ .../SkiaSharpSample/wwwroot/main.js | 22 +++++++++++ 10 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample.sln create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/Program.cs create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/AssemblyInfo.cs create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/launchSettings.json create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/SkiaSharpSample.csproj create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/runtimeconfig.template.json create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/index.html create mode 100644 samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/main.js diff --git a/binding/IncludeNativeAssets.HarfBuzzSharp.targets b/binding/IncludeNativeAssets.HarfBuzzSharp.targets index d28d04fd51..075c0b61a1 100644 --- a/binding/IncludeNativeAssets.HarfBuzzSharp.targets +++ b/binding/IncludeNativeAssets.HarfBuzzSharp.targets @@ -62,14 +62,18 @@ - + true + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_HarfBuzzSharpNativeBinaryType),simd + <_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_HarfBuzzSharpNativeBinaryType) - + - - - + + + \ No newline at end of file diff --git a/binding/IncludeNativeAssets.SkiaSharp.targets b/binding/IncludeNativeAssets.SkiaSharp.targets index 0a692080ce..4596f8942d 100644 --- a/binding/IncludeNativeAssets.SkiaSharp.targets +++ b/binding/IncludeNativeAssets.SkiaSharp.targets @@ -66,15 +66,20 @@ - + true $(EmccExtraLDFlags) -s USE_WEBGL2=1 + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' == 'True'">$(_SkiaSharpNativeBinaryType),simd + <_SkiaSharpNativeBinaryType Condition="'$(WasmEnableSIMD)' != 'True'">$(_SkiaSharpNativeBinaryType) - + - - - + + + + \ No newline at end of file diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample.sln b/samples/Basic/BrowserWebAssembly/SkiaSharpSample.sln new file mode 100644 index 0000000000..a96eff0ec0 --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample.sln @@ -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 diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Program.cs b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Program.cs new file mode 100644 index 0000000000..101c717dda --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Program.cs @@ -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] Span buffer); +} diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/AssemblyInfo.cs b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..9ad9b578f2 --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/AssemblyInfo.cs @@ -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")] diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/launchSettings.json b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/launchSettings.json new file mode 100644 index 0000000000..558768dae5 --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/Properties/launchSettings.json @@ -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}", + } + } +} diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/SkiaSharpSample.csproj b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/SkiaSharpSample.csproj new file mode 100644 index 0000000000..5a385b99e4 --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/SkiaSharpSample.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + true + enable + + + + + + + + + diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/runtimeconfig.template.json b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/runtimeconfig.template.json new file mode 100644 index 0000000000..b96a94320b --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/runtimeconfig.template.json @@ -0,0 +1,10 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "host": "browser" + } + ] + } +} \ No newline at end of file diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/index.html b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/index.html new file mode 100644 index 0000000000..5028f8faea --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/index.html @@ -0,0 +1,16 @@ + + + + + SkiaSharpSample + + + + + + +

SkiaSharpSample

+ + + + diff --git a/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/main.js b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/main.js new file mode 100644 index 0000000000..7133e5df6b --- /dev/null +++ b/samples/Basic/BrowserWebAssembly/SkiaSharpSample/wwwroot/main.js @@ -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();