1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/shader.h>
28 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
29 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
45 * Base class for all Control rendering logic. A control may have multiple visuals.
47 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
49 * The following properties are optional
51 * | %Property Name | Type |
52 * |-------------------------|------------------|
53 * | customShader | MAP |
55 * where custom-shader is a map with the following properties:
56 * | %Property Name | Type |
57 * |-------------------------|------------------|
58 * | vertexShader | STRING |
59 * | fragmentShader | STRING |
60 * | subdivideGridX | INT |
61 * | subdivideGridY | INT |
62 * | shaderHints | INT |
64 class Base : public BaseObject
69 * Initialisation of the visual, this API should only called by the VisualFactory:
70 * request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
71 * record the property values.
73 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
74 * @param[in] propertyMap The properties for the requested Visual object.
76 void Initialize( Actor& actor, const Property::Map& propertyMap );
79 * @copydoc Toolkit::Visual::Base::SetSize
81 virtual void SetSize( const Vector2& size );
84 * @copydoc Toolkit::Visual::Base::GetSize
86 const Vector2& GetSize() const;
89 * @copydoc Toolkit::Visual::Base::GetHeightForWidth
91 virtual float GetHeightForWidth( float width ) const;
94 * @copydoc Toolkit::Visual::Base::GetNaturalSize
96 virtual void GetNaturalSize( Vector2& naturalSize ) const;
99 * @copydoc Toolkit::Visual::Base::SetDepthIndex
101 void SetDepthIndex( float index );
104 * @copydoc Toolkit::Visual::Base::GetDepthIndex
106 float GetDepthIndex() const;
109 * @copydoc Toolkit::Visual::Base::SetOnStage
110 * @pre Impl->mGeometry must be created before this method is called
112 void SetOnStage( Actor& actor );
115 * @copydoc Toolkit::Visual::Base::SetOffStage
117 void SetOffStage( Actor& actor );
120 * @copydoc Toolkit::Visual::Base::CreatePropertyMap
122 void CreatePropertyMap( Property::Map& map ) const;
125 * @brief Set whether the Pre-multiplied Alpha Blending is required
127 * @param[in] preMultipled whether alpha is pre-multiplied.
129 void EnablePreMultipliedAlpha( bool preMultipled );
132 * @brief Query whether alpha is pre-multiplied.
134 * @return True is alpha is pre-multiplied, false otherwise.
136 bool IsPreMultipliedAlphaEnabled() const;
139 * @brief Sets properties of custom shader
140 * @param[in] propertyMap Property map containing the custom shader data
142 void SetCustomShader( const Property::Map& propertyMap );
145 * @copydoc Toolkit::Visual::Base::SetProperty
147 void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
150 * @copydoc Toolkit::Visual::Base::GetProperty
152 Dali::Property::Value GetProperty( Dali::Property::Index index );
157 * @brief Constructor.
159 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
161 Base( VisualFactoryCache& factoryCache );
164 * @brief A reference counted object may only be deleted by calling Unreference().
170 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
172 * @param[out] map The visual property map.
174 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
177 * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
179 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
180 * @param[in] propertyMap The properties for the requested Visual object.
182 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {}
187 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
189 * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
191 * @param[in] actor The actor applying this visual.
193 virtual void DoSetOnStage( Actor& actor )=0;
196 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
198 * @param[in] actor The actor applying this visual.
200 virtual void DoSetOffStage( Actor& actor );
205 * @brief Gets the on stage state for this Visual
207 * @return Returns true if this Visual is on stage, false if it is off the stage
209 bool IsOnStage() const;
212 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
214 * @return Returns true if the renderer is from shared cache, false otherwise
216 bool IsFromCache() const;
220 * @brief Called by SetProperty(). To be overriden by derived clases in order to set properties.
222 * @param [in] index The index of the property.
223 * @param [in] propertyValue The new value of the property.
225 virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ) = 0;
228 * @brief Called by GetProperty(). To be overriden by derived classes in order to retrieve properties.
230 * @param [in] index The index of the property.
232 * @return The property value.
234 virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ) = 0;
239 Base( const Visual::Base& visual );
242 Base& operator=( const Visual::Base& visual );
247 VisualFactoryCache& mFactoryCache;
250 typedef IntrusivePtr<Base> BasePtr;
254 } // namespace Internal
256 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
258 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
260 const BaseObject& handle = visualBase.GetBaseObject();
262 return static_cast<const Internal::Visual::Base&>(handle);
265 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
267 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
269 BaseObject& handle = visualBase.GetBaseObject();
271 return static_cast<Internal::Visual::Base&>(handle);
274 } // namespace Toolkit
278 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H