1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <vulkan/vulkan.h>
17
18 #include "util/log.h"
19 #include "vulkan/create_functions_vk.h"
20 #include "vulkan/validate_vk.h"
21
RENDER_BEGIN_NAMESPACE()22 RENDER_BEGIN_NAMESPACE()
23 VkSurfaceKHR CreateFunctionsVk::CreateSurface(VkInstance instance, Window const& nativeWindow)
24 {
25 VkSurfaceKHR surface = VK_NULL_HANDLE;
26 PLUGIN_ASSERT_MSG(instance, "null instance in CreateSurface()");
27 #ifdef VK_USE_PLATFORM_OHOS
28 if (nativeWindow.window) {
29 PFN_vkCreateSurfaceOHOS vkCreateSurfaceOHOS =
30 (PFN_vkCreateSurfaceOHOS)vkGetInstanceProcAddr(instance, "vkCreateSurfaceOHOS");
31 if (!vkCreateSurfaceOHOS) {
32 PLUGIN_LOG_E("Missing VK_OHOS_surface extension");
33 return surface;
34 }
35 VkSurfaceCreateInfoOHOS const surfaceCreateInfo {
36 VK_STRUCTURE_TYPE_SURFACE_CREATE_INFO_OHOS, // sType
37 nullptr, // pNext
38 0, // flags
39 (OHNativeWindow*)nativeWindow.window, // window
40 };
41 VALIDATE_VK_RESULT(vkCreateSurfaceOHOS(instance, &surfaceCreateInfo, nullptr, &surface));
42 #else
43 #error Missing platform surface type.
44 #endif
45 }
46
47 return surface;
48 }
49 RENDER_END_NAMESPACE()
50