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/VulkanBackendContext.h" 17 #include "include/gpu/vk/VulkanExtensions.h" 18 19 class GrDirectContext; 20 class SkSurface; 21 struct SkISize; 22 23 namespace skiatest { 24 enum class TestType : uint8_t; 25 } 26 27 namespace skgpu::graphite { 28 class Recorder; 29 }; 30 31 #define DECLARE_VK_PROC(name) PFN_vk##name fVk##name 32 33 class VkTestHelper { 34 public: 35 static std::unique_ptr<VkTestHelper> Make(skiatest::TestType, bool isProtected); 36 37 virtual ~VkTestHelper(); 38 39 virtual bool isValid() const = 0; 40 41 virtual sk_sp<SkSurface> createSurface(SkISize, bool textureable, bool isProtected) = 0; 42 virtual void submitAndWaitForCompletion(bool* completionMarker) = 0; 43 directContext()44 virtual GrDirectContext* directContext() { return nullptr; } recorder()45 virtual skgpu::graphite::Recorder* recorder() { return nullptr; } 46 47 protected: VkTestHelper(bool isProtected)48 VkTestHelper(bool isProtected) : fIsProtected(isProtected) {} 49 50 bool setupBackendContext(); 51 virtual bool init() = 0; 52 53 DECLARE_VK_PROC(DestroyInstance); 54 DECLARE_VK_PROC(DeviceWaitIdle); 55 DECLARE_VK_PROC(DestroyDevice); 56 DECLARE_VK_PROC(GetDeviceProcAddr); 57 58 DECLARE_VK_PROC(GetPhysicalDeviceFormatProperties); 59 DECLARE_VK_PROC(GetPhysicalDeviceMemoryProperties); 60 61 DECLARE_VK_PROC(CreateImage); 62 DECLARE_VK_PROC(DestroyImage); 63 DECLARE_VK_PROC(GetImageMemoryRequirements); 64 DECLARE_VK_PROC(AllocateMemory); 65 DECLARE_VK_PROC(FreeMemory); 66 DECLARE_VK_PROC(BindImageMemory); 67 DECLARE_VK_PROC(MapMemory); 68 DECLARE_VK_PROC(UnmapMemory); 69 DECLARE_VK_PROC(FlushMappedMemoryRanges); 70 DECLARE_VK_PROC(GetImageSubresourceLayout); 71 72 bool fIsProtected = false; 73 VkDevice fDevice = VK_NULL_HANDLE; 74 75 skgpu::VulkanExtensions fExtensions; 76 VkPhysicalDeviceFeatures2 fFeatures = {}; 77 VkDebugReportCallbackEXT fDebugCallback = VK_NULL_HANDLE; 78 PFN_vkDestroyDebugReportCallbackEXT fDestroyDebugCallback = nullptr; 79 skgpu::VulkanBackendContext fBackendContext; 80 }; 81 82 #undef DECLARE_VK_PROC 83 84 #endif // SK_VULKAN 85 #endif // VkTestHelper_DEFINED 86