Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions binding/IncludeNativeAssets.HarfBuzzSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@
<Content Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libHarfBuzzSharp.a\*\$(_HarfBuzzSharpNativeBinaryType)\*.a" Visible="false" />
</ItemGroup>

<!-- Uno 6.x single-project browser-wasm (Skia renderer) — see the SkiaSharp targets for
the rationale. Uno links the native through @(HarfBuzzSharpStaticLibrary). -->
<!-- Dedicated property — see the SkiaSharp targets for why _HarfBuzzSharpNativeBinaryType
cannot be reused here. Uno WASM is always SIMD. -->
<!-- Unconditional — see the SkiaSharp targets for the rationale. -->
<PropertyGroup>
<_HarfBuzzSharpUnoWasmBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt</_HarfBuzzSharpUnoWasmBinaryType>
<_HarfBuzzSharpUnoWasmBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st</_HarfBuzzSharpUnoWasmBinaryType>
<_HarfBuzzSharpUnoWasmBinaryType>$(_HarfBuzzSharpUnoWasmBinaryType),simd</_HarfBuzzSharpUnoWasmBinaryType>
</PropertyGroup>
<ItemGroup Condition="'$(IsUnoHead)' == 'True' and '$(UnoRuntimeIdentifier)' == '' and '$(RuntimeIdentifier)' == 'browser-wasm' and '$(TargetFrameworkVersion)' != ''">
<HarfBuzzSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libHarfBuzzSharp.a\3.1.34\$(_HarfBuzzSharpUnoWasmBinaryType)\libHarfBuzzSharp.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '8.0'))" />
<HarfBuzzSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libHarfBuzzSharp.a\3.1.56\$(_HarfBuzzSharpUnoWasmBinaryType)\libHarfBuzzSharp.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0')) and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '11.0'))" />
<HarfBuzzSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libHarfBuzzSharp.a\5.0.6\$(_HarfBuzzSharpUnoWasmBinaryType)\libHarfBuzzSharp.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '11.0'))" />
</ItemGroup>

<PropertyGroup Condition="('$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' or '$(UsingMicrosoftNETSdkWebAssembly)' == 'true')">
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">true</WasmBuildNative>
<_HarfBuzzSharpNativeBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt</_HarfBuzzSharpNativeBinaryType>
Expand Down
23 changes: 23 additions & 0 deletions binding/IncludeNativeAssets.SkiaSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@
<WasmShellExtraEmccFlags Condition="'$(WasmShellEnableThreads)'=='True'" Include="-s OFFSCREEN_FRAMEBUFFER=1" />
</ItemGroup>

<!-- Uno 6.x single-project browser-wasm (Skia renderer). Newer Uno no longer sets
UnoRuntimeIdentifier=WebAssembly (it uses UnoUIRuntimeIdentifier=Skia), so the block
above never matches. Uno's Skia WASM targets link the native through the
@(SkiaSharpStaticLibrary) item, so populate it from the in-tree native output. -->
<!-- Use a dedicated property (not _SkiaSharpNativeBinaryType): Uno also sets
UsingMicrosoftNETSdkWebAssembly=true, so the block below recomputes that shared
property (as 'st', since Uno sets WasmEnableSIMD only after this import) and would
clobber our value. The Uno WASM runtime is always SIMD, so append it unconditionally. -->
<!-- Unconditional: IsUnoHead/RuntimeIdentifier are not yet set where this file is imported
(property pass), while the ItemGroup below is guarded and evaluated later with final
values. The property is only consumed by that guarded ItemGroup, so computing it
everywhere is harmless. Uno WASM is always single-thread + SIMD for this catalog. -->
<PropertyGroup>
<_SkiaSharpUnoWasmBinaryType Condition="'$(WasmEnableThreads)' == 'True'">mt</_SkiaSharpUnoWasmBinaryType>
<_SkiaSharpUnoWasmBinaryType Condition="'$(WasmEnableThreads)' != 'True'">st</_SkiaSharpUnoWasmBinaryType>
<_SkiaSharpUnoWasmBinaryType>$(_SkiaSharpUnoWasmBinaryType),simd</_SkiaSharpUnoWasmBinaryType>
</PropertyGroup>
<ItemGroup Condition="'$(IsUnoHead)' == 'True' and '$(UnoRuntimeIdentifier)' == '' and '$(RuntimeIdentifier)' == 'browser-wasm' and '$(TargetFrameworkVersion)' != ''">
<SkiaSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libSkiaSharp.a\3.1.34\$(_SkiaSharpUnoWasmBinaryType)\libSkiaSharp.a" Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '8.0'))" />
<SkiaSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libSkiaSharp.a\3.1.56\$(_SkiaSharpUnoWasmBinaryType)\libSkiaSharp.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0')) and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '11.0'))" />
<SkiaSharpStaticLibrary Include="$(MSBuildThisFileDirectory)..\output\native\wasm\libSkiaSharp.a\5.0.6\$(_SkiaSharpUnoWasmBinaryType)\libSkiaSharp.a" Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '11.0'))" />
</ItemGroup>

