Supported position/size for underlay video rendering 88/136388/15
authortaeyoon0.lee <taeyoon0.lee@samsung.com>
Wed, 28 Jun 2017 15:29:40 +0000 (00:29 +0900)
committertaeyoon0.lee <taeyoon0.lee@samsung.com>
Tue, 4 Jul 2017 03:19:19 +0000 (12:19 +0900)
 - Set updated video display area by constraint
 - Set video display area by blending of renderer

Change-Id: I3c230796a170cf99a1a0fc7df3e0d3af5010599b

automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-trigger-event-factory.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.h
automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.h

index 521f265..19f812e 100755 (executable)
@@ -83,6 +83,7 @@ LIST(APPEND TC_SOURCES
    dali-toolkit-test-utils/toolkit-tts-player.cpp
    dali-toolkit-test-utils/toolkit-native-image-source.cpp
    dali-toolkit-test-utils/toolkit-video-player.cpp
+   dali-toolkit-test-utils/toolkit-trigger-event-factory.cpp
    dali-toolkit-test-utils/dali-test-suite-utils.cpp
    dali-toolkit-test-utils/dummy-control.cpp
    dali-toolkit-test-utils/mesh-builder.cpp
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-trigger-event-factory.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-trigger-event-factory.cpp
new file mode 100644 (file)
index 0000000..e2d0855
--- /dev/null
@@ -0,0 +1,54 @@
+
+#include <dali/integration-api/adaptors/trigger-event-interface.h>
+#include <dali/integration-api/adaptors/trigger-event-factory.h>
+#include <dali/public-api/signals/callback.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Toolkit
+{
+
+class TriggerEvent: public Dali::TriggerEventInterface
+{
+public:
+
+  TriggerEvent( Dali::CallbackBase* callback, Dali::TriggerEventInterface::Options Options );
+  ~TriggerEvent(){}
+
+  void Trigger();
+
+private:
+  Dali::CallbackBase* mCallback;
+
+};
+
+TriggerEvent::TriggerEvent( Dali::CallbackBase* callback, Dali::TriggerEventInterface::Options Options )
+  : mCallback( callback )
+{
+}
+
+void TriggerEvent::Trigger()
+{
+  Dali::CallbackBase::Execute( *mCallback );
+}
+
+} // namespace Toolkit
+
+} // namespace Internal
+
+} // namespace Dali
+
+Dali::TriggerEventInterface* Dali::TriggerEventFactory::CreateTriggerEvent( Dali::CallbackBase* callback, Dali::TriggerEventInterface::Options options )
+{
+  return new Dali::Internal::Toolkit::TriggerEvent( callback, options );
+}
+
+void Dali::TriggerEventFactory::DestroyTriggerEvent( Dali::TriggerEventInterface* triggerEventInterface )
+{
+  Dali::Internal::Toolkit::TriggerEvent* triggerEvent( static_cast< Dali::Internal::Toolkit::TriggerEvent *>(triggerEventInterface) );
+  delete triggerEvent;
+}
index 05e66d8..eee723b 100644 (file)
@@ -200,6 +200,10 @@ int VideoPlayer::GetPlayPosition()
   return 0;
 }
 
+void VideoPlayer::SetDisplayArea( DisplayArea area )
+{
+}
+
 void VideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
 {
 }
@@ -214,5 +218,13 @@ Dali::VideoPlayerPlugin::VideoPlayerSignalType& VideoPlayer::FinishedSignal()
   return Internal::Adaptor::GetImplementation( *this ).mFinishedSignal;
 }
 
+void VideoPlayer::Forward( int millisecond )
+{
+}
+
+void VideoPlayer::Backward( int millisecond )
+{
+}
+
 } // namespace Dali;
 
index 717a243..199fa12 100644 (file)
@@ -87,12 +87,18 @@ public:
 
   int GetPlayPosition();
 
+  void SetDisplayArea( DisplayArea area );
+
   void SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation );
 
   Dali::VideoPlayerPlugin::DisplayRotation GetDisplayRotation();
 
   Dali::VideoPlayerPlugin::VideoPlayerSignalType& FinishedSignal();
 
