[Tizen] Fix rendering occured unlimited if window size changed multiple
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / adaptor-framework / scene-holder-impl.cpp
index fe93f69..3950b57 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -27,6 +27,7 @@
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
 
 // INTERNAL INCLUDES
 #include <dali/internal/adaptor/common/adaptor-impl.h>
@@ -85,11 +86,18 @@ SceneHolder::SceneHolder()
 
 SceneHolder::~SceneHolder()
 {
+  if(mScene)
+  {
+    // The scene graph object should be removed first.
+    mScene.RemoveSceneObject();
+  }
+
   if(mAdaptor)
   {
     mAdaptor->RemoveObserver(*mLifeCycleObserver.get());
     mAdaptor->RemoveWindow(this);
 
+    // The event queue is flushed and we wait for the completion of the surface removal
     mAdaptor->DeleteSurface(*mSurface.get());
 
     mAdaptor = nullptr;
@@ -97,6 +105,7 @@ SceneHolder::~SceneHolder()
 
   if(mScene)
   {
+    // We should remove the surface from the Core last
     mScene.Discard();
   }
 }
@@ -122,6 +131,11 @@ Dali::Layer SceneHolder::GetRootLayer() const
   return mScene ? mScene.GetRootLayer() : Dali::Layer();
 }
 
+Dali::Layer SceneHolder::GetOverlayLayer()
+{
+  return mScene ? mScene.GetOverlayLayer() : Dali::Layer();
+}
+
 uint32_t SceneHolder::GetId() const
 {
   return mId;
@@ -153,7 +167,9 @@ void SceneHolder::SetSurface(Dali::RenderSurfaceInterface* surface)
 
   mScene.SurfaceReplaced();
 
-  SurfaceResized();
+  PositionSize surfacePositionSize = surface->GetPositionSize();
+
+  SurfaceResized(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height));
 
   InitializeDpi();
 
@@ -166,10 +182,12 @@ void SceneHolder::SetSurface(Dali::RenderSurfaceInterface* surface)
   OnSurfaceSet(surface);
 }
 
-void SceneHolder::SurfaceResized()
+void SceneHolder::SurfaceResized(float width, float height)
 {
-  PositionSize surfacePositionSize = mSurface->GetPositionSize();
-  mScene.SurfaceResized(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height));
+  if(DALI_LIKELY(mScene))
+  {
+    mScene.SurfaceResized(width, height);
+  }
 
   mSurface->SetFullSwapNextFrame();
 
@@ -211,8 +229,10 @@ void SceneHolder::SetAdaptor(Dali::Adaptor& adaptor)
 
   // Create the scene
   PositionSize surfacePositionSize = mSurface->GetPositionSize();
-  int          orientation         = mSurface->GetOrientation();
-  mScene                           = Dali::Integration::Scene::New(Size(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height)), orientation);
+  int          windowOrientation   = mSurface->GetSurfaceOrientation();
+  int          screenOrientation   = mSurface->GetScreenOrientation();
+
+  mScene = Dali::Integration::Scene::New(Size(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height)), windowOrientation, screenOrientation);
 
   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
   mAdaptor                                = &adaptorImpl;
@@ -229,6 +249,9 @@ void SceneHolder::SetAdaptor(Dali::Adaptor& adaptor)
   CreateRenderTarget();
 
   OnAdaptorSet(adaptor);
+
+  // Scene is newly created. Let we increase resize counter
+  mAdaptor->IncreaseSurfaceResizeCounter();
 }
 
 void SceneHolder::CreateRenderTarget()
@@ -238,9 +261,8 @@ void SceneHolder::CreateRenderTarget()
     .SetSurface(mSurface.get())
     .SetExtent({static_cast<uint32_t>(mSurface->GetPositionSize().width), static_cast<uint32_t>(mSurface->GetPositionSize().height)})
     .SetPreTransform(0 | Graphics::RenderTargetTransformFlagBits::TRANSFORM_IDENTITY_BIT);
-  mRenderTarget = mAdaptor->GetGraphicsInterface().GetController().CreateRenderTarget(rtInfo, std::move(mRenderTarget));
 
-  mScene.SetSurfaceRenderTarget(mRenderTarget.get());
+  mScene.SetSurfaceRenderTarget(rtInfo);
 }
 
 void SceneHolder::Pause()
@@ -257,9 +279,20 @@ void SceneHolder::Resume()
   OnResume();
 }
 
-void SceneHolder::SurfaceRotated(float width, float height, int orientation)
+void SceneHolder::SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation)
+{
+  if(DALI_LIKELY(mScene))
+  {
+    mScene.SurfaceRotated(width, height, windowOrientation, screenOrientation);
+  }
+}
+
+void SceneHolder::SetRotationCompletedAcknowledgement()
 {
-  mScene.SurfaceRotated(width, height, orientation);
+  if(DALI_LIKELY(mScene))
+  {
+    mScene.SetRotationCompletedAcknowledgement();
+  }
 }
 
 void SceneHolder::FeedTouchPoint(Dali::Integration::Point& point, int timeStamp)
@@ -269,7 +302,8 @@ void SceneHolder::FeedTouchPoint(Dali::Integration::Point& point, int timeStamp)
     timeStamp = TimeService::GetMilliSeconds();
   }
 
-  RecalculateTouchPosition(point);
+  Vector2 convertedPosition = RecalculatePosition(point.GetScreenPosition());
+  point.SetScreenPosition(convertedPosition);
 
   Integration::TouchEvent                            touchEvent;
   Integration::HoverEvent                            hoverEvent;
@@ -304,6 +338,9 @@ void SceneHolder::FeedWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
   // Keep the handle alive until the core events are processed.
   Dali::BaseHandle sceneHolder(this);
 
+  Vector2 convertedPosition = RecalculatePosition(wheelEvent.point);
+  wheelEvent.point          = convertedPosition;
+
   mScene.QueueEvent(wheelEvent);
   mAdaptor->ProcessCoreEvents();
 }
@@ -342,6 +379,11 @@ void SceneHolder::AddFramePresentedCallback(std::unique_ptr<CallbackBase> callba
   DALI_LOG_RELEASE_INFO("SceneHolder::AddFramePresentedCallback:: Added [%d]\n", frameId);
 }
 
+Dali::RenderTaskList SceneHolder::GetRenderTaskList() const
+{
+  return mScene.GetRenderTaskList();
+}
+
 Dali::Integration::SceneHolder SceneHolder::Get(Dali::Actor actor)
 {
   SceneHolder* sceneHolderImpl = nullptr;