Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-texture-set.h
index d1a94de..6a37f2b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
  */
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/rendering/texture-set.h>
+#include <dali/public-api/rendering/texture-set.h>
 #include <dali/internal/common/buffer-index.h>
+#include <dali/internal/common/message.h>
 #include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/common/animatable-property.h>
-#include <dali/internal/update/common/property-owner.h>
-#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
-#include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/update/resources/resource-manager-declarations.h>
 
 namespace Dali
 {
 namespace Internal
 {
-class ResourceManager;
 
 namespace Render
 {
-class Sampler;
+struct Sampler;
+class Texture;
 }
 namespace SceneGraph
 {
-class Sampler;
-class Shader;
-class ConnectionObserver;
-class SceneController;
+class Renderer;
 
-class TextureSet : public PropertyOwner, public UniformMap::Observer
+class TextureSet
 {
 public:
 
@@ -54,9 +47,9 @@ public:
   static TextureSet* New();
 
   /**
-   * Destructor
+   * Destructor. Not virtual as not a base class and not inheriting anything
    */
-  virtual ~TextureSet();
+  ~TextureSet();
 
   /**
    * Overriden delete operator
@@ -65,24 +58,18 @@ public:
   void operator delete( void* ptr );
 
   /**
-   * Prepare the texture set, check texture loading status, opacity etc
-   * @param resourceManager for checking texture details and loading status
-   */
-  void Prepare( const ResourceManager& resourceManager );
-
-  /**
-   * Set the resource id for the texture at position "index"
+   * Set the sampler to be used by the texture at position "index"
    * @param[in] index The index of the texture
-   * @param[in] imageId the resource id of the imag
+   * @param[in] sampler The sampler to be used by the texture
    */
-  void SetImage( size_t index,  ResourceId imageId );
+  void SetSampler( uint32_t index, Render::Sampler* sampler );
 
   /**
-   * Set the sampler to be used by the texture at position "index"
+   * Set the texture at position "index"
    * @param[in] index The index of the texture
-   * @param[in] sampler The sampler to be used by the texture
+   * @param[in] texture The texture
    */
-  void SetSampler( size_t index, Render::Sampler* sampler );
+  void SetTexture( uint32_t index, Render::Texture* texture );
 
   /**
    * Return whether any texture in the texture set has an alpha channel
@@ -91,81 +78,48 @@ public:
   bool HasAlpha() const;
 
   /**
-   * Get the resource status
-   * Note, we need two values as it's possible that some resource failed to load
-   * in which case resourcesReady is false (the texture set is not good to be used for rendering)
-   * but finishedResourceAcquisition if true as there is no more loading going on
-   * @param[out] resourcesReady if the texture set is ready to be used for rendering
-   * @param[out] finishedResourceAcquisition if
-   */
-  void GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition );
-
-
-public: // Implementation of ObjectOwnerContainer template methods
-
-  /**
-   * Connect the object to the scene graph
+   * Adds a renderer to the Renderers list of the texture set.
+   * Renderers using the TextureSet get a notification when the texture set changes
    *
-   * @param[in] sceneController The scene controller - used for sending messages to render thread
-   * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
-   */
-  void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
-
-  /**
-   * Disconnect the object from the scene graph
-   * @param[in] sceneController The scene controller - used for sending messages to render thread
-   * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
-   */
-  void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
-
-public: // Implementation of ConnectionChangePropagator
-
-  /**
-   * @copydoc ConnectionChangePropagator::AddObserver
+   * @param[in] renderer The renderer using the TextureSet
    */
-  void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
+  void AddObserver( Renderer* renderer );
 
   /**
-   * @copydoc ConnectionChangePropagator::RemoveObserver
+   * Removes a renderer from the TextureSet renderers list
+   *
+   * @param[in] renderer The renderer no longer using the TextureSet
    */
-  void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
-
-public:
-
-  /**
-   * Get the ResourceId of a texture in the TextureSet
-   * @param[in] index The index of the texture in the textures array
-   * @return the ResourceId
-   */
-  ResourceId GetTextureId( size_t index )
-  {
-    return mTextureId[index];
-  }
+  void RemoveObserver( Renderer* renderer );
 
   /**
    * Get the sampler of a texture in the TextureSet
    * @param[in] index The index of the texture in the textures array
    * @return the sampler used by the texture
    */
-  Render::Sampler* GetTextureSampler( size_t index )
+  Render::Sampler* GetTextureSampler( uint32_t index )
   {
     return mSamplers[index];
   }
 
   /**
-   * Get the number of textures in the texture set
-   * @return The number of textures
+   * Get the number of Textures in the texture set
+   * @return The number of Textures
    */
-  size_t GetTextureCount()
+  uint32_t GetTextureCount()
   {
-    return mTextureId.Size();
+    return static_cast<uint32_t>( mTextures.Size() );
   }
 
-public: // UniformMap::Observer
   /**
-   * @copydoc UniformMap::Observer::UniformMappingsChanged
+   * Get the pointer to  a Texture in the TextureSet
+   * @param[in] index The index of the texture in the textures array
+   * @return the pointer to the Texture in that position
    */
-  virtual void UniformMappingsChanged( const UniformMap& mappings );
+  Render::Texture* GetTexture( uint32_t index )
+  {
+    return mTextures[index];
+  }
 
 private:
 
@@ -174,34 +128,37 @@ private:
    */
   TextureSet();
 
+  /**
+   * Helper method to notify the renderers observing the TextureSet
+   * that the TextureSet has changed
+   */
+  void NotifyChangeToRenderers();
+
 private: // Data
 
-  Vector< Render::Sampler* >      mSamplers; // Not owned
-  Vector< ResourceId >            mTextureId;
-  ConnectionChangePropagator      mConnectionObservers;
-  bool                            mResourcesReady; ///< if the textures are ready to be used for rendering
-  bool                            mFinishedResourceAcquisition; ///< if resource loading is completed
-  bool                            mChanged; ///< if the texture set has changed since the last frame
-  bool                            mHasAlpha; ///< if any of the textures has an alpha channel
+  Vector< Render::Sampler* > mSamplers;                    ///< List of samplers used by each texture. Not owned
+  Vector< Render::Texture* > mTextures;                    ///< List of Textures. Not owned
+  Vector<Renderer*>          mRenderers;                   ///< List of renderers using the TextureSet
+  bool                       mHasAlpha;                    ///< if any of the textures has an alpha channel
 };
 
-inline void SetImageMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, ResourceId resourceId )
+inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture )
 {
-  typedef MessageValue2< TextureSet, size_t, ResourceId > LocalType;
+  using LocalType = MessageValue2<TextureSet, uint32_t, Render::Texture*>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &textureSet, &TextureSet::SetImage, index, resourceId );
+  new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
 }
 
-inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::Sampler* sampler )
+inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler )
 {
-  typedef MessageValue2< TextureSet, size_t, Render::Sampler* > LocalType;
+  using LocalType = MessageValue2<TextureSet, uint32_t, Render::Sampler*>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );