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