enhance: do NOT use render target when there's only added or delete image.

This commit is contained in:
leo 2024-06-22 14:00:49 +08:00
parent dde5d4a2a8
commit 4e8e39d2fe
No known key found for this signature in database

View file

@ -244,17 +244,13 @@ namespace SourceGit.Views
var right = NewImage; var right = NewImage;
var drawLeft = left != null && alpha < 1.0; var drawLeft = left != null && alpha < 1.0;
var drawRight = right != null && alpha > 0; var drawRight = right != null && alpha > 0;
var psize = left == null ? right.PixelSize : left.PixelSize;
var dpi = left == null ? right.Dpi : left.Dpi;
using (var rt = new RenderTargetBitmap(psize, dpi)) if (drawLeft && drawRight)
{
using (var rt = new RenderTargetBitmap(right.PixelSize, right.Dpi))
{ {
var rtRect = new Rect(rt.Size); var rtRect = new Rect(rt.Size);
using (var dc = rt.CreateDrawingContext()) using (var dc = rt.CreateDrawingContext())
{
if (drawLeft)
{
if (drawRight)
{ {
using (dc.PushRenderOptions(RO_SRC)) using (dc.PushRenderOptions(RO_SRC))
using (dc.PushOpacity(1 - alpha)) using (dc.PushOpacity(1 - alpha))
@ -264,22 +260,19 @@ namespace SourceGit.Views
using (dc.PushOpacity(alpha)) using (dc.PushOpacity(alpha))
dc.DrawImage(right, rtRect); dc.DrawImage(right, rtRect);
} }
else
{ context.DrawImage(rt, rtRect, rect);
using (dc.PushRenderOptions(RO_SRC))
using (dc.PushOpacity(1 - alpha))
dc.DrawImage(left, rtRect);
} }
} }
else if (drawLeft)
{
using (context.PushOpacity(1 - alpha))
context.DrawImage(left, rect);
}
else if (drawRight) else if (drawRight)
{ {
using (dc.PushRenderOptions(RO_SRC)) using (context.PushOpacity(alpha))
using (dc.PushOpacity(alpha)) context.DrawImage(right, rect);
dc.DrawImage(right, rtRect);
}
}
context.DrawImage(rt, rtRect, rect);
} }
} }