Tizen] Set custom fragment shader to the visual used in WebView accepted/tizen_6.0_unified_hotfix tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.113840 accepted/tizen/6.0/unified/hotfix/20201103.001935 accepted/tizen/unified/20201007.090630 submit/tizen/20201006.153948 submit/tizen_6.0/20201029.205105 submit/tizen_6.0_hotfix/20201102.192505 submit/tizen_6.0_hotfix/20201103.114805 tizen_6.0.m2_release
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Tue, 6 Oct 2020 04:12:53 +0000 (13:12 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Tue, 6 Oct 2020 04:14:51 +0000 (13:14 +0900)
This reverts commit 7a54226e11bb314ac4f03db8f3a7598395ccb66b.

dali-toolkit/internal/controls/web-view/web-view-impl.cpp

index c79e74a..a24d6a6 100644 (file)
@@ -81,6 +81,51 @@ DALI_TYPE_REGISTRATION_END()
 
 const std::string kEmptyString;
 
+const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
+
+const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
+  varying mediump vec2 vTexCoord;\n
+  uniform sampler2D sTexture;\n
+  uniform lowp vec4 uColor;\n
+  uniform lowp vec3 mixColor;\n
+  uniform lowp float preMultipliedAlpha;\n
+  \n
+  void main()\n
+  {\n
+      gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n
+  }\n
+);
+
+Dali::Toolkit::Visual::Base CreateNativeImageVisual( NativeImageInterfacePtr nativeImageInterface )
+{
+  std::string fragmentShader;
+
+  const char* fragmentPrefix = nativeImageInterface->GetCustomFragmentPrefix();
+  if( fragmentPrefix )
+  {
+    fragmentShader = fragmentPrefix;
+    fragmentShader += FRAGMENT_SHADER_TEXTURE;
+  }
+  else
+  {
+    fragmentShader = FRAGMENT_SHADER_TEXTURE;
+  }
+
+  const char* customSamplerTypename = nativeImageInterface->GetCustomSamplerTypename();
+  if( customSamplerTypename )
+  {
+    fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename );
+  }
+
+  Texture texture = Dali::Texture::New( *nativeImageInterface );
+  const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture( texture );
+
+  return Toolkit::VisualFactory::Get().CreateVisual(
+    { { Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE } ,
+      { Toolkit::Visual::Property::SHADER, { { Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, fragmentShader } } },
+      { Toolkit::ImageVisual::Property::URL, nativeImageUrl } } );
+}
+
 } // anonymous namepsace
 
 #define GET_ENUM_STRING( structName, inputExp ) \
@@ -153,11 +198,7 @@ void WebView::LoadUrl( const std::string& url )
   mUrl = url;
   if( mWebEngine )
   {
-    Texture texture = Dali::Texture::New( *mWebEngine.GetNativeImageSource() );
-    const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture( texture );
-    mVisual = Toolkit::VisualFactory::Get().CreateVisual(
-      { { Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE } ,
-        { Toolkit::ImageVisual::Property::URL, nativeImageUrl } } );
+    mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
 
     if( mVisual )
     {
@@ -172,11 +213,7 @@ void WebView::LoadHTMLString( const std::string& htmlString )
 {
   if( mWebEngine )
   {
-    Texture texture = Dali::Texture::New( *mWebEngine.GetNativeImageSource() );
-    const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture( texture );
-    mVisual = Toolkit::VisualFactory::Get().CreateVisual(
-      { { Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE } ,
-        { Toolkit::ImageVisual::Property::URL, nativeImageUrl } } );
+    mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
 
     if( mVisual )
     {