Initial implemention NPatchRenderer only for 9 patch case.
[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,
49     GRADIENT_SHADER_RADIAL,
50     IMAGE_SHADER,
51     NINE_PATCH_SHADER,
52     SVG_SHADER,
53     SHADER_TYPE_MAX = SVG_SHADER
54   };
55
56   /**
57    * Type of geometry for caching.
58    */
59   enum GeometryType
60   {
61     QUAD_GEOMETRY,
62     NINE_PATCH_GEOMETRY,
63     NINE_PATCH_BORDER_GEOMETRY,
64     GEOMETRY_TYPE_MAX = NINE_PATCH_BORDER_GEOMETRY
65   };
66
67 public:
68
69   /**
70    * @brief Constructor
71    */
72   RendererFactoryCache();
73
74   /**
75    * Request geometry of the given type.
76    * @return The geometry of the required type if it exist in the cache. Otherwise, an empty handle is returned.
77    */
78   Geometry GetGeometry( GeometryType type );
79
80   /**
81    * Cache the geometry of the give type.
82    * @param[in] type The geometry type.
83    * @param[in] geometry The geometry for caching.
84    */
85   void SaveGeometry( GeometryType type, Geometry geometry);
86
87   /**
88    * Request shader of the given type.
89    * @return The shader of the required type if it exist in the cache. Otherwise, an empty handle is returned.
90    */
91   Shader GetShader( ShaderType type );
92
93   /**
94    * Cache the geometry of the give type.
95    * @param[in] type The geometry type.
96    * @param[in] geometry The geometry for caching.
97    */
98   void SaveShader( ShaderType type, Shader shader );
99
100   /*
101    * Greate the quad geometry.
102    * Quad geometry is shared by multiple kind of Renderer, so implement it in the factory-cache.
103    */
104   static Geometry CreateQuadGeometry();
105
106 protected:
107
108   /**
109    * A reference counted object may only be deleted by calling Unreference()
110    */
111   virtual ~RendererFactoryCache();
112
113   /**
114    * Undefined copy constructor.
115    */
116   RendererFactoryCache(const RendererFactoryCache&);
117
118   /**
119    * Undefined assignment operator.
120    */
121   RendererFactoryCache& operator=(const RendererFactoryCache& rhs);
122
123 private:
124
125   // ToDo: test whether using the WeakHandle could improve the performance
126   //       With WeakHandle, the resource would be released automatically when no control is using it
127
128   Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
129   Shader mShader[SHADER_TYPE_MAX+1];
130 };
131
132 } // namespace Internal
133
134 } // namespace Toolkit
135
136 } // namespace Dali
137
138 #endif /*__DALI_TOOLKIT_RENDERER_FACTORY_CACHE_H__ */