Fix VideoView to work in multi-window 90/209790/6
authorJiyun Yang <ji.yang@samsung.com>
Thu, 11 Jul 2019 05:34:50 +0000 (14:34 +0900)
committerJIYUN YANG <ji.yang@samsung.com>
Wed, 28 Aug 2019 05:53:52 +0000 (05:53 +0000)
Change-Id: Iee8738a904e8c835c291ff8d465488e6a7d4ea62
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.h

index 63bacde..9071613 100644 (file)
@@ -241,6 +241,11 @@ Any Adaptor::GetNativeWindowHandle()
   return window;
 }
 
+Any Adaptor::GetNativeWindowHandle( Actor actor )
+{
+  return GetNativeWindowHandle();
+}
+
 void Adaptor::ReleaseSurfaceLock()
 {
 }
index 93ce5a3..dfd441b 100755 (executable)
@@ -157,7 +157,6 @@ Toolkit::VideoView VideoView::New()
 void VideoView::OnInitialize()
 {
   mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish );
-  SetWindowSurfaceTarget();
 }
 
 void VideoView::SetUrl( const std::string& url )
@@ -228,7 +227,7 @@ bool VideoView::IsLooping()
 
 void VideoView::Play()
 {
-  if( mIsUnderlay )
+  if( mOverlayRenderer )
   {
     Self().AddRenderer( mOverlayRenderer );
   }
@@ -295,7 +294,7 @@ Dali::Toolkit::VideoView::VideoViewSignalType& VideoView::FinishedSignal()
 
 void VideoView::EmitSignalFinish()
 {
-  if( mIsUnderlay )
+  if( mOverlayRenderer )
   {
     Self().RemoveRenderer( mOverlayRenderer );
   }
@@ -378,91 +377,103 @@ bool VideoView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface*
   return connected;
 }
 
-void VideoView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+void VideoView::SetPropertyInternal( Property::Index index, const Property::Value& value )
 {
-  Toolkit::VideoView videoView = Toolkit::VideoView::DownCast( Dali::BaseHandle( object ) );
-
-  if( videoView )
+  switch( index )
   {
-    VideoView& impl = GetImpl( videoView );
-
-    switch( index )
+    case Toolkit::VideoView::Property::VIDEO:
     {
-      case Toolkit::VideoView::Property::VIDEO:
-      {
-        std::string videoUrl;
-        Property::Map map;
+      std::string videoUrl;
+      Property::Map map;
 
-        if( value.Get( videoUrl ) )
-        {
-          impl.SetUrl( videoUrl );
-        }
-        else if( value.Get( map ) )
-        {
-            impl.SetPropertyMap( map );
-          }
-        break;
+      if( value.Get( videoUrl ) )
+      {
+        SetUrl( videoUrl );
       }
-      case Toolkit::VideoView::Property::LOOPING:
+      else if( value.Get( map ) )
       {
-        bool looping;
-        if( value.Get( looping ) )
-        {
-          impl.SetLooping( looping );
-        }
-        break;
+        SetPropertyMap( map );
       }
-      case Toolkit::VideoView::Property::MUTED:
+      break;
+    }
+    case Toolkit::VideoView::Property::LOOPING:
+    {
+      bool looping;
+      if( value.Get( looping ) )
       {
-        bool mute;
-        if( value.Get( mute ) )
-        {
-          impl.SetMute( mute );
-        }
-        break;
+        SetLooping( looping );
       }
-      case Toolkit::VideoView::Property::VOLUME:
+      break;
+    }
+    case Toolkit::VideoView::Property::MUTED:
+    {
+      bool mute;
+      if( value.Get( mute ) )
       {
-        Property::Map map;
-        float left, right;
-        if( value.Get( map ) )
-        {
-          Property::Value* volumeLeft = map.Find( VOLUME_LEFT );
-          Property::Value* volumeRight = map.Find( VOLUME_RIGHT );
-          if( volumeLeft && volumeLeft->Get( left ) && volumeRight && volumeRight->Get( right ) )
-          {
-            impl.SetVolume( left, right );
-          }
-        }
-        break;
+        SetMute( mute );
       }
-      case Toolkit::VideoView::Property::UNDERLAY:
+      break;
+    }
+    case Toolkit::VideoView::Property::VOLUME:
+    {
+      Property::Map map;
+      float left, right;
+      if( value.Get( map ) )
       {
-        bool underlay;
-        if( value.Get( underlay ) )
+        Property::Value* volumeLeft = map.Find( VOLUME_LEFT );
+        Property::Value* volumeRight = map.Find( VOLUME_RIGHT );
+        if( volumeLeft && volumeLeft->Get( left ) && volumeRight && volumeRight->Get( right ) )
         {
-          impl.SetUnderlay( underlay );
+          SetVolume( left, right );
         }
-        break;
       }
-      case Toolkit::VideoView::Property::PLAY_POSITION:
+      break;
+    }
+    case Toolkit::VideoView::Property::UNDERLAY:
+    {
+      bool underlay;
+      if( value.Get( underlay ) )
       {
-        int pos;
-        if( value.Get( pos ) )
-        {
-          impl.SetPlayPosition( pos );
-        }
-        break;
+        SetUnderlay( underlay );
       }
-      case Toolkit::VideoView::Property::DISPLAY_MODE:
+      break;
+    }
+    case Toolkit::VideoView::Property::PLAY_POSITION:
+    {
+      int pos;
+      if( value.Get( pos ) )
       {
-        int mode;
-        if( value.Get( mode ) )
-        {
-          impl.SetDisplayMode( mode );
-        }
-        break;
+        SetPlayPosition( pos );
       }
+      break;
+    }
+    case Toolkit::VideoView::Property::DISPLAY_MODE:
+    {
+      int mode;
+      if( value.Get( mode ) )
+      {
+        SetDisplayMode( mode );
+      }
+      break;
+    }
+  }
+}
+
+void VideoView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+  Toolkit::VideoView videoView = Toolkit::VideoView::DownCast( Dali::BaseHandle( object ) );
+
+  if( videoView )
+  {
+    VideoView& impl = GetImpl( videoView );
+
+    impl.SetPropertyInternal( index, value );
+
+    if( index != Toolkit::VideoView::Property::UNDERLAY )
+    {
+      // Backup values.
+      // These values will be used when underlay mode is changed.
+      impl.mPropertyBackup[index] = value;
     }
   }
 }
@@ -543,6 +554,11 @@ void VideoView::SetDepthIndex( int depthIndex )
 void VideoView::OnStageConnection( int depth )
 {
   Control::OnStageConnection( depth );
+
+  if( mIsUnderlay )
+  {
+    SetWindowSurfaceTarget();
+  }
 }
 
 void VideoView::OnStageDisconnection()
@@ -594,6 +610,13 @@ float VideoView::GetWidthForHeight( float height )
 void VideoView::SetWindowSurfaceTarget()
 {
   Actor self = Self();
+
+  if( !self.OnStage() )
+  {
+    // When the control is off the stage, it does not have Window.
+    return;
+  }
+
   int curPos = mVideoPlayer.GetPlayPosition();
 
   if( mIsPlay )
@@ -613,8 +636,10 @@ void VideoView::SetWindowSurfaceTarget()
     self.RemoveRenderer( mTextureRenderer );
   }
 
-  mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle() );
-  mVideoPlayer.SetUrl( mUrl );
+  // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping)
+  mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle( self ) );
+
+  ApplyBackupProperties();
 
   if( !mOverlayRenderer )
   {
@@ -655,6 +680,8 @@ void VideoView::SetNativeImageTarget()
   if( mOverlayRenderer )
   {
     self.RemoveRenderer( mOverlayRenderer );
+
+    mOverlayRenderer.Reset();
   }
 
   self.RemovePropertyNotification( mPositionUpdateNotification );
@@ -684,8 +711,10 @@ void VideoView::SetNativeImageTarget()
   }
   Self().AddRenderer( mTextureRenderer );
 
