Flutter Engine
The Flutter Engine
VulkanWindowContext_android.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11
13
14namespace skwindow {
15
16std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow* window,
17 const DisplayParams& params) {
19 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
20 return nullptr;
21 }
22
23 auto createVkSurface = [window, instProc] (VkInstance instance) -> VkSurfaceKHR {
24 PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR =
25 (PFN_vkCreateAndroidSurfaceKHR) instProc(instance, "vkCreateAndroidSurfaceKHR");
26
27 if (!window) {
28 return VK_NULL_HANDLE;
29 }
30 VkSurfaceKHR surface;
31
32 VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo;
33 memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR));
35 surfaceCreateInfo.pNext = nullptr;
36 surfaceCreateInfo.flags = 0;
37 surfaceCreateInfo.window = window;
38
39 VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo,
40 nullptr, &surface);
41 return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE;
42 };
43
44 auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; };
45
46 std::unique_ptr<WindowContext> ctx(
47 new internal::VulkanWindowContext(params, createVkSurface, canPresent, instProc));
48 if (!ctx->isValid()) {
49 return nullptr;
50 }
51 return ctx;
52}
53
54} // namespace skwindow
const EmbeddedViewParams * params
GLFWwindow * window
Definition: main.cc:45
VkInstance instance
Definition: main.cc:48
VkSurfaceKHR surface
Definition: main.cc:49
std::unique_ptr< WindowContext > MakeVulkanForAndroid(ANativeWindow *window, const DisplayParams &params)
struct ANativeWindow * window
VkAndroidSurfaceCreateFlagsKHR flags
VkResult(VKAPI_PTR * PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:3989
@ VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR
Definition: vulkan_core.h:432
struct ANativeWindow ANativeWindow