| 1 |
/* |
| 2 |
* Copyright 2024 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/core/SkString.h" |
| 8 |
#include "include/gpu/GpuTypes.h" |
| 9 |
#include "include/gpu/graphite/BackendSemaphore.h" |
| 10 |
#include "include/private/gpu/vk/SkiaVulkan.h" |
| 11 |
#include "src/gpu/graphite/BackendSemaphorePriv.h" |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
|
| 15 |
namespace skgpu::graphite { |
| 16 |
|
| 17 |
class VulkanBackendSemaphoreData final : public BackendSemaphoreData { |
| 18 |
public: |
| 19 |
VulkanBackendSemaphoreData(VkSemaphore sem) : fVkSemaphore(sem) {} |
| 20 |
|
| 21 |
#if defined(SK_DEBUG) |
| 22 |
skgpu::BackendApi type() const override { return skgpu::BackendApi::kVulkan; } |
| 23 |
#endif |
| 24 |
|
| 25 |
VkSemaphore semaphore() const { return fVkSemaphore; } |
| 26 |
|
| 27 |
private: |
| 28 |
VkSemaphore fVkSemaphore; |
| 29 |
|
| 30 |
void copyTo(AnyBackendSemaphoreData& dstData) const override { |
| 31 |
// Don't assert that dstData has a Vulkan type() because it could be |
| 32 |
// uninitialized and that assert would fail. |
| 33 |
dstData.emplace<VulkanBackendSemaphoreData>(fVkSemaphore); |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
static const VulkanBackendSemaphoreData* get_and_cast_data(const BackendSemaphore& sem) { |
| 38 |
auto data = BackendSemaphorePriv::GetData(sem); |
| 39 |
SkASSERT(!data || data->type() == skgpu::BackendApi::kVulkan); |
| 40 |
return static_cast<const VulkanBackendSemaphoreData*>(data); |
| 41 |
} |
| 42 |
|
| 43 |
namespace BackendSemaphores { |
| 44 |
BackendSemaphore MakeVulkan(VkSemaphore sem) { |
| 45 |
return BackendSemaphorePriv::Make(skgpu::BackendApi::kVulkan, VulkanBackendSemaphoreData(sem)); |
| 46 |
} |
| 47 |
|
| 48 |
VkSemaphore GetVkSemaphore(const BackendSemaphore& sem) { |
| 49 |
if (!sem.isValid() || sem.backend() != skgpu::BackendApi::kVulkan) { |
| 50 |
return VK_NULL_HANDLE; |
| 51 |
} |
| 52 |
const VulkanBackendSemaphoreData* vkData = get_and_cast_data(sem); |
| 53 |
SkASSERT(vkData); |
| 54 |
return vkData->semaphore(); |
| 55 |
} |
| 56 |
|
| 57 |
} // namespace BackendSemaphores |
| 58 |
|
| 59 |
} // namespace skgpu::graphite |