[Tizen] Fix webview rendering issue in TV 42/258442/2
authorJiyun Yang <ji.yang@samsung.com>
Tue, 18 May 2021 04:05:11 +0000 (13:05 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Thu, 20 May 2021 04:43:45 +0000 (13:43 +0900)
Change-Id: I7c2cb780862ec9bb27ad35cabfc6238e0b02ee17

automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp

index e9bd76e..fdf1697 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/public-api/image-loader/image.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include "dummy-control.h"
 
@@ -416,6 +417,51 @@ int UtcDaliImageVisualRemoteImageLoad(void)
   END_TEST;
 }
 
+
+int UtcDaliImageVisualWithNativeImage(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "Use Native Image as url" );
+
+  NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
+  std::string url = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
+
+  VisualFactory factory = VisualFactory::Get();
+  DALI_TEST_CHECK( factory );
+
+  Property::Map propertyMap;
+  propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Visual::IMAGE );
+  propertyMap.Insert( ImageVisual::Property::URL,  url );
+
+  Visual::Base visual = factory.CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  DummyControl actor = DummyControl::New();
+  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+  dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
+
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
+
+  application.GetScene().Add( actor );
+
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+
+  Renderer renderer = actor.GetRendererAt(0);
+  Shader shader = renderer.GetShader();
+
+  Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
+  DALI_TEST_CHECK(value.GetType() == Property::MAP);
+  const Property::Map* outMap = value.GetMap();
+  std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
+
+  const char* fragmentPrefix = nativeImageSource->GetCustomFragmentPrefix();
+  size_t pos = fragmentShader.find(fragmentPrefix);
+
+  DALI_TEST_EQUALS( pos != std::string::npos, true, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliImageVisualTextureReuse1(void)
 {
   ToolkitTestApplication application;
index 6907a90..3342374 100755 (executable)
@@ -109,52 +109,7 @@ 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
+} // namespace
 
 #define GET_ENUM_STRING(structName, inputExp) \
   Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
@@ -329,7 +284,11 @@ void WebView::LoadUrl(const std::string& url)
   mUrl = url;
   if(mWebEngine)
   {
-    mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
+    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}});
 
     if(mVisual)
     {
@@ -349,7 +308,11 @@ void WebView::LoadHtmlString(const std::string& htmlString)
 {
   if(mWebEngine)
   {
-    mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
+    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}});
 
     if(mVisual)
     {
index 03e0657..1c5f5e7 100644 (file)
@@ -626,6 +626,10 @@ void ImageVisual::InitializeRenderer()
   if(mTextures)
   {
     mImpl->mRenderer.SetTextures(mTextures);
+    if(DevelTexture::IsNative(mTextures.GetTexture(0)))
+    {
+      UpdateShader();
+    }
     mTextures.Reset(); // Visual should not keep a handle to the texture after this point.
   }