<PropertyGroup Condition="('$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' or '$(UsingMicrosoftNETSdkWebAssembly)' == 'true')">
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">true</WasmBuildNative>
<EmccExtraLDFlags>$(EmccExtraLDFlags) -s USE_WEBGL2=1</EmccExtraLDFlags>
Expand Down
4 changes: 4 additions & 0 deletions binding/SkiaSharp.Resources/ResourcesApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
using sk_manageddrawable_t = System.IntPtr;
using sk_managedtracememorydump_t = System.IntPtr;
using sk_maskfilter_t = System.IntPtr;
using sk_mesh_index_buffer_t = System.IntPtr;
using sk_mesh_t = System.IntPtr;
using sk_mesh_vertex_buffer_t = System.IntPtr;
using sk_meshspecification_t = System.IntPtr;
using sk_nodraw_canvas_t = System.IntPtr;
using sk_nvrefcnt_t = System.IntPtr;
using sk_nway_canvas_t = System.IntPtr;
Expand Down
4 changes: 4 additions & 0 deletions binding/SkiaSharp.SceneGraph/SceneGraphApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
using sk_manageddrawable_t = System.IntPtr;
using sk_managedtracememorydump_t = System.IntPtr;
using sk_maskfilter_t = System.IntPtr;
using sk_mesh_index_buffer_t = System.IntPtr;
using sk_mesh_t = System.IntPtr;
using sk_mesh_vertex_buffer_t = System.IntPtr;
using sk_meshspecification_t = System.IntPtr;
using sk_nodraw_canvas_t = System.IntPtr;
using sk_nvrefcnt_t = System.IntPtr;
using sk_nway_canvas_t = System.IntPtr;
Expand Down
4 changes: 4 additions & 0 deletions binding/SkiaSharp.Skottie/SkottieApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
using sk_manageddrawable_t = System.IntPtr;
using sk_managedtracememorydump_t = System.IntPtr;
using sk_maskfilter_t = System.IntPtr;
using sk_mesh_index_buffer_t = System.IntPtr;
using sk_mesh_t = System.IntPtr;
using sk_mesh_vertex_buffer_t = System.IntPtr;
using sk_meshspecification_t = System.IntPtr;
using sk_nodraw_canvas_t = System.IntPtr;
using sk_nvrefcnt_t = System.IntPtr;
using sk_nway_canvas_t = System.IntPtr;
Expand Down
16 changes: 16 additions & 0 deletions binding/SkiaSharp/SKCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,22 @@ public void DrawVertices (SKVertices vertices, SKBlendMode mode, SKPaint paint)
GC.KeepAlive (this);
}

// DrawMesh

public void DrawMesh (SKMesh mesh, SKPaint paint)
{
DrawMesh (mesh, null, paint);
}

