Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/patch/v2.80.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Sep 8, 2021
2 parents 5737889 + 1775835 commit f8dbe84
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 5 deletions.
26 changes: 23 additions & 3 deletions binding/Binding/SKPaint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum SKPaintHinting
public unsafe class SKPaint : SKObject, ISKSkipObjectRegistration
{
private SKFont font;
private bool lcdRenderText;

internal SKPaint (IntPtr handle, bool owns)
: base (handle, owns)
Expand All @@ -38,6 +39,8 @@ public SKPaint (SKFont font)

if (Handle == IntPtr.Zero)
throw new InvalidOperationException ("Unable to create a new SKPaint instance.");

LcdRenderText = font.Edging == SKFontEdging.SubpixelAntialias;
}

protected override void Dispose (bool disposing) =>
Expand All @@ -55,7 +58,10 @@ public SKPaint (SKFont font)

public bool IsAntialias {
get => SkiaApi.sk_paint_is_antialias (Handle);
set => SkiaApi.sk_paint_set_antialias (Handle, value);
set {
SkiaApi.sk_paint_set_antialias (Handle, value);
UpdateFontEdging (value);
}
}

public bool IsDither {
Expand All @@ -81,8 +87,11 @@ public SKPaint (SKFont font)
}

public bool LcdRenderText {
get => GetFont ().Edging == SKFontEdging.SubpixelAntialias;
set => GetFont ().Edging = value ? SKFontEdging.SubpixelAntialias : SKFontEdging.Antialias;
get => lcdRenderText;
set {
lcdRenderText = value;
UpdateFontEdging (IsAntialias);
}
}

public bool IsEmbeddedBitmapText {
Expand Down Expand Up @@ -701,6 +710,17 @@ public float[] GetHorizontalTextIntercepts (IntPtr text, IntPtr length, float[]
internal SKFont GetFont () =>
font ??= OwnedBy (SKFont.GetObject (SkiaApi.sk_compatpaint_get_font (Handle), false), this);

private void UpdateFontEdging (bool antialias)
{
var edging = SKFontEdging.Alias;
if (antialias) {
edging = lcdRenderText
? SKFontEdging.SubpixelAntialias
: SKFontEdging.Antialias;
}
GetFont ().Edging = edging;
}

//

internal static SKPaint GetObject (IntPtr handle) =>
Expand Down
2 changes: 1 addition & 1 deletion externals/skia
2 changes: 1 addition & 1 deletion scripts/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ stages:
notifyAlwaysV2: false
instanceUrlForTsaV2: 'DEVDIV'
projectNameDEVDIV: 'DevDiv'
areaPath: 'DevDiv\Xamarin SDK\SkiaSharp'
areaPath: 'DevDiv\VS Client - Runtime SDKs\SkiaSharp'
iterationPath: 'DevDiv\OneVS'
uploadAPIScan: false
uploadBinSkim: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,19 @@ public override void Draw(CGRect dirtyRect)
// draw the surface to the context
drawable.DrawSurface(ctx, Bounds, info, surface);
}

public override void WillMoveToWindow(UIWindow window)
{
if (drawable != null)
{
// release the memory if we are leaving the window
if (window == null)
drawable?.Dispose();
else
SetNeedsDisplay();
}

base.WillMoveToWindow(window);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public SKSurface CreateSurface(CGRect contentsBounds, nfloat scale, out SKImageI
if (bitmapData == null)
{
bitmapData = NSMutableData.FromLength(info.BytesSize);

// in case allocation has failed
if (bitmapData == null)
{
Dispose();
info = Info;
return null;
}

dataProvider = new CGDataProvider(bitmapData.MutableBytes, info.BytesSize, Dummy);

void Dummy(IntPtr data)
Expand Down
14 changes: 14 additions & 0 deletions source/SkiaSharp.Views/SkiaSharp.Views.AppleiOS/SKCanvasView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ public override void Draw(CGRect rect)
}
}

public override void WillMoveToWindow(UIWindow window)
{
if (drawable != null)
{
// release the memory if we are leaving the window
if (window == null)
drawable?.Dispose();
else
SetNeedsDisplay();
}

base.WillMoveToWindow(window);
}

public event EventHandler<SKPaintSurfaceEventArgs> PaintSurface;

protected virtual void OnPaintSurface(SKPaintSurfaceEventArgs e)
Expand Down
87 changes: 87 additions & 0 deletions tests/Tests/SKPaintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,92 @@ public void GetTextPathSucceedsForEmtptyString()

Assert.NotNull(paint.GetTextPath("", 0, 0));
}

[SkippableTheory]
[InlineData(true, true, SKFontEdging.SubpixelAntialias)]
[InlineData(false, true, SKFontEdging.Alias)]
[InlineData(true, false, SKFontEdging.Antialias)]
[InlineData(false, false, SKFontEdging.Alias)]
public void UpdatingPropertiesIsAntialiasLcdRenderText(bool isAntialias, bool lcd, SKFontEdging newEdging)
{
var paint = new SKPaint();

paint.IsAntialias = isAntialias;
paint.LcdRenderText = lcd;

Assert.Equal(newEdging, paint.GetFont().Edging);
}

[SkippableTheory]
[InlineData(true, true, SKFontEdging.SubpixelAntialias)]
[InlineData(false, true, SKFontEdging.Alias)]
[InlineData(true, false, SKFontEdging.Antialias)]
[InlineData(false, false, SKFontEdging.Alias)]
public void UpdatingPropertiesLcdRenderTextIsAntialias(bool isAntialias, bool lcd, SKFontEdging newEdging)
{
var paint = new SKPaint();

paint.LcdRenderText = lcd;
paint.IsAntialias = isAntialias;

Assert.Equal(newEdging, paint.GetFont().Edging);
}

[SkippableFact]
public void PaintWithSubpixelEdgingIsPreserved()
{
var font = new SKFont();
font.Edging = SKFontEdging.SubpixelAntialias;

var paint = new SKPaint(font);

Assert.True(paint.LcdRenderText);
Assert.False(paint.IsAntialias);
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);

paint.IsAntialias = true;

Assert.True(paint.LcdRenderText);
Assert.True(paint.IsAntialias);
Assert.Equal(SKFontEdging.SubpixelAntialias, paint.GetFont().Edging);
}

[SkippableFact]
public void PaintWithAntialiasEdgingIsPreserved()
{
var font = new SKFont();
font.Edging = SKFontEdging.Antialias;

var paint = new SKPaint(font);

Assert.False(paint.LcdRenderText);
Assert.False(paint.IsAntialias);
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);

paint.IsAntialias = true;

Assert.False(paint.LcdRenderText);
Assert.True(paint.IsAntialias);
Assert.Equal(SKFontEdging.Antialias, paint.GetFont().Edging);
}

[SkippableFact]
public void PaintWithAliasEdgingIsPreserved()
{
var font = new SKFont();
font.Edging = SKFontEdging.Alias;

var paint = new SKPaint(font);

Assert.False(paint.LcdRenderText);
Assert.False(paint.IsAntialias);
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);

paint.IsAntialias = true;

Assert.False(paint.LcdRenderText);
Assert.True(paint.IsAntialias);
Assert.Equal(SKFontEdging.Antialias, paint.GetFont().Edging);
}
}
}

0 comments on commit f8dbe84

Please sign in to comment.