Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VkTestContext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
9
10#ifdef SK_VULKAN
11
16
17extern bool gCreateProtectedContext;
18
19namespace {
20
21class VkTestContextImpl : public sk_gpu_test::VkTestContext {
22public:
23 static VkTestContext* Create(VkTestContext* sharedContext) {
24 GrVkBackendContext backendContext;
27 bool ownsContext = true;
28 VkDebugReportCallbackEXT debugCallback = VK_NULL_HANDLE;
29 PFN_vkDestroyDebugReportCallbackEXT destroyCallback = nullptr;
30 if (sharedContext) {
31 backendContext = sharedContext->getVkBackendContext();
32 extensions = const_cast<skgpu::VulkanExtensions*>(sharedContext->getVkExtensions());
33 features = const_cast<VkPhysicalDeviceFeatures2*>(sharedContext->getVkFeatures());
34 // We always delete the parent context last so make sure the child does not think they
35 // own the vulkan context.
36 ownsContext = false;
37 } else {
39 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
40 return nullptr;
41 }
42
44 features = new VkPhysicalDeviceFeatures2;
45 memset(features, 0, sizeof(VkPhysicalDeviceFeatures2));
46 if (!sk_gpu_test::CreateVkBackendContext(instProc, &backendContext, extensions,
47 features, &debugCallback,
48 nullptr, sk_gpu_test::CanPresentFn(),
50 sk_gpu_test::FreeVulkanFeaturesStructs(features);
51 delete features;
52 delete extensions;
53 return nullptr;
54 }
55 if (debugCallback != VK_NULL_HANDLE) {
56 destroyCallback = (PFN_vkDestroyDebugReportCallbackEXT) instProc(
57 backendContext.fInstance, "vkDestroyDebugReportCallbackEXT");
58 }
59 }
60 return new VkTestContextImpl(backendContext, extensions, features, ownsContext,
61 debugCallback, destroyCallback);
62 }
63
64 ~VkTestContextImpl() override { this->teardown(); }
65
66 void testAbandon() override {}
67
68 sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override {
70 }
71
72protected:
73#define ACQUIRE_VK_PROC_LOCAL(name, inst) \
74 PFN_vk##name grVk##name = \
75 reinterpret_cast<PFN_vk##name>(fVk.fGetProc("vk" #name, inst, nullptr)); \
76 do { \
77 if (grVk##name == nullptr) { \
78 SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
79 return; \
80 } \
81 } while (0)
82
83 void teardown() override {
84 INHERITED::teardown();
85 fVk.fMemoryAllocator.reset();
86 if (fOwnsContext) {
87 ACQUIRE_VK_PROC_LOCAL(DeviceWaitIdle, fVk.fInstance);
88 ACQUIRE_VK_PROC_LOCAL(DestroyDevice, fVk.fInstance);
89 ACQUIRE_VK_PROC_LOCAL(DestroyInstance, fVk.fInstance);
90 grVkDeviceWaitIdle(fVk.fDevice);
91 grVkDestroyDevice(fVk.fDevice, nullptr);
92#ifdef SK_ENABLE_VK_LAYERS
93 if (fDebugCallback != VK_NULL_HANDLE) {
94 fDestroyDebugReportCallbackEXT(fVk.fInstance, fDebugCallback, nullptr);
95 }
96#endif
97 grVkDestroyInstance(fVk.fInstance, nullptr);
98 delete fExtensions;
99
100 sk_gpu_test::FreeVulkanFeaturesStructs(fFeatures);
101 delete fFeatures;
102 }
103 }
104
105private:
106 VkTestContextImpl(const GrVkBackendContext& backendContext,
107 const skgpu::VulkanExtensions* extensions,
109 bool ownsContext,
110 VkDebugReportCallbackEXT debugCallback,
112 : VkTestContext(backendContext, extensions, features, ownsContext, debugCallback,
113 destroyCallback) {
114 fFenceSupport = true;
115 }
116
117 void onPlatformMakeNotCurrent() const override {}
118 void onPlatformMakeCurrent() const override {}
119 std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
120
121 using INHERITED = sk_gpu_test::VkTestContext;
122};
123} // anonymous namespace
124
125namespace sk_gpu_test {
126VkTestContext* CreatePlatformVkTestContext(VkTestContext* sharedContext) {
127 return VkTestContextImpl::Create(sharedContext);
128}
129} // namespace sk_gpu_test
130
131#endif
const char * options
bool gCreateProtectedContext
#define ACQUIRE_VK_PROC_LOCAL(name, inst)
static sk_sp< Effect > Create()
#define INHERITED(method,...)
SK_API sk_sp< GrDirectContext > MakeVulkan(const GrVkBackendContext &, const GrContextOptions &)
void(VKAPI_PTR * PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks *pAllocator)
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)