diff options
author | crupest <crupest@outlook.com> | 2019-12-16 00:09:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-12-16 00:09:52 +0800 |
commit | 6ad6638adf64d958cdae44ce1df6a8a3787fed84 (patch) | |
tree | 030af9ca6e19bebc6250a8d278e46af7065fcd2f /include | |
parent | 221c62de313ad811ca2b3ae8ba43996c96c347bc (diff) | |
download | cru-6ad6638adf64d958cdae44ce1df6a8a3787fed84.tar.gz cru-6ad6638adf64d958cdae44ce1df6a8a3787fed84.tar.bz2 cru-6ad6638adf64d958cdae44ce1df6a8a3787fed84.zip |
...
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/platform/exception.hpp | 2 | ||||
-rw-r--r-- | include/cru/win/exception.hpp | 29 | ||||
-rw-r--r-- | include/cru/win/graph/direct/factory.hpp | 21 | ||||
-rw-r--r-- | include/cru/win/native/exception.hpp | 1 | ||||
-rw-r--r-- | include/cru/win/native/window_render_target.hpp | 4 |
5 files changed, 35 insertions, 22 deletions
diff --git a/include/cru/platform/exception.hpp b/include/cru/platform/exception.hpp index 1774b12c..afe11c03 100644 --- a/include/cru/platform/exception.hpp +++ b/include/cru/platform/exception.hpp @@ -1,5 +1,5 @@ #pragma once -#include "cru/common/pre_config.hpp" +#include "cru/common/base.hpp" #include <stdexcept> diff --git a/include/cru/win/exception.hpp b/include/cru/win/exception.hpp index 9e038960..95eb4079 100644 --- a/include/cru/win/exception.hpp +++ b/include/cru/win/exception.hpp @@ -10,12 +10,11 @@ namespace cru::platform::win { class HResultError : public platform::PlatformException { public: explicit HResultError(HRESULT h_result); - explicit HResultError(HRESULT h_result, - const std::string_view& additional_message); - HResultError(const HResultError& other) = default; - HResultError(HResultError&& other) = default; - HResultError& operator=(const HResultError& other) = default; - HResultError& operator=(HResultError&& other) = default; + explicit HResultError(HRESULT h_result, const std::string_view& message); + + CRU_DEFAULT_COPY(HResultError) + CRU_DEFAULT_MOVE(HResultError) + ~HResultError() override = default; HRESULT GetHResult() const { return h_result_; } @@ -35,17 +34,19 @@ inline void ThrowIfFailed(const HRESULT h_result, class Win32Error : public platform::PlatformException { public: - explicit Win32Error(DWORD error_code); - Win32Error(DWORD error_code, const std::string_view& additional_message); - Win32Error(const Win32Error& other) = default; - Win32Error(Win32Error&& other) = default; - Win32Error& operator=(const Win32Error& other) = default; - Win32Error& operator=(Win32Error&& other) = default; + // ::GetLastError is automatically called to get the error code. + // The same as Win32Error(::GetLastError(), message) + explicit Win32Error(const std::string_view& message); + Win32Error(DWORD error_code, const std::string_view& message); + + CRU_DEFAULT_COPY(Win32Error) + CRU_DEFAULT_MOVE(Win32Error) + ~Win32Error() override = default; - HRESULT GetErrorCode() const { return error_code_; } + DWORD GetErrorCode() const { return error_code_; } private: DWORD error_code_; }; -} // namespace cru::win +} // namespace cru::platform::win diff --git a/include/cru/win/graph/direct/factory.hpp b/include/cru/win/graph/direct/factory.hpp index 4c106f54..cf5ccaee 100644 --- a/include/cru/win/graph/direct/factory.hpp +++ b/include/cru/win/graph/direct/factory.hpp @@ -11,14 +11,12 @@ class DirectGraphFactory : public DirectResource, public virtual IGraphFactory { CRU_DELETE_COPY(DirectGraphFactory) CRU_DELETE_MOVE(DirectGraphFactory) - ~DirectGraphFactory() override = default; + ~DirectGraphFactory() override; public: - ID2D1Factory1* GetD2D1Factory() const { return d2d1_factory_.Get(); } - ID2D1DeviceContext* GetD2D1DeviceContext() const { - return d2d1_device_context_.Get(); - } ID3D11Device* GetD3D11Device() const { return d3d11_device_.Get(); } + ID2D1Factory1* GetD2D1Factory() const { return d2d1_factory_.Get(); } + ID2D1Device* GetD2D1Device() const { return d2d1_device_.Get(); } IDXGIFactory2* GetDxgiFactory() const { return dxgi_factory_.Get(); } IDWriteFactory* GetDWriteFactory() const { return dwrite_factory_.Get(); } IDWriteFontCollection* GetSystemFontCollection() const { @@ -26,6 +24,16 @@ class DirectGraphFactory : public DirectResource, public virtual IGraphFactory { } public: + Microsoft::WRL::ComPtr<ID2D1DeviceContext> CreateD2D1DeviceContext(); + + // This context should only be used to create graphic resources like brush. + // Because graphic resources can be shared if they are created in the same + // device. + ID2D1DeviceContext* GetDefaultD2D1DeviceContext() { + return d2d1_device_context_.Get(); + } + + public: std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush() override; std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() override; @@ -38,7 +46,10 @@ class DirectGraphFactory : public DirectResource, public virtual IGraphFactory { private: Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_; + // ID2D1Factory1 is a interface only available in Windows 8 and Windows 7 with + // update. It is d2d v1.1. Microsoft::WRL::ComPtr<ID2D1Factory1> d2d1_factory_; + Microsoft::WRL::ComPtr<ID2D1Device> d2d1_device_; Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_; Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory_; Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_factory_; diff --git a/include/cru/win/native/exception.hpp b/include/cru/win/native/exception.hpp index 637f021d..ac15ab2d 100644 --- a/include/cru/win/native/exception.hpp +++ b/include/cru/win/native/exception.hpp @@ -3,4 +3,5 @@ namespace cru::platform::native::win { using platform::win::Win32Error; +using platform::win::HResultError; } // namespace cru::platform::native::win diff --git a/include/cru/win/native/window_render_target.hpp b/include/cru/win/native/window_render_target.hpp index 248bfc25..ab1d68ef 100644 --- a/include/cru/win/native/window_render_target.hpp +++ b/include/cru/win/native/window_render_target.hpp @@ -24,8 +24,7 @@ class WindowRenderTarget : public Object { return factory_; } - // Get the target bitmap which can be set as the ID2D1DeviceContext's target. - ID2D1Bitmap1* GetTargetBitmap() const { return target_bitmap_.Get(); } + ID2D1DeviceContext* GetD2D1DeviceContext() { return d2d1_device_context_.Get(); } // Resize the underlying buffer. void ResizeBuffer(int width, int height); @@ -41,6 +40,7 @@ class WindowRenderTarget : public Object { private: graph::win::direct::DirectGraphFactory* factory_; + Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_; Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_; Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_; }; |