Skip to content

Commit

Permalink
fix: Fix blending process issue (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd authored Oct 6, 2024
1 parent fcc56b3 commit 628ec5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Beutl.Engine/Graphics/CanvasPushedState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public override void Pop(ImmediateCanvas canvas)
}
}

internal record BlendModePushedState(BlendMode BlendMode) : CanvasPushedState
internal record BlendModePushedState(BlendMode BlendMode, int Count, SKPaint Paint) : CanvasPushedState
{
public override void Pop(ImmediateCanvas canvas)
{
canvas.Canvas.RestoreToCount(Count);
canvas.BlendMode = BlendMode;
Paint.Dispose();
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/Beutl.Engine/Graphics/ImmediateCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public void DrawSurface(SKSurface surface, Point point)
{
_sharedFillPaint.Reset();
_sharedFillPaint.IsAntialias = true;
_sharedFillPaint.BlendMode = (SKBlendMode)BlendMode;

Canvas.DrawSurface(surface, point.X, point.Y, _sharedFillPaint);
}
Expand Down Expand Up @@ -537,7 +536,11 @@ public PushedState PushBlendMode(BlendMode blendMode)
VerifyAccess();
BlendMode tmp = BlendMode;
BlendMode = blendMode;
_states.Push(new CanvasPushedState.BlendModePushedState(tmp));
var paint = new SKPaint();
paint.BlendMode = (SKBlendMode)blendMode;

int count = Canvas.SaveLayer(paint);
_states.Push(new CanvasPushedState.BlendModePushedState(tmp, count, paint));
return new PushedState(this, _states.Count);
}

Expand All @@ -553,7 +556,7 @@ private void VerifyAccess()
_dispatcher?.VerifyAccess();
}

private void ConfigureStrokePaint(Rect bounds, IPen? pen)
private void ConfigureStrokePaint(Rect bounds, IPen? pen, BlendMode blendMode = BlendMode.SrcOver)
{
_sharedStrokePaint.Reset();

Expand Down Expand Up @@ -608,13 +611,13 @@ private void ConfigureStrokePaint(Rect bounds, IPen? pen)
_sharedStrokePaint.PathEffect = pe;
}

new BrushConstructor(original, pen.Brush, BlendMode, this).ConfigurePaint(_sharedStrokePaint);
new BrushConstructor(original, pen.Brush, blendMode, this).ConfigurePaint(_sharedStrokePaint);
}
}

private void ConfigureFillPaint(Rect bounds, IBrush? brush)
private void ConfigureFillPaint(Rect bounds, IBrush? brush, BlendMode blendMode = BlendMode.SrcOver)
{
_sharedFillPaint.Reset();
new BrushConstructor(bounds, brush, BlendMode, this).ConfigurePaint(_sharedFillPaint);
new BrushConstructor(bounds, brush, blendMode, this).ConfigurePaint(_sharedFillPaint);
}
}
1 change: 0 additions & 1 deletion src/Beutl.Engine/Graphics/Rendering/FilterEffectNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private void RenderCore(
{
using (var paint = new SKPaint())
{
paint.BlendMode = (SKBlendMode)canvas.BlendMode;
paint.ImageFilter = builder.GetFilter();

foreach (EffectTarget t in activator.CurrentTargets)
Expand Down

0 comments on commit 628ec5d

Please sign in to comment.