CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UWP/Common/DeviceResources.h
Views: 1401
#pragma once12#include <vector>3#include <string>45namespace DX6{7// Provides an interface for an application that owns DeviceResources to be notified of the device being lost or created.8interface IDeviceNotify9{10virtual void OnDeviceLost() = 0;11virtual void OnDeviceRestored() = 0;12};1314// Controls all the DirectX device resources.15class DeviceResources16{17public:18DeviceResources();19void CreateWindowSizeDependentResources();20void SetWindow(Windows::UI::Core::CoreWindow^ window);21void SetLogicalSize(Windows::Foundation::Size logicalSize);22void SetCurrentOrientation(Windows::Graphics::Display::DisplayOrientations currentOrientation);23void SetDpi(float dpi);24void ValidateDevice();25void HandleDeviceLost();26void RegisterDeviceNotify(IDeviceNotify* deviceNotify);27void Trim();28void Present();2930// The size of the render target, in pixels.31Windows::Foundation::Size GetOutputSize() const { return m_outputSize; }3233// The size of the render target, in dips.34Windows::Foundation::Size GetLogicalSize() const { return m_logicalSize; }35float GetDpi() const { return m_effectiveDpi; }36float GetActualDpi() const { return m_dpi; }3738// D3D Accessors.39ID3D11Device3* GetD3DDevice() const { return m_d3dDevice.Get(); }40ID3D11DeviceContext3* GetD3DDeviceContext() const { return m_d3dContext.Get(); }41IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); }42D3D_FEATURE_LEVEL GetDeviceFeatureLevel() const { return m_d3dFeatureLevel; }43ID3D11RenderTargetView1* GetBackBufferRenderTargetView() const { return m_d3dRenderTargetView.Get(); }44D3D11_VIEWPORT GetScreenViewport() const { return m_screenViewport; }45DirectX::XMFLOAT4X4 GetOrientationTransform3D() const { return m_orientationTransform3D; }4647// D2D Accessors.48ID2D1Factory3* GetD2DFactory() const { return m_d2dFactory.Get(); }49ID2D1Device2* GetD2DDevice() const { return m_d2dDevice.Get(); }50ID2D1DeviceContext2* GetD2DDeviceContext() const { return m_d2dContext.Get(); }51ID2D1Bitmap1* GetD2DTargetBitmap() const { return m_d2dTargetBitmap.Get(); }52IDWriteFactory3* GetDWriteFactory() const { return m_dwriteFactory.Get(); }53IWICImagingFactory2* GetWicImagingFactory() const { return m_wicFactory.Get(); }54D2D1::Matrix3x2F GetOrientationTransform2D() const { return m_orientationTransform2D; }5556DXGI_MODE_ROTATION ComputeDisplayRotation();5758std::vector <std::string> GetAdapters() const { return m_vAdapters; };5960private:61void CreateDeviceIndependentResources();62void CreateDeviceResources(IDXGIAdapter* vAdapter = nullptr);63void UpdateRenderTargetSize();64bool CreateAdaptersList(Microsoft::WRL::ComPtr<ID3D11Device> device);6566// Direct3D objects.67Microsoft::WRL::ComPtr<ID3D11Device3> m_d3dDevice;68Microsoft::WRL::ComPtr<ID3D11DeviceContext3> m_d3dContext;69Microsoft::WRL::ComPtr<IDXGISwapChain3> m_swapChain;70Microsoft::WRL::ComPtr<IDXGIDevice3> m_dxgiDevice;71Microsoft::WRL::ComPtr<IDXGIFactory4> m_dxgiFactory;72Microsoft::WRL::ComPtr<IDXGIAdapter> m_dxgiAdapter;7374// Direct3D adapters75std::vector <std::string> m_vAdapters;7677// Direct3D rendering objects. Required for 3D.78Microsoft::WRL::ComPtr<ID3D11RenderTargetView1> m_d3dRenderTargetView;79D3D11_VIEWPORT m_screenViewport;8081// Direct2D drawing components.82Microsoft::WRL::ComPtr<ID2D1Factory3> m_d2dFactory;83Microsoft::WRL::ComPtr<ID2D1Device2> m_d2dDevice;84Microsoft::WRL::ComPtr<ID2D1DeviceContext2> m_d2dContext;85Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_d2dTargetBitmap;8687// DirectWrite drawing components.88Microsoft::WRL::ComPtr<IDWriteFactory3> m_dwriteFactory;89Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory;9091// Cached device properties.92D3D_FEATURE_LEVEL m_d3dFeatureLevel;93Windows::Foundation::Size m_d3dRenderTargetSize;94Windows::Foundation::Size m_outputSize;95Windows::Foundation::Size m_logicalSize;96Windows::Graphics::Display::DisplayOrientations m_nativeOrientation;97Windows::Graphics::Display::DisplayOrientations m_currentOrientation;98float m_dpi;99100// This is the DPI that will be reported back to the app. It takes into account whether the app supports high resolution screens or not.101float m_effectiveDpi;102103// Transforms used for display orientation.104D2D1::Matrix3x2F m_orientationTransform2D;105DirectX::XMFLOAT4X4 m_orientationTransform3D;106107// The IDeviceNotify can be held directly as it owns the DeviceResources.108IDeviceNotify* m_deviceNotify;109};110}111112113