2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/rendering/decorated-visual-renderer-impl.h>
22 #include <dali/devel-api/rendering/renderer-devel.h>
23 #include <dali/devel-api/scripting/scripting.h>
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/event/common/property-input-impl.h>
26 #include <dali/internal/update/manager/update-manager.h>
27 #include <dali/internal/update/rendering/scene-graph-renderer.h>
28 #include <dali/public-api/object/type-registry.h>
37 * Properties: |name |type |writable|animatable|constraint-input|enum for index-checking|
39 DALI_PROPERTY_TABLE_BEGIN
40 DALI_PROPERTY("cornerRadius", VECTOR4, true, true, true, Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS)
41 DALI_PROPERTY("cornerRadiusPolicy", FLOAT, true, false, true, Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY)
42 DALI_PROPERTY("borderlineWidth", FLOAT, true, true, true, Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH)
43 DALI_PROPERTY("borderlineColor", VECTOR4, true, true, true, Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR)
44 DALI_PROPERTY("borderlineOffset", FLOAT, true, true, true, Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET)
45 DALI_PROPERTY("blurRadius", FLOAT, true, true, true, Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS)
46 DALI_PROPERTY_TABLE_END(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS, DecoratedVisualRendererDefaultProperties)
50 return Dali::BaseHandle();
53 TypeRegistration mType(typeid(Dali::DecoratedVisualRenderer), typeid(Dali::VisualRenderer), Create, DecoratedVisualRendererDefaultProperties);
56 * Sets both the cached value of a property and sends a message to set the animatable property in the Update thread.
57 * @tparam T The property type
58 * @param eventThreadServices The event thread services
59 * @param propertyValue The new property value given
60 * @param cachedValue The local cached value of the property
61 * @param animatableProperty The animatable property to set on the update-thread
64 void SetValue(EventThreadServices& eventThreadServices, const Property::Value& propertyValue, T& cachedValue, const SceneGraph::AnimatableProperty<T>& animatableProperty)
66 if(propertyValue.Get(cachedValue))
68 BakeMessage<T>(eventThreadServices, animatableProperty, cachedValue);
72 } // unnamed namespace
74 DecoratedVisualRendererPtr DecoratedVisualRenderer::New()
76 // create scene object first so it's guaranteed to exist for the event side
77 auto sceneObjectIndex = SceneGraph::Renderer::NewKey();
79 auto animatableVisualProperties = new SceneGraph::VisualRenderer::AnimatableVisualProperties();
80 auto animatableDecoratedVisualProperties = new SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties();
82 // Append extended properties as AnimatableDecoratedVisualProperties.
83 animatableVisualProperties->mExtendedProperties = animatableDecoratedVisualProperties;
84 animatableVisualProperties->mExtendedPropertiesDeleteFunction = SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties::DeleteFunction;
86 auto sceneObject = SceneGraph::Renderer::Get(sceneObjectIndex);
87 sceneObject->SetVisualProperties(animatableVisualProperties);
89 // pass the pointer to base for message passing
90 DecoratedVisualRendererPtr rendererPtr(new DecoratedVisualRenderer(sceneObject));
92 rendererPtr->AddUniformMappings(); // Ensure properties are mapped to uniforms
94 EventThreadServices& eventThreadServices = rendererPtr->GetEventThreadServices();
95 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
96 AddRendererMessage(updateManager, sceneObjectIndex);
98 eventThreadServices.RegisterObject(rendererPtr.Get());
102 DecoratedVisualRenderer::DecoratedVisualRenderer(const SceneGraph::Renderer* sceneObject)
103 : VisualRenderer(sceneObject),
104 mDecoratedPropertyCache(),
109 DecoratedVisualRenderer::~DecoratedVisualRenderer() = default; // The scene object will be deleted by ~VisualRenderer
111 void DecoratedVisualRenderer::SetDefaultProperty(Property::Index index,
112 const Property::Value& propertyValue)
114 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
116 VisualRenderer::SetDefaultProperty(index, propertyValue);
120 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
121 auto visualProperties = sceneObject.GetVisualProperties();
125 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
127 if(decoratedVisualProperties)
129 EventThreadServices& eventThreadServices = GetEventThreadServices();
133 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
135 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadius, decoratedVisualProperties->mCornerRadius);
139 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
141 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadiusPolicy, decoratedVisualProperties->mCornerRadiusPolicy);
145 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
147 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineWidth, decoratedVisualProperties->mBorderlineWidth);
151 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
153 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineColor, decoratedVisualProperties->mBorderlineColor);
157 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
159 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineOffset, decoratedVisualProperties->mBorderlineOffset);
163 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
165 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBlurRadius, decoratedVisualProperties->mBlurRadius);
174 Property::Value DecoratedVisualRenderer::GetDefaultProperty(Property::Index index) const
176 Property::Value value;
178 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
180 value = VisualRenderer::GetDefaultProperty(index);
186 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
188 value = mDecoratedPropertyCache.mCornerRadius;
191 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
193 value = mDecoratedPropertyCache.mCornerRadiusPolicy;
196 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
198 value = mDecoratedPropertyCache.mBorderlineWidth;
201 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
203 value = mDecoratedPropertyCache.mBorderlineColor;
206 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
208 value = mDecoratedPropertyCache.mBorderlineOffset;
211 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
213 value = mDecoratedPropertyCache.mBlurRadius;
226 Property::Value DecoratedVisualRenderer::GetDefaultPropertyCurrentValue(Property::Index index) const
228 Property::Value value;
230 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
232 value = VisualRenderer::GetDefaultPropertyCurrentValue(index);
236 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
240 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
242 auto visualProperties = sceneObject.GetVisualProperties();
245 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
246 if(decoratedVisualProperties)
248 value = decoratedVisualProperties->mCornerRadius[GetEventThreadServices().GetEventBufferIndex()];
253 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
255 auto visualProperties = sceneObject.GetVisualProperties();
258 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
259 if(decoratedVisualProperties)
261 value = decoratedVisualProperties->mCornerRadiusPolicy[GetEventThreadServices().GetEventBufferIndex()];
266 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
268 auto visualProperties = sceneObject.GetVisualProperties();
271 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
272 if(decoratedVisualProperties)
274 value = decoratedVisualProperties->mBorderlineWidth[GetEventThreadServices().GetEventBufferIndex()];
279 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
281 auto visualProperties = sceneObject.GetVisualProperties();
284 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
285 if(decoratedVisualProperties)
287 value = decoratedVisualProperties->mBorderlineColor[GetEventThreadServices().GetEventBufferIndex()];
292 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
294 auto visualProperties = sceneObject.GetVisualProperties();
297 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
298 if(decoratedVisualProperties)
300 value = decoratedVisualProperties->mBorderlineOffset[GetEventThreadServices().GetEventBufferIndex()];
305 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
307 auto visualProperties = sceneObject.GetVisualProperties();
310 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
311 if(decoratedVisualProperties)
313 value = decoratedVisualProperties->mBlurRadius[GetEventThreadServices().GetEventBufferIndex()];
323 void DecoratedVisualRenderer::OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
325 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
327 VisualRenderer::OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
331 switch(animationType)
334 case Animation::BETWEEN:
338 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
340 value.Get(mDecoratedPropertyCache.mCornerRadius);
343 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
345 value.Get(mDecoratedPropertyCache.mBorderlineWidth);
348 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
350 value.Get(mDecoratedPropertyCache.mBorderlineColor);
353 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
355 value.Get(mDecoratedPropertyCache.mBorderlineOffset);
358 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
360 value.Get(mDecoratedPropertyCache.mBlurRadius);
371 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
373 AdjustValue<Vector4>(mDecoratedPropertyCache.mCornerRadius, value);
376 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
378 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineWidth, value);
381 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
383 AdjustValue<Vector4>(mDecoratedPropertyCache.mBorderlineColor, value);
386 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
388 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineOffset, value);
391 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
393 AdjustValue<float>(mDecoratedPropertyCache.mBlurRadius, value);
403 const SceneGraph::PropertyBase* DecoratedVisualRenderer::GetSceneObjectAnimatableProperty(Property::Index index) const
405 const SceneGraph::PropertyBase* property = nullptr;
409 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
411 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
414 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
415 if(decoratedVisualProperties)
417 property = &decoratedVisualProperties->mCornerRadius;
422 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
424 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
427 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
428 if(decoratedVisualProperties)
430 property = &decoratedVisualProperties->mBorderlineWidth;
435 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
437 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
440 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
441 if(decoratedVisualProperties)
443 property = &decoratedVisualProperties->mBorderlineColor;
448 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
450 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
453 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
454 if(decoratedVisualProperties)
456 property = &decoratedVisualProperties->mBorderlineOffset;
461 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
463 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
466 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
467 if(decoratedVisualProperties)
469 property = &decoratedVisualProperties->mBlurRadius;
478 // not our property, ask base
479 property = VisualRenderer::GetSceneObjectAnimatableProperty(index);
485 const PropertyInputImpl* DecoratedVisualRenderer::GetSceneObjectInputProperty(Property::Index index) const
487 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
489 return VisualRenderer::GetSceneObjectInputProperty(index);
493 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
495 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
498 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
499 if(decoratedVisualProperties)
501 return &decoratedVisualProperties->mCornerRadiusPolicy;
508 return GetSceneObjectAnimatableProperty(index);
514 void DecoratedVisualRenderer::RegisterCornerRadiusUniform()
516 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS);
519 void DecoratedVisualRenderer::RegisterBorderlineUniform()
521 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BORDERLINE);
524 void DecoratedVisualRenderer::RegisterBlurRadiusUniform()
526 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS);
529 void DecoratedVisualRenderer::AddUniformFlag(uint8_t newAddFlag)
531 const uint8_t diffUniformFlag = (~mAddUniformFlag) & newAddFlag;
534 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS)
536 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS, ConstString("cornerRadius"));
537 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, ConstString("cornerRadiusPolicy"));
539 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BORDERLINE)
541 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, ConstString("borderlineWidth"));
542 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR, ConstString("borderlineColor"));
543 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, ConstString("borderlineOffset"));
545 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS)
547 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS, ConstString("blurRadius"));
550 // Note. Let we don't remove UniformMapping due to the performane issue.
551 mAddUniformFlag |= newAddFlag;
555 } // namespace Internal