Reset the cache in all the contexts while destroying buffers and textures 53/209653/7
authorRichard Huang <r.huang@samsung.com>
Tue, 9 Jul 2019 15:11:04 +0000 (16:11 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 18 Jul 2019 14:27:16 +0000 (15:27 +0100)
Change-Id: I545fb631ad35e057acd61be34a17dda7434537ff

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

index 2eec97a..b5a5011 100644 (file)
@@ -72,7 +72,7 @@ struct RenderManager::Impl
         Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
         Integration::DepthBufferAvailable depthBufferAvailableParam,
         Integration::StencilBufferAvailable stencilBufferAvailableParam )
         Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
         Integration::DepthBufferAvailable depthBufferAvailableParam,
         Integration::StencilBufferAvailable stencilBufferAvailableParam )
-  : context( glAbstraction ),
+  : context( glAbstraction, &surfaceContextContainer ),
     currentContext( &context ),
     glAbstraction( glAbstraction ),
     glSyncAbstraction( glSyncAbstraction ),
     currentContext( &context ),
     glAbstraction( glAbstraction ),
     glSyncAbstraction( glSyncAbstraction ),
index c3116bf..b37c267 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -64,7 +64,12 @@ errorStrings errors[] =
 Debug::Filter* gContextLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT_STATE");
 #endif
 
 Debug::Filter* gContextLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT_STATE");
 #endif
 
-Context::Context(Integration::GlAbstraction& glAbstraction)
+Context::Context( Integration::GlAbstraction& glAbstraction )
+: Context( glAbstraction, nullptr )
+{
+}
+
+Context::Context( Integration::GlAbstraction& glAbstraction, OwnerContainer< Context* >* contexts )
 : mGlAbstraction(glAbstraction),
   mGlContextCreated(false),
   mColorMask(true),
 : mGlAbstraction(glAbstraction),
   mGlContextCreated(false),
   mColorMask(true),
@@ -101,7 +106,8 @@ Context::Context(Integration::GlAbstraction& glAbstraction)
   mMaxTextureSize(0),
   mClearColor(Color::WHITE),    // initial color, never used until it's been set by the user
   mCullFaceMode( FaceCullingMode::NONE ),
   mMaxTextureSize(0),
   mClearColor(Color::WHITE),    // initial color, never used until it's been set by the user
   mCullFaceMode( FaceCullingMode::NONE ),
-  mViewPort( 0, 0, 0, 0 )
+  mViewPort( 0, 0, 0, 0 ),
+  mSurfaceContexts( contexts )
 {
 }
 
 {
 }
 
index 8757774..06f6ba4 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/public-api/math/rect.h>
 #include <dali/public-api/math/vector4.h>
 #include <dali/public-api/rendering/renderer.h>
 #include <dali/public-api/math/rect.h>
 #include <dali/public-api/math/vector4.h>
 #include <dali/public-api/rendering/renderer.h>
+#include <dali/devel-api/common/owner-container.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/gl-abstraction.h>
 #include <dali/integration-api/gl-defines.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/gl-abstraction.h>
 #include <dali/integration-api/gl-defines.h>
@@ -64,7 +65,7 @@ public:
   static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
 
   /**
   static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
 
   /**
-   * Creates the Dali Context object.
+   * Creates the Dali Context object for surface rendering only.
    * This method does not create an OpenGL context i.e. that is done from outside dali-core.
    * @pre Context has not been created.
    * @exception Context already created.
    * This method does not create an OpenGL context i.e. that is done from outside dali-core.
    * @pre Context has not been created.
    * @exception Context already created.
@@ -73,6 +74,16 @@ public:
   Context( Integration::GlAbstraction& glAbstraction );
 
   /**
   Context( Integration::GlAbstraction& glAbstraction );
 
   /**
+   * Creates the Dali Context object for texture (and surface rendering if required).
+   * This method does not create an OpenGL context i.e. that is done from outside dali-core.
+   * @pre Context has not been created.
+   * @exception Context already created.
+   * @param glAbstraction the gl abstraction.
+   * @param contexts The list of surface contexts (for surface rendering)
+   */
+  Context( Integration::GlAbstraction& glAbstraction, OwnerContainer< Context* >* contexts );
+
+  /**
    * Destructor
    */
   ~Context();
    * Destructor
    */
   ~Context();
