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
10 #include "GrVkGpu.h"
11 #include "GrVkUtil.h"
12
13 #ifdef VK_USE_PLATFORM_WIN32_KHR
14 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW
15 #undef CreateSemaphore
16 #endif
17
Make(const GrVkGpu * gpu)18 sk_sp<GrVkSemaphore> GrVkSemaphore::Make(const GrVkGpu* gpu) {
19 VkSemaphoreCreateInfo createInfo;
20 memset(&createInfo, 0, sizeof(VkFenceCreateInfo));
21 createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22 createInfo.pNext = nullptr;
23 createInfo.flags = 0;
24 VkSemaphore semaphore = VK_NULL_HANDLE;
25 GR_VK_CALL_ERRCHECK(gpu->vkInterface(),
26 CreateSemaphore(gpu->device(), &createInfo, nullptr, &semaphore));
27
28 return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore));
29 }
30
GrVkSemaphore(const GrVkGpu * gpu,VkSemaphore semaphore)31 GrVkSemaphore::GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore) : INHERITED(gpu) {
32 fResource = new Resource(semaphore);
33 }
34
~GrVkSemaphore()35 GrVkSemaphore::~GrVkSemaphore() {
36 if (fGpu) {
37 fResource->unref(static_cast<const GrVkGpu*>(fGpu));
38 } else {
39 fResource->unrefAndAbandon();
40 }
41 }
42
freeGPUData(const GrVkGpu * gpu) const43 void GrVkSemaphore::Resource::freeGPUData(const GrVkGpu* gpu) const {
44 GR_VK_CALL(gpu->vkInterface(),
45 DestroySemaphore(gpu->device(), fSemaphore, nullptr));
46 }
47
48