Add API to UpdateProxy 53/274253/3
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 25 Apr 2022 09:39:06 +0000 (18:39 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 6 May 2022 03:07:51 +0000 (12:07 +0900)
Change-Id: Icd9ef2011a6381ccad62a9f3edea750e392500ae

automated-tests/src/dali/utc-Dali-FrameCallbackInterface.cpp
dali/devel-api/update/update-proxy.cpp
dali/devel-api/update/update-proxy.h
dali/internal/update/manager/update-proxy-impl.cpp
dali/internal/update/manager/update-proxy-impl.h

index f2917ac..23f415f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
@@ -72,6 +72,7 @@ public:
     updateProxy.GetSize(mActorId, mSizeGetSizeCall);
     updateProxy.GetPosition(mActorId, mPositionGetPositionCall);
     updateProxy.GetPositionAndSize(mActorId, mPositionGetPositionAndSizeCall, mSizeGetPositionAndSizeCall);
+    updateProxy.GetWorldPositionScaleAndSize(mActorId, mWorldPosition, mWorldScale, mSizeGetWorldPositionScaleAndSizeCall);
     updateProxy.GetColor(mActorId, mColor);
     updateProxy.GetScale(mActorId, mScale);
   }
@@ -82,6 +83,9 @@ public:
   Vector3 mPositionGetPositionCall;
   Vector3 mPositionGetPositionAndSizeCall;
   Vector3 mSizeGetPositionAndSizeCall;
+  Vector3 mWorldPosition;
+  Vector3 mWorldScale;
+  Vector3 mSizeGetWorldPositionScaleAndSizeCall;
   Vector4 mColor;
   Vector3 mScale;
 };
@@ -105,6 +109,7 @@ public:
 
   virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override
   {
+    Vector3 size;
     FrameCallbackBasic::Update(updateProxy, elapsedSeconds);
     updateProxy.SetSize(mActorId, mSizeToSet);
     updateProxy.SetPosition(mActorId, mPositionToSet);
@@ -147,6 +152,7 @@ public:
 
   virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds) override
   {
+    Vector3 size;
     FrameCallbackBasic::Update(updateProxy, elapsedSeconds);
     updateProxy.BakeSize(mActorId, mSizeToSet);
     updateProxy.BakePosition(mActorId, mPositionToSet);
@@ -210,19 +216,20 @@ public:
     Vector3 vec3;
     Vector4 vec4;
 
-    mGetSizeCallSuccess            = updateProxy.GetSize(mActorId, vec3);
-    mGetPositionCallSuccess        = updateProxy.GetPosition(mActorId, vec3);
-    mGetColorCallSuccess           = updateProxy.GetColor(mActorId, vec4);
-    mGetScaleCallSuccess           = updateProxy.GetScale(mActorId, vec3);
-    mGetPositionAndSizeCallSuccess = updateProxy.GetPositionAndSize(mActorId, vec3, vec3);
-    mSetSizeCallSuccess            = updateProxy.SetSize(mActorId, vec3);
-    mSetPositionCallSuccess        = updateProxy.SetPosition(mActorId, vec3);
-    mSetColorCallSuccess           = updateProxy.SetColor(mActorId, vec4);
-    mSetScaleCallSuccess           = updateProxy.SetScale(mActorId, vec3);
-    mBakeSizeCallSuccess           = updateProxy.BakeSize(mActorId, vec3);
-    mBakePositionCallSuccess       = updateProxy.BakePosition(mActorId, vec3);
-    mBakeColorCallSuccess          = updateProxy.BakeColor(mActorId, vec4);
-    mBakeScaleCallSuccess          = updateProxy.BakeScale(mActorId, vec3);
+    mGetSizeCallSuccess                      = updateProxy.GetSize(mActorId, vec3);
+    mGetPositionCallSuccess                  = updateProxy.GetPosition(mActorId, vec3);
+    mGetColorCallSuccess                     = updateProxy.GetColor(mActorId, vec4);
+    mGetScaleCallSuccess                     = updateProxy.GetScale(mActorId, vec3);
+    mGetPositionAndSizeCallSuccess           = updateProxy.GetPositionAndSize(mActorId, vec3, vec3);
+    mGetWorldPositionScaleAndSizeCallSuccess = updateProxy.GetWorldPositionScaleAndSize(mActorId, vec3, vec3, vec3);
+    mSetSizeCallSuccess                      = updateProxy.SetSize(mActorId, vec3);
+    mSetPositionCallSuccess                  = updateProxy.SetPosition(mActorId, vec3);
+    mSetColorCallSuccess                     = updateProxy.SetColor(mActorId, vec4);
+    mSetScaleCallSuccess                     = updateProxy.SetScale(mActorId, vec3);
+    mBakeSizeCallSuccess                     = updateProxy.BakeSize(mActorId, vec3);
+    mBakePositionCallSuccess                 = updateProxy.BakePosition(mActorId, vec3);
+    mBakeColorCallSuccess                    = updateProxy.BakeColor(mActorId, vec4);
+    mBakeScaleCallSuccess                    = updateProxy.BakeScale(mActorId, vec3);
   }
 
   virtual void Reset() override
