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 sceneObjectKey = 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 sceneObjectKey->SetVisualProperties(animatableVisualProperties);
88 // pass the pointer to base for message passing
89 DecoratedVisualRendererPtr rendererPtr(new DecoratedVisualRenderer(sceneObjectKey.Get()));
91 rendererPtr->AddUniformMappings(); // Ensure properties are mapped to uniforms
93 EventThreadServices& eventThreadServices = rendererPtr->GetEventThreadServices();
94 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
95 AddRendererMessage(updateManager, sceneObjectKey);
97 eventThreadServices.RegisterObject(rendererPtr.Get());
101 DecoratedVisualRenderer::DecoratedVisualRenderer(const SceneGraph::Renderer* sceneObject)
102 : VisualRenderer(sceneObject),
103 mDecoratedPropertyCache(),
108 DecoratedVisualRenderer::~DecoratedVisualRenderer() = default; // The scene object will be deleted by ~VisualRenderer
110 void DecoratedVisualRenderer::SetDefaultProperty(Property::Index index,
111 const Property::Value& propertyValue)
113 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
115 VisualRenderer::SetDefaultProperty(index, propertyValue);
119 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
120 auto visualProperties = sceneObject.GetVisualProperties();
124 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
126 if(decoratedVisualProperties)
128 EventThreadServices& eventThreadServices = GetEventThreadServices();
132 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
134 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadius, decoratedVisualProperties->mCornerRadius);
138 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
140 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadiusPolicy, decoratedVisualProperties->mCornerRadiusPolicy);
144 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
146 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineWidth, decoratedVisualProperties->mBorderlineWidth);
150 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
152 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineColor, decoratedVisualProperties->mBorderlineColor);
156 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
158 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineOffset, decoratedVisualProperties->mBorderlineOffset);
162 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
164 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBlurRadius, decoratedVisualProperties->mBlurRadius);
173 Property::Value DecoratedVisualRenderer::GetDefaultProperty(Property::Index index) const
175 Property::Value value;
177 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
179 value = VisualRenderer::GetDefaultProperty(index);
185 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
187 value = mDecoratedPropertyCache.mCornerRadius;
190 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
192 value = mDecoratedPropertyCache.mCornerRadiusPolicy;
195 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
197 value = mDecoratedPropertyCache.mBorderlineWidth;
200 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
202 value = mDecoratedPropertyCache.mBorderlineColor;
205 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
207 value = mDecoratedPropertyCache.mBorderlineOffset;
210 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
212 value = mDecoratedPropertyCache.mBlurRadius;
225 Property::Value DecoratedVisualRenderer::GetDefaultPropertyCurrentValue(Property::Index index) const
227 Property::Value value;
229 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
231 value = VisualRenderer::GetDefaultPropertyCurrentValue(index);
235 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
239 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
241 auto visualProperties = sceneObject.GetVisualProperties();
244 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
245 if(decoratedVisualProperties)
247 value = decoratedVisualProperties->mCornerRadius[GetEventThreadServices().GetEventBufferIndex()];
252 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
254 auto visualProperties = sceneObject.GetVisualProperties();
257 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
258 if(decoratedVisualProperties)
260 value = decoratedVisualProperties->mCornerRadiusPolicy[GetEventThreadServices().GetEventBufferIndex()];
265 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
267 auto visualProperties = sceneObject.GetVisualProperties();
270 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
271 if(decoratedVisualProperties)
273 value = decoratedVisualProperties->mBorderlineWidth[GetEventThreadServices().GetEventBufferIndex()];
278 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
280 auto visualProperties = sceneObject.GetVisualProperties();
283 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
284 if(decoratedVisualProperties)
286 value = decoratedVisualProperties->mBorderlineColor[GetEventThreadServices().GetEventBufferIndex()];
291 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
293 auto visualProperties = sceneObject.GetVisualProperties();
296 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
297 if(decoratedVisualProperties)
299 value = decoratedVisualProperties->mBorderlineOffset[GetEventThreadServices().GetEventBufferIndex()];
304 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
306 auto visualProperties = sceneObject.GetVisualProperties();
309 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
310 if(decoratedVisualProperties)
312 value = decoratedVisualProperties->mBlurRadius[GetEventThreadServices().GetEventBufferIndex()];
322 void DecoratedVisualRenderer::OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
324 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
326 VisualRenderer::OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
330 switch(animationType)
333 case Animation::BETWEEN:
337 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
339 value.Get(mDecoratedPropertyCache.mCornerRadius);
342 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
344 value.Get(mDecoratedPropertyCache.mBorderlineWidth);
347 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
349 value.Get(mDecoratedPropertyCache.mBorderlineColor);
352 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
354 value.Get(mDecoratedPropertyCache.mBorderlineOffset);
357 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
359 value.Get(mDecoratedPropertyCache.mBlurRadius);
370 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
372 AdjustValue<Vector4>(mDecoratedPropertyCache.mCornerRadius, value);
375 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
377 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineWidth, value);
380 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
382 AdjustValue<Vector4>(mDecoratedPropertyCache.mBorderlineColor, value);
385 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
387 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineOffset, value);
390 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
392 AdjustValue<float>(mDecoratedPropertyCache.mBlurRadius, value);
402 const SceneGraph::PropertyBase* DecoratedVisualRenderer::GetSceneObjectAnimatableProperty(Property::Index index) const
404 const SceneGraph::PropertyBase* property = nullptr;
408 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
410 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
413 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
414 if(decoratedVisualProperties)
416 property = &decoratedVisualProperties->mCornerRadius;
421 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
423 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
426 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
427 if(decoratedVisualProperties)
429 property = &decoratedVisualProperties->mBorderlineWidth;
434 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
436 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
439 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
440 if(decoratedVisualProperties)
442 property = &decoratedVisualProperties->mBorderlineColor;
447 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
449 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
452 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
453 if(decoratedVisualProperties)
455 property = &decoratedVisualProperties->mBorderlineOffset;
460 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
462 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
465 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
466 if(decoratedVisualProperties)
468 property = &decoratedVisualProperties->mBlurRadius;
477 // not our property, ask base
478 property = VisualRenderer::GetSceneObjectAnimatableProperty(index);
484 const PropertyInputImpl* DecoratedVisualRenderer::GetSceneObjectInputProperty(Property::Index index) const
486 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
488 return VisualRenderer::GetSceneObjectInputProperty(index);
492 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
494 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
497 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
498 if(decoratedVisualProperties)
500 return &decoratedVisualProperties->mCornerRadiusPolicy;
507 return GetSceneObjectAnimatableProperty(index);
513 void DecoratedVisualRenderer::RegisterCornerRadiusUniform()
515 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS);
518 void DecoratedVisualRenderer::RegisterBorderlineUniform()
520 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BORDERLINE);
523 void DecoratedVisualRenderer::RegisterBlurRadiusUniform()
525 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS);
528 void DecoratedVisualRenderer::AddUniformFlag(uint8_t newAddFlag)
530 const uint8_t diffUniformFlag = (~mAddUniformFlag) & newAddFlag;
533 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS)
535 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS, ConstString("cornerRadius"));
536 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, ConstString("cornerRadiusPolicy"));
538 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BORDERLINE)
540 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, ConstString("borderlineWidth"));
541 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR, ConstString("borderlineColor"));
542 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, ConstString("borderlineOffset"));
544 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS)
546 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS, ConstString("blurRadius"));
549 // Note. Let we don't remove UniformMapping due to the performane issue.
550 mAddUniformFlag |= newAddFlag;
554 } // namespace Internal