From 8d168e25b93f1c75f04eca490b0c8adbf954a275 Mon Sep 17 00:00:00 2001 From: Sunghyun kim Date: Wed, 22 Jan 2020 11:16:42 +0900 Subject: [PATCH] [Tizen]Apply multi Instance for widget Change-Id: If676925fefc5bd28d9fd3fd147ba19e51760bbe1 --- dali/internal/adaptor/common/adaptor-impl.cpp | 8 +++ dali/internal/adaptor/common/adaptor-impl.h | 5 ++ .../widget-application-impl-tizen.cpp | 81 ++++++++++++++++++---- .../tizen-wayland/widget-application-impl-tizen.h | 18 ++++- dali/public-api/adaptor-framework/widget-impl.cpp | 1 - dali/public-api/adaptor-framework/widget-impl.h | 2 +- dali/public-api/adaptor-framework/widget.h | 1 - dali/public-api/adaptor-framework/window.cpp | 30 ++++++-- 8 files changed, 119 insertions(+), 27 deletions(-) diff --git a/dali/internal/adaptor/common/adaptor-impl.cpp b/dali/internal/adaptor/common/adaptor-impl.cpp index 6049e0e..695688f 100755 --- a/dali/internal/adaptor/common/adaptor-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-impl.cpp @@ -1065,6 +1065,14 @@ void Adaptor::UnregisterProcessor( Integration::Processor& processor ) GetCore().UnregisterProcessor(processor); } +bool Adaptor::IsMultipleWindowSupported() const +{ + auto eglGraphics = static_cast( mGraphics ); + EglImplementation& eglImpl = eglGraphics->GetEglImplementation(); + bool ret = eglImpl.IsSurfacelessContextSupported(); + return ret; +} + void Adaptor::RequestUpdateOnce() { if( mThreadController ) diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index c151865..fd39a3a 100755 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -438,6 +438,11 @@ public: */ void UnregisterProcessor( Integration::Processor& processor ); + /** + * Check MultipleWindow is supported + */ + bool IsMultipleWindowSupported() const; + public: //AdaptorInternalServices /** diff --git a/dali/internal/system/tizen-wayland/widget-application-impl-tizen.cpp b/dali/internal/system/tizen-wayland/widget-application-impl-tizen.cpp index 9393dd8..ff22534 100644 --- a/dali/internal/system/tizen-wayland/widget-application-impl-tizen.cpp +++ b/dali/internal/system/tizen-wayland/widget-application-impl-tizen.cpp @@ -47,8 +47,26 @@ int OnInstanceInit(widget_base_instance_h instanceHandle, bundle *content, int w Dali::Internal::Adaptor::WidgetApplicationTizen* application = static_cast(classData); - // After DALi can support multi window, this part should be changed. - Dali::Window window = application->GetWindow(); + Dali::Window window; + if( application->GetWidgetCount() == 0) + { + window = application->GetWindow(); + DALI_LOG_RELEASE_INFO("Widget Instance use default Window(win:%p), so it need to bind widget (%dx%d) (id:%s) \n",window, w, h, std::string(id).c_str()); + } + else + { + window = Dali::Window::New(PositionSize(0,0,w,h) ,"", false); + if( window ) + { + DALI_LOG_RELEASE_INFO("Widget Instance create new Window (win:%p, cnt:%d) (%dx%d) (id:%s )\n", window, application->GetWidgetCount(), w, h, std::string(id).c_str()); + } + else + { + DALI_LOG_ERROR("This device can't support Multi Widget. it means UI may not be properly drawn."); + window = application->GetWindow(); + } + } + Any nativeHandle = window.GetNativeHandle(); #ifdef ECORE_WAYLAND2 @@ -64,7 +82,7 @@ int OnInstanceInit(widget_base_instance_h instanceHandle, bundle *content, int w Dali::WidgetApplication::CreateWidgetFunction createFunction = pair.second; Dali::Widget widgetInstance = createFunction( pair.first ); - application->AddWidget( instanceHandle, widgetInstance ); + application->AddWidget( instanceHandle, widgetInstance , window ); Dali::Internal::Adaptor::Widget::Impl *widgetImpl = new Dali::Internal::Adaptor::WidgetImplTizen(instanceHandle); Internal::Adaptor::GetImplementation(widgetInstance).SetImpl( widgetImpl ); @@ -157,8 +175,7 @@ int OnInstanceResize(widget_base_instance_h instanceHandle, int w, int h, void * // Get Dali::Widget instance. Dali::Widget widgetInstance = application->GetWidget( instanceHandle ); - - Dali::Window window = application->GetWindow(); + Dali::Window window = application->GetWindowFromWidget( instanceHandle ); window.SetSize( Dali::Window::WindowSize(w, h) ); Internal::Adaptor::GetImplementation(widgetInstance).OnResize(window); @@ -244,9 +261,11 @@ void WidgetApplicationTizen::AddWidgetCreatingFunctionPair( CreateWidgetFunction WidgetApplicationTizen::CreateWidgetFunctionPair WidgetApplicationTizen::GetWidgetCreatingFunctionPair( const std::string& widgetName ) { + int idx = widgetName.find(":"); + std::string widgetID = widgetName.substr( idx + 1 ); for( CreateWidgetFunctionContainer::const_iterator iter = mCreateWidgetFunctionContainer.begin(); iter != mCreateWidgetFunctionContainer.end(); ++iter ) { - if( widgetName.find((*iter).first) != std::string::npos ) + if( widgetID.compare((*iter).first) == 0) { return *iter; } @@ -255,18 +274,19 @@ WidgetApplicationTizen::CreateWidgetFunctionPair WidgetApplicationTizen::GetWidg return CreateWidgetFunctionPair( "", NULL ); } -void WidgetApplicationTizen::AddWidget( widget_base_instance_h widgetBaseInstance, Dali::Widget widget ) +void WidgetApplicationTizen::AddWidget( widget_base_instance_h widgetBaseInstance, Dali::Widget widget , Dali::Window window ) { mWidgetInstanceContainer.push_back( WidgetInstancePair(widgetBaseInstance, widget) ); + mWindowInstanceContainer.push_back( WindowInstancePair(widgetBaseInstance, window) ); } -Dali::Widget WidgetApplicationTizen::GetWidget( widget_base_instance_h widgetBaseInstance ) +Dali::Widget WidgetApplicationTizen::GetWidget( widget_base_instance_h widgetBaseInstance ) const { - for( WidgetInstanceContainer::const_iterator iter = mWidgetInstanceContainer.begin(); iter != mWidgetInstanceContainer.end(); ++iter ) + for( auto&& iter : mWidgetInstanceContainer ) { - if( (*iter).first == widgetBaseInstance ) + if( (iter).first == widgetBaseInstance ) { - return (*iter).second; + return (iter).second; } } return Dali::Widget(); @@ -274,14 +294,45 @@ Dali::Widget WidgetApplicationTizen::GetWidget( widget_base_instance_h widgetBas void WidgetApplicationTizen::DeleteWidget( widget_base_instance_h widgetBaseInstance ) { - for( WidgetInstanceContainer::const_iterator iter = mWidgetInstanceContainer.begin(); iter != mWidgetInstanceContainer.end(); ++iter ) + // Delete WidgetInstance + auto widgetInstance = std::find_if( mWidgetInstanceContainer.begin(), + mWidgetInstanceContainer.end(), + [widgetBaseInstance]( WidgetInstancePair pair ) + { return (pair.first == widgetBaseInstance); } ); + + if(widgetInstance != mWidgetInstanceContainer.end()) { - if( (*iter).first == widgetBaseInstance ) + mWidgetInstanceContainer.erase(widgetInstance); + } + + // Delete WindowInstance + auto windowInstance = std::find_if( mWindowInstanceContainer.begin(), + mWindowInstanceContainer.end(), + [widgetBaseInstance]( WindowInstancePair pair ) + { return (pair.first == widgetBaseInstance); } ); + + if(windowInstance != mWindowInstanceContainer.end()) + { + mWindowInstanceContainer.erase(windowInstance); + } +} + +Dali::Window WidgetApplicationTizen::GetWindowFromWidget( widget_base_instance_h widgetBaseInstance ) const +{ + for( auto&& iter : mWindowInstanceContainer ) + { + if( (iter).first == widgetBaseInstance ) { - mWidgetInstanceContainer.erase(iter); - break; + Dali::Window ret = (iter).second; + return ret; } } + return Dali::Window(); +} + +int WidgetApplicationTizen::GetWidgetCount() +{ + return mWidgetInstanceContainer.size(); } void WidgetApplicationTizen::OnInit() diff --git a/dali/internal/system/tizen-wayland/widget-application-impl-tizen.h b/dali/internal/system/tizen-wayland/widget-application-impl-tizen.h index 9e94388..b7b12a8 100644 --- a/dali/internal/system/tizen-wayland/widget-application-impl-tizen.h +++ b/dali/internal/system/tizen-wayland/widget-application-impl-tizen.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -80,18 +81,28 @@ public: /** * Add widget_base_instance_h - Widget instance pair to container. */ - void AddWidget( widget_base_instance_h widgetBaseInstance, Dali::Widget widget ); + void AddWidget( widget_base_instance_h widgetBaseInstance, Dali::Widget widget , Dali::Window window ); /** * Find and get Widget instance in container by widget_base_instance_h. */ - Dali::Widget GetWidget( widget_base_instance_h widgetBaseInstance ); + Dali::Widget GetWidget( widget_base_instance_h widgetBaseInstance ) const; /** * Delete widget_base_instance_h - Widget instance pair in container. */ void DeleteWidget( widget_base_instance_h widgetBaseInstance ); + /** + * Find and get Window instance in container by widget_base_instance_h. + */ + Dali::Window GetWindowFromWidget( widget_base_instance_h widgetBaseInstance ) const; + + /** + * Get the number of created widget. + */ + int32_t GetWidgetCount(); + protected: /** @@ -118,6 +129,9 @@ private: CreateWidgetFunctionContainer mCreateWidgetFunctionContainer; WidgetInstanceContainer mWidgetInstanceContainer; + typedef std::pair< widget_base_instance_h, Dali::Window > WindowInstancePair; + typedef std::vector< WindowInstancePair > WindowInstanceContainer; + WindowInstanceContainer mWindowInstanceContainer; }; } // namespace Adaptor diff --git a/dali/public-api/adaptor-framework/widget-impl.cpp b/dali/public-api/adaptor-framework/widget-impl.cpp index 7bf34c6..7d67815 100644 --- a/dali/public-api/adaptor-framework/widget-impl.cpp +++ b/dali/public-api/adaptor-framework/widget-impl.cpp @@ -19,7 +19,6 @@ #include "widget-impl.h" // INTERNAL INCLUDES -#include #include namespace Dali diff --git a/dali/public-api/adaptor-framework/widget-impl.h b/dali/public-api/adaptor-framework/widget-impl.h index c30ddc6..75b61da 100644 --- a/dali/public-api/adaptor-framework/widget-impl.h +++ b/dali/public-api/adaptor-framework/widget-impl.h @@ -24,10 +24,10 @@ // INTERNAL INCLUDES #include +#include namespace Dali { -class Window; /** * @addtogroup dali_adaptor_framework diff --git a/dali/public-api/adaptor-framework/widget.h b/dali/public-api/adaptor-framework/widget.h index a0f6991..9332298 100755 --- a/dali/public-api/adaptor-framework/widget.h +++ b/dali/public-api/adaptor-framework/widget.h @@ -42,7 +42,6 @@ class Widget; } -class Window; /** * @brief Widget class is the base class for custom widget. diff --git a/dali/public-api/adaptor-framework/window.cpp b/dali/public-api/adaptor-framework/window.cpp index 2edfae3..08562d0 100644 --- a/dali/public-api/adaptor-framework/window.cpp +++ b/dali/public-api/adaptor-framework/window.cpp @@ -36,10 +36,18 @@ Window Window::New(PositionSize posSize, const std::string& name, bool isTranspa Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(posSize, name, "", isTransparent); Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get(); - Integration::SceneHolder sceneHolder = Integration::SceneHolder( window ); - Internal::Adaptor::Adaptor::GetImplementation( adaptor ).AddWindow( sceneHolder, name, "", isTransparent ); + 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); + return Window(window); + } + else + { + DALI_LOG_ERROR("This device can't support multiple windows.\n"); + return Window(); + } } Window Window::New(PositionSize posSize, const std::string& name, const std::string& className, bool isTransparent) @@ -47,10 +55,18 @@ Window Window::New(PositionSize posSize, const std::string& name, const std::str Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(posSize, name, className, isTransparent); Dali::Adaptor& adaptor = Internal::Adaptor::Adaptor::Get(); - Integration::SceneHolder sceneHolder = Integration::SceneHolder( window ); - Internal::Adaptor::Adaptor::GetImplementation( adaptor ).AddWindow( sceneHolder, name, className, isTransparent ); - - return Window(window); + if( Internal::Adaptor::Adaptor::GetImplementation( adaptor ).IsMultipleWindowSupported() ) + { + Integration::SceneHolder sceneHolder = Integration::SceneHolder( window ); + Internal::Adaptor::Adaptor::GetImplementation( adaptor ).AddWindow( sceneHolder, name, className, isTransparent ); + + return Window(window); + } + else + { + DALI_LOG_ERROR("This device can't support multiple windows.\n"); + return Window(); + } } Window::Window() -- 2.7.4