Add Notification for check WidgetView is culled 63/243363/4 accepted/tizen/unified/20200911.043239 submit/tizen/20200910.200255
authorSunghyun Kim <scholb.kim@samsung.com>
Mon, 7 Sep 2020 05:44:28 +0000 (14:44 +0900)
committerSunghyun Kim <scholb.kim@samsung.com>
Thu, 10 Sep 2020 08:24:14 +0000 (17:24 +0900)
If WidgetView is out of the screen, Widget need to be paused.
For this, we added notification for check it.

Change-Id: I457b39d3a5477c205c6c0f946174651dd844322a

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

index 031d4762982881a0e7f84ad99689d60793eeef83..b18acdc2c618d0337b3467ce1a50a0f72a85dba2 100644 (file)
@@ -309,7 +309,9 @@ WidgetView::WidgetView()
   mBuffer( NULL ),
   mReloadFlag( false ),
   mCreated( false ),
-  mResizeRequired( false )
+  mResizeRequired( false ),
+  mCulled( false ),
+  mPausedManually( false )
 {
 }
 
@@ -335,7 +337,9 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI
   mBuffer( NULL ),
   mReloadFlag( false ),
   mCreated( false ),
-  mResizeRequired( false )
+  mResizeRequired( false ),
+  mCulled( false ),
+  mPausedManually( false )
 {
 }
 
@@ -344,6 +348,18 @@ WidgetView::~WidgetView()
 }
 
 bool WidgetView::PauseWidget()
+{
+  mPausedManually = true;
+  return PauseWidgetInternally();
+}
+
+bool WidgetView::ResumeWidget()
+{
+  mPausedManually = false;
+  return ResumeWidgetInternally();
+}
+
+bool WidgetView::PauseWidgetInternally()
 {
   int ret = widget_instance_pause( mInstanceId.c_str() );
   if( ret < 0 )
@@ -362,7 +378,7 @@ bool WidgetView::PauseWidget()
   return true;
 }
 
-bool WidgetView::ResumeWidget()
+bool WidgetView::ResumeWidgetInternally()
 {
   int ret = widget_instance_resume( mInstanceId.c_str() );
   if( ret < 0 )
@@ -622,6 +638,10 @@ bool WidgetView::TerminateWidget()
 
     mCreated = false;
     mResizeRequired = false;
+    mPausedManually = false;
+
+    Self().RemovePropertyNotification( mViewCulledNotification );
+
     return true;
   }
 
@@ -1060,12 +1080,18 @@ 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;
   mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEN_TYPE_WIDGET, this);
   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
   widget_service_set_lifecycle_event_cb( mWidgetId.c_str(), WidgetLifeCycleCallback, this );
+
 }
 
 void WidgetView::OnSceneConnection( int depth )
@@ -1101,6 +1127,31 @@ void WidgetView::OnWindowVisibilityChanged( Window window, bool visible )
   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnWindowVisibilityChanged: visibility is changed (visible: %d)\n", visible );
 }
 
+void WidgetView::OnChangeCulled( Dali::PropertyNotification& source )
+{
+  bool isCulled = Self().GetProperty( Actor::Property::CULLED ).Get< bool >();
+
+  if( mPausedManually )
+  {
+    mCulled = isCulled;
+    DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "Do not resume widget, because widget is paued manually \n");
+    return;
+  }
+
+  if( mCulled != isCulled )
+  {
+    if( isCulled )
+    {
+      PauseWidgetInternally();
+    }
+    else
+    {
+      ResumeWidgetInternally();
+    }
+    mCulled = isCulled;
+  }
+}
+
 void WidgetView::OnSizeSet( const Vector3& targetSize )
 {
 }
index 56729899344c5504087ce709b2c39c5527165820..113c8b2ef20cfaa374e4488e6dea1ead57659915 100644 (file)
@@ -32,6 +32,7 @@
 #include <tbm_surface.h>
 #include <screen_connector_toolkit.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/public-api/object/property-notification.h>
 
 namespace Dali
 {
@@ -287,11 +288,26 @@ private: // From Control
   virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize ) override ;
 private:
 
+  /**
+   * @brief Call a PauseWidget internally
+   */
+  bool PauseWidgetInternally();
+
+  /**
+   * @brief Call a ResumeWidget internally
+   */
+  bool ResumeWidgetInternally();
+
   /**
    * @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.
+   */
+  void OnChangeCulled( Dali::PropertyNotification& source );
+
   // Undefined
   WidgetView( const WidgetView& );
 
@@ -336,8 +352,11 @@ private:
   bool mReloadFlag;
   bool mCreated;
   bool mResizeRequired;
+  bool mCulled;
+  bool mPausedManually;
 
   Dali::Property::Map mEffectPropertyMap;
+  Dali::PropertyNotification mViewCulledNotification;
 
   // Signals
   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetAddedSignal;