OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
| 9 #include "WindowContextFactory_android.h" |
9 #include "../VulkanWindowContext.h" | 10 #include "../VulkanWindowContext.h" |
10 #include "WindowContext_android.h" | |
11 | |
12 #include "vk/GrVkInterface.h" | |
13 #include "vk/GrVkUtil.h" | |
14 | 11 |
15 namespace sk_app { | 12 namespace sk_app { |
16 | 13 |
17 VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* pla
tformData) { | 14 namespace window_context_factory { |
18 static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr; | 15 |
19 if (!createAndroidSurfaceKHR) { | 16 WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& p
arams) { |
20 createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstancePr
ocAddr(instance, | 17 auto createVkSurface = [window] (VkInstance instance) -> VkSurfaceKHR { |
21 "vkCreate
AndroidSurfaceKHR"); | 18 static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr; |
| 19 if (!createAndroidSurfaceKHR) { |
| 20 createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstan
ceProcAddr( |
| 21 instance, "vkCreateAndroidSurfaceKHR"); |
| 22 } |
| 23 |
| 24 if (!window) { |
| 25 return VK_NULL_HANDLE; |
| 26 } |
| 27 VkSurfaceKHR surface; |
| 28 |
| 29 VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; |
| 30 memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); |
| 31 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_
KHR; |
| 32 surfaceCreateInfo.pNext = nullptr; |
| 33 surfaceCreateInfo.flags = 0; |
| 34 surfaceCreateInfo.window = window; |
| 35 |
| 36 VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo, |
| 37 nullptr, &surface); |
| 38 return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; |
| 39 }; |
| 40 |
| 41 auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true;
}; |
| 42 |
| 43 WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPre
sent); |
| 44 if (!ctx->isValid()) { |
| 45 delete ctx; |
| 46 return nullptr; |
22 } | 47 } |
23 | 48 return ctx; |
24 if (!platformData) { | |
25 return VK_NULL_HANDLE; | |
26 } | |
27 ContextPlatformData_android* androidPlatformData = | |
28 reinterpret_cast<ContextPlatformData_
android*>(platformData); | |
29 VkSurfaceKHR surface; | |
30 | |
31 VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; | |
32 memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); | |
33 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; | |
34 surfaceCreateInfo.pNext = nullptr; | |
35 surfaceCreateInfo.flags = 0; | |
36 surfaceCreateInfo.window = androidPlatformData->fNativeWindow; | |
37 | |
38 VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo, | |
39 nullptr, &surface); | |
40 return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; | |
41 } | 49 } |
42 | 50 |
43 bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physD
ev, | 51 } // namespace window_context_factory |
44 uint32_t queueFamilyIndex, void*) { | 52 } // namespace sk_app |
45 return true; | |
46 } | |
47 | |
48 } // namespace sk_app | |
OLD | NEW |