Revert "Remove EGL surface in the update thread"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index b505b22..a0fd809 100644 (file)
@@ -19,6 +19,7 @@
 #include <dali/internal/window-system/common/window-impl.h>
 
 // EXTERNAL HEADERS
+#include <thread>
 #include <dali/integration-api/core.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/actors/layer.h>
@@ -56,11 +57,17 @@ Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "
 
 } // unnamed namespace
 
-Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
+Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
+{
+  Any surface;
+  return Window::New(surface, positionSize, name, className, isTransparent);
+}
+
+Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
 {
   Window* window = new Window();
   window->mIsTransparent = isTransparent;
-  window->Initialize( positionSize, name, className );
+  window->Initialize(surface, positionSize, name, className);
   return window;
 }
 
@@ -92,16 +99,22 @@ Window::Window()
 
 Window::~Window()
 {
+  mIsBeingDeleted = true;
+
+  while ( mAdaptor && mAdaptor->IsRenderingWindows() )
+  {
+    std::this_thread::yield(); // to allow other threads to run
+  }
+
   if ( mEventHandler )
   {
     mEventHandler->RemoveObserver( *this );
   }
 }
 
-void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
+void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
 {
   // Create a window render surface
-  Any surface;
   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
@@ -872,6 +885,38 @@ Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
   return ConvertToOrientation( mRotationAngle );
 }
 
+void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
+{
+  Dali::Vector<float>::SizeType count = orientations.Count();
+  for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
+  {
+    if( IsOrientationAvailable( orientations[index] ) == false )
+    {
+      DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
+      continue;
+    }
+
+    bool found = false;
+    int convertedAngle = ConvertToAngle( orientations[index] );
+
+    for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
+    {
+      if( mAvailableAngles[i] == convertedAngle )
+      {
+        found = true;
+        break;
+      }
+    }
+
+    if( !found )
+    {
+      DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
+      mAvailableAngles.push_back( convertedAngle );
+    }
+  }
+  SetAvailableAnlges( mAvailableAngles );
+}
+
 } // Adaptor
 
 } // Internal