Skip to content

Commit

Permalink
Merge pull request #216 from mattleibow/dev/skia
Browse files Browse the repository at this point in the history
Use newer SkiaSharp APIs
  • Loading branch information
wieslawsoltes committed Apr 16, 2024
2 parents 2b7dddd + d38f622 commit f987aaf
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 117 deletions.
2 changes: 1 addition & 1 deletion build/SkiaSharp.HarfBuzz.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.6" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.8" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/SkiaSharp.Linux.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/SkiaSharp.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/ShimSkiaSharp/SKImageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public static SKImageFilter CreateOffset(float dx, float dy, SKImageFilter? inpu
public static SKImageFilter CreatePaint(SKPaint paint, CropRect? cropRect = null)
=> new PaintImageFilter(paint, cropRect);

public static SKImageFilter CreateShader(SKShader shader, bool dither, CropRect? cropRect = null)
=> new ShaderImageFilter(shader, dither, cropRect);

public static SKImageFilter CreatePicture(SKPicture picture, SKRect cropRect)
=> new PictureImageFilter(picture, cropRect);

Expand Down Expand Up @@ -99,6 +102,8 @@ public record OffsetImageFilter(float Dx, float Dy, SKImageFilter? Input, SKImag

public record PaintImageFilter(SKPaint? Paint, SKImageFilter.CropRect? Clip) : SKImageFilter;

public record ShaderImageFilter(SKShader? Shader, bool Dither, SKImageFilter.CropRect? Clip) : SKImageFilter;

public record PictureImageFilter(SKPicture? Picture, SKRect? Clip) : SKImageFilter;

public record PointLitDiffuseImageFilter(SKPoint3 Location, SKColor LightColor, float SurfaceScale, float Kd, SKImageFilter? Input, SKImageFilter.CropRect? Clip) : SKImageFilter;
Expand Down
20 changes: 20 additions & 0 deletions src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,26 @@ public static void ToSKImageFilter(this SKImageFilter? imageFilter, SkiaCSharpCo
sb.AppendLine($"{indent}{counter.PaintVarName}{counterPaint}?.Dispose();");
return;
}
case ShaderImageFilter shaderImageFilter:
{
if (shaderImageFilter.Shader is null)
{
sb.AppendLine($"{indent}var {counter.ImageFilterVarName}{counterImageFilter} = default(SKImageFilter);");
return;
}

var counterShader = ++counter.Shader;
shaderImageFilter.Shader.ToSKShader(counter, sb, indent);

sb.Append($"{indent}var {counter.ImageFilterVarName}{counterImageFilter} = ");
sb.AppendLine($"SKImageFilter.CreateShader(");
sb.AppendLine($"{indent} {counter.ShaderVarName}{counterShader},");
sb.AppendLine($"{indent} {shaderImageFilter.Dither.ToBoolString()},");
sb.AppendLine($"{indent} {shaderImageFilter.Clip?.ToCropRect() ?? "null"});");

sb.AppendLine($"{indent}{counter.ShaderVarName}{counterShader}?.Dispose();");
return;
}
case PictureImageFilter pictureImageFilter:
{
if (pictureImageFilter.Picture is null)
Expand Down
Loading

0 comments on commit f987aaf

Please sign in to comment.