| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | // 
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | #include "helper.hpp"
 | 
					
						
							|  |  |  | #include "../base/Resource.h"
 | 
					
						
							|  |  |  | #include "../2d/Font.hpp"
 | 
					
						
							|  |  |  | #include "../2d/TextStyle.hpp"
 | 
					
						
							|  |  |  | #include <dwrite.h>
 | 
					
						
							|  |  |  | #include <d2d1.h>
 | 
					
						
							|  |  |  | #include <d2d1_1.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | namespace kiwano | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 	MIDL_INTERFACE("5706684a-bf6d-4b03-b627-094758a33032") | 
					
						
							|  |  |  | 	KGE_API ID2DDeviceResources | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 		: public IUnknown | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		static HRESULT Create(ID2DDeviceResources** device_resources); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		virtual HRESULT CreateBitmapFromFile( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_Out_ ComPtr<ID2D1Bitmap>& bitmap, | 
					
						
							|  |  |  | 			_In_ String const& file_path | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual HRESULT CreateBitmapFromResource( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_Out_ ComPtr<ID2D1Bitmap>& bitmap, | 
					
						
							|  |  |  | 			_In_ Resource const& res | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual HRESULT CreateTextFormat( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_Out_ ComPtr<IDWriteTextFormat>& text_format, | 
					
						
							|  |  |  | 			_In_ Font const& font, | 
					
						
							|  |  |  | 			_In_ TextStyle const& text_style | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) const = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual HRESULT CreateTextLayout( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_Out_ ComPtr<IDWriteTextLayout>& text_layout, | 
					
						
							|  |  |  | 			_Out_ Size& layout_size, | 
					
						
							|  |  |  | 			_In_ String const& text, | 
					
						
							|  |  |  | 			_In_ ComPtr<IDWriteTextFormat> const& text_format, | 
					
						
							|  |  |  | 			_In_ TextStyle const& text_style | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) const = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual ID2D1StrokeStyle* GetStrokeStyle(StrokeStyle stroke) const = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual HRESULT SetD2DDevice( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_In_ ComPtr<ID2D1Device> const& device | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual void SetTargetBitmap( | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			_In_ ComPtr<ID2D1Bitmap1> const& target | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		) = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual void ClearImageCache() = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		virtual void DiscardResources() = 0; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		inline ID2D1Factory1*			GetFactory() const				{ KGE_ASSERT(factory_); return factory_.Get(); } | 
					
						
							|  |  |  | 		inline IWICImagingFactory*		GetWICImagingFactory() const	{ KGE_ASSERT(imaging_factory_); return imaging_factory_.Get(); } | 
					
						
							|  |  |  | 		inline IDWriteFactory*			GetDWriteFactory() const		{ KGE_ASSERT(dwrite_factory_); return dwrite_factory_.Get(); } | 
					
						
							|  |  |  | 		inline ID2D1Device*				GetDevice() const				{ KGE_ASSERT(device_); return device_.Get(); } | 
					
						
							|  |  |  | 		inline ID2D1DeviceContext*		GetDeviceContext() const		{ KGE_ASSERT(device_context_); return device_context_.Get(); } | 
					
						
							|  |  |  | 		inline ID2D1Bitmap1*			GetTargetBitmap() const			{ KGE_ASSERT(target_bitmap_); return target_bitmap_.Get(); } | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	protected: | 
					
						
							| 
									
										
										
										
											2019-07-30 00:41:06 +08:00
										 |  |  | 		ComPtr<ID2D1Factory1>		factory_; | 
					
						
							|  |  |  | 		ComPtr<ID2D1Device>			device_; | 
					
						
							|  |  |  | 		ComPtr<ID2D1DeviceContext>	device_context_; | 
					
						
							|  |  |  | 		ComPtr<ID2D1Bitmap1>		target_bitmap_; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		ComPtr<IWICImagingFactory>	imaging_factory_; | 
					
						
							|  |  |  | 		ComPtr<IDWriteFactory>		dwrite_factory_; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |