Skip to content

Commit 077fa17

Browse files
committed
feat: implement cache management methods to disable and enable all caches during encoding
1 parent e052d92 commit 077fa17

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/Beutl/ViewModels/Tools/OutputViewModel.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ await RenderThread.Dispatcher.InvokeAsync(async () =>
191191
_logger.LogInformation("Using encoding controller: {Controller}", controller);
192192
}
193193

194+
// キャッシュ無効化
195+
OutputViewModel.DisableAllCache();
196+
194197
// フレームプロバイダー作成
195198
// using var renderer = new SceneRenderer(scene);
196199
var renderer = _editViewModel.Renderer.Value;
@@ -206,11 +209,6 @@ await RenderThread.Dispatcher.InvokeAsync(async () =>
206209
using (frameProgress.CombineLatest(sampleProgress)
207210
.Subscribe(t => ProgressValue.Value = t.Item1.TotalSeconds + t.Item2.TotalSeconds))
208211
{
209-
RenderNodeCacheContext cacheContext = renderer.GetCacheContext();
210-
cacheContext.CacheOptions = RenderCacheOptions.Disabled;
211-
// FrameCacheも無効化
212-
_editViewModel.FrameCacheManager.Value.Clear();
213-
214212
await controller.Encode(frameProvider, sampleProvider, _lastCts.Token);
215213
}
216214
}
@@ -226,8 +224,7 @@ await RenderThread.Dispatcher.InvokeAsync(async () =>
226224
}
227225
finally
228226
{
229-
_editViewModel.Renderer.Value.GetCacheContext().CacheOptions =
230-
RenderCacheOptions.CreateFromGlobalConfiguration();
227+
OutputViewModel.EnableAllCache();
231228
_progress.Value = 0;
232229
ProgressMax.Value = 0;
233230
ProgressValue.Value = 0;
@@ -239,6 +236,30 @@ await RenderThread.Dispatcher.InvokeAsync(async () =>
239236
}
240237
}
241238

239+
private static void DisableAllCache()
240+
{
241+
foreach (EditorTabItem item in EditorService.Current.TabItems)
242+
{
243+
if (item.Context.Value is EditViewModel editViewModel)
244+
{
245+
editViewModel.Renderer.Value.GetCacheContext().CacheOptions = RenderCacheOptions.Disabled;
246+
editViewModel.FrameCacheManager.Value.Clear();
247+
}
248+
}
249+
}
250+
251+
private static void EnableAllCache()
252+
{
253+
foreach (EditorTabItem item in EditorService.Current.TabItems)
254+
{
255+
if (item.Context.Value is EditViewModel editViewModel)
256+
{
257+
editViewModel.Renderer.Value.GetCacheContext().CacheOptions =
258+
RenderCacheOptions.CreateFromGlobalConfiguration();
259+
}
260+
}
261+
}
262+
242263
public void CancelEncode()
243264
{
244265
_logger.LogInformation("Encoding process cancellation requested.");

0 commit comments

Comments
 (0)