dec482585da1e43d8876b4ac7f0c998ce1d124fc
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-command-pool.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-command-pool.h>
20 #include <dali/graphics/vulkan/vulkan-command-buffer.h>
21 #include <dali/graphics/vulkan/vulkan-graphics.h>
22
23 namespace Dali
24 {
25 namespace Graphics
26 {
27 namespace Vulkan
28 {
29
30 CommandPool::CommandPool(Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo)
31 : mGraphics(graphics)
32 {
33   mPool = VkAssert(graphics.GetDevice().createCommandPool(createInfo, graphics.GetAllocator()));
34 }
35
36 CommandPool::~CommandPool()
37 {
38   if(mPool)
39   {
40     mGraphics.GetDevice().destroyCommandPool(mPool, mGraphics.GetAllocator());
41   }
42 }
43
44 std::unique_ptr< CommandBuffer > CommandPool::AllocateCommandBuffer(
45     const vk::CommandBufferAllocateInfo& info)
46 {
47   auto copyInfo = info;
48   copyInfo.setCommandPool(mPool);
49   return MakeUnique<CommandBuffer>(mGraphics, *this, copyInfo);
50 }
51
52 std::unique_ptr< CommandBuffer > CommandPool::AllocateCommandBuffer(vk::CommandBufferLevel level)
53 {
54   auto info =
55       vk::CommandBufferAllocateInfo{}.setCommandBufferCount(1).setLevel(level).setCommandPool(
56           mPool);
57   return MakeUnique<CommandBuffer>(mGraphics, *this, info);
58 }
59
60 vk::CommandPool CommandPool::GetPool() const
61 {
62   return mPool;
63 }
64
65 } // namespace Vulkan
66 } // namespace Graphics
67 } // namespace Dali
68