Rendering API clean-up
[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  * | customShader            | MAP              |
51  *
52  * where custom-shader is a map with the following properties:
53  * | %Property Name          | Type             |
54  * |-------------------------|------------------|
55  * | vertexShader            | STRING           |
56  * | fragmentShader          | STRING           |
57  * | subdivideGridX          | INT              |
58  * | subdivideGridY          | INT              |
59  * | shaderHints             | 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] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
71    * @param[in] propertyMap The properties for the requested ControlRenderer object.
72    */
73   void Initialize( Actor& actor, const Property::Map& propertyMap );
74
75   /**
76    * @copydoc Toolkit::ControlRenderer::SetSize
77    */
78   virtual void SetSize( const Vector2& size );
79
80   /**
81    * @copydoc Toolkit::ControlRenderer::GetSize
82    */
83   const Vector2& GetSize() const;
84
85   /**
86    * @copydoc Toolkit::ControlRenderer::GetNaturalSize
87    */
88   virtual void GetNaturalSize( Vector2& naturalSize ) const;
89
90   /**
91    * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
92    *
93    * Set the clip rectangular of this renderer.
94    * The contents of the renderer will not be visible outside this rectangular.
95    *
96    * @param [in] clipRect The clipping rectangular.
97    */
98   virtual void SetClipRect( const Rect<int>& clipRect );
99
100   /**
101    *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
102    *
103    * Reposition this renderer with a 2D offset.
104    *
105    * @param[in] offset The offset to reposition the renderer.
106    */
107   virtual void SetOffset( const Vector2& offset );
108
109   /**
110    * @copydoc Toolkit::ControlRenderer::SetDepthIndex
111    */
112   void SetDepthIndex( float index );
113
114   /**
115    * @copydoc Toolkit::ControlRenderer::GetDepthIndex
116    */
117   float GetDepthIndex() const;
118
119   /**
120    * @copydoc Toolkit::ControlRenderer::SetOnStage
121    * @pre Impl->mGeometry must be created before this method is called
122    */
123   void SetOnStage( Actor& actor );
124
125   /**
126    * @copydoc Toolkit::ControlRenderer::SetOffStage
127    */
128   void SetOffStage( Actor& actor );
129
130   /**
131    * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
132    */
133   void CreatePropertyMap( Property::Map& map ) const;
134
135   /**
136    * @brief Set whether the Pre-multiplied Alpha Blending is required
137    *
138    * @param[in] preMultipled whether alpha is pre-multiplied.
139    */
140   void EnablePreMultipliedAlpha(  bool preMultipled );
141
142   /**
143    * @brief Query whether alpha is pre-multiplied.
144    *
145    * @return True is alpha is pre-multiplied, false otherwise.
146    */
147   bool IsPreMultipliedAlphaEnabled() const;
148
149 protected:
150
151   /**
152    * @brief Constructor.
153    *
154    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
155    */
156   ControlRenderer( RendererFactoryCache& factoryCache );
157
158   /**
159    * @brief A reference counted object may only be deleted by calling Unreference().
160    */
161   virtual ~ControlRenderer();
162
163 protected:
164   /**
165    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
166    *
167    * @param[out] map The renderer property map.
168    */
169   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
170
171   /**
172    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
173    *
174    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
175    * @param[in] propertyMap The properties for the requested ControlRenderer object.
176    */
177   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
178
179 protected:
180
181   /**
182    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
183    *
184    * @param[in] actor The actor applying this renderer.
185    */
186   virtual void DoSetOnStage( Actor& actor );
187
188   /**
189    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
190    *
191    * @param[in] actor The actor applying this renderer.
192    */
193   virtual void DoSetOffStage( Actor& actor );
194
195 protected:
196   /**
197    * @brief Gets the on stage state for this ControlRenderer
198    *
199    * @return Returns true if this ControlRenderer is on stage, false if it is off the stage
200    */
201   bool GetIsOnStage() const;
202
203   /**
204    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
205    *
206    * @return Returns true if the renderer is from shared cache, false otherwise
207    */
208   bool GetIsFromCache() const;
209
210 private:
211
212   // Undefined
213   ControlRenderer( const ControlRenderer& renderer );
214
215   // Undefined
216   ControlRenderer& operator=( const ControlRenderer& renderer );
217
218 protected:
219   struct Impl;
220   Impl* mImpl;
221   RendererFactoryCache& mFactoryCache;
222 };
223
224 } // namespace Internal
225
226 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
227 {
228   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
229
230   const BaseObject& handle = renderer.GetBaseObject();
231
232   return static_cast<const Internal::ControlRenderer&>(handle);
233 }
234
235 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
236 {
237   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
238
239   BaseObject& handle = renderer.GetBaseObject();
240
241   return static_cast<Internal::ControlRenderer&>(handle);
242 }
243
244 } // namespace Toolkit
245
246 } // namespace Dali
247
248 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */