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