Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / common / discard-queue.cpp
index a4ce6ee..2131cbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/internal/common/message.h>
 #include <dali/internal/update/nodes/node.h>
 #include <dali/internal/render/queue/render-queue.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
-#include <dali/internal/render/shaders/shader.h>
-#include <dali/internal/update/modeling/scene-graph-mesh.h>
+#include <dali/internal/render/renderers/render-renderer.h>
+#include <dali/internal/render/shaders/scene-graph-shader.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
+#include <dali/internal/update/common/scene-graph-scene.h>
 
 namespace Dali
 {
@@ -37,30 +37,17 @@ namespace Internal
 namespace SceneGraph
 {
 
-namespace // unnamed namespace
-{
-
-static void DoGlCleanup( BufferIndex updateBufferIndex, GlResourceOwner& owner, RenderQueue& renderQueue )
-{
-  typedef Message< GlResourceOwner > DerivedType;
-
-  // Reserve some memory inside the render queue
-  unsigned int* slot = renderQueue.ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
-
-  // Construct message in the render queue memory; note that delete should not be called on the return value
-  new (slot) DerivedType( &owner, &GlResourceOwner::GlCleanup );
-}
-
-} // unnamed namespace
-
 DiscardQueue::DiscardQueue( RenderQueue& renderQueue )
-: mRenderQueue( renderQueue )
+: mRenderQueue( renderQueue ),
+  mNodeQueue(),
+  mShaderQueue(),
+  mRendererQueue(),
+  mCameraQueue(),
+  mSceneQueue()
 {
 }
 
-DiscardQueue::~DiscardQueue()
-{
-}
+DiscardQueue::~DiscardQueue() = default;
 
 void DiscardQueue::Add( BufferIndex updateBufferIndex, Node* node )
 {
@@ -69,92 +56,53 @@ void DiscardQueue::Add( BufferIndex updateBufferIndex, Node* node )
   // The GL resources will now be freed in frame N
   // The Update for frame N+1 may occur in parallel with the rendering of frame N
   // Queue the node for destruction in frame N+2
-  if ( 0u == updateBufferIndex )
-  {
-    mNodeQueue0.PushBack( node );
-  }
-  else
-  {
-    mNodeQueue1.PushBack( node );
-  }
+  mNodeQueue[ updateBufferIndex ].PushBack( node );
 }
 
-void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
 {
-  DALI_ASSERT_DEBUG( NULL != attachment );
+  DALI_ASSERT_DEBUG( NULL != shader );
+
+  // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
 
-  // The GL resources will now be freed in Render frame N
+  // The GL resources will now be freed in frame N
   // The Update for frame N+1 may occur in parallel with the rendering of frame N
-  // Queue the attachment for destruction in Update frame N+2
-  if ( 0u == updateBufferIndex )
-  {
-    mAttachmentQueue0.PushBack( attachment );
-  }
-  else
-  {
-    mAttachmentQueue1.PushBack( attachment );
-  }
+  // Queue the node for destruction in frame N+2
+  mShaderQueue[ updateBufferIndex ].PushBack( shader );
 }
 
-void DiscardQueue::Add( BufferIndex updateBufferIndex, Mesh* mesh )
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Renderer* renderer )
 {
-  DALI_ASSERT_DEBUG( mesh );
-
-  // Send message to clean-up GL resources in the next Render
-  DoGlCleanup( updateBufferIndex, *mesh, mRenderQueue );
+  DALI_ASSERT_DEBUG( NULL != renderer );
 
   // The GL resources will now be freed in frame N
   // The Update for frame N+1 may occur in parallel with the rendering of frame N
   // Queue the node for destruction in frame N+2
-  if ( 0u == updateBufferIndex )
-  {
-    mMeshQueue0.PushBack( mesh );
-  }
-  else
-  {
-    mMeshQueue1.PushBack( mesh );
-  }
+  mRendererQueue[ updateBufferIndex ].PushBack( renderer );
 }
 
-void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Camera* camera )
 {
-  DALI_ASSERT_DEBUG( NULL != shader );
+  DALI_ASSERT_DEBUG( NULL != camera );
 
-  // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
+  mCameraQueue[ updateBufferIndex ].PushBack( camera );
+}
 
-  // The GL resources will now be freed in frame N
-  // The Update for frame N+1 may occur in parallel with the rendering of frame N
-  // Queue the node for destruction in frame N+2
-  if ( 0u == updateBufferIndex )
-  {
-    mShaderQueue0.PushBack( shader );
-  }
-  else
-  {
-    mShaderQueue1.PushBack( shader );
-  }
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Scene* scene )
+{
+  DALI_ASSERT_DEBUG( NULL != scene );
+
+  mSceneQueue[ updateBufferIndex ].PushBack( scene );
 }
 
 void DiscardQueue::Clear( BufferIndex updateBufferIndex )
 {
   // Destroy some discarded objects; these should no longer own any GL resources
-
-  if ( 0u == updateBufferIndex )
-  {
-    mNodeQueue0.Clear();
-    mAttachmentQueue0.Clear();
-    mResourceQueue0.clear();
-    mMeshQueue0.Clear();
-    mShaderQueue0.Clear();
-  }
-  else
-  {
-    mNodeQueue1.Clear();
-    mAttachmentQueue1.Clear();
-    mResourceQueue1.clear();
-    mMeshQueue1.Clear();
-    mShaderQueue1.Clear();
-  }
+  mNodeQueue[ updateBufferIndex ].Clear();
+  mShaderQueue[ updateBufferIndex ].Clear();
+  mRendererQueue[ updateBufferIndex ].Clear();
+  mCameraQueue[ updateBufferIndex ].Clear();
+  mSceneQueue[ updateBufferIndex ].Clear();
 }
 
 } // namespace SceneGraph