80 lines
2.7 KiB
C++
80 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
|
|
#include "D3D12WindowRenderer.h"
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
|
|
#include <d2d1_1.h>
|
|
#include <d3d11_4.h>
|
|
#include <d3d11on12.h>
|
|
#include <wrl/client.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace XCEngine::UI::Editor::Host {
|
|
|
|
class D3D12WindowInteropContext {
|
|
public:
|
|
bool Attach(D3D12WindowRenderer& windowRenderer, ID2D1Factory1& d2dFactory);
|
|
void Detach();
|
|
void ReleaseBackBufferTargets();
|
|
bool RebuildBackBufferTargets();
|
|
bool HasAttachedWindowRenderer() const;
|
|
bool HasBackBufferTargets() const;
|
|
bool PrepareSourceTextures(const ::XCEngine::UI::UIDrawData& drawData);
|
|
void ClearSourceTextures();
|
|
bool ResolveInteropBitmap(
|
|
const ::XCEngine::UI::UITextureHandle& texture,
|
|
Microsoft::WRL::ComPtr<ID2D1Bitmap>& outBitmap) const;
|
|
|
|
D3D12WindowRenderer* GetWindowRenderer() const;
|
|
ID3D11On12Device* GetD3D11On12Device() const;
|
|
ID3D11DeviceContext* GetD3D11DeviceContext() const;
|
|
ID2D1DeviceContext* GetD2DDeviceContext() const;
|
|
ID2D1SolidColorBrush* GetInteropBrush() const;
|
|
void BuildAcquiredResources(
|
|
std::uint32_t backBufferIndex,
|
|
std::vector<ID3D11Resource*>& outResources) const;
|
|
ID3D11Resource* GetWrappedBackBufferResource(std::uint32_t index) const;
|
|
ID2D1Bitmap1* GetBackBufferTargetBitmap(std::uint32_t index) const;
|
|
std::uint32_t GetCurrentBackBufferIndex() const;
|
|
const std::string& GetLastError() const;
|
|
|
|
private:
|
|
struct BackBufferTarget {
|
|
Microsoft::WRL::ComPtr<ID3D11Resource> wrappedResource = {};
|
|
Microsoft::WRL::ComPtr<ID2D1Bitmap1> targetBitmap = {};
|
|
};
|
|
|
|
struct SourceTextureResource {
|
|
std::uintptr_t key = 0u;
|
|
Microsoft::WRL::ComPtr<ID3D11Resource> wrappedResource = {};
|
|
Microsoft::WRL::ComPtr<ID2D1Bitmap1> bitmap = {};
|
|
};
|
|
|
|
bool EnsureInterop();
|
|
void ReleaseInteropState();
|
|
|
|
D3D12WindowRenderer* m_windowRenderer = nullptr;
|
|
ID2D1Factory1* m_d2dFactory = nullptr;
|
|
Microsoft::WRL::ComPtr<ID3D11Device> m_d3d11Device = {};
|
|
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_d3d11DeviceContext = {};
|
|
Microsoft::WRL::ComPtr<ID3D11On12Device> m_d3d11On12Device = {};
|
|
Microsoft::WRL::ComPtr<ID2D1Device> m_d2dDevice = {};
|
|
Microsoft::WRL::ComPtr<ID2D1DeviceContext> m_d2dDeviceContext = {};
|
|
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_interopBrush = {};
|
|
std::vector<BackBufferTarget> m_backBufferTargets = {};
|
|
std::vector<SourceTextureResource> m_activeSourceTextures = {};
|
|
std::unordered_map<std::uintptr_t, Microsoft::WRL::ComPtr<ID2D1Bitmap1>> m_activeBitmaps = {};
|
|
std::string m_lastError = {};
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|