[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-fence.cpp
index 74dfa18..772a521 100644 (file)
@@ -26,50 +26,127 @@ namespace Graphics
 namespace Vulkan
 {
 
-Fence::Fence(Graphics& graphics) : mGraphics(graphics), mFence(nullptr)
+/**
+ * Class: Fence::Impl
+ *
+ */
+struct Fence::Impl
 {
-  mFence =
-      VkAssert(mGraphics.GetDevice().createFence(vk::FenceCreateInfo{}, mGraphics.GetAllocator()));
-}
+  Impl( Vulkan::Graphics& graphics )
+  : mGraphics( graphics )
+  {
+  }
 
-Fence::~Fence()
-{
-  if(mFence)
+  ~Impl()
   {
-    mGraphics.GetDevice().destroyFence(mFence, mGraphics.GetAllocator());
+    if( mFence )
+    {
+      mGraphics.GetDevice().destroyFence( mFence, mGraphics.GetAllocator() );
+    }
   }
-}
 
-bool Fence::Wait(uint32_t timeout)
-{
-  if(timeout)
+  vk::Result Initialise()
   {
-    return mGraphics.GetDevice().waitForFences(mFence, true, timeout) == vk::Result::eSuccess;
+    mFence = VkAssert( mGraphics.GetDevice().createFence( vk::FenceCreateInfo{}, mGraphics.GetAllocator() ) );
+    if( mFence )
+      return vk::Result::eSuccess;
+    return vk::Result::eErrorInitializationFailed;
   }
-  else
+
+  /**
+   *
+   * @param timeout
+   * @return
+   */
+  bool Wait( uint32_t timeout = 0u )
   {
-    timeout = 16000000;
-    while(mGraphics.GetDevice().waitForFences(mFence, true, timeout) != vk::Result::eSuccess)
+    if(mFence)
     {
-      // fixme: busy wait, bit ugly
+      if(timeout)
+      {
+        return mGraphics.GetDevice().waitForFences(mFence, true, timeout) == vk::Result::eSuccess;
+      }
+      else
+      {
+        timeout = 16000000;
+        while(mGraphics.GetDevice().waitForFences(mFence, true, timeout) != vk::Result::eSuccess)
+        {
+          // fixme: busy wait, bit ugly
+        }
+        return true;
+      }
     }
-    return true;
+    return false;
   }
-}
 
-void Fence::Reset()
+  /**
+   *
+   */
+  void Reset()
+  {
+    if(mFence)
+    {
+      mGraphics.GetDevice().resetFences(mFence);
+    }
+  }
+
+  vk::Fence GetVkFence() const
+  {
+    return mFence;
+  }
+
+  Vulkan::Graphics& mGraphics;
+  vk::Fence mFence;
+};
+
+/**
+ * Class: Fence
+ *
+ */
+Handle<Fence> Fence::New( Graphics& graphics )
 {
-  if(mFence)
+  auto retval = Handle<Fence>( new Fence(graphics) );
+  if( vk::Result::eSuccess == retval->mImpl->Initialise() )
   {
-    mGraphics.GetDevice().resetFences(mFence);
+    return retval;
   }
+  return Handle<Fence>();
+}
+
+Fence::Fence(Graphics& graphics)
+{
+  mImpl = MakeUnique<Impl>(graphics);
+}
+
+const Fence& Fence::ConstRef() const
+{
+  return *this;
+}
+
+Fence& Fence::Ref()
+{
+  return *this;
+}
+
+Fence::~Fence() = default;
+
+bool Fence::Wait(uint32_t timeout)
+{
+  return mImpl->Wait( timeout );
+}
+
+void Fence::Reset()
+{
+  mImpl->Reset();
 }
 
 vk::Fence Fence::GetFence() const
 {
-  return mFence;
+  return mImpl->GetVkFence();
 }
 
+
+
 } // namespace Vulkan
 } // namespace Graphics
 } // namespace Dali