public void DrawMesh (SKMesh mesh, SKBlender blender, SKPaint paint)
{
if (mesh == null)
throw new ArgumentNullException (nameof (mesh));
if (paint == null)
throw new ArgumentNullException (nameof (paint));
SkiaApi.sk_canvas_draw_mesh (Handle, mesh.Handle, blender?.Handle ?? IntPtr.Zero, paint.Handle);
}

// DrawArc

public void DrawArc (SKRect oval, float startAngle, float sweepAngle, bool useCenter, SKPaint paint)
Expand Down
72 changes: 72 additions & 0 deletions binding/SkiaSharp/SKMesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;

namespace SkiaSharp;

public unsafe class SKMesh : SKObject, ISKSkipObjectRegistration
{
internal SKMesh (IntPtr handle, bool owns)
: base (handle, owns)
{
}

protected override void DisposeNative () =>
SkiaApi.sk_mesh_delete (Handle);

public bool IsValid => SkiaApi.sk_mesh_get_is_valid (Handle);

internal static SKMesh? GetObject (IntPtr handle) =>
handle == IntPtr.Zero ? null : new SKMesh (handle, true);
}

public class SKMeshBuilder : IDisposable
{
public SKMeshBuilder (SKMeshSpecification specification)
{
Specification = specification ?? throw new ArgumentNullException (nameof (specification));
Uniforms = new SKRuntimeEffectUniforms (specification);
Children = new SKRuntimeEffectChildren (specification);
}

public SKMeshSpecification Specification { get; }

public SKRuntimeEffectUniforms Uniforms { get; }

public SKRuntimeEffectChildren Children { get; }

public SKMeshMode Mode { get; set; } = SKMeshMode.Triangles;

public SKRect Bounds { get; set; }

public SKMesh? Build (SKMeshVertexBuffer vertexBuffer, int vertexCount, int vertexOffset)
{
return Specification.ToMesh (Mode, vertexBuffer, vertexCount, vertexOffset,
Uniforms, Children, Bounds);
}

public SKMesh? BuildIndexed (
SKMeshVertexBuffer vertexBuffer,
int vertexCount,
int vertexOffset,
SKMeshIndexBuffer indexBuffer,
int indexCount,
int indexOffset)
{
return Specification.ToMeshIndexed (Mode, vertexBuffer, vertexCount, vertexOffset,
indexBuffer, indexCount, indexOffset, Uniforms, Children, Bounds);
}

public void Dispose ()
{
Uniforms?.Dispose ();
Children?.Dispose ();
Specification?.Dispose ();
}
}

public class SKMeshSpecificationException : ApplicationException
{
public SKMeshSpecificationException (string message)
: base (message)
{
}
}
37 changes: 37 additions & 0 deletions binding/SkiaSharp/SKMeshIndexBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace SkiaSharp;

public unsafe class SKMeshIndexBuffer : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration
{
internal SKMeshIndexBuffer (IntPtr handle, bool owns)
: base (handle, owns)
{
}

protected override void Dispose (bool disposing) =>
base.Dispose (disposing);

public static SKMeshIndexBuffer? Make (ReadOnlySpan<byte> data)
{
fixed (byte* d = data)
{
return GetObject (SkiaApi.sk_mesh_index_buffer_make ((IntPtr)d, (IntPtr)data.Length));
}
}

public static SKMeshIndexBuffer? Make (IntPtr data, int size)
{
return GetObject (SkiaApi.sk_mesh_index_buffer_make (data, (IntPtr)size));
}

public static SKMeshIndexBuffer? Make (int size)
{
return GetObject (SkiaApi.sk_mesh_index_buffer_make (IntPtr.Zero, (IntPtr)size));
}

public int Size => (int)SkiaApi.sk_mesh_index_buffer_get_size (Handle);

internal static SKMeshIndexBuffer? GetObject (IntPtr handle) =>
handle == IntPtr.Zero ? null : new SKMeshIndexBuffer (handle, true);
}
Loading
Loading