From 52279eaa4baede7ba0431c8a6f8fa80ac1a6ab6a Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 9 Oct 2026 21:33:33 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=81=AE=E6=8F=8F=E7=94=BB?= =?UTF-8?q?=E3=81=A7=E3=83=93=E3=83=83=E3=83=88=E3=83=9E=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=81=AE=E3=83=A9=E3=83=83=E3=83=91=E3=83=BC=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E3=81=84=E5=9B=9E=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・毎フレームの入力の描画で発生していたメモリ確保をなくす-M --- .../Effects/WaveOpticsEffectProcessor.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/WaveOptics/Effects/WaveOpticsEffectProcessor.cs b/WaveOptics/Effects/WaveOpticsEffectProcessor.cs index 0889b1e..142bff8 100644 --- a/WaveOptics/Effects/WaveOpticsEffectProcessor.cs +++ b/WaveOptics/Effects/WaveOpticsEffectProcessor.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using System.Numerics; +using System.Runtime.InteropServices; using ComputeGuard; using ComputeWeave; using SpectralConvolution; @@ -47,6 +48,7 @@ internal sealed class WaveOpticsEffectProcessor : VideoEffectProcessorBase private Vector4 _cropRect; private float _amount; private float _appliedAmount = float.NaN; + private readonly ID2D1Bitmap1 _sourceBitmap = new(IntPtr.Zero); private RenderState _renderState; public WaveOpticsEffectProcessor(IGraphicsDevicesAndContext devices, WaveOpticsEffect item) @@ -405,18 +407,27 @@ internal sealed class WaveOpticsEffectProcessor : VideoEffectProcessorBase var renderContext = _interopProvider!.RenderContext; using var borrow = _resourceSet!.BeginSourceExternalOperation(); var previousTarget = renderContext.Target; - using var sourceBitmap = new ID2D1Bitmap1(borrow.DangerousGetView().AddRefBitmap()); - renderContext.Target = sourceBitmap; - renderContext.BeginDraw(); - renderContext.Clear(null); - renderContext.DrawImage( - input, - new Vector2(-bounds.Left, -bounds.Top), - null, - InterpolationMode.NearestNeighbor, - CompositeMode.SourceCopy); - renderContext.EndDraw(); - renderContext.Target = previousTarget; + var bitmapPointer = borrow.DangerousGetView().AddRefBitmap(); + _sourceBitmap.NativePointer = bitmapPointer; + try + { + renderContext.Target = _sourceBitmap; + renderContext.BeginDraw(); + renderContext.Clear(null); + renderContext.DrawImage( + input, + new Vector2(-bounds.Left, -bounds.Top), + null, + InterpolationMode.NearestNeighbor, + CompositeMode.SourceCopy); + renderContext.EndDraw(); + renderContext.Target = previousTarget; + } + finally + { + _sourceBitmap.NativePointer = IntPtr.Zero; + Marshal.Release(bitmapPointer); + } } private static float Sanitize(double value, double minimum, double maximum, double fallback)