xref: /aosp_15_r20/external/skia/src/gpu/ganesh/vk/GrVkBackendSemaphore.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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:
GrVkBackendSemaphoreData(VkSemaphore semaphore)16     GrVkBackendSemaphoreData(VkSemaphore semaphore) : fSemaphore(semaphore) {}
17 
semaphore() const18     VkSemaphore semaphore() const { return fSemaphore; }
19 
20 private:
copyTo(AnySemaphoreData & data) const21     void copyTo(AnySemaphoreData& data) const override {
22         data.emplace<GrVkBackendSemaphoreData>(fSemaphore);
23     }
24 
25 #if defined(SK_DEBUG)
type() const26     GrBackendApi type() const override { return GrBackendApi::kVulkan; }
27 #endif
28 
29     VkSemaphore fSemaphore;
30 };
31 
get_and_cast_data(const GrBackendSemaphore & sem)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 {
MakeVk(VkSemaphore semaphore)39 GrBackendSemaphore MakeVk(VkSemaphore semaphore) {
40     GrVkBackendSemaphoreData data(semaphore);
41     return GrBackendSemaphorePriv::MakeGrBackendSemaphore(GrBackendApi::kVulkan, data);
42 }
43 
GetVkSemaphore(const GrBackendSemaphore & sem)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
51