@@ -230,19 +237,20 @@ public:
     // Up-call
     FrameCallbackBasic::Reset();
 
-    mGetSizeCallSuccess            = false;
-    mGetPositionCallSuccess        = false;
-    mGetColorCallSuccess           = false;
-    mGetScaleCallSuccess           = false;
-    mGetPositionAndSizeCallSuccess = false;
-    mSetSizeCallSuccess            = false;
-    mSetPositionCallSuccess        = false;
-    mSetColorCallSuccess           = false;
-    mSetScaleCallSuccess           = false;
-    mBakeSizeCallSuccess           = false;
-    mBakePositionCallSuccess       = false;
-    mBakeColorCallSuccess          = false;
-    mBakeScaleCallSuccess          = false;
+    mGetSizeCallSuccess                      = false;
+    mGetPositionCallSuccess                  = false;
+    mGetColorCallSuccess                     = false;
+    mGetScaleCallSuccess                     = false;
+    mGetPositionAndSizeCallSuccess           = false;
+    mGetWorldPositionScaleAndSizeCallSuccess = false;
+    mSetSizeCallSuccess                      = false;
+    mSetPositionCallSuccess                  = false;
+    mSetColorCallSuccess                     = false;
+    mSetScaleCallSuccess                     = false;
+    mBakeSizeCallSuccess                     = false;
+    mBakePositionCallSuccess                 = false;
+    mBakeColorCallSuccess                    = false;
+    mBakeScaleCallSuccess                    = false;
   }
 
   const uint32_t mActorId;
@@ -251,6 +259,7 @@ public:
   bool           mGetColorCallSuccess{false};
   bool           mGetScaleCallSuccess{false};
   bool           mGetPositionAndSizeCallSuccess{false};
+  bool           mGetWorldPositionScaleAndSizeCallSuccess{false};
   bool           mSetSizeCallSuccess{false};
   bool           mSetPositionCallSuccess{false};
   bool           mSetColorCallSuccess{false};
@@ -328,6 +337,22 @@ int UtcDaliFrameCallbackGetters(void)
   DALI_TEST_EQUALS(frameCallback.mColor, color, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mScale, scale, TEST_LOCATION);
 
+  frameCallback.Reset();
+
+  application.SendNotification();
+  application.Render();
+
+  Vector2 halfSceneSize(application.GetScene().GetSize() * 0.5f);
+  Vector3 halfActorSize(actorSize * 0.5f);
+  Vector3 worldPosition = position - Vector3(halfSceneSize) + halfActorSize * scale;
+
+  // World position and scale values are updated after FrameCallbackInterface::Update()
+  // So test them after the second rendering
+  DALI_TEST_EQUALS(frameCallback.mCalled, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mWorldPosition, worldPosition, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mWorldScale, scale, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mSizeGetWorldPositionScaleAndSizeCall, Vector3(actorSize.width, actorSize.height, 0.0f), TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -618,9 +643,11 @@ int UtcDaliFrameCallbackCheckActorNotAdded(void)
   // All should be default constructed objects
   DALI_TEST_EQUALS(frameCallback.mCalled, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mPositionGetPositionCall, Vector3::ZERO, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mWorldPosition, Vector3::ZERO, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSizeGetSizeCall, Vector3::ZERO, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mColor, Vector4::ZERO, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mScale, Vector3::ZERO, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mWorldScale, Vector3::ZERO, TEST_LOCATION);
 
   END_TEST;
 }
