Merge "Add ResourceReady for Control" into devel/master
authorSeungho BAEK <sbsh.baek@samsung.com>
Fri, 16 Sep 2022 07:31:27 +0000 (07:31 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 16 Sep 2022 07:31:27 +0000 (07:31 +0000)
12 files changed:
automated-tests/src/dali-scene3d/utc-Dali-ModelView.cpp
automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp
automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp
dali-scene3d/internal/controls/model-view/model-view-impl.cpp
dali-scene3d/internal/controls/model-view/model-view-impl.h
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.h
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/control/control-data-impl.h
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control-impl.h
dali-toolkit/public-api/controls/control.cpp

index 1b9833d..6e3d08f 100644 (file)
@@ -569,4 +569,48 @@ int UtcDaliModelViewAnimation02(void)
   DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
 
   END_TEST;
-}
\ No newline at end of file
+}
+
+// For ResourceReady
+namespace
+{
+static bool gOnRelayoutCallBackCalled = false;
+void OnRelayoutCallback(Actor actor)
+{
+  gOnRelayoutCallBackCalled = true;
+}
+
+static bool gResourceReadyCalled = false;
+void OnResourceReady(Control control)
+{
+  gResourceReadyCalled = true;
+}
+}
+
+int UtcDaliModelViewResourceReady(void)
+{
+  ToolkitTestApplication application;
+
+  gOnRelayoutCallBackCalled = false;
+  gResourceReadyCalled = false;
+  Scene3D::ModelView model = Scene3D::ModelView::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
+  model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  model.OnRelayoutSignal().Connect(OnRelayoutCallback);
+  model.ResourceReadySignal().Connect(OnResourceReady);
+  DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
+
+  // Sanity check
+  DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
+  DALI_TEST_CHECK(!gResourceReadyCalled);
+
+  application.GetScene().Add(model);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  END_TEST;
+}
index 7cabdcd..a6a8332 100644 (file)
@@ -503,3 +503,59 @@ int UtcDaliSceneViewUseFramebuffer02(void)
 
   END_TEST;
 }
+
+// For ResourceReady
+namespace
+{
+static bool gOnRelayoutCallBackCalled = false;
+void OnRelayoutCallback(Actor actor)
+{
+  gOnRelayoutCallBackCalled = true;
+}
+
+static bool gResourceReadyCalled = false;
+void OnResourceReady(Control control)
+{
+  gResourceReadyCalled = true;
+}
+}
+
+int UtcDaliSceneViewResourceReady(void)
+{
+  ToolkitTestApplication application;
+
+  gOnRelayoutCallBackCalled = false;
+  gResourceReadyCalled = false;
+  Scene3D::SceneView view = Scene3D::SceneView::New();
+  view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  view.OnRelayoutSignal().Connect(OnRelayoutCallback);
+  view.ResourceReadySignal().Connect(OnResourceReady);
+  // SceneView::IsResourceReady() returns true by default.
+  DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
+
+  // Sanity check
+  DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
+  DALI_TEST_CHECK(!gResourceReadyCalled);
+
+  application.GetScene().Add(view);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+
+  gOnRelayoutCallBackCalled = false;
+  gResourceReadyCalled = false;
+
+  view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  END_TEST;
+}
index f243709..827703d 100644 (file)
@@ -1167,3 +1167,70 @@ int UtcDaliControlImplOnPinch(void)
 
   END_TEST;
 }
