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 sceneObject = SceneGraph::Renderer::New();
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 sceneObject->SetVisualProperties(animatableVisualProperties);
88 OwnerPointer<SceneGraph::Renderer> transferOwnership(sceneObject);
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 // transfer scene object ownership to update manager
95 EventThreadServices& eventThreadServices = rendererPtr->GetEventThreadServices();
96 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
97 AddRendererMessage(updateManager, transferOwnership);
99 eventThreadServices.RegisterObject(rendererPtr.Get());
103 DecoratedVisualRenderer::DecoratedVisualRenderer(const SceneGraph::Renderer* sceneObject)
104 : VisualRenderer(sceneObject),
105 mDecoratedPropertyCache(),
110 DecoratedVisualRenderer::~DecoratedVisualRenderer() = default; // The scene object will be deleted by ~VisualRenderer
112 void DecoratedVisualRenderer::SetDefaultProperty(Property::Index index,
113 const Property::Value& propertyValue)
115 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
117 VisualRenderer::SetDefaultProperty(index, propertyValue);
121 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
122 auto visualProperties = sceneObject.GetVisualProperties();
126 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
128 if(decoratedVisualProperties)
130 EventThreadServices& eventThreadServices = GetEventThreadServices();
134 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
136 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadius, decoratedVisualProperties->mCornerRadius);
140 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
142 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mCornerRadiusPolicy, decoratedVisualProperties->mCornerRadiusPolicy);
146 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
148 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineWidth, decoratedVisualProperties->mBorderlineWidth);
152 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
154 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineColor, decoratedVisualProperties->mBorderlineColor);
158 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
160 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBorderlineOffset, decoratedVisualProperties->mBorderlineOffset);
164 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
166 SetValue(eventThreadServices, propertyValue, mDecoratedPropertyCache.mBlurRadius, decoratedVisualProperties->mBlurRadius);
175 Property::Value DecoratedVisualRenderer::GetDefaultProperty(Property::Index index) const
177 Property::Value value;
179 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
181 value = VisualRenderer::GetDefaultProperty(index);
187 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
189 value = mDecoratedPropertyCache.mCornerRadius;
192 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
194 value = mDecoratedPropertyCache.mCornerRadiusPolicy;
197 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
199 value = mDecoratedPropertyCache.mBorderlineWidth;
202 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
204 value = mDecoratedPropertyCache.mBorderlineColor;
207 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
209 value = mDecoratedPropertyCache.mBorderlineOffset;
212 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
214 value = mDecoratedPropertyCache.mBlurRadius;
227 Property::Value DecoratedVisualRenderer::GetDefaultPropertyCurrentValue(Property::Index index) const
229 Property::Value value;
231 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
233 value = VisualRenderer::GetDefaultPropertyCurrentValue(index);
237 const SceneGraph::Renderer& sceneObject = GetVisualRendererSceneObject();
241 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
243 auto visualProperties = sceneObject.GetVisualProperties();
246 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
247 if(decoratedVisualProperties)
249 value = decoratedVisualProperties->mCornerRadius[GetEventThreadServices().GetEventBufferIndex()];
254 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
256 auto visualProperties = sceneObject.GetVisualProperties();
259 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
260 if(decoratedVisualProperties)
262 value = decoratedVisualProperties->mCornerRadiusPolicy[GetEventThreadServices().GetEventBufferIndex()];
267 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
269 auto visualProperties = sceneObject.GetVisualProperties();
272 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
273 if(decoratedVisualProperties)
275 value = decoratedVisualProperties->mBorderlineWidth[GetEventThreadServices().GetEventBufferIndex()];
280 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
282 auto visualProperties = sceneObject.GetVisualProperties();
285 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
286 if(decoratedVisualProperties)
288 value = decoratedVisualProperties->mBorderlineColor[GetEventThreadServices().GetEventBufferIndex()];
293 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
295 auto visualProperties = sceneObject.GetVisualProperties();
298 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
299 if(decoratedVisualProperties)
301 value = decoratedVisualProperties->mBorderlineOffset[GetEventThreadServices().GetEventBufferIndex()];
306 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
308 auto visualProperties = sceneObject.GetVisualProperties();
311 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
312 if(decoratedVisualProperties)
314 value = decoratedVisualProperties->mBlurRadius[GetEventThreadServices().GetEventBufferIndex()];
324 void DecoratedVisualRenderer::OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
326 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
328 VisualRenderer::OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
332 switch(animationType)
335 case Animation::BETWEEN:
339 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
341 value.Get(mDecoratedPropertyCache.mCornerRadius);
344 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
346 value.Get(mDecoratedPropertyCache.mBorderlineWidth);
349 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
351 value.Get(mDecoratedPropertyCache.mBorderlineColor);
354 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
356 value.Get(mDecoratedPropertyCache.mBorderlineOffset);
359 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
361 value.Get(mDecoratedPropertyCache.mBlurRadius);
372 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
374 AdjustValue<Vector4>(mDecoratedPropertyCache.mCornerRadius, value);
377 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
379 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineWidth, value);
382 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
384 AdjustValue<Vector4>(mDecoratedPropertyCache.mBorderlineColor, value);
387 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
389 AdjustValue<float>(mDecoratedPropertyCache.mBorderlineOffset, value);
392 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
394 AdjustValue<float>(mDecoratedPropertyCache.mBlurRadius, value);
404 const SceneGraph::PropertyBase* DecoratedVisualRenderer::GetSceneObjectAnimatableProperty(Property::Index index) const
406 const SceneGraph::PropertyBase* property = nullptr;
410 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS:
412 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
415 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
416 if(decoratedVisualProperties)
418 property = &decoratedVisualProperties->mCornerRadius;
423 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH:
425 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
428 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
429 if(decoratedVisualProperties)
431 property = &decoratedVisualProperties->mBorderlineWidth;
436 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR:
438 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
441 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
442 if(decoratedVisualProperties)
444 property = &decoratedVisualProperties->mBorderlineColor;
449 case Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET:
451 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
454 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
455 if(decoratedVisualProperties)
457 property = &decoratedVisualProperties->mBorderlineOffset;
462 case Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS:
464 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
467 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
468 if(decoratedVisualProperties)
470 property = &decoratedVisualProperties->mBlurRadius;
479 // not our property, ask base
480 property = VisualRenderer::GetSceneObjectAnimatableProperty(index);
486 const PropertyInputImpl* DecoratedVisualRenderer::GetSceneObjectInputProperty(Property::Index index) const
488 if(index < Dali::DecoratedVisualRenderer::Property::DEFAULT_DECORATED_VISUAL_RENDERER_PROPERTY_START_INDEX)
490 return VisualRenderer::GetSceneObjectInputProperty(index);
494 case Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY:
496 auto visualProperties = GetVisualRendererSceneObject().GetVisualProperties();
499 auto decoratedVisualProperties = static_cast<SceneGraph::VisualRenderer::AnimatableDecoratedVisualProperties*>(visualProperties->mExtendedProperties);
500 if(decoratedVisualProperties)
502 return &decoratedVisualProperties->mCornerRadiusPolicy;
509 return GetSceneObjectAnimatableProperty(index);
515 void DecoratedVisualRenderer::RegisterCornerRadiusUniform()
517 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS);
520 void DecoratedVisualRenderer::RegisterBorderlineUniform()
522 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BORDERLINE);
525 void DecoratedVisualRenderer::RegisterBlurRadiusUniform()
527 AddUniformFlag(DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS);
530 void DecoratedVisualRenderer::AddUniformFlag(uint8_t newAddFlag)
532 const uint8_t diffUniformFlag = (~mAddUniformFlag) & newAddFlag;
535 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS)
537 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS, ConstString("cornerRadius"));
538 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, ConstString("cornerRadiusPolicy"));
540 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BORDERLINE)
542 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, ConstString("borderlineWidth"));
543 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_COLOR, ConstString("borderlineColor"));
544 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, ConstString("borderlineOffset"));
546 if(diffUniformFlag & DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS)
548 AddUniformMapping(Dali::DecoratedVisualRenderer::Property::BLUR_RADIUS, ConstString("blurRadius"));
551 // Note. Let we don't remove UniformMapping due to the performane issue.
552 mAddUniformFlag |= newAddFlag;
556 } // namespace Internal