Change ownership of Context from Scene to RenderManager 24/239624/1
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 28 Jul 2020 08:01:23 +0000 (17:01 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 28 Jul 2020 08:01:30 +0000 (17:01 +0900)
Change-Id: Idf787e1a582d111e29b92a02a23bd06512c22609

dali/internal/render/common/render-manager.cpp
dali/internal/render/gl-resources/context.cpp
dali/internal/render/gl-resources/context.h
dali/internal/update/common/scene-graph-scene.cpp
dali/internal/update/common/scene-graph-scene.h

index 09aa373..504d6b9 100644 (file)
@@ -150,22 +150,33 @@ struct RenderManager::Impl
 
   Context* CreateSceneContext()
   {
-    sceneContextContainer.push_back( new Context( glAbstraction ) );
-    return sceneContextContainer[ sceneContextContainer.size() - 1 ];
+    Context* context = new Context( glAbstraction );
+
+    //TODO: Need eglMakeCurrent first
+    context->GlContextCreated();
+
+    sceneContextContainer.PushBack( context );
+    return context;
   }
 
   void DestroySceneContext( Context* sceneContext )
   {
-    auto iter = std::find( sceneContextContainer.begin(), sceneContextContainer.end(), sceneContext );
-    if( iter != sceneContextContainer.end() )
+    auto iter = std::find( sceneContextContainer.Begin(), sceneContextContainer.End(), sceneContext );
+    if( iter != sceneContextContainer.End() )
     {
-      sceneContextContainer.erase( iter );
+      ( *iter )->GlContextDestroyed();
+      sceneContextContainer.Erase( iter );
     }
   }
 
   Context* ReplaceSceneContext( Context* oldSceneContext )
   {
     Context* newContext = new Context( glAbstraction );
+
+    oldSceneContext->GlContextDestroyed();
+    //TODO: Need eglMakeCurrent first
+    newContext->GlContextCreated();
+
     std::replace( sceneContextContainer.begin(), sceneContextContainer.end(), oldSceneContext, newContext );
     return newContext;
   }
@@ -182,7 +193,7 @@ struct RenderManager::Impl
   // programs are owned by context at the moment.
   Context                                   context;                 ///< Holds the GL state of the share resource context
   Context*                                  currentContext;          ///< Holds the GL state of the current context for rendering
-  std::vector< Context* >                   sceneContextContainer;   ///< List of owned contexts holding the GL state per scene
+  OwnerContainer< Context* >                sceneContextContainer;   ///< List of owned contexts holding the GL state per scene
   Integration::GlAbstraction&               glAbstraction;           ///< GL abstraction
   Integration::GlSyncAbstraction&           glSyncAbstraction;       ///< GL sync abstraction
   Integration::GlContextHelperAbstraction&  glContextHelperAbstraction; ///< GL context helper abstraction
@@ -285,10 +296,10 @@ void RenderManager::ContextDestroyed()
     renderer->GlContextDestroyed();
   }
 
-  // inform scenes
-  for( auto&& scene : mImpl->sceneContainer )
+  // inform context
+  for( auto&& context : mImpl->sceneContextContainer )
   {
-    scene->GlContextDestroyed();
+    context->GlContextDestroyed();
   }
 }
 
index ead1be3..e045136 100644 (file)
@@ -69,7 +69,7 @@ Context::Context( Integration::GlAbstraction& glAbstraction )
 {
 }
 
-Context::Context( Integration::GlAbstraction& glAbstraction, std::vector< Context* >* contexts )
+Context::Context( Integration::GlAbstraction& glAbstraction, OwnerContainer< Context* >* contexts )
 : mGlAbstraction(glAbstraction),
   mGlContextCreated(false),
   mColorMask(true),
index be2db89..378ee31 100644 (file)
@@ -81,7 +81,7 @@ public:
    * @param glAbstraction the gl abstraction.
    * @param contexts The list of scene contexts (for surface rendering)
    */
-  Context( Integration::GlAbstraction& glAbstraction, std::vector< Context* >* contexts );
+  Context( Integration::GlAbstraction& glAbstraction, OwnerContainer< Context* >* contexts );
 
   /**
    * Destructor
@@ -1829,7 +1829,7 @@ private: // Data
 
   FrameBufferStateCache mFrameBufferStateCache;   ///< frame buffer state cache
 
-  std::vector< Context* >* mSceneContexts;      ///< The pointer of the container of contexts for surface rendering
+  OwnerContainer< Context* >* mSceneContexts;      ///< The pointer of the container of contexts for surface rendering
 };
 
 } // namespace Internal
index 7f9bf31..9b7ddcc 100644 (file)
@@ -17,7 +17,9 @@
 // CLASS HEADER
 #include <dali/internal/update/common/scene-graph-scene.h>
 
+// INTERNAL INCLUDES
 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
+#include <dali/internal/render/gl-resources/context.h>
 
 namespace Dali
 {
@@ -35,39 +37,13 @@ Scene::Scene()
 
 Scene::~Scene()
 {
-  if ( mContext )
-  {
-    mContext->GlContextDestroyed();
-
-    delete mContext;
-    mContext = nullptr;
-  }
-
   mFrameRenderedCallbacks.clear();
   mFramePresentedCallbacks.clear();
 }
 
-void Scene::GlContextDestroyed()
-{
-  if ( mContext )
-  {
-    mContext->GlContextDestroyed();
-  }
-}
-
 void Scene::Initialize( Context& context )
 {
-  if ( mContext != &context )
-  {
-    if ( mContext )
-    {
-      mContext->GlContextDestroyed();
-      delete mContext;
-    }
-
-    mContext = &context;
-    mContext->GlContextCreated();
-  }
+  mContext = &context;
 }
 
 Context* Scene::GetContext()
index a94becc..89d4da1 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/scene.h>
-#include <dali/integration-api/gl-defines.h>
 #include <dali/internal/common/message.h>
 #include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/render/gl-resources/context.h>
 #include <dali/internal/render/common/render-instruction-container.h>
 #include <dali/public-api/common/vector-wrapper.h>
 
@@ -60,11 +58,6 @@ public:
   void Initialize( Context& context );
 
   /**
-   * Called by RenderManager to inform the scene that the context has been destroyed
-   */
-  void GlContextDestroyed();
-
-  /**
    * Gets the context holding the GL state of rendering for the scene
    * @return the context
    */
@@ -124,7 +117,7 @@ public:
 
 private:
 
-  Context*                    mContext;   ///< The context holding the GL state of rendering for the scene
+  Context*                    mContext;   ///< The context holding the GL state of rendering for the scene, not owned
 
   // Render instructions describe what should be rendered during RenderManager::RenderScene()
   // Update manager updates instructions for the next frame while we render the current one