da15492ad5ba3246e399005a38d53278c4b78c2a
[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/images/image-operations.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/rendering/shader.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
28 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 namespace Visual
41 {
42
43 /**
44  * Base class for all Control rendering logic. A control may have multiple visuals.
45  *
46  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
47  *
48  * The following properties are optional
49  *
50  * | %Property Name          | Type             |
51  * |-------------------------|------------------|
52  * | customShader            | MAP              |
53  *
54  * where custom-shader is a map with the following properties:
55  * | %Property Name          | Type             |
56  * |-------------------------|------------------|
57  * | vertexShader            | STRING           |
58  * | fragmentShader          | STRING           |
59  * | subdivideGridX          | INT              |
60  * | subdivideGridY          | INT              |
61  * | shaderHints             | INT              |
62  */
63 class Base : public BaseObject
64 {
65 public:
66
67   /**
68    *  Initialisation of the visual, this API should only called by the VisualFactory:
69    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
70    *  record the property values.
71    *
72    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
73    * @param[in] propertyMap The properties for the requested Visual object.
74    */
75   void Initialize( Actor& actor, const Property::Map& propertyMap );
76
77   /**
78    * @copydoc Toolkit::Visual::Base::SetSize
79    */
80   virtual void SetSize( const Vector2& size );
81
82   /**
83    * @copydoc Toolkit::Visual::Base::GetSize
84    */
85   const Vector2& GetSize() const;
86
87   /**
88    * @copydoc Toolkit::Visual::Base::GetNaturalSize
89    */
90   virtual void GetNaturalSize( Vector2& naturalSize ) const;
91
92   /**
93    * ToDo: Add this function to Toolkit::Visual when it is fully implemented.
94    *
95    * Set the clip rectangular of this visual.
96    * The contents of the visual will not be visible outside this rectangular.
97    *
98    * @param [in] clipRect The clipping rectangular.
99    */
100   virtual void SetClipRect( const Rect<int>& clipRect );
101
102   /**
103    *ToDo: Add this function to Toolkit::Visual when it is fully implemented.
104    *
105    * Reposition this visual with a 2D offset.
106    *
107    * @param[in] offset The offset to reposition the visual.
108    */
109   virtual void SetOffset( const Vector2& offset );
110
111   /**
112    * @copydoc Toolkit::Visual::Base::SetDepthIndex
113    */
114   void SetDepthIndex( float index );
115
116   /**
117    * @copydoc Toolkit::Visual::Base::GetDepthIndex
118    */
119   float GetDepthIndex() const;
120
121   /**
122    * @copydoc Toolkit::Visual::Base::SetOnStage
123    * @pre Impl->mGeometry must be created before this method is called
124    */
125   void SetOnStage( Actor& actor );
126
127   /**
128    * @copydoc Toolkit::Visual::Base::SetOffStage
129    */
130   void SetOffStage( Actor& actor );
131
132   /**
133    * @copydoc Toolkit::Visual::Base::CreatePropertyMap
134    */
135   void CreatePropertyMap( Property::Map& map ) const;
136
137   /**
138    * @brief Set whether the Pre-multiplied Alpha Blending is required
139    *
140    * @param[in] preMultipled whether alpha is pre-multiplied.
141    */
142   void EnablePreMultipliedAlpha(  bool preMultipled );
143
144   /**
145    * @brief Query whether alpha is pre-multiplied.
146    *
147    * @return True is alpha is pre-multiplied, false otherwise.
148    */
149   bool IsPreMultipliedAlphaEnabled() const;
150
151   /**
152    * @brief Sets properties of custom shader
153    * @param[in] propertyMap Property map containing the custom shader data
154    */
155   void SetCustomShader( const Property::Map& propertyMap );
156
157 protected:
158
159   /**
160    * @brief Constructor.
161    *
162    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
163    */
164   Base( VisualFactoryCache& factoryCache );
165
166   /**
167    * @brief A reference counted object may only be deleted by calling Unreference().
168    */
169   virtual ~Base();
170
171 protected:
172   /**
173    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
174    *
175    * @param[out] map The visual property map.
176    */
177   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
178
179   /**
180    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
181    *
182    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
183    * @param[in] propertyMap The properties for the requested Visual object.
184    */
185   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {}
186
187 protected:
188
189   /**
190    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
191    *
192    * @param[in] actor The actor applying this visual.
193    */
194   virtual void DoSetOnStage( Actor& actor );
195
196   /**
197    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
198    *
199    * @param[in] actor The actor applying this visual.
200    */
201   virtual void DoSetOffStage( Actor& actor );
202
203 protected:
204   /**
205    * @brief Gets the on stage state for this Visual
206    *
207    * @return Returns true if this Visual is on stage, false if it is off the stage
208    */
209   bool GetIsOnStage() const;
210
211   /**
212    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
213    *
214    * @return Returns true if the renderer is from shared cache, false otherwise
215    */
216   bool GetIsFromCache() const;
217
218 private:
219
220   // Undefined
221   Base( const Visual::Base& visual );
222
223   // Undefined
224   Base& operator=( const Visual::Base& visual );
225
226 protected:
227   struct Impl;
228   Impl* mImpl;
229   VisualFactoryCache& mFactoryCache;
230 };
231
232 } // namspace Visual
233
234 } // namespace Internal
235
236 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
237 {
238   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
239
240   const BaseObject& handle = visualBase.GetBaseObject();
241
242   return static_cast<const Internal::Visual::Base&>(handle);
243 }
244
245 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
246 {
247   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
248
249   BaseObject& handle = visualBase.GetBaseObject();
250
251   return static_cast<Internal::Visual::Base&>(handle);
252 }
253
254 } // namespace Toolkit
255
256 } // namespace Dali
257
258 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H