Skip call resourceReady() for disabled visual 28/293028/7
authorsunghyun kim <scholb.kim@samsung.com>
Thu, 18 May 2023 07:35:28 +0000 (16:35 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Tue, 23 May 2023 11:38:47 +0000 (20:38 +0900)
for disabled visuals, ResourceReady is not called.

Change-Id: I9864cde4bffeb1eab5c11812f6911c1772692a4a

automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
dali-scene3d/internal/controls/model/model-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
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

index 827703d..3d21701 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -1172,25 +1172,25 @@ int UtcDaliControlImplOnPinch(void)
 namespace
 {
 static bool gOnRelayoutCallBackCalled = false;
-void OnRelayoutCallback(Actor actor)
+void        OnRelayoutCallback(Actor actor)
 {
   gOnRelayoutCallBackCalled = true;
 }
 
 static bool gResourceReadyCalled = false;
-void OnResourceReady(Control control)
+void        OnResourceReady(Control control)
 {
   gResourceReadyCalled = true;
 }
-}
+} // namespace
 
 int UtcDaliControlImplResourceReady(void)
 {
   ToolkitTestApplication application;
 
   gOnRelayoutCallBackCalled = false;
-  gResourceReadyCalled = false;
-  Control control = Control::New();
+  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);
@@ -1215,7 +1215,7 @@ int UtcDaliControlImplResourceReady(void)
   // 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);
+  impl.SetResourceReady();
   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
 
   application.SendNotification();
@@ -1224,13 +1224,13 @@ int UtcDaliControlImplResourceReady(void)
   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
   gResourceReadyCalled = false;
   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
-  impl.SetResourceReady(true);
+  impl.SetResourceReady();
   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
 
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
 
   END_TEST;
 }
index 1487961..ccc8eae 100644 (file)
@@ -4370,7 +4370,7 @@ int UtcDaliImageViewNpatchImageCacheTest02(void)
   END_TEST;
 }
 
-int UtcDaliImageViewPlaceholderImage(void)
+int UtcDaliImageViewPlaceholderImage01(void)
 {
   tet_infoline("Test imageView use placeholder image");
 
@@ -4446,6 +4446,52 @@ int UtcDaliImageViewPlaceholderImage(void)
   END_TEST;
 }
 
+int UtcDaliImageViewPlaceholderImage02(void)
+{
+  tet_infoline("Test imageView use placeholder image without resource ready");
+
+  ToolkitTestApplication application;
+
+  Property::Map map;
+  map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
+
+  ImageView imageView = ImageView::New();
+  imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
+  imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
+  DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
+  imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
+  application.GetScene().Add(imageView);
+
+  Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
+  std::string     url;
+  DALI_TEST_CHECK(value.Get(url));
+  DALI_TEST_CHECK(url.empty());
+
+  imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
+  DALI_TEST_CHECK(value.Get(url));
+  DALI_TEST_CHECK(url == gImage_34_RGBA);
+
+  DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
+
+  gResourceReadySignalFired                = false;
+  map[Toolkit::ImageVisual::Property::URL] = "";
+  imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliImageViewTransitionEffect01(void)
 {
   tet_infoline("Test imageView use transition effect");
index 271246f..c6a8711 100644 (file)
@@ -3017,7 +3017,7 @@ int UtcDaliImageVisualLoadPolicy03(void)
 
   // Ensure texture has been uploaded
   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
 
   END_TEST;
 }
@@ -3055,7 +3055,7 @@ int UtcDaliImageVisualLoadPolicy04(void)
 
   tet_infoline("Testing texture is loaded and resource ready signal fired");
   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
 
   tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
 
index b0f8294..68c0d0b 100644 (file)
@@ -117,8 +117,7 @@ void ConfigureBlendShapeShaders(
   Dali::Scene3D::Loader::ResourceBundle& resources, const Dali::Scene3D::Loader::SceneDefinition& scene, Actor root, std::vector<Dali::Scene3D::Loader::BlendshapeShaderConfigurationRequest>&& requests)
 {
   std::vector<std::string> errors;
-  auto                     onError = [&errors](const std::string& msg)
-  { errors.push_back(msg); };
+  auto                     onError = [&errors](const std::string& msg) { errors.push_back(msg); };
   if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError))
   {
     Dali::Scene3D::Loader::ExceptionFlinger flinger(ASSERT_LOCATION);
@@ -843,7 +842,7 @@ void Model::NotifyResourceReady()
   {
     return;
   }
-  Control::SetResourceReady(false);
+  Control::SetResourceReady();
 }
 
 void Model::CreateModel()
