| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Avalonia.Win32.Interop;
- using SharpDX;
- using SharpDX.DXGI;
- namespace Avalonia.Direct2D1
- {
- class HwndRenderTarget : SwapChainRenderTarget
- {
- private readonly IntPtr _hwnd;
- public HwndRenderTarget(IntPtr hwnd)
- {
- _hwnd = hwnd;
- }
- protected override SwapChain1 CreateSwapChain(Factory2 dxgiFactory, SwapChainDescription1 swapChainDesc)
- {
- return new SwapChain1(dxgiFactory, Device, _hwnd, ref swapChainDesc);
- }
- protected override Size2F GetWindowDpi()
- {
- if (UnmanagedMethods.ShCoreAvailable)
- {
- uint dpix, dpiy;
- var monitor = UnmanagedMethods.MonitorFromWindow(
- _hwnd,
- UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST);
- if (UnmanagedMethods.GetDpiForMonitor(
- monitor,
- UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI,
- out dpix,
- out dpiy) == 0)
- {
- return new Size2F(dpix, dpiy);
- }
- }
- return new Size2F(96, 96);
- }
- protected override Size2 GetWindowSize()
- {
- UnmanagedMethods.RECT rc;
- UnmanagedMethods.GetClientRect(_hwnd, out rc);
- return new Size2(rc.right - rc.left, rc.bottom - rc.top);
- }
- }
- }
|