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";
66 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES_ENV";
68 bool gResourceReadySignalFired = false;
69 std::vector<int> gReadyIds = {};
70 void ResourceReadySignal(Control control)
72 gResourceReadySignalFired = true;
73 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
80 Actor CreateActorWithImageVisual(const Property::Map& map)
82 VisualFactory factory = VisualFactory::Get();
83 DummyControl actor = DummyControl::New();
84 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
85 Visual::Base visual = factory.CreateVisual(map);
86 DALI_TEST_CHECK(visual);
87 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
88 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
89 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
93 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
95 VisualFactory factory = VisualFactory::Get();
97 Property::Map propertyMap;
98 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
99 propertyMap.Insert(ImageVisual::Property::URL, url);
100 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
101 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
102 propertyMap.Insert(key, value);
104 return factory.CreateVisual(propertyMap);
109 void TestVisualRender(ToolkitTestApplication& application,
111 Visual::Base& visual,
112 std::size_t expectedSamplers = 0,
113 ImageDimensions imageDimensions = ImageDimensions(),
114 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
116 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
117 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
121 // set the image size, for test case, this needs to be set before loading started
122 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
125 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
126 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
128 application.GetScene().Add(actor);
130 application.SendNotification(); // Send messages to update
131 application.Render(); // process update and render
132 application.SendNotification(); // process any signals to event
136 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
139 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
142 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
145 visual.CreatePropertyMap(map);
146 Property::Value* value = map.Find(mixColorIndex);
147 DALI_TEST_CHECK(value);
149 DALI_TEST_CHECK(value->Get(mixColor1));
150 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
152 value = map.Find(Visual::Property::MIX_COLOR);
153 DALI_TEST_CHECK(value);
155 DALI_TEST_CHECK(value->Get(mixColor2));
156 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
158 value = map.Find(Visual::Property::OPACITY);
159 DALI_TEST_CHECK(value);
161 DALI_TEST_CHECK(value->Get(opacity));
162 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
165 int UtcDaliImageVisualPropertyMap(void)
167 ToolkitTestApplication application;
168 tet_infoline("Request image visual with a Property::Map");
170 VisualFactory factory = VisualFactory::Get();
171 DALI_TEST_CHECK(factory);
172 factory.SetPreMultiplyOnLoad(true);
174 Property::Map propertyMap;
175 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
176 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
178 Visual::Base visual = factory.CreateVisual(propertyMap);
179 DALI_TEST_CHECK(visual);
181 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
182 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
184 TestGlAbstraction& gl = application.GetGlAbstraction();
185 TraceCallStack& textureTrace = gl.GetTextureTrace();
186 textureTrace.Enable(true);
188 DummyControl actor = DummyControl::New();
189 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
190 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
192 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
193 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
195 application.GetScene().Add(actor);
196 application.SendNotification();
197 application.Render();
199 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
201 application.SendNotification();
202 application.Render();
204 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
205 auto renderer = actor.GetRendererAt(0);
206 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
207 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
208 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
209 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
210 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
211 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
212 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
214 application.GetScene().Remove(actor);
215 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
220 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
222 ToolkitTestApplication application;
223 tet_infoline("Request image visual without pre-multiplied alpha");
225 VisualFactory factory = VisualFactory::Get();
226 DALI_TEST_CHECK(factory);
227 factory.SetPreMultiplyOnLoad(false);
229 Property::Map propertyMap;
230 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
231 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
233 Visual::Base visual = factory.CreateVisual(propertyMap);
234 DALI_TEST_CHECK(visual);
236 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
237 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
239 TestGlAbstraction& gl = application.GetGlAbstraction();
240 TraceCallStack& textureTrace = gl.GetTextureTrace();
241 textureTrace.Enable(true);
243 DummyControl actor = DummyControl::New();
244 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
245 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
247 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
248 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
250 application.GetScene().Add(actor);
251 application.SendNotification();
252 application.Render();
254 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
256 application.SendNotification();
257 application.Render();
259 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
260 auto renderer = actor.GetRendererAt(0);
261 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
262 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
263 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
264 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
266 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
267 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
269 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
271 application.GetScene().Remove(actor);
272 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
277 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
279 ToolkitTestApplication application;
280 tet_infoline("Request image visual with no alpha channel");
282 VisualFactory factory = VisualFactory::Get();
283 DALI_TEST_CHECK(factory);
285 Property::Map propertyMap;
286 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
287 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
289 Visual::Base visual = factory.CreateVisual(propertyMap);
290 DALI_TEST_CHECK(visual);
292 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
293 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
295 TestGlAbstraction& gl = application.GetGlAbstraction();
296 TraceCallStack& textureTrace = gl.GetTextureTrace();
297 textureTrace.Enable(true);
299 DummyControl actor = DummyControl::New();
300 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
301 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
303 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
304 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
306 application.GetScene().Add(actor);
307 application.SendNotification();
308 application.Render();
310 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
312 application.SendNotification();
313 application.Render();
315 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
316 auto renderer = actor.GetRendererAt(0);
317 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
318 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
319 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
320 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
322 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
323 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
325 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
327 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
328 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
329 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
330 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
331 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
332 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
333 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
334 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
336 textureTrace.Reset();
338 // Make a new visual with the same image
339 Visual::Base newVisual = factory.CreateVisual(propertyMap);
340 DALI_TEST_CHECK(newVisual);
342 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
343 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
345 DummyControl newActor = DummyControl::New();
346 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
347 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
349 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
350 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
352 application.GetScene().Add(newActor);
354 application.SendNotification();
355 application.Render();
357 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
358 auto newRenderer = newActor.GetRendererAt(0);
359 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
360 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
361 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
362 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
364 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
365 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
367 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
368 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
369 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
370 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
371 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
372 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
373 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
374 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
376 application.GetScene().Remove(actor);
377 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
382 int UtcDaliImageVisualRemoteImageLoad(void)
384 ToolkitTestApplication application;
385 tet_infoline("Request remote image visual with a Property::Map");
387 VisualFactory factory = VisualFactory::Get();
388 DALI_TEST_CHECK(factory);
390 Property::Map propertyMap;
391 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
392 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
394 Visual::Base visual = factory.CreateVisual(propertyMap);
395 DALI_TEST_CHECK(visual);
397 TestGlAbstraction& gl = application.GetGlAbstraction();
398 TraceCallStack& textureTrace = gl.GetTextureTrace();
399 textureTrace.Enable(true);
401 DummyControl actor = DummyControl::New();
402 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
403 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
405 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
406 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
408 application.GetScene().Add(actor);
409 application.SendNotification();
411 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
413 application.SendNotification();
414 application.Render();
416 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
417 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
419 application.GetScene().Remove(actor);
420 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
425 int UtcDaliImageVisualWithNativeImage(void)
427 ToolkitTestApplication application;
428 tet_infoline("Use Native Image as url");
430 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
431 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
432 std::string url = imageUrl.GetUrl();
434 VisualFactory factory = VisualFactory::Get();
435 DALI_TEST_CHECK(factory);
437 Property::Map propertyMap;
438 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
439 propertyMap.Insert(ImageVisual::Property::URL, url);
441 Visual::Base visual = factory.CreateVisual(propertyMap);
442 DALI_TEST_CHECK(visual);
444 DummyControl actor = DummyControl::New();
445 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
446 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
448 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
450 application.GetScene().Add(actor);
452 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
454 Renderer renderer = actor.GetRendererAt(0);
455 Shader shader = renderer.GetShader();
457 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
458 DALI_TEST_CHECK(value.GetType() == Property::MAP);
459 const Property::Map* outMap = value.GetMap();
460 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
462 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
463 size_t pos = fragmentShader.find(fragmentPrefix);
465 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
470 int UtcDaliImageVisualWithNativeImageCustomShader(void)
472 ToolkitTestApplication application;
473 tet_infoline("Use Native Image as url and Use custom shader");
475 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
476 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
477 std::string url = imageUrl.GetUrl();
479 VisualFactory factory = VisualFactory::Get();
480 DALI_TEST_CHECK(factory);
482 Property::Map propertyMap;
483 Property::Map shaderMap;
484 const std::string customVertexShaderSource = "Foobar";
485 const std::string customFragmentShaderSource = "Foobar";
486 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
487 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
489 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
490 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
491 propertyMap.Insert(ImageVisual::Property::URL, url);
493 Visual::Base visual = factory.CreateVisual(propertyMap);
494 DALI_TEST_CHECK(visual);
496 DummyControl actor = DummyControl::New();
497 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
498 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
500 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
501 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
503 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
505 application.GetScene().Add(actor);
507 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
509 application.SendNotification();
510 application.Render(16);
512 Renderer renderer = actor.GetRendererAt(0);
513 Shader shader = renderer.GetShader();
515 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
516 DALI_TEST_CHECK(value.GetType() == Property::MAP);
517 const Property::Map* outMap = value.GetMap();
518 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
519 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
521 // Compare vertex shader is equal
522 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
524 // Check fragment shader changed
525 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
526 size_t pos = fragmentShaderSource.find(fragmentPrefix);
528 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
530 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
535 int UtcDaliImageVisualWithNativeImageRemoved(void)
537 ToolkitTestApplication application;
538 tet_infoline("Use Native Image as url");
540 TestGlAbstraction& gl = application.GetGlAbstraction();
541 TraceCallStack& textureTrace = gl.GetTextureTrace();
542 textureTrace.Enable(true);
544 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
545 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
546 std::string url = imageUrl.GetUrl();
548 VisualFactory factory = VisualFactory::Get();
549 DALI_TEST_CHECK(factory);
551 Property::Map propertyMap;
552 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
553 propertyMap.Insert(ImageVisual::Property::URL, url);
555 Visual::Base visual = factory.CreateVisual(propertyMap);
556 DALI_TEST_CHECK(visual);
558 DummyControl actor = DummyControl::New();
559 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
560 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
562 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
564 application.GetScene().Add(actor);
565 application.SendNotification();
566 application.Render();
568 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
569 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
571 tet_infoline("No delete texture because reference count is not zero");
573 application.GetScene().Remove(actor);
574 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
575 application.SendNotification();
576 application.Render();
578 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
579 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
581 tet_infoline("Delete texture because reference count is zero");
583 application.SendNotification();
584 application.Render();
586 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
591 int UtcDaliImageVisualWithEncodedImageBuffer(void)
593 ToolkitTestApplication application;
594 tet_infoline("Use Encoded Image Buffer as url");
596 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
597 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
599 VisualFactory factory = VisualFactory::Get();
600 DALI_TEST_CHECK(factory);
602 Property::Map propertyMap;
603 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
604 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
606 Visual::Base visual = factory.CreateVisual(propertyMap);
607 DALI_TEST_CHECK(visual);
609 TestGlAbstraction& gl = application.GetGlAbstraction();
610 TraceCallStack& textureTrace = gl.GetTextureTrace();
611 textureTrace.Enable(true);
613 DummyControl actor = DummyControl::New();
614 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
615 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
617 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
618 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
620 application.GetScene().Add(actor);
621 application.SendNotification();
623 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
625 application.SendNotification();
626 application.Render();
628 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
629 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
631 application.GetScene().Remove(actor);
632 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
637 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
639 ToolkitTestApplication application;
640 tet_infoline("Use Encoded Image Buffer as url");
642 TestGlAbstraction& gl = application.GetGlAbstraction();
643 TraceCallStack& textureTrace = gl.GetTextureTrace();
644 textureTrace.Enable(true);
646 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
647 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
648 std::string url = imageUrl.GetUrl();
650 VisualFactory factory = VisualFactory::Get();
651 DALI_TEST_CHECK(factory);
653 Property::Map propertyMap;
654 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
655 propertyMap.Insert(ImageVisual::Property::URL, url);
657 Visual::Base visual = factory.CreateVisual(propertyMap);
658 DALI_TEST_CHECK(visual);
660 DummyControl actor = DummyControl::New();
661 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
662 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
664 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
666 application.GetScene().Add(actor);
667 application.SendNotification();
669 // Wait for decode buffer and make texture.
670 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
672 application.SendNotification();
673 application.Render();
675 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
676 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
678 tet_infoline("Delete texture because there is no actor to use decoded texture");
680 application.GetScene().Remove(actor);
681 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
682 application.SendNotification();
683 application.Render();
685 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
686 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
691 int UtcDaliImageVisualTextureReuse1(void)
693 ToolkitTestApplication application;
694 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
696 Property::Map propertyMap;
697 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
698 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
699 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
701 TestGlAbstraction& gl = application.GetGlAbstraction();
702 TraceCallStack& textureTrace = gl.GetTextureTrace();
703 textureTrace.Enable(true);
704 TraceCallStack& drawTrace = gl.GetDrawTrace();
705 drawTrace.Enable(true);
707 Actor actor = CreateActorWithImageVisual(propertyMap);
708 application.GetScene().Add(actor);
709 application.SendNotification();
711 // Wait for image to load
712 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
714 application.SendNotification();
715 application.Render();
717 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
718 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
719 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
720 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
721 textureTrace.Reset();
724 Actor actor2 = CreateActorWithImageVisual(propertyMap);
725 application.GetScene().Add(actor2);
727 application.SendNotification(); // Send messages to update
728 application.Render(); // process update and render
729 application.SendNotification(); // process any signals to event
731 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
733 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
734 // backend here, but test graphics backend.
735 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
736 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
738 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
740 application.GetScene().Remove(actor);
741 application.SendNotification();
742 application.Render();
744 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
745 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
747 tet_infoline("Test that removing last actor does delete the texture\n");
749 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
750 application.SendNotification();
751 application.Render();
753 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
754 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
759 int UtcDaliImageVisualTextureReuse2(void)
761 ToolkitTestApplication application;
762 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");
764 Property::Map propertyMap;
765 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
766 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
768 TestGlAbstraction& gl = application.GetGlAbstraction();
769 TraceCallStack& textureTrace = gl.GetTextureTrace();
770 textureTrace.Enable(true);
771 TraceCallStack& drawTrace = gl.GetDrawTrace();
772 drawTrace.Enable(true);
774 Actor actor = CreateActorWithImageVisual(propertyMap);
775 application.GetScene().Add(actor);
776 application.SendNotification();
778 // Wait for image to load
779 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
781 application.SendNotification();
782 application.Render();
784 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
785 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
786 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
787 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
788 textureTrace.Reset();
791 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
792 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
793 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
794 Actor actor2 = CreateActorWithImageVisual(propertyMap);
795 application.GetScene().Add(actor2);
797 application.SendNotification();
799 // Wait for image to load
800 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
802 application.SendNotification();
803 application.Render();
805 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
808 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
809 "renderers are using different textures\n");
811 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
812 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
813 TraceCallStack::NamedParams tex1;
814 tex1["texture"] << 1;
815 TraceCallStack::NamedParams tex2;
816 tex2["texture"] << 2;
817 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
818 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
820 tet_infoline("Test that removing 1 actor deletes it's texture\n");
822 application.GetScene().Remove(actor);
823 application.SendNotification();
824 application.Render();
826 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
827 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
829 tet_infoline("Test that removing last actor deletes it's texture\n");
831 application.GetScene().Remove(actor2);
832 application.SendNotification();
833 application.Render();
835 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
836 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
841 int UtcDaliImageVisualCustomWrapModePixelArea(void)
843 ToolkitTestApplication application;
844 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
846 static std::vector<UniformData> customUniforms =
848 UniformData("pixelArea", Property::Type::VECTOR4),
849 UniformData("wrapMode", Property::Type::VECTOR2),
852 TestGraphicsController& graphics = application.GetGraphicsController();
853 graphics.AddCustomUniforms(customUniforms);
855 VisualFactory factory = VisualFactory::Get();
856 DALI_TEST_CHECK(factory);
858 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
859 const int width = 34;
860 const int height = 34;
861 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
863 Property::Map propertyMap;
864 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
865 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
866 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
867 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
868 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
869 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
870 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
871 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
872 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
874 Visual::Base visual = factory.CreateVisual(propertyMap);
875 DALI_TEST_CHECK(visual);
877 TestGlAbstraction& gl = application.GetGlAbstraction();
878 TraceCallStack& textureTrace = gl.GetTextureTrace();
879 textureTrace.Enable(true);
880 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
881 texParameterTrace.Enable(true);
883 DummyControl actor = DummyControl::New();
884 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
885 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
886 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
887 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
888 application.GetScene().Add(actor);
891 application.SendNotification();
892 application.Render();
894 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
896 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
898 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
899 std::stringstream out;
900 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
901 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
903 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
904 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
906 // test the uniforms which used to handle the wrap mode
907 Renderer renderer = actor.GetRendererAt(0u);
908 DALI_TEST_CHECK(renderer);
910 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
911 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
912 Vector4 pixelAreaUniform;
913 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
914 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
916 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
917 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
918 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
919 Vector2 wrapModeUniform;
920 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
921 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
924 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
929 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
931 ToolkitTestApplication application;
932 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
934 static std::vector<UniformData> customUniforms =
936 UniformData("pixelArea", Property::Type::VECTOR4),
939 TestGraphicsController& graphics = application.GetGraphicsController();
940 graphics.AddCustomUniforms(customUniforms);
942 VisualFactory factory = VisualFactory::Get();
943 DALI_TEST_CHECK(factory);
945 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
946 const int width = 600;
947 const int height = 600;
948 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
950 Property::Map propertyMap;
951 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
952 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
953 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
954 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
955 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
956 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
957 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
958 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
960 Visual::Base visual = factory.CreateVisual(propertyMap);
961 DALI_TEST_CHECK(visual);
963 TestGlAbstraction& gl = application.GetGlAbstraction();
964 TraceCallStack& textureTrace = gl.GetTextureTrace();
965 textureTrace.Enable(true);
966 textureTrace.EnableLogging(true);
967 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
968 texParameterTrace.Enable(true);
969 texParameterTrace.EnableLogging(true);
971 DummyControl actor = DummyControl::New();
972 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
973 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
974 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
975 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
976 application.GetScene().Add(actor);
979 application.SendNotification();
980 application.Render();
981 application.SendNotification();
983 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
985 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
987 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
988 std::stringstream out;
989 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
990 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
992 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
993 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
995 // test the uniforms which used to handle the wrap mode
996 Renderer renderer = actor.GetRendererAt(0u);
997 DALI_TEST_CHECK(renderer);
999 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1000 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1001 Vector4 pixelAreaUniform;
1002 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1003 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1005 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1006 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1009 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1014 int UtcDaliImageVisualAnimateMixColor(void)
1016 ToolkitTestApplication application;
1017 tet_infoline("Animate mix color");
1019 static std::vector<UniformData> customUniforms =
1021 UniformData("mixColor", Property::Type::VECTOR3),
1024 TestGraphicsController& graphics = application.GetGraphicsController();
1025 graphics.AddCustomUniforms(customUniforms);
1027 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1029 VisualFactory factory = VisualFactory::Get();
1030 Property::Map propertyMap;
1031 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1032 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1033 propertyMap.Insert("mixColor", Color::BLUE);
1034 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1035 Visual::Base visual = factory.CreateVisual(propertyMap);
1037 DummyControl actor = DummyControl::New(true);
1038 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1039 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1041 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1042 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1043 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1044 application.GetScene().Add(actor);
1046 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1048 Renderer renderer = actor.GetRendererAt(0);
1050 // @todo Should we add API to make this code work again?
1051 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1053 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1054 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1056 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1059 map["target"] = "testVisual";
1060 map["property"] = "mixColor";
1061 map["initialValue"] = Color::MAGENTA;
1062 map["targetValue"] = TARGET_MIX_COLOR;
1063 map["animator"] = Property::Map()
1064 .Add("alphaFunction", "LINEAR")
1065 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1067 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1069 Animation animation = dummyImpl.CreateTransition(transition);
1071 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1074 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1075 glAbstraction.EnableEnableDisableCallTrace(true);
1076 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1077 std::ostringstream blendStr;
1078 blendStr << std::hex << GL_BLEND;
1080 application.SendNotification();
1081 application.Render(0); // Ensure animation starts
1082 application.Render(2000u); // Halfway point
1083 Vector3 testColor(1.0f, 0.0f, 0.5f);
1085 // uColor.a should be actor's alpha * mixColor.a.
1086 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1087 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1089 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1091 glEnableStack.Reset();
1093 application.SendNotification();
1094 application.Render(2000u);
1096 application.SendNotification();
1097 application.Render();
1098 application.SendNotification();
1100 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1101 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1102 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1104 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1106 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1111 int UtcDaliImageVisualAnimateOpacity(void)
1113 ToolkitTestApplication application;
1114 tet_infoline("Animate image visual opacity");
1116 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1118 VisualFactory factory = VisualFactory::Get();
1119 Property::Map propertyMap;
1120 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1121 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1122 propertyMap.Insert("opacity", 0.5f);
1123 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1124 Visual::Base visual = factory.CreateVisual(propertyMap);
1126 DummyControl actor = DummyControl::New(true);
1127 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1128 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1130 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1131 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1132 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1133 application.GetScene().Add(actor);
1135 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1137 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1138 glAbstraction.EnableEnableDisableCallTrace(true);
1139 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1140 std::ostringstream blendStr;
1141 blendStr << std::hex << GL_BLEND;
1143 application.SendNotification();
1144 application.Render();
1146 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1149 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.");
1152 map["target"] = "testVisual";
1153 map["property"] = "opacity";
1154 map["targetValue"] = 1.0f;
1155 map["animator"] = Property::Map()
1156 .Add("alphaFunction", "LINEAR")
1157 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1159 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1160 Animation animation = dummyImpl.CreateTransition(transition);
1163 glEnableStack.Reset();
1165 application.SendNotification();
1166 application.Render(0); // Ensure animation starts
1167 application.Render(2000u); // Halfway point through animation
1168 application.SendNotification(); // Handle any signals
1171 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1172 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1174 application.Render(2001u); // end
1175 application.SendNotification(); // ensure animation finished signal is sent
1177 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1178 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1180 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1181 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1185 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.");
1188 map["target"] = "testVisual";
1189 map["property"] = Visual::Property::OPACITY;
1190 map["targetValue"] = 0.1f;
1191 map["animator"] = Property::Map()
1192 .Add("alphaFunction", "LINEAR")
1193 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1195 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1196 Animation animation = dummyImpl.CreateTransition(transition);
1199 glEnableStack.Reset();
1201 application.SendNotification();
1202 application.Render(0); // Ensure animation starts
1203 application.Render(2000u); // Halfway point
1204 application.SendNotification();
1207 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1208 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1210 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1212 glEnableStack.Reset();
1214 application.Render(2016u); // end
1215 application.SendNotification();
1217 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1218 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1220 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1221 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1227 int UtcDaliImageVisualAnimateOpacity02(void)
1229 ToolkitTestApplication application;
1230 tet_infoline("Animate image visual opacity");
1232 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1234 VisualFactory factory = VisualFactory::Get();
1235 Property::Map propertyMap;
1236 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1237 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1238 propertyMap.Insert("opacity", 0.5f);
1239 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1240 Visual::Base visual = factory.CreateVisual(propertyMap);
1242 DummyControl actor = DummyControl::New(true);
1243 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1244 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1246 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1247 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1248 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1250 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1252 Property::Array array;
1255 map["target"] = "testVisual";
1256 map["property"] = "opacity";
1257 map["initialValue"] = 0.0f;
1258 map["targetValue"] = 1.0f;
1259 map["animator"] = Property::Map()
1260 .Add("alphaFunction", "LINEAR")
1261 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1264 map2["target"] = "testVisual";
1265 map2["property"] = "size";
1266 map2["targetValue"] = Vector2(1.0f, 1.0f);
1268 array.Add(map).Add(map2);
1270 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1271 Animation animation = dummyImpl.CreateTransition(transition);
1273 application.GetScene().Add(actor);
1274 application.SendNotification();
1275 application.Render(0); // Ensure animation starts
1277 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1279 Renderer renderer = actor.GetRendererAt(0);
1280 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1281 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1283 animation = dummyImpl.CreateTransition(transition);
1286 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1287 glAbstraction.EnableEnableDisableCallTrace(true);
1288 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1289 std::ostringstream blendStr;
1290 blendStr << std::hex << GL_BLEND;
1292 application.SendNotification();
1293 application.Render(0); // Ensure animation starts
1294 application.Render(2000u); // Halfway point through animation
1295 application.SendNotification(); // Handle any signals
1297 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1300 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1301 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1303 glEnableStack.Reset();
1305 application.Render(2001u); // end
1306 application.SendNotification(); // ensure animation finished signal is sent
1308 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1309 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1311 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1316 int UtcDaliImageVisualAnimatePixelArea(void)
1318 ToolkitTestApplication application;
1319 tet_infoline("ImageVisual animate pixel area");
1321 static std::vector<UniformData> customUniforms =
1323 UniformData("pixelArea", Property::Type::VECTOR4),
1326 TestGraphicsController& graphics = application.GetGraphicsController();
1327 graphics.AddCustomUniforms(customUniforms);
1329 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1331 VisualFactory factory = VisualFactory::Get();
1332 Property::Map propertyMap;
1333 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1334 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1335 propertyMap.Insert("mixColor", Color::BLUE);
1336 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1337 Visual::Base visual = factory.CreateVisual(propertyMap);
1339 DummyControl actor = DummyControl::New(true);
1340 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1341 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1343 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1344 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1345 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1346 application.GetScene().Add(actor);
1348 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1350 Renderer renderer = actor.GetRendererAt(0);
1351 // @todo Implement this feature?
1352 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1353 //tet_infoline("Test that the renderer has the mixColor property");
1354 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1356 // TransitionData only takes string keys
1358 map["target"] = "testVisual";
1359 map["property"] = "pixelArea";
1360 map["initialValue"] = Vector4(0, 0, 0, 1);
1361 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1362 map["animator"] = Property::Map()
1363 .Add("alphaFunction", "LINEAR")
1364 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1366 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1368 Animation animation = dummyImpl.CreateTransition(transition);
1369 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1372 application.SendNotification();
1373 application.Render(0); // Ensure animation starts
1374 application.Render(2000u); // Halfway point
1376 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1378 application.Render(2000u); // End of animation
1380 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1385 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1387 ToolkitTestApplication application;
1388 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1390 Property::Map propertyMap;
1391 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1392 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1394 TestGlAbstraction& gl = application.GetGlAbstraction();
1395 TraceCallStack& textureTrace = gl.GetTextureTrace();
1396 textureTrace.Enable(true);
1397 TraceCallStack& drawTrace = gl.GetDrawTrace();
1398 drawTrace.Enable(true);
1400 Actor actor = CreateActorWithImageVisual(propertyMap);
1401 application.GetScene().Add(actor);
1402 application.SendNotification();
1404 application.GetScene().Remove(actor);
1405 application.SendNotification();
1407 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1408 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1409 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1410 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1415 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1417 ToolkitTestApplication application;
1418 tet_infoline("Load image asynchronously, cancel loading, then load again");
1420 VisualFactory factory = VisualFactory::Get();
1421 DALI_TEST_CHECK(factory);
1423 Property::Map propertyMap;
1424 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1425 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1427 Visual::Base visual = factory.CreateVisual(propertyMap);
1428 DALI_TEST_CHECK(visual);
1430 TestGlAbstraction& gl = application.GetGlAbstraction();
1431 TraceCallStack& textureTrace = gl.GetTextureTrace();
1432 textureTrace.Enable(true);
1433 TraceCallStack& drawTrace = gl.GetDrawTrace();
1434 drawTrace.Enable(true);
1436 DummyControl actor = DummyControl::New();
1437 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1438 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1440 application.GetScene().Add(actor);
1443 application.GetScene().Remove(actor);
1445 application.GetScene().Add(actor);
1447 // Create another visual with the same image
1448 visual = factory.CreateVisual(propertyMap);
1449 DALI_TEST_CHECK(visual);
1451 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1453 application.SendNotification();
1454 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1456 application.SendNotification();
1457 application.Render();
1459 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1460 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1461 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1462 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1467 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1469 ToolkitTestApplication application;
1470 tet_infoline("Request image visual with invalid images - should draw broken.png");
1472 VisualFactory factory = VisualFactory::Get();
1473 DALI_TEST_CHECK(factory);
1475 Property::Map propertyMap;
1476 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1477 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1479 Visual::Base visual = factory.CreateVisual(propertyMap);
1480 DALI_TEST_CHECK(visual);
1482 TestGlAbstraction& gl = application.GetGlAbstraction();
1483 TraceCallStack& textureTrace = gl.GetTextureTrace();
1484 textureTrace.Enable(true);
1486 DummyControl actor = DummyControl::New();
1487 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1488 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1490 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1491 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1493 application.GetScene().Add(actor);
1495 application.SendNotification();
1496 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1498 application.SendNotification();
1499 application.Render();
1501 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1502 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1504 application.GetScene().Remove(actor);
1505 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1510 int UtcDaliImageVisualSetInvalidSyncImage(void)
1512 ToolkitTestApplication application;
1513 tet_infoline("Request image visual with invalid images - should draw broken.png");
1515 VisualFactory factory = VisualFactory::Get();
1516 DALI_TEST_CHECK(factory);
1518 Property::Map propertyMap;
1519 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1520 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1521 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1523 Visual::Base visual = factory.CreateVisual(propertyMap);
1524 DALI_TEST_CHECK(visual);
1526 TestGlAbstraction& gl = application.GetGlAbstraction();
1527 TraceCallStack& textureTrace = gl.GetTextureTrace();
1528 textureTrace.Enable(true);
1530 DummyControl actor = DummyControl::New();
1531 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1532 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1534 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1535 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1537 application.GetScene().Add(actor);
1539 application.SendNotification();
1540 application.Render();
1542 // Check resource status
1543 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1544 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1546 // The broken image should be shown.
1547 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1548 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1550 application.GetScene().Remove(actor);
1551 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1556 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1558 ToolkitTestApplication application;
1559 tet_infoline("Request image visual with invalid images - should draw broken.png");
1561 VisualFactory factory = VisualFactory::Get();
1562 DALI_TEST_CHECK(factory);
1564 // Local invalid file, asynchronous loading
1565 Property::Map propertyMap;
1566 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1567 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1569 Visual::Base visual = factory.CreateVisual(propertyMap);
1570 DALI_TEST_CHECK(visual);
1572 TestGlAbstraction& gl = application.GetGlAbstraction();
1573 TraceCallStack& textureTrace = gl.GetTextureTrace();
1574 textureTrace.Enable(true);
1576 DummyControl actor = DummyControl::New();
1577 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1578 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1580 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1581 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1583 application.GetScene().Add(actor);
1585 application.SendNotification();
1586 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1588 application.SendNotification();
1589 application.Render();
1591 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1592 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1594 application.GetScene().Remove(actor);
1595 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1600 int UtcDaliImageVisualAlphaMask01(void)
1602 ToolkitTestApplication application;
1603 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1605 VisualFactory factory = VisualFactory::Get();
1606 DALI_TEST_CHECK(factory);
1608 Property::Map propertyMap;
1609 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1610 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1611 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1613 Visual::Base visual = factory.CreateVisual(propertyMap);
1614 DALI_TEST_CHECK(visual);
1616 Property::Map testMap;
1617 visual.CreatePropertyMap(testMap);
1618 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1620 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1621 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1623 TestGlAbstraction& gl = application.GetGlAbstraction();
1624 TraceCallStack& textureTrace = gl.GetTextureTrace();
1625 textureTrace.Enable(true);
1627 DummyControl actor = DummyControl::New();
1628 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1629 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1631 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1632 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1633 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1635 application.GetScene().Add(actor);
1636 application.SendNotification();
1637 application.Render();
1639 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1641 application.SendNotification();
1642 application.Render();
1644 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1645 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1646 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1648 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1649 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1654 int UtcDaliImageVisualAlphaMask02(void)
1656 ToolkitTestApplication application;
1657 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1659 VisualFactory factory = VisualFactory::Get();
1660 DALI_TEST_CHECK(factory);
1662 Property::Map propertyMap;
1663 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1664 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1665 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1666 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1668 Visual::Base visual = factory.CreateVisual(propertyMap);
1669 DALI_TEST_CHECK(visual);
1671 Property::Map testMap;
1672 visual.CreatePropertyMap(testMap);
1673 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1674 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1676 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1677 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1679 TestGlAbstraction& gl = application.GetGlAbstraction();
1680 TraceCallStack& textureTrace = gl.GetTextureTrace();
1681 textureTrace.Enable(true);
1683 DummyControl actor = DummyControl::New();
1684 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1685 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1687 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1688 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1689 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1691 application.GetScene().Add(actor);
1692 application.SendNotification();
1693 application.Render();
1695 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1697 application.SendNotification();
1698 application.Render();
1700 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1701 Renderer renderer = actor.GetRendererAt(0u);
1702 TextureSet textures = renderer.GetTextures();
1703 DALI_TEST_CHECK(textures);
1704 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1706 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1707 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1709 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1710 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1715 int UtcDaliImageVisualAlphaMask03(void)
1717 ToolkitTestApplication application;
1718 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1720 VisualFactory factory = VisualFactory::Get();
1721 DALI_TEST_CHECK(factory);
1723 Property::Map propertyMap;
1724 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1725 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1726 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1727 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1729 Visual::Base visual = factory.CreateVisual(propertyMap);
1730 DALI_TEST_CHECK(visual);
1732 Property::Map testMap;
1733 visual.CreatePropertyMap(testMap);
1735 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1736 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1738 TestGlAbstraction& gl = application.GetGlAbstraction();
1739 TraceCallStack& textureTrace = gl.GetTextureTrace();
1740 textureTrace.Enable(true);
1742 DummyControl actor = DummyControl::New();
1743 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1744 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1746 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1747 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1748 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1750 application.GetScene().Add(actor);
1751 application.SendNotification();
1752 application.Render();
1754 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1756 application.SendNotification();
1757 application.Render();
1759 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1760 Renderer renderer = actor.GetRendererAt(0u);
1761 TextureSet textures = renderer.GetTextures();
1762 DALI_TEST_CHECK(textures);
1763 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
1765 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1766 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1768 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1769 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1774 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
1776 ToolkitTestApplication application;
1777 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
1779 VisualFactory factory = VisualFactory::Get();
1780 DALI_TEST_CHECK(factory);
1782 Property::Map propertyMap;
1783 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1784 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1785 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1786 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1788 Visual::Base visual = factory.CreateVisual(propertyMap);
1789 DALI_TEST_CHECK(visual);
1791 Property::Map testMap;
1792 visual.CreatePropertyMap(testMap);
1793 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1795 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1796 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1798 TestGlAbstraction& gl = application.GetGlAbstraction();
1799 TraceCallStack& textureTrace = gl.GetTextureTrace();
1800 textureTrace.Enable(true);
1802 DummyControl actor = DummyControl::New();
1803 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1804 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1806 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1807 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1808 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1810 application.GetScene().Add(actor);
1812 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1814 application.SendNotification();
1815 application.Render();
1817 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1818 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1819 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1821 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1822 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1827 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
1829 ToolkitTestApplication application;
1830 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
1832 VisualFactory factory = VisualFactory::Get();
1833 DALI_TEST_CHECK(factory);
1835 Property::Map propertyMap;
1836 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1837 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1838 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1839 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1840 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1842 Visual::Base visual = factory.CreateVisual(propertyMap);
1843 DALI_TEST_CHECK(visual);
1845 Property::Map testMap;
1846 visual.CreatePropertyMap(testMap);
1847 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1849 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1850 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1852 TestGlAbstraction& gl = application.GetGlAbstraction();
1853 TraceCallStack& textureTrace = gl.GetTextureTrace();
1854 textureTrace.Enable(true);
1856 DummyControl actor = DummyControl::New();
1857 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1858 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1860 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1861 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1862 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1864 application.GetScene().Add(actor);
1866 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1868 application.SendNotification();
1869 application.Render();
1871 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1872 Renderer renderer = actor.GetRendererAt(0u);
1873 TextureSet textures = renderer.GetTextures();
1874 DALI_TEST_CHECK(textures);
1875 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1877 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1878 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1880 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1881 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1886 int UtcDaliImageVisualRemoteAlphaMask(void)
1888 ToolkitTestApplication application;
1889 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1891 VisualFactory factory = VisualFactory::Get();
1892 DALI_TEST_CHECK(factory);
1894 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1896 Property::Map propertyMap;
1897 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1898 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1899 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1901 Visual::Base visual = factory.CreateVisual(propertyMap);
1902 DALI_TEST_CHECK(visual);
1904 Property::Map testMap;
1905 visual.CreatePropertyMap(testMap);
1907 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1909 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1910 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1912 TestGlAbstraction& gl = application.GetGlAbstraction();
1913 TraceCallStack& textureTrace = gl.GetTextureTrace();
1914 textureTrace.Enable(true);
1916 DummyControl actor = DummyControl::New();
1917 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1918 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1920 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1922 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1923 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1925 application.GetScene().Add(actor);
1926 application.SendNotification();
1927 application.Render();
1929 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1931 application.SendNotification();
1932 application.Render();
1934 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1935 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1936 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1941 int UtcDaliImageVisualAlphaMaskCrop(void)
1943 ToolkitTestApplication application;
1944 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1946 VisualFactory factory = VisualFactory::Get();
1947 DALI_TEST_CHECK(factory);
1949 Property::Map propertyMap;
1950 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1951 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1952 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1953 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1954 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1956 Visual::Base visual = factory.CreateVisual(propertyMap);
1957 DALI_TEST_CHECK(visual);
1959 Property::Map testMap;
1960 visual.CreatePropertyMap(testMap);
1961 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1962 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1963 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1965 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1966 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1968 TestGlAbstraction& gl = application.GetGlAbstraction();
1969 TraceCallStack& textureTrace = gl.GetTextureTrace();
1970 textureTrace.Enable(true);
1972 DummyControl actor = DummyControl::New();
1973 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1974 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1976 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1977 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1978 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1980 application.GetScene().Add(actor);
1981 application.SendNotification();
1982 application.Render();
1984 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1986 application.SendNotification();
1987 application.Render();
1990 visual.GetNaturalSize(size);
1992 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1993 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1994 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1995 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2000 int UtcDaliImageVisualReleasePolicy01(void)
2002 ToolkitTestApplication application;
2003 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2005 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2006 DALI_TEST_CHECK(imageVisual);
2008 // Set up debug trace
2009 TestGlAbstraction& gl = application.GetGlAbstraction();
2010 TraceCallStack& textureTrace = gl.GetTextureTrace();
2011 textureTrace.Enable(true);
2013 tet_infoline("Register visual with control and ensure it has the only handle");
2014 DummyControl actor = DummyControl::New(true);
2015 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2016 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2017 imageVisual.Reset();
2019 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2021 application.SendNotification();
2022 application.Render(0);
2023 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2024 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2026 application.GetScene().Add(actor);
2028 // Wait for image to load
2029 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2031 application.SendNotification();
2032 application.Render(0);
2033 // Test renderer and texture created
2034 tet_infoline("Confirm texture created");
2035 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2036 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2038 tet_infoline("Disable visual causing the texture to be deleted");
2039 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2041 application.SendNotification();
2042 application.Render(0);
2043 // Test renderer and textures removed.
2044 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2045 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2050 int UtcDaliImageVisualReleasePolicy02(void)
2052 ToolkitTestApplication application;
2053 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2055 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2056 DALI_TEST_CHECK(imageVisual);
2058 // Setup debug trace
2059 TestGlAbstraction& gl = application.GetGlAbstraction();
2060 TraceCallStack& textureTrace = gl.GetTextureTrace();
2061 textureTrace.Enable(true);
2063 tet_infoline("Register visual with control and ensure it has the only handle");
2064 DummyControl actor = DummyControl::New(true);
2065 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2066 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2067 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2069 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2071 application.SendNotification();
2072 application.Render(0);
2073 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2074 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2076 application.GetScene().Add(actor);
2078 // Wait for image to load
2079 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2081 application.SendNotification();
2082 application.Render(0);
2083 // Test renderer and texture created
2084 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2085 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2087 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2088 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2089 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2090 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2091 application.SendNotification();
2092 application.Render();
2094 // Test texture removed after visual destroyed.
2095 tet_infoline("Ensure texture is deleted after visual destroyed");
2096 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2101 int UtcDaliImageVisualReleasePolicy03(void)
2103 ToolkitTestApplication application;
2104 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2106 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2107 DALI_TEST_CHECK(imageVisual);
2109 TestGlAbstraction& gl = application.GetGlAbstraction();
2110 TraceCallStack& textureTrace = gl.GetTextureTrace();
2111 textureTrace.Enable(true);
2113 tet_infoline("Register visual with control and ensure it has the only handle");
2114 DummyControl actor = DummyControl::New(true);
2115 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2116 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2117 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2119 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2121 application.SendNotification();
2122 application.Render(0);
2123 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2124 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2126 application.GetScene().Add(actor);
2128 // Wait for image to load
2129 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2131 application.SendNotification();
2132 application.Render(0);
2133 // Test renderer and texture created
2134 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2135 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2137 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2138 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2139 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2140 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2141 application.SendNotification();
2142 application.Render();
2144 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2145 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2150 int UtcDaliImageVisualReleasePolicy04(void)
2152 ToolkitTestApplication application;
2153 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2155 tet_infoline("Create first visual with Never release policy");
2156 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2158 tet_infoline("Create second visual with Destroyed release policy");
2159 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2161 // Set up trace debug
2162 TestGlAbstraction& gl = application.GetGlAbstraction();
2163 TraceCallStack& textureTrace = gl.GetTextureTrace();
2164 textureTrace.Enable(true);
2166 tet_infoline("Register visuals with control and ensure it has the only handles");
2167 DummyControl actor = DummyControl::New(true);
2168 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2169 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2170 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2171 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2172 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2174 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2176 // Test initially zero renderers
2177 application.SendNotification();
2178 application.Render(0);
2179 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2180 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2182 application.GetScene().Add(actor);
2184 // Wait for image to load
2185 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2187 application.SendNotification();
2188 application.Render(0);
2189 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2190 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2191 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2193 // Test renderer removed when visual destroyed
2194 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2195 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2196 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2197 application.SendNotification();
2198 application.Render();
2200 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2201 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2203 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2204 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2205 application.SendNotification();
2206 application.Render();
2208 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2209 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2210 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2215 int UtcDaliImageVisualReleasePolicy05(void)
2217 ToolkitTestApplication application;
2218 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2220 VisualFactory factory = VisualFactory::Get();
2222 Property::Map propertyMapNeverReleasePolicy;
2223 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2224 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2225 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2226 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2227 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2229 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2231 Property::Map resultMap;
2232 imageVisualNever.CreatePropertyMap(resultMap);
2233 DALI_TEST_CHECK(!resultMap.Empty());
2235 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2240 int UtcDaliImageVisualReleasePolicy06(void)
2242 ToolkitTestApplication application;
2243 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2245 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2246 DALI_TEST_CHECK(imageVisual);
2248 TestGlAbstraction& gl = application.GetGlAbstraction();
2249 TraceCallStack& textureTrace = gl.GetTextureTrace();
2250 textureTrace.Enable(true);
2252 tet_infoline("Register visual with control and ensure it has the only handle");
2253 DummyControl actor = DummyControl::New(true);
2254 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2255 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2256 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2258 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2260 application.SendNotification();
2261 application.Render(0);
2262 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2263 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2265 application.GetScene().Add(actor);
2267 // Wait for image to load
2268 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2270 application.SendNotification();
2271 application.Render(0);
2272 // Test renderer and texture created
2273 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2274 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2275 textureTrace.Reset();
2277 tet_infoline("Disable Visual and check texture not affected");
2278 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2279 application.SendNotification();
2280 application.Render(0);
2281 tet_infoline("Check renderer is destroyed when visual off stage");
2282 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2283 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2284 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2285 textureTrace.Reset();
2287 tet_infoline("Re-enable Visual and check texture not affected");
2288 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2289 application.SendNotification();
2290 application.Render(0);
2291 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2292 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2293 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2294 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2299 int UtcDaliImageVisualReleasePolicy07(void)
2301 ToolkitTestApplication application;
2302 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2304 tet_infoline("Create first visual with DESTROYED release policy");
2305 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2307 tet_infoline("Create second visual with DETACHED release policy");
2308 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2310 // Set up trace debug
2311 TestGlAbstraction& gl = application.GetGlAbstraction();
2312 TraceCallStack& textureTrace = gl.GetTextureTrace();
2313 textureTrace.Enable(true);
2315 tet_infoline("Register visuals with control and ensure it has the only handles");
2316 DummyControl actor = DummyControl::New(true);
2317 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2318 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2319 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2320 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2321 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2323 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2325 // Test initially zero renderers
2326 application.SendNotification();
2327 application.Render(0);
2328 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2329 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2331 application.GetScene().Add(actor);
2333 // Wait for image to load
2334 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2336 application.SendNotification();
2337 application.Render(0);
2338 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2339 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2340 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2342 // Test renderer removed when visual destroyed
2343 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2344 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2345 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2346 application.SendNotification();
2347 application.Render();
2349 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2350 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2352 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2353 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2354 application.SendNotification();
2355 application.Render();
2357 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2358 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2363 int UtcDaliImageVisualReleasePolicy08(void)
2365 ToolkitTestApplication application;
2366 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2368 tet_infoline("Create first visual with DESTROYED release policy");
2369 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2371 // Set up trace debug
2372 TestGlAbstraction& gl = application.GetGlAbstraction();
2373 TraceCallStack& textureTrace = gl.GetTextureTrace();
2374 textureTrace.Enable(true);
2376 tet_infoline("Register visuals with control and ensure it has the only handles");
2377 DummyControl actor = DummyControl::New(true);
2378 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2379 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2380 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2382 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2384 // Test initially zero renderers
2385 application.SendNotification();
2386 application.Render(0);
2387 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2388 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2389 textureTrace.Reset();
2391 application.GetScene().Add(actor);
2393 // Wait for image to load
2394 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2396 application.SendNotification();
2397 application.Render(0);
2398 tet_infoline("Ensure a texture is created");
2399 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2400 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2401 textureTrace.Reset();
2403 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2404 // 1. Get TextureSet
2405 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2407 // 2.Remove actor from stage. In this case, renderer also is deleted.
2408 tet_infoline("Remove actor from stage");
2409 application.GetScene().Remove(actor);
2410 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2411 application.SendNotification();
2412 application.Render();
2414 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2415 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2416 textureTrace.Reset();
2418 // 3.Add actor in stage. In this case, renderer is created.
2419 tet_infoline("Add actor in stage");
2420 application.GetScene().Add(actor);
2421 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2422 application.SendNotification();
2423 application.Render();
2424 tet_infoline("Ensure a texture is not created again");
2425 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2426 textureTrace.Reset();
2428 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2429 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2430 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2431 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2432 textureSetBefore.Reset();
2433 textureSetAfter.Reset();
2435 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2436 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2437 application.SendNotification();
2438 application.Render();
2439 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2444 int UtcDaliImageVisualLoadPolicy01(void)
2446 ToolkitTestApplication application;
2447 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2449 // Set up trace debug
2450 TestGlAbstraction& gl = application.GetGlAbstraction();
2451 TraceCallStack& textureTrace = gl.GetTextureTrace();
2452 textureTrace.Enable(true);
2454 tet_infoline("Create visual with IMMEDIATE load policy");
2455 VisualFactory factory = VisualFactory::Get();
2457 Property::Map propertyMap;
2458 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2459 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2460 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2461 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2462 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2464 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2466 Property::Map resultMap;
2467 imageVisual.CreatePropertyMap(resultMap);
2468 DALI_TEST_CHECK(!resultMap.Empty());
2469 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2471 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2473 // Ensure texture has been uploaded
2474 application.SendNotification();
2475 application.Render();
2477 tet_infoline("Ensure texture loading starts after visual created");
2478 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2479 textureTrace.Reset();
2481 tet_infoline("Register visuals with control and ensure it has the only handles");
2482 DummyControl actor = DummyControl::New(true);
2483 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2484 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2485 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2487 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2488 application.GetScene().Add(actor);
2489 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2490 const unsigned int TIME_OUT_3_SECONDS = 3;
2491 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2493 application.SendNotification();
2494 application.Render();
2496 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2497 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2499 // Ensure texture is deleted when no longer needed (ref count was correct )
2500 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2502 application.SendNotification();
2503 application.Render();
2505 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2506 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2511 int UtcDaliImageVisualLoadPolicy02(void)
2513 ToolkitTestApplication application;
2514 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2516 // Set up trace debug
2517 TestGlAbstraction& gl = application.GetGlAbstraction();
2518 TraceCallStack& textureTrace = gl.GetTextureTrace();
2519 textureTrace.Enable(true);
2521 tet_infoline("Create visual with IMMEDIATE load policy");
2522 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2524 const unsigned int TIME_OUT_3_SECONDS = 3;
2525 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2527 // Act on meeage queue even although nothing expected to load
2528 application.SendNotification();
2529 application.Render();
2531 tet_infoline("Ensure texture is not generated yet");
2532 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2533 textureTrace.Reset();
2535 tet_infoline("Register visuals with control and ensure it has the only handles");
2536 DummyControl actor = DummyControl::New(true);
2537 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2538 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2539 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2541 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2542 application.GetScene().Add(actor);
2543 tet_infoline("Allow image time to load");
2544 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2546 application.SendNotification();
2547 application.Render();
2549 tet_infoline("Ensure texture generated and renderer created");
2550 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2551 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2553 // Ensure texture is delete when no longer needed
2554 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2556 application.SendNotification();
2557 application.Render();
2559 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2560 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2565 int UtcDaliImageVisualLoadPolicy03(void)
2567 ToolkitTestApplication application;
2568 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2570 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2572 // Set up trace debug
2573 TestGlAbstraction& gl = application.GetGlAbstraction();
2574 TraceCallStack& textureTrace = gl.GetTextureTrace();
2575 textureTrace.Enable(true);
2577 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2578 DummyControl actor = DummyControl::New(true);
2579 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2580 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2581 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2583 tet_infoline("Create visual with IMMEDIATE load policy");
2584 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2586 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2587 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2588 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2590 tet_infoline("Allow image time to load resource");
2591 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2592 application.SendNotification();
2593 application.Render();
2595 // Ensure texture has been uploaded
2596 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2597 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2602 int UtcDaliImageVisualLoadPolicy04(void)
2604 ToolkitTestApplication application;
2605 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2606 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2608 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2610 // Set up trace debug
2611 TestGlAbstraction& gl = application.GetGlAbstraction();
2612 TraceCallStack& textureTrace = gl.GetTextureTrace();
2613 textureTrace.Enable(true);
2615 tet_infoline("Create a control and connect to resource ready signal");
2616 DummyControl actor = DummyControl::New(true);
2617 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2618 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2619 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2621 tet_infoline("Create visual with IMMEDIATE load policy");
2622 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2624 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2625 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2626 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2628 tet_infoline("Allow image time to load");
2629 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2630 application.SendNotification();
2631 application.Render();
2633 tet_infoline("Testing texture is loaded and resource ready signal fired");
2634 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2635 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2637 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2639 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2640 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2641 DummyControl actor2 = DummyControl::New(true);
2642 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2643 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2645 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2646 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2647 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2648 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2649 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2650 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2655 int UtcDaliImageVisualLoadPolicy05(void)
2657 ToolkitTestApplication application;
2658 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2659 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2660 // Set up trace debug
2661 TestGlAbstraction& gl = application.GetGlAbstraction();
2662 TraceCallStack& textureTrace = gl.GetTextureTrace();
2663 textureTrace.Enable(true);
2665 tet_infoline("Create a control and connect to resource ready signal");
2666 DummyControl actor = DummyControl::New(true);
2667 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2668 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2669 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2670 application.GetScene().Add(actor);
2672 tet_infoline("Create visual with ATTACHED load policy");
2673 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2675 tet_infoline("Registering visual allows control to get a signal once loaded");
2676 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2677 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2679 tet_infoline("Allow image time to load");
2680 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2681 application.SendNotification();
2682 application.Render();
2684 tet_infoline("Testing texture is loaded and resource ready signal fired");
2685 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2686 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2688 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2690 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2691 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2692 DummyControl actor2 = DummyControl::New(true);
2693 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2694 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2696 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2697 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2698 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2699 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2700 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2701 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2706 int UtcDaliImageVisualOrientationCorrection(void)
2708 ToolkitTestApplication application;
2709 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2711 VisualFactory factory = VisualFactory::Get();
2712 tet_infoline("Create visual with Orientation correction set OFF");
2713 Property::Map propertyMap;
2714 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2715 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2716 propertyMap.Insert("orientationCorrection", false);
2717 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2719 tet_infoline("Create control for visual, need to loaded it");
2720 DummyControl actor = DummyControl::New(true);
2721 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2722 application.GetScene().Add(actor);
2724 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2725 // Wait for image to load
2726 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2728 Vector2 originalImageSize;
2729 tet_infoline("Get size of original visual to compare later with rotated image");
2730 imageVisual.GetNaturalSize(originalImageSize);
2731 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2732 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2733 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2734 application.SendNotification();
2735 application.Render();
2737 tet_infoline("Create visual with Orientation correction set ON ");
2738 propertyMap.Clear();
2739 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2740 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2741 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2742 imageVisual = factory.CreateVisual(propertyMap);
2744 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2745 // Wait for image to load
2746 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2748 Vector2 rotatedImageSize;
2749 imageVisual.GetNaturalSize(rotatedImageSize);
2750 tet_infoline("Confirm that visual has rotated");
2751 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2752 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2754 Property::Map resultMap;
2755 imageVisual.CreatePropertyMap(resultMap);
2757 // check the Property::ORIENTATION_CORRECTION value from the returned map
2758 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2759 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2764 int UtcDaliImageVisualCustomShader(void)
2766 ToolkitTestApplication application;
2767 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2769 VisualFactory factory = VisualFactory::Get();
2770 Property::Map properties;
2771 Property::Map shader;
2772 const std::string vertexShader = "Foobar";
2773 const std::string fragmentShader = "Foobar";
2774 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2775 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2777 properties[Visual::Property::TYPE] = Visual::IMAGE;
2778 properties[Visual::Property::SHADER] = shader;
2779 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2781 Visual::Base visual = factory.CreateVisual(properties);
2783 // trigger creation through setting on stage
2784 DummyControl dummy = DummyControl::New(true);
2785 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2786 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2788 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2789 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2790 application.GetScene().Add(dummy);
2792 application.SendNotification();
2793 application.Render();
2795 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2797 Renderer renderer = dummy.GetRendererAt(0);
2798 Shader shader2 = renderer.GetShader();
2799 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2800 Property::Map* map = value.GetMap();
2801 DALI_TEST_CHECK(map);
2803 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2804 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2806 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2807 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2811 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2812 properties[Visual::Property::SHADER] = shader;
2814 Visual::Base visual1 = factory.CreateVisual(properties);
2816 // trigger creation through setting on stage
2817 DummyControl dummy1 = DummyControl::New(true);
2818 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2819 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2820 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2821 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2822 application.GetScene().Add(dummy1);
2824 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2825 glAbstraction.EnableEnableDisableCallTrace(true);
2827 application.SendNotification();
2828 application.Render();
2830 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2831 std::ostringstream blendStr;
2832 blendStr << std::hex << GL_BLEND;
2833 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2838 void ResourceReadyLoadNext(Control control)
2840 static int callNumber = 0;
2842 gResourceReadySignalFired = true;
2843 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2847 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2849 tet_infoline("Create visual with loaded image from within the signal handler");
2850 VisualFactory factory = VisualFactory::Get();
2851 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2853 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2854 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2859 tet_infoline("3rd signal called");
2860 DALI_TEST_CHECK(true);
2864 int UtcDaliImageVisualLoadReady01(void)
2866 ToolkitTestApplication application;
2867 tet_infoline("UtcDaliImageVisualLoadReady01");
2868 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2869 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2870 tet_infoline("Should get a ready signal for all three visuals");
2874 tet_infoline("Create a control and connect to resource ready signal");
2875 DummyControl actor = DummyControl::New(true);
2876 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2877 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2878 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2879 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2880 application.GetScene().Add(actor);
2882 tet_infoline("Create visual with IMMEDIATE load policy");
2883 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2885 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2886 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2888 tet_infoline("Allow image time to load");
2889 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2890 application.SendNotification();
2891 application.Render();
2893 tet_infoline("Testing texture is loaded and resource ready signal fired");
2894 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2895 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2897 tet_infoline("Original control correctly signalled, now testing failing image");
2899 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2902 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2904 DummyControl actor2 = DummyControl::New(true);
2905 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2906 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2907 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2909 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2910 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2912 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2913 application.GetScene().Add(actor2);
2915 tet_infoline("Wait for loading thread to finish");
2916 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2917 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2919 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2921 tet_infoline("Check for 3rd signal");
2922 application.SendNotification();
2923 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2924 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
2929 int UtcDaliImageVisualLoadImagePlanes01(void)
2931 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
2933 ToolkitTestApplication application;
2935 VisualFactory factory = VisualFactory::Get();
2936 DALI_TEST_CHECK(factory);
2938 Property::Map propertyMap;
2939 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2940 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
2942 Visual::Base visual = factory.CreateVisual(propertyMap);
2943 DALI_TEST_CHECK(visual);
2945 DummyControl actor = DummyControl::New();
2946 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2947 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2948 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2949 application.GetScene().Add(actor);
2951 application.SendNotification();
2952 application.Render();
2954 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2956 TestGlAbstraction& gl = application.GetGlAbstraction();
2957 TraceCallStack& textureTrace = gl.GetTextureTrace();
2958 textureTrace.Enable(true);
2960 application.SendNotification();
2961 application.Render();
2963 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2964 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2965 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
2967 Renderer renderer = actor.GetRendererAt(0);
2968 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
2969 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
2974 int UtcDaliImageVisualLoadImagePlanes02(void)
2976 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
2978 ToolkitTestApplication application;
2980 VisualFactory factory = VisualFactory::Get();
2981 DALI_TEST_CHECK(factory);
2983 // Alpha masking case - not support yuv planes
2984 Property::Map propertyMap;
2985 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2986 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
2987 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2989 Visual::Base visual = factory.CreateVisual(propertyMap);
2990 DALI_TEST_CHECK(visual);
2992 DummyControl actor = DummyControl::New();
2993 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2994 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2995 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2996 application.GetScene().Add(actor);
2998 application.SendNotification();
2999 application.Render();
3001 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3003 TestGlAbstraction& gl = application.GetGlAbstraction();
3004 TraceCallStack& textureTrace = gl.GetTextureTrace();
3005 textureTrace.Enable(true);
3007 application.SendNotification();
3008 application.Render();
3010 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3011 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3012 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3017 int UtcDaliImageVisualLoadImagePlanes03(void)
3019 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3021 ToolkitTestApplication application;
3023 VisualFactory factory = VisualFactory::Get();
3024 DALI_TEST_CHECK(factory);
3026 TestGlAbstraction& gl = application.GetGlAbstraction();
3027 TraceCallStack& textureTrace = gl.GetTextureTrace();
3028 textureTrace.Enable(true);
3030 Property::Map propertyMap;
3031 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3032 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3033 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3035 Visual::Base visual = factory.CreateVisual(propertyMap);
3036 DALI_TEST_CHECK(visual);
3038 DummyControl actor = DummyControl::New();
3039 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3040 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3041 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3042 application.GetScene().Add(actor);
3044 application.SendNotification();
3045 application.Render();
3047 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3048 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3049 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);