2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-environment-variable.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <toolkit-timer.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
30 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
33 #include <dali-toolkit/public-api/image-loader/image-url.h>
34 #include <dali-toolkit/public-api/image-loader/image.h>
36 #include "dummy-control.h"
37 #include "test-encoded-image-buffer.h"
38 #include "test-native-image-source.h"
41 using namespace Dali::Toolkit;
43 void dali_image_visual_startup(void)
45 test_return_value = TET_UNDEF;
48 void dali_image_visual_cleanup(void)
50 test_return_value = TET_PASS;
55 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
56 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
57 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
58 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
59 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
60 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
61 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
62 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
63 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
65 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
67 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
68 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
70 bool gResourceReadySignalFired = false;
71 std::vector<int> gReadyIds = {};
72 void ResourceReadySignal(Control control)
74 gResourceReadySignalFired = true;
75 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
82 Actor CreateActorWithImageVisual(const Property::Map& map)
84 VisualFactory factory = VisualFactory::Get();
85 DummyControl actor = DummyControl::New();
86 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
87 Visual::Base visual = factory.CreateVisual(map);
88 DALI_TEST_CHECK(visual);
89 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
90 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
91 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
95 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
97 VisualFactory factory = VisualFactory::Get();
99 Property::Map propertyMap;
100 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
101 propertyMap.Insert(ImageVisual::Property::URL, url);
102 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
103 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
104 propertyMap.Insert(key, value);
106 return factory.CreateVisual(propertyMap);
111 void TestVisualRender(ToolkitTestApplication& application,
113 Visual::Base& visual,
114 std::size_t expectedSamplers = 0,
115 ImageDimensions imageDimensions = ImageDimensions(),
116 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
118 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
119 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
123 // set the image size, for test case, this needs to be set before loading started
124 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
127 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
128 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
130 application.GetScene().Add(actor);
132 application.SendNotification(); // Send messages to update
133 application.Render(); // process update and render
134 application.SendNotification(); // process any signals to event
138 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
141 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
144 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
147 visual.CreatePropertyMap(map);
148 Property::Value* value = map.Find(mixColorIndex);
149 DALI_TEST_CHECK(value);
151 DALI_TEST_CHECK(value->Get(mixColor1));
152 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
154 value = map.Find(Visual::Property::MIX_COLOR);
155 DALI_TEST_CHECK(value);
157 DALI_TEST_CHECK(value->Get(mixColor2));
158 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
160 value = map.Find(Visual::Property::OPACITY);
161 DALI_TEST_CHECK(value);
163 DALI_TEST_CHECK(value->Get(opacity));
164 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
167 int UtcDaliImageVisualPropertyMap(void)
169 ToolkitTestApplication application;
170 tet_infoline("Request image visual with a Property::Map");
172 VisualFactory factory = VisualFactory::Get();
173 DALI_TEST_CHECK(factory);
174 factory.SetPreMultiplyOnLoad(true);
176 Property::Map propertyMap;
177 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
178 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
180 Visual::Base visual = factory.CreateVisual(propertyMap);
181 DALI_TEST_CHECK(visual);
183 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
184 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
186 TestGlAbstraction& gl = application.GetGlAbstraction();
187 TraceCallStack& textureTrace = gl.GetTextureTrace();
188 textureTrace.Enable(true);
190 DummyControl actor = DummyControl::New();
191 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
194 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
195 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
197 application.GetScene().Add(actor);
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
203 application.SendNotification();
204 application.Render();
206 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
207 auto renderer = actor.GetRendererAt(0);
208 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
209 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
210 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
211 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
212 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
213 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
214 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
216 application.GetScene().Remove(actor);
217 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
222 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
224 ToolkitTestApplication application;
225 tet_infoline("Request image visual without pre-multiplied alpha");
227 VisualFactory factory = VisualFactory::Get();
228 DALI_TEST_CHECK(factory);
229 factory.SetPreMultiplyOnLoad(false);
231 Property::Map propertyMap;
232 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
233 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
235 Visual::Base visual = factory.CreateVisual(propertyMap);
236 DALI_TEST_CHECK(visual);
238 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
239 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
241 TestGlAbstraction& gl = application.GetGlAbstraction();
242 TraceCallStack& textureTrace = gl.GetTextureTrace();
243 textureTrace.Enable(true);
245 DummyControl actor = DummyControl::New();
246 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
247 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
249 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
250 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
252 application.GetScene().Add(actor);
253 application.SendNotification();
254 application.Render();
256 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
258 application.SendNotification();
259 application.Render();
261 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
262 auto renderer = actor.GetRendererAt(0);
263 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
264 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
265 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
266 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
268 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
269 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
271 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
273 application.GetScene().Remove(actor);
274 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
279 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
281 ToolkitTestApplication application;
282 tet_infoline("Request image visual with no alpha channel");
284 VisualFactory factory = VisualFactory::Get();
285 DALI_TEST_CHECK(factory);
287 Property::Map propertyMap;
288 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
289 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
291 Visual::Base visual = factory.CreateVisual(propertyMap);
292 DALI_TEST_CHECK(visual);
294 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
295 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
297 TestGlAbstraction& gl = application.GetGlAbstraction();
298 TraceCallStack& textureTrace = gl.GetTextureTrace();
299 textureTrace.Enable(true);
301 DummyControl actor = DummyControl::New();
302 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
303 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
305 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
306 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
308 application.GetScene().Add(actor);
309 application.SendNotification();
310 application.Render();
312 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
318 auto renderer = actor.GetRendererAt(0);
319 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
320 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
321 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
322 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
324 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
325 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
327 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
329 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
330 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
331 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
332 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
333 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
334 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
335 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
336 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
338 textureTrace.Reset();
340 // Make a new visual with the same image
341 Visual::Base newVisual = factory.CreateVisual(propertyMap);
342 DALI_TEST_CHECK(newVisual);
344 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
345 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
347 DummyControl newActor = DummyControl::New();
348 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
349 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
351 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
352 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
354 application.GetScene().Add(newActor);
356 application.SendNotification();
357 application.Render();
359 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
360 auto newRenderer = newActor.GetRendererAt(0);
361 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
362 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
363 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
364 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
366 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
367 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
369 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
370 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
371 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
372 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
373 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
374 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
375 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
376 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
378 application.GetScene().Remove(actor);
379 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
384 int UtcDaliImageVisualRemoteImageLoad(void)
386 ToolkitTestApplication application;
387 tet_infoline("Request remote image visual with a Property::Map");
389 VisualFactory factory = VisualFactory::Get();
390 DALI_TEST_CHECK(factory);
392 Property::Map propertyMap;
393 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
394 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
396 Visual::Base visual = factory.CreateVisual(propertyMap);
397 DALI_TEST_CHECK(visual);
399 TestGlAbstraction& gl = application.GetGlAbstraction();
400 TraceCallStack& textureTrace = gl.GetTextureTrace();
401 textureTrace.Enable(true);
403 DummyControl actor = DummyControl::New();
404 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
405 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
407 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
408 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
410 application.GetScene().Add(actor);
411 application.SendNotification();
413 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
415 application.SendNotification();
416 application.Render();
418 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
419 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
421 application.GetScene().Remove(actor);
422 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
427 int UtcDaliImageVisualWithNativeImage(void)
429 ToolkitTestApplication application;
430 tet_infoline("Use Native Image as url");
432 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
433 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
434 std::string url = imageUrl.GetUrl();
436 VisualFactory factory = VisualFactory::Get();
437 DALI_TEST_CHECK(factory);
439 Property::Map propertyMap;
440 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
441 propertyMap.Insert(ImageVisual::Property::URL, url);
443 Visual::Base visual = factory.CreateVisual(propertyMap);
444 DALI_TEST_CHECK(visual);
446 DummyControl actor = DummyControl::New();
447 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
448 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
450 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
452 application.GetScene().Add(actor);
454 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
456 Renderer renderer = actor.GetRendererAt(0);
457 Shader shader = renderer.GetShader();
459 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
460 DALI_TEST_CHECK(value.GetType() == Property::MAP);
461 const Property::Map* outMap = value.GetMap();
462 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
464 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
465 size_t pos = fragmentShader.find(fragmentPrefix);
467 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
472 int UtcDaliImageVisualWithNativeImageCustomShader(void)
474 ToolkitTestApplication application;
475 tet_infoline("Use Native Image as url and Use custom shader");
477 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
478 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
479 std::string url = imageUrl.GetUrl();
481 VisualFactory factory = VisualFactory::Get();
482 DALI_TEST_CHECK(factory);
484 Property::Map propertyMap;
485 Property::Map shaderMap;
486 const std::string customVertexShaderSource = "Foobar";
487 const std::string customFragmentShaderSource = "Foobar";
488 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
489 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
491 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
492 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
493 propertyMap.Insert(ImageVisual::Property::URL, url);
495 Visual::Base visual = factory.CreateVisual(propertyMap);
496 DALI_TEST_CHECK(visual);
498 DummyControl actor = DummyControl::New();
499 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
500 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
502 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
503 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
505 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
507 application.GetScene().Add(actor);
509 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
511 application.SendNotification();
512 application.Render(16);
514 Renderer renderer = actor.GetRendererAt(0);
515 Shader shader = renderer.GetShader();
517 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
518 DALI_TEST_CHECK(value.GetType() == Property::MAP);
519 const Property::Map* outMap = value.GetMap();
520 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
521 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
523 // Compare vertex shader is equal
524 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
526 // Check fragment shader changed
527 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
528 size_t pos = fragmentShaderSource.find(fragmentPrefix);
530 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
532 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
537 int UtcDaliImageVisualWithNativeImageRemoved(void)
539 ToolkitTestApplication application;
540 tet_infoline("Use Native Image as url");
542 TestGlAbstraction& gl = application.GetGlAbstraction();
543 TraceCallStack& textureTrace = gl.GetTextureTrace();
544 textureTrace.Enable(true);
546 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
547 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
548 std::string url = imageUrl.GetUrl();
550 VisualFactory factory = VisualFactory::Get();
551 DALI_TEST_CHECK(factory);
553 Property::Map propertyMap;
554 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
555 propertyMap.Insert(ImageVisual::Property::URL, url);
557 Visual::Base visual = factory.CreateVisual(propertyMap);
558 DALI_TEST_CHECK(visual);
560 DummyControl actor = DummyControl::New();
561 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
562 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
564 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
566 application.GetScene().Add(actor);
567 application.SendNotification();
568 application.Render();
570 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
571 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
573 tet_infoline("No delete texture because reference count is not zero");
575 application.GetScene().Remove(actor);
576 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
577 application.SendNotification();
578 application.Render();
580 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
581 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
583 tet_infoline("Delete texture because reference count is zero");
585 application.SendNotification();
586 application.Render();
588 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
593 int UtcDaliImageVisualWithEncodedImageBuffer(void)
595 ToolkitTestApplication application;
596 tet_infoline("Use Encoded Image Buffer as url");
598 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
599 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
601 VisualFactory factory = VisualFactory::Get();
602 DALI_TEST_CHECK(factory);
604 Property::Map propertyMap;
605 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
606 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
608 Visual::Base visual = factory.CreateVisual(propertyMap);
609 DALI_TEST_CHECK(visual);
611 TestGlAbstraction& gl = application.GetGlAbstraction();
612 TraceCallStack& textureTrace = gl.GetTextureTrace();
613 textureTrace.Enable(true);
615 DummyControl actor = DummyControl::New();
616 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
617 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
619 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
620 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
622 application.GetScene().Add(actor);
623 application.SendNotification();
625 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
627 application.SendNotification();
628 application.Render();
630 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
631 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
633 application.GetScene().Remove(actor);
634 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
639 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
641 ToolkitTestApplication application;
642 tet_infoline("Use Encoded Image Buffer as url");
644 TestGlAbstraction& gl = application.GetGlAbstraction();
645 TraceCallStack& textureTrace = gl.GetTextureTrace();
646 textureTrace.Enable(true);
648 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
649 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
650 std::string url = imageUrl.GetUrl();
652 VisualFactory factory = VisualFactory::Get();
653 DALI_TEST_CHECK(factory);
655 Property::Map propertyMap;
656 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
657 propertyMap.Insert(ImageVisual::Property::URL, url);
659 Visual::Base visual = factory.CreateVisual(propertyMap);
660 DALI_TEST_CHECK(visual);
662 DummyControl actor = DummyControl::New();
663 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
664 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
666 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
668 application.GetScene().Add(actor);
669 application.SendNotification();
671 // Wait for decode buffer and make texture.
672 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
674 application.SendNotification();
675 application.Render();
677 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
678 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
680 tet_infoline("Delete texture because there is no actor to use decoded texture");
682 application.GetScene().Remove(actor);
683 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
684 application.SendNotification();
685 application.Render();
687 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
688 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
693 int UtcDaliImageVisualTextureReuse1(void)
695 ToolkitTestApplication application;
696 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
698 Property::Map propertyMap;
699 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
700 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
701 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
703 TestGlAbstraction& gl = application.GetGlAbstraction();
704 TraceCallStack& textureTrace = gl.GetTextureTrace();
705 textureTrace.Enable(true);
706 TraceCallStack& drawTrace = gl.GetDrawTrace();
707 drawTrace.Enable(true);
709 Actor actor = CreateActorWithImageVisual(propertyMap);
710 application.GetScene().Add(actor);
711 application.SendNotification();
713 // Wait for image to load
714 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
716 application.SendNotification();
717 application.Render();
719 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
720 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
721 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
722 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
723 textureTrace.Reset();
726 Actor actor2 = CreateActorWithImageVisual(propertyMap);
727 application.GetScene().Add(actor2);
729 application.SendNotification(); // Send messages to update
730 application.Render(); // process update and render
731 application.SendNotification(); // process any signals to event
733 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
735 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
736 // backend here, but test graphics backend.
737 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
738 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
740 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
742 application.GetScene().Remove(actor);
743 application.SendNotification();
744 application.Render();
746 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
747 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
749 tet_infoline("Test that removing last actor does delete the texture\n");
751 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
752 application.SendNotification();
753 application.Render();
755 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
756 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
761 int UtcDaliImageVisualTextureReuse2(void)
763 ToolkitTestApplication application;
764 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture");
766 Property::Map propertyMap;
767 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
768 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
770 TestGlAbstraction& gl = application.GetGlAbstraction();
771 TraceCallStack& textureTrace = gl.GetTextureTrace();
772 textureTrace.Enable(true);
773 TraceCallStack& drawTrace = gl.GetDrawTrace();
774 drawTrace.Enable(true);
776 Actor actor = CreateActorWithImageVisual(propertyMap);
777 application.GetScene().Add(actor);
778 application.SendNotification();
780 // Wait for image to load
781 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
783 application.SendNotification();
784 application.Render();
786 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
787 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
788 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
789 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
790 textureTrace.Reset();
793 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
794 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
795 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
796 Actor actor2 = CreateActorWithImageVisual(propertyMap);
797 application.GetScene().Add(actor2);
799 application.SendNotification();
801 // Wait for image to load
802 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
804 application.SendNotification();
805 application.Render();
807 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
810 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
811 "renderers are using different textures\n");
813 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
814 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
815 TraceCallStack::NamedParams tex1;
816 tex1["texture"] << 1;
817 TraceCallStack::NamedParams tex2;
818 tex2["texture"] << 2;
819 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
820 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
822 tet_infoline("Test that removing 1 actor deletes it's texture\n");
824 application.GetScene().Remove(actor);
825 application.SendNotification();
826 application.Render();
828 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
829 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
831 tet_infoline("Test that removing last actor deletes it's texture\n");
833 application.GetScene().Remove(actor2);
834 application.SendNotification();
835 application.Render();
837 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
838 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
843 int UtcDaliImageVisualCustomWrapModePixelArea(void)
845 ToolkitTestApplication application;
846 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
848 static std::vector<UniformData> customUniforms =
850 UniformData("pixelArea", Property::Type::VECTOR4),
851 UniformData("wrapMode", Property::Type::VECTOR2),
854 TestGraphicsController& graphics = application.GetGraphicsController();
855 graphics.AddCustomUniforms(customUniforms);
857 VisualFactory factory = VisualFactory::Get();
858 DALI_TEST_CHECK(factory);
860 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
861 const int width = 34;
862 const int height = 34;
863 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
865 Property::Map propertyMap;
866 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
867 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
868 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
869 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
870 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
871 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
872 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
873 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
874 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
876 Visual::Base visual = factory.CreateVisual(propertyMap);
877 DALI_TEST_CHECK(visual);
879 TestGlAbstraction& gl = application.GetGlAbstraction();
880 TraceCallStack& textureTrace = gl.GetTextureTrace();
881 textureTrace.Enable(true);
882 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
883 texParameterTrace.Enable(true);
885 DummyControl actor = DummyControl::New();
886 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
887 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
888 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
889 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
890 application.GetScene().Add(actor);
893 application.SendNotification();
894 application.Render();
896 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
898 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
900 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
901 std::stringstream out;
902 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
903 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
905 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
906 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
908 // test the uniforms which used to handle the wrap mode
909 Renderer renderer = actor.GetRendererAt(0u);
910 DALI_TEST_CHECK(renderer);
912 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
913 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
914 Vector4 pixelAreaUniform;
915 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
916 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
918 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
919 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
920 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
921 Vector2 wrapModeUniform;
922 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
923 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
926 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
931 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
933 ToolkitTestApplication application;
934 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
936 static std::vector<UniformData> customUniforms =
938 UniformData("pixelArea", Property::Type::VECTOR4),
941 TestGraphicsController& graphics = application.GetGraphicsController();
942 graphics.AddCustomUniforms(customUniforms);
944 VisualFactory factory = VisualFactory::Get();
945 DALI_TEST_CHECK(factory);
947 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
948 const int width = 600;
949 const int height = 600;
950 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
952 Property::Map propertyMap;
953 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
954 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
955 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
956 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
957 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
958 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
959 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
960 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
962 Visual::Base visual = factory.CreateVisual(propertyMap);
963 DALI_TEST_CHECK(visual);
965 TestGlAbstraction& gl = application.GetGlAbstraction();
966 TraceCallStack& textureTrace = gl.GetTextureTrace();
967 textureTrace.Enable(true);
968 textureTrace.EnableLogging(true);
969 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
970 texParameterTrace.Enable(true);
971 texParameterTrace.EnableLogging(true);
973 DummyControl actor = DummyControl::New();
974 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
975 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
976 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
977 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
978 application.GetScene().Add(actor);
981 application.SendNotification();
982 application.Render();
983 application.SendNotification();
985 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
987 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
989 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
990 std::stringstream out;
991 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
992 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
994 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
995 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
997 // test the uniforms which used to handle the wrap mode
998 Renderer renderer = actor.GetRendererAt(0u);
999 DALI_TEST_CHECK(renderer);
1001 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1002 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1003 Vector4 pixelAreaUniform;
1004 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1005 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1007 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1008 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1011 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1016 int UtcDaliImageVisualAnimateMixColor(void)
1018 ToolkitTestApplication application;
1019 tet_infoline("Animate mix color");
1021 static std::vector<UniformData> customUniforms =
1023 UniformData("mixColor", Property::Type::VECTOR3),
1026 TestGraphicsController& graphics = application.GetGraphicsController();
1027 graphics.AddCustomUniforms(customUniforms);
1029 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1031 VisualFactory factory = VisualFactory::Get();
1032 Property::Map propertyMap;
1033 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1034 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1035 propertyMap.Insert("mixColor", Color::BLUE);
1036 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1037 Visual::Base visual = factory.CreateVisual(propertyMap);
1039 DummyControl actor = DummyControl::New(true);
1040 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1041 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1043 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1044 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1045 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1046 application.GetScene().Add(actor);
1048 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1050 Renderer renderer = actor.GetRendererAt(0);
1052 // @todo Should we add API to make this code work again?
1053 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1055 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1056 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1058 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1061 map["target"] = "testVisual";
1062 map["property"] = "mixColor";
1063 map["initialValue"] = Color::MAGENTA;
1064 map["targetValue"] = TARGET_MIX_COLOR;
1065 map["animator"] = Property::Map()
1066 .Add("alphaFunction", "LINEAR")
1067 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1069 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1071 Animation animation = dummyImpl.CreateTransition(transition);
1073 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1076 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1077 glAbstraction.EnableEnableDisableCallTrace(true);
1078 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1079 std::ostringstream blendStr;
1080 blendStr << std::hex << GL_BLEND;
1082 application.SendNotification();
1083 application.Render(0); // Ensure animation starts
1084 application.Render(2000u); // Halfway point
1085 Vector3 testColor(1.0f, 0.0f, 0.5f);
1087 // uColor.a should be actor's alpha * mixColor.a.
1088 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1089 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1091 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1093 glEnableStack.Reset();
1095 application.SendNotification();
1096 application.Render(2000u);
1098 application.SendNotification();
1099 application.Render();
1100 application.SendNotification();
1102 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1103 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1104 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1106 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1108 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1113 int UtcDaliImageVisualAnimateOpacity(void)
1115 ToolkitTestApplication application;
1116 tet_infoline("Animate image visual opacity");
1118 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1120 VisualFactory factory = VisualFactory::Get();
1121 Property::Map propertyMap;
1122 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1123 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1124 propertyMap.Insert("opacity", 0.5f);
1125 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1126 Visual::Base visual = factory.CreateVisual(propertyMap);
1128 DummyControl actor = DummyControl::New(true);
1129 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1130 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1132 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1133 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1134 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1135 application.GetScene().Add(actor);
1137 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1139 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1140 glAbstraction.EnableEnableDisableCallTrace(true);
1141 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1142 std::ostringstream blendStr;
1143 blendStr << std::hex << GL_BLEND;
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1151 tet_infoline("Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1154 map["target"] = "testVisual";
1155 map["property"] = "opacity";
1156 map["targetValue"] = 1.0f;
1157 map["animator"] = Property::Map()
1158 .Add("alphaFunction", "LINEAR")
1159 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1161 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1162 Animation animation = dummyImpl.CreateTransition(transition);
1165 glEnableStack.Reset();
1167 application.SendNotification();
1168 application.Render(0); // Ensure animation starts
1169 application.Render(2000u); // Halfway point through animation
1170 application.SendNotification(); // Handle any signals
1173 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1174 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1176 application.Render(2001u); // end
1177 application.SendNotification(); // ensure animation finished signal is sent
1179 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1180 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1182 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1183 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1187 tet_infoline("Test that the opacity can be reduced via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1190 map["target"] = "testVisual";
1191 map["property"] = Visual::Property::OPACITY;
1192 map["targetValue"] = 0.1f;
1193 map["animator"] = Property::Map()
1194 .Add("alphaFunction", "LINEAR")
1195 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1197 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1198 Animation animation = dummyImpl.CreateTransition(transition);
1201 glEnableStack.Reset();
1203 application.SendNotification();
1204 application.Render(0); // Ensure animation starts
1205 application.Render(2000u); // Halfway point
1206 application.SendNotification();
1209 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1210 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1212 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1214 glEnableStack.Reset();
1216 application.Render(2016u); // end
1217 application.SendNotification();
1219 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1220 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1222 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1223 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1229 int UtcDaliImageVisualAnimateOpacity02(void)
1231 ToolkitTestApplication application;
1232 tet_infoline("Animate image visual opacity");
1234 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1236 VisualFactory factory = VisualFactory::Get();
1237 Property::Map propertyMap;
1238 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1239 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1240 propertyMap.Insert("opacity", 0.5f);
1241 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1242 Visual::Base visual = factory.CreateVisual(propertyMap);
1244 DummyControl actor = DummyControl::New(true);
1245 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1246 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1248 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1249 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1250 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1252 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1254 Property::Array array;
1257 map["target"] = "testVisual";
1258 map["property"] = "opacity";
1259 map["initialValue"] = 0.0f;
1260 map["targetValue"] = 1.0f;
1261 map["animator"] = Property::Map()
1262 .Add("alphaFunction", "LINEAR")
1263 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1266 map2["target"] = "testVisual";
1267 map2["property"] = "size";
1268 map2["targetValue"] = Vector2(1.0f, 1.0f);
1270 array.Add(map).Add(map2);
1272 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1273 Animation animation = dummyImpl.CreateTransition(transition);
1275 application.GetScene().Add(actor);
1276 application.SendNotification();
1277 application.Render(0); // Ensure animation starts
1279 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1281 Renderer renderer = actor.GetRendererAt(0);
1282 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1283 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1285 animation = dummyImpl.CreateTransition(transition);
1288 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1289 glAbstraction.EnableEnableDisableCallTrace(true);
1290 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1291 std::ostringstream blendStr;
1292 blendStr << std::hex << GL_BLEND;
1294 application.SendNotification();
1295 application.Render(0); // Ensure animation starts
1296 application.Render(2000u); // Halfway point through animation
1297 application.SendNotification(); // Handle any signals
1299 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1302 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1303 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1305 glEnableStack.Reset();
1307 application.Render(2001u); // end
1308 application.SendNotification(); // ensure animation finished signal is sent
1310 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1311 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1313 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1318 int UtcDaliImageVisualAnimatePixelArea(void)
1320 ToolkitTestApplication application;
1321 tet_infoline("ImageVisual animate pixel area");
1323 static std::vector<UniformData> customUniforms =
1325 UniformData("pixelArea", Property::Type::VECTOR4),
1328 TestGraphicsController& graphics = application.GetGraphicsController();
1329 graphics.AddCustomUniforms(customUniforms);
1331 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1333 VisualFactory factory = VisualFactory::Get();
1334 Property::Map propertyMap;
1335 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1336 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1337 propertyMap.Insert("mixColor", Color::BLUE);
1338 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1339 Visual::Base visual = factory.CreateVisual(propertyMap);
1341 DummyControl actor = DummyControl::New(true);
1342 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1343 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1345 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1346 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1347 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1348 application.GetScene().Add(actor);
1350 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1352 Renderer renderer = actor.GetRendererAt(0);
1353 // @todo Implement this feature?
1354 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1355 //tet_infoline("Test that the renderer has the mixColor property");
1356 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1358 // TransitionData only takes string keys
1360 map["target"] = "testVisual";
1361 map["property"] = "pixelArea";
1362 map["initialValue"] = Vector4(0, 0, 0, 1);
1363 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1364 map["animator"] = Property::Map()
1365 .Add("alphaFunction", "LINEAR")
1366 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1368 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1370 Animation animation = dummyImpl.CreateTransition(transition);
1371 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1374 application.SendNotification();
1375 application.Render(0); // Ensure animation starts
1376 application.Render(2000u); // Halfway point
1378 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1380 application.Render(2000u); // End of animation
1382 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1387 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1389 ToolkitTestApplication application;
1390 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1392 Property::Map propertyMap;
1393 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1394 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1396 TestGlAbstraction& gl = application.GetGlAbstraction();
1397 TraceCallStack& textureTrace = gl.GetTextureTrace();
1398 textureTrace.Enable(true);
1399 TraceCallStack& drawTrace = gl.GetDrawTrace();
1400 drawTrace.Enable(true);
1402 Actor actor = CreateActorWithImageVisual(propertyMap);
1403 application.GetScene().Add(actor);
1404 application.SendNotification();
1406 application.GetScene().Remove(actor);
1407 application.SendNotification();
1409 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1410 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1411 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1412 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1417 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1419 ToolkitTestApplication application;
1420 tet_infoline("Load image asynchronously, cancel loading, then load again");
1422 VisualFactory factory = VisualFactory::Get();
1423 DALI_TEST_CHECK(factory);
1425 Property::Map propertyMap;
1426 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1427 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1429 Visual::Base visual = factory.CreateVisual(propertyMap);
1430 DALI_TEST_CHECK(visual);
1432 TestGlAbstraction& gl = application.GetGlAbstraction();
1433 TraceCallStack& textureTrace = gl.GetTextureTrace();
1434 textureTrace.Enable(true);
1435 TraceCallStack& drawTrace = gl.GetDrawTrace();
1436 drawTrace.Enable(true);
1438 DummyControl actor = DummyControl::New();
1439 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1440 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1442 application.GetScene().Add(actor);
1445 application.GetScene().Remove(actor);
1447 application.GetScene().Add(actor);
1449 // Create another visual with the same image
1450 visual = factory.CreateVisual(propertyMap);
1451 DALI_TEST_CHECK(visual);
1453 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1455 application.SendNotification();
1456 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1458 application.SendNotification();
1459 application.Render();
1461 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1462 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1463 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1464 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1469 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1471 ToolkitTestApplication application;
1472 tet_infoline("Request image visual with invalid images - should draw broken.png");
1474 VisualFactory factory = VisualFactory::Get();
1475 DALI_TEST_CHECK(factory);
1477 Property::Map propertyMap;
1478 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1479 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1481 Visual::Base visual = factory.CreateVisual(propertyMap);
1482 DALI_TEST_CHECK(visual);
1484 TestGlAbstraction& gl = application.GetGlAbstraction();
1485 TraceCallStack& textureTrace = gl.GetTextureTrace();
1486 textureTrace.Enable(true);
1488 DummyControl actor = DummyControl::New();
1489 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1490 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1492 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1493 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1495 application.GetScene().Add(actor);
1497 application.SendNotification();
1498 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1500 application.SendNotification();
1501 application.Render();
1503 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1504 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1506 application.GetScene().Remove(actor);
1507 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1512 int UtcDaliImageVisualSetInvalidSyncImage(void)
1514 ToolkitTestApplication application;
1515 tet_infoline("Request image visual with invalid images - should draw broken.png");
1517 VisualFactory factory = VisualFactory::Get();
1518 DALI_TEST_CHECK(factory);
1520 Property::Map propertyMap;
1521 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1522 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1523 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1525 Visual::Base visual = factory.CreateVisual(propertyMap);
1526 DALI_TEST_CHECK(visual);
1528 TestGlAbstraction& gl = application.GetGlAbstraction();
1529 TraceCallStack& textureTrace = gl.GetTextureTrace();
1530 textureTrace.Enable(true);
1532 DummyControl actor = DummyControl::New();
1533 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1534 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1536 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1537 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1539 application.GetScene().Add(actor);
1541 application.SendNotification();
1542 application.Render();
1544 // Check resource status
1545 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1546 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1548 // The broken image should be shown.
1549 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1550 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1552 application.GetScene().Remove(actor);
1553 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1558 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1560 ToolkitTestApplication application;
1561 tet_infoline("Request image visual with invalid images - should draw broken.png");
1563 VisualFactory factory = VisualFactory::Get();
1564 DALI_TEST_CHECK(factory);
1566 // Local invalid file, asynchronous loading
1567 Property::Map propertyMap;
1568 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1569 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1571 Visual::Base visual = factory.CreateVisual(propertyMap);
1572 DALI_TEST_CHECK(visual);
1574 TestGlAbstraction& gl = application.GetGlAbstraction();
1575 TraceCallStack& textureTrace = gl.GetTextureTrace();
1576 textureTrace.Enable(true);
1578 DummyControl actor = DummyControl::New();
1579 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1580 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1582 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1583 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1585 application.GetScene().Add(actor);
1587 application.SendNotification();
1588 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1590 application.SendNotification();
1591 application.Render();
1593 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1594 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1596 application.GetScene().Remove(actor);
1597 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1602 int UtcDaliImageVisualAlphaMask01(void)
1604 ToolkitTestApplication application;
1605 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1607 VisualFactory factory = VisualFactory::Get();
1608 DALI_TEST_CHECK(factory);
1610 Property::Map propertyMap;
1611 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1612 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1613 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1615 Visual::Base visual = factory.CreateVisual(propertyMap);
1616 DALI_TEST_CHECK(visual);
1618 Property::Map testMap;
1619 visual.CreatePropertyMap(testMap);
1620 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1622 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1623 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1625 TestGlAbstraction& gl = application.GetGlAbstraction();
1626 TraceCallStack& textureTrace = gl.GetTextureTrace();
1627 textureTrace.Enable(true);
1629 DummyControl actor = DummyControl::New();
1630 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1631 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1633 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1634 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1635 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1637 application.GetScene().Add(actor);
1638 application.SendNotification();
1639 application.Render();
1641 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1643 application.SendNotification();
1644 application.Render();
1646 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1647 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1648 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1650 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1651 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1656 int UtcDaliImageVisualAlphaMask02(void)
1658 ToolkitTestApplication application;
1659 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1661 VisualFactory factory = VisualFactory::Get();
1662 DALI_TEST_CHECK(factory);
1664 Property::Map propertyMap;
1665 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1666 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1667 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1668 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1670 Visual::Base visual = factory.CreateVisual(propertyMap);
1671 DALI_TEST_CHECK(visual);
1673 Property::Map testMap;
1674 visual.CreatePropertyMap(testMap);
1675 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1676 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1678 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1679 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1681 TestGlAbstraction& gl = application.GetGlAbstraction();
1682 TraceCallStack& textureTrace = gl.GetTextureTrace();
1683 textureTrace.Enable(true);
1685 DummyControl actor = DummyControl::New();
1686 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1687 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1689 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1690 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1691 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1693 application.GetScene().Add(actor);
1694 application.SendNotification();
1695 application.Render();
1697 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1699 application.SendNotification();
1700 application.Render();
1702 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1703 Renderer renderer = actor.GetRendererAt(0u);
1704 TextureSet textures = renderer.GetTextures();
1705 DALI_TEST_CHECK(textures);
1706 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1708 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1709 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1711 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1712 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1717 int UtcDaliImageVisualAlphaMask03(void)
1719 ToolkitTestApplication application;
1720 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1722 VisualFactory factory = VisualFactory::Get();
1723 DALI_TEST_CHECK(factory);
1725 Property::Map propertyMap;
1726 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1727 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1728 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1729 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1731 Visual::Base visual = factory.CreateVisual(propertyMap);
1732 DALI_TEST_CHECK(visual);
1734 Property::Map testMap;
1735 visual.CreatePropertyMap(testMap);
1737 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1738 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1740 TestGlAbstraction& gl = application.GetGlAbstraction();
1741 TraceCallStack& textureTrace = gl.GetTextureTrace();
1742 textureTrace.Enable(true);
1744 DummyControl actor = DummyControl::New();
1745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1748 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1749 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1750 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1752 application.GetScene().Add(actor);
1753 application.SendNotification();
1754 application.Render();
1756 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1758 application.SendNotification();
1759 application.Render();
1761 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1762 Renderer renderer = actor.GetRendererAt(0u);
1763 TextureSet textures = renderer.GetTextures();
1764 DALI_TEST_CHECK(textures);
1765 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
1767 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1768 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1770 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1771 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1776 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
1778 ToolkitTestApplication application;
1779 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
1781 VisualFactory factory = VisualFactory::Get();
1782 DALI_TEST_CHECK(factory);
1784 Property::Map propertyMap;
1785 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1786 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1787 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1788 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1790 Visual::Base visual = factory.CreateVisual(propertyMap);
1791 DALI_TEST_CHECK(visual);
1793 Property::Map testMap;
1794 visual.CreatePropertyMap(testMap);
1795 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1797 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1798 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1800 TestGlAbstraction& gl = application.GetGlAbstraction();
1801 TraceCallStack& textureTrace = gl.GetTextureTrace();
1802 textureTrace.Enable(true);
1804 DummyControl actor = DummyControl::New();
1805 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1806 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1808 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1809 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1810 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1812 application.GetScene().Add(actor);
1814 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1816 application.SendNotification();
1817 application.Render();
1819 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1820 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1821 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1823 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1824 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1829 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
1831 ToolkitTestApplication application;
1832 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
1834 VisualFactory factory = VisualFactory::Get();
1835 DALI_TEST_CHECK(factory);
1837 Property::Map propertyMap;
1838 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1839 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1840 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1841 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1842 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1844 Visual::Base visual = factory.CreateVisual(propertyMap);
1845 DALI_TEST_CHECK(visual);
1847 Property::Map testMap;
1848 visual.CreatePropertyMap(testMap);
1849 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1851 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1852 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1854 TestGlAbstraction& gl = application.GetGlAbstraction();
1855 TraceCallStack& textureTrace = gl.GetTextureTrace();
1856 textureTrace.Enable(true);
1858 DummyControl actor = DummyControl::New();
1859 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1860 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1862 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1863 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1864 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1866 application.GetScene().Add(actor);
1868 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1870 application.SendNotification();
1871 application.Render();
1873 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1874 Renderer renderer = actor.GetRendererAt(0u);
1875 TextureSet textures = renderer.GetTextures();
1876 DALI_TEST_CHECK(textures);
1877 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1879 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1880 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1882 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1883 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1888 int UtcDaliImageVisualRemoteAlphaMask(void)
1890 ToolkitTestApplication application;
1891 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1893 VisualFactory factory = VisualFactory::Get();
1894 DALI_TEST_CHECK(factory);
1896 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1898 Property::Map propertyMap;
1899 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1900 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1901 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1903 Visual::Base visual = factory.CreateVisual(propertyMap);
1904 DALI_TEST_CHECK(visual);
1906 Property::Map testMap;
1907 visual.CreatePropertyMap(testMap);
1909 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1911 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1912 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1914 TestGlAbstraction& gl = application.GetGlAbstraction();
1915 TraceCallStack& textureTrace = gl.GetTextureTrace();
1916 textureTrace.Enable(true);
1918 DummyControl actor = DummyControl::New();
1919 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1920 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1922 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1924 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1925 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1927 application.GetScene().Add(actor);
1928 application.SendNotification();
1929 application.Render();
1931 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1933 application.SendNotification();
1934 application.Render();
1936 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1937 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1938 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1943 int UtcDaliImageVisualAlphaMaskCrop(void)
1945 ToolkitTestApplication application;
1946 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1948 VisualFactory factory = VisualFactory::Get();
1949 DALI_TEST_CHECK(factory);
1951 Property::Map propertyMap;
1952 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1953 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1954 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1955 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1956 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1958 Visual::Base visual = factory.CreateVisual(propertyMap);
1959 DALI_TEST_CHECK(visual);
1961 Property::Map testMap;
1962 visual.CreatePropertyMap(testMap);
1963 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1964 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1965 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1967 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1968 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1970 TestGlAbstraction& gl = application.GetGlAbstraction();
1971 TraceCallStack& textureTrace = gl.GetTextureTrace();
1972 textureTrace.Enable(true);
1974 DummyControl actor = DummyControl::New();
1975 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1976 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1978 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1979 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1980 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1982 application.GetScene().Add(actor);
1983 application.SendNotification();
1984 application.Render();
1986 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1988 application.SendNotification();
1989 application.Render();
1992 visual.GetNaturalSize(size);
1994 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1995 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1996 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1997 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2002 int UtcDaliImageVisualReleasePolicy01(void)
2004 ToolkitTestApplication application;
2005 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2007 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2008 DALI_TEST_CHECK(imageVisual);
2010 // Set up debug trace
2011 TestGlAbstraction& gl = application.GetGlAbstraction();
2012 TraceCallStack& textureTrace = gl.GetTextureTrace();
2013 textureTrace.Enable(true);
2015 tet_infoline("Register visual with control and ensure it has the only handle");
2016 DummyControl actor = DummyControl::New(true);
2017 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2018 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2019 imageVisual.Reset();
2021 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2023 application.SendNotification();
2024 application.Render(0);
2025 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2026 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2028 application.GetScene().Add(actor);
2030 // Wait for image to load
2031 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2033 application.SendNotification();
2034 application.Render(0);
2035 // Test renderer and texture created
2036 tet_infoline("Confirm texture created");
2037 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2038 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2040 tet_infoline("Disable visual causing the texture to be deleted");
2041 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2043 application.SendNotification();
2044 application.Render(0);
2045 // Test renderer and textures removed.
2046 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2047 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2052 int UtcDaliImageVisualReleasePolicy02(void)
2054 ToolkitTestApplication application;
2055 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2057 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2058 DALI_TEST_CHECK(imageVisual);
2060 // Setup debug trace
2061 TestGlAbstraction& gl = application.GetGlAbstraction();
2062 TraceCallStack& textureTrace = gl.GetTextureTrace();
2063 textureTrace.Enable(true);
2065 tet_infoline("Register visual with control and ensure it has the only handle");
2066 DummyControl actor = DummyControl::New(true);
2067 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2068 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2069 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2071 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2073 application.SendNotification();
2074 application.Render(0);
2075 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2076 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2078 application.GetScene().Add(actor);
2080 // Wait for image to load
2081 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2083 application.SendNotification();
2084 application.Render(0);
2085 // Test renderer and texture created
2086 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2087 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2089 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2090 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2091 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2092 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2093 application.SendNotification();
2094 application.Render();
2096 // Test texture removed after visual destroyed.
2097 tet_infoline("Ensure texture is deleted after visual destroyed");
2098 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2103 int UtcDaliImageVisualReleasePolicy03(void)
2105 ToolkitTestApplication application;
2106 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2108 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2109 DALI_TEST_CHECK(imageVisual);
2111 TestGlAbstraction& gl = application.GetGlAbstraction();
2112 TraceCallStack& textureTrace = gl.GetTextureTrace();
2113 textureTrace.Enable(true);
2115 tet_infoline("Register visual with control and ensure it has the only handle");
2116 DummyControl actor = DummyControl::New(true);
2117 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2118 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2119 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2121 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2123 application.SendNotification();
2124 application.Render(0);
2125 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2126 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2128 application.GetScene().Add(actor);
2130 // Wait for image to load
2131 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2133 application.SendNotification();
2134 application.Render(0);
2135 // Test renderer and texture created
2136 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2137 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2139 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2140 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2141 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2142 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2143 application.SendNotification();
2144 application.Render();
2146 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2147 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2152 int UtcDaliImageVisualReleasePolicy04(void)
2154 ToolkitTestApplication application;
2155 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2157 tet_infoline("Create first visual with Never release policy");
2158 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2160 tet_infoline("Create second visual with Destroyed release policy");
2161 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2163 // Set up trace debug
2164 TestGlAbstraction& gl = application.GetGlAbstraction();
2165 TraceCallStack& textureTrace = gl.GetTextureTrace();
2166 textureTrace.Enable(true);
2168 tet_infoline("Register visuals with control and ensure it has the only handles");
2169 DummyControl actor = DummyControl::New(true);
2170 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2171 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2172 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2173 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2174 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2176 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2178 // Test initially zero renderers
2179 application.SendNotification();
2180 application.Render(0);
2181 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2182 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2184 application.GetScene().Add(actor);
2186 // Wait for image to load
2187 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2189 application.SendNotification();
2190 application.Render(0);
2191 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2192 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2193 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2195 // Test renderer removed when visual destroyed
2196 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2197 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2198 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2199 application.SendNotification();
2200 application.Render();
2202 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2203 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2205 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2206 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2207 application.SendNotification();
2208 application.Render();
2210 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2211 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2212 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2217 int UtcDaliImageVisualReleasePolicy05(void)
2219 ToolkitTestApplication application;
2220 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2222 VisualFactory factory = VisualFactory::Get();
2224 Property::Map propertyMapNeverReleasePolicy;
2225 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2226 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2227 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2228 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2229 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2231 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2233 Property::Map resultMap;
2234 imageVisualNever.CreatePropertyMap(resultMap);
2235 DALI_TEST_CHECK(!resultMap.Empty());
2237 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2242 int UtcDaliImageVisualReleasePolicy06(void)
2244 ToolkitTestApplication application;
2245 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2247 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2248 DALI_TEST_CHECK(imageVisual);
2250 TestGlAbstraction& gl = application.GetGlAbstraction();
2251 TraceCallStack& textureTrace = gl.GetTextureTrace();
2252 textureTrace.Enable(true);
2254 tet_infoline("Register visual with control and ensure it has the only handle");
2255 DummyControl actor = DummyControl::New(true);
2256 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2257 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2258 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2260 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2262 application.SendNotification();
2263 application.Render(0);
2264 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2265 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2267 application.GetScene().Add(actor);
2269 // Wait for image to load
2270 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2272 application.SendNotification();
2273 application.Render(0);
2274 // Test renderer and texture created
2275 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2276 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2277 textureTrace.Reset();
2279 tet_infoline("Disable Visual and check texture not affected");
2280 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2281 application.SendNotification();
2282 application.Render(0);
2283 tet_infoline("Check renderer is destroyed when visual off stage");
2284 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2285 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2286 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2287 textureTrace.Reset();
2289 tet_infoline("Re-enable Visual and check texture not affected");
2290 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2291 application.SendNotification();
2292 application.Render(0);
2293 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2294 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2295 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2296 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2301 int UtcDaliImageVisualReleasePolicy07(void)
2303 ToolkitTestApplication application;
2304 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2306 tet_infoline("Create first visual with DESTROYED release policy");
2307 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2309 tet_infoline("Create second visual with DETACHED release policy");
2310 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2312 // Set up trace debug
2313 TestGlAbstraction& gl = application.GetGlAbstraction();
2314 TraceCallStack& textureTrace = gl.GetTextureTrace();
2315 textureTrace.Enable(true);
2317 tet_infoline("Register visuals with control and ensure it has the only handles");
2318 DummyControl actor = DummyControl::New(true);
2319 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2320 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2321 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2322 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2323 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2325 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2327 // Test initially zero renderers
2328 application.SendNotification();
2329 application.Render(0);
2330 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2331 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2333 application.GetScene().Add(actor);
2335 // Wait for image to load
2336 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2338 application.SendNotification();
2339 application.Render(0);
2340 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2341 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2342 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2344 // Test renderer removed when visual destroyed
2345 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2346 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2347 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2348 application.SendNotification();
2349 application.Render();
2351 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2352 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2354 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2355 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2356 application.SendNotification();
2357 application.Render();
2359 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2360 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2365 int UtcDaliImageVisualReleasePolicy08(void)
2367 ToolkitTestApplication application;
2368 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2370 tet_infoline("Create first visual with DESTROYED release policy");
2371 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2373 // Set up trace debug
2374 TestGlAbstraction& gl = application.GetGlAbstraction();
2375 TraceCallStack& textureTrace = gl.GetTextureTrace();
2376 textureTrace.Enable(true);
2378 tet_infoline("Register visuals with control and ensure it has the only handles");
2379 DummyControl actor = DummyControl::New(true);
2380 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2381 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2382 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2384 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2386 // Test initially zero renderers
2387 application.SendNotification();
2388 application.Render(0);
2389 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2390 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2391 textureTrace.Reset();
2393 application.GetScene().Add(actor);
2395 // Wait for image to load
2396 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2398 application.SendNotification();
2399 application.Render(0);
2400 tet_infoline("Ensure a texture is created");
2401 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2402 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2403 textureTrace.Reset();
2405 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2406 // 1. Get TextureSet
2407 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2409 // 2.Remove actor from stage. In this case, renderer also is deleted.
2410 tet_infoline("Remove actor from stage");
2411 application.GetScene().Remove(actor);
2412 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2413 application.SendNotification();
2414 application.Render();
2416 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2417 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2418 textureTrace.Reset();
2420 // 3.Add actor in stage. In this case, renderer is created.
2421 tet_infoline("Add actor in stage");
2422 application.GetScene().Add(actor);
2423 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2424 application.SendNotification();
2425 application.Render();
2426 tet_infoline("Ensure a texture is not created again");
2427 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2428 textureTrace.Reset();
2430 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2431 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2432 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2433 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2434 textureSetBefore.Reset();
2435 textureSetAfter.Reset();
2437 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2438 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2439 application.SendNotification();
2440 application.Render();
2441 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2446 int UtcDaliImageVisualReleasePolicy09(void)
2448 ToolkitTestApplication application;
2449 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2451 Property::Map propertyMapNPatchReleasePolicy;
2452 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2453 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2454 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2455 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2456 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2458 VisualFactory factory = VisualFactory::Get();
2459 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2460 DALI_TEST_CHECK(imageVisual);
2462 // Setup debug trace
2463 TestGlAbstraction& gl = application.GetGlAbstraction();
2464 TraceCallStack& textureTrace = gl.GetTextureTrace();
2465 textureTrace.Enable(true);
2467 tet_infoline("Register visual with control and ensure it has the only handle");
2468 DummyControl actor = DummyControl::New(true);
2469 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2470 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2471 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2473 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2475 application.SendNotification();
2476 application.Render(0);
2477 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2478 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2480 application.GetScene().Add(actor);
2482 // Wait for image to load
2483 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2485 application.SendNotification();
2486 application.Render(0);
2487 // Test renderer and texture created
2488 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2489 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2491 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2492 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2493 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2494 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2495 application.SendNotification();
2496 application.Render();
2498 // Test texture removed after visual destroyed.
2499 tet_infoline("Ensure texture is deleted after visual destroyed");
2500 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2505 int UtcDaliImageVisualLoadPolicy01(void)
2507 ToolkitTestApplication application;
2508 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2510 // Set up trace debug
2511 TestGlAbstraction& gl = application.GetGlAbstraction();
2512 TraceCallStack& textureTrace = gl.GetTextureTrace();
2513 textureTrace.Enable(true);
2515 tet_infoline("Create visual with IMMEDIATE load policy");
2516 VisualFactory factory = VisualFactory::Get();
2518 Property::Map propertyMap;
2519 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2520 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2521 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2522 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2523 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2525 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2527 Property::Map resultMap;
2528 imageVisual.CreatePropertyMap(resultMap);
2529 DALI_TEST_CHECK(!resultMap.Empty());
2530 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2532 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2534 // Ensure texture has been uploaded
2535 application.SendNotification();
2536 application.Render();
2538 tet_infoline("Ensure texture loading starts after visual created");
2539 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2540 textureTrace.Reset();
2542 tet_infoline("Register visuals with control and ensure it has the only handles");
2543 DummyControl actor = DummyControl::New(true);
2544 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2545 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2546 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2548 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2549 application.GetScene().Add(actor);
2550 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2551 const unsigned int TIME_OUT_3_SECONDS = 3;
2552 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2554 application.SendNotification();
2555 application.Render();
2557 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2558 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2560 // Ensure texture is deleted when no longer needed (ref count was correct )
2561 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2563 application.SendNotification();
2564 application.Render();
2566 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2567 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2572 int UtcDaliImageVisualLoadPolicy02(void)
2574 ToolkitTestApplication application;
2575 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2577 // Set up trace debug
2578 TestGlAbstraction& gl = application.GetGlAbstraction();
2579 TraceCallStack& textureTrace = gl.GetTextureTrace();
2580 textureTrace.Enable(true);
2582 tet_infoline("Create visual with IMMEDIATE load policy");
2583 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2585 const unsigned int TIME_OUT_3_SECONDS = 3;
2586 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2588 // Act on meeage queue even although nothing expected to load
2589 application.SendNotification();
2590 application.Render();
2592 tet_infoline("Ensure texture is not generated yet");
2593 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2594 textureTrace.Reset();
2596 tet_infoline("Register visuals with control and ensure it has the only handles");
2597 DummyControl actor = DummyControl::New(true);
2598 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2599 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2600 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2602 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2603 application.GetScene().Add(actor);
2604 tet_infoline("Allow image time to load");
2605 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2607 application.SendNotification();
2608 application.Render();
2610 tet_infoline("Ensure texture generated and renderer created");
2611 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2612 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2614 // Ensure texture is delete when no longer needed
2615 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2617 application.SendNotification();
2618 application.Render();
2620 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2621 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2626 int UtcDaliImageVisualLoadPolicy03(void)
2628 ToolkitTestApplication application;
2629 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2631 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2633 // Set up trace debug
2634 TestGlAbstraction& gl = application.GetGlAbstraction();
2635 TraceCallStack& textureTrace = gl.GetTextureTrace();
2636 textureTrace.Enable(true);
2638 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2639 DummyControl actor = DummyControl::New(true);
2640 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2641 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2642 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2644 tet_infoline("Create visual with IMMEDIATE load policy");
2645 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2647 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2648 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2649 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2651 tet_infoline("Allow image time to load resource");
2652 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2653 application.SendNotification();
2654 application.Render();
2656 // Ensure texture has been uploaded
2657 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2658 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2663 int UtcDaliImageVisualLoadPolicy04(void)
2665 ToolkitTestApplication application;
2666 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2667 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2669 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2671 // Set up trace debug
2672 TestGlAbstraction& gl = application.GetGlAbstraction();
2673 TraceCallStack& textureTrace = gl.GetTextureTrace();
2674 textureTrace.Enable(true);
2676 tet_infoline("Create a control and connect to resource ready signal");
2677 DummyControl actor = DummyControl::New(true);
2678 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2679 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2680 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2682 tet_infoline("Create visual with IMMEDIATE load policy");
2683 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2685 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2686 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2687 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2689 tet_infoline("Allow image time to load");
2690 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2691 application.SendNotification();
2692 application.Render();
2694 tet_infoline("Testing texture is loaded and resource ready signal fired");
2695 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2696 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2698 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2700 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2701 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2702 DummyControl actor2 = DummyControl::New(true);
2703 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2704 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2706 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2707 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2708 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2709 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2710 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2711 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2716 int UtcDaliImageVisualLoadPolicy05(void)
2718 ToolkitTestApplication application;
2719 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2720 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2721 // Set up trace debug
2722 TestGlAbstraction& gl = application.GetGlAbstraction();
2723 TraceCallStack& textureTrace = gl.GetTextureTrace();
2724 textureTrace.Enable(true);
2726 tet_infoline("Create a control and connect to resource ready signal");
2727 DummyControl actor = DummyControl::New(true);
2728 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2729 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2730 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2731 application.GetScene().Add(actor);
2733 tet_infoline("Create visual with ATTACHED load policy");
2734 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2736 tet_infoline("Registering visual allows control to get a signal once loaded");
2737 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2738 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2740 tet_infoline("Allow image time to load");
2741 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2742 application.SendNotification();
2743 application.Render();
2745 tet_infoline("Testing texture is loaded and resource ready signal fired");
2746 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2747 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2749 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2751 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2752 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2753 DummyControl actor2 = DummyControl::New(true);
2754 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2755 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2757 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2758 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2759 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2760 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2761 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2762 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2767 int UtcDaliImageVisualOrientationCorrection(void)
2769 ToolkitTestApplication application;
2770 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2772 VisualFactory factory = VisualFactory::Get();
2773 tet_infoline("Create visual with Orientation correction set OFF");
2774 Property::Map propertyMap;
2775 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2776 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2777 propertyMap.Insert("orientationCorrection", false);
2778 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2780 tet_infoline("Create control for visual, need to loaded it");
2781 DummyControl actor = DummyControl::New(true);
2782 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2783 application.GetScene().Add(actor);
2785 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2786 // Wait for image to load
2787 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2789 Vector2 originalImageSize;
2790 tet_infoline("Get size of original visual to compare later with rotated image");
2791 imageVisual.GetNaturalSize(originalImageSize);
2792 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2793 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2794 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2795 application.SendNotification();
2796 application.Render();
2798 tet_infoline("Create visual with Orientation correction set ON ");
2799 propertyMap.Clear();
2800 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2801 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2802 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2803 imageVisual = factory.CreateVisual(propertyMap);
2805 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2806 // Wait for image to load
2807 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2809 Vector2 rotatedImageSize;
2810 imageVisual.GetNaturalSize(rotatedImageSize);
2811 tet_infoline("Confirm that visual has rotated");
2812 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2813 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2815 Property::Map resultMap;
2816 imageVisual.CreatePropertyMap(resultMap);
2818 // check the Property::ORIENTATION_CORRECTION value from the returned map
2819 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2820 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2825 int UtcDaliImageVisualCustomShader(void)
2827 ToolkitTestApplication application;
2828 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2830 VisualFactory factory = VisualFactory::Get();
2831 Property::Map properties;
2832 Property::Map shader;
2833 const std::string vertexShader = "Foobar";
2834 const std::string fragmentShader = "Foobar";
2835 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2836 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2838 properties[Visual::Property::TYPE] = Visual::IMAGE;
2839 properties[Visual::Property::SHADER] = shader;
2840 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2842 Visual::Base visual = factory.CreateVisual(properties);
2844 // trigger creation through setting on stage
2845 DummyControl dummy = DummyControl::New(true);
2846 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2847 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2849 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2850 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2851 application.GetScene().Add(dummy);
2853 application.SendNotification();
2854 application.Render();
2856 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2858 Renderer renderer = dummy.GetRendererAt(0);
2859 Shader shader2 = renderer.GetShader();
2860 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2861 Property::Map* map = value.GetMap();
2862 DALI_TEST_CHECK(map);
2864 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2865 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2867 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2868 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2872 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2873 properties[Visual::Property::SHADER] = shader;
2875 Visual::Base visual1 = factory.CreateVisual(properties);
2877 // trigger creation through setting on stage
2878 DummyControl dummy1 = DummyControl::New(true);
2879 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2880 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2881 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2882 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2883 application.GetScene().Add(dummy1);
2885 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2886 glAbstraction.EnableEnableDisableCallTrace(true);
2888 application.SendNotification();
2889 application.Render();
2891 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2892 std::ostringstream blendStr;
2893 blendStr << std::hex << GL_BLEND;
2894 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2899 void ResourceReadyLoadNext(Control control)
2901 static int callNumber = 0;
2903 gResourceReadySignalFired = true;
2904 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2908 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2910 tet_infoline("Create visual with loaded image from within the signal handler");
2911 VisualFactory factory = VisualFactory::Get();
2912 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2914 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2915 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2920 tet_infoline("3rd signal called");
2921 DALI_TEST_CHECK(true);
2925 int UtcDaliImageVisualLoadReady01(void)
2927 ToolkitTestApplication application;
2928 tet_infoline("UtcDaliImageVisualLoadReady01");
2929 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2930 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2931 tet_infoline("Should get a ready signal for all three visuals");
2935 tet_infoline("Create a control and connect to resource ready signal");
2936 DummyControl actor = DummyControl::New(true);
2937 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2938 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2939 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2940 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2941 application.GetScene().Add(actor);
2943 tet_infoline("Create visual with IMMEDIATE load policy");
2944 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2946 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2947 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2949 tet_infoline("Allow image time to load");
2950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2951 application.SendNotification();
2952 application.Render();
2954 tet_infoline("Testing texture is loaded and resource ready signal fired");
2955 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2956 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2958 tet_infoline("Original control correctly signalled, now testing failing image");
2960 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2963 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2965 DummyControl actor2 = DummyControl::New(true);
2966 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2967 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2968 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2970 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2971 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2973 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2974 application.GetScene().Add(actor2);
2976 tet_infoline("Wait for loading thread to finish");
2977 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2978 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2980 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2982 tet_infoline("Check for 3rd signal");
2983 application.SendNotification();
2984 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2985 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
2990 int UtcDaliImageVisualLoadImagePlanes01(void)
2992 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
2993 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
2995 ToolkitTestApplication application;
2997 VisualFactory factory = VisualFactory::Get();
2998 DALI_TEST_CHECK(factory);
3000 Property::Map propertyMap;
3001 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3002 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3004 Visual::Base visual = factory.CreateVisual(propertyMap);
3005 DALI_TEST_CHECK(visual);
3007 DummyControl actor = DummyControl::New();
3008 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3009 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3010 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3011 application.GetScene().Add(actor);
3013 application.SendNotification();
3014 application.Render();
3016 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3018 TestGlAbstraction& gl = application.GetGlAbstraction();
3019 TraceCallStack& textureTrace = gl.GetTextureTrace();
3020 textureTrace.Enable(true);
3022 application.SendNotification();
3023 application.Render();
3025 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3026 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3027 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3029 Renderer renderer = actor.GetRendererAt(0);
3030 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3031 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3036 int UtcDaliImageVisualLoadImagePlanes02(void)
3038 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3039 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3041 ToolkitTestApplication application;
3043 VisualFactory factory = VisualFactory::Get();
3044 DALI_TEST_CHECK(factory);
3046 // Alpha masking case - not support yuv planes
3047 Property::Map propertyMap;
3048 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3049 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3050 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3052 Visual::Base visual = factory.CreateVisual(propertyMap);
3053 DALI_TEST_CHECK(visual);
3055 DummyControl actor = DummyControl::New();
3056 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3057 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3058 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3059 application.GetScene().Add(actor);
3061 application.SendNotification();
3062 application.Render();
3064 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3066 TestGlAbstraction& gl = application.GetGlAbstraction();
3067 TraceCallStack& textureTrace = gl.GetTextureTrace();
3068 textureTrace.Enable(true);
3070 application.SendNotification();
3071 application.Render();
3073 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3074 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3075 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3080 int UtcDaliImageVisualLoadImagePlanes03(void)
3082 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3083 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3085 ToolkitTestApplication application;
3087 VisualFactory factory = VisualFactory::Get();
3088 DALI_TEST_CHECK(factory);
3090 TestGlAbstraction& gl = application.GetGlAbstraction();
3091 TraceCallStack& textureTrace = gl.GetTextureTrace();
3092 textureTrace.Enable(true);
3094 Property::Map propertyMap;
3095 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3096 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3097 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3099 Visual::Base visual = factory.CreateVisual(propertyMap);
3100 DALI_TEST_CHECK(visual);
3102 DummyControl actor = DummyControl::New();
3103 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3104 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3105 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3106 application.GetScene().Add(actor);
3108 application.SendNotification();
3109 application.Render();
3111 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3112 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3113 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);