From 081aacd4fdd6f0ead094c817fc12ecf5fc9ab259 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 25 Jul 2024 23:05:57 -0700 Subject: [PATCH] Implement initial simplified render loop --- .../App.cs | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs b/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs index e8bcd28a..4ad3d4a6 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs @@ -1,7 +1,15 @@ +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Threading; +using ComputeSharp.D2D1.Uwp; +using ComputeSharp.SwapChain.D2D1.CoreWindow.Extensions; +using ComputeSharp.SwapChain.Shaders.D2D1; +using Microsoft.Graphics.Canvas; +using Microsoft.Graphics.Canvas.Effects; using Windows.ApplicationModel.Core; - -#pragma warning disable IDE0052 +using Windows.Graphics.Display; +using Windows.UI; +using Windows.UI.ViewManagement; namespace ComputeSharp.SwapChain.D2D1.CoreWindow; @@ -12,7 +20,14 @@ using Windows.UI.Core; /// public sealed partial class App : IFrameworkViewSource, IFrameworkView { + /// + /// The for the current app instance. + /// private CoreApplicationView? applicationView; + + /// + /// The used to display the app content. + /// private CoreWindow? window; /// @@ -51,6 +66,39 @@ public sealed partial class App : IFrameworkViewSource, IFrameworkView /// public void Run() { + this.applicationView!.TitleBar.ExtendViewIntoTitleBar = true; + + ApplicationView.GetForCurrentView().TitleBar.StyleTitleBarForExtendedIntoViewMode(); + + CanvasSwapChain swapChain = CanvasSwapChain.CreateForCoreWindow( + CanvasDevice.GetSharedDevice(), + this.window, + DisplayInformation.GetForCurrentView().LogicalDpi); + + int2 sizeInPixels = new((int)swapChain.SizeInPixels.Width, (int)swapChain.SizeInPixels.Height); + CancellationTokenSource cancellationTokenSource = new(); + Stopwatch stopwatch = Stopwatch.StartNew(); + + Thread thread = new(() => + { + PixelShaderEffect shader = new(); + PremultiplyEffect premultiply = new() { Source = shader }; + + while (!cancellationTokenSource.IsCancellationRequested) + { + using (CanvasDrawingSession session = swapChain.CreateDrawingSession(Colors.Transparent)) + { + shader.ConstantBuffer = new ColorfulInfinity((float)stopwatch.Elapsed.TotalSeconds, sizeInPixels); + + session.DrawImage(premultiply); + } + + swapChain.Present(syncInterval: 1); + } + }); + + thread.Start(); + this.window!.Activate(); this.window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);