Window - Constructor refactor. 04/223504/16
authorVictor Cebollada <v.cebollada@samsung.com>
Thu, 30 Jan 2020 08:04:48 +0000 (08:04 +0000)
committerVictor Cebollada <v.cebollada@samsung.com>
Tue, 31 Mar 2020 08:06:46 +0000 (09:06 +0100)
* Fixes a memory leak if multiple window is not supported.
* Common code removed by calling one constructor from another.
* Fixes a circular dependency with Adaptor.
  The Adaptor needs a Window and Window needs the Adaptor to
  be created.

Change-Id: Icf4443f1ecfc758d1fd68d6d8ee032dd3e96274e
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali/public-api/adaptor-framework/window.cpp

index 08562d0..9d8c830 100644 (file)
@@ -33,40 +33,41 @@ class DALI_INTERNAL DragAndDropDetector : public BaseHandle {}; // Empty class o
 
 Window Window::New(PositionSize posSize, const std::string& name, bool isTransparent)
 {
-  Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(posSize, name, "", isTransparent);
-
-  Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get();
-  if( Internal::Adaptor::Adaptor::GetImplementation( adaptor ).IsMultipleWindowSupported() )
-  {
-    Integration::SceneHolder sceneHolder = Integration::SceneHolder( window );
-    Internal::Adaptor::Adaptor::GetImplementation( adaptor ).AddWindow( sceneHolder, name, "", isTransparent );
-
-    return Window(window);
-  }
-  else
-  {
-    DALI_LOG_ERROR("This device can't support multiple windows.\n");
-    return Window();
-  }
+  return Dali::Window::New(posSize, name, "", isTransparent);
 }
 
 Window Window::New(PositionSize posSize, const std::string& name, const std::string& className, bool isTransparent)
 {
-  Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(posSize, name, className, isTransparent);
+  Window newWindow;
+
+  const bool isAdaptorAvailable = Dali::Adaptor::IsAvailable();
+  bool isNewWindowAllowed = true;
 
-  Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get();
-  if( Internal::Adaptor::Adaptor::GetImplementation( adaptor ).IsMultipleWindowSupported() )
+  if (isAdaptorAvailable)
   {
-    Integration::SceneHolder sceneHolder = Integration::SceneHolder( window );
-    Internal::Adaptor::Adaptor::GetImplementation( adaptor ).AddWindow( sceneHolder, name, className, isTransparent );
+    Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get();
+    isNewWindowAllowed = Internal::Adaptor::Adaptor::GetImplementation(adaptor).IsMultipleWindowSupported();
+  }
 
-    return Window(window);
+  if (isNewWindowAllowed)
+  {
+    Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(posSize, name, className, isTransparent);
+
+    Integration::SceneHolder sceneHolder = Integration::SceneHolder(window);
+
+    if (isAdaptorAvailable)
+    {
+      Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get();
+      Internal::Adaptor::Adaptor::GetImplementation(adaptor).AddWindow(sceneHolder, name, className, isTransparent);
+    }
+    newWindow = Window(window);
   }
   else
   {
     DALI_LOG_ERROR("This device can't support multiple windows.\n");
-    return Window();
   }
+
+  return newWindow;
 }
 
 Window::Window()