/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
#include <toolkit-environment-variable.h>
#include <toolkit-event-thread-callback.h>
+#include <toolkit-style-monitor.h>
#include <toolkit-texture-upload-manager.h>
#include <toolkit-timer.h>
constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
+constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER";
+
+constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME";
+
+const char* VALID_DEBUG_SHADER_SCRIPT =
+ "{\n"
+ " \"version\": \"1.0.0\",\n"
+ " \"maximumColorRate\": 0.5,\n"
+ " \"extraVaryings\": [\"mediump vec3 vDebug;\"],\n"
+ " \"extraUniforms\": \"mediump float uDebug;\",\n"
+ " \"applyVaryingsCode\": \"vDebug = gl_Position.xyz / gl_Position.w;\",\n"
+ " \"redChannelCodes\":\n"
+ " {\n"
+ " \"triggerCode\":[\"return\",\" false;\"],\n"
+ " \"ratioCode\":\"return 0.0;\"\n"
+ " }\n"
+ "}\n";
+
+constexpr std::string_view THROW_EXCEPTION_STYLE_FILE_NAME = "throwException";
+
bool gResourceReadySignalFired = false;
std::vector<int> gReadyIds = {};
void ResourceReadySignal(Control control)
application.Render();
DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
- auto renderer = actor.GetRendererAt(0);
- auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
+ auto renderer = actor.GetRendererAt(0);
+
+ // Note : renderer don't have "premultipliedAlpha" at pre multiplied alpha enabled. (Since shader hold it.)
+ auto shader = renderer.GetShader();
+ auto preMultipliedIndex = shader.GetPropertyIndex("premultipliedAlpha");
DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
- auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
+ auto preMultipliedAlpha = shader.GetProperty<float>(preMultipliedIndex);
auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
application.Render();
DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
- auto renderer = actor.GetRendererAt(0);
- auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
+ auto renderer = actor.GetRendererAt(0);
+
+ // Note : renderer now have "premultipliedAlpha" since pre multiplied alpha disabled.
+ auto preMultipliedIndex = renderer.GetPropertyIndex("premultipliedAlpha");
DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
- auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
+ auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
- DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+ DALI_TEST_EQUALS(preMultipliedAlpha, 0.0f, TEST_LOCATION);
DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
application.Render();
DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
- auto renderer = actor.GetRendererAt(0);
- auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
+ auto renderer = actor.GetRendererAt(0);
+
+ // Note : renderer now have "premultipliedAlpha" since pre multiplied alpha disabled.
+ auto preMultipliedIndex = renderer.GetPropertyIndex("premultipliedAlpha");
DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
- auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
+ auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
- DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+ DALI_TEST_EQUALS(preMultipliedAlpha, 0.0f, TEST_LOCATION);
DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
auto newRenderer = newActor.GetRendererAt(0);
- preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
+ preMultipliedIndex = newRenderer.GetPropertyIndex("premultipliedAlpha");
DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
- preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
+ preMultipliedAlpha = newRenderer.GetProperty<float>(preMultipliedIndex);
preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
- DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
+ DALI_TEST_EQUALS(preMultipliedAlpha, 0.0f, TEST_LOCATION);
DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
END_TEST;
}
+int UtcDaliImageVisualCustomWrapModePixelArea02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area");
+
+ static std::vector<UniformData> customUniforms =
+ {
+ UniformData("pixelArea", Property::Type::VECTOR4),
+ UniformData("wrapMode", Property::Type::VECTOR2),
+ };
+
+ TestGraphicsController& graphics = application.GetGraphicsController();
+ graphics.AddCustomUniforms(customUniforms);
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
+ const int width = 34;
+ const int height = 34;
+ const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
+ propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
+ propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
+ propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
+ propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
+ propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
+ propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::CLAMP_TO_EDGE);
+
+ Visual::Base visual = factory.CreateVisual(propertyMap);
+ DALI_TEST_CHECK(visual);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+ TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+ texParameterTrace.Enable(true);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+ actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
+ actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ application.GetScene().Add(actor);
+
+ // loading started
+ application.SendNotification();
+ application.Render();
+
+ // Wait image load complete.
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
+
+ DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+ // Following gl function should not be called
+ std::stringstream out;
+ out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
+ DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
+ out.str("");
+ out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE;
+ DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
+
+ // test the uniforms which used to handle the wrap mode
+ Renderer renderer = actor.GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+
+ Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
+ DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
+ Vector4 pixelAreaUniform;
+ DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
+ DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
+
+ actor.Unparent();
+ DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
+
+ END_TEST;
+}
+
int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
{
ToolkitTestApplication application;
ToolkitTestApplication application;
tet_infoline("Animate mix color");
- static std::vector<UniformData> customUniforms =
- {
- UniformData("mixColor", Property::Type::VECTOR3),
- };
-
- TestGraphicsController& graphics = application.GetGraphicsController();
- graphics.AddCustomUniforms(customUniforms);
-
application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
VisualFactory factory = VisualFactory::Get();
application.SendNotification();
application.Render(0); // Ensure animation starts
application.Render(2000u); // Halfway point
- Vector3 testColor(1.0f, 0.0f, 0.5f);
+ Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f);
- // uColor.a should be actor's alpha * mixColor.a.
- DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
- DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
+ // uColor should be actor's color * mixColor.
+ DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f) * testColor), true, TEST_LOCATION);
DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
application.SendNotification();
DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
- DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
- DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE * TARGET_MIX_COLOR), true, TEST_LOCATION);
// (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
application.GetScene().Add(actor);
+ Property::Map resultMap;
+ imageVisual.CreatePropertyMap(resultMap);
+
+ // check the Property::ORIENTATION_CORRECTION value from the returned map
+ Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
+ DALI_TEST_CHECK(typeValue);
+ DALI_TEST_EQUALS(typeValue->Get<bool>(), false, TEST_LOCATION);
+
+ Vector2 originalImageSize;
+ tet_infoline("Get size of original visual before load image");
+ imageVisual.GetNaturalSize(originalImageSize);
dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
+ DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
+
// Wait for image to load
DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
- Vector2 originalImageSize;
+ Vector2 nonRotatedImageSize;
tet_infoline("Get size of original visual to compare later with rotated image");
- imageVisual.GetNaturalSize(originalImageSize);
- DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
- imageVisual.Reset(); // remove handle so can unregister it and remove from cache
+ imageVisual.GetNaturalSize(nonRotatedImageSize);
+ DALI_TEST_GREATER(nonRotatedImageSize.width, nonRotatedImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
+
+ // Note : The size of original image is bigger than MAX_TEXTURE_SIZE. origianImageSize might not be same as nonRotatedImageSize.
+ // TODO : Shouldn't we need to fix it?
+
dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
application.SendNotification();
application.Render();
propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
imageVisual = factory.CreateVisual(propertyMap);
+ Vector2 rotatedImageSize;
+ imageVisual.GetNaturalSize(rotatedImageSize);
+ tet_infoline("Confirm that visual has rotated, even if ");
+ DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
+ DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
+
dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
// Wait for image to load
DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
- Vector2 rotatedImageSize;
imageVisual.GetNaturalSize(rotatedImageSize);
tet_infoline("Confirm that visual has rotated");
- DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
- DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
+ DALI_TEST_EQUALS(nonRotatedImageSize.width, rotatedImageSize.height, TEST_LOCATION);
+ DALI_TEST_EQUALS(nonRotatedImageSize.height, rotatedImageSize.width, TEST_LOCATION);
- Property::Map resultMap;
imageVisual.CreatePropertyMap(resultMap);
// check the Property::ORIENTATION_CORRECTION value from the returned map
- Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
+ typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
+ DALI_TEST_CHECK(typeValue);
DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
END_TEST;
}
+int UtcDaliImageVisualOrientationCorrectionCache(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageVisualOrientationCorrectionCache Check orientation correction value give effort to cache hit");
+
+ VisualFactory factory = VisualFactory::Get();
+ tet_infoline("Create visual with Orientation correction set OFF");
+ Property::Map propertyMap;
+ propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
+ propertyMap.Insert("orientationCorrection", false);
+ Visual::Base imageVisual1 = factory.CreateVisual(propertyMap);
+
+ tet_infoline("Create control for visual, need to loaded it");
+ DummyControl actor1 = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(actor1.GetImplementation());
+ dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
+ application.GetScene().Add(actor1);
+
+ // Wait for image to load
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ tet_infoline("Create visual with Orientation correction set ON ");
+ propertyMap.Clear();
+ propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
+ propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
+ Visual::Base imageVisual2 = factory.CreateVisual(propertyMap);
+
+ tet_infoline("Create control for visual2, need to loaded it");
+ DummyControl actor2 = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
+ dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
+ application.GetScene().Add(actor2);
+
+ // Wait for image to load. Check whether each correction and non-correction image have difference size.
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ Vector2 visual1NaturalSize;
+ imageVisual1.GetNaturalSize(visual1NaturalSize);
+ Vector2 visual2NaturalSize;
+ imageVisual2.GetNaturalSize(visual2NaturalSize);
+
+ DALI_TEST_NOT_EQUALS(visual1NaturalSize.width, visual1NaturalSize.height, 0.01f, TEST_LOCATION); // Width and Height must be different for this test.
+
+ tet_infoline("Confirm that visual has rotated");
+ DALI_TEST_EQUALS(visual1NaturalSize.width, visual2NaturalSize.height, TEST_LOCATION);
+ DALI_TEST_EQUALS(visual1NaturalSize.height, visual2NaturalSize.width, TEST_LOCATION);
+
+ END_TEST;
+}
+
int UtcDaliImageVisualCustomShader(void)
{
ToolkitTestApplication application;
application.Render();
END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliImageVisualDebugImageVisualShaderP1(void)
+{
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "validFile"); // Try to load not exist file.
+
+ // Set valid script file
+ Test::StyleMonitor::SetThemeFileOutput("validFile", VALID_DEBUG_SHADER_SCRIPT);
+
+ ToolkitTestApplication application;
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+
+ 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);
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualDebugImageVisualShaderN1(void)
+{
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "notJsonFile"); // Try to load exist file, but not a json
+
+ // Set invalid script file
+ Test::StyleMonitor::SetThemeFileOutput("notJsonFile", "1");
+
+ ToolkitTestApplication application;
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+
+ 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);
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualDebugImageVisualShaderN2(void)
+{
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
+ EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, std::string(THROW_EXCEPTION_STYLE_FILE_NAME).c_str()); // Try to load file that throw some exception
+
+ // Set throw exception script file
+ Test::StyleMonitor::SetThemeFileOutput(std::string(THROW_EXCEPTION_STYLE_FILE_NAME), "1");
+
+ ToolkitTestApplication application;
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+
+ 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);
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualSynchronousSizing01(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageVisualSynchronousSizing01");
+
+ Vector2 size = Vector2(64.0f, 64.0f);
+ uint32_t width = 64;
+ uint32_t height = 64;
+
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+ imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+ imagePropertyMap.Insert(Toolkit::DevelImageVisual::Property::SYNCHRONOUS_SIZING, true);
+
+ Toolkit::ImageView imageView = Toolkit::ImageView::New();
+ imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
+ imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ imageView.SetProperty(Actor::Property::SIZE, size);
+
+ DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(imageView);
+
+ // load image as size 0x0 (Since we cannot ensure the size of actor yet)
+ // (Texture size is its original size, not the actor size.)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ // Check (current image texture size != actor size)
+ Renderer renderer = imageView.GetRendererAt(0);
+ TextureSet textures = renderer.GetTextures();
+ DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
+
+ Texture texture = textures.GetTexture(0);
+ DALI_TEST_EQUALS(texture.GetWidth(), 128u, TEST_LOCATION);
+ DALI_TEST_EQUALS(texture.GetHeight(), 128u, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
+
+ // load image as size 200x200 (Now we can ensure the size of actor is 200x200)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ // Set size again
+ imageView.SetProperty(Actor::Property::SIZE, size);
+
+ // Check (reloaded image texture size == actor size)
+ renderer = imageView.GetRendererAt(0);
+ textures = renderer.GetTextures();
+ DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
+
+ texture = textures.GetTexture(0);
+ DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
+ DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualSynchronousSizing02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageVisualSynchronousSizing02");
+
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+ imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+ imagePropertyMap.Insert(Toolkit::DevelImageVisual::Property::SYNCHRONOUS_SIZING, true);
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Visual::Base visual = factory.CreateVisual(imagePropertyMap);
+
+ Vector2 size;
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
+
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); // set size(1), no renderer yet
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ // load image as size 0x0 (Since we cannot ensure the size of actor yet)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ application.SendNotification(); // require to load size(1)
+
+ // load image as size 200x200 (Now we can ensure the size of actor is 200x200)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render();
+
+ actor.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f)); // set size(2), no renderer yet
+ visual.GetNaturalSize(size); // get size(1)
+ DALI_TEST_EQUALS(size, Vector2(200.0f, 200.0f), 0.001f, TEST_LOCATION);
+
+ application.SendNotification(); // require to load size(2)
+ application.Render();
+
+ // reload image
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ visual.GetNaturalSize(size); // get size(2)
+ DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliImageVisualSynchronousSizing03(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliImageVisualSynchronousSizing03");
+
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+ imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
+ imagePropertyMap.Insert("synchronousSizing", true);
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK(factory);
+
+ Visual::Base visual1 = factory.CreateVisual(imagePropertyMap); // Create duplicated visuals, to check whether cache system works well.
+ Visual::Base visual2 = factory.CreateVisual(imagePropertyMap);
+ Visual::Base visual3 = factory.CreateVisual(imagePropertyMap);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable(true);
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual1);
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 2, visual2);
+ dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 3, visual3);
+
+ actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); // set size(1), no renderer yet
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ // load image as size 0x0 (Since we cannot ensure the size of actor yet)
+ // NOTE : This behavior might be changed in future.
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+
+ application.SendNotification(); // require to load size(1)
+
+ // load image as size 200x200 (Now we can ensure the size of actor is 200x200)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 2, TEST_LOCATION);
+
+ textureTrace.Reset();
+
+ // Unparent and Add again. Check whether the texture is cached.
+ actor.Unparent();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
+
+ textureTrace.Reset();
+
+ actor.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f)); // set size(2)
+
+ DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+ DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
+
+ application.SendNotification(); // require to load size(2)
+
+ // load image as size 100x100 (Now we can ensure the size of actor is 100x100)
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
+
+ END_TEST;
+}