[3.0](SvgVisual)Stop displaying garbage pixels before rasterization getting finished
[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    * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
193    * @param[in] actor The actor applying this visual.
194    */
195   virtual void DoSetOnStage( Actor& actor ) = 0;
196
197   /**
198    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
199    *
200    * @param[in] actor The actor applying this visual.
201    */
202   virtual void DoSetOffStage( Actor& actor );
203
204 protected:
205   /**
206    * @brief Gets the on stage state for this Visual
207    *
208    * @return Returns true if this Visual is on stage, false if it is off the stage
209    */
210   bool GetIsOnStage() const;
211
212   /**
213    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
214    *
215    * @return Returns true if the renderer is from shared cache, false otherwise
216    */
217   bool GetIsFromCache() const;
218
219 private:
220
221   // Undefined
222   Base( const Visual::Base& visual );
223
224   // Undefined
225   Base& operator=( const Visual::Base& visual );
226
227 protected:
228   struct Impl;
229   Impl* mImpl;
230   VisualFactoryCache& mFactoryCache;
231 };
232
233 } // namspace Visual
234
235 } // namespace Internal
236
237 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
238 {
239   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
240
241   const BaseObject& handle = visualBase.GetBaseObject();
242
243   return static_cast<const Internal::Visual::Base&>(handle);
244 }
245
246 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
247 {
248   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
249
250   BaseObject& handle = visualBase.GetBaseObject();
251
252   return static_cast<Internal::Visual::Base&>(handle);
253 }
254
255 } // namespace Toolkit
256
257 } // namespace Dali
258
259 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H