ContextObserver removal, part I: Program no longer is context observer 21/20621/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 1 May 2014 19:29:41 +0000 (20:29 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Fri, 9 May 2014 14:00:40 +0000 (15:00 +0100)
[Issue#] N/A
[Problem] too many context observers
[Cause] observer pattern
[Solution] remove observer pattern

Change-Id: Ica8dd62613d689d97b7a9846154a589f7626450d
Signed-off-by: Ferran Sole <ferran.sole@samsung.com>
dali/internal/render/gl-resources/context.cpp
dali/internal/render/gl-resources/context.h
dali/internal/render/shaders/program.cpp
dali/internal/render/shaders/program.h

index 4f8274a..1ba1453 100644 (file)
@@ -133,6 +133,12 @@ void Context::GlContextCreated()
   {
     (*it)->GlContextCreated();
   }
+
+  const ProgramContainer::iterator endp = mProgramCache.end();
+  for ( ProgramContainer::iterator itp = mProgramCache.begin(); itp != endp; ++itp )
+  {
+    (*itp).second->GlContextCreated();
+  }
 }
 
 void Context::GlContextToBeDestroyed()
@@ -146,6 +152,12 @@ void Context::GlContextToBeDestroyed()
     (*it)->GlContextToBeDestroyed();
   }
 
+  const ProgramContainer::iterator endp = mProgramCache.end();
+  for ( ProgramContainer::iterator itp = mProgramCache.begin(); itp != endp; ++itp )
+  {
+    (*itp).second->GlContextDestroyed();
+  }
+
   mGlContextCreated = false;
 }
 
index a151c8c..2517b0c 100644 (file)
@@ -1774,7 +1774,8 @@ private: // Data
   std::set<ContextObserver*> mObservers;
 
   Program* mCurrentProgram;
-  std::map< std::size_t, Program* > mProgramCache; /// program cache
+  typedef std::map< std::size_t, Program* > ProgramContainer;
+  ProgramContainer mProgramCache; /// program cache
 
 };
 
index b1a76cb..3c271bc 100644 (file)
@@ -447,7 +447,7 @@ void Program::GlContextCreated()
   }
 }
 
-void Program::GlContextToBeDestroyed()
+void Program::GlContextDestroyed()
 {
   Unload();
 
@@ -470,14 +470,10 @@ Program::Program(Integration::ShaderData* shaderData, Context& context )
 {
   // reset values
   ResetAttribsUniforms();
-
-  mContext.AddObserver( *this );
 }
 
 Program::~Program()
 {
-  mContext.RemoveObserver( *this );
-
   Unload(); // Resets gCurrentProgram
 }
 
index 11b59a1..e55b80a 100644 (file)
@@ -24,7 +24,6 @@
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/gl-resources/context-observer.h>
 #include <dali/integration-api/resource-cache.h>
 
 namespace Dali
@@ -57,7 +56,7 @@ class Context;
  * uColor is set to the value specified by Actor::SetColor and is
  * animatable through the property Actor::COLOR
  */
-class Program : public ContextObserver
+class Program
 {
 public:
 
@@ -247,17 +246,15 @@ public:
    */
   void SetUniformMatrix3fv( GLint location, GLsizei count, const GLfloat* value );
 
-public: // From ContextObserver
-
   /**
-   * @copydoc ContextObserver::GlContextCreated
+   * Needs to be called when GL context is (re)created
    */
-  virtual void GlContextCreated();          // From ContextObserver
+  void GlContextCreated();
 
   /**
-   * @copydoc ContextObserver::GlContextToBeDestroyed
+   * Needs to be called when GL context is destroyed
    */
-  virtual void GlContextToBeDestroyed();   // From ContextObserver
+  void GlContextDestroyed();
 
 private: // Implementation
 
@@ -271,9 +268,9 @@ private: // Implementation
 public:
 
   /**
-   * Destructor
+   * Destructor, non virtual as no virtual methods or inheritance
    */
-  virtual ~Program();
+  ~Program();
 
 private: