Flutter Engine
The Flutter Engine
GrVkSemaphore.cpp
Go to the documentation of this file.
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
9
14
15#ifdef VK_USE_PLATFORM_WIN32_KHR
16// windows wants to define this as CreateSemaphoreA or CreateSemaphoreW
17#undef CreateSemaphore
18#endif
19
20std::unique_ptr<GrVkSemaphore> GrVkSemaphore::Make(GrVkGpu* gpu, bool isOwned) {
21 VkSemaphoreCreateInfo createInfo;
22 memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo));
24 createInfo.pNext = nullptr;
25 createInfo.flags = 0;
26 VkSemaphore semaphore = VK_NULL_HANDLE;
28 GR_VK_CALL_RESULT(gpu, result, CreateSemaphore(gpu->device(), &createInfo, nullptr,
29 &semaphore));
30 if (result != VK_SUCCESS) {
31 return nullptr;
32 }
33
34 return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned));
35}
36
37std::unique_ptr<GrVkSemaphore> GrVkSemaphore::MakeWrapped(GrVkGpu* gpu,
38 VkSemaphore semaphore,
39 GrSemaphoreWrapType wrapType,
40 GrWrapOwnership ownership) {
41 if (VK_NULL_HANDLE == semaphore) {
42 SkDEBUGFAIL("Trying to wrap an invalid VkSemaphore");
43 return nullptr;
44 }
45 bool prohibitSignal = GrSemaphoreWrapType::kWillWait == wrapType;
46 bool prohibitWait = GrSemaphoreWrapType::kWillSignal == wrapType;
47 return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, prohibitSignal,
48 prohibitWait,
49 kBorrow_GrWrapOwnership != ownership));
50}
51
52GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
53 bool prohibitWait, bool isOwned) {
54 fResource = new Resource(gpu, semaphore, prohibitSignal, prohibitWait, isOwned);
55}
56
58 if (fResource) {
59 fResource->unref();
60 }
61}
62
63void GrVkSemaphore::Resource::freeGPUData() const {
64 if (fIsOwned) {
66 DestroySemaphore(fGpu->device(), fSemaphore, nullptr));
67 }
68}
69
71 return GrBackendSemaphores::MakeVk(fResource->semaphore());
72}
GrWrapOwnership
Definition: GrTypesPriv.h:77
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
GrSemaphoreWrapType
Definition: GrTypesPriv.h:146
#define GR_VK_CALL(IFACE, X)
Definition: GrVkUtil.h:24
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition: GrVkUtil.h:35
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
const skgpu::VulkanInterface * vkInterface() const
Definition: GrVkGpu.h:60
VkDevice device() const
Definition: GrVkGpu.h:71
VkSemaphore semaphore() const
Definition: GrVkSemaphore.h:47
~GrVkSemaphore() override
GrBackendSemaphore backendSemaphore() const override
static std::unique_ptr< GrVkSemaphore > Make(GrVkGpu *gpu, bool isOwned)
static std::unique_ptr< GrVkSemaphore > MakeWrapped(GrVkGpu *, VkSemaphore, GrSemaphoreWrapType, GrWrapOwnership)
GAsyncResult * result
SK_API GrBackendSemaphore MakeVk(VkSemaphore semaphore)
VkStructureType sType
Definition: vulkan_core.h:3392
VkSemaphoreCreateFlags flags
Definition: vulkan_core.h:3394
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
@ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
Definition: vulkan_core.h:211