[Tizen] Add ResourceReady for Control 89/280889/2 accepted/tizen/unified/20220913.175616
authorseungho <sbsh.baek@samsung.com>
Mon, 5 Sep 2022 08:11:52 +0000 (17:11 +0900)
committerseungho <sbsh.baek@samsung.com>
Tue, 6 Sep 2022 08:49:03 +0000 (17:49 +0900)
Change-Id: I3fd129e05d53451383411ec904c09c5d3e41e3be
Signed-off-by: seungho <sbsh.baek@samsung.com>
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 61a5303..464b447 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>
@@ -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(false)
 {
 }
 
@@ -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();
+  }
 }
 
 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,11 @@ 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;
+  mIBLResourceReady   = true;
+
+  Control::SetResourceReady();
 }
 
 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 659dd5a..ce4ae17 100644 (file)
@@ -83,6 +83,13 @@ void SceneView::AddCamera(CameraActor camera)
 {
   if(camera)
   {
+    {
+      // To do not change camera properties during OnScene in CameraActor
+      // TODO: this will be removed after CameraActor is fixed.
+      Vector3     size        = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+      const float aspectRatio = (size.height > 0.1f) ? size.width / size.height : 1.0f;
+      camera.SetAspectRatio(aspectRatio);
+    }
     if(mCameras.empty())
     {
       UpdateCamera(camera);
@@ -188,6 +195,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 +215,8 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuse, const std::
       }
     }
   }
+  mIBLResourceReady = true;
+  Control::SetResourceReady();
 }
 
 void SceneView::UseFramebuffer(bool useFramebuffer)
@@ -264,6 +274,11 @@ void SceneView::OnInitialize()
   mDefaultCamera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   mDefaultCamera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
   mDefaultCamera.SetNearClippingPlane(1.0f);
+  {
+    // To do not change camera properties during OnScene in CameraActor
+    // TODO: this will be removed after CameraActor is fixed.
+    mDefaultCamera.SetAspectRatio(1.0f);
+  }
   AddCamera(mDefaultCamera);
   UpdateCamera(mDefaultCamera);
 }
@@ -304,6 +319,11 @@ void SceneView::OnRelayout(const Vector2& size, RelayoutContainer& container)
   UpdateRenderTask();
 }
 
+bool SceneView::IsResourceReady() const
+{
+  return mIBLResourceReady;
+}
+
 void SceneView::UpdateCamera(CameraActor camera)
 {
   if(camera)
@@ -329,25 +349,16 @@ void SceneView::UpdateRenderTask()
     }
 
     Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
-    float   fov  = 0.0f;
-    Vector3 cameraPosition(Vector3::ZERO);
-    float   nearPlain = 1.0f;
-    float   farPlain  = 1.0f;
-
-    // Several properties such as fov, nearPlane, farPlane, and position should not be changed after SetPerspectiveProjection is called.
-    // In the 3D scene, the properties are not changed by the changes of canvas size.
-    fov            = mSelectedCamera[Dali::CameraActor::Property::FIELD_OF_VIEW];
-    nearPlain      = mSelectedCamera[Dali::CameraActor::Property::NEAR_PLANE_DISTANCE];
-    farPlain       = mSelectedCamera[Dali::CameraActor::Property::FAR_PLANE_DISTANCE];
-    cameraPosition = Vector3(mSelectedCamera[Dali::Actor::Property::POSITION]);
-
-    mSelectedCamera.SetPerspectiveProjection(Dali::Size(size));
-
-    mSelectedCamera[Dali::CameraActor::Property::FIELD_OF_VIEW]       = fov;
-    mSelectedCamera[Dali::CameraActor::Property::NEAR_PLANE_DISTANCE] = nearPlain;
-    mSelectedCamera[Dali::CameraActor::Property::FAR_PLANE_DISTANCE]  = farPlain;
-    mSelectedCamera[Dali::Actor::Property::POSITION]                  = cameraPosition;
-
+    const float aspectRatio = size.width / size.height;
+    mSelectedCamera.SetAspectRatio(aspectRatio);
+    const float fov = mSelectedCamera[Dali::CameraActor::Property::FIELD_OF_VIEW];
+    const float near = mSelectedCamera[Dali::CameraActor::Property::NEAR_PLANE_DISTANCE];
+    const float halfHeight = tanf(fov/2) * near;
+    const float halfWidth = aspectRatio * halfHeight;
+    mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE]   = -halfWidth;
+    mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE]  = halfWidth;
+    mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE]    = halfHeight; // Top is +ve to keep consistency with orthographic values
+    mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight; // Bottom is -ve to keep consistency with orthographic values
     if(mUseFrameBuffer)
     {
       Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
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..37a51df 100644 (file)
@@ -910,6 +910,25 @@ void Control::Impl::StartObservingVisual(Toolkit::Visual::Base& visual)
 }
 
 // Called by a Visual when it's resource is ready
+void Control::Impl::ResourceReady()
+{
+  Actor self = mControlImpl.Self();
+  // 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
 void Control::Impl::ResourceReady(Visual::Base& object)
 {
   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count());
@@ -938,20 +957,7 @@ 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();
-  }
+  ResourceReady();
 }
 
 void Control::Impl::NotifyVisualEvent(Visual::Base& object, Property::Index signalId)
index 46cc97b..d242053 100644 (file)
@@ -126,6 +126,11 @@ public:
   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
 
   /**
+   * @brief Called when resources of control are ready.
+   */
+  void ResourceReady();
+
+  /**
    * @brief Called when a resource is ready.
    * @param[in] object The visual whose resources are ready
    * @note Overriding method in Visual::EventObserver.
index 60efa05..6638121 100644 (file)
@@ -167,6 +167,12 @@ void Control::ClearBackground()
   RelayoutRequest();
 }
 
+void Control::SetResourceReady()
+{
+  Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(*this);
+  controlDataImpl.ResourceReady();
+}
+
 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..568d5e3 100644 (file)
@@ -115,6 +115,11 @@ public:
    */
   void ClearBackground();
 
+  /**
+   * @brief Called when resources of control are ready.
+   */
+  void SetResourceReady();
+
   // Accessibility
 
   /**
@@ -456,6 +461,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)