Merge "Fix the warning log in Control causing the wrong position" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_H
3
4 /*
5  * Copyright (c) 2016 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/rendering/renderer.h>
26 #include <dali/public-api/rendering/shader.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
30 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 namespace Visual
43 {
44
45 /**
46  * Base class for all Control rendering logic. A control may have multiple visuals.
47  *
48  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
49  *
50  * The following properties are optional
51  *
52  * | %Property Name          | Type             |
53  * |-------------------------|------------------|
54  * | customShader            | MAP              |
55  *
56  * where custom-shader is a map with the following properties:
57  * | %Property Name          | Type             |
58  * |-------------------------|------------------|
59  * | vertexShader            | STRING           |
60  * | fragmentShader          | STRING           |
61  * | subdivideGridX          | INT              |
62  * | subdivideGridY          | INT              |
63  * | shaderHints             | INT              |
64  */
65 class Base : public BaseObject
66 {
67 public:
68
69   /**
70    * Setting the properties of the visual, this API should only called by the VisualFactory
71    * @param[in] propertyMap The properties for the requested Visual object.
72    */
73   void SetProperties( const Property::Map& propertyMap );
74
75   /**
76    * @copydoc Toolkit::Visual::Base::SetName
77    */
78   void SetName( const std::string& name );
79
80   /**
81    * @copydoc Toolkit::Visual::Base::GetName
82    */
83   const std::string& GetName();
84
85   /**
86    * @copydoc Toolkit::Visual::Base::SetSize
87    */
88   void SetTransformAndSize( const Property::Map& transform, Size controlSize );
89
90   /**
91    * @copydoc Toolkit::Visual::Base::GetHeightForWidth
92    */
93   virtual float GetHeightForWidth( float width );
94
95   /**
96    * @copydoc Toolkit::Visual::Base::GetWidthForHeight
97    */
98   virtual float GetWidthForHeight( float height );
99
100   /**
101    * @copydoc Toolkit::Visual::Base::GetNaturalSize
102    */
103   virtual void GetNaturalSize( Vector2& naturalSize );
104
105   /**
106    * @copydoc Toolkit::Visual::Base::SetDepthIndex
107    */
108   void SetDepthIndex( float index );
109
110   /**
111    * @copydoc Toolkit::Visual::Base::GetDepthIndex
112    */
113   float GetDepthIndex() const;
114
115   /**
116    * @copydoc Toolkit::Visual::Base::SetOnStage
117    * @pre Impl->mGeometry must be created before this method is called
118    */
119   void SetOnStage( Actor& actor );
120
121   /**
122    * @copydoc Toolkit::Visual::Base::SetOffStage
123    */
124   void SetOffStage( Actor& actor );
125
126   /**
127    * @copydoc Toolkit::Visual::Base::CreatePropertyMap
128    */
129   void CreatePropertyMap( Property::Map& map ) const;
130
131   /**
132    * @brief Set whether the Pre-multiplied Alpha Blending is required
133    *
134    * @param[in] preMultipled whether alpha is pre-multiplied.
135    */
136   void EnablePreMultipliedAlpha( bool preMultipled );
137
138   /**
139    * @brief Query whether alpha is pre-multiplied.
140    *
141    * @return True is alpha is pre-multiplied, false otherwise.
142    */
143   bool IsPreMultipliedAlphaEnabled() const;
144
145   /**
146    * @brief Sets properties of custom shader
147    * @param[in] propertyMap Property map containing the custom shader data
148    */
149   void SetCustomShader( const Property::Map& propertyMap );
150
151   /**
152    * @copydoc Toolkit::Visual::Base::SetProperty
153    */
154   void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
155
156   /**
157    * @copydoc Toolkit::Visual::Base::GetProperty
158    */
159   Dali::Property::Value GetProperty( Dali::Property::Index index );
160
161   /**
162    * Gets currently staged renderer, or an empty handle if not staged
163    */
164   Renderer GetRenderer();
165
166 protected:
167
168   /**
169    * @brief Constructor.
170    *
171    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
172    */
173   Base( VisualFactoryCache& factoryCache );
174
175   /**
176    * @brief A reference counted object may only be deleted by calling Unreference().
177    */
178   virtual ~Base();
179
180 protected:
181
182   /**
183    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
184    *
185    * @param[out] map The visual property map.
186    */
187   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
188
189   /**
190    * @brief Called by SetProperties() allowing sub classes to set their properties
191    *
192    * @param[in] propertyMap The properties for the requested Visual object.
193    */
194   virtual void DoSetProperties( const Property::Map& propertyMap ) = 0;
195
196   /**
197    * @brief Called when transform or control size changes
198    * ( Of use to SVG and Text visuals )
199    */
200   virtual void OnSetTransform() = 0;
201
202   /**
203    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
204    *
205    * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
206    *
207    * @param[in] actor The actor applying this visual.
208    */
209   virtual void DoSetOnStage( Actor& actor )=0;
210
211   /**
212    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
213    *
214    * @param[in] actor The actor applying this visual.
215    */
216   virtual void DoSetOffStage( Actor& actor );
217
218 protected:
219
220   /**
221    * @brief Gets the on stage state for this Visual
222    *
223    * @return Returns true if this Visual is on stage, false if it is off the stage
224    */
225   bool IsOnStage() const;
226
227   /**
228    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
229    *
230    * @return Returns true if the renderer is from shared cache, false otherwise
231    */
232   bool IsFromCache() const;
233
234 private:
235
236   // Undefined
237   Base( const Visual::Base& visual );
238
239   // Undefined
240   Base& operator=( const Visual::Base& visual );
241
242 protected:
243   struct Impl;
244   Impl* mImpl;
245   VisualFactoryCache& mFactoryCache;
246 };
247
248 typedef IntrusivePtr<Base> BasePtr;
249
250 } // namspace Visual
251
252 } // namespace Internal
253
254 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
255 {
256   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
257
258   const BaseObject& handle = visualBase.GetBaseObject();
259
260   return static_cast<const Internal::Visual::Base&>(handle);
261 }
262
263 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
264 {
265   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
266
267   BaseObject& handle = visualBase.GetBaseObject();
268
269   return static_cast<Internal::Visual::Base&>(handle);
270 }
271
272 } // namespace Toolkit
273
274 } // namespace Dali
275
276 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H