From b1bd91ad6eb1a77a75f3d10b8e2f05af4bfa39f1 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 25 Jan 2022 11:00:59 +0000 Subject: [PATCH] Adding Handle::ReserveCustomProperties method Change-Id: I2baa3a77e2db557a6a755e66105530cbe72ac442 --- automated-tests/src/dali/utc-Dali-Handle.cpp | 40 ++++++++++++++++++++++ dali/internal/event/common/object-impl.cpp | 7 ++++ dali/internal/event/common/object-impl.h | 5 +++ .../update/common/property-owner-messages.h | 12 ++++++- dali/internal/update/common/property-owner.cpp | 7 +++- dali/internal/update/common/property-owner.h | 7 +++- dali/public-api/object/handle.cpp | 5 +++ dali/public-api/object/handle.h | 10 ++++++ 8 files changed, 90 insertions(+), 3 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index e66312f..3c991ec 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -2030,6 +2030,46 @@ int UtcDaliHandleGetProperties(void) END_TEST; } +int UtcDaliHandleReserveProperties(void) +{ + TestApplication application; + Dali::Handle instance = Handle::New(); + DALI_TEST_EQUALS(instance.GetPropertyCount(), 0, TEST_LOCATION); + + instance.ReserveCustomProperties(0); + DALI_TEST_EQUALS(instance.GetPropertyCount(), 0, TEST_LOCATION); + + instance.ReserveCustomProperties(20); + DALI_TEST_EQUALS(instance.GetPropertyCount(), 0, TEST_LOCATION); + + instance.RegisterProperty("testProperty", 22.0f); + DALI_TEST_EQUALS(instance.GetPropertyCount(), 1, TEST_LOCATION); + + // Test that reserving actor properties doesn't change property count + Dali::Actor actor = Actor::New(); + auto count = actor.GetPropertyCount(); + + actor.ReserveCustomProperties(15); + DALI_TEST_EQUALS(actor.GetPropertyCount(), count, TEST_LOCATION); + + // Test that reserving renderer properties doesn't change property count + Geometry geom = Geometry::New(); + Shader shader = Shader::New("vertex", "frag"); + Dali::Renderer renderer = Renderer::New(geom, shader); + count = renderer.GetPropertyCount(); + renderer.ReserveCustomProperties(22); + DALI_TEST_EQUALS(renderer.GetPropertyCount(), count, TEST_LOCATION); + + count = shader.GetPropertyCount(); + shader.ReserveCustomProperties(5); + DALI_TEST_EQUALS(shader.GetPropertyCount(), count, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + int UtcDaliHandleSetPropertyNegative(void) { TestApplication application; diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index dec0470..da251d7 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -567,6 +567,13 @@ void Object::GetProperties(Property::Map& properties) } } +void Object::ReserveCustomProperties(int propertyCount) +{ + mCustomProperties.Reserve(propertyCount); + const SceneGraph::PropertyOwner& sceneObject = GetSceneObject(); + ReservePropertiesMessage(const_cast(GetEventThreadServices()), sceneObject, propertyCount); +} + Property::Index Object::RegisterProperty(std::string_view name, Property::Value propertyValue) { return RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), Property::ANIMATABLE, true); diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index 702c12b..91143c1 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -232,6 +232,11 @@ public: void GetProperties(Property::Map& properties); /** + * @copydoc Dali::Handle::ReserveCustomProperties() + */ + void ReserveCustomProperties(int propertyCount); + + /** * @copydoc Dali::Handle::RegisterProperty() */ Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue); diff --git a/dali/internal/update/common/property-owner-messages.h b/dali/internal/update/common/property-owner-messages.h index 39ae6a0..d6d24e2 100644 --- a/dali/internal/update/common/property-owner-messages.h +++ b/dali/internal/update/common/property-owner-messages.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_MESSAGES_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -268,6 +268,16 @@ inline void RemoveUniformMapMessage(EventThreadServices& eventThreadServices, co new(slot) LocalType(&owner, &PropertyOwner::RemoveUniformMapping, uniformName); } +inline void ReservePropertiesMessage(EventThreadServices& eventThreadServices, const PropertyOwner& owner, int propertyCount) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + new(slot) LocalType(&owner, &PropertyOwner::ReserveProperties, propertyCount); +} + } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/update/common/property-owner.cpp b/dali/internal/update/common/property-owner.cpp index 51a7dc6..e23831f 100644 --- a/dali/internal/update/common/property-owner.cpp +++ b/dali/internal/update/common/property-owner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,6 +113,11 @@ void PropertyOwner::DisconnectFromSceneGraph(BufferIndex updateBufferIndex) mConstraints.Clear(); } +void PropertyOwner::ReserveProperties(int propertyCount) +{ + mCustomProperties.Reserve(propertyCount); +} + void PropertyOwner::InstallCustomProperty(OwnerPointer& property) { mCustomProperties.PushBack(property.Release()); diff --git a/dali/internal/update/common/property-owner.h b/dali/internal/update/common/property-owner.h index 36a835b..1d3fee7 100644 --- a/dali/internal/update/common/property-owner.h +++ b/dali/internal/update/common/property-owner.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -129,6 +129,11 @@ public: void DisconnectFromSceneGraph(BufferIndex updateBufferIndex); /** + * Reserve the given number of properties + */ + void ReserveProperties(int propertyCount); + + /** * Install a custom property. * @post The PropertyOwner takes ownership of the property. * @param[in] property A pointer to a newly allocated property. diff --git a/dali/public-api/object/handle.cpp b/dali/public-api/object/handle.cpp index ecac036..002b7be 100644 --- a/dali/public-api/object/handle.cpp +++ b/dali/public-api/object/handle.cpp @@ -100,6 +100,11 @@ void Handle::SetProperty(Property::Index index, Property::Value propertyValue) GetImplementation(*this).SetProperty(index, std::move(propertyValue)); } +void Handle::ReserveCustomProperties(int propertyCount) +{ + GetImplementation(*this).ReserveCustomProperties(propertyCount); +} + Property::Index Handle::RegisterProperty(std::string_view name, Property::Value propertyValue) { return GetImplementation(*this).RegisterProperty(name, std::move(propertyValue)); diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index 65604f1..549d274 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -266,6 +266,16 @@ public: void SetProperty(Property::Index index, Property::Value propertyValue); /** + * @brief Reserves a number of custom properties + * + * Saves automatic re-allocation of vectors for properties when we know in advance how many there + * will be. + * + * @param[in] propertyCount The total number of initial properties. + */ + void ReserveCustomProperties(int propertyCount); + + /** * @brief Registers a new animatable property. * * @SINCE_1_0.0 -- 2.7.4