Update toolkit-window to add/remove actors in the correct Scene 59/212959/11
authorRichard Huang <r.huang@samsung.com>
Wed, 28 Aug 2019 13:32:43 +0000 (14:32 +0100)
committerSunghyun kim <scholb.kim@samsung.com>
Wed, 4 Sep 2019 03:26:57 +0000 (12:26 +0900)
Change-Id: Ib6392f85f493405b520850c6f3e98e2cba600213

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-scene-holder-impl.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-scene-holder.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window-impl.h [new file with mode: 0644]
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window.h
dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp

index e4b7bd7..2feb3e0 100644 (file)
@@ -41,6 +41,7 @@ namespace Adaptor
 {
 
 class GraphicsInterface;
 {
 
 class GraphicsInterface;
+class SceneHolder;
 
 } // namespace Adaptor
 
 
 } // namespace Adaptor
 
@@ -78,6 +79,10 @@ public:
   Dali::WindowContainer GetWindows();
   Dali::SceneHolderList GetSceneHolders();
 
   Dali::WindowContainer GetWindows();
   Dali::SceneHolderList GetSceneHolders();
 
+  Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
+  void AddWindow( Internal::Adaptor::SceneHolder* window );
+  void RemoveWindow( Internal::Adaptor::SceneHolder* window );
+
   Dali::Adaptor::AdaptorSignalType& ResizedSignal();
   Dali::Adaptor::AdaptorSignalType& LanguageChangedSignal();
   Dali::Adaptor::WindowCreatedSignalType& WindowCreatedSignal();
   Dali::Adaptor::AdaptorSignalType& ResizedSignal();
   Dali::Adaptor::AdaptorSignalType& LanguageChangedSignal();
   Dali::Adaptor::WindowCreatedSignalType& WindowCreatedSignal();
@@ -88,8 +93,7 @@ public:
 private:
 
   Vector<CallbackBase*> mCallbacks;
 private:
 
   Vector<CallbackBase*> mCallbacks;
-  Dali::WindowContainer mWindows;
-  Dali::SceneHolderList mSceneHolders;
+  std::vector<Internal::Adaptor::SceneHolder*> mWindows;
   Dali::Adaptor::AdaptorSignalType mResizedSignal;
   Dali::Adaptor::AdaptorSignalType mLanguageChangedSignal;
   Dali::Adaptor::WindowCreatedSignalType mWindowCreatedSignal;
   Dali::Adaptor::AdaptorSignalType mResizedSignal;
   Dali::Adaptor::AdaptorSignalType mLanguageChangedSignal;
   Dali::Adaptor::WindowCreatedSignalType mWindowCreatedSignal;
index fc9f1e7..bfc2478 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <algorithm>
 
 
 #include <algorithm>
 
-#include <toolkit-window.h>
+#include <toolkit-window-impl.h>
 
 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
 #define DALI_WINDOW_H
 
 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
 #define DALI_WINDOW_H
@@ -96,12 +96,7 @@ Adaptor::~Adaptor()
 
 void Adaptor::Start( Dali::Window window )
 {
 
 void Adaptor::Start( Dali::Window window )
 {
-  if ( window )
-  {
-    mWindows.push_back( window );
-
-    mSceneHolders.emplace_back( static_cast<SceneHolder*>( &window.GetBaseObject() ) );
-  }
+  AddWindow( &GetImplementation( window ) );
 }
 
 Integration::Scene Adaptor::GetScene( Dali::Window window )
 }
 
 Integration::Scene Adaptor::GetScene( Dali::Window window )
@@ -135,17 +130,71 @@ Dali::RenderSurfaceInterface& Adaptor::GetSurface()
 {
   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
 
 {
   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
 
-  return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front().GetRenderSurface() );
+  return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
 }
 
 Dali::WindowContainer Adaptor::GetWindows()
 {
 }
 
 Dali::WindowContainer Adaptor::GetWindows()
 {
-  return mWindows;
+  Dali::WindowContainer windows;
+
+  for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+  {
+    // Downcast to Dali::Window
+    Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
+    if ( window )
+    {
+      windows.push_back( window );
+    }
+  }
+
+  return windows;
 }
 
 Dali::SceneHolderList Adaptor::GetSceneHolders()
 {
 }
 
 Dali::SceneHolderList Adaptor::GetSceneHolders()
 {
-  return mSceneHolders;
+  Dali::SceneHolderList sceneHolderList;
+
+  for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+  {
+    sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
+  }
+
+  return sceneHolderList;
+}
+
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
+{
+  Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
+
+  for( auto window : mWindows )
+  {
+    if ( scene == window->GetScene() )
+    {
+      return window;
+    }
+  }
+
+  return nullptr;
+}
+
+void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
+{
+  if ( window )
+  {
+    mWindows.push_back( window );
+
+    Dali::Integration::SceneHolder newWindow( window );
+    mWindowCreatedSignal.Emit( newWindow );
+  }
+}
+
+void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
+{
+  auto iter = std::find( mWindows.begin(), mWindows.end(), window );
+  if( iter != mWindows.end() )
+  {
+    mWindows.erase( iter );
+  }
 }
 
 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 }
 
 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
