2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-environment-variable.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <toolkit-timer.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
30 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
33 #include <dali-toolkit/public-api/image-loader/image-url.h>
34 #include <dali-toolkit/public-api/image-loader/image.h>
36 #include "dummy-control.h"
37 #include "test-encoded-image-buffer.h"
38 #include "test-native-image-source.h"
41 using namespace Dali::Toolkit;
43 void dali_image_visual_startup(void)
45 test_return_value = TET_UNDEF;
48 void dali_image_visual_cleanup(void)
50 test_return_value = TET_PASS;
55 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
56 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
57 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
58 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
59 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
60 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
61 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
62 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
63 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
65 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
67 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES_ENV";
69 bool gResourceReadySignalFired = false;
70 std::vector<int> gReadyIds = {};
71 void ResourceReadySignal(Control control)
73 gResourceReadySignalFired = true;
74 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
81 Actor CreateActorWithImageVisual(const Property::Map& map)
83 VisualFactory factory = VisualFactory::Get();
84 DummyControl actor = DummyControl::New();
85 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
86 Visual::Base visual = factory.CreateVisual(map);
87 DALI_TEST_CHECK(visual);
88 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
89 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
90 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
94 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
96 VisualFactory factory = VisualFactory::Get();
98 Property::Map propertyMap;
99 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
100 propertyMap.Insert(ImageVisual::Property::URL, url);
101 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
102 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
103 propertyMap.Insert(key, value);
105 return factory.CreateVisual(propertyMap);
110 void TestVisualRender(ToolkitTestApplication& application,
112 Visual::Base& visual,
113 std::size_t expectedSamplers = 0,
114 ImageDimensions imageDimensions = ImageDimensions(),
115 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
117 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
118 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
122 // set the image size, for test case, this needs to be set before loading started
123 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
126 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
127 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
129 application.GetScene().Add(actor);
131 application.SendNotification(); // Send messages to update
132 application.Render(); // process update and render
133 application.SendNotification(); // process any signals to event
137 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
140 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
143 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
146 visual.CreatePropertyMap(map);
147 Property::Value* value = map.Find(mixColorIndex);
148 DALI_TEST_CHECK(value);
150 DALI_TEST_CHECK(value->Get(mixColor1));
151 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
153 value = map.Find(Visual::Property::MIX_COLOR);
154 DALI_TEST_CHECK(value);
156 DALI_TEST_CHECK(value->Get(mixColor2));
157 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
159 value = map.Find(Visual::Property::OPACITY);
160 DALI_TEST_CHECK(value);
162 DALI_TEST_CHECK(value->Get(opacity));
163 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
166 int UtcDaliImageVisualPropertyMap(void)
168 ToolkitTestApplication application;
169 tet_infoline("Request image visual with a Property::Map");
171 VisualFactory factory = VisualFactory::Get();
172 DALI_TEST_CHECK(factory);
173 factory.SetPreMultiplyOnLoad(true);
175 Property::Map propertyMap;
176 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
177 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
179 Visual::Base visual = factory.CreateVisual(propertyMap);
180 DALI_TEST_CHECK(visual);
182 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
183 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
185 TestGlAbstraction& gl = application.GetGlAbstraction();
186 TraceCallStack& textureTrace = gl.GetTextureTrace();
187 textureTrace.Enable(true);
189 DummyControl actor = DummyControl::New();
190 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
191 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
193 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
194 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
196 application.GetScene().Add(actor);
197 application.SendNotification();
198 application.Render();
200 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
202 application.SendNotification();
203 application.Render();
205 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
206 auto renderer = actor.GetRendererAt(0);
207 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
208 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
209 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
210 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
211 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
212 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
213 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
215 application.GetScene().Remove(actor);
216 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
221 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
223 ToolkitTestApplication application;
224 tet_infoline("Request image visual without pre-multiplied alpha");
226 VisualFactory factory = VisualFactory::Get();
227 DALI_TEST_CHECK(factory);
228 factory.SetPreMultiplyOnLoad(false);
230 Property::Map propertyMap;
231 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
232 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
234 Visual::Base visual = factory.CreateVisual(propertyMap);
235 DALI_TEST_CHECK(visual);
237 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
238 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
240 TestGlAbstraction& gl = application.GetGlAbstraction();
241 TraceCallStack& textureTrace = gl.GetTextureTrace();
242 textureTrace.Enable(true);
244 DummyControl actor = DummyControl::New();
245 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
246 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
248 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
249 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
251 application.GetScene().Add(actor);
252 application.SendNotification();
253 application.Render();
255 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
257 application.SendNotification();
258 application.Render();
260 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
261 auto renderer = actor.GetRendererAt(0);
262 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
263 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
264 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
265 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
267 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
268 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
270 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
272 application.GetScene().Remove(actor);
273 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
278 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
280 ToolkitTestApplication application;
281 tet_infoline("Request image visual with no alpha channel");
283 VisualFactory factory = VisualFactory::Get();
284 DALI_TEST_CHECK(factory);
286 Property::Map propertyMap;
287 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
288 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
290 Visual::Base visual = factory.CreateVisual(propertyMap);
291 DALI_TEST_CHECK(visual);
293 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
294 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
296 TestGlAbstraction& gl = application.GetGlAbstraction();
297 TraceCallStack& textureTrace = gl.GetTextureTrace();
298 textureTrace.Enable(true);
300 DummyControl actor = DummyControl::New();
301 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
302 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
304 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
305 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
307 application.GetScene().Add(actor);
308 application.SendNotification();
309 application.Render();
311 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
313 application.SendNotification();
314 application.Render();
316 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
317 auto renderer = actor.GetRendererAt(0);
318 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
319 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
320 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
321 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
323 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
324 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
326 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
328 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
329 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
330 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
331 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
332 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
333 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
334 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
335 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
337 textureTrace.Reset();
339 // Make a new visual with the same image
340 Visual::Base newVisual = factory.CreateVisual(propertyMap);
341 DALI_TEST_CHECK(newVisual);
343 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
344 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
346 DummyControl newActor = DummyControl::New();
347 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
348 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
350 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
351 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
353 application.GetScene().Add(newActor);
355 application.SendNotification();
356 application.Render();
358 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
359 auto newRenderer = newActor.GetRendererAt(0);
360 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
361 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
362 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
363 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
365 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
366 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
368 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
369 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
370 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
371 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
372 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
373 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
374 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
375 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
377 application.GetScene().Remove(actor);
378 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
383 int UtcDaliImageVisualRemoteImageLoad(void)
385 ToolkitTestApplication application;
386 tet_infoline("Request remote image visual with a Property::Map");
388 VisualFactory factory = VisualFactory::Get();
389 DALI_TEST_CHECK(factory);
391 Property::Map propertyMap;
392 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
393 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
395 Visual::Base visual = factory.CreateVisual(propertyMap);
396 DALI_TEST_CHECK(visual);
398 TestGlAbstraction& gl = application.GetGlAbstraction();
399 TraceCallStack& textureTrace = gl.GetTextureTrace();
400 textureTrace.Enable(true);
402 DummyControl actor = DummyControl::New();
403 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
404 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
406 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
407 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
409 application.GetScene().Add(actor);
410 application.SendNotification();
412 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
414 application.SendNotification();
415 application.Render();
417 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
418 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
420 application.GetScene().Remove(actor);
421 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
426 int UtcDaliImageVisualWithNativeImage(void)
428 ToolkitTestApplication application;
429 tet_infoline("Use Native Image as url");
431 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
432 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
433 std::string url = imageUrl.GetUrl();
435 VisualFactory factory = VisualFactory::Get();
436 DALI_TEST_CHECK(factory);
438 Property::Map propertyMap;
439 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
440 propertyMap.Insert(ImageVisual::Property::URL, url);
442 Visual::Base visual = factory.CreateVisual(propertyMap);
443 DALI_TEST_CHECK(visual);
445 DummyControl actor = DummyControl::New();
446 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
447 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
449 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
451 application.GetScene().Add(actor);
453 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
455 Renderer renderer = actor.GetRendererAt(0);
456 Shader shader = renderer.GetShader();
458 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
459 DALI_TEST_CHECK(value.GetType() == Property::MAP);
460 const Property::Map* outMap = value.GetMap();
461 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
463 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
464 size_t pos = fragmentShader.find(fragmentPrefix);
466 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
471 int UtcDaliImageVisualWithNativeImageCustomShader(void)
473 ToolkitTestApplication application;
474 tet_infoline("Use Native Image as url and Use custom shader");
476 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
477 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
478 std::string url = imageUrl.GetUrl();
480 VisualFactory factory = VisualFactory::Get();
481 DALI_TEST_CHECK(factory);
483 Property::Map propertyMap;
484 Property::Map shaderMap;
485 const std::string customVertexShaderSource = "Foobar";
486 const std::string customFragmentShaderSource = "Foobar";
487 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
488 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
490 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
491 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
492 propertyMap.Insert(ImageVisual::Property::URL, url);
494 Visual::Base visual = factory.CreateVisual(propertyMap);
495 DALI_TEST_CHECK(visual);
497 DummyControl actor = DummyControl::New();
498 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
499 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
501 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
502 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
504 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
506 application.GetScene().Add(actor);
508 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
510 application.SendNotification();
511 application.Render(16);
513 Renderer renderer = actor.GetRendererAt(0);
514 Shader shader = renderer.GetShader();
516 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
517 DALI_TEST_CHECK(value.GetType() == Property::MAP);
518 const Property::Map* outMap = value.GetMap();
519 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
520 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
522 // Compare vertex shader is equal
523 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
525 // Check fragment shader changed
526 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
527 size_t pos = fragmentShaderSource.find(fragmentPrefix);
529 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
531 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
536 int UtcDaliImageVisualWithNativeImageRemoved(void)
538 ToolkitTestApplication application;
539 tet_infoline("Use Native Image as url");
541 TestGlAbstraction& gl = application.GetGlAbstraction();
542 TraceCallStack& textureTrace = gl.GetTextureTrace();
543 textureTrace.Enable(true);
545 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
546 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
547 std::string url = imageUrl.GetUrl();
549 VisualFactory factory = VisualFactory::Get();
550 DALI_TEST_CHECK(factory);
552 Property::Map propertyMap;
553 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
554 propertyMap.Insert(ImageVisual::Property::URL, url);
556 Visual::Base visual = factory.CreateVisual(propertyMap);
557 DALI_TEST_CHECK(visual);
559 DummyControl actor = DummyControl::New();
560 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
561 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
563 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
565 application.GetScene().Add(actor);
566 application.SendNotification();
567 application.Render();
569 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
570 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
572 tet_infoline("No delete texture because reference count is not zero");
574 application.GetScene().Remove(actor);
575 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
576 application.SendNotification();
577 application.Render();
579 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
580 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
582 tet_infoline("Delete texture because reference count is zero");
584 application.SendNotification();
585 application.Render();
587 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
592 int UtcDaliImageVisualWithEncodedImageBuffer(void)
594 ToolkitTestApplication application;
595 tet_infoline("Use Encoded Image Buffer as url");
597 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
598 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
600 VisualFactory factory = VisualFactory::Get();
601 DALI_TEST_CHECK(factory);
603 Property::Map propertyMap;
604 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
605 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
607 Visual::Base visual = factory.CreateVisual(propertyMap);
608 DALI_TEST_CHECK(visual);
610 TestGlAbstraction& gl = application.GetGlAbstraction();
611 TraceCallStack& textureTrace = gl.GetTextureTrace();
612 textureTrace.Enable(true);
614 DummyControl actor = DummyControl::New();
615 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
616 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
618 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
619 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
621 application.GetScene().Add(actor);
622 application.SendNotification();
624 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
626 application.SendNotification();
627 application.Render();
629 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
630 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
632 application.GetScene().Remove(actor);
633 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
638 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
640 ToolkitTestApplication application;
641 tet_infoline("Use Encoded Image Buffer as url");
643 TestGlAbstraction& gl = application.GetGlAbstraction();
644 TraceCallStack& textureTrace = gl.GetTextureTrace();
645 textureTrace.Enable(true);
647 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
648 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
649 std::string url = imageUrl.GetUrl();
651 VisualFactory factory = VisualFactory::Get();
652 DALI_TEST_CHECK(factory);
654 Property::Map propertyMap;
655 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
656 propertyMap.Insert(ImageVisual::Property::URL, url);
658 Visual::Base visual = factory.CreateVisual(propertyMap);
659 DALI_TEST_CHECK(visual);
661 DummyControl actor = DummyControl::New();
662 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
663 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
665 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
667 application.GetScene().Add(actor);
668 application.SendNotification();
670 // Wait for decode buffer and make texture.
671 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
673 application.SendNotification();
674 application.Render();
676 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
677 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
679 tet_infoline("Delete texture because there is no actor to use decoded texture");
681 application.GetScene().Remove(actor);
682 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
683 application.SendNotification();
684 application.Render();
686 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
687 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
692 int UtcDaliImageVisualTextureReuse1(void)
694 ToolkitTestApplication application;
695 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
697 Property::Map propertyMap;
698 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
699 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
700 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
702 TestGlAbstraction& gl = application.GetGlAbstraction();
703 TraceCallStack& textureTrace = gl.GetTextureTrace();
704 textureTrace.Enable(true);
705 TraceCallStack& drawTrace = gl.GetDrawTrace();
706 drawTrace.Enable(true);
708 Actor actor = CreateActorWithImageVisual(propertyMap);
709 application.GetScene().Add(actor);
710 application.SendNotification();
712 // Wait for image to load
713 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
715 application.SendNotification();
716 application.Render();
718 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
719 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
720 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
721 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
722 textureTrace.Reset();
725 Actor actor2 = CreateActorWithImageVisual(propertyMap);
726 application.GetScene().Add(actor2);
728 application.SendNotification(); // Send messages to update
729 application.Render(); // process update and render
730 application.SendNotification(); // process any signals to event
732 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
734 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
735 // backend here, but test graphics backend.
736 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
737 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
739 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
741 application.GetScene().Remove(actor);
742 application.SendNotification();
743 application.Render();
745 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
746 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
748 tet_infoline("Test that removing last actor does delete the texture\n");
750 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
751 application.SendNotification();
752 application.Render();
754 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
755 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
760 int UtcDaliImageVisualTextureReuse2(void)
762 ToolkitTestApplication application;
763 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");
765 Property::Map propertyMap;
766 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
767 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
769 TestGlAbstraction& gl = application.GetGlAbstraction();
770 TraceCallStack& textureTrace = gl.GetTextureTrace();
771 textureTrace.Enable(true);
772 TraceCallStack& drawTrace = gl.GetDrawTrace();
773 drawTrace.Enable(true);
775 Actor actor = CreateActorWithImageVisual(propertyMap);
776 application.GetScene().Add(actor);
777 application.SendNotification();
779 // Wait for image to load
780 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
782 application.SendNotification();
783 application.Render();
785 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
786 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
787 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
788 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
789 textureTrace.Reset();
792 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
793 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
794 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
795 Actor actor2 = CreateActorWithImageVisual(propertyMap);
796 application.GetScene().Add(actor2);
798 application.SendNotification();
800 // Wait for image to load
801 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
803 application.SendNotification();
804 application.Render();
806 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
809 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
810 "renderers are using different textures\n");
812 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
813 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
814 TraceCallStack::NamedParams tex1;
815 tex1["texture"] << 1;
816 TraceCallStack::NamedParams tex2;
817 tex2["texture"] << 2;
818 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
819 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
821 tet_infoline("Test that removing 1 actor deletes it's texture\n");
823 application.GetScene().Remove(actor);
824 application.SendNotification();
825 application.Render();
827 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
828 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
830 tet_infoline("Test that removing last actor deletes it's texture\n");
832 application.GetScene().Remove(actor2);
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
837 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
842 int UtcDaliImageVisualCustomWrapModePixelArea(void)
844 ToolkitTestApplication application;
845 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
847 static std::vector<UniformData> customUniforms =
849 UniformData("pixelArea", Property::Type::VECTOR4),
850 UniformData("wrapMode", Property::Type::VECTOR2),
853 TestGraphicsController& graphics = application.GetGraphicsController();
854 graphics.AddCustomUniforms(customUniforms);
856 VisualFactory factory = VisualFactory::Get();
857 DALI_TEST_CHECK(factory);
859 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
860 const int width = 34;
861 const int height = 34;
862 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
864 Property::Map propertyMap;
865 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
866 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
867 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
868 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
869 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
870 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
871 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
872 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
873 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
875 Visual::Base visual = factory.CreateVisual(propertyMap);
876 DALI_TEST_CHECK(visual);
878 TestGlAbstraction& gl = application.GetGlAbstraction();
879 TraceCallStack& textureTrace = gl.GetTextureTrace();
880 textureTrace.Enable(true);
881 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
882 texParameterTrace.Enable(true);
884 DummyControl actor = DummyControl::New();
885 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
886 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
887 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
888 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
889 application.GetScene().Add(actor);
892 application.SendNotification();
893 application.Render();
895 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
897 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
899 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
900 std::stringstream out;
901 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
902 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
904 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
905 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
907 // test the uniforms which used to handle the wrap mode
908 Renderer renderer = actor.GetRendererAt(0u);
909 DALI_TEST_CHECK(renderer);
911 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
912 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
913 Vector4 pixelAreaUniform;
914 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
915 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
917 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
918 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
919 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
920 Vector2 wrapModeUniform;
921 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
922 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
925 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
930 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
932 ToolkitTestApplication application;
933 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
935 static std::vector<UniformData> customUniforms =
937 UniformData("pixelArea", Property::Type::VECTOR4),
940 TestGraphicsController& graphics = application.GetGraphicsController();
941 graphics.AddCustomUniforms(customUniforms);
943 VisualFactory factory = VisualFactory::Get();
944 DALI_TEST_CHECK(factory);
946 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
947 const int width = 600;
948 const int height = 600;
949 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
951 Property::Map propertyMap;
952 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
953 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
954 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
955 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
956 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
957 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
958 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
959 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
961 Visual::Base visual = factory.CreateVisual(propertyMap);
962 DALI_TEST_CHECK(visual);
964 TestGlAbstraction& gl = application.GetGlAbstraction();
965 TraceCallStack& textureTrace = gl.GetTextureTrace();
966 textureTrace.Enable(true);
967 textureTrace.EnableLogging(true);
968 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
969 texParameterTrace.Enable(true);
970 texParameterTrace.EnableLogging(true);
972 DummyControl actor = DummyControl::New();
973 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
974 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
975 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
976 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
977 application.GetScene().Add(actor);
980 application.SendNotification();
981 application.Render();
982 application.SendNotification();
984 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
986 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
988 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
989 std::stringstream out;
990 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
991 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
993 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
994 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
996 // test the uniforms which used to handle the wrap mode
997 Renderer renderer = actor.GetRendererAt(0u);
998 DALI_TEST_CHECK(renderer);
1000 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1001 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1002 Vector4 pixelAreaUniform;
1003 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1004 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1006 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1007 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1010 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1015 int UtcDaliImageVisualAnimateMixColor(void)
1017 ToolkitTestApplication application;
1018 tet_infoline("Animate mix color");
1020 static std::vector<UniformData> customUniforms =
1022 UniformData("mixColor", Property::Type::VECTOR3),
1025 TestGraphicsController& graphics = application.GetGraphicsController();
1026 graphics.AddCustomUniforms(customUniforms);
1028 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1030 VisualFactory factory = VisualFactory::Get();
1031 Property::Map propertyMap;
1032 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1033 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1034 propertyMap.Insert("mixColor", Color::BLUE);
1035 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1036 Visual::Base visual = factory.CreateVisual(propertyMap);
1038 DummyControl actor = DummyControl::New(true);
1039 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1040 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1042 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1043 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1044 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1045 application.GetScene().Add(actor);
1047 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1049 Renderer renderer = actor.GetRendererAt(0);
1051 // @todo Should we add API to make this code work again?
1052 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1054 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1055 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1057 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1060 map["target"] = "testVisual";
1061 map["property"] = "mixColor";
1062 map["initialValue"] = Color::MAGENTA;
1063 map["targetValue"] = TARGET_MIX_COLOR;
1064 map["animator"] = Property::Map()
1065 .Add("alphaFunction", "LINEAR")
1066 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1068 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1070 Animation animation = dummyImpl.CreateTransition(transition);
1072 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1075 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1076 glAbstraction.EnableEnableDisableCallTrace(true);
1077 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1078 std::ostringstream blendStr;
1079 blendStr << std::hex << GL_BLEND;
1081 application.SendNotification();
1082 application.Render(0); // Ensure animation starts
1083 application.Render(2000u); // Halfway point
1084 Vector3 testColor(1.0f, 0.0f, 0.5f);
1086 // uColor.a should be actor's alpha * mixColor.a.
1087 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1088 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1090 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1092 glEnableStack.Reset();
1094 application.SendNotification();
1095 application.Render(2000u);
1097 application.SendNotification();
1098 application.Render();
1099 application.SendNotification();
1101 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1102 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1103 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1105 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1107 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1112 int UtcDaliImageVisualAnimateOpacity(void)
1114 ToolkitTestApplication application;
1115 tet_infoline("Animate image visual opacity");
1117 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1119 VisualFactory factory = VisualFactory::Get();
1120 Property::Map propertyMap;
1121 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1122 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1123 propertyMap.Insert("opacity", 0.5f);
1124 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1125 Visual::Base visual = factory.CreateVisual(propertyMap);
1127 DummyControl actor = DummyControl::New(true);
1128 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1129 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1131 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1132 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1133 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1134 application.GetScene().Add(actor);
1136 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1138 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1139 glAbstraction.EnableEnableDisableCallTrace(true);
1140 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1141 std::ostringstream blendStr;
1142 blendStr << std::hex << GL_BLEND;
1144 application.SendNotification();
1145 application.Render();
1147 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1150 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.");
1153 map["target"] = "testVisual";
1154 map["property"] = "opacity";
1155 map["targetValue"] = 1.0f;
1156 map["animator"] = Property::Map()
1157 .Add("alphaFunction", "LINEAR")
1158 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1160 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1161 Animation animation = dummyImpl.CreateTransition(transition);
1164 glEnableStack.Reset();
1166 application.SendNotification();
1167 application.Render(0); // Ensure animation starts
1168 application.Render(2000u); // Halfway point through animation
1169 application.SendNotification(); // Handle any signals
1172 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1173 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1175 application.Render(2001u); // end
1176 application.SendNotification(); // ensure animation finished signal is sent
1178 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1179 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1181 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1182 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1186 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.");
1189 map["target"] = "testVisual";
1190 map["property"] = Visual::Property::OPACITY;
1191 map["targetValue"] = 0.1f;
1192 map["animator"] = Property::Map()
1193 .Add("alphaFunction", "LINEAR")
1194 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1196 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1197 Animation animation = dummyImpl.CreateTransition(transition);
1200 glEnableStack.Reset();
1202 application.SendNotification();
1203 application.Render(0); // Ensure animation starts
1204 application.Render(2000u); // Halfway point
1205 application.SendNotification();
1208 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1209 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1211 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1213 glEnableStack.Reset();
1215 application.Render(2016u); // end
1216 application.SendNotification();
1218 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1219 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1221 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1222 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1228 int UtcDaliImageVisualAnimateOpacity02(void)
1230 ToolkitTestApplication application;
1231 tet_infoline("Animate image visual opacity");
1233 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1235 VisualFactory factory = VisualFactory::Get();
1236 Property::Map propertyMap;
1237 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1238 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1239 propertyMap.Insert("opacity", 0.5f);
1240 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1241 Visual::Base visual = factory.CreateVisual(propertyMap);
1243 DummyControl actor = DummyControl::New(true);
1244 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1245 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1247 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1248 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1249 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1251 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1253 Property::Array array;
1256 map["target"] = "testVisual";
1257 map["property"] = "opacity";
1258 map["initialValue"] = 0.0f;
1259 map["targetValue"] = 1.0f;
1260 map["animator"] = Property::Map()
1261 .Add("alphaFunction", "LINEAR")
1262 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1265 map2["target"] = "testVisual";
1266 map2["property"] = "size";
1267 map2["targetValue"] = Vector2(1.0f, 1.0f);
1269 array.Add(map).Add(map2);
1271 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1272 Animation animation = dummyImpl.CreateTransition(transition);
1274 application.GetScene().Add(actor);
1275 application.SendNotification();
1276 application.Render(0); // Ensure animation starts
1278 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1280 Renderer renderer = actor.GetRendererAt(0);
1281 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1282 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1284 animation = dummyImpl.CreateTransition(transition);
1287 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1288 glAbstraction.EnableEnableDisableCallTrace(true);
1289 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1290 std::ostringstream blendStr;
1291 blendStr << std::hex << GL_BLEND;
1293 application.SendNotification();
1294 application.Render(0); // Ensure animation starts
1295 application.Render(2000u); // Halfway point through animation
1296 application.SendNotification(); // Handle any signals
1298 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1301 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1302 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1304 glEnableStack.Reset();
1306 application.Render(2001u); // end
1307 application.SendNotification(); // ensure animation finished signal is sent
1309 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1310 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1312 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1317 int UtcDaliImageVisualAnimatePixelArea(void)
1319 ToolkitTestApplication application;
1320 tet_infoline("ImageVisual animate pixel area");
1322 static std::vector<UniformData> customUniforms =
1324 UniformData("pixelArea", Property::Type::VECTOR4),
1327 TestGraphicsController& graphics = application.GetGraphicsController();
1328 graphics.AddCustomUniforms(customUniforms);
1330 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1332 VisualFactory factory = VisualFactory::Get();
1333 Property::Map propertyMap;
1334 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1335 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1336 propertyMap.Insert("mixColor", Color::BLUE);
1337 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1338 Visual::Base visual = factory.CreateVisual(propertyMap);
1340 DummyControl actor = DummyControl::New(true);
1341 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1342 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1344 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1345 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1346 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1347 application.GetScene().Add(actor);
1349 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1351 Renderer renderer = actor.GetRendererAt(0);
1352 // @todo Implement this feature?
1353 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1354 //tet_infoline("Test that the renderer has the mixColor property");
1355 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1357 // TransitionData only takes string keys
1359 map["target"] = "testVisual";
1360 map["property"] = "pixelArea";
1361 map["initialValue"] = Vector4(0, 0, 0, 1);
1362 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1363 map["animator"] = Property::Map()
1364 .Add("alphaFunction", "LINEAR")
1365 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1367 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1369 Animation animation = dummyImpl.CreateTransition(transition);
1370 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1373 application.SendNotification();
1374 application.Render(0); // Ensure animation starts
1375 application.Render(2000u); // Halfway point
1377 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1379 application.Render(2000u); // End of animation
1381 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1386 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1388 ToolkitTestApplication application;
1389 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1391 Property::Map propertyMap;
1392 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1393 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1395 TestGlAbstraction& gl = application.GetGlAbstraction();
1396 TraceCallStack& textureTrace = gl.GetTextureTrace();
1397 textureTrace.Enable(true);
1398 TraceCallStack& drawTrace = gl.GetDrawTrace();
1399 drawTrace.Enable(true);
1401 Actor actor = CreateActorWithImageVisual(propertyMap);
1402 application.GetScene().Add(actor);
1403 application.SendNotification();
1405 application.GetScene().Remove(actor);
1406 application.SendNotification();
1408 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1409 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1410 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1411 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1416 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1418 ToolkitTestApplication application;
1419 tet_infoline("Load image asynchronously, cancel loading, then load again");
1421 VisualFactory factory = VisualFactory::Get();
1422 DALI_TEST_CHECK(factory);
1424 Property::Map propertyMap;
1425 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1426 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1428 Visual::Base visual = factory.CreateVisual(propertyMap);
1429 DALI_TEST_CHECK(visual);
1431 TestGlAbstraction& gl = application.GetGlAbstraction();
1432 TraceCallStack& textureTrace = gl.GetTextureTrace();
1433 textureTrace.Enable(true);
1434 TraceCallStack& drawTrace = gl.GetDrawTrace();
1435 drawTrace.Enable(true);
1437 DummyControl actor = DummyControl::New();
1438 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1439 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1441 application.GetScene().Add(actor);
1444 application.GetScene().Remove(actor);
1446 application.GetScene().Add(actor);
1448 // Create another visual with the same image
1449 visual = factory.CreateVisual(propertyMap);
1450 DALI_TEST_CHECK(visual);
1452 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1454 application.SendNotification();
1455 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1457 application.SendNotification();
1458 application.Render();
1460 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1461 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1462 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1463 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1468 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1470 ToolkitTestApplication application;
1471 tet_infoline("Request image visual with invalid images - should draw broken.png");
1473 VisualFactory factory = VisualFactory::Get();
1474 DALI_TEST_CHECK(factory);
1476 Property::Map propertyMap;
1477 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1478 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1480 Visual::Base visual = factory.CreateVisual(propertyMap);
1481 DALI_TEST_CHECK(visual);
1483 TestGlAbstraction& gl = application.GetGlAbstraction();
1484 TraceCallStack& textureTrace = gl.GetTextureTrace();
1485 textureTrace.Enable(true);
1487 DummyControl actor = DummyControl::New();
1488 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1489 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1491 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1492 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1494 application.GetScene().Add(actor);
1496 application.SendNotification();
1497 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1499 application.SendNotification();
1500 application.Render();
1502 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1503 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1505 application.GetScene().Remove(actor);
1506 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1511 int UtcDaliImageVisualSetInvalidSyncImage(void)
1513 ToolkitTestApplication application;
1514 tet_infoline("Request image visual with invalid images - should draw broken.png");
1516 VisualFactory factory = VisualFactory::Get();
1517 DALI_TEST_CHECK(factory);
1519 Property::Map propertyMap;
1520 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1521 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1522 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1524 Visual::Base visual = factory.CreateVisual(propertyMap);
1525 DALI_TEST_CHECK(visual);
1527 TestGlAbstraction& gl = application.GetGlAbstraction();
1528 TraceCallStack& textureTrace = gl.GetTextureTrace();
1529 textureTrace.Enable(true);
1531 DummyControl actor = DummyControl::New();
1532 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1533 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1535 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1536 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1538 application.GetScene().Add(actor);
1540 application.SendNotification();
1541 application.Render();
1543 // Check resource status
1544 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1545 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1547 // The broken image should be shown.
1548 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1549 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1551 application.GetScene().Remove(actor);
1552 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1557 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1559 ToolkitTestApplication application;
1560 tet_infoline("Request image visual with invalid images - should draw broken.png");
1562 VisualFactory factory = VisualFactory::Get();
1563 DALI_TEST_CHECK(factory);
1565 // Local invalid file, asynchronous loading
1566 Property::Map propertyMap;
1567 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1568 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1570 Visual::Base visual = factory.CreateVisual(propertyMap);
1571 DALI_TEST_CHECK(visual);
1573 TestGlAbstraction& gl = application.GetGlAbstraction();
1574 TraceCallStack& textureTrace = gl.GetTextureTrace();
1575 textureTrace.Enable(true);
1577 DummyControl actor = DummyControl::New();
1578 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1579 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1581 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1582 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1584 application.GetScene().Add(actor);
1586 application.SendNotification();
1587 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1589 application.SendNotification();
1590 application.Render();
1592 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1593 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1595 application.GetScene().Remove(actor);
1596 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1601 int UtcDaliImageVisualAlphaMask01(void)
1603 ToolkitTestApplication application;
1604 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1606 VisualFactory factory = VisualFactory::Get();
1607 DALI_TEST_CHECK(factory);
1609 Property::Map propertyMap;
1610 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1611 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1612 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1614 Visual::Base visual = factory.CreateVisual(propertyMap);
1615 DALI_TEST_CHECK(visual);
1617 Property::Map testMap;
1618 visual.CreatePropertyMap(testMap);
1619 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1621 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1622 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1624 TestGlAbstraction& gl = application.GetGlAbstraction();
1625 TraceCallStack& textureTrace = gl.GetTextureTrace();
1626 textureTrace.Enable(true);
1628 DummyControl actor = DummyControl::New();
1629 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1630 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1632 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1633 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1634 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1636 application.GetScene().Add(actor);
1637 application.SendNotification();
1638 application.Render();
1640 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1642 application.SendNotification();
1643 application.Render();
1645 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1646 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1647 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1649 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1650 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1655 int UtcDaliImageVisualAlphaMask02(void)
1657 ToolkitTestApplication application;
1658 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1660 VisualFactory factory = VisualFactory::Get();
1661 DALI_TEST_CHECK(factory);
1663 Property::Map propertyMap;
1664 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1665 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1666 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1667 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1669 Visual::Base visual = factory.CreateVisual(propertyMap);
1670 DALI_TEST_CHECK(visual);
1672 Property::Map testMap;
1673 visual.CreatePropertyMap(testMap);
1674 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1675 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1677 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1678 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1680 TestGlAbstraction& gl = application.GetGlAbstraction();
1681 TraceCallStack& textureTrace = gl.GetTextureTrace();
1682 textureTrace.Enable(true);
1684 DummyControl actor = DummyControl::New();
1685 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1686 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1688 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1689 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1690 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1692 application.GetScene().Add(actor);
1693 application.SendNotification();
1694 application.Render();
1696 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1698 application.SendNotification();
1699 application.Render();
1701 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1702 Renderer renderer = actor.GetRendererAt(0u);
1703 TextureSet textures = renderer.GetTextures();
1704 DALI_TEST_CHECK(textures);
1705 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1707 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1708 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1710 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1711 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1716 int UtcDaliImageVisualAlphaMask03(void)
1718 ToolkitTestApplication application;
1719 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1721 VisualFactory factory = VisualFactory::Get();
1722 DALI_TEST_CHECK(factory);
1724 Property::Map propertyMap;
1725 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1726 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1727 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1728 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1730 Visual::Base visual = factory.CreateVisual(propertyMap);
1731 DALI_TEST_CHECK(visual);
1733 Property::Map testMap;
1734 visual.CreatePropertyMap(testMap);
1736 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1737 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1739 TestGlAbstraction& gl = application.GetGlAbstraction();
1740 TraceCallStack& textureTrace = gl.GetTextureTrace();
1741 textureTrace.Enable(true);
1743 DummyControl actor = DummyControl::New();
1744 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1745 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1747 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1748 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1749 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1751 application.GetScene().Add(actor);
1752 application.SendNotification();
1753 application.Render();
1755 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1757 application.SendNotification();
1758 application.Render();
1760 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1761 Renderer renderer = actor.GetRendererAt(0u);
1762 TextureSet textures = renderer.GetTextures();
1763 DALI_TEST_CHECK(textures);
1764 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
1766 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1767 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1769 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1770 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1775 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
1777 ToolkitTestApplication application;
1778 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
1780 VisualFactory factory = VisualFactory::Get();
1781 DALI_TEST_CHECK(factory);
1783 Property::Map propertyMap;
1784 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1785 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1786 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1787 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1789 Visual::Base visual = factory.CreateVisual(propertyMap);
1790 DALI_TEST_CHECK(visual);
1792 Property::Map testMap;
1793 visual.CreatePropertyMap(testMap);
1794 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1796 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1797 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1799 TestGlAbstraction& gl = application.GetGlAbstraction();
1800 TraceCallStack& textureTrace = gl.GetTextureTrace();
1801 textureTrace.Enable(true);
1803 DummyControl actor = DummyControl::New();
1804 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1805 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1807 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1808 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1809 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1811 application.GetScene().Add(actor);
1813 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1815 application.SendNotification();
1816 application.Render();
1818 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1819 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1820 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1822 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1823 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1828 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
1830 ToolkitTestApplication application;
1831 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
1833 VisualFactory factory = VisualFactory::Get();
1834 DALI_TEST_CHECK(factory);
1836 Property::Map propertyMap;
1837 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1838 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1839 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1840 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1841 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1843 Visual::Base visual = factory.CreateVisual(propertyMap);
1844 DALI_TEST_CHECK(visual);
1846 Property::Map testMap;
1847 visual.CreatePropertyMap(testMap);
1848 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1850 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1851 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1853 TestGlAbstraction& gl = application.GetGlAbstraction();
1854 TraceCallStack& textureTrace = gl.GetTextureTrace();
1855 textureTrace.Enable(true);
1857 DummyControl actor = DummyControl::New();
1858 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1859 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1861 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1862 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1863 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1865 application.GetScene().Add(actor);
1867 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1869 application.SendNotification();
1870 application.Render();
1872 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1873 Renderer renderer = actor.GetRendererAt(0u);
1874 TextureSet textures = renderer.GetTextures();
1875 DALI_TEST_CHECK(textures);
1876 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1878 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1879 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1881 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1882 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1887 int UtcDaliImageVisualRemoteAlphaMask(void)
1889 ToolkitTestApplication application;
1890 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1892 VisualFactory factory = VisualFactory::Get();
1893 DALI_TEST_CHECK(factory);
1895 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1897 Property::Map propertyMap;
1898 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1899 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1900 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1902 Visual::Base visual = factory.CreateVisual(propertyMap);
1903 DALI_TEST_CHECK(visual);
1905 Property::Map testMap;
1906 visual.CreatePropertyMap(testMap);
1908 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1910 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1911 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1913 TestGlAbstraction& gl = application.GetGlAbstraction();
1914 TraceCallStack& textureTrace = gl.GetTextureTrace();
1915 textureTrace.Enable(true);
1917 DummyControl actor = DummyControl::New();
1918 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1919 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1921 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1923 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1924 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1926 application.GetScene().Add(actor);
1927 application.SendNotification();
1928 application.Render();
1930 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1932 application.SendNotification();
1933 application.Render();
1935 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1936 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1937 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1942 int UtcDaliImageVisualAlphaMaskCrop(void)
1944 ToolkitTestApplication application;
1945 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1947 VisualFactory factory = VisualFactory::Get();
1948 DALI_TEST_CHECK(factory);
1950 Property::Map propertyMap;
1951 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1952 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1953 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1954 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1955 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1957 Visual::Base visual = factory.CreateVisual(propertyMap);
1958 DALI_TEST_CHECK(visual);
1960 Property::Map testMap;
1961 visual.CreatePropertyMap(testMap);
1962 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1963 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1964 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1966 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1967 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1969 TestGlAbstraction& gl = application.GetGlAbstraction();
1970 TraceCallStack& textureTrace = gl.GetTextureTrace();
1971 textureTrace.Enable(true);
1973 DummyControl actor = DummyControl::New();
1974 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1975 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1977 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1978 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1979 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1981 application.GetScene().Add(actor);
1982 application.SendNotification();
1983 application.Render();
1985 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1987 application.SendNotification();
1988 application.Render();
1991 visual.GetNaturalSize(size);
1993 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1994 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1995 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1996 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2001 int UtcDaliImageVisualReleasePolicy01(void)
2003 ToolkitTestApplication application;
2004 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2006 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2007 DALI_TEST_CHECK(imageVisual);
2009 // Set up debug trace
2010 TestGlAbstraction& gl = application.GetGlAbstraction();
2011 TraceCallStack& textureTrace = gl.GetTextureTrace();
2012 textureTrace.Enable(true);
2014 tet_infoline("Register visual with control and ensure it has the only handle");
2015 DummyControl actor = DummyControl::New(true);
2016 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2017 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2018 imageVisual.Reset();
2020 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2022 application.SendNotification();
2023 application.Render(0);
2024 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2025 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2027 application.GetScene().Add(actor);
2029 // Wait for image to load
2030 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2032 application.SendNotification();
2033 application.Render(0);
2034 // Test renderer and texture created
2035 tet_infoline("Confirm texture created");
2036 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2037 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2039 tet_infoline("Disable visual causing the texture to be deleted");
2040 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2042 application.SendNotification();
2043 application.Render(0);
2044 // Test renderer and textures removed.
2045 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2046 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2051 int UtcDaliImageVisualReleasePolicy02(void)
2053 ToolkitTestApplication application;
2054 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2056 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2057 DALI_TEST_CHECK(imageVisual);
2059 // Setup debug trace
2060 TestGlAbstraction& gl = application.GetGlAbstraction();
2061 TraceCallStack& textureTrace = gl.GetTextureTrace();
2062 textureTrace.Enable(true);
2064 tet_infoline("Register visual with control and ensure it has the only handle");
2065 DummyControl actor = DummyControl::New(true);
2066 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2067 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2068 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2070 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2072 application.SendNotification();
2073 application.Render(0);
2074 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2075 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2077 application.GetScene().Add(actor);
2079 // Wait for image to load
2080 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2082 application.SendNotification();
2083 application.Render(0);
2084 // Test renderer and texture created
2085 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2086 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2088 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2089 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2090 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2091 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2092 application.SendNotification();
2093 application.Render();
2095 // Test texture removed after visual destroyed.
2096 tet_infoline("Ensure texture is deleted after visual destroyed");
2097 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2102 int UtcDaliImageVisualReleasePolicy03(void)
2104 ToolkitTestApplication application;
2105 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2107 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2108 DALI_TEST_CHECK(imageVisual);
2110 TestGlAbstraction& gl = application.GetGlAbstraction();
2111 TraceCallStack& textureTrace = gl.GetTextureTrace();
2112 textureTrace.Enable(true);
2114 tet_infoline("Register visual with control and ensure it has the only handle");
2115 DummyControl actor = DummyControl::New(true);
2116 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2117 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2118 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2120 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2122 application.SendNotification();
2123 application.Render(0);
2124 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2125 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2127 application.GetScene().Add(actor);
2129 // Wait for image to load
2130 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2132 application.SendNotification();
2133 application.Render(0);
2134 // Test renderer and texture created
2135 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2136 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2138 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2139 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2140 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2141 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2142 application.SendNotification();
2143 application.Render();
2145 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2146 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2151 int UtcDaliImageVisualReleasePolicy04(void)
2153 ToolkitTestApplication application;
2154 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2156 tet_infoline("Create first visual with Never release policy");
2157 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2159 tet_infoline("Create second visual with Destroyed release policy");
2160 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2162 // Set up trace debug
2163 TestGlAbstraction& gl = application.GetGlAbstraction();
2164 TraceCallStack& textureTrace = gl.GetTextureTrace();
2165 textureTrace.Enable(true);
2167 tet_infoline("Register visuals with control and ensure it has the only handles");
2168 DummyControl actor = DummyControl::New(true);
2169 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2170 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2171 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2172 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2173 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2175 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2177 // Test initially zero renderers
2178 application.SendNotification();
2179 application.Render(0);
2180 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2181 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2183 application.GetScene().Add(actor);
2185 // Wait for image to load
2186 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2188 application.SendNotification();
2189 application.Render(0);
2190 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2191 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2192 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2194 // Test renderer removed when visual destroyed
2195 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2196 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2197 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2198 application.SendNotification();
2199 application.Render();
2201 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2202 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2204 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2205 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2206 application.SendNotification();
2207 application.Render();
2209 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2210 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2211 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2216 int UtcDaliImageVisualReleasePolicy05(void)
2218 ToolkitTestApplication application;
2219 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2221 VisualFactory factory = VisualFactory::Get();
2223 Property::Map propertyMapNeverReleasePolicy;
2224 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2225 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2226 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2227 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2228 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2230 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2232 Property::Map resultMap;
2233 imageVisualNever.CreatePropertyMap(resultMap);
2234 DALI_TEST_CHECK(!resultMap.Empty());
2236 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2241 int UtcDaliImageVisualReleasePolicy06(void)
2243 ToolkitTestApplication application;
2244 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2246 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2247 DALI_TEST_CHECK(imageVisual);
2249 TestGlAbstraction& gl = application.GetGlAbstraction();
2250 TraceCallStack& textureTrace = gl.GetTextureTrace();
2251 textureTrace.Enable(true);
2253 tet_infoline("Register visual with control and ensure it has the only handle");
2254 DummyControl actor = DummyControl::New(true);
2255 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2256 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2257 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2259 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2261 application.SendNotification();
2262 application.Render(0);
2263 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2264 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2266 application.GetScene().Add(actor);
2268 // Wait for image to load
2269 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2271 application.SendNotification();
2272 application.Render(0);
2273 // Test renderer and texture created
2274 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2275 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2276 textureTrace.Reset();
2278 tet_infoline("Disable Visual and check texture not affected");
2279 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2280 application.SendNotification();
2281 application.Render(0);
2282 tet_infoline("Check renderer is destroyed when visual off stage");
2283 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2284 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2285 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2286 textureTrace.Reset();
2288 tet_infoline("Re-enable Visual and check texture not affected");
2289 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2290 application.SendNotification();
2291 application.Render(0);
2292 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2293 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2294 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2295 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2300 int UtcDaliImageVisualReleasePolicy07(void)
2302 ToolkitTestApplication application;
2303 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2305 tet_infoline("Create first visual with DESTROYED release policy");
2306 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2308 tet_infoline("Create second visual with DETACHED release policy");
2309 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2311 // Set up trace debug
2312 TestGlAbstraction& gl = application.GetGlAbstraction();
2313 TraceCallStack& textureTrace = gl.GetTextureTrace();
2314 textureTrace.Enable(true);
2316 tet_infoline("Register visuals with control and ensure it has the only handles");
2317 DummyControl actor = DummyControl::New(true);
2318 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2319 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2320 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2321 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2322 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2324 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2326 // Test initially zero renderers
2327 application.SendNotification();
2328 application.Render(0);
2329 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2330 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2332 application.GetScene().Add(actor);
2334 // Wait for image to load
2335 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2337 application.SendNotification();
2338 application.Render(0);
2339 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2340 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2341 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2343 // Test renderer removed when visual destroyed
2344 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2345 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2346 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2347 application.SendNotification();
2348 application.Render();
2350 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2351 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2353 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2354 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2355 application.SendNotification();
2356 application.Render();
2358 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2359 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2364 int UtcDaliImageVisualReleasePolicy08(void)
2366 ToolkitTestApplication application;
2367 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2369 tet_infoline("Create first visual with DESTROYED release policy");
2370 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2372 // Set up trace debug
2373 TestGlAbstraction& gl = application.GetGlAbstraction();
2374 TraceCallStack& textureTrace = gl.GetTextureTrace();
2375 textureTrace.Enable(true);
2377 tet_infoline("Register visuals with control and ensure it has the only handles");
2378 DummyControl actor = DummyControl::New(true);
2379 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2380 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2381 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2383 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2385 // Test initially zero renderers
2386 application.SendNotification();
2387 application.Render(0);
2388 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2389 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2390 textureTrace.Reset();
2392 application.GetScene().Add(actor);
2394 // Wait for image to load
2395 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2397 application.SendNotification();
2398 application.Render(0);
2399 tet_infoline("Ensure a texture is created");
2400 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2401 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2402 textureTrace.Reset();
2404 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2405 // 1. Get TextureSet
2406 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2408 // 2.Remove actor from stage. In this case, renderer also is deleted.
2409 tet_infoline("Remove actor from stage");
2410 application.GetScene().Remove(actor);
2411 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2412 application.SendNotification();
2413 application.Render();
2415 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2416 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2417 textureTrace.Reset();
2419 // 3.Add actor in stage. In this case, renderer is created.
2420 tet_infoline("Add actor in stage");
2421 application.GetScene().Add(actor);
2422 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2423 application.SendNotification();
2424 application.Render();
2425 tet_infoline("Ensure a texture is not created again");
2426 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2427 textureTrace.Reset();
2429 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2430 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2431 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2432 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2433 textureSetBefore.Reset();
2434 textureSetAfter.Reset();
2436 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2437 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2438 application.SendNotification();
2439 application.Render();
2440 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2445 int UtcDaliImageVisualReleasePolicy09(void)
2447 ToolkitTestApplication application;
2448 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2450 Property::Map propertyMapNPatchReleasePolicy;
2451 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2452 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2453 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2454 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2455 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2457 VisualFactory factory = VisualFactory::Get();
2458 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2459 DALI_TEST_CHECK(imageVisual);
2461 // Setup debug trace
2462 TestGlAbstraction& gl = application.GetGlAbstraction();
2463 TraceCallStack& textureTrace = gl.GetTextureTrace();
2464 textureTrace.Enable(true);
2466 tet_infoline("Register visual with control and ensure it has the only handle");
2467 DummyControl actor = DummyControl::New(true);
2468 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2469 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2470 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2472 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2474 application.SendNotification();
2475 application.Render(0);
2476 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2477 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2479 application.GetScene().Add(actor);
2481 // Wait for image to load
2482 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2484 application.SendNotification();
2485 application.Render(0);
2486 // Test renderer and texture created
2487 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2488 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2490 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2491 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2492 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2493 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2494 application.SendNotification();
2495 application.Render();
2497 // Test texture removed after visual destroyed.
2498 tet_infoline("Ensure texture is deleted after visual destroyed");
2499 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2504 int UtcDaliImageVisualLoadPolicy01(void)
2506 ToolkitTestApplication application;
2507 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2509 // Set up trace debug
2510 TestGlAbstraction& gl = application.GetGlAbstraction();
2511 TraceCallStack& textureTrace = gl.GetTextureTrace();
2512 textureTrace.Enable(true);
2514 tet_infoline("Create visual with IMMEDIATE load policy");
2515 VisualFactory factory = VisualFactory::Get();
2517 Property::Map propertyMap;
2518 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2519 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2520 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2521 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2522 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2524 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2526 Property::Map resultMap;
2527 imageVisual.CreatePropertyMap(resultMap);
2528 DALI_TEST_CHECK(!resultMap.Empty());
2529 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2531 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2533 // Ensure texture has been uploaded
2534 application.SendNotification();
2535 application.Render();
2537 tet_infoline("Ensure texture loading starts after visual created");
2538 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2539 textureTrace.Reset();
2541 tet_infoline("Register visuals with control and ensure it has the only handles");
2542 DummyControl actor = DummyControl::New(true);
2543 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2544 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2545 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2547 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2548 application.GetScene().Add(actor);
2549 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2550 const unsigned int TIME_OUT_3_SECONDS = 3;
2551 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2553 application.SendNotification();
2554 application.Render();
2556 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2557 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2559 // Ensure texture is deleted when no longer needed (ref count was correct )
2560 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2562 application.SendNotification();
2563 application.Render();
2565 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2566 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2571 int UtcDaliImageVisualLoadPolicy02(void)
2573 ToolkitTestApplication application;
2574 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2576 // Set up trace debug
2577 TestGlAbstraction& gl = application.GetGlAbstraction();
2578 TraceCallStack& textureTrace = gl.GetTextureTrace();
2579 textureTrace.Enable(true);
2581 tet_infoline("Create visual with IMMEDIATE load policy");
2582 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2584 const unsigned int TIME_OUT_3_SECONDS = 3;
2585 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2587 // Act on meeage queue even although nothing expected to load
2588 application.SendNotification();
2589 application.Render();
2591 tet_infoline("Ensure texture is not generated yet");
2592 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2593 textureTrace.Reset();
2595 tet_infoline("Register visuals with control and ensure it has the only handles");
2596 DummyControl actor = DummyControl::New(true);
2597 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2598 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2599 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2601 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2602 application.GetScene().Add(actor);
2603 tet_infoline("Allow image time to load");
2604 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2606 application.SendNotification();
2607 application.Render();
2609 tet_infoline("Ensure texture generated and renderer created");
2610 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2611 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2613 // Ensure texture is delete when no longer needed
2614 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2616 application.SendNotification();
2617 application.Render();
2619 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2620 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2625 int UtcDaliImageVisualLoadPolicy03(void)
2627 ToolkitTestApplication application;
2628 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2630 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2632 // Set up trace debug
2633 TestGlAbstraction& gl = application.GetGlAbstraction();
2634 TraceCallStack& textureTrace = gl.GetTextureTrace();
2635 textureTrace.Enable(true);
2637 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2638 DummyControl actor = DummyControl::New(true);
2639 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2640 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2641 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2643 tet_infoline("Create visual with IMMEDIATE load policy");
2644 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2646 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2647 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2648 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2650 tet_infoline("Allow image time to load resource");
2651 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2652 application.SendNotification();
2653 application.Render();
2655 // Ensure texture has been uploaded
2656 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2657 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2662 int UtcDaliImageVisualLoadPolicy04(void)
2664 ToolkitTestApplication application;
2665 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2666 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2668 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2670 // Set up trace debug
2671 TestGlAbstraction& gl = application.GetGlAbstraction();
2672 TraceCallStack& textureTrace = gl.GetTextureTrace();
2673 textureTrace.Enable(true);
2675 tet_infoline("Create a control and connect to resource ready signal");
2676 DummyControl actor = DummyControl::New(true);
2677 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2678 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2679 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2681 tet_infoline("Create visual with IMMEDIATE load policy");
2682 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2684 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2685 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2686 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2688 tet_infoline("Allow image time to load");
2689 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2690 application.SendNotification();
2691 application.Render();
2693 tet_infoline("Testing texture is loaded and resource ready signal fired");
2694 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2695 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2697 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2699 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2700 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2701 DummyControl actor2 = DummyControl::New(true);
2702 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2703 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2705 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2706 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2707 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2708 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2709 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2710 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2715 int UtcDaliImageVisualLoadPolicy05(void)
2717 ToolkitTestApplication application;
2718 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2719 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2720 // Set up trace debug
2721 TestGlAbstraction& gl = application.GetGlAbstraction();
2722 TraceCallStack& textureTrace = gl.GetTextureTrace();
2723 textureTrace.Enable(true);
2725 tet_infoline("Create a control and connect to resource ready signal");
2726 DummyControl actor = DummyControl::New(true);
2727 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2728 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2729 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2730 application.GetScene().Add(actor);
2732 tet_infoline("Create visual with ATTACHED load policy");
2733 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2735 tet_infoline("Registering visual allows control to get a signal once loaded");
2736 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2737 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2739 tet_infoline("Allow image time to load");
2740 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2741 application.SendNotification();
2742 application.Render();
2744 tet_infoline("Testing texture is loaded and resource ready signal fired");
2745 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2746 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2748 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2750 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2751 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2752 DummyControl actor2 = DummyControl::New(true);
2753 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2754 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2756 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2757 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2758 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2759 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2760 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2761 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2766 int UtcDaliImageVisualOrientationCorrection(void)
2768 ToolkitTestApplication application;
2769 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2771 VisualFactory factory = VisualFactory::Get();
2772 tet_infoline("Create visual with Orientation correction set OFF");
2773 Property::Map propertyMap;
2774 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2775 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2776 propertyMap.Insert("orientationCorrection", false);
2777 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2779 tet_infoline("Create control for visual, need to loaded it");
2780 DummyControl actor = DummyControl::New(true);
2781 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2782 application.GetScene().Add(actor);
2784 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2785 // Wait for image to load
2786 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2788 Vector2 originalImageSize;
2789 tet_infoline("Get size of original visual to compare later with rotated image");
2790 imageVisual.GetNaturalSize(originalImageSize);
2791 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2792 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2793 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2794 application.SendNotification();
2795 application.Render();
2797 tet_infoline("Create visual with Orientation correction set ON ");
2798 propertyMap.Clear();
2799 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2800 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2801 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2802 imageVisual = factory.CreateVisual(propertyMap);
2804 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2805 // Wait for image to load
2806 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2808 Vector2 rotatedImageSize;
2809 imageVisual.GetNaturalSize(rotatedImageSize);
2810 tet_infoline("Confirm that visual has rotated");
2811 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2812 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2814 Property::Map resultMap;
2815 imageVisual.CreatePropertyMap(resultMap);
2817 // check the Property::ORIENTATION_CORRECTION value from the returned map
2818 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2819 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2824 int UtcDaliImageVisualCustomShader(void)
2826 ToolkitTestApplication application;
2827 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2829 VisualFactory factory = VisualFactory::Get();
2830 Property::Map properties;
2831 Property::Map shader;
2832 const std::string vertexShader = "Foobar";
2833 const std::string fragmentShader = "Foobar";
2834 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2835 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2837 properties[Visual::Property::TYPE] = Visual::IMAGE;
2838 properties[Visual::Property::SHADER] = shader;
2839 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2841 Visual::Base visual = factory.CreateVisual(properties);
2843 // trigger creation through setting on stage
2844 DummyControl dummy = DummyControl::New(true);
2845 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2846 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2848 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2849 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2850 application.GetScene().Add(dummy);
2852 application.SendNotification();
2853 application.Render();
2855 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2857 Renderer renderer = dummy.GetRendererAt(0);
2858 Shader shader2 = renderer.GetShader();
2859 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2860 Property::Map* map = value.GetMap();
2861 DALI_TEST_CHECK(map);
2863 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2864 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2866 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2867 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2871 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2872 properties[Visual::Property::SHADER] = shader;
2874 Visual::Base visual1 = factory.CreateVisual(properties);
2876 // trigger creation through setting on stage
2877 DummyControl dummy1 = DummyControl::New(true);
2878 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2879 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2880 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2881 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2882 application.GetScene().Add(dummy1);
2884 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2885 glAbstraction.EnableEnableDisableCallTrace(true);
2887 application.SendNotification();
2888 application.Render();
2890 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2891 std::ostringstream blendStr;
2892 blendStr << std::hex << GL_BLEND;
2893 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2898 void ResourceReadyLoadNext(Control control)
2900 static int callNumber = 0;
2902 gResourceReadySignalFired = true;
2903 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2907 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2909 tet_infoline("Create visual with loaded image from within the signal handler");
2910 VisualFactory factory = VisualFactory::Get();
2911 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2913 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2914 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2919 tet_infoline("3rd signal called");
2920 DALI_TEST_CHECK(true);
2924 int UtcDaliImageVisualLoadReady01(void)
2926 ToolkitTestApplication application;
2927 tet_infoline("UtcDaliImageVisualLoadReady01");
2928 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2929 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2930 tet_infoline("Should get a ready signal for all three visuals");
2934 tet_infoline("Create a control and connect to resource ready signal");
2935 DummyControl actor = DummyControl::New(true);
2936 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2937 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2938 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2939 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2940 application.GetScene().Add(actor);
2942 tet_infoline("Create visual with IMMEDIATE load policy");
2943 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2945 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2946 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2948 tet_infoline("Allow image time to load");
2949 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2950 application.SendNotification();
2951 application.Render();
2953 tet_infoline("Testing texture is loaded and resource ready signal fired");
2954 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2955 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2957 tet_infoline("Original control correctly signalled, now testing failing image");
2959 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2962 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2964 DummyControl actor2 = DummyControl::New(true);
2965 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2966 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2967 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2969 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2970 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2972 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2973 application.GetScene().Add(actor2);
2975 tet_infoline("Wait for loading thread to finish");
2976 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2977 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2979 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2981 tet_infoline("Check for 3rd signal");
2982 application.SendNotification();
2983 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2984 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
2989 int UtcDaliImageVisualLoadImagePlanes01(void)
2991 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
2993 ToolkitTestApplication application;
2995 VisualFactory factory = VisualFactory::Get();
2996 DALI_TEST_CHECK(factory);
2998 Property::Map propertyMap;
2999 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3000 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3002 Visual::Base visual = factory.CreateVisual(propertyMap);
3003 DALI_TEST_CHECK(visual);
3005 DummyControl actor = DummyControl::New();
3006 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3007 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3008 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3009 application.GetScene().Add(actor);
3011 application.SendNotification();
3012 application.Render();
3014 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3016 TestGlAbstraction& gl = application.GetGlAbstraction();
3017 TraceCallStack& textureTrace = gl.GetTextureTrace();
3018 textureTrace.Enable(true);
3020 application.SendNotification();
3021 application.Render();
3023 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3024 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3025 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3027 Renderer renderer = actor.GetRendererAt(0);
3028 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3029 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3034 int UtcDaliImageVisualLoadImagePlanes02(void)
3036 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3038 ToolkitTestApplication application;
3040 VisualFactory factory = VisualFactory::Get();
3041 DALI_TEST_CHECK(factory);
3043 // Alpha masking case - not support yuv planes
3044 Property::Map propertyMap;
3045 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3046 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3047 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3049 Visual::Base visual = factory.CreateVisual(propertyMap);
3050 DALI_TEST_CHECK(visual);
3052 DummyControl actor = DummyControl::New();
3053 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3054 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3055 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3056 application.GetScene().Add(actor);
3058 application.SendNotification();
3059 application.Render();
3061 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3063 TestGlAbstraction& gl = application.GetGlAbstraction();
3064 TraceCallStack& textureTrace = gl.GetTextureTrace();
3065 textureTrace.Enable(true);
3067 application.SendNotification();
3068 application.Render();
3070 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3071 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3072 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3077 int UtcDaliImageVisualLoadImagePlanes03(void)
3079 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3081 ToolkitTestApplication application;
3083 VisualFactory factory = VisualFactory::Get();
3084 DALI_TEST_CHECK(factory);
3086 TestGlAbstraction& gl = application.GetGlAbstraction();
3087 TraceCallStack& textureTrace = gl.GetTextureTrace();
3088 textureTrace.Enable(true);
3090 Property::Map propertyMap;
3091 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3092 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3093 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3095 Visual::Base visual = factory.CreateVisual(propertyMap);
3096 DALI_TEST_CHECK(visual);
3098 DummyControl actor = DummyControl::New();
3099 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3100 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3101 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3102 application.GetScene().Add(actor);
3104 application.SendNotification();
3105 application.Render();
3107 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3108 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3109 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);