+
+// For ResourceReady
+namespace
+{
+static bool gOnRelayoutCallBackCalled = false;
+void OnRelayoutCallback(Actor actor)
+{
+  gOnRelayoutCallBackCalled = true;
+}
+
+static bool gResourceReadyCalled = false;
+void OnResourceReady(Control control)
+{
+  gResourceReadyCalled = true;
+}
+}
+
+int UtcDaliControlImplResourceReady(void)
+{
+  ToolkitTestApplication application;
+
+  gOnRelayoutCallBackCalled = false;
+  gResourceReadyCalled = false;
+  Control control = Control::New();
+  control.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+  control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  control.OnRelayoutSignal().Connect(OnRelayoutCallback);
+  control.ResourceReadySignal().Connect(OnResourceReady);
+  application.GetScene().Add(control);
+
+  // Sanity check
+  DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
+  DALI_TEST_CHECK(!gResourceReadyCalled);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
+  gOnRelayoutCallBackCalled = false;
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
+  Toolkit::Internal::Control& impl = Toolkit::Internal::GetImplementation(control);
+  // ResourceReady is true when there is no visual in the default Toolkit::Internal::Control.
+  DALI_TEST_EQUALS(impl.IsResourceReady(), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+  impl.SetResourceReady(false);
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
+  gResourceReadyCalled = false;
+  DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
+  impl.SetResourceReady(true);
+  DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
+
+  END_TEST;
+}
index 61a5303..06ed187 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 #include <dali/integration-api/debug.h>
@@ -29,8 +28,8 @@
 #include <filesystem>
 
 // INTERNAL INCLUDES
-#include <dali-scene3d/public-api/controls/model-view/model-view.h>
 #include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
+#include <dali-scene3d/public-api/controls/model-view/model-view.h>
 #include <dali-scene3d/public-api/loader/animation-definition.h>
 #include <dali-scene3d/public-api/loader/camera-parameters.h>
 #include <dali-scene3d/public-api/loader/cube-map-loader.h>
@@ -173,7 +172,7 @@ void AddModelTreeToAABB(BoundingVolume& AABB, const Dali::Scene3D::Loader::Scene
 } // anonymous namespace
 
 ModelView::ModelView(const std::string& modelPath, const std::string& resourcePath)
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+: Control(ControlBehaviour(DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS)),
   mModelPath(modelPath),
   mResourcePath(resourcePath),
   mModelRoot(),
@@ -181,7 +180,9 @@ ModelView::ModelView(const std::string& modelPath, const std::string& resourcePa
   mModelPivot(AnchorPoint::CENTER),
   mIblScaleFactor(1.0f),
   mFitSize(true),
-  mFitCenter(true)
+  mFitCenter(true),
+  mModelResourceReady(false),
+  mIBLResourceReady(true)
 {
 }
 
@@ -221,9 +222,18 @@ void ModelView::FitCenter(bool fit)
 
 void ModelView::SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor)
 {
+  mIBLResourceReady = false;
   Texture diffuseTexture  = Dali::Scene3D::Loader::LoadCubeMap(diffuse);
   Texture specularTexture = Dali::Scene3D::Loader::LoadCubeMap(specular);
   SetImageBasedLightTexture(diffuseTexture, specularTexture, scaleFactor);
+  mIBLResourceReady = true;
+
+  // If Model resource is already ready, then set resource ready.
+  // If Model resource is still not ready, wait for model resource ready.
+  if(IsResourceReady())
+  {
+    SetResourceReady(false);
+  }
 }
 
 void ModelView::SetImageBasedLightTexture(Dali::Texture diffuse, Dali::Texture specular, float scaleFactor)
@@ -339,6 +349,11 @@ void ModelView::OnRelayout(const Vector2& size, RelayoutContainer& container)
   ScaleModel();
 }
 
+bool ModelView::IsResourceReady() const
+{
+  return mModelResourceReady && mIBLResourceReady;
+}
+
 void ModelView::LoadModel()
 {
   std::filesystem::path modelPath(mModelPath);
@@ -464,6 +479,10 @@ void ModelView::LoadModel()
 
   Self().SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   Self().SetProperty(Dali::Actor::Property::ANCHOR_POINT, Vector3(mModelPivot.x, 1.0f - mModelPivot.y, mModelPivot.z));
+
+  mModelResourceReady = true;
+
+  Control::SetResourceReady(false);
 }
 
 void ModelView::ScaleModel()
index 10d04f2..2ec360f 100644 (file)
@@ -135,6 +135,11 @@ private:
   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
 
   /**
+   * @copydoc Toolkit::Control::IsResourceReady()
+   */
+  bool IsResourceReady() const override;
+
+  /**
    * @brief Loads a model from file
    */
   void LoadModel();
@@ -174,6 +179,8 @@ private:
   float         mIblScaleFactor;
   bool          mFitSize;
   bool          mFitCenter;
+  bool          mModelResourceReady;
+  bool          mIBLResourceReady;
 };
 
 } // namespace Internal
index b230f86..99ddef2 100644 (file)
@@ -188,6 +188,7 @@ void SceneView::UnregisterModelView(Scene3D::ModelView modelView)
 
 void SceneView::SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor)
 {
+  mIBLResourceReady = false;
   Texture diffuseTexture = Dali::Scene3D::Loader::LoadCubeMap(diffuse);
   if(diffuseTexture)
   {
@@ -207,6 +208,8 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuse, const std::
       }
     }
   }
+  mIBLResourceReady = true;
+  Control::SetResourceReady(false);
 }
 
 void SceneView::UseFramebuffer(bool useFramebuffer)
@@ -305,6 +308,11 @@ void SceneView::OnRelayout(const Vector2& size, RelayoutContainer& container)
   UpdateRenderTask();
 }
 
