From cf07d193b97168048a72793c59f096504acf78a5 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 28 Oct 2020 20:36:47 +0800 Subject: ... --- include/cru/win/graph/direct/WindowPainter.hpp | 21 ++++++++++ .../cru/win/graph/direct/WindowRenderTarget.hpp | 42 +++++++++++++++++++ include/cru/win/native/Base.hpp | 1 - include/cru/win/native/Window.hpp | 6 ++- include/cru/win/native/WindowRenderTarget.hpp | 48 ---------------------- 5 files changed, 67 insertions(+), 51 deletions(-) create mode 100644 include/cru/win/graph/direct/WindowPainter.hpp create mode 100644 include/cru/win/graph/direct/WindowRenderTarget.hpp delete mode 100644 include/cru/win/native/WindowRenderTarget.hpp (limited to 'include') diff --git a/include/cru/win/graph/direct/WindowPainter.hpp b/include/cru/win/graph/direct/WindowPainter.hpp new file mode 100644 index 00000000..53961586 --- /dev/null +++ b/include/cru/win/graph/direct/WindowPainter.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "Painter.hpp" +#include "WindowRenderTarget.hpp" + +namespace cru::platform::graph::win::direct { +class D2DWindowPainter : public graph::win::direct::D2DPainter { + public: + explicit D2DWindowPainter(D2DWindowRenderTarget* window); + + CRU_DELETE_COPY(D2DWindowPainter) + CRU_DELETE_MOVE(D2DWindowPainter) + + ~D2DWindowPainter() override; + + protected: + void DoEndDraw() override; + + private: + D2DWindowRenderTarget* render_target_; +}; +} // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/graph/direct/WindowRenderTarget.hpp b/include/cru/win/graph/direct/WindowRenderTarget.hpp new file mode 100644 index 00000000..c9ee098f --- /dev/null +++ b/include/cru/win/graph/direct/WindowRenderTarget.hpp @@ -0,0 +1,42 @@ +#pragma once +#include "Factory.hpp" + +namespace cru::platform::graph::win::direct { +// Represents a window render target. +class D2DWindowRenderTarget : public Object { + public: + D2DWindowRenderTarget(gsl::not_null factory, HWND hwnd); + + CRU_DELETE_COPY(D2DWindowRenderTarget) + CRU_DELETE_MOVE(D2DWindowRenderTarget) + + ~D2DWindowRenderTarget() override = default; + + public: + graph::win::direct::DirectGraphFactory* GetDirectFactory() const { + return factory_; + } + + ID2D1DeviceContext* GetD2D1DeviceContext() { + return d2d1_device_context_.Get(); + } + + void SetDpi(float x, float y); + + // Resize the underlying buffer. + void ResizeBuffer(int width, int height); + + // Present the data of the underlying buffer to the window. + void Present(); + + private: + void CreateTargetBitmap(); + + private: + DirectGraphFactory* factory_; + HWND hwnd_; + Microsoft::WRL::ComPtr d2d1_device_context_; + Microsoft::WRL::ComPtr dxgi_swap_chain_; + Microsoft::WRL::ComPtr target_bitmap_; +}; +} // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/native/Base.hpp b/include/cru/win/native/Base.hpp index a50c6dd1..7ddc6b54 100644 --- a/include/cru/win/native/Base.hpp +++ b/include/cru/win/native/Base.hpp @@ -10,7 +10,6 @@ class WinCursor; class WinCursorManager; class WindowClass; class WindowManager; -class WindowRenderTarget; class WinNativeWindow; class WinNativeWindowResolver; class WinUiApplication; diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp index 37df0768..ecc0dd04 100644 --- a/include/cru/win/native/Window.hpp +++ b/include/cru/win/native/Window.hpp @@ -4,6 +4,7 @@ #include "WindowNativeMessageEventArgs.hpp" #include "cru/platform/GraphBase.hpp" #include "cru/platform/native/Window.hpp" +#include "cru/win/graph/direct/WindowRenderTarget.hpp" #include @@ -86,7 +87,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { bool HandleNativeWindowMessage(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, LRESULT* result); - WindowRenderTarget* GetWindowRenderTarget() const { + graph::win::direct::D2DWindowRenderTarget* GetWindowRenderTarget() const { return window_render_target_.get(); } @@ -157,7 +158,8 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { bool has_focus_ = false; bool is_mouse_in_ = false; - std::unique_ptr window_render_target_; + std::unique_ptr + window_render_target_; std::shared_ptr cursor_; diff --git a/include/cru/win/native/WindowRenderTarget.hpp b/include/cru/win/native/WindowRenderTarget.hpp deleted file mode 100644 index 786a90a6..00000000 --- a/include/cru/win/native/WindowRenderTarget.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include "Base.hpp" - -namespace cru::platform::graph::win::direct { -class DirectGraphFactory; -} - -namespace cru::platform::native::win { -// Represents a window render target. -class WindowRenderTarget : public Object { - public: - WindowRenderTarget(graph::win::direct::DirectGraphFactory* factory, - WinNativeWindow* window); - - CRU_DELETE_COPY(WindowRenderTarget) - CRU_DELETE_MOVE(WindowRenderTarget) - - ~WindowRenderTarget() override = default; - - public: - graph::win::direct::DirectGraphFactory* GetDirectFactory() const { - return factory_; - } - - ID2D1DeviceContext* GetD2D1DeviceContext() { - return d2d1_device_context_.Get(); - } - - // Resize the underlying buffer. - void ResizeBuffer(int width, int height); - - // Set this render target as the d2d device context's target. - void SetAsTarget(); - - // Present the data of the underlying buffer to the window. - void Present(); - - private: - void CreateTargetBitmap(); - - private: - WinNativeWindow* window_; - graph::win::direct::DirectGraphFactory* factory_; - Microsoft::WRL::ComPtr d2d1_device_context_; - Microsoft::WRL::ComPtr dxgi_swap_chain_; - Microsoft::WRL::ComPtr target_bitmap_; -}; -} // namespace cru::platform::native::win -- cgit v1.2.3