1 #ifndef DALI_INTERNAL_VISUAL_RENDERER_H
2 #define DALI_INTERNAL_VISUAL_RENDERER_H
5 * Copyright (c) 2022 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/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/public-api/rendering/visual-renderer.h> // Dali::VisualRenderer
36 using VisualRendererPtr = IntrusivePtr<VisualRenderer>;
39 * VisualRenderer is a Renderer that has additional default properties for toolkit
41 class VisualRenderer : public Renderer
45 * Create a new VisualRenderer.
46 * @return A smart-pointer to the newly allocated VisualRenderer.
48 static VisualRendererPtr New();
51 * @brief Get the scene graph object
53 * @return the scene object
55 const SceneGraph::Renderer& GetVisualRendererSceneObject() const;
57 public: // Default property extensions from Object
59 * @copydoc Dali::Internal::Object::SetDefaultProperty()
61 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
64 * @copydoc Dali::Internal::Object::GetDefaultProperty()
66 Property::Value GetDefaultProperty(Property::Index index) const override;
69 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
71 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
74 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
76 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
79 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
81 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
84 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
86 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
88 private: // implementation
92 * @param sceneObject the scene graph renderer
94 VisualRenderer(const SceneGraph::Renderer* sceneObject);
97 * @brief Retrieves the current value of a default property from the scene-graph.
98 * @param[in] index The index of the property
99 * @param[out] value Is set with the current scene-graph value of the property
100 * @return True if value set, false otherwise.
102 bool GetCurrentPropertyValue(Property::Index index, Property::Value& value) const;
106 * A reference counted object may only be deleted by calling Unreference()
108 ~VisualRenderer() override;
111 VisualRenderer(const VisualRenderer&) = delete;
112 VisualRenderer& operator=(const VisualRenderer&) = delete;
115 * @brief Ensure that properties are mapped to uniforms
117 void AddUniformMappings();
120 struct VisualPropertyCache
122 Vector2 mTransformOffset{Vector2::ZERO};
123 Vector2 mTransformSize{Vector2::ZERO};
124 Vector2 mTransformOrigin{Vector2::ZERO};
125 Vector2 mTransformAnchorPoint{Vector2::ZERO};
126 Vector4 mTransformOffsetSizeMode{Vector2::ZERO};
127 Vector2 mExtraSize{Vector2::ZERO};
128 Vector3 mMixColor{Vector3::ONE};
129 float mPreMultipliedAlpha{0.0f};
132 struct AnimatableVisualProperties
134 AnimatableVisualProperties()
135 : mTransformOffset(Vector2::ZERO),
136 mTransformSize(Vector2::ZERO),
137 mTransformOrigin(Vector2::ZERO),
138 mTransformAnchorPoint(Vector2::ZERO),
139 mTransformOffsetSizeMode(Vector4::ZERO),
140 mExtraSize(Vector2::ZERO),
141 mMixColor(Vector3::ONE),
142 mPreMultipliedAlpha(0.0f)
146 SceneGraph::AnimatableProperty<Vector2> mTransformOffset;
147 SceneGraph::AnimatableProperty<Vector2> mTransformSize;
148 SceneGraph::AnimatableProperty<Vector2> mTransformOrigin;
149 SceneGraph::AnimatableProperty<Vector2> mTransformAnchorPoint;
150 SceneGraph::AnimatableProperty<Vector4> mTransformOffsetSizeMode;
151 SceneGraph::AnimatableProperty<Vector2> mExtraSize;
152 SceneGraph::AnimatableProperty<Vector3> mMixColor;
153 SceneGraph::AnimatableProperty<float> mPreMultipliedAlpha;
155 void* mExtendedProperties{nullptr}; // Enable derived class to extend properties further
159 VisualPropertyCache mPropertyCache;
162 } // namespace Internal
164 // Helpers for public-api forwarding methods
165 inline Internal::VisualRenderer& GetImplementation(Dali::VisualRenderer& handle)
167 DALI_ASSERT_ALWAYS(handle && "VisualRenderer handle is empty");
169 BaseObject& object = handle.GetBaseObject();
171 return static_cast<Internal::VisualRenderer&>(object);
174 inline const Internal::VisualRenderer& GetImplementation(const Dali::VisualRenderer& handle)
176 DALI_ASSERT_ALWAYS(handle && "VisualRenderer handle is empty");
178 const BaseObject& object = handle.GetBaseObject();
180 return static_cast<const Internal::VisualRenderer&>(object);
185 #endif // DALI_INTERNAL_RENDERER_H