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