Flutter Engine
The Flutter Engine
GraphiteVulkanWindowContext.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
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 GraphiteVulkanWindowContext_DEFINED
8#define GraphiteVulkanWindowContext_DEFINED
9
11
12#ifdef SK_VULKAN
13
16
17class GrRenderTarget;
18
19namespace skgpu { struct VulkanInterface; }
20
21namespace skwindow::internal {
22
23class GraphiteVulkanWindowContext : public WindowContext {
24public:
25 ~GraphiteVulkanWindowContext() override;
26
27 sk_sp<SkSurface> getBackbufferSurface() override;
28
29 bool isValid() override { return fDevice != VK_NULL_HANDLE; }
30
31 void resize(int w, int h) override {
32 this->createSwapchain(w, h, fDisplayParams);
33 }
34
35 void setDisplayParams(const DisplayParams& params) override {
36 this->destroyContext();
37 fDisplayParams = params;
38 this->initializeContext();
39 }
40
41 /** Platform specific function that creates a VkSurfaceKHR for a window */
42 using CreateVkSurfaceFn = std::function<VkSurfaceKHR(VkInstance)>;
43 /** Platform specific function that determines whether presentation will succeed. */
44 using CanPresentFn = sk_gpu_test::CanPresentFn;
45
46 GraphiteVulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn,
48
49private:
50 void initializeContext();
51 void destroyContext();
52
53 struct BackbufferInfo {
54 uint32_t fImageIndex; // image this is associated with
55 VkSemaphore fRenderSemaphore; // we wait on this for rendering to be done
56 };
57
58 BackbufferInfo* getAvailableBackbuffer();
59 bool createSwapchain(int width, int height, const DisplayParams& params);
61 void destroyBuffers();
62 void onSwapBuffers() override;
63
64 VkInstance fInstance = VK_NULL_HANDLE;
65 VkPhysicalDevice fPhysicalDevice = VK_NULL_HANDLE;
66 VkDevice fDevice = VK_NULL_HANDLE;
67 VkDebugReportCallbackEXT fDebugCallback = VK_NULL_HANDLE;
68
69 // Create functions
70 CreateVkSurfaceFn fCreateVkSurfaceFn;
71 CanPresentFn fCanPresentFn;
72
73 PFN_vkGetInstanceProcAddr fGetInstanceProcAddr = nullptr;
74
75 // WSI interface functions
76 PFN_vkDestroySurfaceKHR fDestroySurfaceKHR = nullptr;
77 PFN_vkGetPhysicalDeviceSurfaceSupportKHR fGetPhysicalDeviceSurfaceSupportKHR = nullptr;
78 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fGetPhysicalDeviceSurfaceCapabilitiesKHR =nullptr;
79 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fGetPhysicalDeviceSurfaceFormatsKHR = nullptr;
80 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fGetPhysicalDeviceSurfacePresentModesKHR =nullptr;
81
82 PFN_vkCreateSwapchainKHR fCreateSwapchainKHR = nullptr;
83 PFN_vkDestroySwapchainKHR fDestroySwapchainKHR = nullptr;
84 PFN_vkGetSwapchainImagesKHR fGetSwapchainImagesKHR = nullptr;
85 PFN_vkAcquireNextImageKHR fAcquireNextImageKHR = nullptr;
86 PFN_vkQueuePresentKHR fQueuePresentKHR = nullptr;
87
88 PFN_vkDestroyInstance fDestroyInstance = nullptr;
89 PFN_vkDeviceWaitIdle fDeviceWaitIdle = nullptr;
90 PFN_vkDestroyDebugReportCallbackEXT fDestroyDebugReportCallbackEXT = nullptr;
91 PFN_vkQueueWaitIdle fQueueWaitIdle = nullptr;
92 PFN_vkDestroyDevice fDestroyDevice = nullptr;
93 PFN_vkGetDeviceQueue fGetDeviceQueue = nullptr;
94
96
97 VkSurfaceKHR fSurface;
98 VkSwapchainKHR fSwapchain;
99 uint32_t fGraphicsQueueIndex;
100 VkQueue fGraphicsQueue;
101 uint32_t fPresentQueueIndex;
102 VkQueue fPresentQueue;
103
104 uint32_t fImageCount;
105 VkImage* fImages; // images in the swapchain
106 VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
107 sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may not be based on rts)
108 BackbufferInfo* fBackbuffers;
109 uint32_t fCurrentBackbufferIndex;
110 VkSemaphore fWaitSemaphore = VK_NULL_HANDLE;
111};
112
113} // namespace skwindow::internal
114
115#endif // SK_VULKAN
116
117#endif // GraphiteVulkanWindowContext_DEFINED
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