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 #include "SkTypes.h" // required to pull in any SkUserConfig defines | 11 #include "SkTypes.h" // required to pull in any SkUserConfig defines |
12 | 12 |
13 #ifdef SK_VULKAN | 13 #ifdef SK_VULKAN |
14 | 14 |
15 #include "vk/GrVkBackendContext.h" | 15 #include "vk/GrVkBackendContext.h" |
16 #include "WindowContext.h" | 16 #include "WindowContext.h" |
17 | 17 |
18 class GrRenderTarget; | 18 class GrRenderTarget; |
19 | 19 |
20 namespace sk_app { | 20 namespace sk_app { |
21 | 21 |
22 class VulkanWindowContext : public WindowContext { | 22 class VulkanWindowContext : public WindowContext { |
23 public: | 23 public: |
24 ~VulkanWindowContext() override; | 24 ~VulkanWindowContext() override; |
25 | 25 |
26 // each platform will have to implement these in its CPP file | |
27 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); | |
28 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd
ex, | |
29 void* platformData); | |
30 | |
31 static VulkanWindowContext* Create(void* platformData, const DisplayParams&
params) { | |
32 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, params)
; | |
33 if (!ctx->isValid()) { | |
34 delete ctx; | |
35 return nullptr; | |
36 } | |
37 return ctx; | |
38 } | |
39 | |
40 sk_sp<SkSurface> getBackbufferSurface() override; | 26 sk_sp<SkSurface> getBackbufferSurface() override; |
41 void swapBuffers() override; | 27 void swapBuffers() override; |
42 | 28 |
43 bool isValid() override { return SkToBool(fBackendContext.get()); } | 29 bool isValid() override { return SkToBool(fBackendContext.get()); } |
44 | 30 |
45 void resize(uint32_t w, uint32_t h) override { | 31 void resize(uint32_t w, uint32_t h) override { |
46 this->createSwapchain(w, h, fDisplayParams); | 32 this->createSwapchain(w, h, fDisplayParams); |
47 } | 33 } |
48 | 34 |
49 void setDisplayParams(const DisplayParams& params) override { | 35 void setDisplayParams(const DisplayParams& params) override { |
50 this->createSwapchain(fWidth, fHeight, params); | 36 this->createSwapchain(fWidth, fHeight, params); |
51 } | 37 } |
52 | 38 |
53 GrBackendContext getBackendContext() override { | 39 GrBackendContext getBackendContext() override { |
54 return (GrBackendContext) fBackendContext.get(); | 40 return (GrBackendContext) fBackendContext.get(); |
55 } | 41 } |
56 | 42 |
| 43 /** Platform specific function that creates a VkSurfaceKHR for a window */ |
| 44 using CreateVkSurfaceFn = std::function<VkSurfaceKHR(VkInstance)>; |
| 45 /** Platform specific function that determines whether presentation will suc
ceed. */ |
| 46 using CanPresentFn = GrVkBackendContext::CanPresentFn; |
| 47 |
| 48 VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn); |
| 49 |
57 private: | 50 private: |
58 VulkanWindowContext(void*, const DisplayParams&); | |
59 void initializeContext(void*, const DisplayParams&); | |
60 void destroyContext(); | 51 void destroyContext(); |
61 | 52 |
62 struct BackbufferInfo { | 53 struct BackbufferInfo { |
63 uint32_t fImageIndex; // image this is associated with | 54 uint32_t fImageIndex; // image this is associated with |
64 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti
on of image | 55 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti
on of image |
65 VkSemaphore fRenderSemaphore; // we wait on this for rendering t
o be done | 56 VkSemaphore fRenderSemaphore; // we wait on this for rendering t
o be done |
66 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee
n present and render | 57 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee
n present and render |
67 VkFence fUsageFences[2]; // used to ensure this data is no
longer used on GPU | 58 VkFence fUsageFences[2]; // used to ensure this data is no
longer used on GPU |
68 }; | 59 }; |
69 | 60 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 VkCommandPool fCommandPool; | 102 VkCommandPool fCommandPool; |
112 BackbufferInfo* fBackbuffers; | 103 BackbufferInfo* fBackbuffers; |
113 uint32_t fCurrentBackbufferIndex; | 104 uint32_t fCurrentBackbufferIndex; |
114 }; | 105 }; |
115 | 106 |
116 } // namespace sk_app | 107 } // namespace sk_app |
117 | 108 |
118 #endif // SK_VULKAN | 109 #endif // SK_VULKAN |
119 | 110 |
120 #endif | 111 #endif |
OLD | NEW |