X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fvideo-view%2Fvideo-view-impl.cpp;h=58349507c9e25770c3fd5010662deaef5e35bff1;hb=bc5e9a0b52e07309fd557deb212333d1798109f3;hp=2ec07ef8a9a293c55d2461d0ae883ffda10d6566;hpb=1e7f2e72fcc37576c754ca2ed563ece458942960;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp index 2ec07ef..5834950 100644 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -26,10 +26,18 @@ #include #include #include +#include +#include +#include // INTERNAL INCLUDES #include +#include +#include +#include +#include #include +#include namespace Dali { @@ -54,6 +62,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "video", MAP, VIDEO ) DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "looping", BOOLEAN, LOOPING ) DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "muted", BOOLEAN, MUTED ) DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "volume", MAP, VOLUME ) +DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "underlay", BOOLEAN, UNDERLAY ) DALI_SIGNAL_REGISTRATION( Toolkit, VideoView, "finished", FINISHED_SIGNAL ) @@ -67,24 +76,78 @@ DALI_TYPE_REGISTRATION_END() const char* const VOLUME_LEFT( "volumeLeft" ); const char* const VOLUME_RIGHT( "volumeRight" ); -const char* const RENDERING_TARGET( "RENDERING_TARGET" ); + +// 3.0 TC uses RENDERING_TARGET. It should be removed in next release +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 ), - mSetRenderingTarget( false ), mIsPlay( false ), - mIsPause( false ) + mIsPause( false ), + mIsUnderlay( true ) { 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() @@ -97,23 +160,28 @@ Toolkit::VideoView VideoView::New() return handle; } +void VideoView::OnInitialize() +{ + mUpdateTriggerPropertyIndex = Self().RegisterProperty( "updateTrigger", true ); + mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish ); + SetWindowSurfaceTarget(); +} + void VideoView::SetUrl( const std::string& url ) { if( mUrl != url || !mPropertyMap.Empty() ) { - mPropertyMap.Clear(); - mUrl = url; + mPropertyMap.Clear(); } - if( mSetRenderingTarget ) - { - mVideoPlayer.SetUrl( mUrl ); - } - else + if( !mIsUnderlay ) { - SetNativeImageTarget(); + Actor self( Self() ); + Internal::InitializeVisual( self, mVisual, mNativeImage ); } + + mVideoPlayer.SetUrl( mUrl ); } void VideoView::SetPropertyMap( Property::Map map ) @@ -143,6 +211,20 @@ void VideoView::SetPropertyMap( Property::Map map ) } } + Property::Value* target = map.Find( RENDERING_TARGET ); + std::string targetType; + + if( target && target->Get( targetType ) && targetType == WINDOW_SURFACE_TARGET ) + { + mIsUnderlay = true; + SetWindowSurfaceTarget(); + } + else if( target && target->Get( targetType ) && targetType == NATIVE_IMAGE_TARGET ) + { + mIsUnderlay = false; + SetNativeImageTarget(); + } + RelayoutRequest(); } @@ -319,25 +401,33 @@ void VideoView::SetProperty( BaseObject* object, Property::Index index, const Pr case Toolkit::VideoView::Property::VIDEO: { std::string videoUrl; + Property::Map map; + if( value.Get( videoUrl ) ) { impl.SetUrl( videoUrl ); } - - Property::Map map; - if( value.Get( map ) ) + else if( value.Get( map ) ) { - impl.SetPropertyMap( map ); + Property::Value* shaderValue = map.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); - Property::Value* target = map.Find( RENDERING_TARGET ); - std::string targetType; - if( target && target->Get( targetType ) && targetType == WINDOW_SURFACE_TARGET ) + if( map.Count() > 1u || !shaderValue ) { - impl.SetWindowSurfaceTarget(); + impl.SetPropertyMap( map ); } - else if( target && target->Get( targetType ) && targetType == NATIVE_IMAGE_TARGET ) + else if( impl.mVisual && map.Count() == 1u && shaderValue ) { - impl.SetNativeImageTarget(); + Property::Map shaderMap; + if( shaderValue->Get( shaderMap ) ) + { + Internal::Visual::Base& visual = Toolkit::GetImplementation( impl.mVisual ); + visual.SetCustomShader( shaderMap ); + if( videoView.OnStage() ) + { + visual.SetOffStage( videoView ); + visual.SetOnStage( videoView ); + } + } } } break; @@ -375,6 +465,15 @@ void VideoView::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::VideoView::Property::UNDERLAY: + { + bool underlay; + if( value.Get( underlay ) ) + { + impl.SetUnderlay( underlay ); + } + break; + } } } } @@ -423,6 +522,11 @@ Property::Value VideoView::GetProperty( BaseObject* object, Property::Index prop value = map; break; } + case Toolkit::VideoView::Property::UNDERLAY: + { + value = impl.IsUnderlay(); + break; + } } } @@ -505,17 +609,36 @@ void VideoView::SetWindowSurfaceTarget() Actor self = Self(); int curPos = mVideoPlayer.GetPlayPosition(); - mSetRenderingTarget = true; - if( mVisual ) { Toolkit::GetImplementation(mVisual).SetOffStage(self); mVisual.Reset(); } + Constraint constraint = Constraint::New( 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 ); - mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish ); + + if( !mRenderer ) + { + // For underlay rendering mode, video display area have to be transparent. + Geometry geometry = VisualFactoryCache::CreateQuadGeometry(); + Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mRenderer = Renderer::New( geometry, shader ); + + mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + mRenderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE ); + mRenderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ZERO ); + mRenderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE ); + mRenderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ZERO ); + } + self.AddRenderer( mRenderer ); + + UpdateDisplayArea(); if( mIsPlay ) { @@ -526,25 +649,34 @@ void VideoView::SetWindowSurfaceTarget() mVideoPlayer.Play(); mVideoPlayer.Pause(); } - mVideoPlayer.SetPlayPosition( curPos ); + + if( curPos > 0 ) + { + mVideoPlayer.SetPlayPosition( curPos ); + } } void VideoView::SetNativeImageTarget() { + if( mVideoPlayer.IsVideoTextureSupported() == false ) + { + DALI_LOG_ERROR( "Platform doesn't support decoded video frame images\n" ); + mIsUnderlay = true; + return; + } + Actor self( Self() ); int curPos = mVideoPlayer.GetPlayPosition(); - mSetRenderingTarget = true; - Any source; Dali::NativeImageSourcePtr nativeImageSourcePtr = Dali::NativeImageSource::New( source ); mNativeImage = Dali::NativeImage::New( *nativeImageSourcePtr ); mVideoPlayer.SetRenderingTarget( nativeImageSourcePtr ); mVideoPlayer.SetUrl( mUrl ); - mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish ); Internal::InitializeVisual( self, mVisual, mNativeImage ); + Self().RemoveRenderer( mRenderer ); if( mIsPlay ) { @@ -556,11 +688,59 @@ void VideoView::SetNativeImageTarget() mVideoPlayer.Play(); mVideoPlayer.Pause(); } - mVideoPlayer.SetPlayPosition( curPos ); + if( curPos > 0 ) + { + mVideoPlayer.SetPlayPosition( curPos ); + } +} + +void VideoView::UpdateDisplayArea() +{ + if( !mIsUnderlay ) + { + return; + } + + 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 ); +} + +void VideoView::SetUnderlay( bool set ) +{ + if( set != mIsUnderlay ) + { + mIsUnderlay = set; + + if( mIsUnderlay ) + { + SetWindowSurfaceTarget(); + } + else + { + SetNativeImageTarget(); + } + } +} + +bool VideoView::IsUnderlay() +{ + return mIsUnderlay; } } // namespace Internal -} // namespace Toolkit +} // namespace toolkit } // namespace Dali