+  void Forward( int millisecond );
+
+  void Backward( int millisecond );
+
 private:
 
   VideoPlayer( Internal::Adaptor::VideoPlayer* internal );
index d082f07..884efc4 100644 (file)
@@ -346,6 +346,7 @@ int UtcDaliVideoViewCustomShaderForCoverage(void)
   ToolkitTestApplication application;
   VideoView videoView = VideoView::New();
   DALI_TEST_CHECK( videoView );
+
   Stage::GetCurrent().Add( videoView );
   videoView.SetProperty( VideoView::Property::VIDEO, "testvideo" );
 
@@ -362,6 +363,45 @@ int UtcDaliVideoViewCustomShaderForCoverage(void)
   Property::Value value = videoView.GetProperty( VideoView::Property::VIDEO );
 
   DALI_TEST_CHECK( !value.Get( map2 ) );
+  END_TEST;
+}
+
+int UtcDaliVideoViewMethodsForCoverage2(void)
+{
+  ToolkitTestApplication application;
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK( videoView );
+
+  Property::Map windowSurfaceTarget;
+
+  windowSurfaceTarget.Insert( RENDERING_TYPE, "windowSurfaceTarget" );
+
+  Stage::GetCurrent().Add( videoView );
+
+  application.SendNotification();
+  application.Render();
+
+  Property::Map map;
+  Property::Value value;
+  videoView.SetProperty( VideoView::Property::VIDEO, windowSurfaceTarget );
+
+  value = videoView.GetProperty( VideoView::Property::VIDEO );
+  DALI_TEST_CHECK( value.Get( map ) );
+
+  Property::Value* type = map.Find( RENDERING_TYPE );
+  DALI_TEST_CHECK( type );
+  DALI_TEST_EQUALS( "windowSurfaceTarget", type->Get<std::string>(), TEST_LOCATION );
+
+  Vector3 vector(100.0f, 100.0f, 0.0f);
+
+  DALI_TEST_CHECK(vector != videoView.GetCurrentSize());
+  videoView.SetSize( vector );
+
+  application.SendNotification();
+  application.Render();
+
+  // Check the size in the new frame
+  DALI_TEST_CHECK(vector == videoView.GetCurrentSize());
 
   END_TEST;
 }
index fc0f27d..b09de6b 100644 (file)
@@ -26,6 +26,9 @@
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
 #include <dali/integration-api/adaptors/adaptor.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/devel-api/actors/actor-devel.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
@@ -34,6 +37,7 @@
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 
 namespace Dali
 {
@@ -75,20 +79,72 @@ const char* const RENDERING_TARGET( "renderingTarget" );
 const char* const WINDOW_SURFACE_TARGET( "windowSurfaceTarget" );
 const char* const NATIVE_IMAGE_TARGET( "nativeImageTarget" );
 
+const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
+  attribute mediump vec2 aPosition;\n
+  uniform mediump mat4 uMvpMatrix;\n
+  uniform mediump vec3 uSize;\n
+  \n
+  void main()\n
+  {\n
+    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
+    vertexPosition.xyz *= uSize;\n
+    gl_Position = uMvpMatrix * vertexPosition;\n
+  }\n
+);
+
+const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
+  uniform lowp vec4 uColor;\n
+  uniform lowp vec3 mixColor;\n
+  uniform lowp float opacity;\n
+  \n
+  void main()\n
+  {\n
+    gl_FragColor = vec4(mixColor, opacity)*uColor;\n
+  }\n
+);
+
+struct TriggerFunctor
+{
+  TriggerFunctor( TriggerEventInterface* notification )
+  : mNotification( notification )
+  {
+  }
+
+  void operator()( bool& current, const PropertyInputContainer& inputs )
+  {
+    if( mNotification != NULL )
+    {
+      mNotification->Trigger();
+    }
+  }
+
+  TriggerEventInterface* mNotification;
+};
+
 } // anonymous namepsace
 
 VideoView::VideoView()
 : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ),