+bool SceneView::IsResourceReady() const
+{
+  return mIBLResourceReady;
+}
+
 void SceneView::UpdateCamera(CameraActor camera)
 {
   if(camera)
index 724bc7d..e3de91e 100644 (file)
@@ -178,6 +178,11 @@ private:
   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
 
   /**
+   * @copydoc Toolkit::Control::IsResourceReady()
+   */
+  bool IsResourceReady() const override;
+
+  /**
    * @brief Changes main camera as a input camera
    *
    * @param camera CameraActor that will be a main camera of the SceneView
@@ -208,6 +213,7 @@ private:
   Dali::Texture mDiffuseTexture;
   float         mIblScaleFactor{1.0f};
   bool          mUseFrameBuffer{false};
+  bool          mIBLResourceReady{true};
 
   // TODO : Light Source
 };
index 4c74704..84d44b9 100644 (file)
@@ -909,6 +909,24 @@ void Control::Impl::StartObservingVisual(Toolkit::Visual::Base& visual)
   visualImpl.AddEventObserver(*this);
 }
 
+void Control::Impl::ResourceReady(bool relayoutRequest)
+{
+  Actor self = mControlImpl.Self();
+  // A visual is ready so control may need relayouting if staged
+  if(relayoutRequest && self.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
+  {
+    mControlImpl.RelayoutRequest();
+  }
+
+  // Emit signal if all enabled visuals registered by the control are ready or there are no visuals.
+  if(IsResourceReady())
+  {
+    // Reset the flag
+    mNeedToEmitResourceReady = false;
+    EmitResourceReadySignal();
+  }
+}
+
 // Called by a Visual when it's resource is ready
 void Control::Impl::ResourceReady(Visual::Base& object)
 {
@@ -938,20 +956,8 @@ void Control::Impl::ResourceReady(Visual::Base& object)
     }
   }
 
-  // A visual is ready so control may need relayouting if staged
-  if(self.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
-  {
-    mControlImpl.RelayoutRequest();
-  }
-
-  // Emit signal if all enabled visuals registered by the control are ready.
-  if(IsResourceReady())
-  {
-    // Reset the flag
-    mNeedToEmitResourceReady = false;
-
-    EmitResourceReadySignal();
-  }
+  // Called by a Visual when it's resource is ready
+  ResourceReady(true);
 }
 
 void Control::Impl::NotifyVisualEvent(Visual::Base& object, Property::Index signalId)
index 46cc97b..421d69d 100644 (file)
@@ -126,6 +126,12 @@ public:
   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
 
   /**
+   * @brief Called when resources of control are ready.
+   * @param[in] relayoutRequest True to request relayout
+   */
+  void ResourceReady(bool relayoutRequest);
+
+  /**
    * @brief Called when a resource is ready.
    * @param[in] object The visual whose resources are ready
    * @note Overriding method in Visual::EventObserver.
index 60efa05..6019285 100644 (file)
@@ -167,6 +167,12 @@ void Control::ClearBackground()
   RelayoutRequest();
 }
 
+void Control::SetResourceReady(bool relayoutRequest)
+{
+  Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
+  controlDataImpl.ResourceReady(relayoutRequest);
+}
+
 Toolkit::DevelControl::ControlAccessible* Control::GetAccessibleObject()
 {
   return mImpl->GetAccessibleObject();
@@ -450,6 +456,12 @@ void Control::OnInitialize()
 {
 }
 
+bool Control::IsResourceReady() const
+{
+  const Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
+  return controlDataImpl.IsResourceReady();
+}
+
 void Control::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
 {
   // By default the control is only interested in theme (not font) changes
index 9ccb533..4db0504 100644 (file)
@@ -115,6 +115,12 @@ public:
    */
   void ClearBackground();
 
+  /**
+   * @brief Called when resources of control are ready.
+   * @param[in] relayoutRequest True to request relayout
+   */
+  void SetResourceReady(bool relayoutRequest);
+
   // Accessibility
 
   /**
@@ -456,6 +462,11 @@ public: // API for derived classes to override
    */
   virtual void OnInitialize();
 
+  /**
+   * @copydoc Dali::Toolkit::Control::IsResourceReady
+   */
+  virtual bool IsResourceReady() const;
+
   // Styling
 
   /**
index 245bdd5..f411d4d 100644 (file)
@@ -117,10 +117,7 @@ void Control::ClearBackground()
 
 bool Control::IsResourceReady() const
 {
-  const Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(*this);
-  const Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(internalControl);
-
-  return controlDataImpl.IsResourceReady();
+  return Internal::GetImplementation(*this).IsResourceReady();
 }
 
 Toolkit::Visual::ResourceStatus Control::GetVisualResourceStatus(Dali::Property::Index index)