Debian Codegraph @

src/gpu/ganesh/vk/GrVkBackendSemaphore.cpp

raw
1 /*
2 * Copyright 2023 Google LLC
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 #include "include/gpu/ganesh/vk/GrVkBackendSemaphore.h"
8
9 #include "include/gpu/ganesh/GrTypes.h"
10 #include "include/private/base/SkAssert.h"
11 #include "include/private/base/SkDebug.h"
12 #include "src/gpu/ganesh/GrBackendSemaphorePriv.h"
13
14 class GrVkBackendSemaphoreData final : public GrBackendSemaphoreData {
15 public:
16 GrVkBackendSemaphoreData(VkSemaphore semaphore) : fSemaphore(semaphore) {}
17
18 VkSemaphore semaphore() const { return fSemaphore; }
19
20 private:
21 void copyTo(AnySemaphoreData& data) const override {
22 data.emplace<GrVkBackendSemaphoreData>(fSemaphore);
23 }
24
25 #if defined(SK_DEBUG)
26 GrBackendApi type() const override { return GrBackendApi::kVulkan; }
27 #endif
28
29 VkSemaphore fSemaphore;
30 };
31
32 static const GrVkBackendSemaphoreData* get_and_cast_data(const GrBackendSemaphore& sem) {
33 auto data = GrBackendSemaphorePriv::GetBackendData(sem);
34 SkASSERT(!data || data->type() == GrBackendApi::kVulkan);
35 return static_cast<const GrVkBackendSemaphoreData*>(data);
36 }
37
38 namespace GrBackendSemaphores {
39 GrBackendSemaphore MakeVk(VkSemaphore semaphore) {
40 GrVkBackendSemaphoreData data(semaphore);
41 return GrBackendSemaphorePriv::MakeGrBackendSemaphore(GrBackendApi::kVulkan, data);
42 }
43
44 VkSemaphore GetVkSemaphore(const GrBackendSemaphore& sem) {
45 SkASSERT(sem.backend() == GrBackendApi::kVulkan);
46 const GrVkBackendSemaphoreData* data = get_and_cast_data(sem);
47 SkASSERT(data);
48 return data->semaphore();
49 }
50 } // namespace GrBackendSemaphores