djsollen | 12d62a7 | 2016-04-21 07:59:44 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright 2016 Google Inc. |
djsollen | 12d62a7 | 2016-04-21 07:59:44 -0700 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 9 | #include "WindowContextFactory_android.h" |
liyuqian | 6cb7025 | 2016-06-02 12:16:25 -0700 | [diff] [blame] | 10 | #include "../VulkanWindowContext.h" |
djsollen | 12d62a7 | 2016-04-21 07:59:44 -0700 | [diff] [blame] | 11 | |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame^] | 12 | #include "vk/VkTestUtils.h" |
| 13 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 14 | namespace sk_app { |
| 15 | |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 16 | namespace window_context_factory { |
| 17 | |
| 18 | WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& params) { |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame^] | 19 | PFN_vkGetInstanceProcAddr instProc; |
| 20 | PFN_vkGetDeviceProcAddr devProc; |
| 21 | if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) { |
| 22 | return nullptr; |
| 23 | } |
| 24 | |
| 25 | auto createVkSurface = [window, instProc] (VkInstance instance) -> VkSurfaceKHR { |
egdaniel | f5fe4b5 | 2016-08-11 08:15:12 -0700 | [diff] [blame] | 26 | PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame^] | 27 | (PFN_vkCreateAndroidSurfaceKHR) instProc(instance, "vkCreateAndroidSurfaceKHR"); |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 28 | |
| 29 | if (!window) { |
| 30 | return VK_NULL_HANDLE; |
| 31 | } |
| 32 | VkSurfaceKHR surface; |
| 33 | |
| 34 | VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; |
| 35 | memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); |
| 36 | surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; |
| 37 | surfaceCreateInfo.pNext = nullptr; |
| 38 | surfaceCreateInfo.flags = 0; |
| 39 | surfaceCreateInfo.window = window; |
| 40 | |
| 41 | VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo, |
| 42 | nullptr, &surface); |
| 43 | return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; |
| 44 | }; |
| 45 | |
| 46 | auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; }; |
| 47 | |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame^] | 48 | WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent, |
| 49 | instProc, devProc); |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 50 | if (!ctx->isValid()) { |
| 51 | delete ctx; |
| 52 | return nullptr; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 53 | } |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 54 | return ctx; |
djsollen | 12d62a7 | 2016-04-21 07:59:44 -0700 | [diff] [blame] | 55 | } |
| 56 | |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 57 | } // namespace window_context_factory |
| 58 | } // namespace sk_app |