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 VulkanTestContext_DEFINED | 8 #ifndef VulkanWindowContext_DEFINED |
9 #define VulkanTestContext_DEFINED | 9 #define VulkanWindowContext_DEFINED |
10 | 10 |
11 #ifdef SK_VULKAN | 11 #ifdef SK_VULKAN |
12 | 12 |
13 #include "GrTypes.h" | |
14 #include "vk/GrVkBackendContext.h" | 13 #include "vk/GrVkBackendContext.h" |
| 14 #include "WindowContext.h" |
15 | 15 |
16 class SkSurface; | 16 class SkSurface; |
17 class GrContext; | 17 class GrContext; |
18 | 18 |
19 class VulkanTestContext { | 19 namespace sk_app { |
| 20 |
| 21 class VulkanWindowContext : public WindowContext { |
20 public: | 22 public: |
21 ~VulkanTestContext(); | 23 ~VulkanWindowContext() override; |
22 | 24 |
23 // each platform will have to implement these in its CPP file | 25 // each platform will have to implement these in its CPP file |
24 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); | 26 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); |
25 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd
ex); | 27 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd
ex); |
26 | 28 |
27 static VulkanTestContext* Create(void* platformData, int msaaSampleCount) { | 29 static VulkanWindowContext* Create(void* platformData, int msaaSampleCount)
{ |
28 VulkanTestContext* ctx = new VulkanTestContext(platformData, msaaSampleC
ount); | 30 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, msaaSam
pleCount); |
29 if (!ctx->isValid()) { | 31 if (!ctx->isValid()) { |
30 delete ctx; | 32 delete ctx; |
31 return nullptr; | 33 return nullptr; |
32 } | 34 } |
33 return ctx; | 35 return ctx; |
34 } | 36 } |
35 | 37 |
36 SkSurface* getBackbufferSurface(); | 38 SkSurface* getBackbufferSurface() override; |
37 void swapBuffers(); | 39 void swapBuffers() override; |
38 | 40 |
39 bool makeCurrent() { return true; } | 41 bool makeCurrent() override { return true; } |
40 | 42 |
41 bool isValid() { return SkToBool(fBackendContext.get()); } | 43 bool isValid() override { return SkToBool(fBackendContext.get()); } |
42 | 44 |
43 void resize(uint32_t w, uint32_t h) { | 45 void resize(uint32_t w, uint32_t h) override { |
44 this->createSwapchain(w, h); | 46 this->createSwapchain(w, h); |
45 } | 47 } |
46 | 48 |
47 GrBackendContext getBackendContext() { return (GrBackendContext)fBackendCont
ext.get(); } | 49 GrBackendContext getBackendContext() override { |
| 50 return (GrBackendContext) fBackendContext.get(); |
| 51 } |
48 | 52 |
49 private: | 53 private: |
50 VulkanTestContext(); | 54 VulkanWindowContext(); |
51 VulkanTestContext(void*, int msaaSampleCount); | 55 VulkanWindowContext(void*, int msaaSampleCount); |
52 void initializeContext(void*); | 56 void initializeContext(void*); |
53 void destroyContext(); | 57 void destroyContext(); |
54 | 58 |
55 struct BackbufferInfo { | 59 struct BackbufferInfo { |
56 uint32_t fImageIndex; // image this is associated with | 60 uint32_t fImageIndex; // image this is associated with |
57 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti
on of image | 61 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti
on of image |
58 VkSemaphore fRenderSemaphore; // we wait on this for rendering t
o be done | 62 VkSemaphore fRenderSemaphore; // we wait on this for rendering t
o be done |
59 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee
n present and render | 63 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee
n present and render |
60 VkFence fUsageFences[2]; // used to ensure this data is no
longer used on GPU | 64 VkFence fUsageFences[2]; // used to ensure this data is no
longer used on GPU |
61 }; | 65 }; |
62 | 66 |
63 BackbufferInfo* getAvailableBackbuffer(); | 67 BackbufferInfo* getAvailableBackbuffer(); |
64 bool createSwapchain(uint32_t width, uint32_t height); | 68 bool createSwapchain(uint32_t width, uint32_t height); |
65 void createBuffers(VkFormat format); | 69 void createBuffers(VkFormat format); |
66 void destroyBuffers(); | 70 void destroyBuffers(); |
67 | 71 |
68 SkAutoTUnref<const GrVkBackendContext> fBackendContext; | 72 SkAutoTUnref<const GrVkBackendContext> fBackendContext; |
69 | 73 |
70 // simple wrapper class that exists only to initialize a pointer to NULL | 74 // simple wrapper class that exists only to initialize a pointer to NULL |
71 template <typename FNPTR_TYPE> class VkPtr { | 75 template <typename FNPTR_TYPE> class VkPtr { |
72 public: | 76 public: |
73 VkPtr() : fPtr(NULL) {} | 77 VkPtr() : fPtr(NULL) {} |
74 VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } | 78 VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } |
75 operator FNPTR_TYPE() const { return fPtr; } | 79 operator FNPTR_TYPE() const { return fPtr; } |
76 private: | 80 private: |
77 FNPTR_TYPE fPtr; | 81 FNPTR_TYPE fPtr; |
78 }; | 82 }; |
79 | 83 |
80 // WSI interface functions | 84 // WSI interface functions |
81 VkPtr<PFN_vkDestroySurfaceKHR> fDestroySurfaceKHR; | 85 VkPtr<PFN_vkDestroySurfaceKHR> fDestroySurfaceKHR; |
82 VkPtr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR> fGetPhysicalDeviceSurfaceSup
portKHR; | 86 VkPtr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR> fGetPhysicalDeviceSurfaceSup
portKHR; |
83 VkPtr<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR> fGetPhysicalDeviceSurfa
ceCapabilitiesKHR; | 87 VkPtr<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR> fGetPhysicalDeviceSurfa
ceCapabilitiesKHR; |
84 VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFor
matsKHR; | 88 VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFor
matsKHR; |
85 VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfa
cePresentModesKHR; | 89 VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfa
cePresentModesKHR; |
86 | 90 |
87 VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR; | 91 VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR; |
88 VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR; | 92 VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR; |
89 VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR; | 93 VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR; |
(...skipping 12 matching lines...) Expand all Loading... |
102 | 106 |
103 uint32_t fImageCount; | 107 uint32_t fImageCount; |
104 VkImage* fImages; // images in the swapchain | 108 VkImage* fImages; // images in the swapchain |
105 VkImageLayout* fImageLayouts; // layouts of these images when not color
attachment | 109 VkImageLayout* fImageLayouts; // layouts of these images when not color
attachment |
106 sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images | 110 sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images |
107 VkCommandPool fCommandPool; | 111 VkCommandPool fCommandPool; |
108 BackbufferInfo* fBackbuffers; | 112 BackbufferInfo* fBackbuffers; |
109 uint32_t fCurrentBackbufferIndex; | 113 uint32_t fCurrentBackbufferIndex; |
110 }; | 114 }; |
111 | 115 |
| 116 } // namespace sk_app |
| 117 |
112 #endif // SK_VULKAN | 118 #endif // SK_VULKAN |
113 | 119 |
114 #endif | 120 #endif |
OLD | NEW |