Category Archives: DirectX

The Windows 8.1 PDF API and innovations from the ecosystem

It feels good when you work with a feature team (Dev/Test/PM) and bring a new system to life. In Windows 8.1, I worked with a great team of developers and testers to add a new API family to the Windows Runtime. These are the new PDF APIs for supporting rendering of PDF content in Windows Store apps. The APIs are of two flavors:

  1. pure WinRT APIs that can be accessed from any WinRT-supported language like JavaScript, C#, C++ etc and
  2. a “native” API that can be accessed only from C++.

Watch out for my column in the December edition of the MSDN Magazine that talks a bit more in detail about these APIs and the need to have two flavors.

Anyways, more to the point. When my team was beginning to think about these APIs, one of the underlying aspirations was to enable external partners, developers or anyone who is interested in extending the APIs be allowed to do so. I think the community is taking baby steps in that direction!

One of the first extensions on the APIs is a new PDF XAML control built by the awesome folks at DevExpress. They have built a new control, named as the PDF-Viewer (aptly I think) that allows any XAML app to simply drag-drop a UI control and bind to a PDF document source. It really is that simple. This control is built over the native API that draws Pdf content directly to a DirectX backed drawing surface. Right now head over to the site, download the bits and start playing with them.

This week also marks my movement away from the Windows team. I have moved over the Visual Studio group here in India and will be working on the next big thing. Just don’t ask what it is Smile

-Sridhar

What’s new in XAML for Windows 8.1?

//BUILD 2013 concluded last week and there was a ton of stuff to assimilate. I will attempt to summarize a few important changes for C++/XAML/DirectX developers in this blog post., focusing exclusively on the XAML/DirectX Interop scenarios.

If you are interested in knowing what is new with just the XAML framework (new controls, binding features etc), check out this great video from Tim Heuer.

New Stuff for XAML/DirectX interop scenarios using SwapChainPanel

1. A new SwapChainPanel control present in the Windows::UI::Xaml::Controls class.

2. In Windows 8, you were restricted to creating a full screen SwapChainBackgroundPanel and the swap chain had to be present at the root of your control hierarchy. The new SwapChainPanel controls removes these restrictions.

3. This does not mean you can have hundreds of SwapChainPanel controls in your app (Well, not even in the low double digits). Turns out using too many SwapChainPanel controls incurs a heavy cost. So restrict them to at the most 3 or 4. Do not go beyond that.

4. It is composable like any normal XAML element. You can have text layered below or above the control and have the XAML framework render content.

5. A Size Changed notification event provides for crisp re-drawing of content.

New Stuff for XAML/DirectX interop scenarios using the new SiS/VSiS

1. Has updated methods for faster D2D drawing by using drawing with a Direct2D DeviceContext.

2. Using the D2D DeviceContext allows the framework to batch the drawing requests.

3. Supports multi-threaded drawing.

4. Has new methods, SuspendDraw and ResumeDraw to enable you to suspend drawing operations and resume them later.

5. No longer needed to call BeginDraw on the XAML UI thread. In fact, BeginDraw, SuspendDraw and ResumeDraw can be called from any thread.

6. EndDraw should still be called on the UI thread. This allows the XAML framework to update the scene.

SwapChainPanel with Independent Input

1. The new SwapChainPanel now has support for processing touch, pen and mouse input on a background thread. This provides a path for low latency interactivity and high performance.

These are some of the high level changes. I encourage all of you to check out the excellent //BUILD 2013 talk by Bede Jordan,  a Senior Development Lead on the XAML team.

Enjoy the new C++/XAML/DirectX interop stuff in Windows 8.1

-Sridhar

A getting started template for creating XAML/DX apps using C++ and the SwapChainBackgroundPanel

This post comes courtesy of Wayne Ransier.

Start a XAML/C++ project in Visual Studio 2012 with the default Blank Template and replace the generated <Grid> element with a <SwapChainBackgroundPanel>

<SwapChainBackgroundPanel x:Name="DXSwapChainPanel">
</SwapChainBackgroundPanel>
If you build the solution now, the code compiles but the app crashes at runtime. The fix for the crash is simple.
Replace the OnLaunched method of your App class with the below code
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args)
{
    m_mainPage = ref new MainPage();    
    Window::Current->Content = m_mainPage;
    Window::Current->Activate();
}

 

The code to replace the OnLaunched method of the App class is missing from the step by step application tutorial of the DrawIt application.

You can get the complete details about why the crash happens here.
A simple project template with this fix applied can be found here.
Copy this project template (the zip file) to “C:\Users\<username>\Documents\Visual Studio 2012\Templates\ProjectTemplates” and re-start Visual Studio 2012.
A new template with the name SCBPCppProject will be listed when you select Visual C++ project type in Visual Studio 2012.
Another nifty tip to keep in mind and this is obtained from the DrawIt sample from “Modern C++ and Windows Store apps” book.
There are a few styles that I have created for the ApplicationBar and placed them in Styles.xaml. In the sample I do not use the default generated styles from StandardStyles.xaml.
You can see the change in app.xaml for the DrawIt project.
<ResourceDictionary.MergedDictionaries>

    <!-- 
        Styles that define common aspects of the platform look and feel
        Required by Visual Studio project and item templates
     -->
    <ResourceDictionary Source="Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>

 

Merging only the resources your application requires, into the Resource Dictionary is a nifty optimization.
A version of the sample that supports multi-touch can be downloaded here.
-Sridhar