Flutter Engine
The Flutter Engine
VulkanWindowContext.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef VulkanWindowContext_DEFINED
8#define VulkanWindowContext_DEFINED
9
11
12#ifdef SK_VULKAN
13
17
18class GrRenderTarget;
19
20namespace skgpu { struct VulkanInterface; }
21
22namespace skwindow::internal {
23
24class VulkanWindowContext : public WindowContext {
25public:
26 ~VulkanWindowContext() override;
27
28 sk_sp<SkSurface> getBackbufferSurface() override;
29
30 bool isValid() override { return fDevice != VK_NULL_HANDLE; }
31
32 void resize(int w, int h) override {
33 this->createSwapchain(w, h, fDisplayParams);
34 }
35
36 void setDisplayParams(const DisplayParams& params) override {
37 this->destroyContext();
38 fDisplayParams = params;
39 this->initializeContext();
40 }
41
42 /** Platform specific function that creates a VkSurfaceKHR for a window */
43 using CreateVkSurfaceFn = std::function<VkSurfaceKHR(VkInstance)>;
44 /** Platform specific function that determines whether presentation will succeed. */
45 using CanPresentFn = sk_gpu_test::CanPresentFn;
46
47 VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn,
49
50private:
51 void initializeContext();
52 void destroyContext();
53
54 struct BackbufferInfo {
55 uint32_t fImageIndex; // image this is associated with
56 VkSemaphore fRenderSemaphore; // we wait on this for rendering to be done
57 };
58
59 BackbufferInfo* getAvailableBackbuffer();
60 bool createSwapchain(int width, int height, const DisplayParams& params);
62 void destroyBuffers();
63 void onSwapBuffers() override;
64
65 VkInstance fInstance = VK_NULL_HANDLE;
66 VkPhysicalDevice fPhysicalDevice = VK_NULL_HANDLE;
67 VkDevice fDevice = VK_NULL_HANDLE;
68 VkDebugReportCallbackEXT fDebugCallback = VK_NULL_HANDLE;
69
70 // Create functions
71 CreateVkSurfaceFn fCreateVkSurfaceFn;
72 CanPresentFn fCanPresentFn;
73
74 PFN_vkGetInstanceProcAddr fGetInstanceProcAddr = nullptr;
75
76 // WSI interface functions
77 PFN_vkDestroySurfaceKHR fDestroySurfaceKHR = nullptr;
78 PFN_vkGetPhysicalDeviceSurfaceSupportKHR fGetPhysicalDeviceSurfaceSupportKHR = nullptr;
79 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fGetPhysicalDeviceSurfaceCapabilitiesKHR =nullptr;
80 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fGetPhysicalDeviceSurfaceFormatsKHR = nullptr;
81 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fGetPhysicalDeviceSurfacePresentModesKHR =nullptr;
82
83 PFN_vkCreateSwapchainKHR fCreateSwapchainKHR = nullptr;
84 PFN_vkDestroySwapchainKHR fDestroySwapchainKHR = nullptr;
85 PFN_vkGetSwapchainImagesKHR fGetSwapchainImagesKHR = nullptr;
86 PFN_vkAcquireNextImageKHR fAcquireNextImageKHR = nullptr;
87 PFN_vkQueuePresentKHR fQueuePresentKHR = nullptr;
88
89 PFN_vkDestroyInstance fDestroyInstance = nullptr;
90 PFN_vkDeviceWaitIdle fDeviceWaitIdle = nullptr;
91 PFN_vkDestroyDebugReportCallbackEXT fDestroyDebugReportCallbackEXT = nullptr;
92 PFN_vkQueueWaitIdle fQueueWaitIdle = nullptr;
93 PFN_vkDestroyDevice fDestroyDevice = nullptr;
94 PFN_vkGetDeviceQueue fGetDeviceQueue = nullptr;
95
97
98 VkSurfaceKHR fSurface;
99 VkSwapchainKHR fSwapchain;
100 uint32_t fGraphicsQueueIndex;
101 VkQueue fGraphicsQueue;
102 uint32_t fPresentQueueIndex;
103 VkQueue fPresentQueue;
104
105 uint32_t fImageCount;
106 VkImage* fImages; // images in the swapchain
107 VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
108 sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may not be based on rts)
109 BackbufferInfo* fBackbuffers;
110 uint32_t fCurrentBackbufferIndex;
111};
112
113} // namespace skwindow::internal
114
115#endif // SK_VULKAN
116
117#endif
SkColorType
Definition: SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
const EmbeddedViewParams * params
uint32_t uint32_t * format
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: GpuTools.h:21
SkScalar w
SkScalar h
int32_t height
int32_t width
void(VKAPI_PTR * PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks *pAllocator)
VkResult(VKAPI_PTR * PFN_vkGetSwapchainImagesKHR)(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages)
Definition: vulkan_core.h:7804
VkImageLayout
Definition: vulkan_core.h:1330
VkSharingMode
Definition: vulkan_core.h:1812
void(VKAPI_PTR * PFN_vkGetDeviceQueue)(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue)
Definition: vulkan_core.h:3997
VkFlags VkImageUsageFlags
Definition: vulkan_core.h:2382
void(VKAPI_PTR * PFN_vkDestroyInstance)(VkInstance instance, const VkAllocationCallbacks *pAllocator)
Definition: vulkan_core.h:3981
VkResult(VKAPI_PTR * PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
Definition: vulkan_core.h:7668
void(VKAPI_PTR * PFN_vkDestroySurfaceKHR)(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator)
Definition: vulkan_core.h:7666
VkResult(VKAPI_PTR * PFN_vkQueueWaitIdle)(VkQueue queue)
Definition: vulkan_core.h:3999
VkResult(VKAPI_PTR * PFN_vkGetPhysicalDeviceSurfaceSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32 *pSupported)
Definition: vulkan_core.h:7667
void(VKAPI_PTR * PFN_vkDestroyDevice)(VkDevice device, const VkAllocationCallbacks *pAllocator)
Definition: vulkan_core.h:3992
VkResult(VKAPI_PTR * PFN_vkCreateSwapchainKHR)(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
Definition: vulkan_core.h:7802
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
VkFormat
Definition: vulkan_core.h:1458
VkResult(VKAPI_PTR * PFN_vkQueuePresentKHR)(VkQueue queue, const VkPresentInfoKHR *pPresentInfo)
Definition: vulkan_core.h:7806
VkResult(VKAPI_PTR * PFN_vkDeviceWaitIdle)(VkDevice device)
Definition: vulkan_core.h:4000
VkResult(VKAPI_PTR * PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats)
Definition: vulkan_core.h:7669
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:3989
VkResult(VKAPI_PTR * PFN_vkAcquireNextImageKHR)(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex)
Definition: vulkan_core.h:7805
VkResult(VKAPI_PTR * PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes)
Definition: vulkan_core.h:7670
void(VKAPI_PTR * PFN_vkDestroySwapchainKHR)(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator)
Definition: vulkan_core.h:7803