22#include <kiwano/render/DirectX/helper.h>
23#include <kiwano/render/DirectX/FontCollectionLoader.h>
32MIDL_INTERFACE(
"5706684a-bf6d-4b03-b627-094758a33032")
33KGE_API ID2DDeviceResources : public IUnknown
36 virtual HRESULT Initialize(_In_ ComPtr<IDXGIDevice> dxgi_device, _In_ ComPtr<IDXGISwapChain> dxgi_swap_chain) = 0;
38 virtual HRESULT CreateBitmapSourceFromMemory(_Out_ ComPtr<IWICBitmapSource> & source, _In_ UINT width,
39 _In_ UINT height, _In_ UINT cbStride, _In_ UINT cbBufferSize,
40 _In_ BYTE * buffer, _In_ REFWICPixelFormatGUID cPixelFormat) = 0;
42 virtual HRESULT CreateBitmapConverter(_Out_ ComPtr<IWICFormatConverter> & converter,
43 _In_opt_ ComPtr<IWICBitmapSource> source, _In_ REFWICPixelFormatGUID format,
44 WICBitmapDitherType dither, _In_opt_ ComPtr<IWICPalette> palette,
45 double alpha_threshold_percent, WICBitmapPaletteType palette_translate) = 0;
47 virtual HRESULT CreateBitmapFromConverter(_Out_ ComPtr<ID2D1Bitmap> & bitmap,
48 _In_opt_
const D2D1_BITMAP_PROPERTIES* properties,
49 _In_ ComPtr<IWICFormatConverter> converter) = 0;
51 virtual HRESULT CreateBitmapDecoderFromFile(_Out_ ComPtr<IWICBitmapDecoder> & decoder, _In_ LPCWSTR file_path) = 0;
53 virtual HRESULT CreateBitmapDecoderFromResource(_Out_ ComPtr<IWICBitmapDecoder> & decoder, _In_
void* data,
56 virtual HRESULT CreateTextFormat(_Out_ ComPtr<IDWriteTextFormat> & text_format, _In_ LPCWSTR family,
57 _In_ ComPtr<IDWriteFontCollection> collection, DWRITE_FONT_WEIGHT weight,
58 DWRITE_FONT_STYLE style, DWRITE_FONT_STRETCH stretch, FLOAT font_size) = 0;
60 virtual HRESULT CreateTextLayout(_Out_ ComPtr<IDWriteTextLayout> & text_layout, _In_ LPCWSTR text, UINT32 length,
61 _In_ ComPtr<IDWriteTextFormat> text_format) = 0;
63 virtual HRESULT CreateFontCollectionFromFiles(_Out_ ComPtr<IDWriteFontCollection> & font_collection,
64 const Vector<String>& file_paths) = 0;
66 virtual HRESULT CreateFontCollectionFromBinaryData(_Out_ ComPtr<IDWriteFontCollection> & font_collection,
67 const Vector<BinaryData>& data) = 0;
69 virtual HRESULT GetFontFamilyNames(_Out_ Vector<String> & family_names,
70 _In_ ComPtr<IDWriteFontCollection> font_collection) = 0;
72 virtual HRESULT SetDpi(
float dpi) = 0;
74 virtual HRESULT SetLogicalSize(
float width,
float height) = 0;
76 virtual HRESULT HandleDeviceLost(_In_ ComPtr<IDXGIDevice> dxgi_device,
77 _In_ ComPtr<IDXGISwapChain> dxgi_swap_chain) = 0;
79 virtual void DiscardResources() = 0;
81 virtual void ResetTextRenderingParams(_In_ HMONITOR monitor) = 0;
83 inline ID2D1Factory1* GetFactory()
86 return factory_.Get();
89 inline IWICImagingFactory* GetWICImagingFactory()
91 KGE_ASSERT(imaging_factory_);
92 return imaging_factory_.Get();
95 inline IDWriteFactory* GetDWriteFactory()
97 KGE_ASSERT(dwrite_factory_);
98 return dwrite_factory_.Get();
101 inline ID2D1Device* GetDevice()
104 return device_.Get();
107 inline ID2D1DeviceContext* GetDeviceContext()
109 KGE_ASSERT(device_context_);
110 return device_context_.Get();
114 ComPtr<ID2D1Factory1> factory_;
115 ComPtr<ID2D1Device> device_;
116 ComPtr<ID2D1DeviceContext> device_context_;
118 ComPtr<IWICImagingFactory> imaging_factory_;
119 ComPtr<IDWriteFactory> dwrite_factory_;
122extern ComPtr<ID2DDeviceResources> GetD2DDeviceResources();