index 62c432e..a937262 100644 (file)
@@ -41,6 +41,10 @@ public:
 
   virtual ~SceneHolder();
 
 
   virtual ~SceneHolder();
 
+  void Add( Dali::Actor actor );
+
+  void Remove( Dali::Actor actor );
+
   Dali::Layer GetRootLayer() const;
 
   void SetBackgroundColor( Vector4 color );
   Dali::Layer GetRootLayer() const;
 
   void SetBackgroundColor( Vector4 color );
index 98ea7dc..7aec884 100644 (file)
@@ -28,6 +28,8 @@
 #include <dali/integration-api/adaptors/adaptor.h>
 #include <toolkit-adaptor-impl.h>
 
 #include <dali/integration-api/adaptors/adaptor.h>
 #include <toolkit-adaptor-impl.h>
 
+using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
+
 namespace Dali
 {
 
 namespace Dali
 {
 
@@ -51,6 +53,25 @@ SceneHolder::SceneHolder( const Dali::Rect<int>& positionSize )
 
 SceneHolder::~SceneHolder()
 {
 
 SceneHolder::~SceneHolder()
 {
+  if ( Dali::Adaptor::IsAvailable() )
+  {
+    AdaptorImpl::GetImpl( AdaptorImpl::Get() ).RemoveWindow( this );
+  }
+}
+
+void SceneHolder::Add( Dali::Actor actor )
+{
+  mScene.Add( actor );
+}
+
+void SceneHolder::Remove( Dali::Actor actor )
+{
+  mScene.Add( actor );
+}
+
+Dali::Layer SceneHolder::GetRootLayer() const
+{
+  return mScene.GetRootLayer();
 }
 
 void SceneHolder::SetBackgroundColor( Vector4 color )
 }
 
 void SceneHolder::SetBackgroundColor( Vector4 color )
@@ -143,17 +164,31 @@ SceneHolder& SceneHolder::operator=( const SceneHolder& rhs )
   return *this;
 }
 
   return *this;
 }
 
+Dali::Integration::SceneHolder SceneHolder::Get( Dali::Actor actor )
+{
+  Internal::Adaptor::SceneHolder* sceneHolderImpl = nullptr;
+
+  if ( Dali::Adaptor::IsAvailable() )
+  {
+    sceneHolderImpl = AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor );
+  }
+
+  return Dali::Integration::SceneHolder( sceneHolderImpl );
+}
+
 void SceneHolder::Add( Actor actor )
 {
 void SceneHolder::Add( Actor actor )
 {
+  GetImplementation( *this ).Add( actor );
 }
 
 void SceneHolder::Remove( Actor actor )
 {
 }
 
 void SceneHolder::Remove( Actor actor )
 {
+  GetImplementation( *this ).Remove( actor );
 }
 
 Dali::Layer SceneHolder::GetRootLayer() const
 {
 }
 
 Dali::Layer SceneHolder::GetRootLayer() const
 {
-  return Dali::Stage::GetCurrent().GetRootLayer();
+  return GetImplementation( *this ).GetRootLayer();
 }
 
 void SceneHolder::SetBackgroundColor( Vector4 color )
 }
 
 void SceneHolder::SetBackgroundColor( Vector4 color )
@@ -201,11 +236,6 @@ SceneHolder::WheelEventSignalType& SceneHolder::WheelEventSignal()
   return GetImplementation( *this ).WheelEventSignal();
 }
 
   return GetImplementation( *this ).WheelEventSignal();
 }
 
-SceneHolder SceneHolder::Get( Actor actor )
-{
-  return SceneHolder();
-}
-
 } // Integration
 
 } // Dali
 } // Integration
 
 } // Dali
index 53cd1d9..1ee9219 100644 (file)
@@ -33,6 +33,7 @@ using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
 
 ToolkitTestApplication::ToolkitTestApplication( size_t surfaceWidth, size_t surfaceHeight, float  horizontalDpi, float verticalDpi )
 : TestApplication( surfaceWidth, surfaceHeight, horizontalDpi, verticalDpi, ResourcePolicy::DALI_DISCARDS_ALL_DATA, false /* Do not Initialize Core */ ),
 
 ToolkitTestApplication::ToolkitTestApplication( size_t surfaceWidth, size_t surfaceHeight, float  horizontalDpi, float verticalDpi )
 : TestApplication( surfaceWidth, surfaceHeight, horizontalDpi, verticalDpi, ResourcePolicy::DALI_DISCARDS_ALL_DATA, false /* Do not Initialize Core */ ),
