Modified video view impl by considering visual 52/136352/7
authortaeyoon <taeyoon0.lee@samsung.com>
Fri, 9 Sep 2016 10:09:40 +0000 (19:09 +0900)
committertaeyoon0.lee <taeyoon0.lee@samsung.com>
Mon, 3 Jul 2017 04:46:59 +0000 (13:46 +0900)
 - modified rendering target and custom shader

Change-Id: I3f0d1082f4e210f23a2aec0524016bbc08b38ff5

automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.cpp

index 983ac77..d082f07 100644 (file)
@@ -31,6 +31,34 @@ const char* const VOLUME_LEFT( "volumeLeft" );
 const char* const VOLUME_RIGHT( "volumeRight" );
 const char* const RENDERING_TYPE( "renderingTarget" );
 
+const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
+  attribute mediump vec2 aPosition;\n
+  varying mediump vec2 vTexCoord;\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
+    vertexPosition = uMvpMatrix * vertexPosition;\n
+    \n
+    vTexCoord = aPosition + vec2(0.5);\n
+    gl_Position = vertexPosition;\n
+  }\n
+);
+
+const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
+  varying mediump vec2 vTexCoord;\n
+  uniform sampler2D sTexture;\n
+  uniform lowp vec4 uColor;\n
+  \n
+  void main()\n
+  {\n
+    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
+  }\n
+);
+
 }
 
 void video_view_startup(void)
@@ -312,3 +340,28 @@ int UtcDaliVideoViewMethodsForRenderType(void)
 
   END_TEST;
 }
+
+int UtcDaliVideoViewCustomShaderForCoverage(void)
+{
+  ToolkitTestApplication application;
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK( videoView );
+  Stage::GetCurrent().Add( videoView );
+  videoView.SetProperty( VideoView::Property::VIDEO, "testvideo" );
+
+  Property::Map customShader;
+  customShader.Insert( "vertexShader", VERTEX_SHADER );
+  customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
+
+  Property::Map map;
+  map.Insert( "shader", customShader );
+
+  videoView.SetProperty( VideoView::Property::VIDEO, map );
+
+  Property::Map map2;
+  Property::Value value = videoView.GetProperty( VideoView::Property::VIDEO );
+
+  DALI_TEST_CHECK( !value.Get( map2 ) );
+
+  END_TEST;
+}
index 1fd4be5..fc0f27d 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#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>
 
 namespace Dali
@@ -151,6 +155,18 @@ 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 )
+  {
+    this->SetWindowSurfaceTarget();
+  }
+  else if( target && target->Get( targetType ) && targetType == NATIVE_IMAGE_TARGET )
+  {
+    this->SetNativeImageTarget();
+  }
+
   RelayoutRequest();
 }
 
@@ -327,25 +343,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;