• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrBackendSemaphore.h"
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 
Make(const GrVkGpu * gpu,bool isOwned)19 sk_sp<GrVkSemaphore> GrVkSemaphore::Make(const GrVkGpu* gpu, bool isOwned) {
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 
29     return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, isOwned));
30 }
31 
MakeWrapped(const GrVkGpu * gpu,VkSemaphore semaphore,GrWrapOwnership ownership)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 
GrVkSemaphore(const GrVkGpu * gpu,VkSemaphore semaphore,bool isOwned)42 GrVkSemaphore::GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore, bool isOwned)
43         : INHERITED(gpu) {
44     fResource = new Resource(semaphore, isOwned);
45 }
46 
~GrVkSemaphore()47 GrVkSemaphore::~GrVkSemaphore() {
48     if (fGpu) {
49         fResource->unref(static_cast<const GrVkGpu*>(fGpu));
50     } else {
51         fResource->unrefAndAbandon();
52     }
53 }
54 
freeGPUData(const GrVkGpu * gpu) const55 void GrVkSemaphore::Resource::freeGPUData(const GrVkGpu* gpu) const {
56     if (fIsOwned) {
57         GR_VK_CALL(gpu->vkInterface(),
58                    DestroySemaphore(gpu->device(), fSemaphore, nullptr));
59     }
60 }
61 
setBackendSemaphore(GrBackendSemaphore * backendSemaphore) const62 void GrVkSemaphore::setBackendSemaphore(GrBackendSemaphore* backendSemaphore) const {
63     backendSemaphore->initVulkan(fResource->semaphore());
64 }
65 
66