@@ -646,6 +673,7 @@ int UtcDaliFrameCallbackInvalidActorId(void)
   DALI_TEST_EQUALS(frameCallback.mGetColorCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetScaleCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetPositionAndSizeCallSuccess, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mGetWorldPositionScaleAndSizeCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetSizeCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetPositionCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetColorCallSuccess, false, TEST_LOCATION);
@@ -683,6 +711,7 @@ int UtcDaliFrameCallbackActorRemovedAndAdded(void)
   DALI_TEST_EQUALS(frameCallback.mGetColorCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetScaleCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetPositionAndSizeCallSuccess, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mGetWorldPositionScaleAndSizeCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetSizeCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetPositionCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetColorCallSuccess, true, TEST_LOCATION);
@@ -706,6 +735,7 @@ int UtcDaliFrameCallbackActorRemovedAndAdded(void)
   DALI_TEST_EQUALS(frameCallback.mGetColorCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetScaleCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetPositionAndSizeCallSuccess, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mGetWorldPositionScaleAndSizeCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetSizeCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetPositionCallSuccess, false, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetColorCallSuccess, false, TEST_LOCATION);
@@ -729,6 +759,7 @@ int UtcDaliFrameCallbackActorRemovedAndAdded(void)
   DALI_TEST_EQUALS(frameCallback.mGetColorCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetScaleCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mGetPositionAndSizeCallSuccess, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(frameCallback.mGetWorldPositionScaleAndSizeCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetSizeCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetPositionCallSuccess, true, TEST_LOCATION);
   DALI_TEST_EQUALS(frameCallback.mSetColorCallSuccess, true, TEST_LOCATION);
index a79159b..b157d09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
@@ -58,6 +58,11 @@ bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& si
   return mImpl.GetPositionAndSize(id, position, size);
 }
 
+bool UpdateProxy::GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const
+{
+  return mImpl.GetWorldPositionScaleAndSize(id, position, scale, size);
+}
+
 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
 {
   return mImpl.GetScale(id, scale);
index 8a66dab..0698b9a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_UPDATE_PROXY_H
 
 /*
- * Copyright (c) 2020 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.
@@ -107,6 +107,16 @@ public:
   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
 
   /**
+   * @brief Given the Actor ID, this retrieves that Actor's world position and size.
+   * @param[in]   id        The Actor ID
+   * @param[out]  position  Set to the Actor's current world position, if Actor ID is valid
+   * @param[out]  scale     Set to the Actor's current world scale, if Actor ID is valid
+   * @param[out]  size      Set to the Actor's current size, if Actor ID is valid
+   * @return Whether the method call was successful or not.
+   */
+  bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
+
+  /**
    * @brief Given the Actor ID, this retrieves that Actor's local scale.
    * @param[in]   id     The Actor ID
    * @param[out]  scale  Set to the Actor's current scale, if Actor ID is valid
index f5a387e..2a995c6 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.
@@ -154,6 +154,24 @@ bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& si
   return success;
 }
 
+bool UpdateProxy::GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const
+{
+  bool                    success = false;
+  const SceneGraph::Node* node    = GetNodeWithId(id);
+  if(node)
+  {
+    const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
+    const Matrix&                       worldMatrix      = transformManager.GetWorldMatrix(node->GetTransformId());
+
+    Quaternion orientation;
+    worldMatrix.GetTransformComponents(position, orientation, scale);
+
+    size    = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
+    success = true;
+  }
+  return success;
+}
+
 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
 {
   bool                    success = false;
index 9a45c9f..7ae5655 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_UPDATE_PROXY_IMPL_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.
@@ -105,6 +105,11 @@ public:
   bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
 
   /**
+   * @copydoc Dali::UpdateProxy::GetWorldPositionScaleAndSize()
+   */
+  bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
+
+  /**
    * @copydoc Dali::UpdateProxy::GetScale()
    */
   bool GetScale(uint32_t id, Vector3& scale) const;