OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrRenderTarget.h" | 10 #include "GrRenderTarget.h" |
11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
12 #include "VulkanWindowContext.h" | 12 #include "VulkanWindowContext.h" |
13 | 13 |
14 #include "vk/GrVkInterface.h" | 14 #include "vk/GrVkInterface.h" |
15 #include "vk/GrVkUtil.h" | 15 #include "vk/GrVkUtil.h" |
16 #include "vk/GrVkTypes.h" | 16 #include "vk/GrVkTypes.h" |
17 | 17 |
18 #ifdef VK_USE_PLATFORM_WIN32_KHR | 18 #ifdef VK_USE_PLATFORM_WIN32_KHR |
19 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW | 19 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
20 #undef CreateSemaphore | 20 #undef CreateSemaphore |
21 #endif | 21 #endif |
22 | 22 |
23 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk"
#F) | 23 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk"
#F) |
24 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk"
#F) | 24 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk"
#F) |
25 | 25 |
26 namespace sk_app { | 26 namespace sk_app { |
27 | 27 |
28 VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams
& params) | 28 VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, |
| 29 CreateVkSurfaceFn createVkSurface, |
| 30 CanPresentFn canPresent) |
29 : WindowContext() | 31 : WindowContext() |
30 , fSurface(VK_NULL_HANDLE) | 32 , fSurface(VK_NULL_HANDLE) |
31 , fSwapchain(VK_NULL_HANDLE) | 33 , fSwapchain(VK_NULL_HANDLE) |
32 , fImages(nullptr) | 34 , fImages(nullptr) |
33 , fImageLayouts(nullptr) | 35 , fImageLayouts(nullptr) |
34 , fSurfaces(nullptr) | 36 , fSurfaces(nullptr) |
35 , fCommandPool(VK_NULL_HANDLE) | 37 , fCommandPool(VK_NULL_HANDLE) |
36 , fBackbuffers(nullptr) { | 38 , fBackbuffers(nullptr) { |
37 | 39 |
38 // any config code here (particularly for msaa)? | 40 // any config code here (particularly for msaa)? |
39 | 41 fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPre
sent)); |
40 this->initializeContext(platformData, params); | |
41 } | |
42 | |
43 void VulkanWindowContext::initializeContext(void* platformData, const DisplayPar
ams& params) { | |
44 fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPre
sent, | |
45 platformData)); | |
46 | 42 |
47 if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || | 43 if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || |
48 !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { | 44 !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { |
49 fBackendContext.reset(nullptr); | 45 fBackendContext.reset(nullptr); |
50 return; | 46 return; |
51 } | 47 } |
52 | 48 |
53 VkInstance instance = fBackendContext->fInstance; | 49 VkInstance instance = fBackendContext->fInstance; |
54 VkDevice device = fBackendContext->fDevice; | 50 VkDevice device = fBackendContext->fDevice; |
55 GET_PROC(DestroySurfaceKHR); | 51 GET_PROC(DestroySurfaceKHR); |
56 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); | 52 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); |
57 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); | 53 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); |
58 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); | 54 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); |
59 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); | 55 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); |
60 GET_DEV_PROC(CreateSwapchainKHR); | 56 GET_DEV_PROC(CreateSwapchainKHR); |
61 GET_DEV_PROC(DestroySwapchainKHR); | 57 GET_DEV_PROC(DestroySwapchainKHR); |
62 GET_DEV_PROC(GetSwapchainImagesKHR); | 58 GET_DEV_PROC(GetSwapchainImagesKHR); |
63 GET_DEV_PROC(AcquireNextImageKHR); | 59 GET_DEV_PROC(AcquireNextImageKHR); |
64 GET_DEV_PROC(QueuePresentKHR); | 60 GET_DEV_PROC(QueuePresentKHR); |
65 | 61 |
66 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendC
ontext.get()); | 62 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendC
ontext.get()); |
67 | 63 |
68 fSurface = createVkSurface(instance, platformData); | 64 fSurface = createVkSurface(instance); |
69 if (VK_NULL_HANDLE == fSurface) { | 65 if (VK_NULL_HANDLE == fSurface) { |
70 fBackendContext.reset(nullptr); | 66 fBackendContext.reset(nullptr); |
71 return; | 67 return; |
72 } | 68 } |
73 | 69 |
74 VkBool32 supported; | 70 VkBool32 supported; |
75 VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysica
lDevice, | 71 VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysica
lDevice, |
76 fPresentQueueIndex, fSurf
ace, | 72 fPresentQueueIndex, fSurf
ace, |
77 &supported); | 73 &supported); |
78 if (VK_SUCCESS != res) { | 74 if (VK_SUCCESS != res) { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 &fSwapchain, // pSwapchains | 590 &fSwapchain, // pSwapchains |
595 &backbuffer->fImageIndex, // pImageIndices | 591 &backbuffer->fImageIndex, // pImageIndices |
596 NULL // pResults | 592 NULL // pResults |
597 }; | 593 }; |
598 | 594 |
599 fQueuePresentKHR(fPresentQueue, &presentInfo); | 595 fQueuePresentKHR(fPresentQueue, &presentInfo); |
600 | 596 |
601 } | 597 } |
602 | 598 |
603 } //namespace sk_app | 599 } //namespace sk_app |
OLD | NEW |