Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/gpu/GrBackendSemaphore.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2017 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 GrBackendSemaphore_DEFINED
9
#define GrBackendSemaphore_DEFINED
10
11
#include "include/gpu/GrTypes.h"
12
13
#include "include/gpu/gl/GrGLTypes.h"
14
#include "include/gpu/mtl/GrMtlTypes.h"
15
#include "include/gpu/vk/GrVkTypes.h"
16
#ifdef SK_DIRECT3D
17
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
18
#endif
19
20
/**
21
 * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
22
 */
23
class GrBackendSemaphore {
24
public:
25
    // For convenience we just set the backend here to OpenGL. The GrBackendSemaphore cannot be used
26
    // until either initGL or initVulkan are called which will set the appropriate GrBackend.
27
    GrBackendSemaphore()
28
0
            : fBackend(GrBackendApi::kOpenGL), fGLSync(nullptr), fIsInitialized(false) {}
29
30
#ifdef SK_DIRECT3D
31
    // We only need to specify these if Direct3D is enabled, because it requires special copy
32
    // characteristics.
33
    ~GrBackendSemaphore();
34
    GrBackendSemaphore(const GrBackendSemaphore&);
35
    GrBackendSemaphore& operator=(const GrBackendSemaphore&);
36
#endif
37
38
0
    void initGL(GrGLsync sync) {
39
0
        fBackend = GrBackendApi::kOpenGL;
40
0
        fGLSync = sync;
41
0
        fIsInitialized = true;
42
0
    }
43
44
0
    void initVulkan(VkSemaphore semaphore) {
45
0
        fBackend = GrBackendApi::kVulkan;
46
0
        fVkSemaphore = semaphore;
47
0
#ifdef SK_VULKAN
48
0
        fIsInitialized = true;
49
0
#else
50
0
        fIsInitialized = false;
51
0
#endif
52
0
    }
53
54
    // It is the creator's responsibility to ref the MTLEvent passed in here, via __bridge_retained.
55
    // The other end will wrap this BackendSemaphore and take the ref, via __bridge_transfer.
56
0
    void initMetal(GrMTLHandle event, uint64_t value) {
57
0
        fBackend = GrBackendApi::kMetal;
58
0
        fMtlEvent = event;
59
0
        fMtlValue = value;
60
0
#ifdef SK_METAL
61
0
        fIsInitialized = true;
62
0
#else
63
0
        fIsInitialized = false;
64
0
#endif
65
0
    }
66
67
#ifdef SK_DIRECT3D
68
    void initDirect3D(const GrD3DFenceInfo& info) {
69
        fBackend = GrBackendApi::kDirect3D;
70
        this->assignD3DFenceInfo(info);
71
        fIsInitialized = true;
72
    }
73
#endif
74
75
0
    bool isInitialized() const { return fIsInitialized; }
76
77
0
    GrGLsync glSync() const {
78
0
        if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) {
79
0
            return nullptr;
80
0
        }
81
0
        return fGLSync;
82
0
    }
83
84
0
    VkSemaphore vkSemaphore() const {
85
0
        if (!fIsInitialized || GrBackendApi::kVulkan != fBackend) {
86
0
            return VK_NULL_HANDLE;
87
0
        }
88
0
        return fVkSemaphore;
89
0
    }
90
91
0
    GrMTLHandle mtlSemaphore() const {
92
0
        if (!fIsInitialized || GrBackendApi::kMetal != fBackend) {
93
0
            return nullptr;
94
0
        }
95
0
        return fMtlEvent;
96
0
    }
97
98
0
    uint64_t mtlValue() const {
99
0
        if (!fIsInitialized || GrBackendApi::kMetal != fBackend) {
100
0
            return 0;
101
0
        }
102
0
        return fMtlValue;
103
0
    }
104
105
#ifdef SK_DIRECT3D
106
    bool getD3DFenceInfo(GrD3DFenceInfo* outInfo) const;
107
#endif
108
109
private:
110
#ifdef SK_DIRECT3D
111
    void assignD3DFenceInfo(const GrD3DFenceInfo& info);
112
#endif
113
114
    GrBackendApi fBackend;
115
    union {
116
        GrGLsync    fGLSync;
117
        VkSemaphore fVkSemaphore;
118
        GrMTLHandle fMtlEvent;    // Expected to be an id<MTLEvent>
119
#ifdef SK_DIRECT3D
120
        GrD3DFenceInfo* fD3DFenceInfo;
121
#endif
122
    };
123
    uint64_t fMtlValue;
124
    bool fIsInitialized;
125
};
126
127
#endif