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/renderer.h>
26 #include <dali/public-api/rendering/shader.h>
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>
46 * Base class for all Control rendering logic. A control may have multiple visuals.
48 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
50 * The following properties are optional
52 * | %Property Name | Type |
53 * |-------------------------|------------------|
54 * | customShader | MAP |
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 |
65 class Base : public BaseObject
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.
73 void SetProperties( const Property::Map& propertyMap );
76 * @copydoc Toolkit::Visual::Base::SetName
78 void SetName( const std::string& name );
81 * @copydoc Toolkit::Visual::Base::GetName
83 const std::string& GetName();
86 * @copydoc Toolkit::Visual::Base::SetSize
88 void SetTransformAndSize( const Property::Map& transform, Size controlSize );
91 * @copydoc Toolkit::Visual::Base::GetHeightForWidth
93 virtual float GetHeightForWidth( float width );
96 * @copydoc Toolkit::Visual::Base::GetWidthForHeight
98 virtual float GetWidthForHeight( float height );
101 * @copydoc Toolkit::Visual::Base::GetNaturalSize
103 virtual void GetNaturalSize( Vector2& naturalSize );
106 * @copydoc Toolkit::Visual::Base::SetDepthIndex
108 void SetDepthIndex( float index );
111 * @copydoc Toolkit::Visual::Base::GetDepthIndex
113 float GetDepthIndex() const;
116 * @copydoc Toolkit::Visual::Base::SetOnStage
117 * @pre Impl->mGeometry must be created before this method is called
119 void SetOnStage( Actor& actor );
122 * @copydoc Toolkit::Visual::Base::SetOffStage
124 void SetOffStage( Actor& actor );
127 * @copydoc Toolkit::Visual::Base::CreatePropertyMap
129 void CreatePropertyMap( Property::Map& map ) const;
132 * @brief Set whether the Pre-multiplied Alpha Blending is required
134 * @param[in] preMultipled whether alpha is pre-multiplied.
136 void EnablePreMultipliedAlpha( bool preMultipled );
139 * @brief Query whether alpha is pre-multiplied.
141 * @return True is alpha is pre-multiplied, false otherwise.
143 bool IsPreMultipliedAlphaEnabled() const;
146 * @brief Sets properties of custom shader
147 * @param[in] propertyMap Property map containing the custom shader data
149 void SetCustomShader( const Property::Map& propertyMap );
152 * @copydoc Toolkit::Visual::Base::SetProperty
154 void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
157 * @copydoc Toolkit::Visual::Base::GetProperty
159 Dali::Property::Value GetProperty( Dali::Property::Index index );
162 * Gets currently staged renderer, or an empty handle if not staged
164 Renderer GetRenderer();
169 * @brief Constructor.
171 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
173 Base( VisualFactoryCache& factoryCache );
176 * @brief A reference counted object may only be deleted by calling Unreference().
182 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
184 * @param[out] map The visual property map.
186 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
189 * @brief Called by SetProperties() allowing sub classes to set their properties
191 * @param[in] propertyMap The properties for the requested Visual object.
193 virtual void DoSetProperties( const Property::Map& propertyMap ) = 0;
196 * @brief Called when transform or control size changes
197 * ( Of use to SVG and Text visuals )
199 virtual void OnSetTransform() = 0;
204 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
206 * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
208 * @param[in] actor The actor applying this visual.
210 virtual void DoSetOnStage( Actor& actor )=0;
213 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
215 * @param[in] actor The actor applying this visual.
217 virtual void DoSetOffStage( Actor& actor );
222 * @brief Gets the on stage state for this Visual
224 * @return Returns true if this Visual is on stage, false if it is off the stage
226 bool IsOnStage() const;
229 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
231 * @return Returns true if the renderer is from shared cache, false otherwise
233 bool IsFromCache() const;
238 Base( const Visual::Base& visual );
241 Base& operator=( const Visual::Base& visual );
246 VisualFactoryCache& mFactoryCache;
249 typedef IntrusivePtr<Base> BasePtr;
253 } // namespace Internal
255 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
257 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
259 const BaseObject& handle = visualBase.GetBaseObject();
261 return static_cast<const Internal::Visual::Base&>(handle);
264 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
266 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
268 BaseObject& handle = visualBase.GetBaseObject();
270 return static_cast<Internal::Visual::Base&>(handle);
273 } // namespace Toolkit
277 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H