#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"
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;
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)
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)
{
{
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)
{