• 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 
19 SkMutex GrVkSemaphore::Resource::gMutex;
20 
Make(const GrVkGpu * gpu,bool isOwned)21 sk_sp<GrVkSemaphore> GrVkSemaphore::Make(const GrVkGpu* gpu, bool isOwned) {
22     VkSemaphoreCreateInfo createInfo;
23     memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo));
24     createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
25     createInfo.pNext = nullptr;
26     createInfo.flags = 0;
27     VkSemaphore semaphore = VK_NULL_HANDLE;
28     GR_VK_CALL_ERRCHECK(gpu->vkInterface(),
29                         CreateSemaphore(gpu->device(), &createInfo, nullptr, &semaphore));
30 
31     return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned));
32 }
33 
MakeWrapped(const GrVkGpu * gpu,VkSemaphore semaphore,WrapType wrapType,GrWrapOwnership ownership)34 sk_sp<GrVkSemaphore> GrVkSemaphore::MakeWrapped(const GrVkGpu* gpu,
35                                                 VkSemaphore semaphore,
36                                                 WrapType wrapType,
37                                                 GrWrapOwnership ownership) {
38     if (VK_NULL_HANDLE == semaphore) {
39         return nullptr;
40     }
41     bool prohibitSignal = WrapType::kWillWait == wrapType;
42     bool prohibitWait = WrapType::kWillSignal == wrapType;
43     return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, prohibitSignal, prohibitWait,
44                                                   kBorrow_GrWrapOwnership != ownership));
45 }
46 
GrVkSemaphore(const GrVkGpu * gpu,VkSemaphore semaphore,bool prohibitSignal,bool prohibitWait,bool isOwned)47 GrVkSemaphore::GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
48                              bool prohibitWait, bool isOwned)
49         : INHERITED(gpu) {
50     fResource = new Resource(semaphore, prohibitSignal, prohibitWait, isOwned);
51 }
52 
~GrVkSemaphore()53 GrVkSemaphore::~GrVkSemaphore() {
54     if (fGpu) {
55         fResource->unref(static_cast<const GrVkGpu*>(fGpu));
56     } else {
57         fResource->unrefAndAbandon();
58     }
59 }
60 
freeGPUData(const GrVkGpu * gpu) const61 void GrVkSemaphore::Resource::freeGPUData(const GrVkGpu* gpu) const {
62     if (fIsOwned) {
63         GR_VK_CALL(gpu->vkInterface(),
64                    DestroySemaphore(gpu->device(), fSemaphore, nullptr));
65     }
66 }
67 
setBackendSemaphore(GrBackendSemaphore * backendSemaphore) const68 void GrVkSemaphore::setBackendSemaphore(GrBackendSemaphore* backendSemaphore) const {
69     backendSemaphore->initVulkan(fResource->semaphore());
70 }
71 
72