Implemented custom shader in ImageRenderer and changed Dissolve-effect to utilise...
[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
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class RendererFactoryCache;
41
42 /**
43  * Base class for all Control rendering logic. A control may have multiple control renderers.
44  *
45  * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
46  *
47  * The following properties are optional
48  *
49  * | %Property Name            | Type             |
50  * |---------------------------|------------------|
51  * | custom-shader             | MAP              |
52  *
53  * where custom-shader is a map with the following properties:
54  * | %Property Name            | Type             |
55  * |---------------------------|------------------|
56  * | vertex-shader             | STRING           |
57  * | fragment-shader           | STRING           |
58  * | subdivide-grid-x          | INT              |
59  * | subdivide-grid-y          | INT              |
60  * | shader-hints              | INT              |
61  */
62 class ControlRenderer : public BaseObject
63 {
64 public:
65
66   /**
67    * Initialisation of the renderer, this API should only called by the RendererFactory:
68    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
69    *  record the property values.
70    *
71    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
72    * @param[in] propertyMap The properties for the requested ControlRenderer object.
73    */
74   void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap );
75
76   /**
77    * @copydoc Toolkit::ControlRenderer::SetSize
78    */
79   virtual void SetSize( const Vector2& size );
80
81   /**
82    * @copydoc Toolkit::ControlRenderer::GetSize
83    */
84   const Vector2& GetSize() const;
85
86   /**
87    * @copydoc Toolkit::ControlRenderer::GetNaturalSize
88    */
89   virtual void GetNaturalSize( Vector2& naturalSize ) const;
90
91   /**
92    * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
93    *
94    * Set the clip rectangular of this renderer.
95    * The contents of the renderer will not be visible outside this rectangular.
96    *
97    * @param [in] clipRect The clipping rectangular.
98    */
99   virtual void SetClipRect( const Rect<int>& clipRect );
100
101   /**
102    *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
103    *
104    * Reposition this renderer with a 2D offset.
105    *
106    * @param[in] offset The offset to reposition the renderer.
107    */
108   virtual void SetOffset( const Vector2& offset );
109
110   /**
111    * @copydoc Toolkit::ControlRenderer::SetDepthIndex
112    */
113   void SetDepthIndex( float index );
114
115   /**
116    * @copydoc Toolkit::ControlRenderer::GetDepthIndex
117    */
118   float GetDepthIndex() const;
119
120   /**
121    * @copydoc Toolkit::ControlRenderer::SetOnStage
122    * @pre Impl->mGeometry must be created before this method is called
123    */
124   void SetOnStage( Actor& actor );
125
126   /**
127    * @copydoc Toolkit::ControlRenderer::SetOffStage
128    */
129   void SetOffStage( Actor& actor );
130
131   /**
132    * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
133    */
134   void CreatePropertyMap( Property::Map& map ) const;
135
136 protected:
137
138   /**
139    * @brief Constructor.
140    */
141   ControlRenderer();
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( RendererFactoryCache& factoryCache, const Property::Map& propertyMap ) = 0;
163
164 protected:
165
166   /**
167    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
168    *
169    * @param[in] actor The actor applying this renderer.
170    */
171   virtual void DoSetOnStage( Actor& actor );
172
173   /**
174    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
175    *
176    * @param[in] actor The actor applying this renderer.
177    */
178   virtual void DoSetOffStage( Actor& actor );
179
180 private:
181
182   // Undefined
183   ControlRenderer( const ControlRenderer& renderer );
184
185   // Undefined
186   ControlRenderer& operator=( const ControlRenderer& renderer );
187
188 protected:
189   struct Impl;
190   Impl* mImpl;
191 };
192
193 } // namespace Internal
194
195 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
196 {
197   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
198
199   const BaseObject& handle = renderer.GetBaseObject();
200
201   return static_cast<const Internal::ControlRenderer&>(handle);
202 }
203
204 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
205 {
206   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
207
208   BaseObject& handle = renderer.GetBaseObject();
209
210   return static_cast<Internal::ControlRenderer&>(handle);
211 }
212
213 } // namespace Toolkit
214
215 } // namespace Dali
216
217 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */