Remove Geometry::QUAD() usage in Toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / renderer-factory-cache.h
index e6c8d88..f6fd573 100644 (file)
  * limitations under the License.
  */
 
+// INTERNAL INCLUDES
+#include "svg/svg-rasterize-thread.h"
+
 // EXTERNAL INCLUDES
+#include <dali/public-api/math/uint-16-pair.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/devel-api/rendering/geometry.h>
 #include <dali/devel-api/rendering/shader.h>
+#include <dali/devel-api/rendering/renderer.h>
+#include <dali/devel-api/common/owner-container.h>
+#include <dali/devel-api/object/weak-handle.h>
+
 
 namespace Dali
 {
@@ -45,10 +53,13 @@ public:
   {
     COLOR_SHADER,
     BORDER_SHADER,
-    GRADIENT_SHADER_LINEAR,
-    GRADIENT_SHADER_RADIAL,
+    BORDER_SHADER_ANTI_ALIASING,
+    GRADIENT_SHADER_LINEAR_USER_SPACE,
+    GRADIENT_SHADER_LINEAR_BOUNDING_BOX,
+    GRADIENT_SHADER_RADIAL_USER_SPACE,
+    GRADIENT_SHADER_RADIAL_BOUNDING_BOX,
     IMAGE_SHADER,
-    N_PATCH_SHADER,
+    NINE_PATCH_SHADER,
     SVG_SHADER,
     SHADER_TYPE_MAX = SVG_SHADER
   };
@@ -59,8 +70,10 @@ public:
   enum GeometryType
   {
     QUAD_GEOMETRY,
+    BORDER_GEOMETRY,
     NINE_PATCH_GEOMETRY,
-    GEOMETRY_TYPE_MAX = NINE_PATCH_GEOMETRY
+    NINE_PATCH_BORDER_GEOMETRY,
+    GEOMETRY_TYPE_MAX = NINE_PATCH_BORDER_GEOMETRY
   };
 
 public:
@@ -102,6 +115,65 @@ public:
    */
   static Geometry CreateQuadGeometry();
 
+  /**
+   * Create the grid geometry.
+   * @param[in] gridSize The size of the grid.
+   * @return The created grid geometry.
+   */
+  static Geometry CreateGridGeometry( Uint16Pair gridSize );
+
+public:
+
+  /**
+   * @brief Request renderer from the url
+   *
+   * @return The cached renderer if exist in the cache. Otherwise an empty handle is returned.
+   */
+  Renderer GetRenderer( const std::string& key ) const;
+
+  /**
+   * @brief Cache the renderer based on the given key.
+   *
+   * If the key already exists in the cache, then the cache will save an additional renderer to the cache.
+   * RemoveRenderer will then need to be called twice to remove both items from the cache.
+   *
+   * @param[in] key The key to use for caching
+   * @param[in] renderer The Renderer to be cached
+   */
+  void SaveRenderer( const std::string& key, Renderer& renderer );
+
+  /**
+   * @brief Cleans the renderer cache by removing the renderer from the cache based on the given key if there are no longer any references to it
+   *
+   * @param[in] key The key used for caching
+   *
+   * @return True if the renderer is no longer used anywhere, false otherwise
+   */
+  bool CleanRendererCache( const std::string& key );
+
+  /**
+   * @brief Cache the debug renderer
+   */
+  void CacheDebugRenderer( Renderer& renderer );
+
+  /**
+   * @brief Request the debug renderer;
+   */
+  Renderer GetDebugRenderer();
+
+  /**
+   * Get the SVG rasterization thread.
+   * @return A pointer pointing to the SVG rasterization thread.
+   */
+  SvgRasterizeThread* GetSVGRasterizationThread();
+
+private: // for svg rasterization thread
+
+  /**
+   * Applies the rasterized image to material
+   */
+  void ApplyRasterizedSVGToSampler();
+
 protected:
 
   /**
@@ -120,12 +192,37 @@ protected:
   RendererFactoryCache& operator=(const RendererFactoryCache& rhs);
 
 private:
+  struct CachedRenderer
+  {
+    std::string mKey;
+    WeakHandle< Renderer > mRenderer;
 
-  // ToDo: test whether using the WeakHandle could improve the performance
-  //       With WeakHandle, the resource would be released automatically when no control is using it
+    CachedRenderer( const std::string& key, Renderer& renderer )
+    : mKey( key ),
+      mRenderer( renderer)
+    {}
+  };
+
+  typedef Dali::Vector< std::size_t > HashVector;
+  typedef Dali::OwnerContainer< const CachedRenderer* > CachedRenderers;
+
+  /**
+   * @brief Finds the first index into the cached renderers from the url
+   *
+   * @return Returns the first index into the cached renderer from the url if it exists in the cache, otherwise returns -1
+   */
+  int FindRenderer( const std::string& key ) const;
 
+private:
   Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
   Shader mShader[SHADER_TYPE_MAX+1];
+
+  HashVector mRendererHashes;
+  CachedRenderers mRenderers;
+
+  Renderer mDebugRenderer;
+
+  SvgRasterizeThread*  mSvgRasterizeThread;
 };
 
 } // namespace Internal