Not ref counting the windows in the adaptor 65/207865/4
authorRichard Huang <r.huang@samsung.com>
Thu, 13 Jun 2019 10:11:15 +0000 (11:11 +0100)
committerRichard Huang <r.huang@samsung.com>
Tue, 18 Jun 2019 10:48:01 +0000 (11:48 +0100)
Change-Id: I515a13a2281d51e68f2fe1d27a231b6e1f832abe

dali/integration-api/scene-holder-impl.cpp
dali/internal/adaptor/common/adaptor-impl.cpp
dali/internal/adaptor/common/adaptor-impl.h

index efbbd60..deaf965 100644 (file)
@@ -133,6 +133,11 @@ SceneHolder::~SceneHolder()
     mAdaptor->RemoveWindow( this );
     mAdaptor = nullptr;
   }
+
+  if ( mScene )
+  {
+    mScene.Discard();
+  }
 }
 
 void SceneHolder::Add( Dali::Actor actor )
index 28417ee..0aa9feb 100755 (executable)
@@ -156,7 +156,7 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   mCallbackManager = CallbackManager::New();
 
-  SceneHolderPtr defaultWindow = mWindows.front();
+  Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
 
   DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
 
@@ -182,7 +182,7 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   defaultWindow->SetAdaptor( Get() );
 
-  Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( ( &defaultWindow )->Get() ) );
+  Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( defaultWindow ) );
   if ( window )
   {
     mWindowCreatedSignal.Emit( window );
@@ -341,7 +341,7 @@ void Adaptor::Start()
   // Start the callback manager
   mCallbackManager->Start();
 
-  SceneHolderPtr defaultWindow = mWindows.front();
+  Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
 
   unsigned int dpiHor, dpiVer;
   dpiHor = dpiVer = 0;
@@ -382,7 +382,7 @@ void Adaptor::Pause()
     }
 
     // Pause all windows event handlers when adaptor paused
-    for( SceneHolderPtr window : mWindows )
+    for( auto window : mWindows )
     {
       window->Pause();
     }
@@ -410,7 +410,7 @@ void Adaptor::Resume()
     mState = RUNNING;
 
     // Reset the event handlers when adaptor resumed
-    for( SceneHolderPtr window : mWindows )
+    for( auto window : mWindows )
     {
       window->Resume();
     }
@@ -505,9 +505,9 @@ void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
 {
   Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
-  for( SceneHolderPtr windowPtr : mWindows )
+  for( auto windowPtr : mWindows )
   {
-    if( windowPtr.Get() == windowImpl ) // the window is not deleted
+    if( windowPtr == windowImpl ) // the window is not deleted
     {
       // Let the core know the surface size has changed
       mCore->SurfaceResized( &newSurface );
@@ -577,7 +577,7 @@ bool Adaptor::AddWindow( Dali::Integration::SceneHolder* childWindow, const std:
   windowImpl.SetAdaptor( Get() );
 
   // Add the new Window to the container - the order is not important
-  mWindows.push_back( SceneHolderPtr( &windowImpl ) );
+  mWindows.push_back( &windowImpl );
 
   Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( &windowImpl ) );
   if ( window )
@@ -871,7 +871,7 @@ void Adaptor::OnWindowHidden()
   {
     bool allWindowsHidden = true;
 
-    for( SceneHolderPtr window : mWindows )
+    for( auto window : mWindows )
     {
       if ( window->IsVisible() )
       {
@@ -1014,7 +1014,7 @@ Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
   {
     if ( scene == window->GetScene() )
     {
-      return window.Get();
+      return window;
     }
   }
 
@@ -1028,7 +1028,7 @@ Dali::WindowContainer Adaptor::GetWindows() const
   for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
   {
     // Downcast to Dali::Window
-    Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( iter->Get() ) );
+    Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
     if ( window )
     {
       windows.push_back( window );
@@ -1069,7 +1069,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mUseRemoteSurface( false )
 {
   DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
-  mWindows.insert( mWindows.begin(), SceneHolderPtr( &Dali::GetImplementation( window ) ) );
+  mWindows.insert( mWindows.begin(), &Dali::GetImplementation( window ) );
 
   gThreadLocalAdaptor = this;
 }
index d36f8a6..4a77dfa 100755 (executable)
@@ -638,8 +638,9 @@ private: // Types
     STOPPED,                   ///< Adaptor has been stopped.
   };
 
-  using SceneHolderPtr = IntrusivePtr< Dali::Internal::Adaptor::SceneHolder >;
-  using WindowContainer = std::vector<SceneHolderPtr>;
+  // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
+  // so we have to store the raw pointer.
+  using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
   using ObserverContainer = std::vector<LifeCycleObserver*>;
 
 private: // Data