• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2016 Google Inc.
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 
9 #include "include/gpu/vk/GrVkVulkan.h"
10 
11 #include "tools/sk_app/android/WindowContextFactory_android.h"
12 
13 #include "tools/sk_app/VulkanWindowContext.h"
14 
15 #include "tools/gpu/vk/VkTestUtils.h"
16 
17 namespace sk_app {
18 
19 namespace window_context_factory {
20 
MakeVulkanForAndroid(ANativeWindow * window,const DisplayParams & params)21 std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow* window,
22                                                     const DisplayParams& params) {
23     PFN_vkGetInstanceProcAddr instProc;
24     PFN_vkGetDeviceProcAddr devProc;
25     if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
26         return nullptr;
27     }
28 
29     auto createVkSurface = [window, instProc] (VkInstance instance) -> VkSurfaceKHR {
30         PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR =
31                 (PFN_vkCreateAndroidSurfaceKHR) instProc(instance, "vkCreateAndroidSurfaceKHR");
32 
33         if (!window) {
34             return VK_NULL_HANDLE;
35         }
36         VkSurfaceKHR surface;
37 
38         VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo;
39         memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR));
40         surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
41         surfaceCreateInfo.pNext = nullptr;
42         surfaceCreateInfo.flags = 0;
43         surfaceCreateInfo.window = window;
44 
45         VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo,
46                                                nullptr, &surface);
47         return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE;
48     };
49 
50     auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; };
51 
52     std::unique_ptr<WindowContext> ctx(
53             new VulkanWindowContext(params, createVkSurface, canPresent, instProc, devProc));
54     if (!ctx->isValid()) {
55         return nullptr;
56     }
57     return ctx;
58 }
59 
60 }  // namespace window_context_factory
61 }  // namespace sk_app
62