Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 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 | #include "GrVkSemaphore.h" |
| 9 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame^] | 10 | #include "GrBackendSemaphore.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 11 | #include "GrVkGpu.h" |
| 12 | #include "GrVkUtil.h" |
| 13 | |
| 14 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 15 | // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
| 16 | #undef CreateSemaphore |
| 17 | #endif |
| 18 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame^] | 19 | sk_sp<GrVkSemaphore> GrVkSemaphore::Make(const GrVkGpu* gpu, bool isOwned) { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 20 | VkSemaphoreCreateInfo createInfo; |
| 21 | memset(&createInfo, 0, sizeof(VkFenceCreateInfo)); |
| 22 | createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 23 | createInfo.pNext = nullptr; |
| 24 | createInfo.flags = 0; |
| 25 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 26 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), |
| 27 | CreateSemaphore(gpu->device(), &createInfo, nullptr, &semaphore)); |
| 28 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame^] | 29 | return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, isOwned)); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame^] | 32 | sk_sp<GrVkSemaphore> GrVkSemaphore::MakeWrapped(const GrVkGpu* gpu, |
| 33 | VkSemaphore semaphore, |
| 34 | GrWrapOwnership ownership) { |
| 35 | if (VK_NULL_HANDLE == semaphore) { |
| 36 | return nullptr; |
| 37 | } |
| 38 | return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, |
| 39 | kBorrow_GrWrapOwnership != ownership)); |
| 40 | } |
| 41 | |
| 42 | GrVkSemaphore::GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore, bool isOwned) |
| 43 | : INHERITED(gpu) { |
| 44 | fResource = new Resource(semaphore, isOwned); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | GrVkSemaphore::~GrVkSemaphore() { |
| 48 | if (fGpu) { |
| 49 | fResource->unref(static_cast<const GrVkGpu*>(fGpu)); |
| 50 | } else { |
| 51 | fResource->unrefAndAbandon(); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void GrVkSemaphore::Resource::freeGPUData(const GrVkGpu* gpu) const { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame^] | 56 | if (fIsOwned) { |
| 57 | GR_VK_CALL(gpu->vkInterface(), |
| 58 | DestroySemaphore(gpu->device(), fSemaphore, nullptr)); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void GrVkSemaphore::setBackendSemaphore(GrBackendSemaphore* backendSemaphore) const { |
| 63 | backendSemaphore->initVulkan(fResource->semaphore()); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 64 | } |
| 65 | |