(GradientRenderer)Respond to actor size change automatically when using ObjectBoundin...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / renderer-factory-cache.h
1 #ifndef __DALI_TOOLKIT_RENDERER_FACTORY_CACHE_H__
2 #define __DALI_TOOLKIT_RENDERER_FACTORY_CACHE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/devel-api/rendering/geometry.h>
23 #include <dali/devel-api/rendering/shader.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 /**
35  * Caches shaders and geometries. Owned by RenderFactory.
36  */
37 class RendererFactoryCache : public RefObject
38 {
39 public:
40
41   /**
42    * Type of shader for caching.
43    */
44   enum ShaderType
45   {
46     COLOR_SHADER,
47     BORDER_SHADER,
48     GRADIENT_SHADER_LINEAR_USER_SPACE,
49     GRADIENT_SHADER_LINEAR_BOUNDING_BOX,
50     GRADIENT_SHADER_RADIAL_USER_SPACE,
51     GRADIENT_SHADER_RADIAL_BOUNDING_BOX,
52     IMAGE_SHADER,
53     NINE_PATCH_SHADER,
54     SVG_SHADER,
55     SHADER_TYPE_MAX = SVG_SHADER
56   };
57
58   /**
59    * Type of geometry for caching.
60    */
61   enum GeometryType
62   {
63     QUAD_GEOMETRY,
64     BORDER_GEOMETRY,
65     NINE_PATCH_GEOMETRY,
66     NINE_PATCH_BORDER_GEOMETRY,
67     GEOMETRY_TYPE_MAX = NINE_PATCH_BORDER_GEOMETRY
68   };
69
70 public:
71
72   /**
73    * @brief Constructor
74    */
75   RendererFactoryCache();
76
77   /**
78    * Request geometry of the given type.
79    * @return The geometry of the required type if it exist in the cache. Otherwise, an empty handle is returned.
80    */
81   Geometry GetGeometry( GeometryType type );
82
83   /**
84    * Cache the geometry of the give type.
85    * @param[in] type The geometry type.
86    * @param[in] geometry The geometry for caching.
87    */
88   void SaveGeometry( GeometryType type, Geometry geometry);
89
90   /**
91    * Request shader of the given type.
92    * @return The shader of the required type if it exist in the cache. Otherwise, an empty handle is returned.
93    */
94   Shader GetShader( ShaderType type );
95
96   /**
97    * Cache the geometry of the give type.
98    * @param[in] type The geometry type.
99    * @param[in] geometry The geometry for caching.
100    */
101   void SaveShader( ShaderType type, Shader shader );
102
103   /*
104    * Greate the quad geometry.
105    * Quad geometry is shared by multiple kind of Renderer, so implement it in the factory-cache.
106    */
107   static Geometry CreateQuadGeometry();
108
109 protected:
110
111   /**
112    * A reference counted object may only be deleted by calling Unreference()
113    */
114   virtual ~RendererFactoryCache();
115
116   /**
117    * Undefined copy constructor.
118    */
119   RendererFactoryCache(const RendererFactoryCache&);
120
121   /**
122    * Undefined assignment operator.
123    */
124   RendererFactoryCache& operator=(const RendererFactoryCache& rhs);
125
126 private:
127
128   // ToDo: test whether using the WeakHandle could improve the performance
129   //       With WeakHandle, the resource would be released automatically when no control is using it
130
131   Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
132   Shader mShader[SHADER_TYPE_MAX+1];
133 };
134
135 } // namespace Internal
136
137 } // namespace Toolkit
138
139 } // namespace Dali
140
141 #endif /*__DALI_TOOLKIT_RENDERER_FACTORY_CACHE_H__ */