@@ -122,6 +133,26 @@ public:
     DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
   }
 
     DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
   }
 
+  void ResetBufferCache()
+  {
+    // reset the cached buffer id's
+    // fixes problem where some drivers will a generate a buffer with the
+    // same id, as the last deleted buffer id.
+    mBoundArrayBufferId = 0;
+    mBoundElementArrayBufferId = 0;
+    mBoundTransformFeedbackBufferId = 0;
+  }
+
+  void ResetTextureCache()
+  {
+    // reset the cached texture id's in case the driver re-uses them
+    // when creating new textures
+    for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
+    {
+       mBoundTextureId[ i ] = 0;
+    }
+  }
+
   /****************************************************************************************
    * The following methods are forwarded to Dali::Integration::GlAbstraction.
    * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
   /****************************************************************************************
    * The following methods are forwarded to Dali::Integration::GlAbstraction.
    * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
@@ -606,19 +637,26 @@ public:
    */
   void DeleteBuffers(GLsizei n, const GLuint* buffers)
   {
    */
   void DeleteBuffers(GLsizei n, const GLuint* buffers)
   {
-    // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
-    // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
     if( this->IsGlContextCreated() )
     {
       LOG_GL("DeleteBuffers %d %p\n", n, buffers);
       CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
     }
     if( this->IsGlContextCreated() )
     {
       LOG_GL("DeleteBuffers %d %p\n", n, buffers);
       CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
     }
-    // reset the cached buffer id's
-    // fixes problem where some drivers will a generate a buffer with the
-    // same id, as the last deleted buffer id.
-    mBoundArrayBufferId = 0;
-    mBoundElementArrayBufferId = 0;
-    mBoundTransformFeedbackBufferId = 0;
+
+    ResetBufferCache();
+
+    // Need to reset the buffer cache in the surface contexts
+    // This will only be executed by the surfaceless context when there are contexts for surface rendering
+    if ( mSurfaceContexts )
+    {
+      for ( auto&& context : *mSurfaceContexts )
+      {
+        if ( context )
+        {
+          context->ResetBufferCache();
+        }
+      }
+    }
   }
 
   /**
   }
 
   /**
@@ -658,11 +696,19 @@ public:
     LOG_GL("DeleteTextures %d %p\n", n, textures);
     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
 
     LOG_GL("DeleteTextures %d %p\n", n, textures);
     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
 
-    // reset the cached texture id's incase the driver re-uses them
-    // when creating new textures
-    for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
+    ResetTextureCache();
+
+    // Need to reset the texture cache in the surface contexts
+    // This will only be executed by the surfaceless context when there are contexts for surface rendering
+    if ( mSurfaceContexts )
     {
     {
-       mBoundTextureId[ i ] = 0;
+      for ( auto&& context : *mSurfaceContexts )
+      {
+        if ( context )
+        {
+          context->ResetTextureCache();
+        }
+      }
     }
   }
 
     }
   }
 
@@ -1782,6 +1828,8 @@ private: // Data
   bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ];   ///< Current state on the driver for Enable Vertex Attribute
 
   FrameBufferStateCache mFrameBufferStateCache;   ///< frame buffer state cache
   bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ];   ///< Current state on the driver for Enable Vertex Attribute
 
   FrameBufferStateCache mFrameBufferStateCache;   ///< frame buffer state cache
+
+  OwnerContainer< Context* >* mSurfaceContexts;   ///< The pointer of the container of contexts for surface rendering
 };
 
 } // namespace Internal
 };
 
 } // namespace Internal