+  // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping)
   mVideoPlayer.SetRenderingTarget( nativeImageSourcePtr );
-  mVideoPlayer.SetUrl( mUrl );
+
+  ApplyBackupProperties();
 
   if( mIsPlay )
   {
@@ -835,6 +864,19 @@ bool VideoView::GetStringFromProperty( const Dali::Property::Value& value, std::
   return extracted;
 }
 
+void VideoView::ApplyBackupProperties()
+{
+  Property::Map::SizeType pos = 0;
+  Property::Map::SizeType count = mPropertyBackup.Count();
+
+  for( ; pos < count; pos++ )
+  {
+    KeyValuePair property = mPropertyBackup.GetKeyValue( pos );
+
+    SetPropertyInternal( property.first.indexKey, property.second );
+  }
+}
+
 } // namespace Internal
 
 } // namespace toolkit
index bed7c9f..44695bb 100755 (executable)
@@ -316,6 +316,16 @@ private:
    */
   bool GetStringFromProperty( const Dali::Property::Value& value, std::string& output );
 
+  /*
+   * @brief Internal version of SetProperty
+   */
+  void SetPropertyInternal( Property::Index index, const Property::Value& value );
+
+  /*
+   * @brief Apply properties after reset video player
+   */
+  void ApplyBackupProperties();
+
 private:
 
   Dali::VideoPlayer mVideoPlayer;
@@ -331,6 +341,7 @@ private:
   Dali::PropertyNotification mPositionUpdateNotification;
   Dali::PropertyNotification mSizeUpdateNotification;
   Dali::PropertyNotification mScaleUpdateNotification;
+  Dali::Property::Map mPropertyBackup;
 
   int mCurrentVideoPlayPosition;
   bool mIsPlay;