Committing TBB 2019 Update 8 source code
[platform/upstream/tbb.git] / examples / parallel_for / tachyon / msvs / uwp / DirectXBase.h
1 /*
2     Copyright (c) 2005-2019 Intel Corporation
3
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7
8         http://www.apache.org/licenses/LICENSE-2.0
9
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16
17 #pragma once
18
19 #include <wrl/client.h>
20 #include <d3d11_1.h>
21 #include <d2d1_1.h>
22 #include <d2d1effects.h>
23 #include <dwrite_1.h>
24 #include <wincodec.h>
25 #include "App.xaml.h"
26 #include <agile.h>
27
28 #pragma warning (disable: 4449)
29
30 // Helper utilities to make DirectX APIs work with exceptions
31 namespace DX
32 {
33     inline void ThrowIfFailed(HRESULT hr)
34     {
35         if (FAILED(hr))
36         {
37             // Set a breakpoint on this line to catch DirectX API errors
38             throw Platform::Exception::CreateException(hr);
39         }
40     }
41 }
42
43 // Helper class that initializes DirectX APIs
44 ref class DirectXBase abstract
45 {
46 internal:
47     DirectXBase();
48
49 public:
50     virtual void Initialize(Windows::UI::Core::CoreWindow^ window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel, float dpi);
51     virtual void CreateDeviceIndependentResources();
52     virtual void CreateDeviceResources();
53     virtual void SetDpi(float dpi);
54     virtual void CreateWindowSizeDependentResources();
55     virtual void UpdateForWindowSizeChange();
56     virtual void Render() = 0;
57     virtual void Present();
58     virtual float ConvertDipsToPixels(float dips);
59
60 protected private:
61
62     Platform::Agile<Windows::UI::Core::CoreWindow>         m_window;
63     Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_panel;
64
65     // Direct2D Objects
66     Microsoft::WRL::ComPtr<ID2D1Factory1>                  m_d2dFactory;
67     Microsoft::WRL::ComPtr<ID2D1Device>                    m_d2dDevice;
68     Microsoft::WRL::ComPtr<ID2D1DeviceContext>             m_d2dContext;
69     Microsoft::WRL::ComPtr<ID2D1Bitmap1>                   m_d2dTargetBitmap;
70
71     // DirectWrite & Windows Imaging Component Objects
72     Microsoft::WRL::ComPtr<IDWriteFactory1>                m_dwriteFactory;
73     Microsoft::WRL::ComPtr<IWICImagingFactory2>            m_wicFactory;
74
75     // Direct3D Objects
76     Microsoft::WRL::ComPtr<ID3D11Device1>                  m_d3dDevice;
77     Microsoft::WRL::ComPtr<ID3D11DeviceContext1>           m_d3dContext;
78     Microsoft::WRL::ComPtr<IDXGISwapChain1>                m_swapChain;
79     Microsoft::WRL::ComPtr<ID3D11RenderTargetView>         m_renderTargetView;
80     Microsoft::WRL::ComPtr<ID3D11DepthStencilView>         m_depthStencilView;
81
82     D3D_FEATURE_LEVEL                                      m_featureLevel;
83     Windows::Foundation::Size                              m_renderTargetSize;
84     Windows::Foundation::Rect                              m_windowBounds;
85     float                                                  m_dpi;
86 };
87
88 #pragma warning (default: 4449)