Skip to content

Latest commit

 

History

History
69 lines (41 loc) · 7.29 KB

swapchainpanel.md

File metadata and controls

69 lines (41 loc) · 7.29 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.SwapChainPanel
winrt class

Windows.UI.Xaml.Controls.SwapChainPanel

-description

Provides a hosting surface, where Microsoft DirectX swap chains provide content that can be rendered into a XAML UI. A SwapChainPanel element is a key component for an app that renders Microsoft DirectX graphics and then presents those visuals within a XAML page.

-xaml-syntax

<SwapChainPanel .../>

-remarks

A SwapChainPanel is a Grid subclass, so you can use ColumnDefinitions and RowDefinitions properties to declare the panel's characteristics, and the attached properties of Grid such as Grid.Row and Grid.Column on child elements to position those child elements in the layout.

SwapChainPanel inherits the Background property from Panel, but you can't set the Background on a SwapChainPanel. An error occurs if you attempt to set it.

The SwapChainPanel class does not inherit from the Control class, so you can't programmatically focus it directly for purposes of capturing key events. Consider setting the focus to a focusable element inside the panel and letting the key event bubble.

In order to maintain crisp vector rendering, you should listen for the CompositionScaleChanged event and query the CompositionScaleX and CompositionScaleY property values to account for the current UI scale, and potentially render again from DirectX. Otherwise XAML layout might do the scaling and your visuals might be degraded.

Initializing a SwapChainPanel element

For code examples that use SwapChainPanel, see XAML SwapChainPanel DirectX interop sample.

Before a SwapChainPanel can render content, you must initialize it from the Microsoft DirectX side.

Cast the SwapChainPanel instance to IInspectable or IUnknown, then call QueryInterface to obtain a reference to the ISwapChainPanelNative interface (this is the native interface implementation that is the complement to the SwapChainPanel and enables the interop bridge). Then, call ISwapChainPanelNative.SetSwapChain on that reference to associate your implemented swap chain with the SwapChainPanel instance.

It's common to put the code that queries the interface and sets the swap chain as part of a Create*Resources method. The Create*Resources methods are an implementation pattern that's seen in the Microsoft DirectX Renderer class templates/examples, and you'll also see this implementation pattern in the SDK samples, and in the code you get from the DirectX (XAML) project template in Microsoft Visual Studio. Specifically, in the DirectX (XAML) project template, you'll see the QueryInterface call and the call to ISwapChainPanelNative.SetSwapChain in the DeviceResources::CreateWindowSizeDependentResources method implementation in DeviceResources.cpp.

The API that enables you to add a SwapChain to an existing SwapChainPanel is not a runtime class API, it is a Microsoft DirectX API. You implement the swap chain input as a Microsoft DirectX interface (IDXGISwapChain).

SwapChainPanel and SwapChainBackgroundPanel

SwapChainPanel has less restrictions on its interactions and placement in UI than does SwapChainBackgroundPanel.

  • SwapChainPanel can be used as a control anywhere in a visual tree of a page. SwapChainBackgroundPanel can only be the root element.
  • The typical XAML UI API that are inherited from the Grid base class can be used on a SwapChainPanel. SwapChainBackgroundPanel doesn't permit you to set most Grid inherited API.
  • For new apps you should generally use SwapChainPanel and should consider SwapChainBackgroundPanel to be a legacy technique for Windows 8 apps that weren't updated for Windows 8.1.

Swap chains

  • Swap chains must run on the main UI thread. This is usually accomplished by calling SetSwapChain on a reference that was initialized as a XAML object element.
  • A single swap chain can be associated with multiple SwapChainPanel elements. Or, your app can have multiple swap chains, with each providing the presentation for a separate SwapChainPanel.
  • However, performance can decline if many swap chains are updated simultaneously. We recommend that your app use no more than four swap chains.
  • Content that's rendered via the swap chain is not stretched when it's resized by the user; instead, the resizing behavior is similar to setting Stretch="None" on an Image element.
  • There are other techniques for rendering swap chain content that goes directly to the app's core window rather than a XAML-composed element. See CreateSwapChainForCoreWindow.

Processing input on background threads

Using the CreateCoreIndependentInputSource method, apps can process input and render to a SwapChainPanel entirely on one or more background threads. This enables high performance input and rendering independent of the XAML UI thread.

-examples

-see-also

Grid, SwapChainBackgroundPanel, ISwapChainPanelNative, DirectX and XAML interop, XAML SwapChainPanel DirectX interop sample, DirectX and XAML game sample (Windows 10), Direct2D photo adjustment sample (Windows 10), Low latency input sample, Direct2D SVG image rendering sample