+  mUpdateTriggerPropertyIndex( Property::INVALID_INDEX),
+  mNotification( NULL ),
   mCurrentVideoPlayPosition( 0 ),
   mIsNativeImageTarget( true ),
   mIsPlay( false ),
   mIsPause( false )
 {
   mVideoPlayer = Dali::VideoPlayer::New();
+
+  TriggerEventFactory triggerEventFactory;
+  mNotification = triggerEventFactory.CreateTriggerEvent( MakeCallback(this, &VideoView::UpdateDisplayArea ),
+                                                               TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
 }
 
 VideoView::~VideoView()
 {
+  if( mNotification != NULL )
+  {
+    delete mNotification;
+  }
 }
 
 Toolkit::VideoView VideoView::New()
@@ -109,6 +165,8 @@ void VideoView::OnInitialize()
 
   mVideoPlayer.SetRenderingTarget( nativeImageSourcePtr );
   mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish );
+
+  mUpdateTriggerPropertyIndex = Self().RegisterProperty( "updateTrigger", true );
 }
 
 void VideoView::SetUrl( const std::string& url )
@@ -543,6 +601,11 @@ void VideoView::SetWindowSurfaceTarget()
     mVisual.Reset();
   }
 
+  Constraint constraint = Constraint::New<bool>( self, mUpdateTriggerPropertyIndex, TriggerFunctor( mNotification ) );
+  constraint.AddSource( Source( self, Actor::Property::POSITION ) );
+  constraint.AddSource( Source( self, Actor::Property::SIZE ) );
+  constraint.Apply();
+
   mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle() );
   mVideoPlayer.SetUrl( mUrl );
 
@@ -558,6 +621,18 @@ void VideoView::SetWindowSurfaceTarget()
     mVideoPlayer.Pause();
   }
   mVideoPlayer.SetPlayPosition( curPos );
+
+  // For underlay rendering mode, video display area have to be transparent.
+  Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
+  Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+  Renderer renderer = Renderer::New( geometry, shader );
+
+  renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ZERO );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ZERO );
+  self.AddRenderer( renderer );
 }
 
 void VideoView::SetNativeImageTarget()
@@ -588,8 +663,26 @@ void VideoView::SetNativeImageTarget()
   mVideoPlayer.SetPlayPosition( curPos );
 }
 
+void VideoView::UpdateDisplayArea()
+{
+  Actor self( Self() );
+
+  bool positionUsesAnchorPoint = self.GetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >();
+  Vector3 actorSize = self.GetCurrentSize() * self.GetCurrentScale();
+  Vector3 anchorPointOffSet = actorSize * ( positionUsesAnchorPoint ? self.GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT );
+
+  Vector2 screenPosition = self.GetProperty( DevelActor::Property::SCREEN_POSITION ).Get< Vector2 >();
+
+  mDisplayArea.x = screenPosition.x - anchorPointOffSet.x;
+  mDisplayArea.y = screenPosition.y - anchorPointOffSet.y;
+  mDisplayArea.width = actorSize.x;
+  mDisplayArea.height = actorSize.y;
+
+  mVideoPlayer.SetDisplayArea( mDisplayArea );
+}
+
 } // namespace Internal
 
-} // namespace Toolkit
+} // namespace toolkit
 
 } // namespace Dali
index a662802..130d2c2 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/images/native-image.h>
 #include <dali/devel-api/adaptor-framework/video-player.h>
+#include <dali/integration-api/adaptors/trigger-event-factory.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image/image-visual.h>
@@ -195,8 +196,22 @@ public:
    */
   static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
 
+  /**
+   * Connects a callback function with the object's signals.
+   * @param[in] object The object providing the signal.
+   * @param[in] tracker Used to disconnect the signal.
+   * @param[in] signalName The signal to connect to.
+   * @param[in] functor A newly allocated FunctorDelegate.
+   * @return True if the signal was connected.
+   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
+   */
   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
 
+  /*
+   * @brief Updates video display area for window rendering target
+   */
+  void UpdateDisplayArea();
+
 private: // From Control
 
   /**
@@ -249,6 +264,11 @@ private:
   Dali::NativeImage mNativeImage; ///< Native image handle for video rendering by texture streaming
   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
   std::string mUrl;
+  Dali::DisplayArea mDisplayArea;
+
+  Property::Index mUpdateTriggerPropertyIndex;
+  TriggerEventInterface* mNotification;
+
   int mCurrentVideoPlayPosition;
   bool mIsNativeImageTarget;
   bool mIsPlay;