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 SkSurface; |
17 class GrContext; | 17 class GrContext; |
18 | 18 |
19 namespace sk_app { | 19 namespace sk_app { |
20 | 20 |
21 class VulkanWindowContext : public WindowContext { | 21 class VulkanWindowContext : public WindowContext { |
22 public: | 22 public: |
23 ~VulkanWindowContext() override; | 23 ~VulkanWindowContext() override; |
24 | 24 |
25 // each platform will have to implement these in its CPP file | 25 // each platform will have to implement these in its CPP file |
26 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); | 26 static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); |
27 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd ex); | 27 static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyInd ex); |
28 | 28 |
29 static VulkanWindowContext* Create(void* platformData, int msaaSampleCount) { | 29 static VulkanWindowContext* Create(void* platformData, int msaaSampleCount, bool srgb) { |
30 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, msaaSam pleCount); | 30 VulkanWindowContext* ctx = new VulkanWindowContext(platformData, msaaSam pleCount, srgb); |
31 if (!ctx->isValid()) { | 31 if (!ctx->isValid()) { |
32 delete ctx; | 32 delete ctx; |
33 return nullptr; | 33 return nullptr; |
34 } | 34 } |
35 return ctx; | 35 return ctx; |
36 } | 36 } |
37 | 37 |
38 SkSurface* getBackbufferSurface() override; | 38 SkSurface* getBackbufferSurface() override; |
39 void swapBuffers() override; | 39 void swapBuffers() override; |
40 | 40 |
41 bool makeCurrent() override { return true; } | 41 bool makeCurrent() override { return true; } |
42 | 42 |
43 bool isValid() override { return SkToBool(fBackendContext.get()); } | 43 bool isValid() override { return SkToBool(fBackendContext.get()); } |
44 | 44 |
45 void resize(uint32_t w, uint32_t h) override { | 45 void resize(uint32_t w, uint32_t h) override { |
46 this->createSwapchain(w, h); | 46 this->createSwapchain(w, h, fSRGB); |
47 } | |
48 | |
49 bool getSRGB() override { return fSRGB; } | |
50 void setSRGB(bool srgb) override { | |
51 this->createSwapchain(fWidth, fHeight, srgb); | |
47 } | 52 } |
48 | 53 |
49 GrBackendContext getBackendContext() override { | 54 GrBackendContext getBackendContext() override { |
50 return (GrBackendContext) fBackendContext.get(); | 55 return (GrBackendContext) fBackendContext.get(); |
51 } | 56 } |
52 | 57 |
53 private: | 58 private: |
54 VulkanWindowContext(); | 59 VulkanWindowContext(void*, int msaaSampleCount, bool srgb); |
55 VulkanWindowContext(void*, int msaaSampleCount); | 60 void initializeContext(void*, bool srgb); |
56 void initializeContext(void*); | |
57 void destroyContext(); | 61 void destroyContext(); |
58 | 62 |
59 struct BackbufferInfo { | 63 struct BackbufferInfo { |
60 uint32_t fImageIndex; // image this is associated with | 64 uint32_t fImageIndex; // image this is associated with |
61 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti on of image | 65 VkSemaphore fAcquireSemaphore; // we signal on this for acquisiti on of image |
62 VkSemaphore fRenderSemaphore; // we wait on this for rendering t o be done | 66 VkSemaphore fRenderSemaphore; // we wait on this for rendering t o be done |
63 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee n present and render | 67 VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout betwee n present and render |
64 VkFence fUsageFences[2]; // used to ensure this data is no longer used on GPU | 68 VkFence fUsageFences[2]; // used to ensure this data is no longer used on GPU |
65 }; | 69 }; |
66 | 70 |
67 BackbufferInfo* getAvailableBackbuffer(); | 71 BackbufferInfo* getAvailableBackbuffer(); |
68 bool createSwapchain(uint32_t width, uint32_t height); | 72 bool createSwapchain(uint32_t width, uint32_t height, bool srgb); |
bsalomon
2016/05/06 18:30:15
Should we take a config here or something more gen
Brian Osman
2016/05/06 18:42:06
Did you mean GrPixelConfig? That would invert some
bsalomon
2016/05/06 18:48:32
What about (SkColorType, SkProfileType)?
I think
| |
69 void createBuffers(VkFormat format); | 73 void createBuffers(VkFormat format); |
70 void destroyBuffers(); | 74 void destroyBuffers(); |
71 | 75 |
72 SkAutoTUnref<const GrVkBackendContext> fBackendContext; | 76 SkAutoTUnref<const GrVkBackendContext> fBackendContext; |
73 | 77 |
74 // simple wrapper class that exists only to initialize a pointer to NULL | 78 // simple wrapper class that exists only to initialize a pointer to NULL |
75 template <typename FNPTR_TYPE> class VkPtr { | 79 template <typename FNPTR_TYPE> class VkPtr { |
76 public: | 80 public: |
77 VkPtr() : fPtr(NULL) {} | 81 VkPtr() : fPtr(NULL) {} |
78 VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } | 82 VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; } |
(...skipping 16 matching lines...) Expand all Loading... | |
95 VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR; | 99 VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR; |
96 VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR; | 100 VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR; |
97 | 101 |
98 GrContext* fContext; | 102 GrContext* fContext; |
99 VkSurfaceKHR fSurface; | 103 VkSurfaceKHR fSurface; |
100 VkSwapchainKHR fSwapchain; | 104 VkSwapchainKHR fSwapchain; |
101 uint32_t fPresentQueueIndex; | 105 uint32_t fPresentQueueIndex; |
102 VkQueue fPresentQueue; | 106 VkQueue fPresentQueue; |
103 int fWidth; | 107 int fWidth; |
104 int fHeight; | 108 int fHeight; |
109 bool fSRGB; | |
105 GrPixelConfig fPixelConfig; | 110 GrPixelConfig fPixelConfig; |
106 | 111 |
107 uint32_t fImageCount; | 112 uint32_t fImageCount; |
108 VkImage* fImages; // images in the swapchain | 113 VkImage* fImages; // images in the swapchain |
109 VkImageLayout* fImageLayouts; // layouts of these images when not color attachment | 114 VkImageLayout* fImageLayouts; // layouts of these images when not color attachment |
110 sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images | 115 sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images |
111 VkCommandPool fCommandPool; | 116 VkCommandPool fCommandPool; |
112 BackbufferInfo* fBackbuffers; | 117 BackbufferInfo* fBackbuffers; |
113 uint32_t fCurrentBackbufferIndex; | 118 uint32_t fCurrentBackbufferIndex; |
114 }; | 119 }; |
115 | 120 |
116 } // namespace sk_app | 121 } // namespace sk_app |
117 | 122 |
118 #endif // SK_VULKAN | 123 #endif // SK_VULKAN |
119 | 124 |
120 #endif | 125 #endif |
OLD | NEW |