@@ -889,8 +888,7 @@ void Model::CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene)
   mAnimations.clear();
   if(!mModelLoadTask->GetAnimations().empty())
   {
-    auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property)
-    {
+    auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) {
       if(property.mNodeIndex == Scene3D::Loader::INVALID_INDEX)
       {
         return mModelRoot.FindChildByName(property.mNodeName);
index c606f8f..0dcbb6b 100644 (file)
@@ -391,7 +391,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
   // If diffuse and specular textures are already loaded, emits resource ready signal here.
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
@@ -758,7 +758,7 @@ void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentM
 
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
@@ -778,7 +778,7 @@ void SceneView::OnSkyboxLoadComplete()
   mSkyboxResourceReady = true;
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 
   mSkyboxTexture = mSkyboxLoadTask->GetLoadedTexture();
@@ -832,7 +832,7 @@ void SceneView::OnIblLoadComplete()
   NotifyImageBasedLightTextureChange();
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
index 308ce4d..0a19706 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -132,7 +132,7 @@ bool FindVisual(std::string visualName, const RegisteredVisualContainer& visuals
 /**
  *  Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
  */
-bool FindVisual(const Toolkit::Visual::Base findVisual , const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter)
+bool FindVisual(const Toolkit::Visual::Base findVisual, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter)
 {
   for(iter = visuals.Begin(); iter != visuals.End(); iter++)
   {
@@ -145,6 +145,22 @@ bool FindVisual(const Toolkit::Visual::Base findVisual , const RegisteredVisualC
   return false;
 }
 
+/**
+ *  Finds internal visual in given array, returning true if found along with the iterator for that visual as a out parameter
+ */
+bool FindVisual(const Visual::Base& findInternalVisual, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter)
+{
+  for(iter = visuals.Begin(); iter != visuals.End(); iter++)
+  {
+    Visual::Base& visual = Toolkit::GetImplementation((*iter)->visual);
+    if((&visual == &findInternalVisual))
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
 void FindChangableVisuals(Dictionary<Property::Map>& stateVisualsToAdd,
                           Dictionary<Property::Map>& stateVisualsToChange,
                           DictionaryKeys&            stateVisualsToRemove)
@@ -821,7 +837,7 @@ void Control::Impl::RegisterVisual(Property::Index index, Toolkit::Visual::Base&
     {
       visualImpl.SetOnScene(self);
     }
-    else if(visualImpl.IsResourceReady()) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
+    else if(enabled && visualImpl.IsResourceReady()) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
     {
       ResourceReady(visualImpl);
     }
@@ -923,7 +939,7 @@ void Control::Impl::EnableReadyTransitionOverriden(Toolkit::Visual::Base& visual
       return;
     }
 
-    (*iter)->overideReadyTransition  = enable;
+    (*iter)->overideReadyTransition = enable;
   }
 }
 
@@ -943,15 +959,8 @@ void Control::Impl::StartObservingVisual(Toolkit::Visual::Base& visual)
   visualImpl.AddEventObserver(*this);
 }
 
-void Control::Impl::ResourceReady(bool relayoutRequest)
+void Control::Impl::ResourceReady()
 {
-  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())
   {
@@ -968,33 +977,37 @@ void Control::Impl::ResourceReady(Visual::Base& object)
 
   Actor self = mControlImpl.Self();
 
+  RegisteredVisualContainer::Iterator registeredIter;
+
   // A resource is ready, find resource in the registered visuals container and get its index
-  for(auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter)
+  if(!FindVisual(object, mVisuals, registeredIter))
   {
-    Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation((*registeredIter)->visual);
+    return;
+  }
 
-    if(&object == &registeredVisualImpl)
+  RegisteredVisualContainer::Iterator visualToRemoveIter;
+  // Find visual with the same index in the removal container
+  // Set if off stage as it's replacement is now ready.
+  // Remove if from removal list as now removed from stage.
+  // Set Pending flag on the ready visual to false as now ready.
+  if(FindVisual((*registeredIter)->index, mRemoveVisuals, visualToRemoveIter))
+  {
+    (*registeredIter)->pending = false;
+    if(!((*visualToRemoveIter)->overideReadyTransition))
     {
-      RegisteredVisualContainer::Iterator visualToRemoveIter;
-      // Find visual with the same index in the removal container
-      // Set if off stage as it's replacement is now ready.
-      // Remove if from removal list as now removed from stage.
-      // Set Pending flag on the ready visual to false as now ready.
-      if(FindVisual((*registeredIter)->index, mRemoveVisuals, visualToRemoveIter))
-      {
-        (*registeredIter)->pending = false;
-        if(!((*visualToRemoveIter)->overideReadyTransition))
-        {
-          Toolkit::GetImplementation((*visualToRemoveIter)->visual).SetOffScene(self);
-        }
-        mRemoveVisuals.Erase(visualToRemoveIter);
-      }
-      break;
+      Toolkit::GetImplementation((*visualToRemoveIter)->visual).SetOffScene(self);
     }
+    mRemoveVisuals.Erase(visualToRemoveIter);
   }
 
+  // A visual is ready so control may need relayouting if staged
+  RelayoutRequest(object);
+
   // Called by a Visual when it's resource is ready
-  ResourceReady(true);
+  if(((*registeredIter)->enabled))
+  {
+    ResourceReady();
+  }
 }
 
 void Control::Impl::NotifyVisualEvent(Visual::Base& object, Property::Index signalId)
@@ -1013,7 +1026,10 @@ void Control::Impl::NotifyVisualEvent(Visual::Base& object, Property::Index sign
 
 void Control::Impl::RelayoutRequest(Visual::Base& object)
 {
-  mControlImpl.RelayoutRequest();
+  if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
+  {
+    mControlImpl.RelayoutRequest();
+  }
 }
 
 bool Control::Impl::IsResourceReady() const
index b84694d..3a42718 100644 (file)
@@ -129,9 +129,8 @@ public:
 
   /**
    * @brief Called when resources of control are ready.
-   * @param[in] relayoutRequest True to request relayout
    */
-  void ResourceReady(bool relayoutRequest);
+  void ResourceReady();
 
   /**
    * @brief Called when a resource is ready.
index 2bd33ca..e590f91 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -168,10 +168,10 @@ void Control::ClearBackground()
   RelayoutRequest();
 }
 
-void Control::SetResourceReady(bool relayoutRequest)
+void Control::SetResourceReady()
 {
   Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
-  controlDataImpl.ResourceReady(relayoutRequest);
+  controlDataImpl.ResourceReady();
 }
 
 Toolkit::DevelControl::ControlAccessible* Control::GetAccessibleObject()
index 4db0504..8f3920c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_CONTROL_IMPL_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -51,7 +51,6 @@ class ControlAccessible;
 
 namespace Internal
 {
-
 /**
  * @brief This is the internal base class for all controls.
  *
@@ -116,10 +115,9 @@ public:
   void ClearBackground();
 
   /**
-   * @brief Called when resources of control are ready.
-   * @param[in] relayoutRequest True to request relayout
+   * @brief Called when resources of control are ready. this api does not request relayout.
    */
-  void SetResourceReady(bool relayoutRequest);
+  void SetResourceReady();
 
   // Accessibility
 
@@ -278,7 +276,6 @@ public:
   DALI_INTERNAL void KeyboardEnter();
   /// @endcond
 
-
   // Signals
 
   /**
@@ -407,7 +404,6 @@ protected: // From CustomActorImpl
   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
 
 public: // Helpers for deriving classes
-
   /**
    * @brief Flags for the constructor.
    * @SINCE_1_0.0
@@ -689,8 +685,7 @@ public: // API for derived classes to override
    * @param[in] destination Destination control of the animation.
    * @param[in] visualIndex Property::Index to make animation.
    */
-  void MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap,
-                            Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
+  void MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap, Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex);
 
   /**
    * @brief Retrieves source and destination visual properties for the Transition of this Control.