Kiwano Engine v1.3.x
D2DDeviceResources.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/render/DirectX/helper.h>
23#include <kiwano/render/DirectX/FontCollectionLoader.h>
24
25namespace kiwano
26{
27namespace graphics
28{
29namespace directx
30{
31
32MIDL_INTERFACE("5706684a-bf6d-4b03-b627-094758a33032")
33KGE_API ID2DDeviceResources : public IUnknown
34{
35public:
36 virtual HRESULT Initialize(_In_ ComPtr<IDXGIDevice> dxgi_device, _In_ ComPtr<IDXGISwapChain> dxgi_swap_chain) = 0;
37
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;
41
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;
46
47 virtual HRESULT CreateBitmapFromConverter(_Out_ ComPtr<ID2D1Bitmap> & bitmap,
48 _In_opt_ const D2D1_BITMAP_PROPERTIES* properties,
49 _In_ ComPtr<IWICFormatConverter> converter) = 0;
50
51 virtual HRESULT CreateBitmapDecoderFromFile(_Out_ ComPtr<IWICBitmapDecoder> & decoder, _In_ LPCWSTR file_path) = 0;
52
53 virtual HRESULT CreateBitmapDecoderFromResource(_Out_ ComPtr<IWICBitmapDecoder> & decoder, _In_ void* data,
54 DWORD data_size) = 0;
55
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;
59
60 virtual HRESULT CreateTextLayout(_Out_ ComPtr<IDWriteTextLayout> & text_layout, _In_ LPCWSTR text, UINT32 length,
61 _In_ ComPtr<IDWriteTextFormat> text_format) = 0;
62
63 virtual HRESULT CreateFontCollectionFromFiles(_Out_ ComPtr<IDWriteFontCollection> & font_collection,
64 const Vector<String>& file_paths) = 0;
65
66 virtual HRESULT CreateFontCollectionFromBinaryData(_Out_ ComPtr<IDWriteFontCollection> & font_collection,
67 const Vector<BinaryData>& data) = 0;
68
69 virtual HRESULT GetFontFamilyNames(_Out_ Vector<String> & family_names,
70 _In_ ComPtr<IDWriteFontCollection> font_collection) = 0;
71
72 virtual HRESULT SetDpi(float dpi) = 0;
73
74 virtual HRESULT SetLogicalSize(float width, float height) = 0;
75
76 virtual HRESULT HandleDeviceLost(_In_ ComPtr<IDXGIDevice> dxgi_device,
77 _In_ ComPtr<IDXGISwapChain> dxgi_swap_chain) = 0;
78
79 virtual void DiscardResources() = 0;
80
81 virtual void ResetTextRenderingParams(_In_ HMONITOR monitor) = 0;
82
83 inline ID2D1Factory1* GetFactory()
84 {
85 KGE_ASSERT(factory_);
86 return factory_.Get();
87 }
88
89 inline IWICImagingFactory* GetWICImagingFactory()
90 {
91 KGE_ASSERT(imaging_factory_);
92 return imaging_factory_.Get();
93 }
94
95 inline IDWriteFactory* GetDWriteFactory()
96 {
97 KGE_ASSERT(dwrite_factory_);
98 return dwrite_factory_.Get();
99 }
100
101 inline ID2D1Device* GetDevice()
102 {
103 KGE_ASSERT(device_);
104 return device_.Get();
105 }
106
107 inline ID2D1DeviceContext* GetDeviceContext()
108 {
109 KGE_ASSERT(device_context_);
110 return device_context_.Get();
111 }
112
113protected:
114 ComPtr<ID2D1Factory1> factory_;
115 ComPtr<ID2D1Device> device_;
116 ComPtr<ID2D1DeviceContext> device_context_;
117
118 ComPtr<IWICImagingFactory> imaging_factory_;
119 ComPtr<IDWriteFactory> dwrite_factory_;
120};
121
122extern ComPtr<ID2DDeviceResources> GetD2DDeviceResources();
123
124} // namespace directx
125} // namespace graphics
126} // namespace kiwano