Adding Handle::ReserveCustomProperties method 97/270097/1
authorDavid Steele <david.steele@samsung.com>
Tue, 25 Jan 2022 11:00:59 +0000 (11:00 +0000)
committerDavid Steele <david.steele@samsung.com>
Tue, 25 Jan 2022 11:09:07 +0000 (11:09 +0000)
Change-Id: I2baa3a77e2db557a6a755e66105530cbe72ac442

automated-tests/src/dali/utc-Dali-Handle.cpp
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/object-impl.h
dali/internal/update/common/property-owner-messages.h
dali/internal/update/common/property-owner.cpp
dali/internal/update/common/property-owner.h
dali/public-api/object/handle.cpp
dali/public-api/object/handle.h

index e66312f..3c991ec 100644 (file)
@@ -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;
index dec0470..da251d7 100644 (file)
@@ -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<EventThreadServices&>(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);
index 702c12b..91143c1 100644 (file)
@@ -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);
index 39ae6a0..d6d24e2 100644 (file)
@@ -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<PropertyOwner, int>;
+
+  // 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
index 51a7dc6..e23831f 100644 (file)
@@ -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<PropertyBase>& property)
 {
   mCustomProperties.PushBack(property.Release());
index 36a835b..1d3fee7 100644 (file)
@@ -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.
index ecac036..002b7be 100644 (file)
@@ -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));
index 65604f1..549d274 100644 (file)
@@ -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