Skip to content

Commit

Permalink
Merge commit 'fc81cd93a0095bc8c15198ea8afbd2fa7aa3421d'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Aug 24, 2024
2 parents 7f53d6c + fc81cd9 commit 755ff8b
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions Workbench/HuremluhuhaChilejelawlai/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Windows.ApplicationModel.Core;
using Windows.Graphics.DirectX;
using Windows.Graphics.Display;
using Windows.Foundation;
using Windows.UI.Core;
using Microsoft.Graphics.Canvas;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Graphics.Canvas.UI.Composition;
using Microsoft.Graphics.DirectX;
using Microsoft.UI;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Hosting;

namespace FinayfuweewawWakibawlu;

Expand Down Expand Up @@ -34,10 +38,10 @@ public void Load(string entryPoint)

public void Run()
{
var swapChain = CanvasSwapChain.CreateForCoreWindow(
resourceCreator: CanvasDevice.GetSharedDevice(),
coreWindow: _coreWindow,
dpi: DisplayInformation.GetForCurrentView().LogicalDpi);
//var swapChain = CanvasSwapChain.CreateForCoreWindow(
// resourceCreator: CanvasDevice.GetSharedDevice(),
// coreWindow: _coreWindow,
// dpi: DisplayInformation.GetForCurrentView().LogicalDpi);
}

public void Uninitialize()
Expand Down Expand Up @@ -66,23 +70,34 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)

window.Activated += (sender, eventArgs) =>
{
if (window.Content is Grid grid)
{
grid.Loaded += (o, routedEventArgs) =>
{
var xamlRoot = window.Content.XamlRoot;
var rasterizationScale = xamlRoot.RasterizationScale;
var canvasDevice = new CanvasDevice();
var compositor = window.Compositor;
};
var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice);
var compositionDrawingSurface = compositionGraphicsDevice.CreateDrawingSurface(
new Windows.Foundation.Size(100, 100),
DirectXPixelFormat.B8G8R8A8UIntNormalized,
DirectXAlphaMode.Premultiplied);
using (CanvasDrawingSession? drawingSession = CanvasComposition.CreateDrawingSession(compositionDrawingSurface))
{
drawingSession.FillRectangle(new Rect(10, 10, 10, 10), Windows.UI.Color.FromArgb(0xFF, 0x56, 0x56, 0x56));
}
var coreWindow = window.CoreWindow;
var sharedDevice = CanvasDevice.GetSharedDevice();
// 在 Win2d 渲染到平面完成之后,将这个平面作为一个画刷用于在之后的效果
CompositionSurfaceBrush surfaceBrush = compositor.CreateSurfaceBrush(compositionDrawingSurface);
var canvasSwapChain = new CanvasSwapChain(sharedDevice,100,100,96);
var swapChain = CanvasSwapChain.CreateForCoreWindow(sharedDevice, coreWindow, 96,100,96,DirectXPixelFormat.R8G8B8A8Int,2);
SpriteVisual visual = compositor.CreateSpriteVisual();
visual.Brush = surfaceBrush;
Visual elementVisual = ElementCompositionPreview.GetElementVisual(window.Content);
if (elementVisual is ContainerVisual containerVisual)
{
containerVisual.Children.InsertAtTop(visual);
}
};

window.Activate();

base.OnLaunched(args);
Expand Down

0 comments on commit 755ff8b

Please sign in to comment.