Refactored the Vulkan::CommandPool class
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-fence.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // INTERNAL INCLUDES
19 #include <dali/graphics/vulkan/vulkan-fence.h>
20 #include <dali/graphics/vulkan/vulkan-graphics.h>
21
22 namespace Dali
23 {
24 namespace Graphics
25 {
26 namespace Vulkan
27 {
28
29 /**
30  * Class: Fence
31  *
32  */
33 RefCountedFence Fence::New( Graphics& graphics )
34 {
35   return Handle<Fence>( new Fence(graphics) );
36 }
37
38 Fence::Fence( Graphics& graphics ) : mGraphics(&graphics)
39 {
40 }
41
42 const Fence& Fence::ConstRef() const
43 {
44   return *this;
45 }
46
47 Fence& Fence::Ref()
48 {
49   return *this;
50 }
51
52 Fence::~Fence() = default;
53
54 vk::Fence Fence::GetVkHandle() const
55 {
56   return mFence;
57 }
58
59 Fence::operator vk::Fence*()
60 {
61   return &mFence;
62 }
63
64 bool Fence::OnDestroy()
65 {
66   // Copy the Vulkan handles and pointers here.
67   // Cannot capture the "this" pointer in the lambda.
68   // When the lambda is invoked "this" is already destroyed.
69   // This method is only deferring execution to the end of the frame.
70   auto device = mGraphics->GetDevice();
71   auto fence = mFence;
72   auto allocator = &mGraphics->GetAllocator();
73
74   // capture copies of the pointers and handles
75   mGraphics->DiscardResource( [device, fence, allocator]() {
76     device.destroyFence( fence, allocator );
77   } );
78
79   return false;
80 }
81
82
83 } // namespace Vulkan
84 } // namespace Graphics
85 } // namespace Dali