X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fvideo-view%2Fvideo-view-impl.cpp;h=8c34ab5dc464e5f67144918245843d41b038a676;hp=25dff0111ada502c8519d19aa408af7f067ac60c;hb=dc3bbd29a417e1fbc7f81104c60c5ba90212f216;hpb=3297062b74ec6c1e48177974e3d8d7de9b86ff57 diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp old mode 100644 new mode 100755 index 25dff01..8c34ab5 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,19 +25,14 @@ #include #include #include -#include #include #include #include // INTERNAL INCLUDES #include -#include -#include -#include -#include -#include #include +#include namespace Dali { @@ -63,6 +58,8 @@ 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_PROPERTY_REGISTRATION( Toolkit, VideoView, "playPosition", INTEGER, PLAY_POSITION ) +DALI_PROPERTY_REGISTRATION( Toolkit, VideoView, "displayMode", INTEGER, DISPLAY_MODE ) DALI_SIGNAL_REGISTRATION( Toolkit, VideoView, "finished", FINISHED_SIGNAL ) @@ -82,9 +79,15 @@ const char* const RENDERING_TARGET( "renderingTarget" ); const char* const WINDOW_SURFACE_TARGET( "windowSurfaceTarget" ); const char* const NATIVE_IMAGE_TARGET( "nativeImageTarget" ); +const char* const CUSTOM_SHADER( "shader" ); +const char* const CUSTOM_VERTEX_SHADER( "vertexShader" ); +const char* const CUSTOM_FRAGMENT_SHADER( "fragmentShader" ); +const char* const DEFAULT_SAMPLER_TYPE_NAME( "sampler2D" ); +const char* const CUSTOM_SAMPLER_TYPE_NAME( "samplerExternalOES" ); + const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n - uniform mediump mat4 uMvpMatrix;\n + uniform highp mat4 uMvpMatrix;\n uniform mediump vec3 uSize;\n \n void main()\n @@ -96,13 +99,33 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( ); 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 + gl_FragColor = vec4(0.0);\n + }\n +); + +const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + attribute mediump vec2 aPosition;\n + varying mediump vec2 vTexCoord;\n + uniform highp mat4 uMvpMatrix;\n + uniform mediump vec3 uSize;\n + varying mediump vec2 sTexCoordRect;\n + void main()\n + {\n + gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n + vTexCoord = aPosition + vec2(0.5);\n + }\n +); + +const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + uniform lowp vec4 uColor;\n + varying mediump vec2 vTexCoord;\n + uniform samplerExternalOES sTexture;\n + void main()\n + {\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n }\n ); @@ -134,22 +157,12 @@ Toolkit::VideoView VideoView::New() void VideoView::OnInitialize() { mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish ); - SetWindowSurfaceTarget(); } void VideoView::SetUrl( const std::string& url ) { - if( mUrl != url || !mPropertyMap.Empty() ) - { mUrl = url; mPropertyMap.Clear(); - } - - if( !mIsUnderlay ) - { - Actor self( Self() ); - Internal::InitializeVisual( self, mVisual, mNativeImage ); - } mVideoPlayer.SetUrl( mUrl ); } @@ -158,29 +171,6 @@ void VideoView::SetPropertyMap( Property::Map map ) { mPropertyMap = map; - Actor self( Self() ); - Internal::InitializeVisual( self, mVisual, mPropertyMap ); - - Property::Value* widthValue = mPropertyMap.Find( "width" ); - if( widthValue ) - { - int width; - if( widthValue->Get( width ) ) - { - mVideoSize = ImageDimensions( width, mVideoSize.GetHeight() ); - } - } - - Property::Value* heightValue = mPropertyMap.Find( "height" ); - if( heightValue ) - { - int height; - if( heightValue->Get( height ) ) - { - mVideoSize = ImageDimensions( mVideoSize.GetWidth(), height ); - } - } - Property::Value* target = map.Find( RENDERING_TARGET ); std::string targetType; @@ -195,6 +185,28 @@ void VideoView::SetPropertyMap( Property::Map map ) SetNativeImageTarget(); } + // Custom shader + Property::Value* shaderValue; + if( !map.Empty() ) + { + shaderValue = map.Find( CUSTOM_SHADER ); + + if( shaderValue ) + { + Property::Map* shaderMap = shaderValue->GetMap(); + if( shaderMap ) + { + mEffectPropertyMap = *shaderMap; + } + } + } + + if( mTextureRenderer && !mEffectPropertyMap.Empty() ) + { + Dali::Shader shader = CreateShader(); + mTextureRenderer.SetShader( shader ); + } + RelayoutRequest(); } @@ -203,7 +215,7 @@ std::string VideoView::GetUrl() return mUrl; } -void VideoView::SetLooping(bool looping) +void VideoView::SetLooping( bool looping ) { mVideoPlayer.SetLooping( looping ); } @@ -215,9 +227,9 @@ bool VideoView::IsLooping() void VideoView::Play() { - if( mIsUnderlay ) + if( mOverlayRenderer ) { - Self().AddRenderer( mRenderer ); + Self().AddRenderer( mOverlayRenderer ); } mVideoPlayer.Play(); @@ -282,9 +294,9 @@ Dali::Toolkit::VideoView::VideoViewSignalType& VideoView::FinishedSignal() void VideoView::EmitSignalFinish() { - if( mIsUnderlay ) + if( mOverlayRenderer ) { - Self().RemoveRenderer( mRenderer ); + Self().RemoveRenderer( mOverlayRenderer ); } if ( !mFinishedSignal.Empty() ) @@ -365,92 +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 ); + case Toolkit::VideoView::Property::VIDEO: + { + std::string videoUrl; + Property::Map map; - switch( index ) + if( value.Get( videoUrl ) ) + { + SetUrl( videoUrl ); + } + else if( value.Get( map ) ) + { + SetPropertyMap( map ); + } + break; + } + case Toolkit::VideoView::Property::LOOPING: { - case Toolkit::VideoView::Property::VIDEO: + bool looping; + if( value.Get( looping ) ) { - std::string videoUrl; - Property::Map map; - - if( value.Get( videoUrl ) ) - { - impl.SetUrl( videoUrl ); - } - else if( value.Get( map ) ) - { - Property::Value* shaderValue = map.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); - - if( map.Count() > 1u || !shaderValue ) - { - impl.SetPropertyMap( map ); - } - else if( impl.mVisual && map.Count() == 1u && shaderValue ) - { - 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; + SetLooping( looping ); } - case Toolkit::VideoView::Property::LOOPING: + break; + } + case Toolkit::VideoView::Property::MUTED: + { + bool mute; + if( value.Get( mute ) ) { - bool looping; - if( value.Get( looping ) ) - { - impl.SetLooping( looping ); - } - break; + SetMute( mute ); } - case Toolkit::VideoView::Property::MUTED: + break; + } + case Toolkit::VideoView::Property::VOLUME: + { + Property::Map map; + float left, right; + if( value.Get( map ) ) { - bool mute; - if( value.Get( mute ) ) + Property::Value* volumeLeft = map.Find( VOLUME_LEFT ); + Property::Value* volumeRight = map.Find( VOLUME_RIGHT ); + if( volumeLeft && volumeLeft->Get( left ) && volumeRight && volumeRight->Get( right ) ) { - impl.SetMute( mute ); + SetVolume( left, right ); } - break; } - case Toolkit::VideoView::Property::VOLUME: + break; + } + case Toolkit::VideoView::Property::UNDERLAY: + { + bool underlay; + if( value.Get( underlay ) ) { - 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; + SetUnderlay( underlay ); } - case Toolkit::VideoView::Property::UNDERLAY: + break; + } + case Toolkit::VideoView::Property::PLAY_POSITION: + { + int pos; + if( value.Get( pos ) ) { - bool underlay; - if( value.Get( underlay ) ) - { - impl.SetUnderlay( underlay ); - } - 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; } } } @@ -504,6 +527,16 @@ Property::Value VideoView::GetProperty( BaseObject* object, Property::Index prop value = impl.IsUnderlay(); break; } + case Toolkit::VideoView::Property::PLAY_POSITION: + { + value = impl.GetPlayPosition(); + break; + } + case Toolkit::VideoView::Property::DISPLAY_MODE: + { + value = impl.GetDisplayMode(); + break; + } } } @@ -512,31 +545,24 @@ Property::Value VideoView::GetProperty( BaseObject* object, Property::Index prop void VideoView::SetDepthIndex( int depthIndex ) { - if( mVisual ) + if( mTextureRenderer ) { - mVisual.SetDepthIndex( depthIndex ); + mTextureRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex ); } } void VideoView::OnStageConnection( int depth ) { - if( mVisual ) + Control::OnStageConnection( depth ); + + if( mIsUnderlay ) { - CustomActor self = Self(); - Toolkit::GetImplementation(mVisual).SetOnStage( self ); + SetWindowSurfaceTarget(); } - - Control::OnStageConnection( depth ); } void VideoView::OnStageDisconnection() { - if( mVisual ) - { - CustomActor self = Self(); - Toolkit::GetImplementation(mVisual).SetOffStage( self ); - } - Control::OnStageDisconnection(); } @@ -584,14 +610,15 @@ float VideoView::GetWidthForHeight( float height ) void VideoView::SetWindowSurfaceTarget() { Actor self = Self(); - int curPos = mVideoPlayer.GetPlayPosition(); - if( mVisual ) + if( !self.OnStage() ) { - Toolkit::GetImplementation(mVisual).SetOffStage(self); - mVisual.Reset(); + // When the control is off the stage, it does not have Window. + return; } + int curPos = mVideoPlayer.GetPlayPosition(); + if( mIsPlay ) { mVideoPlayer.Pause(); @@ -604,21 +631,23 @@ void VideoView::SetWindowSurfaceTarget() mSizeUpdateNotification.NotifySignal().Connect( this, &VideoView::UpdateDisplayArea ); mScaleUpdateNotification.NotifySignal().Connect( this, &VideoView::UpdateDisplayArea ); - mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle() ); - mVideoPlayer.SetUrl( mUrl ); + if( mTextureRenderer ) + { + self.RemoveRenderer( mTextureRenderer ); + } + + // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping) + mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle( self ) ); - if( !mRenderer ) + ApplyBackupProperties(); + + if( !mOverlayRenderer ) { // 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 ); + mOverlayRenderer = Renderer::New( geometry, shader ); + mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); } if( mIsPlay ) @@ -647,8 +676,13 @@ void VideoView::SetNativeImageTarget() } Actor self( Self() ); - self.RemoveRenderer( mRenderer ); - Dali::Stage::GetCurrent().KeepRendering( 0.0f ); + + if( mOverlayRenderer ) + { + self.RemoveRenderer( mOverlayRenderer ); + + mOverlayRenderer.Reset(); + } self.RemovePropertyNotification( mPositionUpdateNotification ); self.RemovePropertyNotification( mSizeUpdateNotification ); @@ -658,13 +692,29 @@ void VideoView::SetNativeImageTarget() Any source; Dali::NativeImageSourcePtr nativeImageSourcePtr = Dali::NativeImageSource::New( source ); - mNativeImage = Dali::NativeImage::New( *nativeImageSourcePtr ); + mNativeTexture = Dali::Texture::New( *nativeImageSourcePtr ); + + if( !mTextureRenderer ) + { + Dali::Geometry geometry = VisualFactoryCache::CreateQuadGeometry(); + Dali::Shader shader = CreateShader(); + Dali::TextureSet textureSet = Dali::TextureSet::New(); + textureSet.SetTexture( 0u, mNativeTexture ); + mTextureRenderer = Renderer::New( geometry, shader ); + mTextureRenderer.SetTextures( textureSet ); + } + else + { + Dali::TextureSet textureSet = mTextureRenderer.GetTextures(); + textureSet.SetTexture( 0u, mNativeTexture ); + } + Self().AddRenderer( mTextureRenderer ); + + // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping) mVideoPlayer.SetRenderingTarget( nativeImageSourcePtr ); - mVideoPlayer.SetUrl( mUrl ); - Internal::InitializeVisual( self, mVisual, mNativeImage ); - Self().RemoveRenderer( mRenderer ); + ApplyBackupProperties(); if( mIsPlay ) { @@ -724,6 +774,114 @@ bool VideoView::IsUnderlay() return mIsUnderlay; } +void VideoView::SetSWCodec( bool on ) +{ + // If setting SW or HW type is failed , video-view shows video by default codec type. + // The default codec type is selected by platform. + if( on ) + { + mVideoPlayer.SetCodecType( Dali::VideoPlayerPlugin::CodecType::SW ); + } + else + { + mVideoPlayer.SetCodecType( Dali::VideoPlayerPlugin::CodecType::HW ); + } +} + +int VideoView::GetPlayPosition() +{ + return mVideoPlayer.GetPlayPosition(); +} + +void VideoView::SetPlayPosition( int pos ) +{ + mVideoPlayer.SetPlayPosition( pos ); +} + +void VideoView::SetDisplayMode( int mode ) +{ + mVideoPlayer.SetDisplayMode( static_cast< Dali::VideoPlayerPlugin::DisplayMode::Type >( mode ) ); +} + +int VideoView::GetDisplayMode() const +{ + return static_cast< int >( mVideoPlayer.GetDisplayMode() ); +} + +Any VideoView::GetMediaPlayer() +{ + return mVideoPlayer.GetMediaPlayer(); +} + +Dali::Shader VideoView::CreateShader() +{ + std::string fragmentShader = "#extension GL_OES_EGL_image_external:require\n"; + std::string vertexShader; + std::string customFragmentShader; + bool checkShader = false; + + if( !mEffectPropertyMap.Empty() ) + { + Property::Value* vertexShaderValue = mEffectPropertyMap.Find( CUSTOM_VERTEX_SHADER ); + if( vertexShaderValue ) + { + checkShader = GetStringFromProperty( *vertexShaderValue, vertexShader ); + } + + if( !vertexShaderValue || !checkShader ) + { + vertexShader = VERTEX_SHADER_TEXTURE; + } + + Property::Value* fragmentShaderValue = mEffectPropertyMap.Find( CUSTOM_FRAGMENT_SHADER ); + if( fragmentShaderValue ) + { + checkShader = GetStringFromProperty( *fragmentShaderValue, customFragmentShader ); + + if( checkShader ) + { + fragmentShader = customFragmentShader; + } + } + + if( !fragmentShaderValue || !checkShader ) + { + fragmentShader += FRAGMENT_SHADER_TEXTURE; + } + } + else + { + vertexShader = VERTEX_SHADER_TEXTURE; + fragmentShader += FRAGMENT_SHADER_TEXTURE; + } + + return Dali::Shader::New( vertexShader, fragmentShader ); +} + +bool VideoView::GetStringFromProperty( const Dali::Property::Value& value, std::string& output ) +{ + bool extracted = false; + if( value.Get( output ) ) + { + extracted = true; + } + + 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