1 /* 2 * Copyright 2020 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 8 #ifndef VkTestHelper_DEFINED 9 #define VkTestHelper_DEFINED 10 11 #include "include/core/SkTypes.h" 12 13 #ifdef SK_VULKAN 14 15 #include "include/core/SkRefCnt.h" 16 #include "include/gpu/vk/GrVkBackendContext.h" 17 #include "include/gpu/vk/GrVkExtensions.h" 18 19 class GrDirectContext; 20 class SkSurface; 21 22 #define DECLARE_VK_PROC(name) PFN_vk##name fVk##name 23 24 class VkTestHelper { 25 public: VkTestHelper(bool isProtected)26 VkTestHelper(bool isProtected) : fIsProtected(isProtected) {} 27 ~VkTestHelper()28 ~VkTestHelper() { 29 this->cleanup(); 30 } 31 32 bool init(); 33 directContext()34 GrDirectContext* directContext() { return fDirectContext.get(); } 35 36 private: 37 void cleanup(); 38 39 DECLARE_VK_PROC(DestroyInstance); 40 DECLARE_VK_PROC(DeviceWaitIdle); 41 DECLARE_VK_PROC(DestroyDevice); 42 DECLARE_VK_PROC(GetDeviceProcAddr); 43 44 DECLARE_VK_PROC(GetPhysicalDeviceFormatProperties); 45 DECLARE_VK_PROC(GetPhysicalDeviceMemoryProperties); 46 47 DECLARE_VK_PROC(CreateImage); 48 DECLARE_VK_PROC(DestroyImage); 49 DECLARE_VK_PROC(GetImageMemoryRequirements); 50 DECLARE_VK_PROC(AllocateMemory); 51 DECLARE_VK_PROC(FreeMemory); 52 DECLARE_VK_PROC(BindImageMemory); 53 DECLARE_VK_PROC(MapMemory); 54 DECLARE_VK_PROC(UnmapMemory); 55 DECLARE_VK_PROC(FlushMappedMemoryRanges); 56 DECLARE_VK_PROC(GetImageSubresourceLayout); 57 58 bool fIsProtected = false; 59 VkDevice fDevice = VK_NULL_HANDLE; 60 61 GrVkExtensions fExtensions; 62 VkPhysicalDeviceFeatures2 fFeatures = {}; 63 VkDebugReportCallbackEXT fDebugCallback = VK_NULL_HANDLE; 64 PFN_vkDestroyDebugReportCallbackEXT fDestroyDebugCallback = nullptr; 65 GrVkBackendContext fBackendContext; 66 sk_sp<GrDirectContext> fDirectContext; 67 }; 68 69 #undef DECLARE_VK_PROC 70 71 #endif // SK_VULKAN 72 #endif // VkTestHelper_DEFINED 73