Skip to content

Commit

Permalink
Run canvas swap chain loop on bg task
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasf committed Jan 25, 2025
1 parent 4f49059 commit 97ac191
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Samples/MediaPlayerCS/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void StartRenderSubtitles()
}
else if (renderTech == SubtitleRenderTech.SwapChain)
{
subtitleLoop = SubtitleRenderLoopSwapChain(cancelSubtitlesSource.Token);
subtitleLoop = Task.Run(() => SubtitleRenderLoopSwapChain(cancelSubtitlesSource.Token));
}
else
{
Expand Down Expand Up @@ -238,7 +238,7 @@ private async Task SubtitleRenderLoop(CancellationToken token)
{
continue; // target has changed
}

var t2 = stopwatch.Elapsed;
if (renderResult.Succeeded && renderResult.HasChanged)
{
Expand Down Expand Up @@ -276,11 +276,14 @@ private async Task SubtitleRenderLoopSwapChain(CancellationToken token)
{
if (swapChainSizeChanged)
{
var displayInfo = DisplayInformation.GetForCurrentView();
var width = mediaPlayerElement.ActualWidth;
var height = mediaPlayerElement.ActualHeight;
swapChain?.ResizeBuffers((float)width, (float)height, displayInfo.LogicalDpi);
swapChainSizeChanged = false;
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var displayInfo = DisplayInformation.GetForCurrentView();
var width = mediaPlayerElement.ActualWidth;
var height = mediaPlayerElement.ActualHeight;
swapChain?.ResizeBuffers((float)width, (float)height, displayInfo.LogicalDpi);
swapChainSizeChanged = false;
});
}

using (var swapChainDS = swapChain.CreateDrawingSession(Colors.Transparent))
Expand Down

0 comments on commit 97ac191

Please sign in to comment.