+  mMainWindow( new Dali::Window ),
   mAdaptor( &AdaptorImpl::New() ) // Need to create Adaptor first as many singletons in dali-adaptor need it
 {
   // Create Core next
   mAdaptor( &AdaptorImpl::New() ) // Need to create Adaptor first as many singletons in dali-adaptor need it
 {
   // Create Core next
@@ -40,8 +41,8 @@ ToolkitTestApplication::ToolkitTestApplication( size_t surfaceWidth, size_t surf
 
   // Override Scene creation in TestApplication by creating a window.
   // The window will create a Scene & surface and set up the scene's surface appropriately.
 
   // Override Scene creation in TestApplication by creating a window.
   // The window will create a Scene & surface and set up the scene's surface appropriately.
-  Window window( Window::New( PositionSize( 0, 0, surfaceWidth, surfaceHeight ), "" ) );
-  mScene = AdaptorImpl::GetScene( window );
+  *mMainWindow = Window::New( PositionSize( 0, 0, surfaceWidth, surfaceHeight ), "" );
+  mScene = AdaptorImpl::GetScene( *mMainWindow );
   mRenderSurface = dynamic_cast< TestRenderSurface* >( mScene.GetSurface() );
   mScene.SetDpi( Vector2( horizontalDpi, verticalDpi ) );
 
   mRenderSurface = dynamic_cast< TestRenderSurface* >( mScene.GetSurface() );
   mScene.SetDpi( Vector2( horizontalDpi, verticalDpi ) );
 
@@ -52,7 +53,7 @@ ToolkitTestApplication::ToolkitTestApplication( size_t surfaceWidth, size_t surf
   Test::SetApplication( singletonService, *this );
 
   // This will also emit the window created signals
   Test::SetApplication( singletonService, *this );
 
   // This will also emit the window created signals
-  AdaptorImpl::GetImpl( *mAdaptor ).Start( window );
+  AdaptorImpl::GetImpl( *mAdaptor ).Start( *mMainWindow );
 
   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
   lifecycleController.InitSignal().Emit();
 
   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
   lifecycleController.InitSignal().Emit();
index a984a37..7dd21b5 100644 (file)
@@ -28,6 +28,7 @@ namespace Dali
 {
 
 class Adaptor;
 {
 
 class Adaptor;
+class Window;
 
 /**
  * Adds some functionality on top of TestApplication that is required by the Toolkit.
 
 /**
  * Adds some functionality on top of TestApplication that is required by the Toolkit.
@@ -54,6 +55,8 @@ public:
   void RunIdles();
 
 private:
   void RunIdles();
 
 private:
+
+  std::unique_ptr<Dali::Window> mMainWindow;
   std::unique_ptr< Adaptor > mAdaptor;
 };
 
   std::unique_ptr< Adaptor > mAdaptor;
 };
 
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window-impl.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-window-impl.h
new file mode 100644 (file)
index 0000000..64b0a40
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef TOOLKIT_WINDOW_IMPL_H
+#define TOOLKIT_WINDOW_IMPL_H
+
+/*
+ * Copyright (c) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+#include <dali/integration-api/adaptors/scene-holder.h>
+
+// INTERNAL INCLUDES
+#include <toolkit-window.h>
+#include <toolkit-scene-holder-impl.h>
+
+namespace Dali
+{
+
+typedef Dali::Rect<int> PositionSize;
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+class Window : public SceneHolder
+{
+public:
+
+  Window( const PositionSize& positionSize );
+  virtual ~Window() = default;
+  static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent);
+};
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
+
+
+#endif // TOOLKIT_WINDOW_IMPL_H
index 506bee8..1424f1a 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 // CLASS HEADER
  */
 
 // CLASS HEADER
-#include "toolkit-window.h"
+#include "toolkit-window-impl.h"
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
@@ -24,9 +24,6 @@
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/object/base-object.h>
 
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/object/base-object.h>
 
-#include <dali/integration-api/adaptors/scene-holder.h>
-#include <toolkit-scene-holder-impl.h>
-
 #define DALI_WINDOW_H
 #include <dali/integration-api/adaptors/adaptor.h>
 #include <toolkit-adaptor-impl.h>
 #define DALI_WINDOW_H
 #include <dali/integration-api/adaptors/adaptor.h>
 #include <toolkit-adaptor-impl.h>
@@ -49,22 +46,16 @@ namespace Internal
 {
 namespace Adaptor
 {
 {
 namespace Adaptor
 {
-class Window : public SceneHolder
-{
-public:
-
-  Window( const PositionSize& positionSize )
-  : SceneHolder( positionSize )
-  {
-  }
 
 
-  virtual ~Window() = default;
+Window::Window( const PositionSize& positionSize )
+: SceneHolder( positionSize )
+{
+}
 
 
-  static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
-  {
-    return new Window( positionSize );
-  }
-};
+Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
+{
+  return new Window( positionSize );
+}
 
 } // Adaptor
 } // Internal
 
 } // Adaptor
 } // Internal
@@ -76,6 +67,13 @@ inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
   return static_cast<Internal::Adaptor::Window&>(object);
 }
 
   return static_cast<Internal::Adaptor::Window&>(object);
 }
 
+inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
+{
+  DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
+  const BaseObject& object = window.GetBaseObject();
+  return static_cast<const Internal::Adaptor::Window&>(object);
+}
+
 Window::Window()
 {
 }
 Window::Window()
 {
 }
@@ -106,17 +104,12 @@ Dali::Window Window::New(PositionSize windowPosition, const std::string& name, c
 
   Dali::Window result( window );
 
 
   Dali::Window result( window );
 
-  Dali::Integration::SceneHolder sceneHolder( static_cast<Dali::Internal::Adaptor::SceneHolder*>( window ) );
-  Dali::Internal::Adaptor::Adaptor::Get().WindowCreatedSignal().Emit( sceneHolder );
+  // This will also emit the window created signals
+  AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
 
   return result;
 }
 
 
   return result;
 }
 
-Dali::Layer Window::GetRootLayer() const
-{
-  return Dali::Stage::GetCurrent().GetRootLayer();
-}
-
 Window::Window( Internal::Adaptor::Window* window )
 : BaseHandle( window )
 {
 Window::Window( Internal::Adaptor::Window* window )
 : BaseHandle( window )
 {
@@ -137,7 +130,14 @@ namespace DevelWindow
 
 Window Get( Actor actor )
 {
 
 Window Get( Actor actor )
 {
-  return Window();
+  Internal::Adaptor::Window* windowImpl = nullptr;
+
+  if ( Dali::Adaptor::IsAvailable() )
+  {
+    windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
+  }
+
+  return Dali::Window( windowImpl );
 }
 
 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
 }
 
 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
index f2fc19a..3fac48d 100644 (file)
@@ -55,7 +55,6 @@ public:
   ~Window();
   Window(const Window& handle);
   Window& operator=(const Window& rhs);
   ~Window();
   Window(const Window& handle);
   Window& operator=(const Window& rhs);
-  Layer GetRootLayer() const;
 
   Integration::Scene GetScene();
   Integration::RenderSurface& GetRenderSurface();
 
   Integration::Scene GetScene();
   Integration::RenderSurface& GetRenderSurface();
@@ -64,6 +63,9 @@ public:
   explicit Window( Internal::Adaptor::Window* window );
 };
 
   explicit Window( Internal::Adaptor::Window* window );
 };
 
+Internal::Adaptor::Window& GetImplementation(Dali::Window& window);
+const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window);
+
 namespace DevelWindow
 {
 typedef Signal< void () > EventProcessingFinishedSignalType;
 namespace DevelWindow
 {
 typedef Signal< void () > EventProcessingFinishedSignalType;
index 7117686..bba7702 100644 (file)
@@ -328,7 +328,12 @@ Toolkit::Control KeyboardFocusManager::GetParentLayoutControl(Actor actor) const
   Actor parent;
   if(actor)
   {
   Actor parent;
   if(actor)
   {
-    rootActor = Integration::SceneHolder::Get( actor ).GetRootLayer();
+    Integration::SceneHolder window = Integration::SceneHolder::Get( actor );
+    if ( window )
+    {
+      rootActor = window.GetRootLayer();
+    }
+
     parent = actor.GetParent();
   }
 
     parent = actor.GetParent();
   }
 
@@ -410,7 +415,11 @@ bool KeyboardFocusManager::MoveFocus(Toolkit::Control::KeyboardFocus::Direction
 
           if( !nextFocusableActor )
           {
 
           if( !nextFocusableActor )
           {
-            nextFocusableActor = Integration::SceneHolder::Get( currentFocusActor ).GetRootLayer().FindChildById( actorId );
+            Integration::SceneHolder window = Integration::SceneHolder::Get( currentFocusActor );
+            if ( window )
+            {
+              nextFocusableActor = window.GetRootLayer().FindChildById( actorId );
+            }
           }
         }
       }
           }
         }
       }