10a13dc7e76fe79b23e65280eacd7501888fbb97
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / control-renderer-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_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
21
22 // EXTERNAL INCLUDES
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/devel-api/rendering/shader.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
29 #include <dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h>
30 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42  * Base class for all Control rendering logic. A control may have multiple control renderers.
43  *
44  * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
45  *
46  * The following properties are optional
47  *
48  * | %Property Name            | Type             |
49  * |---------------------------|------------------|
50  * | custom-shader             | MAP              |
51  *
52  * where custom-shader is a map with the following properties:
53  * | %Property Name            | Type             |
54  * |---------------------------|------------------|
55  * | vertex-shader             | STRING           |
56  * | fragment-shader           | STRING           |
57  * | subdivide-grid-x          | INT              |
58  * | subdivide-grid-y          | INT              |
59  * | shader-hints              | INT              |
60  */
61 class ControlRenderer : public BaseObject
62 {
63 public:
64
65   /**
66    * Initialisation of the renderer, this API should only called by the RendererFactory:
67    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
68    *  record the property values.
69    *
70    * @param[in] propertyMap The properties for the requested ControlRenderer object.
71    */
72   void Initialize( const Property::Map& propertyMap );
73
74   /**
75    * @copydoc Toolkit::ControlRenderer::SetSize
76    */
77   virtual void SetSize( const Vector2& size );
78
79   /**
80    * @copydoc Toolkit::ControlRenderer::GetSize
81    */
82   const Vector2& GetSize() const;
83
84   /**
85    * @copydoc Toolkit::ControlRenderer::GetNaturalSize
86    */
87   virtual void GetNaturalSize( Vector2& naturalSize ) const;
88
89   /**
90    * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
91    *
92    * Set the clip rectangular of this renderer.
93    * The contents of the renderer will not be visible outside this rectangular.
94    *
95    * @param [in] clipRect The clipping rectangular.
96    */
97   virtual void SetClipRect( const Rect<int>& clipRect );
98
99   /**
100    *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
101    *
102    * Reposition this renderer with a 2D offset.
103    *
104    * @param[in] offset The offset to reposition the renderer.
105    */
106   virtual void SetOffset( const Vector2& offset );
107
108   /**
109    * @copydoc Toolkit::ControlRenderer::SetDepthIndex
110    */
111   void SetDepthIndex( float index );
112
113   /**
114    * @copydoc Toolkit::ControlRenderer::GetDepthIndex
115    */
116   float GetDepthIndex() const;
117
118   /**
119    * @copydoc Toolkit::ControlRenderer::SetOnStage
120    * @pre Impl->mGeometry must be created before this method is called
121    */
122   void SetOnStage( Actor& actor );
123
124   /**
125    * @copydoc Toolkit::ControlRenderer::SetOffStage
126    */
127   void SetOffStage( Actor& actor );
128
129   /**
130    * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
131    */
132   void CreatePropertyMap( Property::Map& map ) const;
133
134 protected:
135
136   /**
137    * @brief Constructor.
138    *
139    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
140    */
141   ControlRenderer( RendererFactoryCache& factoryCache );
142
143   /**
144    * @brief A reference counted object may only be deleted by calling Unreference().
145    */
146   virtual ~ControlRenderer();
147
148 protected:
149   /**
150    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
151    *
152    * @param[out] map The renderer property map.
153    */
154   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
155
156   /**
157    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
158    *
159    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
160    * @param[in] propertyMap The properties for the requested ControlRenderer object.
161    */
162   virtual void DoInitialize( const Property::Map& propertyMap ) = 0;
163
164   /**
165    * @brief Initialises a renderer ready to be put on stage.
166    *
167    * @param[inout] renderer The Renderer to initialise. If the renderer is not empty then re-initialise the renderer
168    */
169   virtual void InitializeRenderer( Renderer& renderer ) = 0;
170
171 protected:
172
173   /**
174    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
175    *
176    * @param[in] actor The actor applying this renderer.
177    */
178   virtual void DoSetOnStage( Actor& actor );
179
180   /**
181    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
182    *
183    * @param[in] actor The actor applying this renderer.
184    */
185   virtual void DoSetOffStage( Actor& actor );
186
187 protected:
188
189   /**
190    * @brief Sets the key to use for caching the renderer. If this is empty then no caching will occur
191    *
192    * @param[in] cachedRendererKey The key to use for caching the renderer.
193    */
194   void SetCachedRendererKey( const std::string& cachedRendererKey );
195
196 private:
197
198   // Undefined
199   ControlRenderer( const ControlRenderer& renderer );
200
201   // Undefined
202   ControlRenderer& operator=( const ControlRenderer& renderer );
203
204 protected:
205   struct Impl;
206   Impl* mImpl;
207   RendererFactoryCache& mFactoryCache;
208 };
209
210 } // namespace Internal
211
212 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
213 {
214   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
215
216   const BaseObject& handle = renderer.GetBaseObject();
217
218   return static_cast<const Internal::ControlRenderer&>(handle);
219 }
220
221 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
222 {
223   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
224
225   BaseObject& handle = renderer.GetBaseObject();
226
227   return static_cast<Internal::ControlRenderer&>(handle);
228 }
229
230 } // namespace Toolkit
231
232 } // namespace Dali
233
234 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */