1
- using DirectN ;
2
- using Files . App . ViewModels . Properties ;
1
+ using Files . App . ViewModels . Properties ;
3
2
using Microsoft . UI . Content ;
4
3
using Microsoft . UI . Xaml ;
5
4
using Microsoft . UI . Xaml . Hosting ;
6
5
using System . Runtime . InteropServices ;
7
6
using System . Text ;
8
7
using Vanara . PInvoke ;
8
+ using Windows . Win32 ;
9
+ using Windows . Win32 . Graphics . Direct3D ;
10
+ using Windows . Win32 . Graphics . Direct3D11 ;
11
+ using Windows . Win32 . Graphics . Dxgi ;
12
+ using Windows . Win32 . Graphics . DirectComposition ;
9
13
using WinRT ;
10
14
using static Vanara . PInvoke . ShlwApi ;
11
15
using static Vanara . PInvoke . User32 ;
@@ -112,7 +116,7 @@ public void LoadPreview(UIElement presenter)
112
116
_ = ChildWindowToXaml ( parent , presenter ) ;
113
117
}
114
118
115
- private bool ChildWindowToXaml ( IntPtr parent , UIElement presenter )
119
+ private unsafe bool ChildWindowToXaml ( IntPtr parent , UIElement presenter )
116
120
{
117
121
D3D_DRIVER_TYPE [ ] driverTypes =
118
122
[
@@ -122,36 +126,36 @@ private bool ChildWindowToXaml(IntPtr parent, UIElement presenter)
122
126
123
127
ID3D11Device ? d3d11Device = null ;
124
128
ID3D11DeviceContext ? d3d11DeviceContext = null ;
125
- D3D_FEATURE_LEVEL featureLevelSupported ;
126
129
127
130
foreach ( var driveType in driverTypes )
128
131
{
129
- var hr = D3D11Functions . D3D11CreateDevice (
132
+ var hr = PInvoke . D3D11CreateDevice (
130
133
null ,
131
134
driveType ,
132
- IntPtr . Zero ,
133
- ( uint ) D3D11_CREATE_DEVICE_FLAG . D3D11_CREATE_DEVICE_BGRA_SUPPORT ,
135
+ new ( IntPtr . Zero ) ,
136
+ D3D11_CREATE_DEVICE_FLAG . D3D11_CREATE_DEVICE_BGRA_SUPPORT ,
134
137
null ,
135
138
0 ,
136
139
7 ,
137
140
out d3d11Device ,
138
- out featureLevelSupported ,
141
+ null ,
139
142
out d3d11DeviceContext ) ;
140
143
141
- if ( hr . IsSuccess )
144
+ if ( hr . Succeeded )
142
145
break ;
143
146
}
144
147
145
148
if ( d3d11Device is null )
146
149
return false ;
147
150
IDXGIDevice dxgiDevice = ( IDXGIDevice ) d3d11Device ;
148
- if ( Functions . DCompositionCreateDevice ( dxgiDevice , typeof ( IDCompositionDevice ) . GUID , out var compDevicePtr ) . IsError )
151
+ if ( PInvoke . DCompositionCreateDevice ( dxgiDevice , typeof ( IDCompositionDevice ) . GUID , out var compDevicePtr ) . Failed )
149
152
return false ;
150
- IDCompositionDevice compDevice = ( IDCompositionDevice ) Marshal . GetObjectForIUnknown ( compDevicePtr ) ;
153
+ IDCompositionDevice compDevice = ( IDCompositionDevice ) compDevicePtr ;
151
154
152
- if ( compDevice . CreateVisual ( out var childVisual ) . IsError ||
153
- compDevice . CreateSurfaceFromHwnd ( hwnd . DangerousGetHandle ( ) , out var controlSurface ) . IsError ||
154
- childVisual . SetContent ( controlSurface ) . IsError )
155
+ compDevice . CreateVisual ( out var childVisual ) ;
156
+ compDevice . CreateSurfaceFromHwnd ( new ( hwnd . DangerousGetHandle ( ) ) , out var controlSurface ) ;
157
+ childVisual . SetContent ( controlSurface ) ;
158
+ if ( childVisual is null || controlSurface is null )
155
159
return false ;
156
160
157
161
var compositor = ElementCompositionPreview . GetElementVisual ( presenter ) . Compositor ;
@@ -169,7 +173,7 @@ private bool ChildWindowToXaml(IntPtr parent, UIElement presenter)
169
173
Marshal . ReleaseComObject ( childVisual ) ;
170
174
Marshal . ReleaseComObject ( controlSurface ) ;
171
175
Marshal . ReleaseComObject ( compDevice ) ;
172
- Marshal . Release ( compDevicePtr ) ;
176
+ Marshal . ReleaseComObject ( compDevicePtr ) ;
173
177
Marshal . ReleaseComObject ( dxgiDevice ) ;
174
178
Marshal . ReleaseComObject ( d3d11Device ) ;
175
179
Marshal . ReleaseComObject ( d3d11DeviceContext ) ;
0 commit comments