From f407d341fa68daa7b1e4758995636173705167d4 Mon Sep 17 00:00:00 2001 From: Sunghyun Kim Date: Thu, 17 Sep 2020 19:06:53 +0900 Subject: [PATCH] Check area for widget pause/resume automatically widgetView need to check area for widget pause/resume Change-Id: I3958e5f7dd92b9fdfae57b9d79e3a07a1bbc7c52 --- .../internal/widget_view/widget_view_impl.cpp | 89 ++++++++++++++----- .../internal/widget_view/widget_view_impl.h | 15 +++- 2 files changed, 80 insertions(+), 24 deletions(-) diff --git a/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp b/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp index c3d5a0c..fc0da92 100644 --- a/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp +++ b/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -300,7 +303,7 @@ WidgetView::WidgetView() mReloadFlag( false ), mCreated( false ), mResizeRequired( false ), - mCulled( false ), + mPaused( false ), mPausedManually( false ) { } @@ -328,7 +331,7 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI mReloadFlag( false ), mCreated( false ), mResizeRequired( false ), - mCulled( false ), + mPaused( false ), mPausedManually( false ) { } @@ -363,7 +366,7 @@ bool WidgetView::PauseWidgetInternally() tizen_remote_surface_transfer_visibility( mRemoteSurface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_INVISIBLE); } - DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() ); + DALI_LOG_RELEASE_INFO("WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() ); return true; } @@ -382,11 +385,36 @@ bool WidgetView::ResumeWidgetInternally() tizen_remote_surface_transfer_visibility( mRemoteSurface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE); } - DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() ); + DALI_LOG_RELEASE_INFO("WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() ); return true; } +bool WidgetView::IsOutOfScreen() +{ + Actor self = Self(); + Window window = DevelWindow::Get( self ); + RenderTaskList taskList = window.GetRenderTaskList(); + RenderTask task = taskList.GetTask( 0u ); + Vector3 cameraPosition = task.GetCameraActor().GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >(); + Vector3 worldPosition = self.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >(); + Vector2 size = self.GetProperty( Actor::Property::SIZE ).Get< Vector2 >(); + Vector3 worldScale = self.GetProperty( Actor::Property::WORLD_SCALE ).Get< Vector3 >(); + + Vector2 windowSize = window.GetSize(); + worldPosition -= cameraPosition; + + Vector2 actorSize = Vector2(size.width*worldScale.x , size.height*worldScale.y); + if( worldPosition.x >= (-0.5f)*(actorSize.width + windowSize.width) && worldPosition.x <= (0.5f)*(actorSize.width + windowSize.width) ) + { + if( worldPosition.y >= (-0.5f)*(actorSize.height + windowSize.height) && worldPosition.y <= (0.5f)*(actorSize.height + windowSize.height) ) + { + return false; + } + } + return true; +} + const std::string& WidgetView::GetWidgetId() const { return mWidgetId; @@ -630,8 +658,6 @@ bool WidgetView::TerminateWidget() mResizeRequired = false; mPausedManually = false; - Self().RemovePropertyNotification( mViewCulledNotification ); - return true; } @@ -1070,11 +1096,6 @@ void WidgetView::OnInitialize() return; } - // Add Notification for check WidgetView is culled or not. - mViewCulledNotification = Self().AddPropertyNotification( Actor::Property::CULLED, LessThanCondition( 0.5f ) ); - mViewCulledNotification.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED ); - mViewCulledNotification.NotifySignal().Connect( this, &WidgetView::OnChangeCulled ); - ops.updated_cb = OnBufferUpdated; ops.removed_cb = OnSurfaceRemoved; ops.added_cb = OnBufferAdded; @@ -1089,6 +1110,19 @@ void WidgetView::OnSceneConnection( int depth ) if( window ) { DevelWindow::VisibilityChangedSignal( window ).Connect( this, &WidgetView::OnWindowVisibilityChanged ); + + // Add Notification for check WidgetView is out-of-screen or not. + auto self = Self(); + mPositionUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_POSITION, StepCondition( 1.0f, 1.0f ) ); + mPositionUpdateNotification.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED ); + mSizeUpdateNotification = self.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ) ); + mSizeUpdateNotification.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED ); + mScaleUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_SCALE, StepCondition( 0.1f, 1.0f ) ); + mScaleUpdateNotification.SetNotifyMode( PropertyNotification::NOTIFY_ON_CHANGED ); + + mPositionUpdateNotification.NotifySignal().Connect( this, &WidgetView::OnUpdateArea ); + mSizeUpdateNotification.NotifySignal().Connect( this, &WidgetView::OnUpdateArea ); + mScaleUpdateNotification.NotifySignal().Connect( this, &WidgetView::OnUpdateArea ); } } @@ -1099,36 +1133,51 @@ void WidgetView::OnSceneDisconnection() if( window ) { DevelWindow::VisibilityChangedSignal( window ).Disconnect( this, &WidgetView::OnWindowVisibilityChanged ); + + Self().RemovePropertyNotification( mPositionUpdateNotification ); + Self().RemovePropertyNotification( mSizeUpdateNotification ); + Self().RemovePropertyNotification( mScaleUpdateNotification ); } } void WidgetView::OnWindowVisibilityChanged( Window window, bool visible ) { + bool needPaused = IsOutOfScreen(); + if( mPausedManually ) + { + mPaused = ( needPaused || !visible ); + DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "Do not resume widget, because widget is paued manually \n"); + return; + } + if( visible ) { - ResumeWidget(); + if( !needPaused) + { + ResumeWidgetInternally(); + } } else { - PauseWidget(); + PauseWidgetInternally(); } + DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnWindowVisibilityChanged: visibility is changed (visible: %d)\n", visible ); } -void WidgetView::OnChangeCulled( Dali::PropertyNotification& source ) +void WidgetView::OnUpdateArea( Dali::PropertyNotification& source ) { - bool isCulled = Self().GetProperty( Actor::Property::CULLED ).Get< bool >(); - + bool needPaused = IsOutOfScreen(); if( mPausedManually ) { - mCulled = isCulled; + mPaused = needPaused; DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "Do not resume widget, because widget is paued manually \n"); return; } - if( mCulled != isCulled ) + if( mPaused != needPaused ) { - if( isCulled ) + if( needPaused ) { PauseWidgetInternally(); } @@ -1136,7 +1185,7 @@ void WidgetView::OnChangeCulled( Dali::PropertyNotification& source ) { ResumeWidgetInternally(); } - mCulled = isCulled; + mPaused = needPaused; } } diff --git a/widget_viewer_dali/internal/widget_view/widget_view_impl.h b/widget_viewer_dali/internal/widget_view/widget_view_impl.h index 113c8b2..d206604 100644 --- a/widget_viewer_dali/internal/widget_view/widget_view_impl.h +++ b/widget_viewer_dali/internal/widget_view/widget_view_impl.h @@ -298,15 +298,20 @@ private: */ bool ResumeWidgetInternally(); + /** + * @brief check WidgetView is out of screen. + */ + bool IsOutOfScreen(); + /** * @brief Callback when the visibility of the window is changed. */ void OnWindowVisibilityChanged( Window window, bool visible ); /** - * @brief Callback when the actor is out of the view frustum. + * @brief Callback when the actor area is changed */ - void OnChangeCulled( Dali::PropertyNotification& source ); + void OnUpdateArea( Dali::PropertyNotification& source ); // Undefined WidgetView( const WidgetView& ); @@ -352,11 +357,13 @@ private: bool mReloadFlag; bool mCreated; bool mResizeRequired; - bool mCulled; + bool mPaused; bool mPausedManually; Dali::Property::Map mEffectPropertyMap; - Dali::PropertyNotification mViewCulledNotification; + Dali::PropertyNotification mPositionUpdateNotification; + Dali::PropertyNotification mSizeUpdateNotification; + Dali::PropertyNotification mScaleUpdateNotification; // Signals Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetAddedSignal; -- 2.34.1