2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/graphics/vulkan/vulkan-fence.h>
20 #include <dali/graphics/vulkan/vulkan-graphics.h>
35 Impl( Vulkan::Graphics& graphics )
36 : mGraphics( graphics )
44 mGraphics.GetDevice().destroyFence( mFence, mGraphics.GetAllocator() );
48 vk::Result Initialise()
50 mFence = VkAssert( mGraphics.GetDevice().createFence( vk::FenceCreateInfo{}, mGraphics.GetAllocator() ) );
52 return vk::Result::eSuccess;
53 return vk::Result::eErrorInitializationFailed;
61 bool Wait( uint32_t timeout = 0u )
67 return mGraphics.GetDevice().waitForFences(mFence, true, timeout) == vk::Result::eSuccess;
72 while(mGraphics.GetDevice().waitForFences(mFence, true, timeout) != vk::Result::eSuccess)
74 // fixme: busy wait, bit ugly
89 mGraphics.GetDevice().resetFences(mFence);
93 vk::Fence GetVkFence() const
98 Vulkan::Graphics& mGraphics;
106 Handle<Fence> Fence::New( Graphics& graphics )
108 auto retval = Handle<Fence>( new Fence(graphics) );
109 if( vk::Result::eSuccess == retval->mImpl->Initialise() )
113 return Handle<Fence>();
116 Fence::Fence(Graphics& graphics)
118 mImpl = MakeUnique<Impl>(graphics);
121 const Fence& Fence::ConstRef() const
131 Fence::~Fence() = default;
133 bool Fence::Wait(uint32_t timeout)
135 return mImpl->Wait( timeout );
143 vk::Fence Fence::GetFence() const
145 return mImpl->GetVkFence();
150 } // namespace Vulkan
151 } // namespace Graphics