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; using Windows.Graphics.Display; using Windows.UI; using Windows.UI.ViewManagement; namespace ComputeSharp.SwapChain.D2D1.CoreWindow; using Windows.UI.Core; /// /// A sample app rendering D2D shaders into a instance. /// 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; /// /// The entry point for the application. /// public static void Main() { CoreApplication.Run(new App()); } /// public IFrameworkView CreateView() { return this; } /// [MemberNotNull(nameof(applicationView))] public void Initialize(CoreApplicationView applicationView) { this.applicationView = applicationView; } /// [MemberNotNull(nameof(window))] public void SetWindow(CoreWindow window) { this.window = window; } /// public void Load(string entryPoint) { } /// 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); } /// public void Uninitialize() { } }