Check area for widget pause/resume automatically 34/244334/8 accepted/tizen/unified/20200921.042431 accepted/tizen/unified/20200924.072527 submit/tizen/20200918.105610 submit/tizen/20200921.011116 submit/tizen/20200923.133541 submit/tizen/20200923.193806
authorSunghyun Kim <scholb.kim@samsung.com>
Thu, 17 Sep 2020 10:06:53 +0000 (19:06 +0900)
committerSunghyun Kim <scholb.kim@samsung.com>
Fri, 18 Sep 2020 10:39:04 +0000 (19:39 +0900)
widgetView need to check area for widget pause/resume

Change-Id: I3958e5f7dd92b9fdfae57b9d79e3a07a1bbc7c52

widget_viewer_dali/internal/widget_view/widget_view_impl.cpp
widget_viewer_dali/internal/widget_view/widget_view_impl.h

index c3d5a0cc27d475ca859ccfa83e0ebc38412f20ff..fc0da92ae1d166903f0716884d76a6b6d35da61b 100644 (file)
@@ -28,6 +28,9 @@
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/object/property-array.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/actors/camera-actor.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali/integration-api/debug.h>
@@ -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;
   }
 }
 
index 113c8b2ef20cfaa374e4488e6dea1ead57659915..d206604ac83608224118252203df4dc0317cf606 100644 (file)
@@ -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;