Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix blending process issue #1114

Merged
merged 1 commit into from
Oct 6, 2024
Merged
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
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
Loading