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 #ifndef VulkanWindowContext_DEFINED | 8 #ifndef VulkanWindowContext_DEFINED |
9 #define VulkanWindowContext_DEFINED | 9 #define VulkanWindowContext_DEFINED |
10 | 10 |
11 #ifdef SK_VULKAN | 11 #ifdef SK_VULKAN |
12 | 12 |
13 #include "vk/GrVkBackendContext.h" | 13 #include "vk/GrVkBackendContext.h" |
14 #include "WindowContext.h" | 14 #include "WindowContext.h" |
15 | 15 |
16 class SkSurface; | 16 class GrRenderTarget; |
17 class GrContext; | |
18 | 17 |
19 namespace sk_app { | 18 namespace sk_app { |
20 | 19 |
21 class VulkanWindowContext : public WindowContext { | 20 class VulkanWindowContext : public WindowContext { |
22 public: | 21 public: |
23 ~VulkanWindowContext() override; | 22 ~VulkanWindowContext() override; |
24 | 23 |
25 // each platform will have to implement these in its CPP file | 24 // each platform will have to implement these in its CPP file |
26 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); | 25 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); |
27 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd
ex); | 26 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd
ex); |
28 | 27 |
29 static VulkanWindowContext* Create(void* platformData, const DisplayParams&
params) { | 28 static VulkanWindowContext* Create(void* platformData, const DisplayParams&
params) { |
30 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, params)
; | 29 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, params)
; |
31 if (!ctx->isValid()) { | 30 if (!ctx->isValid()) { |
32 delete ctx; | 31 delete ctx; |
33 return nullptr; | 32 return nullptr; |
34 } | 33 } |
35 return ctx; | 34 return ctx; |
36 } | 35 } |
37 | 36 |
38 SkSurface* getBackbufferSurface() override; | 37 sk_sp<SkSurface> getBackbufferSurface() override; |
39 void swapBuffers() override; | 38 void swapBuffers() override; |
40 | 39 |
41 bool makeCurrent() override { return true; } | |
42 | |
43 bool isValid() override { return SkToBool(fBackendContext.get()); } | 40 bool isValid() override { return SkToBool(fBackendContext.get()); } |
44 | 41 |
45 void resize(uint32_t w, uint32_t h) override { | 42 void resize(uint32_t w, uint32_t h) override { |
46 this->createSwapchain(w, h, fDisplayParams); | 43 this->createSwapchain(w, h, fDisplayParams); |
47 } | 44 } |
48 | 45 |
49 const DisplayParams& getDisplayParams() override { return fDisplayParams; } | |
50 void setDisplayParams(const DisplayParams& params) override { | 46 void setDisplayParams(const DisplayParams& params) override { |
51 this->createSwapchain(fWidth, fHeight, params); | 47 this->createSwapchain(fWidth, fHeight, params); |
52 } | 48 } |
53 | 49 |
54 GrBackendContext getBackendContext() override { | 50 GrBackendContext getBackendContext() override { |
55 return (GrBackendContext) fBackendContext.get(); | 51 return (GrBackendContext) fBackendContext.get(); |
56 } | 52 } |
57 | 53 |
58 private: | 54 private: |
59 VulkanWindowContext(void*, const DisplayParams&); | 55 VulkanWindowContext(void*, const DisplayParams&); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFor
matsKHR; | 88 VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFor
matsKHR; |
93 VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfa
cePresentModesKHR; | 89 VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfa
cePresentModesKHR; |
94 | 90 |
95 VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR; | 91 VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR; |
96 VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR; | 92 VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR; |
97 VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR; | 93 VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR; |
98 VkPtr<PFN_vkAcquireNextImageKHR> fAcquireNextImageKHR; | 94 VkPtr<PFN_vkAcquireNextImageKHR> fAcquireNextImageKHR; |
99 VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR; | 95 VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR; |
100 VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR; | 96 VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR; |
101 | 97 |
102 GrContext* fContext; | |
103 VkSurfaceKHR fSurface; | 98 VkSurfaceKHR fSurface; |
104 VkSwapchainKHR fSwapchain; | 99 VkSwapchainKHR fSwapchain; |
105 uint32_t fPresentQueueIndex; | 100 uint32_t fPresentQueueIndex; |
106 VkQueue fPresentQueue; | 101 VkQueue fPresentQueue; |
107 int fWidth; | 102 int fWidth; |
108 int fHeight; | 103 int fHeight; |
109 DisplayParams fDisplayParams; | |
110 GrPixelConfig fPixelConfig; | |
111 | 104 |
112 uint32_t fImageCount; | 105 uint32_t fImageCount; |
113 VkImage* fImages; // images in the swapchain | 106 VkImage* fImages; // images in the swapchain |
114 VkImageLayout* fImageLayouts; // layouts of these images when not color
attachment | 107 VkImageLayout* fImageLayouts; // layouts of these images when not
color attachment |
115 sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images | 108 sk_sp<GrRenderTarget>* fRenderTargets; // wrapped rendertargets for those i
mages |
116 VkCommandPool fCommandPool; | 109 sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may n
ot be based on rts) |
117 BackbufferInfo* fBackbuffers; | 110 VkCommandPool fCommandPool; |
118 uint32_t fCurrentBackbufferIndex; | 111 BackbufferInfo* fBackbuffers; |
| 112 uint32_t fCurrentBackbufferIndex; |
119 }; | 113 }; |
120 | 114 |
121 } // namespace sk_app | 115 } // namespace sk_app |
122 | 116 |
123 #endif // SK_VULKAN | 117 #endif // SK_VULKAN |
124 | 118 |
125 #endif | 119 #endif |
OLD | NEW |