|
786 | 786 | <span id="786">786</span>
|
787 | 787 | <span id="787">787</span>
|
788 | 788 | <span id="788">788</span>
|
| 789 | +<span id="789">789</span> |
| 790 | +<span id="790">790</span> |
| 791 | +<span id="791">791</span> |
| 792 | +<span id="792">792</span> |
| 793 | +<span id="793">793</span> |
| 794 | +<span id="794">794</span> |
| 795 | +<span id="795">795</span> |
| 796 | +<span id="796">796</span> |
| 797 | +<span id="797">797</span> |
| 798 | +<span id="798">798</span> |
| 799 | +<span id="799">799</span> |
| 800 | +<span id="800">800</span> |
| 801 | +<span id="801">801</span> |
| 802 | +<span id="802">802</span> |
| 803 | +<span id="803">803</span> |
| 804 | +<span id="804">804</span> |
| 805 | +<span id="805">805</span> |
| 806 | +<span id="806">806</span> |
| 807 | +<span id="807">807</span> |
| 808 | +<span id="808">808</span> |
789 | 809 | </pre><pre class="rust"><code><span class="kw">use </span>std::{
|
790 | 810 | ffi::{c_void, CStr, CString},
|
791 | 811 | slice,
|
|
1091 | 1111 | <span class="kw-2">&</span><span class="self">self</span>,
|
1092 | 1112 | dpy: <span class="kw-2">*mut </span>vk::Display,
|
1093 | 1113 | window: vk::Window,
|
1094 |
| - ) -> <span class="kw">super</span>::Surface { |
| 1114 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
1095 | 1115 | <span class="kw">if </span>!<span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>khr::XlibSurface::name()) {
|
1096 |
| - <span class="macro">panic!</span>(<span class="string">"Vulkan driver does not support VK_KHR_XLIB_SURFACE"</span>); |
| 1116 | + <span class="macro">log::warn!</span>(<span class="string">"Vulkan driver does not support VK_KHR_xlib_surface"</span>); |
| 1117 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
1097 | 1118 | }
|
1098 | 1119 |
|
1099 | 1120 | <span class="kw">let </span>surface = {
|
|
1107 | 1128 | .expect(<span class="string">"XlibSurface::create_xlib_surface() failed"</span>)
|
1108 | 1129 | };
|
1109 | 1130 |
|
1110 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1131 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1111 | 1132 | }
|
1112 | 1133 |
|
1113 | 1134 | <span class="attribute">#[allow(dead_code)]
|
1114 | 1135 | </span><span class="kw">fn </span>create_surface_from_xcb(
|
1115 | 1136 | <span class="kw-2">&</span><span class="self">self</span>,
|
1116 | 1137 | connection: <span class="kw-2">*mut </span>vk::xcb_connection_t,
|
1117 | 1138 | window: vk::xcb_window_t,
|
1118 |
| - ) -> <span class="kw">super</span>::Surface { |
| 1139 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
1119 | 1140 | <span class="kw">if </span>!<span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>khr::XcbSurface::name()) {
|
1120 |
| - <span class="macro">panic!</span>(<span class="string">"Vulkan driver does not support VK_KHR_XCB_SURFACE"</span>); |
| 1141 | + <span class="macro">log::warn!</span>(<span class="string">"Vulkan driver does not support VK_KHR_xcb_surface"</span>); |
| 1142 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
1121 | 1143 | }
|
1122 | 1144 |
|
1123 | 1145 | <span class="kw">let </span>surface = {
|
|
1131 | 1153 | .expect(<span class="string">"XcbSurface::create_xcb_surface() failed"</span>)
|
1132 | 1154 | };
|
1133 | 1155 |
|
1134 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1156 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1135 | 1157 | }
|
1136 | 1158 |
|
1137 | 1159 | <span class="attribute">#[allow(dead_code)]
|
1138 | 1160 | </span><span class="kw">fn </span>create_surface_from_wayland(
|
1139 | 1161 | <span class="kw-2">&</span><span class="self">self</span>,
|
1140 | 1162 | display: <span class="kw-2">*mut </span>c_void,
|
1141 | 1163 | surface: <span class="kw-2">*mut </span>c_void,
|
1142 |
| - ) -> <span class="kw">super</span>::Surface { |
| 1164 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
1143 | 1165 | <span class="kw">if </span>!<span class="self">self
|
1144 | 1166 | </span>.shared
|
1145 | 1167 | .extensions
|
1146 | 1168 | .contains(<span class="kw-2">&</span>khr::WaylandSurface::name())
|
1147 | 1169 | {
|
1148 |
| - <span class="macro">panic!</span>(<span class="string">"Vulkan driver does not support VK_KHR_WAYLAND_SURFACE"</span>); |
| 1170 | + <span class="macro">log::debug!</span>(<span class="string">"Vulkan driver does not support VK_KHR_wayland_surface"</span>); |
| 1171 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
1149 | 1172 | }
|
1150 | 1173 |
|
1151 | 1174 | <span class="kw">let </span>surface = {
|
|
1158 | 1181 | <span class="kw">unsafe </span>{ w_loader.create_wayland_surface(<span class="kw-2">&</span>info, <span class="prelude-val">None</span>) }.expect(<span class="string">"WaylandSurface failed"</span>)
|
1159 | 1182 | };
|
1160 | 1183 |
|
1161 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1184 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1162 | 1185 | }
|
1163 | 1186 |
|
1164 | 1187 | <span class="attribute">#[allow(dead_code)]
|
1165 |
| - </span><span class="kw">fn </span>create_surface_android(<span class="kw-2">&</span><span class="self">self</span>, window: <span class="kw-2">*const </span>c_void) -> <span class="kw">super</span>::Surface { |
| 1188 | + </span><span class="kw">fn </span>create_surface_android( |
| 1189 | + <span class="kw-2">&</span><span class="self">self</span>, |
| 1190 | + window: <span class="kw-2">*const </span>c_void, |
| 1191 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
| 1192 | + <span class="kw">if </span>!<span class="self">self |
| 1193 | + </span>.shared |
| 1194 | + .extensions |
| 1195 | + .contains(<span class="kw-2">&</span>khr::AndroidSurface::name()) |
| 1196 | + { |
| 1197 | + <span class="macro">log::warn!</span>(<span class="string">"Vulkan driver does not support VK_KHR_android_surface"</span>); |
| 1198 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
| 1199 | + } |
| 1200 | + |
1166 | 1201 | <span class="kw">let </span>surface = {
|
1167 | 1202 | <span class="kw">let </span>a_loader = khr::AndroidSurface::new(<span class="kw-2">&</span><span class="self">self</span>.shared.entry, <span class="kw-2">&</span><span class="self">self</span>.shared.raw);
|
1168 | 1203 | <span class="kw">let </span>info = vk::AndroidSurfaceCreateInfoKHR::builder()
|
|
1172 | 1207 | <span class="kw">unsafe </span>{ a_loader.create_android_surface(<span class="kw-2">&</span>info, <span class="prelude-val">None</span>) }.expect(<span class="string">"AndroidSurface failed"</span>)
|
1173 | 1208 | };
|
1174 | 1209 |
|
1175 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1210 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1176 | 1211 | }
|
1177 | 1212 |
|
1178 | 1213 | <span class="attribute">#[allow(dead_code)]
|
1179 | 1214 | </span><span class="kw">fn </span>create_surface_from_hwnd(
|
1180 | 1215 | <span class="kw-2">&</span><span class="self">self</span>,
|
1181 | 1216 | hinstance: <span class="kw-2">*mut </span>c_void,
|
1182 | 1217 | hwnd: <span class="kw-2">*mut </span>c_void,
|
1183 |
| - ) -> <span class="kw">super</span>::Surface { |
| 1218 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
1184 | 1219 | <span class="kw">if </span>!<span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>khr::Win32Surface::name()) {
|
1185 |
| - <span class="macro">panic!</span>(<span class="string">"Vulkan driver does not support VK_KHR_WIN32_SURFACE"</span>); |
| 1220 | + <span class="macro">log::debug!</span>(<span class="string">"Vulkan driver does not support VK_KHR_win32_surface"</span>); |
| 1221 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
1186 | 1222 | }
|
1187 | 1223 |
|
1188 | 1224 | <span class="kw">let </span>surface = {
|
|
1198 | 1234 | }
|
1199 | 1235 | };
|
1200 | 1236 |
|
1201 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1237 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1202 | 1238 | }
|
1203 | 1239 |
|
1204 | 1240 | <span class="attribute">#[cfg(any(target_os = <span class="string">"macos"</span>, target_os = <span class="string">"ios"</span>))]
|
1205 |
| - </span><span class="kw">fn </span>create_surface_from_view(<span class="kw-2">&</span><span class="self">self</span>, view: <span class="kw-2">*mut </span>c_void) -> <span class="kw">super</span>::Surface { |
| 1241 | + </span><span class="kw">fn </span>create_surface_from_view( |
| 1242 | + <span class="kw-2">&</span><span class="self">self</span>, |
| 1243 | + view: <span class="kw-2">*mut </span>c_void, |
| 1244 | + ) -> <span class="prelude-ty">Result</span><<span class="kw">super</span>::Surface, <span class="kw">crate</span>::InstanceError> { |
| 1245 | + <span class="kw">if </span>!<span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>ext::MetalSurface::name()) { |
| 1246 | + <span class="macro">log::warn!</span>(<span class="string">"Vulkan driver does not support VK_EXT_metal_surface"</span>); |
| 1247 | + <span class="kw">return </span><span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError); |
| 1248 | + } |
| 1249 | + |
1206 | 1250 | <span class="kw">let </span>layer = <span class="kw">unsafe </span>{
|
1207 | 1251 | <span class="kw">crate</span>::metal::Surface::get_metal_layer(view <span class="kw">as </span><span class="kw-2">*mut </span>objc::runtime::Object, <span class="prelude-val">None</span>)
|
1208 | 1252 | };
|
|
1217 | 1261 | <span class="kw">unsafe </span>{ metal_loader.create_metal_surface(<span class="kw-2">&</span>vk_info, <span class="prelude-val">None</span>).unwrap() }
|
1218 | 1262 | };
|
1219 | 1263 |
|
1220 |
| - <span class="self">self</span>.create_surface_from_vk_surface_khr(surface) |
| 1264 | + <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_vk_surface_khr(surface)) |
1221 | 1265 | }
|
1222 | 1266 |
|
1223 | 1267 | <span class="kw">fn </span>create_surface_from_vk_surface_khr(<span class="kw-2">&</span><span class="self">self</span>, surface: vk::SurfaceKHR) -> <span class="kw">super</span>::Surface {
|
|
1386 | 1430 |
|
1387 | 1431 | <span class="kw">match </span>(window_handle, display_handle) {
|
1388 | 1432 | (Rwh::Wayland(handle), Rdh::Wayland(display)) => {
|
1389 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_wayland(display.display, handle.surface)) |
| 1433 | + <span class="self">self</span>.create_surface_from_wayland(display.display, handle.surface) |
1390 | 1434 | }
|
1391 |
| - (Rwh::Xlib(handle), Rdh::Xlib(display)) |
1392 |
| - <span class="kw">if </span><span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>khr::XlibSurface::name()) => |
1393 |
| - { |
1394 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_xlib(display.display <span class="kw">as </span><span class="kw-2">*mut </span><span class="kw">_</span>, handle.window)) |
| 1435 | + (Rwh::Xlib(handle), Rdh::Xlib(display)) => { |
| 1436 | + <span class="self">self</span>.create_surface_from_xlib(display.display <span class="kw">as </span><span class="kw-2">*mut </span><span class="kw">_</span>, handle.window) |
1395 | 1437 | }
|
1396 |
| - (Rwh::Xcb(handle), Rdh::Xcb(display)) |
1397 |
| - <span class="kw">if </span><span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>khr::XcbSurface::name()) => |
1398 |
| - { |
1399 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_xcb(display.connection, handle.window)) |
| 1438 | + (Rwh::Xcb(handle), Rdh::Xcb(display)) => { |
| 1439 | + <span class="self">self</span>.create_surface_from_xcb(display.connection, handle.window) |
1400 | 1440 | }
|
1401 |
| - (Rwh::AndroidNdk(handle), <span class="kw">_</span>) => <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_android(handle.a_native_window)), |
| 1441 | + (Rwh::AndroidNdk(handle), <span class="kw">_</span>) => <span class="self">self</span>.create_surface_android(handle.a_native_window), |
1402 | 1442 | <span class="attribute">#[cfg(windows)]
|
1403 | 1443 | </span>(Rwh::Win32(handle), <span class="kw">_</span>) => {
|
1404 | 1444 | <span class="kw">use </span>winapi::um::libloaderapi::GetModuleHandleW;
|
1405 | 1445 |
|
1406 | 1446 | <span class="kw">let </span>hinstance = GetModuleHandleW(std::ptr::null());
|
1407 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_hwnd(hinstance <span class="kw">as </span><span class="kw-2">*mut </span><span class="kw">_</span>, handle.hwnd)) |
| 1447 | + <span class="self">self</span>.create_surface_from_hwnd(hinstance <span class="kw">as </span><span class="kw-2">*mut </span><span class="kw">_</span>, handle.hwnd) |
1408 | 1448 | }
|
1409 | 1449 | <span class="attribute">#[cfg(target_os = <span class="string">"macos"</span>)]
|
1410 | 1450 | </span>(Rwh::AppKit(handle), <span class="kw">_</span>)
|
1411 | 1451 | <span class="kw">if </span><span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>ext::MetalSurface::name()) =>
|
1412 | 1452 | {
|
1413 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_view(handle.ns_view)) |
| 1453 | + <span class="self">self</span>.create_surface_from_view(handle.ns_view) |
1414 | 1454 | }
|
1415 | 1455 | <span class="attribute">#[cfg(target_os = <span class="string">"ios"</span>)]
|
1416 | 1456 | </span>(Rwh::UiKit(handle), <span class="kw">_</span>)
|
1417 | 1457 | <span class="kw">if </span><span class="self">self</span>.shared.extensions.contains(<span class="kw-2">&</span>ext::MetalSurface::name()) =>
|
1418 | 1458 | {
|
1419 |
| - <span class="prelude-val">Ok</span>(<span class="self">self</span>.create_surface_from_view(handle.ui_view)) |
| 1459 | + <span class="self">self</span>.create_surface_from_view(handle.ui_view) |
1420 | 1460 | }
|
1421 | 1461 | (<span class="kw">_</span>, <span class="kw">_</span>) => <span class="prelude-val">Err</span>(<span class="kw">crate</span>::InstanceError),
|
1422 | 1462 | }
|
|
0 commit comments