[
  {
    "path": ".gitignore",
    "content": "# Created by https://www.gitignore.io/api/visualstudio\n\n### VisualStudio ###\n## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n\n# User-specific files\n*.suo\n*.user\n*.userosscache\n*.sln.docstates\n\n# User-specific files (MonoDevelop/Xamarin Studio)\n*.userprefs\n\n# Build results\n[Dd]ebug/\n[Dd]ebugPublic/\n[Rr]elease/\n[Rr]eleases/\nx64/\nx86/\nbuild/\nbld/\n[Bb]in/\n[Oo]bj/\n\n# Visual Studio 2015 cache/options directory\n.vs/\n# Uncomment if you have tasks that create the project's static files in wwwroot\n#wwwroot/\n\n# MSTest test Results\n[Tt]est[Rr]esult*/\n[Bb]uild[Ll]og.*\n\n# NUNIT\n*.VisualState.xml\nTestResult.xml\n\n# Build Results of an ATL Project\n[Dd]ebugPS/\n[Rr]eleasePS/\ndlldata.c\n\n# DNX\nproject.lock.json\nartifacts/\n\n*_i.c\n*_p.c\n*_i.h\n*.ilk\n*.meta\n*.obj\n*.pch\n*.pdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.tmp_proj\n*.log\n*.vspscc\n*.vssscc\n.builds\n*.pidb\n*.svclog\n*.scc\n\n# Chutzpah Test files\n_Chutzpah*\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opensdf\n*.sdf\n*.cachefile\n\n# Visual Studio profiler\n*.psess\n*.vsp\n*.vspx\n\n# TFS 2012 Local Workspace\n$tf/\n\n# Guidance Automation Toolkit\n*.gpState\n\n# ReSharper is a .NET coding add-in\n_ReSharper*/\n*.[Rr]e[Ss]harper\n*.DotSettings.user\n\n# JustCode is a .NET coding add-in\n.JustCode\n\n# TeamCity is a build add-in\n_TeamCity*\n\n# DotCover is a Code Coverage Tool\n*.dotCover\n\n# NCrunch\n_NCrunch_*\n.*crunch*.local.xml\nnCrunchTemp_*\n\n# MightyMoose\n*.mm.*\nAutoTest.Net/\n\n# Web workbench (sass)\n.sass-cache/\n\n# Installshield output folder\n[Ee]xpress/\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish/\n\n# Publish Web Output\n*.[Pp]ublish.xml\n*.azurePubxml\n# TODO: Comment the next line if you want to checkin your web deploy settings \n# but database connection strings (with potential passwords) will be unencrypted\n*.pubxml\n*.publishproj\n\n# NuGet Packages\n*.nupkg\n# The packages folder can be ignored because of Package Restore\n**/packages/*\n# except build/, which is used as an MSBuild target.\n!**/packages/build/\n# Uncomment if necessary however generally it will be regenerated when needed\n#!**/packages/repositories.config\n\n# Windows Azure Build Output\ncsx/\n*.build.csdef\n\n# Windows Store app package directory\nAppPackages/\n\n# Visual Studio cache files\n# files ending in .cache can be ignored\n*.[Cc]ache\n# but keep track of directories ending in .cache\n!*.[Cc]ache/\n\n# Others\nClientBin/\n[Ss]tyle[Cc]op.*\n~$*\n*~\n*.dbmdl\n*.dbproj.schemaview\n*.pfx\n*.publishsettings\nnode_modules/\norleans.codegen.cs\n\n# RIA/Silverlight projects\nGenerated_Code/\n\n# Backup & report files from converting an old project file\n# to a newer Visual Studio version. Backup files are not needed,\n# because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\nUpgradeLog*.htm\n\n# SQL Server files\n*.mdf\n*.ldf\n\n# Business Intelligence projects\n*.rdl.data\n*.bim.layout\n*.bim_*.settings\n\n# Microsoft Fakes\nFakesAssemblies/\n\n# Node.js Tools for Visual Studio\n.ntvs_analysis.dat\n\n# Visual Studio 6 build log\n*.plg\n\n# Visual Studio 6 workspace options file\n*.opt\n\n# Visual Studio LightSwitch build output\n**/*.HTMLClient/GeneratedArtifacts\n**/*.DesktopClient/GeneratedArtifacts\n**/*.DesktopClient/ModelManifest.xml\n**/*.Server/GeneratedArtifacts\n**/*.Server/ModelManifest.xml\n_Pvt_Extensions\n\n\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 Microsoft\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# **WPF DirectX Extensions**\nWPF DirectX Extensions allow you to easily host DirectX 10 and DirectX 11 content in WPF applications.\n\nGetting Started\n-------------------\n **Where to get it**\n\n - NuGet package\n \t- [x86](https://www.nuget.org/packages/Microsoft.Wpf.Interop.DirectX-x86/0.9.0-beta-22856)\n\t- [x64](https://www.nuget.org/packages/Microsoft.Wpf.Interop.DirectX-x64/0.9.0-beta-22856)\n - [Source Code](https://github.com/Microsoft/WPFDXInterop)\n\n**Resources**\n\n - [Documentation](https://github.com/Microsoft/WPFDXInterop/wiki)\n - [Samples](/samples)\n\n**More Info**\n\n - [Report a bug or ask a question](https://github.com/Microsoft/WPFDXInterop/issues)\n - [License](http://opensource.org/licenses/MIT)\n\nCode Example\n------------\n\n***XAML***\n```\n<Window x:Class=\"WpfApplication5.MainWindow\"\n        xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n        xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"\n        xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\n        xmlns:local=\"clr-namespace:WpfApplication5\"\n        mc:Ignorable=\"d\"\n        xmlns:DXExtensions=\"clr-namespace:Microsoft.Wpf.Interop.DirectX;assembly=Microsoft.Wpf.Interop.DirectX\"\n        Title=\"MainWindow\" Height=\"350\" Width=\"525\">\n    <Grid>\n        <Image>\n            <Image.Source>\n                <DXExtensions:D3D11Image  x:Name=\"InteropImage\"/>\n            </Image.Source>\n        </Image>\n    </Grid>\n</Window>\n```\n\n***C#***\n\nThe C# portions of interfacing with a native component that generates the DX visualization is not concise enough to host as an example. We would recommend that you look at sample code [here](https://github.com/Microsoft/WPFDXInterop/blob/master/samples/D3D11Image/WpfD3D11Interop/MainWindow.xaml.cs) to get a detailed understanding of the code required\n\n\nUsing WPF DirectX Extensions\n-------------------\nThe [documentation](https://github.com/Microsoft/WPFDXInterop/wiki) explains how to install Visual Studio, add the WPF DirectX Extension NuGet package to your project, and get started using the API.\n\nBuilding WPF DirectX Extensions from Source\n------------------------------\n**What You Need**\n\n - [Visual Studio 2015](https://www.visualstudio.com/features/wpf-vs)\n - [DirectX SDK](http://www.microsoft.com/en-us/download/details.aspx?id=6812)\n - [Windows SDK](https://dev.windows.com/en-us/downloads/windows-10-sdk)\n \n**Build and Create WPF DirectX Extensions NuGet**\n \n - [Clone the Repository](https://github.com/Microsoft/WPFDXInterop)\n - Open Microsoft.Wpf.Interop.DirectX_winsdk or Microsoft.Wpf.Interop.DirectX_dxsdk solution from [Source](/src)  in Visual Studio\n - Change Build Configuration to Release and build for x86 and x64\n - Run BuildNuGetPackage in [scripts](/scripts) to create nuget packages \n\n"
  },
  {
    "path": "SECURITY.md",
    "content": "<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->\n\n## Security\n\nMicrosoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).\n\nIf you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.\n\n## Reporting Security Issues\n\n**Please do not report security vulnerabilities through public GitHub issues.**\n\nInstead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).\n\nIf you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com).  If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).\n\nYou should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). \n\nPlease include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:\n\n  * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)\n  * Full paths of source file(s) related to the manifestation of the issue\n  * The location of the affected source code (tag/branch/commit or direct URL)\n  * Any special configuration required to reproduce the issue\n  * Step-by-step instructions to reproduce the issue\n  * Proof-of-concept or exploit code (if possible)\n  * Impact of the issue, including how an attacker might exploit the issue\n\nThis information will help us triage your report more quickly.\n\nIf you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.\n\n## Preferred Languages\n\nWe prefer all communications to be in English.\n\n## Policy\n\nMicrosoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).\n\n<!-- END MICROSOFT SECURITY.MD BLOCK -->\n"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.cpp",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"D3DVisualization.cpp\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#include \"D3DVisualization.h\"\n\n#ifndef DIRECTX_SDK\n    using namespace DirectX;\n    using namespace DirectX::PackedVector;\n#endif\n\n// Global Variables\nCCube * pApplication;  // Application class\n\n//--------------------------------------------------------------------------------------\n// Structures\n//--------------------------------------------------------------------------------------\nstruct SimpleVertex\n{\n\tXMFLOAT3 Pos;\n    XMFLOAT4 Color;\n};\n\nstruct ConstantBuffer\n{\n    XMMATRIX mWorld;\n    XMMATRIX mView;\n    XMMATRIX mProjection;\n};\n\nBOOL WINAPI DllMain(HINSTANCE hInstance,DWORD fwdReason, LPVOID lpvReserved) \n{\n    return TRUE;\n}\n\n/// <summary>\n/// Init global class instance\n/// </summary>\nextern HRESULT __cdecl Init()\n{\n\tpApplication = new CCube();\n\n    HRESULT hr = S_OK;\n\n    if ( FAILED( hr = pApplication->InitDevice() ) )\n    {\n        return hr;\n    }\n\n    return hr;\n}\n\n/// <summary>\n/// Cleanup global class instance\n/// </summary>\nextern void __cdecl Cleanup()\n{\n    delete pApplication;\n    pApplication = NULL;\n}\n\n/// <summary>\n/// Render for global class instance\n/// </summary>\nextern HRESULT __cdecl Render(void * pResource, bool isNewSurface)\n{\n    if ( NULL == pApplication )\n    {\n        return E_FAIL;\n    }\n\n    return pApplication->Render(pResource, isNewSurface);\n}\n\n/// <summary>\n/// Sets the Radius value of the camera\n/// </summary>\nextern HRESULT _cdecl SetCameraRadius(float r)\n{\n    if ( NULL == pApplication )\n    {\n        return E_FAIL;\n    }\n\n    pApplication->GetCamera()->SetRadius(r);\n    return 0;\n}\n\n/// <summary>\n/// Sets the Theta value of the camera\n/// Theta represents the angle (in radians) of the camera around the \n/// center in the x-y plane\n/// </summary>\nextern HRESULT _cdecl SetCameraTheta(float theta)\n{\n    if ( NULL == pApplication )\n    {\n        return E_FAIL;\n    }\n\n    pApplication->GetCamera()->SetTheta(theta);\n    return 0;\n}\n\n/// <summary>\n/// Sets the Phi value of the camera\n/// Phi represents angle (in radians) of the camera around the center \n/// in the y-z plane (over the top and below the scene)\n/// </summary>\nextern HRESULT _cdecl SetCameraPhi(float phi)\n{\n    if ( NULL == pApplication )\n    {\n        return E_FAIL;\n    }\n\n    pApplication->GetCamera()->SetPhi(phi);\n    return 0;\n}\n\n/// <summary>\n/// Constructor\n/// </summary>\nCCube::CCube()\n{\n\tm_Height = 0;\n\tm_Width = 0;\n\n    m_hInst = NULL;\n    m_featureLevel = D3D_FEATURE_LEVEL_11_0;\n    m_pd3dDevice = NULL;\n    m_pImmediateContext = NULL;\n    m_pVertexLayout = NULL;\n    m_pVertexBuffer = NULL;\n    m_pVertexShader = NULL;\n    m_pPixelShader = NULL;\n}\n\n/// <summary>\n/// Destructor\n/// </summary>\nCCube::~CCube()\n{\n    if (m_pImmediateContext) \n    {\n        m_pImmediateContext->ClearState();\n    }\n\n\tSAFE_RELEASE(m_pIndexBuffer);\n    SAFE_RELEASE(m_pPixelShader);\n    SAFE_RELEASE(m_pVertexBuffer);\n    SAFE_RELEASE(m_pVertexLayout);\n    SAFE_RELEASE(m_pVertexShader);\n    SAFE_RELEASE(m_pImmediateContext);\n    SAFE_RELEASE(m_pd3dDevice);\n}\n\n\n/// <summary>\n/// Compile and set layout for shaders\n/// </summary>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CCube::LoadShaders()\n{\n\tHRESULT hr = S_OK;\n\n\t// Compile the pixel shader\n\tID3DBlob* pPSBlob = NULL;\n\thr = CompileShaderFromFile(L\"D3DVisualization.fx\", \"PS\", \"ps_4_0\", &pPSBlob);\n\tif (FAILED(hr))\n\t{\n\t\tMessageBox(NULL,\n\t\t\tL\"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.\", L\"Error\", MB_OK);\n\t\treturn hr;\n\t}\n\n\t// Create the pixel shader\n\thr = m_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, &m_pPixelShader);\n\tpPSBlob->Release();\n\tif (FAILED(hr))\n\t\treturn hr;\n\n\t// Compile the vertex shader\n\tID3DBlob* pVSBlob = NULL;\n\thr = CompileShaderFromFile(L\"D3DVisualization.fx\", \"VS\", \"vs_4_0\", &pVSBlob);\n\tif (FAILED(hr))\n\t{\n\t\tMessageBox(NULL,\n\t\t\tL\"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.\", L\"Error\", MB_OK);\n\t\treturn hr;\n\t}\n\n\t// Create the vertex shader\n\thr = m_pd3dDevice->CreateVertexShader(pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, &m_pVertexShader);\n\tif (FAILED(hr))\n\t{\n\t\tpVSBlob->Release();\n\t\treturn hr;\n\t}\n\n\t// Define the input layout\n\tD3D11_INPUT_ELEMENT_DESC layout[] =\n\t{\n\t\t{ \"POSITION\", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },\n\t\t{ \"COLOR\", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },\n\t};\n\tUINT numElements = ARRAYSIZE(layout);\n\n\t// Create the input layout\n\thr = m_pd3dDevice->CreateInputLayout(layout, numElements, pVSBlob->GetBufferPointer(),\n\t\tpVSBlob->GetBufferSize(), &m_pVertexLayout);\n\tpVSBlob->Release();\n\tif (FAILED(hr))\n\t\treturn hr;\n\n\t// Set the input layout\n\tm_pImmediateContext->IASetInputLayout(m_pVertexLayout);\n\n    return hr;\n}\n\n/// <summary>\n/// Create Direct3D device\n/// </summary>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CCube::InitDevice()\n{\n    HRESULT hr = S_OK;\n\n\tUINT createDeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;\n\n    D3D_DRIVER_TYPE driverTypes[] =\n    {\n        D3D_DRIVER_TYPE_HARDWARE,\n        D3D_DRIVER_TYPE_WARP,\n        D3D_DRIVER_TYPE_REFERENCE,\n    };\n    UINT numDriverTypes = ARRAYSIZE(driverTypes);\n\n    // DX10 or 11 devices are suitable\n    D3D_FEATURE_LEVEL featureLevels[] =\n    {\n        D3D_FEATURE_LEVEL_11_0,\n        D3D_FEATURE_LEVEL_10_1,\n        D3D_FEATURE_LEVEL_10_0,\n    };\n    UINT numFeatureLevels = ARRAYSIZE(featureLevels);\n\n    for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; ++driverTypeIndex)\n    {\n        hr = D3D11CreateDevice(NULL, driverTypes[driverTypeIndex], NULL, createDeviceFlags, featureLevels, numFeatureLevels,\n            D3D11_SDK_VERSION, &m_pd3dDevice, &m_featureLevel, &m_pImmediateContext);\n\n        if ( SUCCEEDED(hr) )\n        {\n\t\t\tm_driverType = driverTypes[driverTypeIndex];\n\t\t\tbreak;\n        }\n    }\n\n    if ( FAILED(hr) )\n    {\n        MessageBox(NULL, L\"Could not create a Direct3D 10 or 11 device.\", L\"Error\", MB_ICONHAND | MB_OK);\n        return hr;\n    }\n\n    hr = LoadShaders();\n\n    if ( FAILED(hr) )\n    {\n        MessageBox(NULL, L\"Could not load shaders.\", L\"Error\", MB_ICONHAND | MB_OK);\n        return hr;\n    }\n\n\t// Create vertex buffer\n\tSimpleVertex vertices[] =\n\t{\n\t\t{ XMFLOAT3(-1.0f, 1.0f, -1.0f), XMFLOAT4(0.0f, 0.0f, 1.0f, 0.5f) },\n\t\t{ XMFLOAT3(1.0f, 1.0f, -1.0f), XMFLOAT4(0.0f, 1.0f, 0.0f, 0.5f) },\n\t\t{ XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT4(0.0f, 1.0f, 1.0f, 0.5f) },\n\t\t{ XMFLOAT3(-1.0f, 1.0f, 1.0f), XMFLOAT4(1.0f, 0.0f, 0.0f, 0.5f) },\n\t\t{ XMFLOAT3(-1.0f, -1.0f, -1.0f), XMFLOAT4(1.0f, 0.0f, 1.0f, 0.5f) },\n\t\t{ XMFLOAT3(1.0f, -1.0f, -1.0f), XMFLOAT4(1.0f, 1.0f, 0.0f, 0.5f) },\n\t\t{ XMFLOAT3(1.0f, -1.0f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 0.5f) },\n\t\t{ XMFLOAT3(-1.0f, -1.0f, 1.0f), XMFLOAT4(0.0f, 0.0f, 0.0f, 0.5f) },\n\t};\n\tD3D11_BUFFER_DESC bd;\n\tZeroMemory(&bd, sizeof(bd));\n\tbd.Usage = D3D11_USAGE_DEFAULT;\n\tbd.ByteWidth = sizeof(SimpleVertex)* 8;\n\tbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;\n\tbd.CPUAccessFlags = 0;\n\tD3D11_SUBRESOURCE_DATA InitData;\n\tZeroMemory(&InitData, sizeof(InitData));\n\tInitData.pSysMem = vertices;\n\thr = m_pd3dDevice->CreateBuffer(&bd, &InitData, &m_pVertexBuffer);\n\tif (FAILED(hr))\n\t\treturn hr;\n\n\t// Set vertex buffer\n\tUINT stride = sizeof(SimpleVertex);\n\tUINT offset = 0;\n\tm_pImmediateContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);\n\n\t// Create index buffer\n\tWORD indices[] =\n\t{\n\t\t3, 1, 0,\n\t\t2, 1, 3,\n\n\t\t0, 5, 4,\n\t\t1, 5, 0,\n\n\t\t3, 4, 7,\n\t\t0, 4, 3,\n\n\t\t1, 6, 5,\n\t\t2, 6, 1,\n\n\t\t2, 7, 6,\n\t\t3, 7, 2,\n\n\t\t6, 4, 5,\n\t\t7, 4, 6,\n\t};\n\tbd.Usage = D3D11_USAGE_DEFAULT;\n\tbd.ByteWidth = sizeof(WORD)* 36;        // 36 vertices needed for 12 triangles in a triangle list\n\tbd.BindFlags = D3D11_BIND_INDEX_BUFFER;\n\tbd.CPUAccessFlags = 0;\n\tInitData.pSysMem = indices;\n\thr = m_pd3dDevice->CreateBuffer(&bd, &InitData, &m_pIndexBuffer);\n\tif (FAILED(hr))\n\t\treturn hr;\n\n\t// Set index buffer\n\tm_pImmediateContext->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);\n\n    // Set primitive topology\n\tm_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);\n\n\t// Create the constant buffer\n\tbd.Usage = D3D11_USAGE_DEFAULT;\n\tbd.ByteWidth = sizeof(ConstantBuffer);\n\tbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;\n\tbd.CPUAccessFlags = 0;\n\thr = m_pd3dDevice->CreateBuffer(&bd, NULL, &m_pConstantBuffer);\n\tif (FAILED(hr))\n\t\treturn hr;\n\n\t// Initialize the world matrix\n\tm_World = XMMatrixIdentity();\n\n\t// Initialize the view matrix\n\tXMVECTOR Eye = XMVectorSet(0.0f, 1.0f, -5.0f, 0.0f);\n\tXMVECTOR At = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);\n\tXMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);\n\tm_View = XMMatrixLookAtLH(Eye, At, Up);\n\n    return S_OK;\n}\n\nvoid CCube::SetUpViewport()\n{\n\t// Setup the viewport\n\tD3D11_VIEWPORT vp;\n\tvp.Width = (float)m_Width;\n\tvp.Height = (float)m_Height;\n\tvp.MinDepth = 0.0f;\n\tvp.MaxDepth = 1.0f;\n\tvp.TopLeftX = 0;\n\tvp.TopLeftY = 0;\n\tm_pImmediateContext->RSSetViewports(1, &vp);\n\n\t// Initialize the projection matrix\n\tm_Projection = XMMatrixPerspectiveFovLH(XM_PIDIV4, m_Width / (FLOAT)m_Height, 0.01f, 100.0f);\n}\n\n/// <summary>\n/// Initializes RenderTarget\n/// </summary>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CCube::InitRenderTarget(void * pResource)\n{\n    HRESULT hr = S_OK;\n\n    IUnknown *pUnk = (IUnknown*)pResource;\n\n    IDXGIResource * pDXGIResource;\n    hr = pUnk->QueryInterface(__uuidof(IDXGIResource), (void**)&pDXGIResource);\n    if (FAILED(hr))\n    {\n        return hr;\n    }\n\n    HANDLE sharedHandle;\n    hr = pDXGIResource->GetSharedHandle(&sharedHandle);\n    if (FAILED(hr))\n    {\n        return hr;\n    }\n\n    pDXGIResource->Release();\n\n    IUnknown * tempResource11;\n    hr = m_pd3dDevice->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&tempResource11));\n    if (FAILED(hr))\n    {\n        return hr;\n    }\n\n    ID3D11Texture2D * pOutputResource;\n    hr = tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)(&pOutputResource));\n    if (FAILED(hr))\n    {\n        return hr;\n    }\n    tempResource11->Release();\n\n    D3D11_RENDER_TARGET_VIEW_DESC rtDesc;\n    rtDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;\n    rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;\n    rtDesc.Texture2D.MipSlice = 0;\n\n    hr = m_pd3dDevice->CreateRenderTargetView(pOutputResource, &rtDesc, &m_pRenderTargetView);\n    if (FAILED(hr))\n    {\n        return hr;\n    }\n\n    D3D11_TEXTURE2D_DESC outputResourceDesc;\n    pOutputResource->GetDesc(&outputResourceDesc);\n    if ( outputResourceDesc.Width != m_Width || outputResourceDesc.Height != m_Height )\n    {\n        m_Width = outputResourceDesc.Width;\n        m_Height = outputResourceDesc.Height;\n\n        SetUpViewport();\n    }\n\n    m_pImmediateContext->OMSetRenderTargets(1, &m_pRenderTargetView, NULL);\n\n    if ( NULL != pOutputResource )\n    {\n        pOutputResource->Release();\n    }\n\n    return hr;\n}\n\n/// <summary>\n/// Renders a frame\n/// </summary>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CCube::Render(void * pResource, bool isNewSurface)\n{\n    HRESULT hr = S_OK;\n\n    // If we've gotten a new Surface, need to initialize the renderTarget.\n    // One of the times that this happens is on a resize.\n    if ( isNewSurface )\n    {\n        m_pImmediateContext->OMSetRenderTargets(0, NULL, NULL);\n        hr = InitRenderTarget(pResource);\n        if (FAILED(hr))\n        {\n            return hr;\n        }\n    }\n\n\t// Update our time\n\tstatic float t = 0.0f;\n\tif (m_driverType == D3D_DRIVER_TYPE_REFERENCE)\n\t{\n\t\tt += (float)XM_PI * 0.0125f;\n\t}\n\telse\n\t{\n\t\tstatic DWORD dwTimeStart = 0;\n\t\tDWORD dwTimeCur = GetTickCount();\n\t\tif (dwTimeStart == 0)\n\t\t\tdwTimeStart = dwTimeCur;\n\t\tt = (dwTimeCur - dwTimeStart) / 1000.0f;\n\t}\n\n\t//\n\t// Animate the cube\n\t//\n\tm_World = XMMatrixRotationX(t) * XMMatrixRotationY(t);\n\n    // Clear the back buffer\n    static float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };\n    m_pImmediateContext->ClearRenderTargetView(m_pRenderTargetView, ClearColor);\n\n    // Update the view matrix\n    m_camera.Update();\n\n    XMMATRIX viewProjection = XMMatrixMultiply(m_camera.View, m_Projection);\n\t\n\tConstantBuffer cb;\n\tcb.mWorld = XMMatrixTranspose(m_World);\n\tcb.mView = XMMatrixTranspose(m_View);\n\tcb.mProjection = XMMatrixTranspose(viewProjection);\n\tm_pImmediateContext->UpdateSubresource(m_pConstantBuffer, 0, NULL, &cb, 0, 0);\n\n\t// Renders a triangle\n\tm_pImmediateContext->VSSetShader(m_pVertexShader, NULL, 0);\n\tm_pImmediateContext->VSSetConstantBuffers(0, 1, &m_pConstantBuffer);\n\tm_pImmediateContext->PSSetShader(m_pPixelShader, NULL, 0);\n\tm_pImmediateContext->DrawIndexed(36, 0, 0);        // 36 vertices needed for 12 triangles in a triangle list\n\n    if ( NULL != m_pImmediateContext )\n    {\n        m_pImmediateContext->Flush();\n    }\n\n    return 0;\n}\n\n/// <summary>\n/// Method for retreiving the camera\n/// </summary>\n/// <returns>Pointer to the camera</returns>\nCCamera* CCube::GetCamera()\n{\n    return &m_camera;\n}"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.fx",
    "content": "//--------------------------------------------------------------------------------------\n// File: D3DVisualization.fx\n// Originally from DirectX SDK - Tutorial 4 sample\n// Copyright (c) Microsoft Corporation. All rights reserved.\n//--------------------------------------------------------------------------------------\n\n//--------------------------------------------------------------------------------------\n// Constant Buffer Variables\n//--------------------------------------------------------------------------------------\ncbuffer ConstantBuffer : register(b0)\n{\n    matrix World;\n    matrix View;\n    matrix Projection;\n}\n\n//--------------------------------------------------------------------------------------\nstruct VS_OUTPUT\n{\n    float4 Pos : SV_POSITION;\n    float4 Color : COLOR0;\n};\n\n//--------------------------------------------------------------------------------------\n// Vertex Shader\n//--------------------------------------------------------------------------------------\nVS_OUTPUT VS(float4 Pos : POSITION, float4 Color : COLOR)\n{\n    VS_OUTPUT output = (VS_OUTPUT)0;\n    output.Pos = mul(Pos, World);\n    output.Pos = mul(output.Pos, View);\n    output.Pos = mul(output.Pos, Projection);\n    output.Color = Color;\n    return output;\n}\n\n\n//--------------------------------------------------------------------------------------\n// Pixel Shader\n//--------------------------------------------------------------------------------------\nfloat4 PS(VS_OUTPUT input) : SV_Target\n{\n    return input.Color;\n}\n"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.h",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"D3DVizualization.h\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#pragma once\n\n#include <windows.h>\n#include <d3d11.h>\n\n#ifdef DIRECTX_SDK  // requires DirectX SDK June 2010\n    #include <xnamath.h>\n    #define DirectX_NS                 // DirectX SDK requires a blank namespace for several types\n#else // Windows SDK\n    #include <DirectXMath.h>\n    #include <DirectXPackedVector.h>\n    #define DirectX_NS DirectX         // Windows SDK requires a DirectX namespace for several types\n#endif \n\n#include \"OrbitCamera.h\"\n#include \"DX11Utils.h\"\n#include \"resource.h\"\n\n\nextern \"C\" {\n    __declspec(dllexport) HRESULT __cdecl Init();\n}\n\nextern \"C\" {\n    __declspec(dllexport) void __cdecl Cleanup();\n}\n\nextern \"C\" {\n    __declspec(dllexport) HRESULT __cdecl Render(void * pResource, bool isNewSurface);\n}\n\nextern \"C\" {\n    __declspec(dllexport) HRESULT __cdecl SetCameraRadius(float r);\n}\n\nextern \"C\" {\n    __declspec(dllexport) HRESULT __cdecl SetCameraTheta(float theta);\n}\n\nextern \"C\" {\n    __declspec(dllexport) HRESULT __cdecl SetCameraPhi(float phi);\n}\n\nclass CCube\n{\n\npublic:\n    /// <summary>\n    /// Constructor\n    /// </summary>\n    CCube();\n\n    /// <summary>\n    /// Destructor\n    /// </summary>\n    ~CCube();\n\n    /// <summary>\n    /// Create Direct3D device and swap chain\n    /// </summary>\n    /// <returns>S_OK for success, or failure code</returns>\n    HRESULT                             InitDevice();\n\n    /// <summary>\n    /// Renders a frame\n    /// </summary>\n    /// <returns>S_OK for success, or failure code</returns>\n    HRESULT                             Render(void * pResource, bool isNewSurface);\n\n\n    /// <summary>\n    /// Method for retrieving the camera\n    /// </summary>\n    /// <returns>Pointer to the camera</returns>\n    CCamera*                            GetCamera();\n\n    // Special function definitions to ensure alignment between c# and c++ \n    void* operator new(size_t size)\n    {\n        return _aligned_malloc(size, 16);\n    }\n\n    void operator delete(void *p)\n    {\n        _aligned_free(p);\n    }\n\nprivate:\n\n    HRESULT InitRenderTarget(void * pResource);\n    void SetUpViewport();\n\n    // 3d camera\n    CCamera                             m_camera;\n\n    HINSTANCE                           m_hInst;\n    D3D_DRIVER_TYPE                     m_driverType;\n    D3D_FEATURE_LEVEL                   m_featureLevel;\n    \n    ID3D11Device*                       m_pd3dDevice;\n    ID3D11DeviceContext*                m_pImmediateContext;\n    IDXGISwapChain*                     m_pSwapChain = NULL;\n    ID3D11RenderTargetView*             m_pRenderTargetView = NULL;\n    ID3D11InputLayout*                  m_pVertexLayout;\n    ID3D11Buffer*                       m_pVertexBuffer;\n    ID3D11Buffer*                       m_pIndexBuffer = NULL;\n    ID3D11Buffer*                       m_pConstantBuffer = NULL;\n\n    DirectX_NS::XMMATRIX                 m_World;\n    DirectX_NS::XMMATRIX                 m_View;\n    DirectX_NS::XMMATRIX                 m_Projection;\n   \n    ID3D11VertexShader*                 m_pVertexShader;\n    ID3D11PixelShader*                  m_pPixelShader;\n\n    // Initial window resolution\n    UINT                                 m_Width;\n    UINT                                 m_Height;\n\n    /// <summary>\n    /// Compile and set layout for shaders\n    /// </summary>\n    /// <returns>S_OK for success, or failure code</returns>\n    HRESULT                             LoadShaders();\n};"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.rc",
    "content": "//------------------------------------------------------------------------------\n// <copyright file=\"D3DVisualization.rc\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n//Microsoft Visual C++ generated resource script.\n//\n#include \"resource.h\"\n\n#define APSTUDIO_READONLY_SYMBOLS\n/////////////////////////////////////////////////////////////////////////////\n//\n// Generated from the TEXTINCLUDE 2 resource.\n//\n#define APSTUDIO_HIDDEN_SYMBOLS\n#include \"windows.h\"\n#undef APSTUDIO_HIDDEN_SYMBOLS\n/////////////////////////////////////////////////////////////////////////////\n#undef APSTUDIO_READONLY_SYMBOLS\n\n#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\nLANGUAGE 9, 1\n#pragma code_page(1252)\n\n\n/////////////////////////////////////////////////////////////////////////////\n//\n// Dialog\n//\n\n#ifdef APSTUDIO_INVOKED\n/////////////////////////////////////////////////////////////////////////////\n//\n// TEXTINCLUDE\n//\n1 TEXTINCLUDE  \nBEGIN\n    \"resource.h\\0\"\nEND\n\n2 TEXTINCLUDE  \nBEGIN\n    \"#define APSTUDIO_HIDDEN_SYMBOLS\\r\\n\"\n    \"#include \"\"windows.h\"\"\\r\\n\"\n    \"#undef APSTUDIO_HIDDEN_SYMBOLS\\r\\n\"\n    \"\\0\"\nEND\n\n3 TEXTINCLUDE  \nBEGIN\n    \"\\r\\n\"\n    \"\\0\"\nEND\n\n#endif    // APSTUDIO_INVOKED\n\n#endif\n/////////////////////////////////////////////////////////////////////////////\n\n\n\n#ifndef APSTUDIO_INVOKED\n/////////////////////////////////////////////////////////////////////////////\n//\n// Generated from the TEXTINCLUDE 3 resource.\n//\n\n\n/////////////////////////////////////////////////////////////////////////////\n#endif    // not APSTUDIO_INVOKED\n"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"12.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\" />\n    <ClInclude Include=\"DX11Utils.h\" />\n    <ClInclude Include=\"OrbitCamera.h\" />\n    <ClInclude Include=\"Resource.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"D3DVisualization.cpp\" />\n    <ClCompile Include=\"DX11Utils.cpp\" />\n    <ClCompile Include=\"OrbitCamera.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\">\n      <EntryPointName Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n      </EntryPointName>\n      <FileType>Document</FileType>\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">true</DeploymentContent>\n    </Text>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}</ProjectGuid>\n    <RootNamespace>D3DVisualization</RootNamespace>\n    <TargetName>D3DVisualization</TargetName>\n    <TargetExt>.dll</TargetExt>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x64;$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x64;$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"DX11Utils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"OrbitCamera.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"Resource.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\">\n      <Filter>Resource Files</Filter>\n    </ResourceCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"DX11Utils.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"OrbitCamera.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"D3DVisualization.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization_dxsdk.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"12.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\" />\n    <ClInclude Include=\"DX11Utils.h\" />\n    <ClInclude Include=\"OrbitCamera.h\" />\n    <ClInclude Include=\"Resource.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"D3DVisualization.cpp\" />\n    <ClCompile Include=\"DX11Utils.cpp\" />\n    <ClCompile Include=\"OrbitCamera.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\">\n      <EntryPointName Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n      </EntryPointName>\n      <FileType>Document</FileType>\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">true</DeploymentContent>\n    </Text>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}</ProjectGuid>\n    <RootNamespace>D3DVisualization</RootNamespace>\n    <TargetName>D3DVisualization</TargetName>\n    <TargetExt>.dll</TargetExt>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x64;$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x64;$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>DIRECTX_SDK;WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization_dxsdk.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"DX11Utils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"OrbitCamera.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"Resource.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\">\n      <Filter>Resource Files</Filter>\n    </ResourceCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"DX11Utils.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"OrbitCamera.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"D3DVisualization.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization_winsdk.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\" />\n    <ClInclude Include=\"DX11Utils.h\" />\n    <ClInclude Include=\"OrbitCamera.h\" />\n    <ClInclude Include=\"Resource.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"D3DVisualization.cpp\" />\n    <ClCompile Include=\"DX11Utils.cpp\" />\n    <ClCompile Include=\"OrbitCamera.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\">\n      <EntryPointName Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n      </EntryPointName>\n      <FileType>Document</FileType>\n      <DeploymentContent Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">true</DeploymentContent>\n    </Text>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}</ProjectGuid>\n    <RootNamespace>D3DVisualization</RootNamespace>\n    <TargetName>D3DVisualization</TargetName>\n    <TargetExt>.dll</TargetExt>\n    <WindowsTargetPlatformVersion>10.0.10240.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath)</IncludePath>\n    <LibraryPath>$(LibraryPath)</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x86\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <TargetExt>.dll</TargetExt>\n    <ExecutablePath>$(DXSDK_DIR)Utilities\\bin\\x64;$(DXSDK_DIR)Utilities\\bin\\x86;$(ExecutablePath)</ExecutablePath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <OutDir>$(SolutionDir)x64\\$(Configuration)\\</OutDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x86\\$(Configuration)\\\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;d3dx11d.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n    <PostBuildEvent>\n      <Command>copy d3dvisualization.fx \"$(SolutionDir)x64\\$(Configuration)\\\"\"</Command>\n    </PostBuildEvent>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/D3DVisualization_winsdk.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3DVisualization.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"DX11Utils.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"OrbitCamera.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"Resource.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"D3DVisualization.rc\">\n      <Filter>Resource Files</Filter>\n    </ResourceCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"DX11Utils.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"OrbitCamera.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"D3DVisualization.cpp\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <Text Include=\"D3DVisualization.fx\" />\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/DX11Utils.cpp",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"DX11Utils.cpp\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#include \"DX11Utils.h\"\n\n#ifdef DIRECTX_SDK  // requires DirectX SDK June 2010\n    #include <d3dx11.h>\n#else // Windows SDK\n    #include <d3d11.h>\n    #include <D3Dcompiler.h>\n#endif \n\n/// <summary>\n/// Helper for compiling shaders with D3DX11\n/// </summary>\n/// <param name=\"szFileName\">full path to shader to compile</param>\n/// <param name=\"szEntryPoint\">entry point of shader</param>\n/// <param name=\"szShaderModel\">shader model to compile for</param>\n/// <param name=\"ppBlobOut\">holds result of compilation</param>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3D10Blob** ppBlobOut)\n{\n    HRESULT hr = S_OK;\n\n    ID3D10Blob* pErrorBlob = NULL;\n    \n#ifdef DIRECTX_SDK  // requires DirectX SDK June 2010\n    hr = D3DX11CompileFromFileW( szFileName, NULL, NULL, szEntryPoint, szShaderModel, \n        0, 0, NULL, ppBlobOut, &pErrorBlob, NULL );\n#else // Windows SDK\n    hr = D3DCompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel,\n        0, 0, ppBlobOut, &pErrorBlob);\n#endif \n\n\n    if ( FAILED(hr) )\n    {\n        if (NULL != pErrorBlob)\n        {\n            OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );\n        }\n    }\n\n    SAFE_RELEASE(pErrorBlob);\n\n    return hr;\n}"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/DX11Utils.h",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"DX11Utils.h\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#pragma once\n\n#include <windows.h>\n#include <d3d11.h>\n\n#ifndef SAFE_DELETE\n#define SAFE_DELETE(p)       { if (p) { delete (p);     (p)=NULL; } }\n#endif\n#ifndef SAFE_DELETE_ARRAY\n#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p);   (p)=NULL; } }\n#endif\n#ifndef SAFE_RELEASE\n#define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=NULL; } }\n#endif\n\n/// <summary>\n/// Helper for compiling shaders with D3DX11\n/// </summary>\n/// <param name=\"szFileName\">full path to shader to compile</param>\n/// <param name=\"szEntryPoint\">entry point of shader</param>\n/// <param name=\"szShaderModel\">shader model to compile for</param>\n/// <param name=\"ppBlobOut\">holds result of compilation</param>\n/// <returns>S_OK for success, or failure code</returns>\nHRESULT CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3D10Blob** ppBlobOut );"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/OrbitCamera.cpp",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"OrbitCamera.cpp\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#include \"OrbitCamera.h\"\n\n#ifndef DIRECTX_SDK  // Windows SDK\n    using namespace DirectX;\n    using namespace DirectX::PackedVector;\n#endif \n\n/// <summary>\n/// Constructor\n/// </summary>\nCCamera::CCamera()\n{\n    Reset();\n}\n\n/// <summary>\n/// Move camera into position\n/// </summary>\nint CCamera::UpdatePosition()\n{\n    m_eye = XMVectorSet(r * sinf(theta) * cosf(phi), r * sinf(phi), -r * cosf(theta) * cosf(phi), 0.0F);\n\n    return 0;\n}\n\n/// <summary>\n/// Reset the camera state to initial values\n/// </summary>\nvoid CCamera::Reset()\n{\n    View       = XMMatrixIdentity();\n\n    m_eye      = XMVectorSet(0.f, 0.f, -0.3f, 0.f);\n    m_at       = XMVectorSet(0.f, 0.f,  1.0f, 0.f);\n    m_up       = XMVectorSet(0.f, 1.f,   0.f, 0.f);\n}\n\n/// <summary>\n/// Update the view matrix\n/// </summary>\nvoid CCamera::Update()\n{\n    View = XMMatrixLookAtLH(m_eye + m_at, m_at, m_up);\n}\n\n/// <summary>\n/// Sets the center depth of the rendered image\n/// </summary>\nvoid CCamera::SetCenterDepth(float depth)\n{\n    m_at = XMVectorSet(0.0f, 0.0f, depth, 0.0f);\n}\n\n/// <summary>\n/// Sets the R value of the camera from the depth center\n/// R value represents the distance of the camera from the players\n/// </summary>\nvoid CCamera::SetRadius(float r)\n{\n    this->r = r;\n    UpdatePosition();\n}\n\n/// <summary>\n/// Sets the Theta value of the camera from around the depth center\n/// Theta represents the angle (in radians) of the camera around the \n/// center in the x-y plane (circling around players)\n/// </summary>\nvoid CCamera::SetTheta(float theta)\n{\n    this->theta = theta;\n    UpdatePosition();\n}\n\n/// <summary>\n/// Sets the Phi value of the camera\n/// Phi represents angle (in radians) of the camera around the center \n/// in the y-z plane (over the top and below players)\n/// </summary>\nvoid CCamera::SetPhi(float phi)\n{\n    this->phi = phi;\n    UpdatePosition();\n}"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/OrbitCamera.h",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"OrbitCamera.h\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n#pragma once\n\n#include <windows.h>\n\n#ifdef DIRECTX_SDK  // requires DirectX SDK June 2010\n    #include <xnamath.h>\n    #define DirectX_NS                 // DirectX SDK requires a blank namespace for several types\n#else // Windows SDK\n    #include <DirectXMath.h>\n    #include <DirectXPackedVector.h>\n    #define DirectX_NS DirectX         // Windows SDK requires a DirectX namespace for several types\n#endif \n\n\nclass CCamera\n{\npublic:\n    DirectX_NS::XMMATRIX View;\n\n    /// <summary>\n    /// Constructor\n    /// </summary>\n    CCamera();\n\n    /// <summary>\n    /// Reset the camera state to initial values\n    /// </summary>\n    void Reset();\n\n    /// <summary>\n    /// Update the view matrix\n    /// </summary>\n    void Update();\n\n    /// <summary>\n    /// Move camera into position\n    /// </summary>\n    int UpdatePosition();\n\n    /// <summary>\n    /// Sets the R value of the camera.\n    /// R value represents the distance of the camera from the center\n    /// </summary>\n    void SetRadius(float r);\n\n    /// <summary>\n    /// Sets the Theta value of the camera from around the depth center\n    /// Theta represents the angle (in radians) of the camera around the \n    /// center in the x-y plane (circling around players)\n    /// </summary>\n    void SetTheta(float theta);\n\n    /// <summary>\n    /// Sets the Phi value of the camera\n    /// Phi represents angle (in radians) of the camera around the center \n    /// in the y-z plane (over the top and below players)\n    /// </summary>\n    void SetPhi(float phi);\n\n    /// <summary>\n    /// Get the camera's up vector\n    /// </summary>\n    /// <returns>camera's up vector</returns>\n    DirectX_NS::XMVECTOR  GetUp() { return m_up; }\n\n    /// <summary>\n    /// Get the camera's position vector\n    /// </summary>\n    /// <returns>camera's position vector</returns>\n    DirectX_NS::XMVECTOR  GetEye() { return m_eye; }\n\n    /// <summary>\n    /// Sets the center depth of the rendered image\n    /// </summary>\n    void SetCenterDepth(float depth);\n\nprivate:\n    float r;\n    float theta;\n    float phi;\n\n    DirectX_NS::XMVECTOR  m_eye;\n    DirectX_NS::XMVECTOR  m_at;\n    DirectX_NS::XMVECTOR  m_up;\n};"
  },
  {
    "path": "samples/D3D11Image/D3D11Visualization/Resource.h",
    "content": "﻿//------------------------------------------------------------------------------\n// <copyright file=\"resource.h\" company=\"Microsoft\">\n//     Copyright (c) Microsoft Corporation.  All rights reserved.\n// </copyright>\n//------------------------------------------------------------------------------\n\n//{{NO_DEPENDENCIES}}\n// Microsoft Visual C++ generated include file.\n// Used by Depth-D3D.rc\n//\n\n#define IDS_APP_TITLE           103\n\n#define IDI_APP                 107\n#define IDC_STATIC              -1\n// Next default values for new objects\n// \n#ifdef APSTUDIO_INVOKED\n#ifndef APSTUDIO_READONLY_SYMBOLS\n\n#define _APS_NO_MFC                 130\n#define _APS_NEXT_RESOURCE_VALUE    129\n#define _APS_NEXT_COMMAND_VALUE     32771\n#define _APS_NEXT_CONTROL_VALUE     1000\n#define _APS_NEXT_SYMED_VALUE       110\n#endif\n#endif\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/App.xaml",
    "content": "﻿<Application x:Class=\"Microsoft.Samples.Wpf.D3D11Interop.App\"\n             xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n             xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n             StartupUri=\"MainWindow.xaml\">\n    <Application.Resources>\n         \n    </Application.Resources>\n</Application>\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/App.xaml.cs",
    "content": "﻿namespace Microsoft.Samples.Wpf.D3D11Interop\n{\n    using System.Windows;\n\n    /// <summary>\n    /// Interaction logic for App.xaml\n    /// </summary>\n    public partial class App : Application\n    {\n    }\n}\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/MainWindow.xaml",
    "content": "﻿<Window x:Class=\"Microsoft.Samples.Wpf.D3D11Interop.MainWindow\"\n        xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n        xmlns:dx=\"clr-namespace:Microsoft.Wpf.Interop.DirectX;assembly=Microsoft.Wpf.Interop.DirectX\"\n        Title=\"WPF D3D11 Interop\" Height=\"540\" Width=\"900\" Closing=\"Window_Closing\">\n\n    <Window.Resources>\n        <SolidColorBrush x:Key=\"MediumGreyBrush\" Color=\"#ff4e4e4e\"/>\n        <SolidColorBrush x:Key=\"KinectPurpleBrush\" Color=\"#ff52318f\"/>\n        <Style TargetType=\"{x:Type CheckBox}\" x:Key=\"SquareCheckBox\">\n            <Setter Property=\"Template\">\n                <Setter.Value>\n                    <ControlTemplate TargetType=\"{x:Type CheckBox}\">\n                        <Grid>\n                            <StackPanel Orientation=\"Horizontal\" Background=\"Transparent\">\n                                <Grid x:Name=\"SquareCheckBoxChecked\">\n                                    <Image x:Name=\"CheckedNormal\" Source=\"Images\\Checkbox_checked.png\" Stretch=\"None\" HorizontalAlignment=\"Center\"/>\n                                </Grid>\n                                <Grid x:Name=\"SquareCheckBoxUnchecked\" Visibility=\"Collapsed\">\n                                    <Image x:Name=\"UncheckedNormal\" Source=\"Images\\Checkbox_unchecked.png\" Stretch=\"None\" HorizontalAlignment=\"Center\"/>\n                                </Grid>\n                                <TextBlock x:Name=\"SquareCheckBoxText\" Text=\"Recreate Surface on Resize\" TextAlignment=\"Left\"  VerticalAlignment=\"Center\" FontSize=\"15\"  Margin=\"9,0,0,0\"/>\n                            </StackPanel>\n                        </Grid>\n                        <ControlTemplate.Triggers>\n                            <Trigger Property=\"IsChecked\" Value=\"false\">\n                                <Setter Property=\"Visibility\" Value=\"Collapsed\" TargetName=\"SquareCheckBoxChecked\"/>\n                                <Setter Property=\"Visibility\" Value=\"Visible\" TargetName=\"SquareCheckBoxUnchecked\"/>\n                            </Trigger>\n                        </ControlTemplate.Triggers>\n                    </ControlTemplate>\n                </Setter.Value>\n            </Setter>\n        </Style>\n\n        <Style TargetType=\"{x:Type RadioButton}\" x:Key=\"KinectRadioButton\">\n            <Setter Property=\"Template\">\n                <Setter.Value>\n                    <ControlTemplate TargetType=\"{x:Type RadioButton}\">\n                        <Grid>\n                            <Grid x:Name=\"KinectRadioButtonOnSet\" HorizontalAlignment=\"Left\">\n                                <Image Source=\"Images\\radiobutton_on.png\" Stretch=\"None\"/>\n                            </Grid>\n                            <Grid x:Name=\"KinectRadioButtonOnUnset\" HorizontalAlignment=\"Left\" Visibility=\"Collapsed\">\n                                <Image Source=\"Images\\radiobutton_off.png\" Stretch=\"None\"/>\n                            </Grid>\n                            <TextBlock x:Name=\"KinectRadioButton\" Text=\"{TemplateBinding Content}\" TextAlignment=\"Left\"  VerticalAlignment=\"Center\" FontSize=\"15\"  Margin=\"25,0,0,0\"/>\n                        </Grid>\n                        <ControlTemplate.Triggers>\n                            <Trigger Property=\"IsChecked\" Value=\"false\">\n                                <Setter Property=\"Visibility\" Value=\"Collapsed\" TargetName=\"KinectRadioButtonOnSet\"/>\n                                <Setter Property=\"Visibility\" Value=\"Visible\" TargetName=\"KinectRadioButtonOnUnset\"/>\n                            </Trigger>\n                        </ControlTemplate.Triggers>\n                    </ControlTemplate>\n                </Setter.Value>\n            </Setter>\n        </Style>\n\n        <!--Create a slider background like the standard one-->\n        <LinearGradientBrush x:Key=\"HorizontalSliderTrackNormalBorder\" EndPoint=\"0,1\" StartPoint=\"0,0\">\n            <GradientStop Color=\"#FFAEB1AF\" Offset=\"0.1\"/>\n            <GradientStop Color=\"White\" Offset=\".9\"/>\n        </LinearGradientBrush>\n\n        <Style x:Key=\"KinectSlider\" \n           TargetType=\"{x:Type Slider}\">\n            <Setter Property=\"Orientation\" Value=\"Horizontal\" />\n            <Setter Property=\"Template\">\n                <Setter.Value>\n                    <ControlTemplate TargetType=\"{x:Type Slider}\">\n                        <Grid>\n                            <Border Background=\"#FFE7EAEA\" BorderBrush=\"{StaticResource HorizontalSliderTrackNormalBorder}\" BorderThickness=\"1\" CornerRadius=\"1\" Margin=\"5,0\" Height=\"4.0\" Grid.Row=\"1\"/>\n                            <Track Visibility=\"Visible\" x:Name=\"PART_Track\">\n                                <Track.Thumb>\n                                    <Thumb>\n                                        <Thumb.Template>\n                                            <ControlTemplate>\n                                                <Image Source=\"Images/Slider.png\"/>\n                                            </ControlTemplate>\n                                        </Thumb.Template>\n                                    </Thumb>\n                                </Track.Thumb>\n                            </Track>\n                        </Grid>\n                    </ControlTemplate>\n                </Setter.Value>\n            </Setter>\n        </Style>\n    </Window.Resources>\n\n    <Grid Margin=\"10,0,10,10\">\n        <Grid.RowDefinitions>\n            <RowDefinition Height=\"62\" />\n            <RowDefinition Height=\"*\" />\n        </Grid.RowDefinitions>\n        <Grid Grid.Row=\"1\">\n            <Grid.ColumnDefinitions>\n                <ColumnDefinition Width=\"*\" />\n                <ColumnDefinition Width=\"250\" />\n            </Grid.ColumnDefinitions>\n\n            <Grid Grid.Row=\"1\" ClipToBounds=\"True\">\n                <Border Name=\"ControlHostElement\"\n                 BorderBrush=\"{StaticResource KinectPurpleBrush}\"\n                 BorderThickness=\"2\" HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\">\n                    <Grid x:Name=\"host\" Cursor=\"None\">\n                        <Rectangle Grid.Column=\"0\" Fill=\"Black\"/>\n                        <Image Name =\"Backdrop\" Source=\"Images\\Background.jpg\"/>\n                        <Image Stretch=\"Fill\" Name=\"ImageHost\" >\n                            <Image.Source>\n                                <dx:D3D11Image x:Name=\"InteropImage\" />\n                            </Image.Source>\n                        </Image>\n                    </Grid>\n                </Border>\n                <Canvas x:Name=\"MagCurserToggle2\">\n                    <Ellipse x:Name=\"MagEllipse\" Visibility=\"Hidden\">\n                        <Ellipse.Fill>\n                            <VisualBrush x:Name=\"MagBrush\" ViewboxUnits=\"Absolute\"\n                                        Visual=\"{Binding ElementName=ControlHostElement}\"/>\n                        </Ellipse.Fill>\n                    </Ellipse>\n                </Canvas>\n                <Canvas x:Name=\"MagCurserToggle1\" Cursor=\"None\">\n                    <Image Name =\"MagImage\" Source=\"Images\\MagnifyingGlass.png\" Visibility=\"Hidden\"/>\n                </Canvas>\n            </Grid>\n\n            <Rectangle Grid.Column=\"1\" Fill=\"{StaticResource MediumGreyBrush}\" Margin=\"10,0,0,0\"/>\n            <StackPanel Grid.Column=\"1\">\n                <Grid Margin=\"20,10,10,10\">\n                    <Grid.RowDefinitions>\n                        <RowDefinition Height=\"35\"/>\n                        <RowDefinition Height=\"*\"/>\n                        <RowDefinition Height=\"15\"/>\n                        <RowDefinition Height=\"25\"/>\n                        <RowDefinition Height=\"15\"/>\n                        <RowDefinition Height=\"25\"/>\n                        <RowDefinition Height=\"50\"/>\n                        <RowDefinition Height=\"35\"/>\n                        <RowDefinition Height=\"25\"/>\n                        <RowDefinition Height=\"15\"/>\n                        <RowDefinition Height=\"25\"/>\n                        <RowDefinition Height=\"15\"/>\n                        <RowDefinition Height=\"25\"/>\n                    </Grid.RowDefinitions>\n                    <TextBlock Grid.Row=\"0\" Text=\"Magnifier\" HorizontalAlignment=\"Left\" FontSize=\"20\" FontFamily=\"Segeo UI\" Foreground=\"White\"/>\n                    <RadioButton Grid.Row=\"1\" x:Name=\"MagBox\" Style=\"{StaticResource KinectRadioButton}\" IsChecked=\"True\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Content=\"On\"/>\n                    <RadioButton Grid.Row=\"1\" x:Name=\"MagBox2\" Style=\"{StaticResource KinectRadioButton}\" IsChecked=\"False\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Content=\"Off\" Margin=\"60,0\"/>\n                    <Label Grid.Row=\"3\" HorizontalAlignment=\"Left\" Content=\"_Size\"  VerticalAlignment=\"Center\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Target=\"{Binding ElementName=Size}\"/>\n                    <Slider Grid.Row=\"3\" x:Name=\"Size\" Style=\"{StaticResource KinectSlider}\" Minimum=\"30\" Maximum=\"300\" Value=\"100\"  ValueChanged=\"Size_ValueChanged\" Margin=\"50,0,30,0\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\"/>\n                    <Label Grid.Row=\"5\" HorizontalAlignment=\"Left\" Content=\"_Scale\"  VerticalAlignment=\"Center\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Target=\"{Binding ElementName=Scale}\"/>\n                    <Slider Grid.Row=\"5\" x:Name=\"Scale\" Style=\"{StaticResource KinectSlider}\" Minimum=\"1\" Value=\"2\" Maximum=\"5\" ValueChanged=\"Scale_ValueChanged\" Margin=\"50,0,30,0\"/>\n                    <TextBlock Grid.Row=\"7\" Text=\"Camera Position\" HorizontalAlignment=\"Left\" FontSize=\"20\" FontFamily=\"Segeo UI\" Foreground=\"White\"/>\n                    <Label Grid.Row=\"8\" Content=\"_Radius\" VerticalAlignment=\"Center\" HorizontalAlignment=\"Left\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Target=\"{Binding ElementName=RadiusSlider}\"/>\n                    <Slider Grid.Row=\"8\" x:Name=\"RadiusSlider\" Style=\"{StaticResource KinectSlider}\" ValueChanged=\"Radius_ValueChanged\" Minimum=\".1\" Value=\"2\" Maximum=\"5\" Margin=\"50,0,30,0\" DataContext=\"{Binding}\" />\n                    <Label Grid.Row=\"10\" Content=\"_Theta\"  VerticalAlignment=\"Center\" HorizontalAlignment=\"Left\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Target=\"{Binding ElementName=ThetaSlider}\"/>\n                    <Slider Grid.Row=\"10\" x:Name=\"ThetaSlider\"  Style=\"{StaticResource KinectSlider}\" ValueChanged=\"Theta_ValueChanged\" Minimum=\"-180\" Maximum=\"180\" Value=\"0\" Margin=\"50,0,30,0\"/>\n                    <Label Grid.Row=\"12\" Content=\"_Phi\" VerticalAlignment=\"Center\" HorizontalAlignment=\"Left\" FontSize=\"12\" FontFamily=\"Segeo UI\" Foreground=\"White\" Target=\"{Binding ElementName=PhiSlider}\"/>\n                    <Slider Grid.Row=\"12\" x:Name=\"PhiSlider\" Style=\"{StaticResource KinectSlider}\" ValueChanged=\"Phi_ValueChanged\" Minimum=\"-89.9\" Maximum=\"89.9\" Value=\"0\" Margin=\"50,0,30,0\"/>\n                </Grid>\n            </StackPanel>\n        </Grid>\n        \n        <TextBlock Text=\"WPF D3D11 Interop\" HorizontalAlignment=\"Right\" VerticalAlignment=\"Bottom\" Margin=\"0,0,0,17\" FontSize=\"14\" Foreground=\"{StaticResource MediumGreyBrush}\" FontFamily=\"Segoe UI\"/>\n    </Grid>\n</Window>\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/MainWindow.xaml.cs",
    "content": "﻿namespace Microsoft.Samples.Wpf.D3D11Interop\n{\n    using System;\n    using System.Runtime.InteropServices;\n    using System.Windows;\n    using System.Windows.Input;\n    using System.Windows.Interop;\n    using System.Windows.Media;\n\n    /// <summary>\n    /// Interaction logic for MainWindow.xaml\n    /// </summary>\n    public partial class MainWindow : Window\n    {\n        // Magnifier Image Settings\n        private const double MagImageScale = 1.25; // Scale of image to magnified ellipse\n        private const double MagImageOffset = 0.12; // Offset of magnified ellipse within image\n\n        // Unit conversion\n        private const float DegreesToRadians = (float)Math.PI / 180;\n\n        // State Management\n        private bool magnify = true;\n        TimeSpan lastRender;\n        bool lastVisible;\n\n        // Magnifier Settings (filled by default slider vlaues)\n        private double magSize;\n        private double magScale;\n\n        public MainWindow()\n        {\n            this.InitializeComponent();\n            this.host.Loaded += new RoutedEventHandler(this.Host_Loaded);\n            this.host.SizeChanged += new SizeChangedEventHandler(this.Host_SizeChanged);\n        }\n        \n        private static bool Init()\n        {\n            \n            bool initSucceeded = NativeMethods.InvokeWithDllProtection(() => NativeMethods.Init()) >= 0;\n            \n            if (!initSucceeded)\n            {\n                MessageBox.Show(\"Failed to initialize.\", \"WPF D3D Interop\", MessageBoxButton.OK, MessageBoxImage.Error);\n\n                if (Application.Current != null)\n                {\n                    Application.Current.Shutdown();\n                }\n            }\n\n            return initSucceeded;\n        }\n\n        private static void Cleanup()\n        {\n            NativeMethods.InvokeWithDllProtection(NativeMethods.Cleanup);\n        }\n\n        private static int Render(IntPtr resourcePointer, bool isNewSurface)\n        {\n            return NativeMethods.InvokeWithDllProtection(() => NativeMethods.Render(resourcePointer, isNewSurface));      \n        }\n\n        private static int SetCameraRadius(float radius)\n        {\n            return NativeMethods.InvokeWithDllProtection(() => NativeMethods.SetCameraRadius(radius));\n        }\n\n        private static int SetCameraTheta(float theta)\n        {\n            return NativeMethods.InvokeWithDllProtection(() => NativeMethods.SetCameraTheta(theta));    \n        }\n\n        private static int SetCameraPhi(float phi)\n        {\n            return NativeMethods.InvokeWithDllProtection(() => NativeMethods.SetCameraPhi(phi));\n        }\n\n        #region Callbacks\n        private void Host_Loaded(object sender, RoutedEventArgs e)\n        {\n            Init();\n            this.InitializeRendering();\n\n            // Setup the Magnifier Size\n            MagEllipse.Height = this.magSize;\n            MagEllipse.Width = this.magSize;\n            Scale.Value = this.magScale;\n\n            // Add mouse over event\n            host.MouseMove += this.MagElement_MouseMove;\n            ImageHost.MouseMove += this.MagElement_MouseMove;\n            MagEllipse.MouseMove += this.MagElement_MouseMove;\n            MagImage.MouseMove += this.MagElement_MouseMove;\n\n            host.MouseLeave += this.MagElement_MouseLeave;\n            MagEllipse.MouseLeave += this.MagElement_MouseLeave;\n            ImageHost.MouseLeave += this.MagElement_MouseLeave;\n            MagImage.MouseLeave += this.MagElement_MouseLeave;\n\n            MagBox.Checked += this.MagBox_Checked;\n            MagBox.Unchecked += this.MagBox_Unchecked;\n        }\n\n        private void Host_SizeChanged(object sender, SizeChangedEventArgs e)\n        {\n            double dpiScale = 1.0; // default value for 96 dpi\n\n            // determine DPI\n            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)\n            var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;\n            if (hwndTarget != null)\n            {\n                dpiScale = hwndTarget.TransformToDevice.M11;\n            }\n\n            int surfWidth = (int)(host.ActualWidth < 0 ? 0 : Math.Ceiling(host.ActualWidth * dpiScale));\n            int surfHeight = (int)(host.ActualHeight < 0 ? 0 : Math.Ceiling(host.ActualHeight * dpiScale));\n\n            // Notify the D3D11Image of the pixel size desired for the DirectX rendering.\n            // The D3DRendering component will determine the size of the new surface it is given, at that point.\n            InteropImage.SetPixelSize(surfWidth, surfHeight);\n                \n            // Stop rendering if the D3DImage isn't visible - currently just if width or height is 0\n            // TODO: more optimizations possible (scrolled off screen, etc...)\n            bool isVisible = (surfWidth != 0 && surfHeight != 0);\n            if (lastVisible != isVisible)\n            {\n                lastVisible = isVisible;\n                if (lastVisible)\n                {\n                    CompositionTarget.Rendering += CompositionTarget_Rendering;\n                }\n                else\n                {\n                    CompositionTarget.Rendering -= CompositionTarget_Rendering;\n                }\n            }\n        }\n\n        private void Scale_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\n        {\n            this.magScale = e.NewValue;\n        }\n\n        private void Size_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\n        {\n            this.magSize = e.NewValue;\n\n            // Setup the Magnifier Size\n            this.MagEllipse.Height = this.magSize;\n            this.MagEllipse.Width = this.magSize;\n        }\n\n        private void MagBox_Checked(object sender, RoutedEventArgs e)\n        {\n            this.magnify = true;\n\n            MagCurserToggle1.Cursor = System.Windows.Input.Cursors.None;\n            MagCurserToggle2.Cursor = System.Windows.Input.Cursors.None;\n            host.Cursor = System.Windows.Input.Cursors.None;\n        }\n\n        private void MagBox_Unchecked(object sender, RoutedEventArgs e)\n        {\n            this.magnify = false;\n\n            MagCurserToggle1.Cursor = System.Windows.Input.Cursors.Arrow;\n            MagCurserToggle2.Cursor = System.Windows.Input.Cursors.Arrow;\n            host.Cursor = System.Windows.Input.Cursors.Arrow;\n        }\n\n        private void MagElement_MouseMove(object sender, MouseEventArgs e)\n        {\n            if (this.magnify)\n            {\n                Point point = Mouse.GetPosition(host);\n\n                if (!(point.X < 0 || point.Y < 0 || point.X > host.ActualWidth || point.Y > host.ActualHeight))\n                {\n                    // Draw the Magnified ellipse on top of image\n                    System.Windows.Controls.Canvas.SetTop(this.MagEllipse, point.Y - (this.magSize / 2));\n                    System.Windows.Controls.Canvas.SetLeft(this.MagEllipse, point.X - (this.magSize / 2));\n\n                    // Set the magnifier image on top of magnified ellipse \n                    System.Windows.Controls.Canvas.SetTop(this.MagImage, point.Y - (this.magSize * (.5 + MagImageOffset)));\n                    System.Windows.Controls.Canvas.SetLeft(this.MagImage, point.X - (this.magSize * (.5 + MagImageOffset)));\n                    MagImage.Width = this.magSize * MagImageScale;\n\n                    MagEllipse.Visibility = System.Windows.Visibility.Visible;\n                    MagImage.Visibility = System.Windows.Visibility.Visible;\n\n                    double magViewboxSize = this.magSize / this.magScale;\n                    MagBrush.Viewbox = new Rect(point.X - (.5 * magViewboxSize), point.Y - (.5 * magViewboxSize), magViewboxSize, magViewboxSize);\n                }\n                else\n                {\n                    MagEllipse.Visibility = Visibility.Hidden;\n                    MagImage.Visibility = Visibility.Hidden;\n                }\n            }\n        }\n\n        private void MagElement_MouseLeave(object sender, MouseEventArgs e)\n        {\n            MagEllipse.Visibility = Visibility.Hidden;\n            MagImage.Visibility = Visibility.Hidden;\n        }\n\n        private void Radius_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\n        {\n            SetCameraRadius((float)e.NewValue);\n        }\n\n        private void Theta_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\n        {\n            SetCameraTheta((float)e.NewValue * DegreesToRadians);\n        }\n\n        private void Phi_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\n        {\n            SetCameraPhi((float)e.NewValue * DegreesToRadians);\n        }\n        #endregion Callbacks\n\n        #region Helpers\n        private void InitializeRendering()\n        {\n            InteropImage.WindowOwner = (new System.Windows.Interop.WindowInteropHelper(this)).Handle;\n            InteropImage.OnRender = this.DoRender;\n\n            // Set up camera\n            SetCameraRadius((float)RadiusSlider.Value);\n            SetCameraPhi((float)PhiSlider.Value * DegreesToRadians);\n            SetCameraTheta((float)ThetaSlider.Value * DegreesToRadians);\n\n            // Start rendering now!\n            InteropImage.RequestRender();\n        }\n\n        void CompositionTarget_Rendering(object sender, EventArgs e)\n        {\n            RenderingEventArgs args = (RenderingEventArgs)e;\n\n            // It's possible for Rendering to call back twice in the same frame \n            // so only render when we haven't already rendered in this frame.\n            if (this.lastRender != args.RenderingTime)\n            {\n                InteropImage.RequestRender();\n                this.lastRender = args.RenderingTime;\n            }\n        }\n\n        private void UninitializeRendering()\n        {\n            Cleanup();\n\n            CompositionTarget.Rendering -= this.CompositionTarget_Rendering;\n        }\n        #endregion Helpers\n\n        private void DoRender(IntPtr surface, bool isNewSurface)\n        {\n            Render(surface, isNewSurface);\n        }\n\n        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)\n        {\n            this.UninitializeRendering();\n\n            host.MouseMove -= this.MagElement_MouseMove;\n            ImageHost.MouseMove -= this.MagElement_MouseMove;\n            MagEllipse.MouseMove -= this.MagElement_MouseMove;\n            MagImage.MouseMove -= this.MagElement_MouseMove;\n\n            host.MouseLeave -= this.MagElement_MouseLeave;\n            MagEllipse.MouseLeave -= this.MagElement_MouseLeave;\n            ImageHost.MouseLeave -= this.MagElement_MouseLeave;\n            MagImage.MouseLeave -= this.MagElement_MouseLeave;\n\n            MagBox.Checked -= this.MagBox_Checked;\n            MagBox.Unchecked -= this.MagBox_Unchecked;\n        }\n\n        private static class NativeMethods\n        {\n            /// <summary>\n            /// Variable used to track whether the missing dependency dialog has been displayed,\n            /// used to prevent multiple notifications of the same failure.\n            /// </summary>\n            private static bool errorHasDisplayed;\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern int Init();\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern void Cleanup();\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern int Render(IntPtr resourcePointer, bool isNewSurface);\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern int SetCameraRadius(float radius);\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern int SetCameraTheta(float theta);\n\n            [DllImport(\"D3DVisualization.dll\", CallingConvention = CallingConvention.Cdecl)]\n            public static extern int SetCameraPhi(float phi);\n\n            /// <summary>\n            /// Method used to invoke an Action that will catch DllNotFoundExceptions and display a warning dialog.\n            /// </summary>\n            /// <param name=\"action\">The Action to invoke.</param>\n            public static void InvokeWithDllProtection(Action action)\n            {\n                InvokeWithDllProtection(\n                    () => \n                    { \n                        action.Invoke();\n                        return 0;\n                    }); \n            }\n\n            /// <summary>\n            /// Method used to invoke A Func that will catch DllNotFoundExceptions and display a warning dialog.\n            /// </summary>\n            /// <param name=\"func\">The Func to invoke.</param>\n            /// <returns>The return value of func, or default(T) if a DllNotFoundException was caught.</returns>\n            /// <typeparam name=\"T\">The return type of the func.</typeparam>\n            public static T InvokeWithDllProtection<T>(Func<T> func)\n            {\n                try\n                {\n                    return func.Invoke();\n                }\n                catch (DllNotFoundException e)\n                {\n                    if (!errorHasDisplayed)\n                    {\n                        MessageBox.Show(\"This sample requires:\\nManual build of the D3DVisualization project, which requires installation of Windows 10 SDK or DirectX SDK.\\n\" +\n                                        \"Installation of the DirectX runtime on non-build machines.\\n\\n\"+\n                                        \"Detailed exception message: \" + e.Message, \"WPF D3D11 Interop\",\n                                        MessageBoxButton.OK, MessageBoxImage.Error);\n                        errorHasDisplayed = true;\n\n                        if (Application.Current != null)\n                        {\n                            Application.Current.Shutdown();                            \n                        }\n                    }\n                }\n\n                return default(T);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/Properties/AssemblyInfo.cs",
    "content": "﻿using System;\nusing System.Reflection;\nusing System.Resources;\nusing System.Runtime.InteropServices;\nusing System.Windows;\n\n// General Information about an assembly is controlled through the following \n// set of attributes. Change these attribute values to modify the information\n// associated with an assembly.\n[assembly: AssemblyTitle(\"Wpf D3D11 Interop Sample\")]\n\n// Setting ComVisible to false makes the types in this assembly not visible \n// to COM components.  If you need to access a type in this assembly from \n// COM, set the ComVisible attribute to true on that type.\n[assembly: ComVisible(false)]\n\n// In order to begin building localizable applications, set \n// <UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file\n// inside a <PropertyGroup>.  For example, if you are using US english\n// in your source files, set the <UICulture> to en-US.  Then uncomment\n// the NeutralResourceLanguage attribute below.  Update the \"en-US\" in\n// the line below to match the UICulture setting in the project file.\n\n////[assembly: NeutralResourcesLanguage(\"en-US\", UltimateResourceFallbackLocation.Satellite)]\n\n\n[assembly: ThemeInfo(\n    ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located\n    // (used if a resource is not found in the page, \n    // or application resource dictionaries)\n    ResourceDictionaryLocation.SourceAssembly // where the generic resource dictionary is located\n    // (used if a resource is not found in the page, \n    // app, or any theme specific resource dictionaries)\n)]\n\n[assembly: NeutralResourcesLanguageAttribute(\"en-US\")]\n[assembly: CLSCompliant(true)]\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/Properties/Resources.Designer.cs",
    "content": "﻿//------------------------------------------------------------------------------\n// <auto-generated>\n//     This code was generated by a tool.\n//     Runtime Version:4.0.30319.42000\n//\n//     Changes to this file may cause incorrect behavior and will be lost if\n//     the code is regenerated.\n// </auto-generated>\n//------------------------------------------------------------------------------\n\nnamespace Microsoft.Samples.Wpf.D3D11Interop.Properties {\n    using System;\n    \n    \n    /// <summary>\n    ///   A strongly-typed resource class, for looking up localized strings, etc.\n    /// </summary>\n    // This class was auto-generated by the StronglyTypedResourceBuilder\n    // class via a tool like ResGen or Visual Studio.\n    // To add or remove a member, edit your .ResX file then rerun ResGen\n    // with the /str option, or rebuild your VS project.\n    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Resources.Tools.StronglyTypedResourceBuilder\", \"4.0.0.0\")]\n    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]\n    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]\n    internal class Resources {\n        \n        private static global::System.Resources.ResourceManager resourceMan;\n        \n        private static global::System.Globalization.CultureInfo resourceCulture;\n        \n        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n        internal Resources() {\n        }\n        \n        /// <summary>\n        ///   Returns the cached ResourceManager instance used by this class.\n        /// </summary>\n        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]\n        internal static global::System.Resources.ResourceManager ResourceManager {\n            get {\n                if (object.ReferenceEquals(resourceMan, null)) {\n                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(\"D3D11ImageSample.Properties.Resources\", typeof(Resources).Assembly);\n                    resourceMan = temp;\n                }\n                return resourceMan;\n            }\n        }\n        \n        /// <summary>\n        ///   Overrides the current thread's CurrentUICulture property for all\n        ///   resource lookups using this strongly typed resource class.\n        /// </summary>\n        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]\n        internal static global::System.Globalization.CultureInfo Culture {\n            get {\n                return resourceCulture;\n            }\n            set {\n                resourceCulture = value;\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/Properties/Resources.resx",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n  <!-- \n    Microsoft ResX Schema \n    \n    Version 2.0\n    \n    The primary goals of this format is to allow a simple XML format \n    that is mostly human readable. The generation and parsing of the \n    various data types are done through the TypeConverter classes \n    associated with the data types.\n    \n    Example:\n    \n    ... ado.net/XML headers & schema ...\n    <resheader name=\"resmimetype\">text/microsoft-resx</resheader>\n    <resheader name=\"version\">2.0</resheader>\n    <resheader name=\"reader\">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>\n    <resheader name=\"writer\">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>\n    <data name=\"Name1\"><value>this is my long string</value><comment>this is a comment</comment></data>\n    <data name=\"Color1\" type=\"System.Drawing.Color, System.Drawing\">Blue</data>\n    <data name=\"Bitmap1\" mimetype=\"application/x-microsoft.net.object.binary.base64\">\n        <value>[base64 mime encoded serialized .NET Framework object]</value>\n    </data>\n    <data name=\"Icon1\" type=\"System.Drawing.Icon, System.Drawing\" mimetype=\"application/x-microsoft.net.object.bytearray.base64\">\n        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>\n        <comment>This is a comment</comment>\n    </data>\n                \n    There are any number of \"resheader\" rows that contain simple \n    name/value pairs.\n    \n    Each data row contains a name, and value. The row also contains a \n    type or mimetype. Type corresponds to a .NET class that support \n    text/value conversion through the TypeConverter architecture. \n    Classes that don't support this are serialized and stored with the \n    mimetype set.\n    \n    The mimetype is used for serialized objects, and tells the \n    ResXResourceReader how to depersist the object. This is currently not \n    extensible. For a given mimetype the value must be set accordingly:\n    \n    Note - application/x-microsoft.net.object.binary.base64 is the format \n    that the ResXResourceWriter will generate, however the reader can \n    read any of the formats listed below.\n    \n    mimetype: application/x-microsoft.net.object.binary.base64\n    value   : The object must be serialized with \n            : System.Serialization.Formatters.Binary.BinaryFormatter\n            : and then encoded with base64 encoding.\n    \n    mimetype: application/x-microsoft.net.object.soap.base64\n    value   : The object must be serialized with \n            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter\n            : and then encoded with base64 encoding.\n\n    mimetype: application/x-microsoft.net.object.bytearray.base64\n    value   : The object must be serialized into a byte array \n            : using a System.ComponentModel.TypeConverter\n            : and then encoded with base64 encoding.\n    -->\n  <xsd:schema id=\"root\" xmlns=\"\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n    <xsd:element name=\"root\" msdata:IsDataSet=\"true\">\n      <xsd:complexType>\n        <xsd:choice maxOccurs=\"unbounded\">\n          <xsd:element name=\"metadata\">\n            <xsd:complexType>\n              <xsd:sequence>\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" />\n              </xsd:sequence>\n              <xsd:attribute name=\"name\" type=\"xsd:string\" />\n              <xsd:attribute name=\"type\" type=\"xsd:string\" />\n              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" />\n            </xsd:complexType>\n          </xsd:element>\n          <xsd:element name=\"assembly\">\n            <xsd:complexType>\n              <xsd:attribute name=\"alias\" type=\"xsd:string\" />\n              <xsd:attribute name=\"name\" type=\"xsd:string\" />\n            </xsd:complexType>\n          </xsd:element>\n          <xsd:element name=\"data\">\n            <xsd:complexType>\n              <xsd:sequence>\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n                <xsd:element name=\"comment\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"2\" />\n              </xsd:sequence>\n              <xsd:attribute name=\"name\" type=\"xsd:string\" msdata:Ordinal=\"1\" />\n              <xsd:attribute name=\"type\" type=\"xsd:string\" msdata:Ordinal=\"3\" />\n              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" msdata:Ordinal=\"4\" />\n            </xsd:complexType>\n          </xsd:element>\n          <xsd:element name=\"resheader\">\n            <xsd:complexType>\n              <xsd:sequence>\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n              </xsd:sequence>\n              <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" />\n            </xsd:complexType>\n          </xsd:element>\n        </xsd:choice>\n      </xsd:complexType>\n    </xsd:element>\n  </xsd:schema>\n  <resheader name=\"resmimetype\">\n    <value>text/microsoft-resx</value>\n  </resheader>\n  <resheader name=\"version\">\n    <value>2.0</value>\n  </resheader>\n  <resheader name=\"reader\">\n    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n  </resheader>\n  <resheader name=\"writer\">\n    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n  </resheader>\n</root>"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/Properties/Settings.Designer.cs",
    "content": "﻿//------------------------------------------------------------------------------\n// <auto-generated>\n//     This code was generated by a tool.\n//     Runtime Version:4.0.30319.42000\n//\n//     Changes to this file may cause incorrect behavior and will be lost if\n//     the code is regenerated.\n// </auto-generated>\n//------------------------------------------------------------------------------\n\nnamespace Microsoft.Samples.Wpf.D3D11Interop.Properties {\n    \n    \n    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]\n    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator\", \"12.0.0.0\")]\n    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {\n        \n        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));\n        \n        public static Settings Default {\n            get {\n                return defaultInstance;\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/Properties/Settings.settings",
    "content": "﻿<?xml version='1.0' encoding='utf-8'?>\n<SettingsFile xmlns=\"uri:settings\" CurrentProfile=\"(Default)\">\n  <Profiles>\n    <Profile Name=\"(Default)\" />\n  </Profiles>\n  <Settings />\n</SettingsFile>"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/WpfD3D11Interop.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <PropertyGroup>\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\n    <Platform Condition=\" '$(Platform)' == '' \">x86</Platform>\n    <ProductVersion>8.0.30703</ProductVersion>\n    <SchemaVersion>2.0</SchemaVersion>\n    <ProjectGuid>{19855A82-A7EC-4E95-B0C4-B1A2356732B7}</ProjectGuid>\n    <OutputType>WinExe</OutputType>\n    <AppDesignerFolder>Properties</AppDesignerFolder>\n    <RootNamespace>Microsoft.Samples.Wpf.D3D11Interop</RootNamespace>\n    <AssemblyName>WpfD3D11Interop</AssemblyName>\n    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\n    <TargetFrameworkProfile>\n    </TargetFrameworkProfile>\n    <FileAlignment>512</FileAlignment>\n    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>\n    <WarningLevel>4</WarningLevel>\n    <NuGetPackageImportStamp>\n    </NuGetPackageImportStamp>\n  </PropertyGroup>\n  <PropertyGroup>\n    <ApplicationIcon>\n    </ApplicationIcon>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)' == 'Debug|Win32'\">\n    <PlatformTarget>x86</PlatformTarget>\n    <OutputPath>..\\x86\\Debug\\</OutputPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <UseVSHostingProcess>false</UseVSHostingProcess>\n    <Prefer32Bit>false</Prefer32Bit>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)' == 'Release|Win32'\">\n    <PlatformTarget>x86</PlatformTarget>\n    <OutputPath>..\\x86\\Release\\</OutputPath>\n    <DebugType>pdbonly</DebugType>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <Prefer32Bit>false</Prefer32Bit>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)' == 'Debug|x64'\">\n    <PlatformTarget>x64</PlatformTarget>\n    <OutputPath>..\\x64\\Debug\\</OutputPath>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <Prefer32Bit>false</Prefer32Bit>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)' == 'Release|x64'\">\n    <PlatformTarget>x64</PlatformTarget>\n    <OutputPath>..\\x64\\Release\\</OutputPath>\n    <DebugType>pdbonly</DebugType>\n    <CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>\n    <Prefer32Bit>false</Prefer32Bit>\n  </PropertyGroup>\n  <ItemGroup>\n    <Reference Include=\"Microsoft.Wpf.Interop.DirectX\">\n      <HintPath>..\\packages\\Microsoft.Wpf.Interop.DirectX-x64.0.9.0-beta-22856\\lib\\net45\\Microsoft.Wpf.Interop.DirectX.dll</HintPath>\n    </Reference>\n    <Reference Include=\"System\" />\n    <Reference Include=\"System.Xml\" />\n    <Reference Include=\"Microsoft.CSharp\" />\n    <Reference Include=\"System.Core\" />\n    <Reference Include=\"System.Xaml\">\n      <RequiredTargetFramework>4.0</RequiredTargetFramework>\n    </Reference>\n    <Reference Include=\"WindowsBase\" />\n    <Reference Include=\"PresentationCore\" />\n    <Reference Include=\"PresentationFramework\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Compile Include=\"App.xaml.cs\">\n      <DependentUpon>App.xaml</DependentUpon>\n    </Compile>\n    <Compile Include=\"MainWindow.xaml.cs\">\n      <DependentUpon>MainWindow.xaml</DependentUpon>\n    </Compile>\n    <Compile Include=\"Properties\\AssemblyInfo.cs\">\n      <SubType>Code</SubType>\n    </Compile>\n    <Compile Include=\"Properties\\Resources.Designer.cs\">\n      <AutoGen>True</AutoGen>\n      <DesignTime>True</DesignTime>\n      <DependentUpon>Resources.resx</DependentUpon>\n    </Compile>\n    <Compile Include=\"Properties\\Settings.Designer.cs\">\n      <AutoGen>True</AutoGen>\n      <DependentUpon>Settings.settings</DependentUpon>\n      <DesignTimeSharedInput>True</DesignTimeSharedInput>\n    </Compile>\n    <EmbeddedResource Include=\"Properties\\Resources.resx\">\n      <Generator>ResXFileCodeGenerator</Generator>\n      <LastGenOutput>Resources.Designer.cs</LastGenOutput>\n    </EmbeddedResource>\n    <None Include=\"app.config\" />\n    <None Include=\"packages.config\" />\n    <None Include=\"Properties\\Settings.settings\">\n      <Generator>SettingsSingleFileGenerator</Generator>\n      <LastGenOutput>Settings.Designer.cs</LastGenOutput>\n    </None>\n    <AppDesigner Include=\"Properties\\\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ApplicationDefinition Include=\"App.xaml\">\n      <Generator>MSBuild:Compile</Generator>\n      <SubType>Designer</SubType>\n    </ApplicationDefinition>\n    <Page Include=\"MainWindow.xaml\">\n      <Generator>MSBuild:Compile</Generator>\n      <SubType>Designer</SubType>\n    </Page>\n  </ItemGroup>\n  <ItemGroup>\n    <Resource Include=\"Images\\Checkbox_checked.png\" />\n    <Resource Include=\"Images\\Checkbox_unchecked.png\" />\n    <Resource Include=\"Images\\MagnifyingGlass.PNG\" />\n    <Resource Include=\"Images\\background.jpg\" />\n    <Resource Include=\"Images\\radiobutton_off.png\" />\n    <Resource Include=\"Images\\radiobutton_on.png\" />\n    <Resource Include=\"Images\\Slider.png\" />\n  </ItemGroup>\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \n       Other similar extension points exist, see Microsoft.Common.targets.\n  <Target Name=\"BeforeBuild\">\n  </Target>\n  <Target Name=\"AfterBuild\">\n  </Target>\n  -->\n</Project>"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/app.config",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<configuration>\n<startup><supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\"/></startup></configuration>\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n  <package id=\"Microsoft.Wpf.Interop.DirectX-x64\" version=\"0.9.0-beta-22856\" targetFramework=\"net45\" />\n</packages>"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop_dxsdk.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 14\nVisualStudioVersion = 14.0.23107.0\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"WpfD3D11Interop\", \"WpfD3D11Interop\\WpfD3D11Interop.csproj\", \"{19855A82-A7EC-4E95-B0C4-B1A2356732B7}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"D3DVisualization_dxsdk\", \"D3D11Visualization\\D3DVisualization_dxsdk.vcxproj\", \"{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x64.Build.0 = Debug|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x86.Build.0 = Debug|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x64.ActiveCfg = Release|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x64.Build.0 = Release|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x86.ActiveCfg = Release|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x86.Build.0 = Release|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x64.Build.0 = Debug|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x86.Build.0 = Debug|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x64.ActiveCfg = Release|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x64.Build.0 = Release|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x86.ActiveCfg = Release|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x86.Build.0 = Release|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x64.Build.0 = Debug|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x86.Build.0 = Debug|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x64.ActiveCfg = Release|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x64.Build.0 = Release|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x86.ActiveCfg = Release|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "samples/D3D11Image/WpfD3D11Interop_winsdk.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 14\nVisualStudioVersion = 14.0.23107.0\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"WpfD3D11Interop\", \"WpfD3D11Interop\\WpfD3D11Interop.csproj\", \"{19855A82-A7EC-4E95-B0C4-B1A2356732B7}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"D3DVisualization_winsdk\", \"D3D11Visualization\\D3DVisualization_winsdk.vcxproj\", \"{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x64.Build.0 = Debug|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Debug|x86.Build.0 = Debug|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x64.ActiveCfg = Release|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x64.Build.0 = Release|x64\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x86.ActiveCfg = Release|Win32\n\t\t{19855A82-A7EC-4E95-B0C4-B1A2356732B7}.Release|x86.Build.0 = Release|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x64.Build.0 = Debug|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Debug|x86.Build.0 = Debug|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x64.ActiveCfg = Release|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x64.Build.0 = Release|x64\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x86.ActiveCfg = Release|Win32\n\t\t{3FEB553A-62BD-42E1-9A70-0CD3E45929D0}.Release|x86.Build.0 = Release|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x64.Build.0 = Debug|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Debug|x86.Build.0 = Debug|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x64.ActiveCfg = Release|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x64.Build.0 = Release|x64\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x86.ActiveCfg = Release|Win32\n\t\t{D73DCE48-0DBC-40FE-AC89-2C06AF01060B}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "scripts/BuildNuGetPackage.cmd",
    "content": "nuget.exe pack Microsoft.Wpf.Interop.DirectX.nuspec -Version 0.9.0-beta-99999 -Properties ArchitecturePublicName=x64;NuGetBinaries=..\\src\\x64\\release -symbols\nnuget.exe pack Microsoft.Wpf.Interop.DirectX.nuspec -Version 0.9.0-beta-99999 -Properties ArchitecturePublicName=x86;NuGetBinaries=..\\src\\release -symbols"
  },
  {
    "path": "scripts/Microsoft.Wpf.Interop.DirectX.nuspec",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">\n    <metadata>\n        <id>Microsoft.Wpf.Interop.DirectX-$ArchitecturePublicName$</id>\n        <title>Microsoft.Wpf.Interop.DirectX-$ArchitecturePublicName$</title>\n        <version>$version$</version>\n        <authors>Microsoft</authors>\n        <owners>Microsoft, NugetWPF</owners>\n        <copyright>© Microsoft Corporation. All rights reserved</copyright>\n        <requireLicenseAcceptance>true</requireLicenseAcceptance>\n        <licenseUrl>https://github.com/Microsoft/WPFDXInterop/blob/master/LICENSE</licenseUrl>\n        <summary>Microsoft.Wpf.Interop.DirectX provides a new implementation of D3DImage that enables you to seamlessly interop with DirectX 10 or 11 content in your WPF application.</summary>\n        <projectUrl>https://github.com/Microsoft/WPFDXInterop </projectUrl>\n        <iconUrl>http://go.microsoft.com/fwlink/?LinkID=532657</iconUrl>\n        <tags>WPF DirectX D3DImage D3D11Image DirectX11 DirectX10</tags>\n        <description>\n            Microsoft.Wpf.Interop.DirectX.D3D11Image is a version of D3DImage that supports DirectX 11 or DirectX 10. For more information, check out the project here: https://github.com/Microsoft/WPFDXInterop\n        </description>\n    </metadata>\n    <files>\n        <file src=\"$NuGetBinaries$\\Microsoft.Wpf.Interop.DirectX.dll\" target=\"lib\\net45\\Microsoft.Wpf.Interop.DirectX.dll\" />\n        <file src=\"$NuGetBinaries$\\Microsoft.Wpf.Interop.DirectX.pdb\" target=\"lib\\net45\\Microsoft.Wpf.Interop.DirectX.pdb\" />\n    </files>\n</package>\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/AssemblyInfo.cpp",
    "content": "// Copyright (c) Microsoft Corporation.  All rights reserved.\n#include \"stdafx.h\"\n\nusing namespace System;\nusing namespace System::Reflection;\nusing namespace System::Runtime::CompilerServices;\nusing namespace System::Runtime::InteropServices;\nusing namespace System::Security::Permissions;\n\n[assembly:ComVisible(false)];\n\n[assembly:CLSCompliantAttribute(true)];\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/D3D11Image.cpp",
    "content": "#include \"D3D11Image.h\"\n\nnamespace Microsoft {\n    namespace Wpf {\n        namespace Interop {\n            namespace DirectX {\n\n                static D3D11Image::D3D11Image()\n                {\n                    OnRenderProperty = DependencyProperty::Register(\"OnRender\",\n                        Action<IntPtr, bool>::typeid,\n                        D3D11Image::typeid,\n                        gcnew UIPropertyMetadata(nullptr, gcnew PropertyChangedCallback(&RenderChanged)));\n\n                    WindowOwnerProperty = DependencyProperty::Register(\"WindowOwner\",\n                        IntPtr::typeid,\n                        D3D11Image::typeid,\n                        gcnew UIPropertyMetadata(IntPtr::Zero, gcnew PropertyChangedCallback(&HWNDOwnerChanged)));\n                }\n\n                D3D11Image::D3D11Image()\n                {\n                }\n\n                D3D11Image::~D3D11Image()\n                {\n                    if (this->Helper != nullptr)\n                    {\n                        this->Helper->~SurfaceQueueInteropHelper();\n                        this->Helper = nullptr;\n                    }\n                }\n\n                Freezable^ D3D11Image::CreateInstanceCore()\n                {\n                    return gcnew D3D11Image();\n                }\n\n                void D3D11Image::HWNDOwnerChanged(DependencyObject^ sender, DependencyPropertyChangedEventArgs args)\n                {\n                    D3D11Image^ image = dynamic_cast<D3D11Image^>(sender);\n\n                    if (image != nullptr)\n                    {\n                        if (image->Helper != nullptr)\n                        {\n                            image->Helper->HWND = static_cast<IntPtr>(args.NewValue);\n                        }\n                    }\n                }\n\n                void D3D11Image::RenderChanged(DependencyObject^ sender, DependencyPropertyChangedEventArgs args)\n                {\n                    D3D11Image^ image = dynamic_cast<D3D11Image^>(sender);\n\n                    if (image != nullptr)\n                    {\n                        if (image->Helper != nullptr)\n                        {\n                            image->Helper->RenderD2D = static_cast<Action<IntPtr, bool>^>(args.NewValue);\n                        }\n                    }\n                }\n\n                void D3D11Image::EnsureHelper()\n                {\n                    if (this->Helper == nullptr)\n                    {\n                        this->Helper = gcnew SurfaceQueueInteropHelper();\n                        this->Helper->HWND = this->WindowOwner;\n                        this->Helper->D3DImage = this;\n                        this->Helper->RenderD2D = this->OnRender;\n                    }\n                }\n\n                void D3D11Image::RequestRender()\n                {\n                    this->EnsureHelper();\n\n                    // Don't bother with a call if there's no callback registered.\n                    if (nullptr != this->OnRender)\n                    {\n                        this->Helper->RequestRenderD2D();\n                    }\n                }\n\n                void D3D11Image::SetPixelSize(int pixelWidth, int pixelHeight)\n                {\n                    this->EnsureHelper();\n                    this->Helper->SetPixelSize(static_cast<UInt32>(pixelWidth), static_cast<UInt32>(pixelHeight));\n                }\n            }\n        }\n    }\n}"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/D3D11Image.h",
    "content": "// SurfaceQueueInteropHelper.h\n\n#pragma once\n\n#include \"SurfaceQueueInteropHelper.h\"\n\n\nusing namespace System;\nusing namespace System::Windows;\nusing namespace System::Windows::Interop;\nusing namespace Microsoft::Windows::Media;\n\nnamespace Microsoft {\n    namespace Wpf {\n        namespace Interop {\n            namespace DirectX {\n\n                /// A System.Windows.Media.ImageSource which displays a user provided DirectX 10 or 11 surface.\n                public ref class D3D11Image :\n                    public D3DImage\n                {\n                private:\n                    static void RenderChanged(DependencyObject^ sender, DependencyPropertyChangedEventArgs args);\n                    static void HWNDOwnerChanged(DependencyObject^ sender, DependencyPropertyChangedEventArgs args);\n                    void EnsureHelper();\n                    static D3D11Image();\n\n                internal:\n                    SurfaceQueueInteropHelper^ Helper;\n\n                protected:\n                    Freezable^ CreateInstanceCore() override;\n\n                public:\n                    D3D11Image();\n                    ~D3D11Image();\n\n                    static DependencyProperty^ OnRenderProperty;\n                    static DependencyProperty^ WindowOwnerProperty;\n\n                    /// The OnRender action delegate will fire and pass the surface to the application that the DirectX rendering component should \n                    /// render into.\n                    property Action<IntPtr, bool>^ OnRender\n                    {\n                        Action<IntPtr, bool>^ get()\n                        {\n                            return static_cast<Action<IntPtr, bool>^>(GetValue(OnRenderProperty));\n                        }\n\n                        void set(Action<IntPtr, bool>^ value)\n                        {\n                            SetValue(OnRenderProperty, value);\n                        }\n                    }\n\n                    /// The window handle (HWND) of the Window which hosts the D3D11Image (used during DirectX surface creation).\n                    property IntPtr WindowOwner\n                    {\n                        IntPtr get()\n                        {\n                            return static_cast<IntPtr>(GetValue(WindowOwnerProperty));\n                        }\n\n                        void set(IntPtr value)\n                        {\n                            SetValue(WindowOwnerProperty, value);\n                        }\n                    }\n\n                    /// The RequestRender method signals that the D3D11Image should get the DirectX rendering code to render a new frame to the provided surface.\n                    /// Typically the user of the D3D11Image calls this every time the CompositionTarget.Rendering event fires.\n                    void RequestRender();\n                    \n                    /// The application hosting the D3D11Image should ensure that the PixelSize is the number of pixels that the D3D11Image is\n                    /// being displayed in.\n                    void SetPixelSize(int pixelWidth, int pixelHeight);\n                };\n            }\n        }\n    }\n}"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/Microsoft.Wpf.Interop.DirectX_dxsdk.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"12.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"AssemblyInfo.cpp\" />\n    <ClCompile Include=\"Stdafx.cpp\">\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">Create</PrecompiledHeader>\n    </ClCompile>\n    <ClCompile Include=\"SurfaceQueueInteropHelper.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"Stdafx.h\" />\n    <ClInclude Include=\"SurfaceQueueInteropHelper.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"SurfaceQueue.h\" />\n    <ClInclude Include=\"SurfaceQueueImpl.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"SurfaceDevice10.cpp\" />\n    <ClCompile Include=\"SurfaceDevice11.cpp\" />\n    <ClCompile Include=\"SurfaceDevice9.cpp\" />\n    <ClCompile Include=\"SurfaceQueue.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"SurfaceQueue.inl\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Reference Include=\"PresentationCore\" />\n    <Reference Include=\"System\" />\n    <Reference Include=\"System.Data\" />\n    <Reference Include=\"System.Xml\" />\n    <Reference Include=\"WindowsBase\" />\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <TargetName>Microsoft.Wpf.Interop.DirectX</TargetName>\n    <RootNamespace>Microsoft.Wpf.Interop.DirectX</RootNamespace>\n    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v120</PlatformToolset>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x86</LibraryPath>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <LinkIncremental>true</LinkIncremental>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <LinkIncremental>false</LinkIncremental>\n    <IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>\n    <LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\\x64</LibraryPath>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>DIRECTX_SDK;WIN32;_DEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3dx9d.lib;d3d10_1.lib;d3dx10d.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\\x86;..\\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>DIRECTX_SDK;_DEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3dx9d.lib;d3d10_1.lib;d3dx10d.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\\x64;..\\x64\\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>MaxSpeed</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>DIRECTX_SDK;WIN32;NDEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <ExceptionHandling>Async</ExceptionHandling>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3dx9d.lib;d3d10_1.lib;d3dx10d.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\\x86;..\\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <FixedBaseAddress>false</FixedBaseAddress>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>MaxSpeed</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>DIRECTX_SDK;NDEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <ExceptionHandling>Async</ExceptionHandling>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3dx9d.lib;d3d10_1.lib;d3dx10d.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\\x64;..\\x64\\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <FixedBaseAddress>false</FixedBaseAddress>\n    </Link>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/Microsoft.Wpf.Interop.DirectX_winsdk.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"AssemblyInfo.cpp\" />\n    <ClCompile Include=\"D3D11Image.cpp\" />\n    <ClCompile Include=\"Stdafx.cpp\">\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">Create</PrecompiledHeader>\n    </ClCompile>\n    <ClCompile Include=\"SurfaceQueueInteropHelper.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"D3D11Image.h\" />\n    <ClInclude Include=\"Stdafx.h\" />\n    <ClInclude Include=\"SurfaceQueueInteropHelper.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"SurfaceQueue.h\" />\n    <ClInclude Include=\"SurfaceQueueImpl.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"SurfaceDevice10.cpp\" />\n    <ClCompile Include=\"SurfaceDevice11.cpp\" />\n    <ClCompile Include=\"SurfaceDevice9.cpp\" />\n    <ClCompile Include=\"SurfaceQueue.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <None Include=\"SurfaceQueue.inl\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Reference Include=\"PresentationCore\" />\n    <Reference Include=\"System\" />\n    <Reference Include=\"System.Data\" />\n    <Reference Include=\"System.Xml\" />\n    <Reference Include=\"WindowsBase\" />\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <TargetName>Microsoft.Wpf.Interop.DirectX</TargetName>\n    <RootNamespace>Microsoft.Wpf.Interop.DirectX</RootNamespace>\n    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\n    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>\n    <ProjectName>Microsoft.Wpf.Interop.DirectX_winsdk</ProjectName>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n    <CLRSupport>true</CLRSupport>\n    <PlatformToolset>v140</PlatformToolset>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n    <LibraryPath>$(LibraryPath)</LibraryPath>\n    <IncludePath>$(IncludePath)</IncludePath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <LibraryPath>$(LibraryPath)</LibraryPath>\n    <IncludePath>$(IncludePath)</IncludePath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <LinkIncremental>true</LinkIncremental>\n    <IncludePath>$(IncludePath)</IncludePath>\n    <LibraryPath>$(LibraryPath)</LibraryPath>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <LinkIncremental>false</LinkIncremental>\n    <IncludePath>$(IncludePath)</IncludePath>\n    <LibraryPath>$(LibraryPath)</LibraryPath>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>WIN32;_DEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3d10_1.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>..\\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>Level3</WarningLevel>\n      <Optimization>Disabled</Optimization>\n      <PreprocessorDefinitions>_DEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n      <GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3d10_1.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>..\\x64\\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>MaxSpeed</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <ExceptionHandling>Async</ExceptionHandling>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3d10_1.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>..\\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <FixedBaseAddress>false</FixedBaseAddress>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>MaxSpeed</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>NDEBUG;QUEUE_USE_CONFORMANT_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\n      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <ExceptionHandling>Async</ExceptionHandling>\n      <DebugInformationFormat>\n      </DebugInformationFormat>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>\n      dxgi.lib;d3d9.lib;d3d10_1.lib;%(AdditionalDependencies)\n      </AdditionalDependencies>\n      <AdditionalLibraryDirectories>..\\x64\\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <FixedBaseAddress>false</FixedBaseAddress>\n    </Link>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/Stdafx.cpp",
    "content": "// stdafx.cpp : source file that includes just the standard includes\n// SurfaceQueueInteropHelper.pch will be the pre-compiled header\n// stdafx.obj will contain the pre-compiled type information\n\n#include \"stdafx.h\"\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/Stdafx.h",
    "content": "// stdafx.h : include file for standard system include files,\n// or project specific include files that are used frequently,\n// but are changed infrequently\n\n#pragma once\n\n// Windows Header Files:\n#include <windows.h>\n\n// C RunTime Header Files\n#include <stdlib.h>\n#include <stdio.h>\n\n#include \"SurfaceQueue.h\"\n\n#if DIRECTX_SDK\n#include <d3dx9.h>\n#else\n#include \"d3d9.h\"\n#endif\n\n#include <D3D10_1.h>\n//#include <d3dx10.h>\n\n\n#define IFC(x) { hr = (x); if (FAILED(hr)) { goto Cleanup; }}\n#define ReleaseInterface(x) { if (NULL != x) { x->Release(); x = NULL; }}"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceDevice10.cpp",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#include \"SurfaceQueueImpl.h\"\n\n//-----------------------------------------------------------------------------\n// Implementation of D3D10 Device Wrapper.  This is a simple wrapper around the\n// public D3D10 APIs that are necessary for the shared surface queue.  See\n// the comments in SharedSurfaceQueue.h to descriptions of these functions.\n//-----------------------------------------------------------------------------\nCSurfaceQueueDeviceD3D10::CSurfaceQueueDeviceD3D10(ID3D10Device* pD3D10Device) :\n    m_pDevice(pD3D10Device)\n{\n\tASSERT(m_pDevice);\n\tif (NULL != m_pDevice)\n\t{\n\t\tm_pDevice->AddRef();\n\t}\n}\n\nCSurfaceQueueDeviceD3D10::~CSurfaceQueueDeviceD3D10()\n{\n    m_pDevice->Release();\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::CreateSharedSurface(\n                                UINT Width, UINT Height, \n                                DXGI_FORMAT format, \n                                IUnknown** ppUnknown,\n                                HANDLE* pHandle)\n{\n    ASSERT(m_pDevice);\n    ASSERT(ppUnknown);\n    ASSERT(pHandle);\n\n\tif (NULL == m_pDevice || NULL == ppUnknown || NULL == pHandle)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr;\n\n    ID3D10Texture2D** ppTexture = (ID3D10Texture2D**)ppUnknown;\n\n    D3D10_TEXTURE2D_DESC Desc;\n    Desc.Width              = Width;\n    Desc.Height             = Height;\n    Desc.MipLevels          = 1;\n    Desc.ArraySize          = 1;\n    Desc.Format             = format;\n    Desc.SampleDesc.Count   = 1;\n    Desc.SampleDesc.Quality = 0;\n    Desc.Usage              = D3D10_USAGE_DEFAULT;\n    Desc.BindFlags          = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;\n    Desc.CPUAccessFlags     = 0;\n    Desc.MiscFlags          = D3D10_RESOURCE_MISC_SHARED;\n\n    hr = m_pDevice->CreateTexture2D(&Desc, NULL, ppTexture);\n\n    if (SUCCEEDED(hr))\n    {\n        if (FAILED( GetSharedHandle(*ppUnknown, pHandle)))\n        {\n            (*ppTexture)->Release();\n            (*ppTexture) = NULL;\n        }\n    }\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::OpenSurface(\n                                    HANDLE hSharedHandle, \n                                    void** ppSurface, \n                                    UINT, \n                                    UINT, \n                                    DXGI_FORMAT)\n{\n    return m_pDevice->OpenSharedResource(hSharedHandle, __uuidof(ID3D10Texture2D), ppSurface);\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::GetSharedHandle(IUnknown* pUnknown, HANDLE* pHandle)\n{\n    ASSERT(pUnknown);\n    ASSERT(pHandle);\n\n\tif (NULL == pUnknown || NULL == pHandle)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n    \n    *pHandle = NULL;\n    IDXGIResource* pSurface;\n\n    if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))\n    {\n        return hr;\n    }\n\n    hr = pSurface->GetSharedHandle(pHandle);\n    pSurface->Release();\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::CreateCopyResource(DXGI_FORMAT format, UINT width, UINT height, IUnknown** ppRes)\n{\n    ASSERT(ppRes);\n    ASSERT(m_pDevice);\n\n\tif (NULL == ppRes || NULL == m_pDevice)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    D3D10_TEXTURE2D_DESC Desc;\n    Desc.Width              = width;\n    Desc.Height             = height;\n    Desc.MipLevels          = 1;\n    Desc.ArraySize          = 1;\n    Desc.Format             = format;\n    Desc.SampleDesc.Count   = 1;\n    Desc.SampleDesc.Quality = 0;\n    Desc.Usage              = D3D10_USAGE_STAGING;\n    Desc.BindFlags          = 0;\n    Desc.CPUAccessFlags     = D3D10_CPU_ACCESS_READ;\n    Desc.MiscFlags          = 0;\n   \n    return m_pDevice->CreateTexture2D(&Desc, NULL, reinterpret_cast<ID3D10Texture2D**>(ppRes)); \n}\n\nHRESULT CSurfaceQueueDeviceD3D10::CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height)\n{\n    HRESULT hr;\n    \n    D3D10_BOX UnitBox = {0, 0, 0, width, height, 1};\n    \n    ID3D10Resource* pSrcRes = NULL;\n    ID3D10Resource* pDstRes = NULL;\n\n    if (FAILED(hr = pDst->QueryInterface(__uuidof(ID3D10Resource), (void**)&pDstRes)))\n    {\n        goto end;\n    }\n    \n    if (FAILED(hr = pSrc->QueryInterface(__uuidof(ID3D10Resource), (void**)&pSrcRes)))\n    {\n        goto end;\n    }\n\n    m_pDevice->CopySubresourceRegion(\n            pDstRes, \n            0, \n            0, 0, 0, //(x, y, z)\n            pSrcRes,\n            0, \n            &UnitBox);\nend:\n    if (pSrcRes)\n    {\n        pSrcRes->Release();\n    }\n    if (pDstRes)\n    {\n        pDstRes->Release();\n    }\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::LockSurface(IUnknown* pSurface, DWORD flags)\n{\n    ASSERT(pSurface);\n\n\tif (NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT                 hr          = S_OK;\n    ID3D10Texture2D*        pTex2D      = NULL;\n    DWORD                   d3d10flags  = 0;\n    D3D10_MAPPED_TEXTURE2D  region;\n\n    if (flags & SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    {\n        flags |= D3D10_MAP_FLAG_DO_NOT_WAIT;\n    }\n    \n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(ID3D10Texture2D), (void**)&pTex2D)))\n    {\n        goto end;\n    }\n    \n    hr = pTex2D->Map(0, D3D10_MAP_READ, d3d10flags, &region);\n\nend:\n    if (pTex2D)\n    {\n        pTex2D->Release();\n    }\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D10::UnlockSurface(IUnknown* pSurface)\n{\n    ASSERT(pSurface);\n\n\tif (NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n    ID3D10Texture2D* pTex2D = NULL;\n\n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(ID3D10Texture2D), (void**)&pTex2D)))\n    {\n\t\treturn hr;\n    }\n\n    pTex2D->Unmap(0);\n    pTex2D->Release();\n\n\treturn hr;\n}\n\nBOOL CSurfaceQueueDeviceD3D10::ValidateREFIID(REFIID id)\n{\n    return (id == __uuidof(ID3D10Texture2D)) ||\n\t\t   (id == __uuidof(IDXGISurface));\n}\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceDevice11.cpp",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#include \"SurfaceQueueImpl.h\"\n\n//-----------------------------------------------------------------------------\n// Implementation of D3D11 Device Wrapper.  This is a simple wrapper around the\n// public D3D11 APIs that are necessary for the shared surface queue.  See\n// the comments in SharedSurfaceQueue.h to descriptions of these functions.\n//-----------------------------------------------------------------------------\nCSurfaceQueueDeviceD3D11::CSurfaceQueueDeviceD3D11(ID3D11Device* pD3D11Device) :\n    m_pDevice(pD3D11Device)\n{\n    ASSERT(m_pDevice);\n\tif (NULL != m_pDevice)\n\t{\n\t\tm_pDevice->AddRef();\n\t}\n}\n\nCSurfaceQueueDeviceD3D11::~CSurfaceQueueDeviceD3D11()\n{\n    m_pDevice->Release();\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::CreateSharedSurface(\n                                UINT Width, UINT Height, \n                                DXGI_FORMAT format, \n                                IUnknown** ppUnknown,\n                                HANDLE* pHandle)\n{\n    ASSERT(m_pDevice);\n    ASSERT(ppUnknown);\n    ASSERT(pHandle);\n\n\tif(NULL == m_pDevice || NULL == ppUnknown || NULL == pHandle)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr;\n\n    ID3D11Texture2D** ppTexture = (ID3D11Texture2D**)ppUnknown;\n\n    D3D11_TEXTURE2D_DESC Desc;\n    Desc.Width              = Width;\n    Desc.Height             = Height;\n    Desc.MipLevels          = 1;\n    Desc.ArraySize          = 1;\n    Desc.Format             = format;\n    Desc.SampleDesc.Count   = 1;\n    Desc.SampleDesc.Quality = 0;\n    Desc.Usage              = D3D11_USAGE_DEFAULT;\n    Desc.BindFlags          = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;\n    Desc.CPUAccessFlags     = 0;\n    Desc.MiscFlags          = D3D11_RESOURCE_MISC_SHARED;\n\n    hr = m_pDevice->CreateTexture2D(&Desc, NULL, ppTexture);\n\n    if (SUCCEEDED(hr))\n    {\n        if (FAILED( GetSharedHandle(*ppUnknown, pHandle)))\n        {\n            (*ppTexture)->Release();\n            (*ppTexture) = NULL;\n        }\n    }\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::OpenSurface(\n                                    HANDLE hSharedHandle, \n                                    void** ppSurface, \n                                    UINT, \n                                    UINT, \n                                    DXGI_FORMAT)\n{\n    return m_pDevice->OpenSharedResource(hSharedHandle, __uuidof(ID3D11Texture2D), ppSurface);\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::GetSharedHandle(IUnknown* pUnknown, HANDLE* pHandle)\n{\n    ASSERT(pUnknown);\n    ASSERT(pHandle);\n\n\tif(NULL == pUnknown || NULL == pHandle)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n    \n    *pHandle = NULL;\n    IDXGIResource* pSurface;\n\n    if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))\n    {\n        return hr;\n    }\n\n    hr = pSurface->GetSharedHandle(pHandle);\n    pSurface->Release();\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::CreateCopyResource(DXGI_FORMAT format, UINT width, UINT height, IUnknown** ppRes)\n{\n    ASSERT(ppRes);\n    ASSERT(m_pDevice);\n\n\tif(NULL == ppRes || NULL == m_pDevice)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    D3D11_TEXTURE2D_DESC Desc;\n    Desc.Width              = width;\n    Desc.Height             = height;\n    Desc.MipLevels          = 1;\n    Desc.ArraySize          = 1;\n    Desc.Format             = format;\n    Desc.SampleDesc.Count   = 1;\n    Desc.SampleDesc.Quality = 0;\n    Desc.Usage              = D3D11_USAGE_STAGING;\n    Desc.BindFlags          = 0;\n    Desc.CPUAccessFlags     = D3D11_CPU_ACCESS_READ;\n    Desc.MiscFlags          = 0;\n   \n    return m_pDevice->CreateTexture2D(&Desc, NULL, reinterpret_cast<ID3D11Texture2D**>(ppRes)); \n}\n\nHRESULT CSurfaceQueueDeviceD3D11::CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height)\n{\n    HRESULT hr;\n    \n    D3D11_BOX UnitBox = {0, 0, 0, width, height, 1};\n    \n    ID3D11DeviceContext*    pContext = NULL;\n    ID3D11Resource*         pSrcRes = NULL;\n    ID3D11Resource*         pDstRes = NULL;\n\n    m_pDevice->GetImmediateContext(&pContext);\n    ASSERT(pContext);\n\n    if (FAILED(hr = pDst->QueryInterface(__uuidof(ID3D11Resource), (void**)&pDstRes)))\n    {\n        goto end;\n    }\n    \n    if (FAILED(hr = pSrc->QueryInterface(__uuidof(ID3D11Resource), (void**)&pSrcRes)))\n    {\n        goto end;\n    }\n\n    pContext->CopySubresourceRegion(\n            pDstRes, \n            0, \n            0, 0, 0, //(x, y, z)\n            pSrcRes,\n            0, \n            &UnitBox);\nend:\n    if (pSrcRes)\n    {\n        pSrcRes->Release();\n    }\n    if (pDstRes)\n    {\n        pDstRes->Release();\n    }\n    if (pContext)\n    {\n        pContext->Release();\n    }\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::LockSurface(IUnknown* pSurface, DWORD flags)\n{\n    ASSERT(pSurface);\n\n\tif(NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n    D3D11_MAPPED_SUBRESOURCE region;\n\n    ID3D11Resource*         pResource   = NULL;\n    ID3D11DeviceContext*    pContext    = NULL;\n    DWORD                   d3d11flags  = 0;\n\n    m_pDevice->GetImmediateContext(&pContext);\n    ASSERT(pContext);\n    \n    if (flags & SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    {\n        d3d11flags |= D3D11_MAP_FLAG_DO_NOT_WAIT;\n    }\n   \n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(ID3D11Resource), (void**)&pResource)))\n    {\n        goto end;\n    }\n\n    hr = pContext->Map(pResource, 0, D3D11_MAP_READ, d3d11flags, &region); \n\nend:\n    if (pResource)\n    {\n        pResource->Release();\n    }\n    if (pContext)\n    {\n        pContext->Release();\n    }\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D11::UnlockSurface(IUnknown* pSurface)\n{\n    ASSERT(pSurface);\n\n\tif(NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n\n    ID3D11DeviceContext*    pContext    = NULL;\n    ID3D11Resource*         pResource   = NULL;\n\n    m_pDevice->GetImmediateContext(&pContext);\n    ASSERT(pContext);\n\n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(ID3D11Resource), (void**)&pResource)))\n    {\n        goto end;\n    }\n\n    pContext->Unmap(pResource, 0);\n\nend:\n    if (pResource)\n    {\n        pResource->Release();\n    }\n    if (pContext)\n    {\n        pContext->Release();\n    }\n    return hr;\n}\n\nBOOL CSurfaceQueueDeviceD3D11::ValidateREFIID(REFIID id)\n{\n    return (id == __uuidof(ID3D11Texture2D)) ||\n\t\t   (id == __uuidof(IDXGISurface));\n}\n\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceDevice9.cpp",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#include \"SurfaceQueueImpl.h\"\n\n//-----------------------------------------------------------------------------\n// Implementation of D3D9 Device Wrapper.  This is a simple wrapper around the\n// public D3D9Ex APIs that are necessary for the shared surface queue.  See\n// the comments in SharedSurfaceQueue.h to descriptions of these functions.\n//-----------------------------------------------------------------------------\n\n//\n// D3D9Ex does not have an API to get shared handles.  We replicate that functionality\n// using setprivatedata.\n//\nstatic GUID SharedHandleGuid = {0x91facf2d, 0xe464, 0x4495, 0x84, 0xa6, 0x37, 0xbe, 0xd3, 0x56, 0x8d, 0xa3};\n\n//\n// This function will convert from DXGI formats (d3d10/d3d11) to D3D9 formats.\n// Most formtas are not cross api shareable and for those the function will\n// return D3DFMT_UNKNOWN.\n//\nD3DFORMAT DXGIToCrossAPID3D9Format(DXGI_FORMAT Format)\n{\n    switch (Format)\n    {\n        case DXGI_FORMAT_B8G8R8A8_UNORM:\n            return D3DFMT_A8R8G8B8;\n        case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: \n            return D3DFMT_A8R8G8B8;\n        case DXGI_FORMAT_B8G8R8X8_UNORM:\n            return D3DFMT_X8R8G8B8;\n        case DXGI_FORMAT_R8G8B8A8_UNORM: \n            return D3DFMT_A8B8G8R8;\n        case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: \n            return D3DFMT_A8B8G8R8;\n        case DXGI_FORMAT_R10G10B10A2_UNORM:\n            return D3DFMT_A2B10G10R10;\n        case DXGI_FORMAT_R16G16B16A16_FLOAT: \n            return D3DFMT_A16B16G16R16F;\n        default:\n            return D3DFMT_UNKNOWN;\n    };\n}\n\n\nCSurfaceQueueDeviceD3D9::CSurfaceQueueDeviceD3D9(IDirect3DDevice9Ex* pD3D9Device) :\n    m_pDevice(pD3D9Device)\n{\n    ASSERT(m_pDevice);\n\tif(NULL != m_pDevice)\n\t{\n\t\tm_pDevice->AddRef();\n\t}\n}\n\nCSurfaceQueueDeviceD3D9::~CSurfaceQueueDeviceD3D9()\n{\n    m_pDevice->Release();\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::CreateSharedSurface(\n                                UINT Width, UINT Height, \n                                DXGI_FORMAT Format, \n                                IUnknown** ppTexture,\n                                HANDLE* pHandle)\n{\n    ASSERT(m_pDevice);\n\n\tif(NULL == m_pDevice)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    D3DFORMAT D3D9Format;\n\n    if ((D3D9Format = DXGIToCrossAPID3D9Format(Format)) == D3DFMT_UNKNOWN)\n    {\n        return E_INVALIDARG;\n    }\n\n    HRESULT hr;\n\n    *pHandle = NULL;\n\n    hr = m_pDevice->CreateTexture(Width, Height, 1,\n                                  D3DUSAGE_RENDERTARGET,\n                                  D3D9Format,\n                                  D3DPOOL_DEFAULT,\n                                  (IDirect3DTexture9**)ppTexture,\n                                  pHandle);\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::OpenSurface(\n                                    HANDLE hSharedHandle, \n                                    void** ppUnknown, \n                                    UINT Width, \n                                    UINT Height, \n                                    DXGI_FORMAT Format)\n{\n    \n    D3DFORMAT D3D9Format;\n\n    // If the format is not cross api shareable the utility function will return\n    // D3DFMT_UNKNOWN\n    if ((D3D9Format = DXGIToCrossAPID3D9Format(Format)) == D3DFMT_UNKNOWN)\n    {\n        return E_INVALIDARG;\n    }\n\n    HRESULT hr = S_OK;\n    IDirect3DTexture9** ppTexture = (IDirect3DTexture9**)ppUnknown;\n\n    hr = m_pDevice->CreateTexture(Width, Height, 1,\n                                  D3DUSAGE_RENDERTARGET,\n                                  D3D9Format,\n                                  D3DPOOL_DEFAULT,\n                                  ppTexture,\n                                  &hSharedHandle);\n    if (SUCCEEDED(hr))\n    {\n        // Store the shared handle\n        hr = (*ppTexture)->SetPrivateData(SharedHandleGuid, &hSharedHandle, sizeof(HANDLE), 0);\n\n        if (FAILED(hr))\n        {\n            (*ppTexture)->Release();\n            *ppTexture = NULL;\n        }\n    }\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::GetSharedHandle(IUnknown* pUnknown, HANDLE* pHandle)\n{\n    ASSERT(pUnknown);\n    ASSERT(pHandle);\n\n\tif(NULL == pUnknown || NULL == pHandle)\n\t{\n\t\treturn E_FAIL;\n\t}\n    \n    HRESULT hr = S_OK;\n    \n    *pHandle = NULL;\n    IDirect3DTexture9* pTexture;\n\n    if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDirect3DTexture9), (void**)&pTexture)))\n    {\n        return hr;\n    }\n\n    DWORD size = sizeof(HANDLE);\n\n    hr = pTexture->GetPrivateData(SharedHandleGuid, pHandle, &size);\n    pTexture->Release();\n\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::CreateCopyResource(DXGI_FORMAT Format, UINT width, UINT height, IUnknown** ppRes)\n{\n      \n    D3DFORMAT D3D9Format;\n\n    if ((D3D9Format = DXGIToCrossAPID3D9Format(Format)) == D3DFMT_UNKNOWN)\n    {\n        return E_INVALIDARG;\n    }\n\n    return m_pDevice->CreateRenderTarget(\n            width, height,\n            D3D9Format,\n            D3DMULTISAMPLE_NONE,\n            0,\n            TRUE,\n            (IDirect3DSurface9**)ppRes,\n            NULL\n            );\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height)\n{\n    ASSERT(pDst);\n    ASSERT(pSrc);\n    ASSERT(m_pDevice);\n\n\tif(NULL == pDst || NULL == pSrc || NULL == m_pDevice)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT             hr          = S_OK;\n    IDirect3DSurface9*  pSrcSurf    = NULL;\n    IDirect3DSurface9*  pDstSurf    = NULL;\n    IDirect3DTexture9*  pSrcTex     = NULL;\n    RECT                rect        = {(long)0, (long)0, (long)width, (long)height };\n   \n    // The source should be a IDirect3DTexture9.  We need to QI for it and then get the\n    // top most surface from it.\n    if (FAILED(hr = pSrc->QueryInterface(__uuidof(IDirect3DTexture9), (void**)&pSrcTex)))\n    {\n        goto end;\n    }\n    if (FAILED(hr = pSrcTex->GetSurfaceLevel(0, &pSrcSurf)))\n    {\n        goto end;\n    }\n    // The dst is a IDirect3DSurface9 so we can simply QI for it.\n    if (FAILED(hr = pDst->QueryInterface(__uuidof(IDirect3DSurface9), (void**)&pDstSurf)))\n    {\n        goto end;\n    }\n\n    hr = m_pDevice->StretchRect(pSrcSurf, &rect, pDstSurf, &rect, D3DTEXF_NONE);\n\nend:\n    if (pSrcTex)\n    {\n        pSrcTex->Release();\n    }\n    if (pSrcSurf)\n    {\n        pSrcSurf->Release();\n    }\n    if (pDstSurf)\n    {\n        pDstSurf->Release();\n    }\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::LockSurface(IUnknown* pSurface, DWORD flags)\n{\n    ASSERT(pSurface);\n\n\tif(NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT             hr          = S_OK;\n    IDirect3DSurface9*  pSurf       = NULL;\n    DWORD               d3d9flags   = D3DLOCK_READONLY;\n    D3DLOCKED_RECT      region;\n\n    \n    if (flags & SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    {\n        d3d9flags |= D3DLOCK_DONOTWAIT;\n    }\n\n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(IDirect3DSurface9), (void**)&pSurf)))\n    {\n        goto end;\n    }\n   \n    hr = pSurf->LockRect(&region, NULL, d3d9flags);\n\nend:\n    if (pSurf)\n    {\n        pSurf->Release();\n    }\n    if (hr == D3DERR_WASSTILLDRAWING)\n    {\n        hr = DXGI_ERROR_WAS_STILL_DRAWING;\n    }\n    return hr;\n}\n\nHRESULT CSurfaceQueueDeviceD3D9::UnlockSurface(IUnknown* pSurface)\n{\n    ASSERT(pSurface);\n\n\tif(NULL == pSurface)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT             hr          = S_OK;\n    IDirect3DSurface9*  pSurf       = NULL;\n\n    if (FAILED(hr = pSurface->QueryInterface(__uuidof(IDirect3DSurface9), (void**)&pSurf)))\n    {\n        goto end;\n    }\n\n    hr = pSurf->UnlockRect();\n\nend:\n    if (pSurf)\n    {\n        pSurf->Release();\n    }\n    return hr;\n}\n\nBOOL CSurfaceQueueDeviceD3D9::ValidateREFIID(REFIID id)\n{\n    return id == __uuidof(IDirect3DTexture9);\n}\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueue.cpp",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#include <new>\n#include \"SurfaceQueue.inl\"\n\n//\n// Notes about the synchronization:  It's important for this library\n// to be reasonably parallel; it should be possible to have simultaneously\n// enqueues/dequeues.  It is undesirable for a thread to grab the queue\n// lock while it calls into a blocking or very time consuming DirectX API.\n//\n// The single threaded flag will disable the synchronization constructs.\n//\n// There are 4 synchronization primitives used in this library.  \n//\t\t1) Critical Section in CSurfaceProducer/CSurfaceConsumer that protects\n//         simultaneous access to their apis (Enqueue&Flush/Dequeue).  The public\n//         functions from those objects are not designed to be multithreaded.  It\n//         is not designed to support, for example, simultaneous Enqueues to the same\n//         queue.  This lock guarantees that the Queue can not have simultaneous Enqueues\n//         and Flushes.  There are a few CSurfaceQueue member variables that are shared\n//         ONLY between Enqueue and Flush and do not need to be protected in CSurfaceQueue.\n//      2) A Semaphore to control waiting when the Queue is empty.  The semaphore is\n//         released on Enqueue/Flush and is waited on in Dequeue.  \n//      3) A SlimReaderWriter lock protecting the CSurfaceQueue object.  All of the\n//         high frequency calls grab shared locks (Enqueue/Flush/Dequeue) to allow\n//         parallel access to the queue.  The low frequency state changes\n//         (i.e. OpenProducer) will grab an exclusive lock.\n//      4) A critical section protecting the underlying circular queue.  Both Enqueue\n//         and dequeue will contend for this lock but the duration the lock is held\n//         is kept to a minimum.\n//\n\n//-----------------------------------------------------------------------------\n// Helper Functions\n//-----------------------------------------------------------------------------\nHRESULT CreateDeviceWrapper(IUnknown* pUnknown, ISurfaceQueueDevice** ppDevice)\n{\n    IDirect3DDevice9Ex* pD3D9Device;\n    ID3D10Device*       pD3D10Device;\n    ID3D11Device*       pD3D11Device;\n\n    HRESULT hr = S_OK;\n    *ppDevice  = NULL;\n\n    if (SUCCEEDED(pUnknown->QueryInterface(__uuidof(IDirect3DDevice9Ex), (void**)&pD3D9Device)))\n    {\n        pD3D9Device->Release();\n        *ppDevice = new QUEUE_NOTHROW_SPECIFIER CSurfaceQueueDeviceD3D9(pD3D9Device);\n    }\n    else if (SUCCEEDED(pUnknown->QueryInterface(__uuidof(ID3D10Device), (void**)&pD3D10Device)))\n    {\n        pD3D10Device->Release();\n        *ppDevice = new QUEUE_NOTHROW_SPECIFIER CSurfaceQueueDeviceD3D10(pD3D10Device);\n    }\n    else if (SUCCEEDED(pUnknown->QueryInterface(__uuidof(ID3D11Device), (void**)&pD3D11Device)))\n    {\n        pD3D11Device->Release();\n        *ppDevice = new QUEUE_NOTHROW_SPECIFIER CSurfaceQueueDeviceD3D11(pD3D11Device);\n    }\n    else\n    {\n        hr = E_INVALIDARG;    \n    }\n\n    if (SUCCEEDED(hr) && *ppDevice == NULL)\n    {\n        hr = E_OUTOFMEMORY;\n    }\n\n    return hr; \n};\n\n//-----------------------------------------------------------------------------\n// SharedSurfaceObject Implementation\n//-----------------------------------------------------------------------------\nSharedSurfaceObject::SharedSurfaceObject(UINT Width, UINT Height, DXGI_FORMAT Format)\n{\n    hSharedHandle   = NULL;\n    state           = SHARED_SURFACE_STATE_UNINITIALIZED;\n    queue           = NULL;\n\n    width           = Width;\n    height          = Height;\n    format          = Format;\n\n    pSurface        = NULL;\n}\n\nSharedSurfaceObject::~SharedSurfaceObject()\n{\n    // Release the reference to the created surface\n    if (pSurface)\n    {\n        pSurface->Release();\n    }\n}\n\n//-----------------------------------------------------------------------------\n// CreateSurfaceQueue\n//-----------------------------------------------------------------------------\nHRESULT WINAPI CreateSurfaceQueue(\n                    SURFACE_QUEUE_DESC*  pDesc,\n                    IUnknown*            pDevice,\n                    ISurfaceQueue**      ppQueue)\n{\n    HRESULT hr  = E_FAIL;\n    \n    if (ppQueue == NULL)\n    {\n        return E_INVALIDARG;\n    }\n    \n    *ppQueue    = NULL;\n\n    if (pDesc == NULL)\n    {\n        return E_INVALIDARG;\n    }\n\n    if (pDevice == NULL)\n    {\n        return E_INVALIDARG;\n    }\n\n    if (pDesc->NumSurfaces == 0)\n    {\n        return E_INVALIDARG;\n    }\n   \n    if (pDesc->Width == 0 || pDesc->Height == 0)\n    {\n        return E_INVALIDARG;\n    }\n\n    if (pDesc->Flags != 0 && pDesc->Flags != SURFACE_QUEUE_FLAG_SINGLE_THREADED)\n    {\n        return E_INVALIDARG;\n    }\n\n    CSurfaceQueue* pSurfaceQueue = new QUEUE_NOTHROW_SPECIFIER CSurfaceQueue();\n    if (!pSurfaceQueue)\n    {\n        hr = E_OUTOFMEMORY;\n        goto end;\n    }\n    \n    hr = pSurfaceQueue->Initialize(pDesc, pDevice, pSurfaceQueue);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    hr = pSurfaceQueue->QueryInterface(__uuidof(ISurfaceQueue), (void**)ppQueue);\n\nend:\n    if (FAILED(hr))\n    {\n        if (pSurfaceQueue)\n        {\n            delete pSurfaceQueue;\n        }\n        *ppQueue = NULL;\n    }\n\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\n// CSurfaceConsumer implementation\n//-----------------------------------------------------------------------------\n\n//-----------------------------------------------------------------------------\nCSurfaceConsumer:: CSurfaceConsumer(BOOL IsMultithreaded) :\n    m_RefCount(0),\n    m_IsMultithreaded(IsMultithreaded),\n    m_pQueue(NULL),\n    m_pDevice(NULL)\n{\n    if (m_IsMultithreaded)\n    {\n        InitializeCriticalSection(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nCSurfaceConsumer::~CSurfaceConsumer()\n{\n    if (m_pQueue)\n    {\n        m_pQueue->RemoveConsumer();\n        m_pQueue->Release();\n    }\n    if (m_pDevice)\n    {\n        delete m_pDevice;\n    }\n    if (m_IsMultithreaded)\n    {\n        DeleteCriticalSection(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceConsumer::Initialize(IUnknown* pDevice)\n{\n    ASSERT(pDevice);\n    ASSERT(m_pDevice == NULL);\n   \n    HRESULT hr;\n    hr = CreateDeviceWrapper(pDevice, &m_pDevice);\n\n    if (FAILED(hr))\n    {\n        if (m_pDevice)\n        {\n            delete m_pDevice;\n            m_pDevice = NULL;\n        }\n    }\n\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceConsumer::SetQueue(CSurfaceQueue* queue)\n{\n    ASSERT(!m_pQueue && queue);\n\n\tif (NULL != m_pQueue || NULL == queue)\n\t{\n\t\treturn;\n\t}\n\n    m_pQueue = queue;\n    m_pQueue->AddRef();\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceConsumer::Dequeue(\n                        REFIID id,\n                        IUnknown** ppSurface,\n                        void*  pBuffer,\n                        UINT*  BufferSize,\n                        DWORD  dwTimeout)\n{\n    ASSERT(m_pQueue);\n\n\tif (NULL == m_pQueue)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n\n    if (m_IsMultithreaded)\n    {\n        EnterCriticalSection(&m_lock);\n    }\n\n    // Validate that REFIID is correct for a surface from this device\n    if (!m_pDevice->ValidateREFIID(id))\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n    if (ppSurface == NULL)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    *ppSurface = NULL;\n    \n    // Forward to queue\n    hr = m_pQueue->Dequeue(ppSurface, pBuffer, BufferSize, dwTimeout);\n\nend:\n    if (m_IsMultithreaded)\n    {\n        LeaveCriticalSection(&m_lock);\n    }\n    return hr;\n}\n\n\n//-----------------------------------------------------------------------------\n// CSurfaceProducer implementation\n//-----------------------------------------------------------------------------\n\n//-----------------------------------------------------------------------------\nCSurfaceProducer:: CSurfaceProducer(BOOL IsMultithreaded) :\n    m_RefCount(0),\n    m_IsMultithreaded(IsMultithreaded),\n    m_pQueue(NULL),\n    m_pDevice(NULL),\n    m_nStagingResources(0),\n    m_pStagingResources(NULL),\n    m_uiStagingResourceHeight(0),\n    m_uiStagingResourceWidth(0),\n    m_iCurrentResource(0)\n{\n    if (m_IsMultithreaded)\n    {\n        InitializeCriticalSection(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nCSurfaceProducer::~CSurfaceProducer()\n{\n    if (m_pQueue)\n    {\n        m_pQueue->RemoveProducer();\n        m_pQueue->Release();\n    }\n\n    if (m_pStagingResources)\n    {\n        for (UINT i = 0; i < m_nStagingResources; i++)\n        {\n            if (m_pStagingResources[i])\n            {\n                m_pStagingResources[i]->Release();\n            }\n        }\n        delete[] m_pStagingResources;\n    }\n    \n    if (m_pDevice)\n    {\n        delete m_pDevice;\n    }\n    \n    if (m_IsMultithreaded)\n    { \n        DeleteCriticalSection(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceProducer::SetQueue(CSurfaceQueue* queue)\n{\n    ASSERT(!m_pQueue && queue);\n\n\tif (NULL != m_pQueue || NULL == queue)\n\t{\n\t\treturn;\n\t}\n\n    m_pQueue = queue;\n    m_pQueue->AddRef();\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceProducer::Initialize(IUnknown* pDevice, UINT uNumSurfaces, SURFACE_QUEUE_DESC* queueDesc)\n{\n    ASSERT(pDevice);\n    ASSERT(!m_pStagingResources && m_nStagingResources == 0)\n   \n    HRESULT hr = S_OK;\n    hr = CreateDeviceWrapper(pDevice, &m_pDevice);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    m_pStagingResources = new QUEUE_NOTHROW_SPECIFIER IUnknown*[uNumSurfaces];\n    if (!m_pStagingResources)\n    {\n        hr = E_OUTOFMEMORY;\n        goto end;\n    }\n    ZeroMemory(m_pStagingResources, sizeof(IUnknown*) * uNumSurfaces);\n    m_nStagingResources = uNumSurfaces;\n   \n    // Determine the size of the staging resource in case the queue surface is less than SHARED_SURFACE_COPY_SIZE\n    m_uiStagingResourceWidth    = min(queueDesc->Width, SHARED_SURFACE_COPY_SIZE);\n    m_uiStagingResourceHeight   = min(queueDesc->Height, SHARED_SURFACE_COPY_SIZE);\n\n    // Create the staging resources\n    for (UINT i = 0; i < m_nStagingResources; i++)\n    {\n        if (FAILED(hr = m_pDevice->CreateCopyResource(queueDesc->Format, m_uiStagingResourceWidth,\n                                                      m_uiStagingResourceHeight, &(m_pStagingResources[i]))))\n        {\n            goto end;\n        }\n    }\n\nend:\n    if (FAILED(hr))\n    {\n        if (m_pStagingResources)\n        {\n            for (UINT i = 0; i < m_nStagingResources; i++)\n            {\n                if (m_pStagingResources[i])\n                {\n                    m_pStagingResources[i]->Release();\n                }\n            }\n            delete[] m_pStagingResources;\n            m_pStagingResources = NULL;\n            m_nStagingResources = 0;\n        }\n\n        if (m_pDevice)\n        {\n            delete m_pDevice;\n            m_pDevice = NULL;\n        }\n    }\n\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceProducer::Enqueue(\n                        IUnknown*   pSurface,\n                        void*       pBuffer,\n                        UINT        BufferSize,\n                        DWORD       Flags )\n{\n    //\n    // This function essentially does simple error checking and then\n    // forwards the call to the queue object.  The SurfaceProducer\n    // maintains a circular buffer of staging resources to use and will\n    // pass the next availible one to the queue.\n    //\n\n    ASSERT(m_pQueue);\n\n\tif (NULL == m_pQueue)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    if (m_IsMultithreaded)\n    {\n        EnterCriticalSection(&m_lock);\n    }\n\n    HRESULT hr;\n\n    if (m_pDevice == NULL)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n    if (!pSurface)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n    if (Flags && Flags != SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    // Forward call to queue\n    hr = m_pQueue->Enqueue(\n                            pSurface, \n                            pBuffer, \n                            BufferSize, \n                            Flags, \n                            m_pStagingResources[m_iCurrentResource],\n                            m_uiStagingResourceWidth,\n                            m_uiStagingResourceHeight\n                          );\n    \n    if (hr == DXGI_ERROR_WAS_STILL_DRAWING)\n    {\n        //\n        // Increment the staging resource only if the current one is still\n        // being used.  This only happens if the function returns with \n        // DXGI_ERROR_WAS_STILL_DRAWING indicating that a future flush \n        // will still need the resource\n        //\n        // We do not need to worry about wrapping around and reusing staging\n        // surfaces that are currently in use.  The design of the queue makes\n        // it invalid to enqueue when the queue is already full.  If the user\n        // does that, the queue will fail the call with E_INVALIDARG.\n        m_iCurrentResource = (m_iCurrentResource + 1) % m_nStagingResources;\n    }\n\nend:\n    if (m_IsMultithreaded)\n    {\n        LeaveCriticalSection(&m_lock);\n    }\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceProducer::Flush(\n                        DWORD       Flags,\n                        UINT*       NumSurfaces )\n{\n    ASSERT(m_pQueue);\n\n\tif (NULL == m_pQueue)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    if (m_IsMultithreaded)\n    {\n        EnterCriticalSection(&m_lock);\n    }\n\n    HRESULT hr;\n\n    if (m_pDevice == NULL)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n    if (Flags && Flags != SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n    \n    // Forward call to queue\n    hr = m_pQueue->Flush(Flags, NumSurfaces);\n\nend:\n    if (m_IsMultithreaded)\n    {\n        LeaveCriticalSection(&m_lock);\n    }\n    return hr;\n}\n\n\n\n//-----------------------------------------------------------------------------\n// CSurfaceQueue implementation\n//-----------------------------------------------------------------------------\n\n//-----------------------------------------------------------------------------\nCSurfaceQueue:: CSurfaceQueue()\n    :\n        m_RefCount(0),\n        m_IsMultithreaded(TRUE),\n        m_hSemaphore(NULL),\n        m_pRootQueue(NULL),\n        m_NumQueuesInNetwork(0),\n        m_pConsumer(NULL),\n        m_pProducer(NULL),\n        m_pCreator(NULL),\n        m_SurfaceQueue(NULL),\n        m_QueueHead(0),\n        m_QueueSize(0),\n        m_ConsumerSurfaces(NULL),\n        m_CreatedSurfaces(NULL),\n        m_iEnqueuedHead(0),\n        m_nEnqueuedSurfaces(0)\n{\n}\n\n//-----------------------------------------------------------------------------\nCSurfaceQueue::~CSurfaceQueue()\n{\n    Destroy();\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::Destroy()\n{\n    RemoveQueueFromNetwork();\n    \n    // The ref counting should guarantee that the root queue object\n    // is the last to be deleted\n    if (m_pRootQueue != this)\n    {\n        m_pRootQueue->Release();\n    }\n    else\n    {\n        ASSERT(m_NumQueuesInNetwork == 0);\n    }\n    \n    // The root queue will destroy the creating device\n    if (m_pCreator)\n    {\n        delete m_pCreator;\n        m_pCreator = NULL;\n    }\n\n    // Release all opened surfaces\n    if (m_ConsumerSurfaces)\n    {\n        for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n        {\n            if (m_ConsumerSurfaces[i].pSurface)\n            {\n                m_ConsumerSurfaces[i].pSurface->Release();\n            }\n        }\n        delete[] m_ConsumerSurfaces;\n        m_ConsumerSurfaces = NULL;\n    }\n\n    // Clean up the allocated meta data buffers\n    if (m_SurfaceQueue)\n    {\n        for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n        {\n            if (m_SurfaceQueue[i].pMetaData)\n            {\n                delete[] m_SurfaceQueue[i].pMetaData;\n            }\n        }\n        delete[] m_SurfaceQueue;\n        m_SurfaceQueue = NULL;\n    }\n\n    // The root queue object created the surfaces.  All other queue\n    // objects only have a reference.\n    if (m_CreatedSurfaces)\n    {\n        for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n        {\n            if (m_pRootQueue == this && m_CreatedSurfaces[i])\n            {\n                delete m_CreatedSurfaces[i];\n            }\n            m_CreatedSurfaces[i] = NULL;\n        }\n        delete[] m_CreatedSurfaces;\n        m_CreatedSurfaces = NULL;\n    }\n\n    m_pConsumer = NULL;\n    m_pProducer = NULL;\n\n    if (m_IsMultithreaded)\n    {\n        if (m_hSemaphore)\n        {\n            CloseHandle(m_hSemaphore);\n            m_hSemaphore = NULL;\n        }\n        DeleteCriticalSection(&m_QueueLock);\n    }\n    else\n    {\n        m_nFlushedSurfaces = 0;\n    }\n}\n\n//-----------------------------------------------------------------------------\nISurfaceQueueDevice* CSurfaceQueue::GetCreatorDevice()\n{\n    return m_pRootQueue->m_pCreator;\n}\n\n//-----------------------------------------------------------------------------\nUINT CSurfaceQueue::GetNumQueuesInNetwork()\n{\n    return m_pRootQueue->m_NumQueuesInNetwork;\n}\n\n\n//-----------------------------------------------------------------------------\nUINT CSurfaceQueue::AddQueueToNetwork()\n{\n    if (m_pRootQueue == this)\n    {\n        return InterlockedIncrement(&m_NumQueuesInNetwork);\n    }\n    else\n    {\n        return m_pRootQueue->AddQueueToNetwork();\n    }\n}\n\n//-----------------------------------------------------------------------------\nUINT CSurfaceQueue::RemoveQueueFromNetwork()\n{\n    ASSERT(GetNumQueuesInNetwork() > 0);\n    if (m_pRootQueue == this)\n    {\n        return InterlockedDecrement(&m_NumQueuesInNetwork);\n    }\n    else\n    {\n        return m_pRootQueue->RemoveQueueFromNetwork();\n    }\n}\n\n//-----------------------------------------------------------------------------\nSharedSurfaceObject* CSurfaceQueue::GetSurfaceObjectFromHandle(HANDLE handle)\n{\n    // \n    // This does a linear search through the created surfaces for the specific \n    // handle.  When the user enqueues, we get the shared handle from surface\n    // and then use the handle to get to the SharedSurfaceObject.  This essentially\n    // converts from a \"generic d3d surface\" to a \"surface queue surface\".\n    //\n    // This search is linear with the number of surfaces created.  We expect that\n    // number to be small.\n    //\n    ASSERT(handle);\n    ASSERT(m_CreatedSurfaces);\n\n\tif (NULL == handle || NULL == m_CreatedSurfaces)\n\t{\n\t\treturn NULL;\n\t}\n\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        if (m_CreatedSurfaces[i]->hSharedHandle == handle)\n        {\n            return m_CreatedSurfaces[i];\n        }\n    }\n    // The user tried to enqueue an shared surface that was not part of the queue.\n    return NULL;\n}\n\n//-----------------------------------------------------------------------------\nIUnknown* CSurfaceQueue::GetOpenedSurface(const SharedSurfaceObject* pObject) const\n{\n    // \n    // On OpenConsumer, all of the shared surfaces will be opened by the consuming\n    // device and cached.  On dequeue, we simply look in the cache and return the\n    // appropriate surface, getting a significant perf bonus over opening/closing\n    // the surface on every dequeue/enqueue.\n    //\n    // This method is also linear with respect to the number of surfaces and a more\n    // scalable data structure can be used if the number of surfaces is used.\n    //\n    ASSERT(pObject);\n    ASSERT(m_ConsumerSurfaces);\n\n\tif (NULL == pObject || NULL == m_ConsumerSurfaces)\n\t{\n\t\treturn NULL;\n\t}\n\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        if (m_ConsumerSurfaces[i].pObject == pObject)\n        {\n            return m_ConsumerSurfaces[i].pSurface;\n        }\n    }\n    return NULL;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::AllocateMetaDataBuffers()\n{\n    // This function allocates the meta data buffers during creation time.\n    if (m_Desc.MetaDataSize != 0)\n    {\n        for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n        {\n            m_SurfaceQueue[i].pMetaData = new QUEUE_NOTHROW_SPECIFIER BYTE[m_Desc.MetaDataSize];\n            if (m_SurfaceQueue[i].pMetaData == NULL)\n            {\n                return E_OUTOFMEMORY;\n            }\n        }\n    }\n    return S_OK;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::CreateSurfaces()\n{\n    //\n    // This function is only called by the root queue to create the surfaces.  \n    // The queue has the property that the root queue starts off full (all the\n    // surfaces on it are ready for dequeue.  This function will use the creating\n    // device to create the shared surfaces and initialize them for dequeue.\n    //\n    \n    HRESULT hr = S_OK;\n    ASSERT(m_pRootQueue == this);\n\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        SharedSurfaceObject* pSurfaceObject = new QUEUE_NOTHROW_SPECIFIER SharedSurfaceObject(m_Desc.Width, m_Desc.Height, m_Desc.Format);\n        if (!pSurfaceObject)\n        {\n            return E_OUTOFMEMORY;\n        }\n\n        m_CreatedSurfaces[i] = pSurfaceObject;\n\n        if (FAILED(hr = m_pCreator->CreateSharedSurface(\n                                            m_Desc.Width, \n                                            m_Desc.Height,\n                                            m_Desc.Format,\n                                            &(pSurfaceObject->pSurface),\n                                            &(pSurfaceObject->hSharedHandle)\n                                            )))\n        {\n            return hr;\n        }\n\n        // Important to note that created surfaces start in the flushed state.  This\n        // lets the system start in a state that makes it ready to go.\n        m_SurfaceQueue[i].surface = m_CreatedSurfaces[i];\n        m_SurfaceQueue[i].surface->state  = SHARED_SURFACE_STATE_FLUSHED;\n        m_SurfaceQueue[i].surface->queue  = this;\n    }\n\n    return S_OK;\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::CopySurfaceReferences(CSurfaceQueue* pRootQueue)\n{\n    // This is called by cloned devices.  They simply take a reference\n    // to the shared created surfaces.\n    ASSERT(m_pRootQueue != this);\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        m_CreatedSurfaces[i] = pRootQueue->m_CreatedSurfaces[i];\n    }\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::Initialize(SURFACE_QUEUE_DESC* pDesc, \n                                      IUnknown* pDevice, \n                                      CSurfaceQueue* pRootQueue)\n{\n    ASSERT(pDesc);\n    ASSERT(pRootQueue);\n\n\tif (NULL == pDesc || NULL == pRootQueue)\n\t{\n\t\treturn E_FAIL;\n\t}\n\n    HRESULT hr = S_OK;\n\n    m_Desc              = *pDesc;\n    m_pRootQueue        = pRootQueue;\n    m_IsMultithreaded   = !(m_Desc.Flags & SURFACE_QUEUE_FLAG_SINGLE_THREADED);\n\n    AddQueueToNetwork();\n   \n    if (m_IsMultithreaded)\n    { \n        InitializeCriticalSection(&m_QueueLock);\n    }\n\n    // Allocate Queue\n    ASSERT(!m_SurfaceQueue);\n    m_SurfaceQueue = new QUEUE_NOTHROW_SPECIFIER SharedSurfaceQueueEntry[pDesc->NumSurfaces];\n    if (!m_SurfaceQueue)\n    {\n        hr = E_OUTOFMEMORY;\n        goto cleanup;\n    }\n    ZeroMemory(m_SurfaceQueue, sizeof(SharedSurfaceQueueEntry) * pDesc->NumSurfaces);\n\n    // Allocate array to keep track of opened surfaces\n    ASSERT(!m_ConsumerSurfaces);\n    m_ConsumerSurfaces = new QUEUE_NOTHROW_SPECIFIER SharedSurfaceOpenedMapping[pDesc->NumSurfaces];\n    if (!m_ConsumerSurfaces)\n    {\n        hr = E_OUTOFMEMORY;\n        goto cleanup;\n    }\n    ZeroMemory(m_ConsumerSurfaces, sizeof(SharedSurfaceOpenedMapping) * pDesc->NumSurfaces);\n\n    // Allocate created surface tracking list\n    ASSERT(!m_CreatedSurfaces);\n    m_CreatedSurfaces = new QUEUE_NOTHROW_SPECIFIER SharedSurfaceObject*[pDesc->NumSurfaces];\n    if (!m_CreatedSurfaces)\n    {\n        hr = E_OUTOFMEMORY;\n        goto cleanup;\n    }\n    ZeroMemory(m_CreatedSurfaces, sizeof(SharedSurfaceObject*) * pDesc->NumSurfaces);\n\n    // If this is the root queue, create the surfaces\n    if (m_pRootQueue == this)\n    {\n        ASSERT(pDevice);\n\n        hr = CreateDeviceWrapper(pDevice, &m_pCreator);\n        if (FAILED(hr))\n        {\n            ASSERT(m_pCreator == NULL);\n            goto cleanup;\n        }\n\n        hr = CreateSurfaces();\n        if (FAILED(hr))\n        {\n            goto cleanup;\n        }\n        m_QueueSize         = pDesc->NumSurfaces;\n    }\n    else\n    {\n        // Increment the reference count on the src queue\n        m_pRootQueue->AddRef();\n        CopySurfaceReferences(pRootQueue); \n        m_QueueSize         = 0;\n    }\n\n    if (m_Desc.MetaDataSize)\n    {\n       if (FAILED(hr = AllocateMetaDataBuffers()))\n       {\n           goto cleanup;\n       }\n    }\n    \n    ASSERT(m_pRootQueue);\n\n    if (m_IsMultithreaded)\n    {\n        // Create Semaphore for queue synchronization\n        m_hSemaphore = CreateSemaphore(NULL, \n                        m_pRootQueue == this ? pDesc->NumSurfaces : 0, \n                        pDesc->NumSurfaces, \n                        NULL);\n        if (m_hSemaphore == NULL)\n        {\n            hr = HRESULT_FROM_WIN32(GetLastError());\n            goto cleanup;\n        }\n\n        \n        // Initialize the slim reader/writer lock\n        InitializeSRWLock(&m_lock);\n    }\n    else\n    {\n\t\tm_nFlushedSurfaces = m_pRootQueue == this ? pDesc->NumSurfaces : 0;\n    }\n\ncleanup:\n    // The object will get destroyed if initialize fails.  Cleanup\n    // will happen then.\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::OpenConsumer(\n                    IUnknown*              pDevice,\n                    ISurfaceConsumer**     ppConsumer)\n{\n    if (pDevice == NULL)\n    {\n        return E_INVALIDARG;\n    }\n    if (ppConsumer == NULL)\n    {\n        return E_INVALIDARG;\n    }\n\n    *ppConsumer = NULL;\n\n    HRESULT hr = E_FAIL;\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockExclusive(&m_lock);\n    }\n\n\t// \n\t// If a consumer exists, we need to bail early. The normal error \n\t// path will deallocate the current consumer.  Instead this will \n\t// be a no-op for the queue and E_INVALIDARG will be returned.\n\t//\n    if (m_pConsumer)\n    {\n        if (m_IsMultithreaded)\n        {\n            ReleaseSRWLockExclusive(&m_lock);\n        }\n        return E_INVALIDARG;\n    }\n\n    m_pConsumer = new QUEUE_NOTHROW_SPECIFIER CSurfaceConsumer(m_IsMultithreaded);\n    if (m_pConsumer == NULL)\n    {\n        hr = E_OUTOFMEMORY;\n        goto end;\n    }\n\n    hr = m_pConsumer->Initialize(pDevice);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    //\n    // For all the surfaces in the queue, we want to open it with the producing device.\n    // This guarantees that surfaces are only open at creation time.\n    //\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        ASSERT(m_CreatedSurfaces[i]);\n        ASSERT(m_ConsumerSurfaces);\n\n\t\tif (NULL == m_CreatedSurfaces[i] || NULL == m_ConsumerSurfaces)\n\t\t{\n\t\t\treturn E_FAIL;\n\t\t}\n\n        IUnknown*   pSurface = NULL;\n\n        hr = m_pConsumer->GetDevice()->OpenSurface(\n                                        m_CreatedSurfaces[i]->hSharedHandle, \n                                        (void**)&pSurface, \n                                        m_Desc.Width, \n                                        m_Desc.Height, \n                                        m_Desc.Format);\n        if (FAILED(hr))\n        {\n            goto end;\n        }\n\n        ASSERT(pSurface);\n    \n        m_ConsumerSurfaces[i].pObject     = m_CreatedSurfaces[i];\n        m_ConsumerSurfaces[i].pSurface    = pSurface;\n    }\n\n    hr = m_pConsumer->QueryInterface(__uuidof(ISurfaceConsumer), (void**) ppConsumer);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    m_pConsumer->SetQueue(this);\n\nend:\n    if (FAILED(hr))\n    {\n        *ppConsumer = NULL;\n        \n        if (m_pConsumer)\n        {\n            if (m_pConsumer->GetDevice())\n            {\n                for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n                {\n                    if (m_ConsumerSurfaces[i].pSurface)\n                    {\n                        m_ConsumerSurfaces[i].pSurface->Release();\n                    }\n                }\n            }\n            \n            ZeroMemory(m_ConsumerSurfaces, sizeof(SharedSurfaceOpenedMapping) * m_Desc.NumSurfaces);\n \n            delete m_pConsumer;\n            m_pConsumer = NULL;\n        }\n    }\n\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockExclusive(&m_lock);\n    }\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::OpenProducer(\n                    IUnknown*                   pDevice,\n                    ISurfaceProducer**     ppProducer)\n{\n    if (pDevice == NULL)\n    {\n        return E_INVALIDARG;\n    }\n    if (ppProducer == NULL)\n    {\n        return E_INVALIDARG;\n    }\n\n    *ppProducer = NULL;\n\n    HRESULT hr = E_FAIL;\n\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockExclusive(&m_lock);\n    }\n\n    if (m_pProducer)\n    {\n        if (m_IsMultithreaded)\n        {\n            ReleaseSRWLockExclusive(&m_lock);\n        }\n        return E_INVALIDARG;\n    }\n\n    m_pProducer = new QUEUE_NOTHROW_SPECIFIER CSurfaceProducer(m_IsMultithreaded);\n    if (m_pProducer == NULL)\n    {\n        hr = E_OUTOFMEMORY;\n        goto end;\n    }\n\n    hr = m_pProducer->Initialize(pDevice, m_Desc.NumSurfaces, &m_Desc);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n    \n    hr = m_pProducer->QueryInterface(__uuidof(ISurfaceProducer), (void**)ppProducer);\n    if (FAILED (hr))\n    {\n        goto end;\n    }\n\n    m_pProducer->SetQueue(this);\n\nend:\n    if (FAILED(hr))\n    {\n        *ppProducer = NULL;\n        if (m_pProducer)\n        {\n            delete m_pProducer;\n            m_pProducer = NULL;\n            *ppProducer = NULL;\n        }\n    }\n\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockExclusive(&m_lock);\n    }\n    \n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::RemoveProducer()\n{\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockExclusive(&m_lock);\n    }\n    \n    ASSERT(m_pProducer);\n    m_pProducer = NULL;\n\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockExclusive(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::RemoveConsumer()\n{\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockExclusive(&m_lock);\n    }\n\n    ASSERT(m_pConsumer && m_pConsumer->GetDevice());\n    for (UINT i = 0; i < m_Desc.NumSurfaces; i++)\n    {\n        if (m_ConsumerSurfaces[i].pSurface)\n        {\n            m_ConsumerSurfaces[i].pSurface->Release();\n        }\n    }\n    ZeroMemory(m_ConsumerSurfaces, sizeof(SharedSurfaceOpenedMapping) * m_Desc.NumSurfaces);\n    m_pConsumer = NULL; \n    \n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockExclusive(&m_lock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::Clone(\n                    SURFACE_QUEUE_CLONE_DESC*   pDesc,\n                    ISurfaceQueue**        ppQueue)\n{\n    // Have all the clones originate from the root queue.  This makes tracking\n    // referenes easier.\n    if (m_pRootQueue != this)\n    {\n        return m_pRootQueue->Clone(pDesc, ppQueue);\n    }\n\n    if (!pDesc)\n    {\n        return E_INVALIDARG;\n    }\n    if (!ppQueue)\n    {\n        return E_INVALIDARG;\n    }\n    if (pDesc->Flags != 0 && pDesc->Flags != SURFACE_QUEUE_FLAG_SINGLE_THREADED)\n    {\n        return E_INVALIDARG;\n    }\n\n    *ppQueue    = NULL;\n    HRESULT hr  = E_FAIL;\n   \n    if (m_IsMultithreaded)\n    { \n        AcquireSRWLockExclusive(&m_lock);\n    }\n\n    SURFACE_QUEUE_DESC createDesc = m_Desc;\n    createDesc.MetaDataSize = pDesc->MetaDataSize;\n    createDesc.Flags = pDesc->Flags;\n\n    CSurfaceQueue* pQueue = new QUEUE_NOTHROW_SPECIFIER CSurfaceQueue();\n    if (!pQueue)\n    {\n        hr = E_OUTOFMEMORY;\n        goto end;\n    }\n    hr = pQueue->Initialize(&createDesc, NULL, this);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    hr = pQueue->QueryInterface(__uuidof(ISurfaceQueue), (void**)ppQueue);\n\nend:\n    if (FAILED(hr))\n    {\n        if (pQueue)\n        {\n            delete pQueue;\n        }\n        *ppQueue = NULL;\n    }\n\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockExclusive(&m_lock);\n    }\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::Enqueue(\n                            IUnknown*   pSurface, \n                            void*       pBuffer, \n                            UINT        BufferSize, \n                            DWORD       Flags,\n                            IUnknown*   pStagingResource,\n                            UINT        width,\n                            UINT        height\n                        )\n{\n    ASSERT( pSurface );\n\n    if (pBuffer && !BufferSize)\n    {\n        return E_INVALIDARG;\n    }\n    if (!pBuffer && BufferSize)\n    {\n        return E_INVALIDARG;\n    }\n    if (BufferSize > m_Desc.MetaDataSize)\n    {\n        return E_INVALIDARG;\n    }\n\n    HRESULT hr = E_FAIL;\n\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockShared(&m_lock);\n    }\n\n    ASSERT( m_pProducer );\n   \n    SharedSurfaceQueueEntry QueueEntry;\n    HANDLE                  hSharedHandle;\n    SharedSurfaceObject*    pSurfaceObject;\n\n    // Require both the producer and consumer to be initialized.\n    // This avoids a potential race condition\n    if (!m_pProducer || !m_pConsumer)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    \n    // Check that the queue is not full.  Enqueuing onto a full queue is\n    // not a scenario that makes sense\n    if (m_QueueSize == m_Desc.NumSurfaces)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    } \n\n    // Get the SharedSurfaceObject from the surface\n    hr = m_pProducer->GetDevice()->GetSharedHandle(pSurface, &hSharedHandle);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n    pSurfaceObject = GetSurfaceObjectFromHandle(hSharedHandle);\n\n    // Validate that this surface is one that can be part of this queue\n    if (pSurfaceObject == NULL)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    if (pSurfaceObject->state != SHARED_SURFACE_STATE_DEQUEUED)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    QueueEntry.surface          = pSurfaceObject;\n    QueueEntry.pMetaData        = (BYTE*)pBuffer;\n    QueueEntry.bMetaDataSize    = BufferSize;\n    QueueEntry.pStagingResource = NULL;\n\n    // Copy a small portion of the surface onto the staging surface\n    hr = m_pProducer->GetDevice()->CopySurface(pStagingResource, pSurface, width, height);\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n    \n    pSurfaceObject->state = SHARED_SURFACE_STATE_ENQUEUED;\n    pSurfaceObject->queue = this;\n\n    //\n    // At this point we have succesfully issued the copy to the staging resource.\n    // The surface will now must be added to the fifo queue either in the ENQUEUED\n    // or FLUSHED state.\n    //\n\n    // \n    // Do not attempt to flush the surfaces if the DO_NOT_WAIT flag was used.\n    // In these cases, simply add the surface to the FIFO queue as an ENQUEUED surface.\n    //\n    //\n    // Note: m_nEnqueuedSurfaces and m_iEnqueuedHead are protected by the lock in the \n    // SurfaceProducer.  This value is not shared between the Consumer and Producer and \n    // therefore does not need any sychronization in the queue object.\n    //\n    if (Flags & SURFACE_QUEUE_FLAG_DO_NOT_WAIT)\n    { \n        //\n        // The surface should go into the ENQUEUED but not FLUSHED state.\n        //\n\n        //\n        // Queue the entry into the fifo queue along with the staging resource for it\n        //\n        QueueEntry.pStagingResource = pStagingResource;\n        Enqueue(QueueEntry);\n        m_nEnqueuedSurfaces++;\n\n        //\n        // Since the surface did not flush, set the return to DXGI_ERROR_WAS_STILL_DRAWING\n        // and return.\n        //\n        hr = DXGI_ERROR_WAS_STILL_DRAWING;\n        goto end;\n    }\n    else if (m_nEnqueuedSurfaces)\n    {\n        //\n        // Enqueued was called without the DO_NOT_WAIT flag but there are enqueued surfaces\n        // currently not flushed.  First flush the existing surfaces and then perform the\n        // current Enqueue.\n        //\n        hr = Flush(0, NULL);\n        ASSERT(SUCCEEDED(hr));\n    }\n\n    //\n    // Force rendering to complete by locking the staging resource.\n    //\n    if (FAILED(hr = m_pProducer->GetDevice()->LockSurface(pStagingResource, Flags)))\n    {\n        goto end;\n    }\n    if (FAILED(hr = m_pProducer->GetDevice()->UnlockSurface(pStagingResource)))\n    {\n        goto end;\n    }\n    ASSERT(QueueEntry.pStagingResource == NULL); \n    //\n    // The call to lock the surface completed succesfully meaning the surface if flushed\n    // and ready for dequeue.  Mark the surface as such and add it to the fifo queue.\n    //\n    pSurfaceObject->state = SHARED_SURFACE_STATE_FLUSHED;\n\n    m_iEnqueuedHead = (m_iEnqueuedHead + 1) % m_Desc.NumSurfaces;\n    Enqueue(QueueEntry);\n\n    if (m_IsMultithreaded)\n    {\n        // Increment the semaphore\n        ReleaseSemaphore(m_hSemaphore, 1, NULL);\n    }\n    else\n    {\n        m_nFlushedSurfaces++;\n    }\n    \n\nend:\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockShared(&m_lock);\n    }\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::Dequeue(\n                            IUnknown**              ppSurface,\n                            void*                   pBuffer,\n                            UINT*                   BufferSize,\n                            DWORD                   dwTimeout  \n                        )\n{\n    if (!pBuffer && BufferSize)\n    {\n        return E_INVALIDARG;\n    }\n    if (pBuffer)\n    {\n       if (!BufferSize || *BufferSize == 0)\n       {\n            return E_INVALIDARG;\n       }\n       if (*BufferSize > m_Desc.MetaDataSize)\n       {\n           return E_INVALIDARG;\n       }\n    }\n\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockShared(&m_lock);\n    }\n\n    SharedSurfaceQueueEntry QueueElement;\n    IUnknown*               pSurface    = NULL;\n    HRESULT                 hr          = E_FAIL;\n\n    // Require both the producer and consumer to be initialized.\n    // This avoids a potential race condition\n    if (!m_pProducer || !m_pConsumer)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    if (m_IsMultithreaded)\n    {\n        // Wait on the semaphore until the queue is not empty\n        DWORD dwWait = WaitForSingleObject(m_hSemaphore, dwTimeout);\n        switch (dwWait)\n        {\n            case WAIT_ABANDONED:\n                hr = E_FAIL;\n                break;\n            case WAIT_OBJECT_0:\n                hr = S_OK;\n                break;\n            case WAIT_TIMEOUT:\n                hr = HRESULT_FROM_WIN32(WAIT_TIMEOUT);\n                break;\n            case WAIT_FAILED:\n                hr = HRESULT_FROM_WIN32(GetLastError());\n                break;\n            default:\n                hr = E_FAIL;\n                break;\n        }\n    }\n    else\n    {\n        // In the single threaded case, dequeuing on an empty \n        // will return immediately.  The error returned is not\n        // *exactly* right but it parallels the multithreaded\n        // case.\n        if (m_nFlushedSurfaces == 0)\n        {\n            hr = HRESULT_FROM_WIN32(WAIT_TIMEOUT);\n        }\n        else\n        {\n            m_nFlushedSurfaces--;\n            hr = S_OK;\n        }\n    }\n\n    \n    // Early return because of timeout or wait error\n    if (FAILED(hr))\n    {\n        goto end;\n    }\n\n\n    //\n    // At this point, there must be a surface in the queue ready to be\n    // dequeued.  Get a reference to the first surface make sure\n    // it is valid.  We don't want the situation where the surface is\n    // removed but then fails.\n    //\n\n    // At this point there must be an surface in the queue ready to go\n    // Dequeue it\n    \n    Front(QueueElement);\n\n    ASSERT (QueueElement.surface->state == SHARED_SURFACE_STATE_FLUSHED);\n    ASSERT (QueueElement.surface->queue == this);\n\n    //\n    // Update the state of the surface to dequeued\n    //\n    QueueElement.surface->state  = SHARED_SURFACE_STATE_DEQUEUED;\n    QueueElement.surface->device = m_pConsumer->GetDevice();   \n   \n    // \n    // Get the surface for the consuming device from the surface object\n    //\n    pSurface = GetOpenedSurface(QueueElement.surface);\n\n    ASSERT(pSurface);\n\n    pSurface->AddRef();\n    *ppSurface = pSurface;\n\n    // \n    // There should be no more failures after here\n    //\n    \n    if (pBuffer && QueueElement.bMetaDataSize)\n    {\n        memcpy(pBuffer, QueueElement.pMetaData, sizeof(BYTE) * QueueElement.bMetaDataSize);\n    }\n\n    //\n    // Store the actual number of bytes copied as meta data.\n    //\n    if (BufferSize)\n    {\n        *BufferSize = QueueElement.bMetaDataSize;\n    }\n\n    //\n    // Remove the element from the queue.  We do it at the very end in case there are\n    // errors.\n    //\n    Dequeue(QueueElement);\n\nend:\n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockShared(&m_lock);\n    }\n\n    return hr;\n}\n\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::Flush(\n                            DWORD   Flags,\n                            UINT*   pRemainingSurfaces\n                        )\n{\n    if (m_IsMultithreaded)\n    {\n        AcquireSRWLockShared(&m_lock);\n    }\n\n    HRESULT hr = S_OK; \n    UINT    uiFlushedSurfaces = 0;\n    UINT    index, i;\n\n    // Store this locally for the loop counter.  The loop will change the\n    // value of m_nEnqueuedSurfaces.\n    UINT    uiEnqueuedSize = m_nEnqueuedSurfaces;\n\n    // Require both the producer and consumer to be initialized.\n    // This avoids a potential race condition\n    if (!m_pProducer || !m_pConsumer)\n    {\n        hr = E_INVALIDARG;\n        goto end;\n    }\n\n    // Iterate over all queue entries starting at the head.\n    for (index = m_iEnqueuedHead, i = 0; i < uiEnqueuedSize; i++, index++)\n    {\n        index = index % m_Desc.NumSurfaces;\n        \n        SharedSurfaceQueueEntry& queueEntry = m_SurfaceQueue[index];\n  \n        ASSERT(queueEntry.surface->state == SHARED_SURFACE_STATE_ENQUEUED);\n        ASSERT(queueEntry.surface->queue == this);\n        ASSERT(queueEntry.pStagingResource);\n\n        IUnknown* pStagingResource = queueEntry.pStagingResource;\n        \n        // \n        // Attempt to lock the staging surface to see if the rendering\n        // is complete.\n        //\n        hr = m_pProducer->GetDevice()->LockSurface(pStagingResource, Flags);\n        if (FAILED(hr))\n        {\n            //\n            // As soon as the first surface is not flushed, skip the remaining\n            //\n            goto end;\n        }\n\n        hr = m_pProducer->GetDevice()->UnlockSurface(pStagingResource);\n        ASSERT(SUCCEEDED(hr));\n\n        // When the lock is complete, rendering is complete and the the surface is\n        // ready for dequeue\n        queueEntry.surface->state = SHARED_SURFACE_STATE_FLUSHED;\n        queueEntry.pStagingResource = NULL;\n\n        uiFlushedSurfaces++;\n       \n        // This is protected by the SurfaceProducer lock.\n        m_nEnqueuedSurfaces--;\n        m_iEnqueuedHead = (m_iEnqueuedHead + 1) % m_Desc.NumSurfaces;\n\n        if (m_IsMultithreaded)\n        {\n            // Increment the semaphore count\n            ReleaseSemaphore(m_hSemaphore, 1, NULL);\n        }\n        else\n        {\n            m_nFlushedSurfaces++;\n        }\n    }\n\nend:\n\n    if (pRemainingSurfaces)\n    {\n        *pRemainingSurfaces = m_nEnqueuedSurfaces;\n    }\n    \n    if (m_IsMultithreaded)\n    {\n        ReleaseSRWLockShared(&m_lock);\n    }\n\n    return hr; \n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::Front(SharedSurfaceQueueEntry& entry)\n{\n    entry = m_SurfaceQueue[m_QueueHead];\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::Dequeue(SharedSurfaceQueueEntry& entry)\n{\n    // The semaphore protecting access to the queue guarantees that the queue\n    // can not be empty.\n    if (m_IsMultithreaded)\n    {\n        EnterCriticalSection(&m_QueueLock);\n    }\n\n    entry = m_SurfaceQueue[m_QueueHead];\n    m_QueueHead = (m_QueueHead + 1) % m_Desc.NumSurfaces;\n    m_QueueSize--;\n\n    if (m_IsMultithreaded)\n    {\n        LeaveCriticalSection(&m_QueueLock);\n    }\n}\n\n//-----------------------------------------------------------------------------\nvoid CSurfaceQueue::Enqueue(SharedSurfaceQueueEntry& entry)\n{\n    //\n    // The validation in the queue should guarantee that the queue is not full\n    //\n    \n\n    if (m_IsMultithreaded)\n    {\n        EnterCriticalSection(&m_QueueLock);\n    }\n\n    UINT end = (m_QueueHead + m_QueueSize) % m_Desc.NumSurfaces;\n    m_QueueSize++;\n    \n    if (m_IsMultithreaded)\n    {\n        LeaveCriticalSection(&m_QueueLock);\n    }\n\n    m_SurfaceQueue[end].surface          = entry.surface;\n    m_SurfaceQueue[end].bMetaDataSize    = entry.bMetaDataSize;\n    m_SurfaceQueue[end].pStagingResource = entry.pStagingResource;\n    if (entry.bMetaDataSize)\n    {\n        memcpy(m_SurfaceQueue[end].pMetaData, entry.pMetaData, sizeof(BYTE) * entry.bMetaDataSize);\n    }\n\n}\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueue.h",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n/* this ALWAYS GENERATED file contains the definitions for the interfaces */\n\n\n /* File created by MIDL compiler version 7.00.0555 */\n/* Compiler settings for surfacequeue.idl:\n    Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 \n    protocol : dce , ms_ext, c_ext, robust\n    error checks: allocation ref bounds_check enum stub_data \n    VC __declspec() decoration level: \n         __declspec(uuid()), __declspec(selectany), __declspec(novtable)\n         DECLSPEC_UUID(), MIDL_INTERFACE()\n*/\n/* @@MIDL_FILE_HEADING(  ) */\n\n#pragma warning( disable: 4049 )  /* more than 64k source lines */\n\n\n/* verify that the <rpcndr.h> version is high enough to compile this file*/\n#ifndef __REQUIRED_RPCNDR_H_VERSION__\n#define __REQUIRED_RPCNDR_H_VERSION__ 500\n#endif\n\n/* verify that the <rpcsal.h> version is high enough to compile this file*/\n#ifndef __REQUIRED_RPCSAL_H_VERSION__\n#define __REQUIRED_RPCSAL_H_VERSION__ 100\n#endif\n\n#include \"rpc.h\"\n#include \"rpcndr.h\"\n\n#ifndef __RPCNDR_H_VERSION__\n#error this stub requires an updated version of <rpcndr.h>\n#endif // __RPCNDR_H_VERSION__\n\n#ifndef COM_NO_WINDOWS_H\n#include \"windows.h\"\n#include \"ole2.h\"\n#endif /*COM_NO_WINDOWS_H*/\n\n#ifndef __surfacequeue_h__\n#define __surfacequeue_h__\n\n#if defined(_MSC_VER) && (_MSC_VER >= 1020)\n#pragma once\n#endif\n\n/* Forward Declarations */ \n\n#ifndef __ISurfaceProducer_FWD_DEFINED__\n#define __ISurfaceProducer_FWD_DEFINED__\ntypedef interface ISurfaceProducer ISurfaceProducer;\n#endif \t/* __ISurfaceProducer_FWD_DEFINED__ */\n\n\n#ifndef __ISurfaceConsumer_FWD_DEFINED__\n#define __ISurfaceConsumer_FWD_DEFINED__\ntypedef interface ISurfaceConsumer ISurfaceConsumer;\n#endif \t/* __ISurfaceConsumer_FWD_DEFINED__ */\n\n\n#ifndef __ISurfaceQueue_FWD_DEFINED__\n#define __ISurfaceQueue_FWD_DEFINED__\ntypedef interface ISurfaceQueue ISurfaceQueue;\n#endif \t/* __ISurfaceQueue_FWD_DEFINED__ */\n\n\n/* header files for imported files */\n#include \"oaidl.h\"\n#include \"ocidl.h\"\n#include \"dxgitype.h\"\n\n#ifdef __cplusplus\nextern \"C\"{\n#endif \n\n\n/* interface __MIDL_itf_surfacequeue_0000_0000 */\n/* [local] */ \n\ntypedef struct SURFACE_QUEUE_DESC\n    {\n    UINT Width;\n    UINT Height;\n    DXGI_FORMAT Format;\n    UINT NumSurfaces;\n    UINT MetaDataSize;\n    DWORD Flags;\n    } \tSURFACE_QUEUE_DESC;\n\ntypedef struct SURFACE_QUEUE_CLONE_DESC\n    {\n    UINT MetaDataSize;\n    DWORD Flags;\n    } \tSURFACE_QUEUE_CLONE_DESC;\n\ntypedef \nenum SURFACE_QUEUE_FLAG\n    {\tSURFACE_QUEUE_FLAG_DO_NOT_WAIT\t= 0x1L,\n\tSURFACE_QUEUE_FLAG_SINGLE_THREADED\t= 0x2L\n    } \tSURFACE_QUEUE_FLAG;\n\n\n\nextern RPC_IF_HANDLE __MIDL_itf_surfacequeue_0000_0000_v0_0_c_ifspec;\nextern RPC_IF_HANDLE __MIDL_itf_surfacequeue_0000_0000_v0_0_s_ifspec;\n\n#ifndef __ISurfaceProducer_INTERFACE_DEFINED__\n#define __ISurfaceProducer_INTERFACE_DEFINED__\n\n/* interface ISurfaceProducer */\n/* [unique][local][uuid][object] */ \n\n\nEXTERN_C const IID IID_ISurfaceProducer;\n\n#if defined(__cplusplus) && !defined(CINTERFACE)\n    \n    MIDL_INTERFACE(\"B8B0B73B-79C1-4446-BB8A-19595018B0B7\")\n    ISurfaceProducer : public IUnknown\n    {\n    public:\n        virtual HRESULT STDMETHODCALLTYPE Enqueue( \n            /* [in] */ IUnknown *pSurface,\n            /* [in] */ void *pBuffer,\n            /* [in] */ UINT BufferSize,\n            /* [in] */ DWORD Flags) = 0;\n        \n        virtual HRESULT STDMETHODCALLTYPE Flush( \n            /* [in] */ DWORD Flags,\n            /* [out] */ UINT *NumSurfaces) = 0;\n        \n    };\n    \n#else \t/* C style interface */\n\n    typedef struct ISurfaceProducerVtbl\n    {\n        BEGIN_INTERFACE\n        \n        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( \n            ISurfaceProducer * This,\n            /* [in] */ REFIID riid,\n            /* [annotation][iid_is][out] */ \n            __RPC__deref_out  void **ppvObject);\n        \n        ULONG ( STDMETHODCALLTYPE *AddRef )( \n            ISurfaceProducer * This);\n        \n        ULONG ( STDMETHODCALLTYPE *Release )( \n            ISurfaceProducer * This);\n        \n        HRESULT ( STDMETHODCALLTYPE *Enqueue )( \n            ISurfaceProducer * This,\n            /* [in] */ IUnknown *pSurface,\n            /* [in] */ void *pBuffer,\n            /* [in] */ UINT BufferSize,\n            /* [in] */ DWORD Flags);\n        \n        HRESULT ( STDMETHODCALLTYPE *Flush )( \n            ISurfaceProducer * This,\n            /* [in] */ DWORD Flags,\n            /* [out] */ UINT *NumSurfaces);\n        \n        END_INTERFACE\n    } ISurfaceProducerVtbl;\n\n    interface ISurfaceProducer\n    {\n        CONST_VTBL struct ISurfaceProducerVtbl *lpVtbl;\n    };\n\n    \n\n#ifdef COBJMACROS\n\n\n#define ISurfaceProducer_QueryInterface(This,riid,ppvObject)\t\\\n    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) \n\n#define ISurfaceProducer_AddRef(This)\t\\\n    ( (This)->lpVtbl -> AddRef(This) ) \n\n#define ISurfaceProducer_Release(This)\t\\\n    ( (This)->lpVtbl -> Release(This) ) \n\n\n#define ISurfaceProducer_Enqueue(This,pSurface,pBuffer,BufferSize,Flags)\t\\\n    ( (This)->lpVtbl -> Enqueue(This,pSurface,pBuffer,BufferSize,Flags) ) \n\n#define ISurfaceProducer_Flush(This,Flags,NumSurfaces)\t\\\n    ( (This)->lpVtbl -> Flush(This,Flags,NumSurfaces) ) \n\n#endif /* COBJMACROS */\n\n\n#endif \t/* C style interface */\n\n\n\n\n#endif \t/* __ISurfaceProducer_INTERFACE_DEFINED__ */\n\n\n#ifndef __ISurfaceConsumer_INTERFACE_DEFINED__\n#define __ISurfaceConsumer_INTERFACE_DEFINED__\n\n/* interface ISurfaceConsumer */\n/* [unique][local][uuid][object] */ \n\n\nEXTERN_C const IID IID_ISurfaceConsumer;\n\n#if defined(__cplusplus) && !defined(CINTERFACE)\n    \n    MIDL_INTERFACE(\"97E305E1-1EC7-41a6-972C-99092DE6A31E\")\n    ISurfaceConsumer : public IUnknown\n    {\n    public:\n        virtual HRESULT STDMETHODCALLTYPE Dequeue( \n            /* [in] */ REFIID id,\n            /* [out] */ IUnknown **ppSurface,\n            /* [out] */ void *pBuffer,\n            /* [out][in] */ UINT *pBufferSize,\n            /* [in] */ DWORD dwTimeout) = 0;\n        \n    };\n    \n#else \t/* C style interface */\n\n    typedef struct ISurfaceConsumerVtbl\n    {\n        BEGIN_INTERFACE\n        \n        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( \n            ISurfaceConsumer * This,\n            /* [in] */ REFIID riid,\n            /* [annotation][iid_is][out] */ \n            __RPC__deref_out  void **ppvObject);\n        \n        ULONG ( STDMETHODCALLTYPE *AddRef )( \n            ISurfaceConsumer * This);\n        \n        ULONG ( STDMETHODCALLTYPE *Release )( \n            ISurfaceConsumer * This);\n        \n        HRESULT ( STDMETHODCALLTYPE *Dequeue )( \n            ISurfaceConsumer * This,\n            /* [in] */ REFIID id,\n            /* [out] */ IUnknown **ppSurface,\n            /* [out] */ void *pBuffer,\n            /* [out][in] */ UINT *pBufferSize,\n            /* [in] */ DWORD dwTimeout);\n        \n        END_INTERFACE\n    } ISurfaceConsumerVtbl;\n\n    interface ISurfaceConsumer\n    {\n        CONST_VTBL struct ISurfaceConsumerVtbl *lpVtbl;\n    };\n\n    \n\n#ifdef COBJMACROS\n\n\n#define ISurfaceConsumer_QueryInterface(This,riid,ppvObject)\t\\\n    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) \n\n#define ISurfaceConsumer_AddRef(This)\t\\\n    ( (This)->lpVtbl -> AddRef(This) ) \n\n#define ISurfaceConsumer_Release(This)\t\\\n    ( (This)->lpVtbl -> Release(This) ) \n\n\n#define ISurfaceConsumer_Dequeue(This,id,ppSurface,pBuffer,pBufferSize,dwTimeout)\t\\\n    ( (This)->lpVtbl -> Dequeue(This,id,ppSurface,pBuffer,pBufferSize,dwTimeout) ) \n\n#endif /* COBJMACROS */\n\n\n#endif \t/* C style interface */\n\n\n\n\n#endif \t/* __ISurfaceConsumer_INTERFACE_DEFINED__ */\n\n\n#ifndef __ISurfaceQueue_INTERFACE_DEFINED__\n#define __ISurfaceQueue_INTERFACE_DEFINED__\n\n/* interface ISurfaceQueue */\n/* [unique][local][uuid][object] */ \n\n\nEXTERN_C const IID IID_ISurfaceQueue;\n\n#if defined(__cplusplus) && !defined(CINTERFACE)\n    \n    MIDL_INTERFACE(\"1C08437F-48DF-467e-8D55-CA9268C73779\")\n    ISurfaceQueue : public IUnknown\n    {\n    public:\n        virtual HRESULT STDMETHODCALLTYPE OpenProducer( \n            /* [in] */ IUnknown *pDevice,\n            /* [out] */ ISurfaceProducer **ppProducer) = 0;\n        \n        virtual HRESULT STDMETHODCALLTYPE OpenConsumer( \n            /* [in] */ IUnknown *pDevice,\n            /* [out] */ ISurfaceConsumer **ppConsumer) = 0;\n        \n        virtual HRESULT STDMETHODCALLTYPE Clone( \n            /* [in] */ SURFACE_QUEUE_CLONE_DESC *pDesc,\n            /* [out] */ ISurfaceQueue **ppQueue) = 0;\n        \n    };\n    \n#else \t/* C style interface */\n\n    typedef struct ISurfaceQueueVtbl\n    {\n        BEGIN_INTERFACE\n        \n        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( \n            ISurfaceQueue * This,\n            /* [in] */ REFIID riid,\n            /* [annotation][iid_is][out] */ \n            __RPC__deref_out  void **ppvObject);\n        \n        ULONG ( STDMETHODCALLTYPE *AddRef )( \n            ISurfaceQueue * This);\n        \n        ULONG ( STDMETHODCALLTYPE *Release )( \n            ISurfaceQueue * This);\n        \n        HRESULT ( STDMETHODCALLTYPE *OpenProducer )( \n            ISurfaceQueue * This,\n            /* [in] */ IUnknown *pDevice,\n            /* [out] */ ISurfaceProducer **ppProducer);\n        \n        HRESULT ( STDMETHODCALLTYPE *OpenConsumer )( \n            ISurfaceQueue * This,\n            /* [in] */ IUnknown *pDevice,\n            /* [out] */ ISurfaceConsumer **ppConsumer);\n        \n        HRESULT ( STDMETHODCALLTYPE *Clone )( \n            ISurfaceQueue * This,\n            /* [in] */ SURFACE_QUEUE_CLONE_DESC *pDesc,\n            /* [out] */ ISurfaceQueue **ppQueue);\n        \n        END_INTERFACE\n    } ISurfaceQueueVtbl;\n\n    interface ISurfaceQueue\n    {\n        CONST_VTBL struct ISurfaceQueueVtbl *lpVtbl;\n    };\n\n    \n\n#ifdef COBJMACROS\n\n\n#define ISurfaceQueue_QueryInterface(This,riid,ppvObject)\t\\\n    ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) \n\n#define ISurfaceQueue_AddRef(This)\t\\\n    ( (This)->lpVtbl -> AddRef(This) ) \n\n#define ISurfaceQueue_Release(This)\t\\\n    ( (This)->lpVtbl -> Release(This) ) \n\n\n#define ISurfaceQueue_OpenProducer(This,pDevice,ppProducer)\t\\\n    ( (This)->lpVtbl -> OpenProducer(This,pDevice,ppProducer) ) \n\n#define ISurfaceQueue_OpenConsumer(This,pDevice,ppConsumer)\t\\\n    ( (This)->lpVtbl -> OpenConsumer(This,pDevice,ppConsumer) ) \n\n#define ISurfaceQueue_Clone(This,pDesc,ppQueue)\t\\\n    ( (This)->lpVtbl -> Clone(This,pDesc,ppQueue) ) \n\n#endif /* COBJMACROS */\n\n\n#endif \t/* C style interface */\n\n\n\n\n#endif \t/* __ISurfaceQueue_INTERFACE_DEFINED__ */\n\n\n/* interface __MIDL_itf_surfacequeue_0000_0003 */\n/* [local] */ \n\nHRESULT WINAPI CreateSurfaceQueue( SURFACE_QUEUE_DESC*  pDesc,\n                                   IUnknown*            pDevice,\n                                   ISurfaceQueue**      ppQueue);\n\n\nextern RPC_IF_HANDLE __MIDL_itf_surfacequeue_0000_0003_v0_0_c_ifspec;\nextern RPC_IF_HANDLE __MIDL_itf_surfacequeue_0000_0003_v0_0_s_ifspec;\n\n/* Additional Prototypes for ALL interfaces */\n\n/* end of Additional Prototypes */\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueue.inl",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#include \"SurfaceQueueImpl.h\"\n\n//-----------------------------------------------------------------------------\n// CSurfaceConsumer IUnknown implementation\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceConsumer::QueryInterface(REFIID id, void** ppInterface)\n{\n    *ppInterface = NULL;\n    if (id == __uuidof(ISurfaceConsumer))\n    {\n        *reinterpret_cast<ISurfaceConsumer**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    else if (id == __uuidof(IUnknown))\n    {\n        *reinterpret_cast<ISurfaceConsumer**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    return E_NOINTERFACE;\n}\n\nULONG CSurfaceConsumer::AddRef()\n{\n    InterlockedIncrement(&m_RefCount);\n    return m_RefCount;\n}\n\nULONG CSurfaceConsumer::Release()\n{\n    InterlockedDecrement(&m_RefCount);\n    ULONG RefCount = m_RefCount;\n    if (m_RefCount == 0)\n    {\n        delete this;\n    };\n    return RefCount;\n}\n\n//-----------------------------------------------------------------------------\n// CSurfaceProducer IUnknown implementation\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceProducer::QueryInterface(REFIID id, void** ppInterface)\n{\n    *ppInterface = NULL;\n    if (id == __uuidof(ISurfaceProducer))\n    {\n        *reinterpret_cast<ISurfaceProducer**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    else if (id == __uuidof(IUnknown))\n    {\n        *reinterpret_cast<ISurfaceProducer**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    return E_NOINTERFACE;\n}\n\nULONG CSurfaceProducer::AddRef()\n{\n    InterlockedIncrement(&m_RefCount);\n    return m_RefCount;\n}\n\nULONG CSurfaceProducer::Release()\n{\n    InterlockedDecrement(&m_RefCount);\n    ULONG RefCount = m_RefCount;\n    if (m_RefCount == 0)\n    {\n        delete this;\n    };\n    return RefCount;\n}\n\n//-----------------------------------------------------------------------------\n// CSurfaceQueue IUnknown implementation\n//-----------------------------------------------------------------------------\nHRESULT CSurfaceQueue::QueryInterface(REFIID id, void** ppInterface)\n{\n    *ppInterface = NULL;\n    if (id == __uuidof(ISurfaceQueue))\n    {\n        *reinterpret_cast<ISurfaceQueue**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    else if (id == __uuidof(IUnknown))\n    {\n        *reinterpret_cast<ISurfaceQueue**>(ppInterface) = this;\n        AddRef();\n        return S_OK;\n    }\n    return E_NOINTERFACE;\n}\n\nULONG CSurfaceQueue::AddRef()\n{\n    InterlockedIncrement(&m_RefCount);\n    return m_RefCount;\n}\n\nULONG CSurfaceQueue::Release()\n{\n    InterlockedDecrement(&m_RefCount);\n    ULONG RefCount = m_RefCount;\n    if (m_RefCount == 0)\n    {\n        delete this;\n    };\n    return RefCount;\n}\n\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueueImpl.h",
    "content": "// THIS CODE AND INFORMATION IS PROVIDED \"AS IS\" WITHOUT WARRANTY OF\n// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n// PARTICULAR PURPOSE.\n//\n// Copyright (c) Microsoft Corporation. All rights reserved\n\n#pragma once\n\n#include <d3d9.h>\n#include <D3D10_1.h>\n#include <D3D11.h>\n\n#include \"surfacequeue.h\"\n\n#include <assert.h>\n#define ASSERT(x) assert(x);\n\n//\n// This library doesnt use exceptions, and can be used in C++ environments with or without exception support.  \n// It uses a non-throwing new that returns null on out-of-memory.  The user of the library MUST provide a define \n// to tell it whether the C++ environment provides a standard throwing new.  In standard-compliant environments \n// define QUEUE_USE_CONFORMANT_NEW (the library will specify std::nothrow to opt for a non-throwing new.)  In \n// environments where new doesnt throw by default define QUEUE_USE_OLD_NEW.\n//\n// WARNING: If  you define QUEUE_USE_OLD_NEW and use the library with a throwing new the library will have undefined behavior.\n//\n// For the default Visual Studio solution, QUEUE_USE_CONFORMANT_NEW has been defined.\n//\n#if defined(QUEUE_USE_OLD_NEW)        \n#define QUEUE_NOTHROW_SPECIFIER \n#elif defined (QUEUE_USE_CONFORMANT_NEW)\n#define QUEUE_NOTHROW_SPECIFIER (std::nothrow) \n#else\n#error \"Please select operator new for out-of-memory exception behavior.\"\n#endif\n\n\n//\n// This defines the size of staging resource.  The purpose of the staging resource is\n// so we can copy & lock as a way to wait for rendering to complete.  We ideally, want \n// to copy to a 1x1 staging texture but because of various driver bugs, it is more reliable\n// to use a slightly bigger texture (16x16).\n//\n#define SHARED_SURFACE_COPY_SIZE (16)\n\n/****************************************************************************************\\\n *\n *  Implementation\n *\n\\****************************************************************************************/\nclass CSurfaceConsumer;\nclass CSurfaceProducer;\nclass CSurfaceQueue;\n\n// Interface to abstract away different runtime devices.  Each of the runtimes will\n// have a wrapper that implements this interface.  This interface contains a small\n// subset of the public APIs that the queue needs.\nclass ISurfaceQueueDevice\n{\n    public:\n        virtual HRESULT CreateSharedSurface(UINT Width, UINT Height, \n                                            DXGI_FORMAT format, \n                                            IUnknown** ppSurface,\n                                            HANDLE* handle) = 0;\n\n        // The surface queue is designed to only share 2D textures.  \n        //    D3D9 will be expecting IDirect3DTexture9\n        //    D3D10 will be expecting ID3D10Texture2D\n        //    D3D11 will be expecting ID3D11Texture2D \n        virtual BOOL ValidateREFIID(REFIID) = 0;\n\n        // Opens a shared surface with the given handle.\n        virtual HRESULT OpenSurface(HANDLE, void**, UINT w, UINT h, DXGI_FORMAT) = 0;\n\n        // Returns the shared handle for a queue surface.  This lets the queue\n        // validate that the surface the user provided is one owned by the queue.\n        virtual HRESULT GetSharedHandle(IUnknown*, HANDLE*) = 0;\n\n        // Creates a staging resource that will be used for the synchronization.\n        virtual HRESULT CreateCopyResource(DXGI_FORMAT, UINT width, UINT height, IUnknown** pRes) = 0;\n       \n        // Copy from the queue surface to the staging resource.\n        virtual HRESULT CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height) = 0;\n\n        // Locks the (staging) surface.  When this call completes, the surface\n        // has been flushed and is ready to be used by another device\n        virtual HRESULT LockSurface(IUnknown* pSurface, DWORD flags) = 0;\n\n        // Unlocks the (staging) surface.\n        virtual HRESULT UnlockSurface(IUnknown* pSurface) = 0;\n\n        // The wrapper maintins a refence to the underlying I*Device.\n        virtual ~ISurfaceQueueDevice() {};\n};\n\n// Implementation of SurfaceQueueDevice for D3D9Ex\nclass CSurfaceQueueDeviceD3D9 : public ISurfaceQueueDevice\n{\n    public:\n        HRESULT CreateSharedSurface(UINT Width, UINT Height, \n                                    DXGI_FORMAT format, \n                                    IUnknown** ppSurface,\n                                    HANDLE* handle);\n        BOOL ValidateREFIID(REFIID);\n        HRESULT OpenSurface(HANDLE, void**, UINT Width, UINT Height, DXGI_FORMAT format);\n        HRESULT GetSharedHandle(IUnknown*, HANDLE*);\n        HRESULT CreateCopyResource(DXGI_FORMAT, UINT width, UINT height, IUnknown** pRes);\n\n        HRESULT CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height);\n        HRESULT LockSurface(IUnknown* pSurface, DWORD flags);\n        HRESULT UnlockSurface(IUnknown* pSurface);\n\n        CSurfaceQueueDeviceD3D9(IDirect3DDevice9Ex* pD3D9Device);\n        ~CSurfaceQueueDeviceD3D9();\n\n    private:\n        IDirect3DDevice9Ex*     m_pDevice;\n};\n\n// Implementation of SurfaceQueueDevice for D3D10\nclass CSurfaceQueueDeviceD3D10 : public ISurfaceQueueDevice\n{\n    public:\n        HRESULT CreateSharedSurface(UINT Width, UINT Height, \n                                    DXGI_FORMAT format, \n                                    IUnknown** ppSurface,\n                                    HANDLE* handle);\n        BOOL ValidateREFIID(REFIID);\n        HRESULT OpenSurface(HANDLE, void**, UINT w, UINT h, DXGI_FORMAT);\n        HRESULT GetSharedHandle(IUnknown*, HANDLE*);\n        HRESULT CreateCopyResource(DXGI_FORMAT, UINT width, UINT height, IUnknown** pRes);\n\n        HRESULT CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height);\n        HRESULT LockSurface(IUnknown* pSurface, DWORD flags);\n        HRESULT UnlockSurface(IUnknown* pSurface);\n\n        CSurfaceQueueDeviceD3D10(ID3D10Device* pD3D10Device);\n        ~CSurfaceQueueDeviceD3D10();\n\n    private:\n        ID3D10Device*           m_pDevice;\n};\n\n// Implementation of SurfaceQueueDevice for D3D11\nclass CSurfaceQueueDeviceD3D11 : public ISurfaceQueueDevice\n{\n    public:\n        HRESULT CreateSharedSurface(UINT Width, UINT Height, \n                                    DXGI_FORMAT format, \n                                    IUnknown** ppSurface,\n                                    HANDLE* handle);\n        BOOL ValidateREFIID(REFIID);\n        HRESULT OpenSurface(HANDLE, void**, UINT w, UINT h, DXGI_FORMAT);\n        HRESULT GetSharedHandle(IUnknown*, HANDLE*);\n        HRESULT CreateCopyResource(DXGI_FORMAT, UINT width, UINT height, IUnknown** pRes);\n\n        HRESULT CopySurface(IUnknown* pDst, IUnknown* pSrc, UINT width, UINT height);\n        HRESULT LockSurface(IUnknown* pSurface, DWORD flags);\n        HRESULT UnlockSurface(IUnknown* pSurface);\n\n        CSurfaceQueueDeviceD3D11(ID3D11Device* pD3D11Device);\n        ~CSurfaceQueueDeviceD3D11();\n\n    private:\n        ID3D11Device*           m_pDevice;\n};\n\nenum SharedSurfaceState\n{\n    SHARED_SURFACE_STATE_UNINITIALIZED = 0,\n    SHARED_SURFACE_STATE_DEQUEUED,\n    SHARED_SURFACE_STATE_ENQUEUED,\n    SHARED_SURFACE_STATE_FLUSHED,\n};\n\n// This object is shared between all queues in a network and maintains state \n// about the surface.  \nstruct SharedSurfaceObject\n{\n    HANDLE                      hSharedHandle;\n    SharedSurfaceState          state; \n\n    UINT                        width;\n    UINT                        height;\n    DXGI_FORMAT                 format;\n\n    // Tracks which queue or device currently is using the surface\n    union\n    {\n        ISurfaceQueue*          queue;\n        ISurfaceQueueDevice*    device;\n    };\n    IUnknown*                   pSurface;\n\n    SharedSurfaceObject(UINT Width, UINT Height, DXGI_FORMAT format);\n    ~SharedSurfaceObject();\n};\n\nclass CSurfaceConsumer : public ISurfaceConsumer\n{\n    // Com Interfaces\n    public:\n        STDMETHOD(  QueryInterface) (REFIID ID, void** ppInterface);\n        STDMETHOD_( ULONG, AddRef)();\n        STDMETHOD_( ULONG, Release)();\n\n    // Public Interfaces\n    public:\n        STDMETHOD (Dequeue) (\n                                REFIID id,\n                                IUnknown** ppSurface,\n                                void*  pBuffer,\n                                UINT*  BufferSize,\n                                DWORD  dwTimeout \n                            );\n    // Implementation\n    public:\n        CSurfaceConsumer(BOOL IsMultithreaded);\n        ~CSurfaceConsumer();\n\n        HRESULT Initialize(IUnknown* pDevice);\n        void SetQueue(CSurfaceQueue*);\n\n        ISurfaceQueueDevice* GetDevice() { return m_pDevice; }\n    \n    private:\n        \n        LONG                                m_RefCount;\n\n        BOOL                                m_IsMultithreaded;\n        \n        // Weak reference to the queue this is part of\n        CSurfaceQueue*                      m_pQueue;\n\n        // The device this was opened with\n        ISurfaceQueueDevice*                m_pDevice;\n        \n        // Critical Section for the consumer\n        CRITICAL_SECTION                    m_lock;\n\n};\n\nclass CSurfaceProducer : public ISurfaceProducer\n{\n    // Com Interfaces\n    public:\n        STDMETHOD(  QueryInterface) (REFIID ID, void** ppInterface);\n        STDMETHOD_( ULONG, AddRef)();\n        STDMETHOD_( ULONG, Release)();\n    \n    // Public Interfaces\n    public:\n        STDMETHOD (Enqueue) ( \n                                IUnknown* pSurface,\n                                void*     pBuffer,\n                                UINT      BufferSize,\n                                DWORD     Flags \n                            );\n\n        STDMETHOD (Flush)   (\n                                DWORD     Flags,\n                                UINT*     NumSurfaces\n                            );\n\n    // Implementation\n    public:\n        CSurfaceProducer(BOOL IsMultithreaded);\n        ~CSurfaceProducer();\n\n        HRESULT Initialize(IUnknown* pDevice, UINT uNumSurfaces, SURFACE_QUEUE_DESC* queueDesc);\n        void SetQueue(CSurfaceQueue*);\n        \n        ISurfaceQueueDevice* GetDevice() { return m_pDevice; }\n\n    private:\n        LONG                        m_RefCount;       \n\n        BOOL                        m_IsMultithreaded;        \n\n        // Reference to the queue this is part of\n        CSurfaceQueue*              m_pQueue;\n\n        // The producer device\n        ISurfaceQueueDevice*        m_pDevice;\n        \n        // Critical Section for the producer\n        CRITICAL_SECTION            m_lock;\n\n        // Circular buffer of staging resources\n        UINT                        m_nStagingResources;\n        IUnknown**                  m_pStagingResources;\n\n        // Size of staging resource\n        UINT                        m_uiStagingResourceWidth;\n        UINT                        m_uiStagingResourceHeight;\n\n        // Index of current staging resource to use\n        UINT                        m_iCurrentResource;\n};\n\nclass CSurfaceQueue : public ISurfaceQueue\n{\n    // Com Functions\n    public:\n        STDMETHOD(  QueryInterface) (REFIID ID, void** ppInterface);\n        STDMETHOD_( ULONG, AddRef)();\n        STDMETHOD_( ULONG, Release)();\n\n    // ISurfaceQueue functions\n    public:\n        STDMETHOD (OpenProducer) (\n                                    IUnknown*                   pDevice,\n                                    ISurfaceProducer**          ppProducer\n                                 );\n\n        STDMETHOD (OpenConsumer) (\n                                    IUnknown*                   pDevice,\n                                    ISurfaceConsumer**          ppConsumer\n                                 );\n\n        STDMETHOD (Clone)        (   \n                                    SURFACE_QUEUE_CLONE_DESC*   pDesc,\n                                    ISurfaceQueue**             ppQueue \n                                 );\n    \n    // Implementation Functions\n    public:\n        CSurfaceQueue();\n        ~CSurfaceQueue();\n\n        // Initializes the queue.  Creates the surfaces, initializes the synchronization code\n        HRESULT Initialize(SURFACE_QUEUE_DESC*, IUnknown*, CSurfaceQueue*);\n\n        // Removes the producer device\n        void RemoveProducer();\n\n        // Removes the consumer device.  \n        void RemoveConsumer();\n\n        HRESULT Enqueue(\n                            IUnknown*   pSurface, \n                            void*       pBuffer, \n                            UINT        BufferSize, \n                            DWORD       Flags,\n                            IUnknown*   pStagingResource,\n                            UINT        width,\n                            UINT        height        \n                        );\n\n        HRESULT Dequeue(\n                            IUnknown**      ppSurface,\n                            void*       pBuffer,\n                            UINT*       BufferSize,\n                            DWORD       dwTimeout  \n                        );\n\n        HRESULT Flush(\n                            DWORD       Flags,\n                            UINT*       NumSurfaces\n                        );\n\n    private:\n        struct SharedSurfaceQueueEntry\n        {\n            SharedSurfaceObject*    surface;\n            BYTE*                   pMetaData;\n            UINT                    bMetaDataSize;\n            IUnknown*               pStagingResource;\n\n            SharedSurfaceQueueEntry()\n            {\n                surface             = NULL;\n                pMetaData           = NULL;\n                bMetaDataSize       = 0;\n                pStagingResource    = NULL;\n            }\n        };\n\n        struct SharedSurfaceOpenedMapping\n        {\n            SharedSurfaceObject*    pObject;\n            IUnknown*               pSurface;\n        };\n\n    private:\n        void Destroy();\n\n        HRESULT CreateSurfaces();\n        void CopySurfaceReferences(CSurfaceQueue*);\n        HRESULT AllocateMetaDataBuffers();\n\n        ISurfaceQueueDevice* GetCreatorDevice();\n\n        UINT GetNumQueuesInNetwork(); \n        UINT AddQueueToNetwork(); \n        UINT RemoveQueueFromNetwork();\n\n        void Dequeue(SharedSurfaceQueueEntry& entry);\n        void Enqueue(SharedSurfaceQueueEntry& entry);\n        void Front(SharedSurfaceQueueEntry& entry);\n\n        SharedSurfaceObject* GetSurfaceObjectFromHandle(HANDLE h);\n        IUnknown* GetOpenedSurface(const SharedSurfaceObject*) const;\n\n    private:\n        LONG                                    m_RefCount;\n\n        BOOL                                    m_IsMultithreaded;\n\n        // Synchronization object to handle concurrent dequeues and enqueues\n        // For the single threaded case, we can keep track of the number of\n        // availible surfaces to help the user prevent hanging on an empty\n        // queue.\n        union\n        {\n            HANDLE                              m_hSemaphore;\n\t    UINT\t\t\t\tm_nFlushedSurfaces;\n\t};\n\n        // Refernce to the source queue object\n        CSurfaceQueue*                          m_pRootQueue;\n\n        // Number of Queue objects in the network - only stored in root queue\n        volatile LONG                           m_NumQueuesInNetwork;\n\n        // References to producer and consumer objects\n        CSurfaceConsumer*                       m_pConsumer;\n        CSurfaceProducer*                       m_pProducer;\n\n        // Reference to the creating device\n        ISurfaceQueueDevice*                    m_pCreator;\n        \n        // FIFO Surface Queue\n        SharedSurfaceQueueEntry*                m_SurfaceQueue;\n        UINT                                    m_QueueHead;\n        UINT                                    m_QueueSize;\n\n        SharedSurfaceOpenedMapping*             m_ConsumerSurfaces;\n        SharedSurfaceObject**                   m_CreatedSurfaces;\n       \n        UINT                                    m_iEnqueuedHead; \n        UINT                                    m_nEnqueuedSurfaces;\n\n        SURFACE_QUEUE_DESC                      m_Desc;\n        \n        // Lock around all of the public queue functions.  This should have very little contention\n        // and is used to synchronize rare queue state changes (i.e. the consumer device changes).\n        SRWLOCK                                 m_lock;\n\n        // Lock for access to the underlying queue\n        CRITICAL_SECTION                        m_QueueLock;\n};\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueueInteropHelper.cpp",
    "content": "#include \"SurfaceQueueInteropHelper.h\"\n\n#pragma once\n\nusing namespace System;\nusing namespace System::Windows;\nusing namespace System::Windows::Interop;\n\n#define WIDTH 640\n#define HEIGHT 480\n\nREFIID                  surfaceIDDXGI = __uuidof(IDXGISurface);\nREFIID                  surfaceID9 = __uuidof(IDirect3DTexture9);\n\nnamespace Microsoft {\n    namespace Windows {\n        namespace Media {\n            HRESULT SurfaceQueueInteropHelper::InitD3D10()\n            {\n                HRESULT hr;\n                UINT\t\tDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;\n                //DWORD\t\tdwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;\n\n#ifdef _DEBUG\n                    // To debug DirectX, uncomment the following lines:\n\n                    //DeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;\n                    //dwShaderFlags\t|= D3D10_SHADER_DEBUG;\n#endif\n\n                {\n                    pin_ptr<ID3D10Device1*> pinD3D10Device = &m_D3D10Device;\n                    ID3D10Device1** ppD3D10Device = pinD3D10Device;\n\n                    if (FAILED(hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL,\n                        DeviceFlags, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, ppD3D10Device)))\n                    {\n                        return hr;\n                    }\n                }\n\n                D3D10_VIEWPORT vp;\n                vp.Width = WIDTH;\n                vp.Height = HEIGHT;\n                vp.MinDepth = 0.0f;\n                vp.MaxDepth = 1.0f;\n                vp.TopLeftX = 0;\n                vp.TopLeftY = 0;\n                m_D3D10Device->RSSetViewports(1, &vp);\n\n                return S_OK;\n            }\n\n            void SurfaceQueueInteropHelper::RenderToDXGI(IntPtr pdxgiSurface, bool isNewSurface)\n            {\n                if (nullptr != m_renderD2D)\n                {\n                    m_renderD2D(pdxgiSurface, isNewSurface);\n                }\n            }\n\n            void SurfaceQueueInteropHelper::CleanupD3D10()\n            {\n                ReleaseInterface(m_D3D10Device);\n            }\n\n            HRESULT SurfaceQueueInteropHelper::InitD3D9()\n            {\n                HRESULT hr;\n\n                {\n                    pin_ptr<IDirect3D9Ex*> pinD3D9 = &m_pD3D9;\n                    IDirect3D9Ex** ppD3D9 = pinD3D9;\n\n                    Direct3DCreate9Ex(D3D_SDK_VERSION, ppD3D9);\n                }\n\n                if (!m_pD3D9)\n                {\n                    return E_FAIL;\n                }\n\n                D3DPRESENT_PARAMETERS\t\td3dpp;\n                ZeroMemory(&d3dpp, sizeof(d3dpp));\n                d3dpp.Windowed = TRUE;\n                d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;\n                d3dpp.hDeviceWindow = NULL;\n                d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;\n\n                {\n                    pin_ptr<IDirect3DDevice9Ex*> pinD3D9Device = &m_pD3D9Device;\n                    IDirect3DDevice9Ex** ppD3D9Device = pinD3D9Device;\n\n                    hr = m_pD3D9->CreateDeviceEx(\n                        D3DADAPTER_DEFAULT,\n                        D3DDEVTYPE_HAL,\n                        m_hwnd,\n                        D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,\n                        &d3dpp,\n                        NULL,\n                        ppD3D9Device);\n                }\n\n                return hr;\n            }\n\n            void SurfaceQueueInteropHelper::CleanupD3D9()\n            {\n                ReleaseInterface(m_pD3D9Device);\n                ReleaseInterface(m_pD3D9);\n            }\n\n            void SurfaceQueueInteropHelper::CleanupSurfaces()\n            {\n                m_areSurfacesInitialized = false;\n\n                ReleaseInterface(m_BAProducer);\n                ReleaseInterface(m_ABProducer);\n                ReleaseInterface(m_BAConsumer);\n                ReleaseInterface(m_ABConsumer);\n\n                ReleaseInterface(m_ABQueue);\n                ReleaseInterface(m_BAQueue);\n            }\n\n            void SurfaceQueueInteropHelper::CleanupD3D()\n            {\n                if (m_areSurfacesInitialized)\n                {\n                    CleanupSurfaces();\n                }\n\n                m_isD3DInitialized = false;\n\n                CleanupD3D10();\n                CleanupD3D9();\n            }\n\n            HRESULT SurfaceQueueInteropHelper::InitD3D()\n            {\n                HRESULT hr = S_OK;\n\n                if (!m_isD3DInitialized)\n                {\n                    IFC(InitD3D9());\n                    IFC(InitD3D10());\n\n                    m_isD3DInitialized = true;\n                }\n\n            Cleanup:\n                if (FAILED(hr))\n                {\n                    CleanupD3D();\n                }\n\n                return hr;\n            }\n\n            HRESULT SurfaceQueueInteropHelper::InitSurfaces()\n            {\n                HRESULT hr = S_OK;\n\n                SURFACE_QUEUE_DESC  desc;\n                ZeroMemory(&desc, sizeof(desc));\n                desc.Width = m_pixelWidth;\n                desc.Height = m_pixelHeight;\n                desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;\n                desc.NumSurfaces = 1;\n                desc.MetaDataSize = sizeof(int);\n                desc.Flags = SURFACE_QUEUE_FLAG_SINGLE_THREADED;\n\n                SURFACE_QUEUE_CLONE_DESC CloneDesc = { 0 };\n                CloneDesc.MetaDataSize = 0;\n                CloneDesc.Flags = SURFACE_QUEUE_FLAG_SINGLE_THREADED;\n\n                if (!m_isD3DInitialized || (desc.Width <= 0) || (desc.Height <= 0))\n                {\n                    hr = S_FALSE;\n                    goto Cleanup;\n                }\n\n                if (!m_areSurfacesInitialized)\n                {\n                    // \n                    // Initialize the surface queues\n                    //\n\n                    {\n                        pin_ptr<ISurfaceQueue*> pinABQueue = &m_ABQueue;\n                        ISurfaceQueue** ppABQueue = pinABQueue;\n\n                        IFC(CreateSurfaceQueue(&desc, m_pD3D9Device, ppABQueue));\n                    }\n\n                    // Clone the queue           \n                    {\n                        pin_ptr<ISurfaceQueue*> pinBAQueue = &m_BAQueue;\n                        ISurfaceQueue** ppBAQueue = pinBAQueue;\n\n                        IFC(m_ABQueue->Clone(&CloneDesc, ppBAQueue));\n                    }\n\n                    // Setup queue management\n                    {\n                        pin_ptr<ISurfaceProducer*> pinm_BAProducer = &m_BAProducer;\n                        ISurfaceProducer** ppm_BAProducer = pinm_BAProducer;\n\n                        IFC(m_BAQueue->OpenProducer(m_D3D10Device, ppm_BAProducer));\n                    }\n\n                    {\n                        pin_ptr<ISurfaceConsumer*> pinm_ABConsumer = &m_ABConsumer;\n                        ISurfaceConsumer** ppm_ABConsumer = pinm_ABConsumer;\n\n                        IFC(m_ABQueue->OpenConsumer(m_D3D10Device, ppm_ABConsumer));\n                    }\n\n                    {\n                        pin_ptr<ISurfaceProducer*> pinm_ABProducer = &m_ABProducer;\n                        ISurfaceProducer** ppm_ABProducer = pinm_ABProducer;\n\n                        IFC(m_ABQueue->OpenProducer(m_pD3D9Device, ppm_ABProducer));\n                    }\n\n                    {\n                        pin_ptr<ISurfaceConsumer*> pinm_BAConsumer = &m_BAConsumer;\n                        ISurfaceConsumer** ppm_BAConsumer = pinm_BAConsumer;\n\n                        IFC(m_BAQueue->OpenConsumer(m_pD3D9Device, ppm_BAConsumer));\n                    }\n\n                    m_areSurfacesInitialized = true;\n                }\n\n            Cleanup:\n\n                return hr;\n            }\n\n            // Returns true if this instance is now initialized.\n            bool SurfaceQueueInteropHelper::Initialize()\n            {\n                HRESULT hr = S_OK;\n\n                if (m_isD3DInitialized)\n                {\n                    hr = m_pD3D9Device->CheckDeviceState(NULL);\n\n                    if (D3D_OK != hr)\n                    {\n                        CleanupD3D();\n                    }\n                }\n\n                if (!m_isD3DInitialized)\n                {\n                    IFC(InitD3D());\n                }\n\n                if (!m_areSurfacesInitialized)\n                {\n                    // Can be S_FALSE if there's nothing to do.\n                    IFC(InitSurfaces());\n                }\n\n            Cleanup:\n\n                // Clean up, but don't throw, as this can be a transient failure.\n                // TODO: Consider if/how to differentiate between fatal failure and transient failure.\n                if (FAILED(hr))\n                {\n                    CleanupD3D();\n                }\n\n                return m_areSurfacesInitialized;\n            }\n\n            // If fShouldRenderD3D10 is true, this method performs the callout to RenderD3D10.\n            // In any case, this method always initializes m_d3dImage which incurrs no cost if this results in no change.\n            void SurfaceQueueInteropHelper::QueueHelper(QueueRenderMode renderMode)\n            {\n                HRESULT hr = S_OK;\n\n                IDXGISurface*           pDXGISurface = NULL;\n                IUnknown*               pUnkDXGISurface = NULL;\n\n                IDirect3DTexture9*      pTexture9 = NULL;\n                IUnknown*               pUnkTexture9 = NULL;\n\n                IDirect3DSurface9*      pSurface9 = NULL;\n\n                DXGI_SURFACE_DESC desc;\n\n                // D3D10 portion\n                int count = 0;\n                UINT size = sizeof(int);\n\n                bool fNeedUnlock = false;\n                \n                bool isNewSurface = !m_areSurfacesInitialized;\n\n                if (m_shouldSkipRender || (nullptr == m_d3dImage) || !Initialize())\n                {\n                    goto Cleanup;\n                }\n\n                m_d3dImage->Lock();\n                fNeedUnlock = true;\n\n                // Flush the AB queue\n                m_ABProducer->Flush(0 /* wait */, NULL);\n\n                // Dequeue from AB queue\n                IFC(m_ABConsumer->Dequeue(surfaceIDDXGI, &pUnkDXGISurface, &count, &size, INFINITE));\n\n                IFC(pUnkDXGISurface->QueryInterface(surfaceIDDXGI, (void**)&pDXGISurface));\n\n                IFC(pDXGISurface->GetDesc(&desc));\n\n                if (renderMode == QueueRenderMode::RenderDXGI)\n                {\n                    // Render D3D10 content\n                    try\n                    {\n                        RenderToDXGI((IntPtr)(void*)pDXGISurface, isNewSurface);\n                    }\n                    catch (Exception^)\n                    {\n                        IFC(E_FAIL);\n                    }\n                }\n\n                // Produce the surface\n                m_BAProducer->Enqueue(pDXGISurface, NULL, NULL, SURFACE_QUEUE_FLAG_DO_NOT_WAIT);\n\n                // Flush the BA queue\n                m_BAProducer->Flush(0 /* wait, *not* SURFACE_QUEUE_FLAG_DO_NOT_WAIT*/, NULL);\n\n                // Dequeue from BA queue\n                IFC(m_BAConsumer->Dequeue(surfaceID9, &pUnkTexture9, NULL, NULL, INFINITE));\n                IFC(pUnkTexture9->QueryInterface(surfaceID9, (void**)&pTexture9));\n\n                // Get the top level surface from the texture\n                IFC(pTexture9->GetSurfaceLevel(0, &pSurface9));\n\n                m_d3dImage->SetBackBuffer(System::Windows::Interop::D3DResourceType::IDirect3DSurface9,\n                    (IntPtr)(void*)pSurface9, \n                    true // enableSoftwareFallback\n                         // Supports fallback to software rendering for Remote Desktop, etc...\n                         // Was added in WPF 4.5\n                    );\n\n                // Produce Surface\n                m_ABProducer->Enqueue(pTexture9, &count, sizeof(int), SURFACE_QUEUE_FLAG_DO_NOT_WAIT);\n\n                // Flush the AB queue - use \"do not wait\" here, we'll block at the top of the *next* call if we need to\n                m_ABProducer->Flush(SURFACE_QUEUE_FLAG_DO_NOT_WAIT, NULL);\n\n            Cleanup:\n                if (fNeedUnlock)\n                {\n                    m_d3dImage->AddDirtyRect(Int32Rect(0, 0, m_d3dImage->PixelWidth, m_d3dImage->PixelHeight));\n                    m_d3dImage->Unlock();\n                }\n\n                ReleaseInterface(pSurface9);\n\n                ReleaseInterface(pTexture9);\n                ReleaseInterface(pUnkTexture9);\n\n                ReleaseInterface(pDXGISurface);\n                ReleaseInterface(pUnkDXGISurface);\n            }\n\n\n            void SurfaceQueueInteropHelper::SetPixelSize(unsigned int pixelWidth, unsigned int pixelHeight)\n            {\n                if ((m_pixelWidth != pixelWidth) ||\n                    (m_pixelHeight != pixelHeight))\n                {\n                    m_pixelWidth = pixelWidth;\n                    m_pixelHeight = pixelHeight;\n                    CleanupSurfaces();\n                    QueueHelper(QueueRenderMode::RenderDXGI);\n                }\n            }\n\n            void SurfaceQueueInteropHelper::RequestRenderD2D()\n            {\n                QueueHelper(QueueRenderMode::RenderDXGI);\n            }\n\n            SurfaceQueueInteropHelper::!SurfaceQueueInteropHelper()\n            {\n                CleanupD3D();\n            }\n\n            SurfaceQueueInteropHelper::~SurfaceQueueInteropHelper()\n            {\n                CleanupD3D();\n            }\n        }\n    }\n}"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/SurfaceQueueInteropHelper.h",
    "content": "// SurfaceQueueInteropHelper.h\n\n#include \"stdafx.h\"\n\n#pragma once\n\nusing namespace System;\nusing namespace System::Windows;\nusing namespace System::Windows::Interop;\n\nnamespace Microsoft {\n    namespace Windows {\n        namespace Media {\n\n            /// A helper class which enables several versions of DirectX to share the same rendering surface.\n            public ref class SurfaceQueueInteropHelper : IDisposable\n            {\n            private:\n                Action<IntPtr, bool>^ m_renderD2D;\n                D3DImage^ m_d3dImage;\n                DependencyPropertyChangedEventHandler^ m_frontBufferAvailableChanged;\n                UINT m_pixelWidth, m_pixelHeight;\n                HWND m_hwnd;\n\n                IDirect3D9Ex*           m_pD3D9;\n                IDirect3DDevice9Ex*     m_pD3D9Device;\n\n                ID3D10Device1*          m_D3D10Device;\n\n                ISurfaceQueue*\t\t\tm_ABQueue;\n                ISurfaceQueue*\t\t\tm_BAQueue;\n\n                ISurfaceConsumer*\t\tm_ABConsumer;\n                ISurfaceProducer*\t\tm_BAProducer;\n                ISurfaceConsumer*\t\tm_BAConsumer;\n                ISurfaceProducer*\t\tm_ABProducer;\n\n                bool m_isD3DInitialized;\n                bool m_areSurfacesInitialized;\n                bool m_shouldSkipRender;\n\n                // Could hypothetically add additional types\n                enum struct QueueRenderMode\n                {\n                    None = 0,\n                    RenderDXGI = 1\n                };\n\n                HRESULT InitD3D10();\n\n                void RenderToDXGI(IntPtr pdxgiSurface, bool isNewSurface);\n\n                void CleanupD3D10();\n\n                HRESULT InitD3D9();\n\n                void CleanupD3D9();\n\n                void CleanupSurfaces();\n\n                void CleanupD3D();\n\n                HRESULT InitD3D();\n\n                HRESULT InitSurfaces();\n\n                bool Initialize();\n\n                // If fShouldRenderD3D10 is true, this method performs the callout to RenderD3D10.\n                // In any case, this method always initializes m_d3dImage which incurrs no cost if this results in no change.\n                void QueueHelper(QueueRenderMode renderMode);\n\n            public:\n\n                /// The action delegate called when a render is required.\n                property Action<IntPtr, bool>^ SurfaceQueueInteropHelper::RenderD2D\n                {\n                    void set(Action<IntPtr, bool>^ value) { m_renderD2D = value; }\n                }\n\n                /// Gets or sets the associated D3DImage object that is working in conjunction with this helper.\n                property D3DImage^ SurfaceQueueInteropHelper::D3DImage\n                {\n                    System::Windows::Interop::D3DImage^ get()\n                    {\n                        return m_d3dImage;\n                    }\n\n                    void set(System::Windows::Interop::D3DImage^ d3dImage)\n                    {\n                        if (d3dImage != m_d3dImage)\n                        {\n                            if (nullptr != m_d3dImage)\n                            {\n                                m_d3dImage->SetBackBuffer(System::Windows::Interop::D3DResourceType::IDirect3DSurface9, (IntPtr)nullptr);\n                            }\n\n                            m_d3dImage = d3dImage;\n\n                            // TODO: Force a rerender...?\n                        }\n                    }\n                }\n\n                /// Gets the desired pixel width for the surface.\n                property unsigned int SurfaceQueueInteropHelper::PixelWidth\n                {\n                    unsigned int get()\n                    {\n                        return m_pixelWidth;\n                    }\n                }\n\n                /// Gets the desired pixel height for the surface.\n                property unsigned int SurfaceQueueInteropHelper::PixelHeight\n                {\n                    unsigned int get()\n                    {\n                        return m_pixelHeight;\n                    }\n                }\n\n                /// Enables user of this component to set the desired pixel size for the surface.\n                void SetPixelSize(unsigned int pixelWidth, unsigned int pixelHeight);\n\n                /// Gets or sets the HWND used by the helper while creating DirectX devices.\n                property IntPtr SurfaceQueueInteropHelper::HWND\n                {\n                    IntPtr get() { return (IntPtr)(void*)m_hwnd; }\n                    void set(IntPtr hwnd) { m_hwnd = (::HWND)(void*)hwnd; }\n                }\n\n                /// Requests render to happen.\n                void RequestRenderD2D();\n\n                !SurfaceQueueInteropHelper();\n\n                ~SurfaceQueueInteropHelper();\n            };\n\n        }\n    }\n}\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX/version.rc",
    "content": "/////////////////////////////////////////////////////////////////////////////\n//\n// Version\n//\n\n\n#include <fxver.h>\n#include <fxver.rc>\n\n\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX_dxsdk.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 14\nVisualStudioVersion = 14.0.23107.0\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Microsoft.Wpf.Interop.DirectX_dxsdk\", \"Microsoft.Wpf.Interop.DirectX\\Microsoft.Wpf.Interop.DirectX.csproj\", \"{51880B2F-A2DD-4669-B7F2-D5315B03C06D}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x64.Build.0 = Debug|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x86.Build.0 = Debug|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x64.ActiveCfg = Release|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x64.Build.0 = Release|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x86.ActiveCfg = Release|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x86.Build.0 = Release|Win32\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Debug|x64.Build.0 = Debug|x64\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Debug|x86.Build.0 = Debug|Win32\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Release|x64.ActiveCfg = Release|x64\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Release|x64.Build.0 = Release|x64\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Release|x86.ActiveCfg = Release|Win32\n\t\t{51880B2F-A2DD-4669-B7F2-D5315B03C06D}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "src/Microsoft.Wpf.Interop.DirectX_winsdk.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 14\nVisualStudioVersion = 14.0.23107.0\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"Microsoft.Wpf.Interop.DirectX_winsdk\", \"Microsoft.Wpf.Interop.DirectX\\Microsoft.Wpf.Interop.DirectX_winsdk.vcxproj\", \"{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x64.Build.0 = Debug|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Debug|x86.Build.0 = Debug|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x64.ActiveCfg = Release|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x64.Build.0 = Release|x64\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x86.ActiveCfg = Release|Win32\n\t\t{157A478D-FE02-4EB2-BD7C-8CF3BF1CB9A2}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  }
]