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-event-thread-callback.h>
24 #include <toolkit-timer.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
29 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
32 #include <dali-toolkit/public-api/image-loader/image-url.h>
33 #include <dali-toolkit/public-api/image-loader/image.h>
35 #include "dummy-control.h"
36 #include "test-encoded-image-buffer.h"
37 #include "test-native-image-source.h"
40 using namespace Dali::Toolkit;
42 void dali_image_visual_startup(void)
44 test_return_value = TET_UNDEF;
47 void dali_image_visual_cleanup(void)
49 test_return_value = TET_PASS;
54 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
55 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
56 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
57 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
58 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
59 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
60 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
61 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
62 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 bool gResourceReadySignalFired = false;
65 std::vector<int> gReadyIds = {};
66 void ResourceReadySignal(Control control)
68 gResourceReadySignalFired = true;
69 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
76 Actor CreateActorWithImageVisual(const Property::Map& map)
78 VisualFactory factory = VisualFactory::Get();
79 DummyControl actor = DummyControl::New();
80 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
81 Visual::Base visual = factory.CreateVisual(map);
82 DALI_TEST_CHECK(visual);
83 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
84 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
85 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
89 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
91 VisualFactory factory = VisualFactory::Get();
93 Property::Map propertyMap;
94 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
95 propertyMap.Insert(ImageVisual::Property::URL, url);
96 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
97 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
98 propertyMap.Insert(key, value);
100 return factory.CreateVisual(propertyMap);
105 void TestVisualRender(ToolkitTestApplication& application,
107 Visual::Base& visual,
108 std::size_t expectedSamplers = 0,
109 ImageDimensions imageDimensions = ImageDimensions(),
110 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
112 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
113 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
117 // set the image size, for test case, this needs to be set before loading started
118 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
121 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
122 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
124 application.GetScene().Add(actor);
126 application.SendNotification(); // Send messages to update
127 application.Render(); // process update and render
128 application.SendNotification(); // process any signals to event
132 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
135 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
138 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
141 visual.CreatePropertyMap(map);
142 Property::Value* value = map.Find(mixColorIndex);
143 DALI_TEST_CHECK(value);
145 DALI_TEST_CHECK(value->Get(mixColor1));
146 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
148 value = map.Find(Visual::Property::MIX_COLOR);
149 DALI_TEST_CHECK(value);
151 DALI_TEST_CHECK(value->Get(mixColor2));
152 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
154 value = map.Find(Visual::Property::OPACITY);
155 DALI_TEST_CHECK(value);
157 DALI_TEST_CHECK(value->Get(opacity));
158 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
161 int UtcDaliImageVisualPropertyMap(void)
163 ToolkitTestApplication application;
164 tet_infoline("Request image visual with a Property::Map");
166 VisualFactory factory = VisualFactory::Get();
167 DALI_TEST_CHECK(factory);
168 factory.SetPreMultiplyOnLoad(true);
170 Property::Map propertyMap;
171 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
172 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
174 Visual::Base visual = factory.CreateVisual(propertyMap);
175 DALI_TEST_CHECK(visual);
177 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
178 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
180 TestGlAbstraction& gl = application.GetGlAbstraction();
181 TraceCallStack& textureTrace = gl.GetTextureTrace();
182 textureTrace.Enable(true);
184 DummyControl actor = DummyControl::New();
185 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
186 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
188 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
189 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
191 application.GetScene().Add(actor);
192 application.SendNotification();
193 application.Render();
195 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
197 application.SendNotification();
198 application.Render();
200 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
201 auto renderer = actor.GetRendererAt(0);
202 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
203 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
204 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
205 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
206 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
207 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
208 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
210 application.GetScene().Remove(actor);
211 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
216 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
218 ToolkitTestApplication application;
219 tet_infoline("Request image visual without pre-multiplied alpha");
221 VisualFactory factory = VisualFactory::Get();
222 DALI_TEST_CHECK(factory);
223 factory.SetPreMultiplyOnLoad(false);
225 Property::Map propertyMap;
226 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
227 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
229 Visual::Base visual = factory.CreateVisual(propertyMap);
230 DALI_TEST_CHECK(visual);
232 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
233 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
235 TestGlAbstraction& gl = application.GetGlAbstraction();
236 TraceCallStack& textureTrace = gl.GetTextureTrace();
237 textureTrace.Enable(true);
239 DummyControl actor = DummyControl::New();
240 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
241 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
243 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
244 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
246 application.GetScene().Add(actor);
247 application.SendNotification();
248 application.Render();
250 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
252 application.SendNotification();
253 application.Render();
255 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
256 auto renderer = actor.GetRendererAt(0);
257 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
258 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
259 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
260 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
262 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
263 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
265 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
267 application.GetScene().Remove(actor);
268 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
273 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
275 ToolkitTestApplication application;
276 tet_infoline("Request image visual with no alpha channel");
278 VisualFactory factory = VisualFactory::Get();
279 DALI_TEST_CHECK(factory);
281 Property::Map propertyMap;
282 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
283 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
285 Visual::Base visual = factory.CreateVisual(propertyMap);
286 DALI_TEST_CHECK(visual);
288 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
289 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
291 TestGlAbstraction& gl = application.GetGlAbstraction();
292 TraceCallStack& textureTrace = gl.GetTextureTrace();
293 textureTrace.Enable(true);
295 DummyControl actor = DummyControl::New();
296 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
297 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
299 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
300 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
302 application.GetScene().Add(actor);
303 application.SendNotification();
304 application.Render();
306 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
308 application.SendNotification();
309 application.Render();
311 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
312 auto renderer = actor.GetRendererAt(0);
313 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
314 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
315 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
316 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
318 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
319 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
321 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
323 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
324 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
325 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
326 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
327 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
328 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
329 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
330 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
332 textureTrace.Reset();
334 // Make a new visual with the same image
335 Visual::Base newVisual = factory.CreateVisual(propertyMap);
336 DALI_TEST_CHECK(newVisual);
338 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
339 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
341 DummyControl newActor = DummyControl::New();
342 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
343 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
345 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
346 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
348 application.GetScene().Add(newActor);
350 application.SendNotification();
351 application.Render();
353 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
354 auto newRenderer = newActor.GetRendererAt(0);
355 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
356 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
357 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
358 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
360 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
361 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
363 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
364 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
365 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
366 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
367 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
368 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
369 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
370 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
372 application.GetScene().Remove(actor);
373 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
378 int UtcDaliImageVisualRemoteImageLoad(void)
380 ToolkitTestApplication application;
381 tet_infoline("Request remote image visual with a Property::Map");
383 VisualFactory factory = VisualFactory::Get();
384 DALI_TEST_CHECK(factory);
386 Property::Map propertyMap;
387 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
388 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
390 Visual::Base visual = factory.CreateVisual(propertyMap);
391 DALI_TEST_CHECK(visual);
393 TestGlAbstraction& gl = application.GetGlAbstraction();
394 TraceCallStack& textureTrace = gl.GetTextureTrace();
395 textureTrace.Enable(true);
397 DummyControl actor = DummyControl::New();
398 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
399 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
401 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
402 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
404 application.GetScene().Add(actor);
405 application.SendNotification();
407 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
409 application.SendNotification();
410 application.Render();
412 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
413 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
415 application.GetScene().Remove(actor);
416 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
421 int UtcDaliImageVisualWithNativeImage(void)
423 ToolkitTestApplication application;
424 tet_infoline("Use Native Image as url");
426 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
427 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
428 std::string url = imageUrl.GetUrl();
430 VisualFactory factory = VisualFactory::Get();
431 DALI_TEST_CHECK(factory);
433 Property::Map propertyMap;
434 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
435 propertyMap.Insert(ImageVisual::Property::URL, url);
437 Visual::Base visual = factory.CreateVisual(propertyMap);
438 DALI_TEST_CHECK(visual);
440 DummyControl actor = DummyControl::New();
441 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
442 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
444 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
446 application.GetScene().Add(actor);
448 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
450 Renderer renderer = actor.GetRendererAt(0);
451 Shader shader = renderer.GetShader();
453 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
454 DALI_TEST_CHECK(value.GetType() == Property::MAP);
455 const Property::Map* outMap = value.GetMap();
456 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
458 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
459 size_t pos = fragmentShader.find(fragmentPrefix);
461 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
466 int UtcDaliImageVisualWithNativeImageCustomShader(void)
468 ToolkitTestApplication application;
469 tet_infoline("Use Native Image as url and Use custom shader");
471 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
472 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
473 std::string url = imageUrl.GetUrl();
475 VisualFactory factory = VisualFactory::Get();
476 DALI_TEST_CHECK(factory);
478 Property::Map propertyMap;
479 Property::Map shaderMap;
480 const std::string customVertexShaderSource = "Foobar";
481 const std::string customFragmentShaderSource = "Foobar";
482 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
483 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
485 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
486 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
487 propertyMap.Insert(ImageVisual::Property::URL, url);
489 Visual::Base visual = factory.CreateVisual(propertyMap);
490 DALI_TEST_CHECK(visual);
492 DummyControl actor = DummyControl::New();
493 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
494 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
496 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
497 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
499 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
501 application.GetScene().Add(actor);
503 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
505 application.SendNotification();
506 application.Render(16);
508 Renderer renderer = actor.GetRendererAt(0);
509 Shader shader = renderer.GetShader();
511 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
512 DALI_TEST_CHECK(value.GetType() == Property::MAP);
513 const Property::Map* outMap = value.GetMap();
514 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
515 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
517 // Compare vertex shader is equal
518 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
520 // Check fragment shader changed
521 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
522 size_t pos = fragmentShaderSource.find(fragmentPrefix);
524 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
526 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
531 int UtcDaliImageVisualWithNativeImageRemoved(void)
533 ToolkitTestApplication application;
534 tet_infoline("Use Native Image as url");
536 TestGlAbstraction& gl = application.GetGlAbstraction();
537 TraceCallStack& textureTrace = gl.GetTextureTrace();
538 textureTrace.Enable(true);
540 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
541 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
542 std::string url = imageUrl.GetUrl();
544 VisualFactory factory = VisualFactory::Get();
545 DALI_TEST_CHECK(factory);
547 Property::Map propertyMap;
548 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
549 propertyMap.Insert(ImageVisual::Property::URL, url);
551 Visual::Base visual = factory.CreateVisual(propertyMap);
552 DALI_TEST_CHECK(visual);
554 DummyControl actor = DummyControl::New();
555 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
556 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
558 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
560 application.GetScene().Add(actor);
561 application.SendNotification();
562 application.Render();
564 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
565 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
567 tet_infoline("No delete texture because reference count is not zero");
569 application.GetScene().Remove(actor);
570 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
571 application.SendNotification();
572 application.Render();
574 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
575 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
577 tet_infoline("Delete texture because reference count is zero");
579 application.SendNotification();
580 application.Render();
582 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
587 int UtcDaliImageVisualWithEncodedImageBuffer(void)
589 ToolkitTestApplication application;
590 tet_infoline("Use Encoded Image Buffer as url");
592 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
593 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
595 VisualFactory factory = VisualFactory::Get();
596 DALI_TEST_CHECK(factory);
598 Property::Map propertyMap;
599 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
600 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
602 Visual::Base visual = factory.CreateVisual(propertyMap);
603 DALI_TEST_CHECK(visual);
605 TestGlAbstraction& gl = application.GetGlAbstraction();
606 TraceCallStack& textureTrace = gl.GetTextureTrace();
607 textureTrace.Enable(true);
609 DummyControl actor = DummyControl::New();
610 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
611 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
613 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
614 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
616 application.GetScene().Add(actor);
617 application.SendNotification();
619 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
621 application.SendNotification();
622 application.Render();
624 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
625 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
627 application.GetScene().Remove(actor);
628 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
633 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
635 ToolkitTestApplication application;
636 tet_infoline("Use Encoded Image Buffer as url");
638 TestGlAbstraction& gl = application.GetGlAbstraction();
639 TraceCallStack& textureTrace = gl.GetTextureTrace();
640 textureTrace.Enable(true);
642 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
643 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
644 std::string url = imageUrl.GetUrl();
646 VisualFactory factory = VisualFactory::Get();
647 DALI_TEST_CHECK(factory);
649 Property::Map propertyMap;
650 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
651 propertyMap.Insert(ImageVisual::Property::URL, url);
653 Visual::Base visual = factory.CreateVisual(propertyMap);
654 DALI_TEST_CHECK(visual);
656 DummyControl actor = DummyControl::New();
657 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
658 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
660 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
662 application.GetScene().Add(actor);
663 application.SendNotification();
665 // Wait for decode buffer and make texture.
666 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
668 application.SendNotification();
669 application.Render();
671 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
672 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
674 tet_infoline("Delete texture because there is no actor to use decoded texture");
676 application.GetScene().Remove(actor);
677 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
678 application.SendNotification();
679 application.Render();
681 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
682 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
687 int UtcDaliImageVisualTextureReuse1(void)
689 ToolkitTestApplication application;
690 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
692 Property::Map propertyMap;
693 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
694 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
695 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
697 TestGlAbstraction& gl = application.GetGlAbstraction();
698 TraceCallStack& textureTrace = gl.GetTextureTrace();
699 textureTrace.Enable(true);
700 TraceCallStack& drawTrace = gl.GetDrawTrace();
701 drawTrace.Enable(true);
703 Actor actor = CreateActorWithImageVisual(propertyMap);
704 application.GetScene().Add(actor);
705 application.SendNotification();
707 // Wait for image to load
708 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
710 application.SendNotification();
711 application.Render();
713 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
714 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
715 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
716 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
717 textureTrace.Reset();
720 Actor actor2 = CreateActorWithImageVisual(propertyMap);
721 application.GetScene().Add(actor2);
723 application.SendNotification(); // Send messages to update
724 application.Render(); // process update and render
725 application.SendNotification(); // process any signals to event
727 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
729 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
730 // backend here, but test graphics backend.
731 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
732 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
734 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
736 application.GetScene().Remove(actor);
737 application.SendNotification();
738 application.Render();
740 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
741 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
743 tet_infoline("Test that removing last actor does delete the texture\n");
745 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
746 application.SendNotification();
747 application.Render();
749 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
750 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
755 int UtcDaliImageVisualTextureReuse2(void)
757 ToolkitTestApplication application;
758 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");
760 Property::Map propertyMap;
761 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
762 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
764 TestGlAbstraction& gl = application.GetGlAbstraction();
765 TraceCallStack& textureTrace = gl.GetTextureTrace();
766 textureTrace.Enable(true);
767 TraceCallStack& drawTrace = gl.GetDrawTrace();
768 drawTrace.Enable(true);
770 Actor actor = CreateActorWithImageVisual(propertyMap);
771 application.GetScene().Add(actor);
772 application.SendNotification();
774 // Wait for image to load
775 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
777 application.SendNotification();
778 application.Render();
780 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
781 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
782 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
783 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
784 textureTrace.Reset();
787 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
788 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
789 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
790 Actor actor2 = CreateActorWithImageVisual(propertyMap);
791 application.GetScene().Add(actor2);
793 application.SendNotification();
795 // Wait for image to load
796 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
798 application.SendNotification();
799 application.Render();
801 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
804 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
805 "renderers are using different textures\n");
807 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
808 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
809 TraceCallStack::NamedParams tex1;
810 tex1["texture"] << 1;
811 TraceCallStack::NamedParams tex2;
812 tex2["texture"] << 2;
813 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
814 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
816 tet_infoline("Test that removing 1 actor deletes it's texture\n");
818 application.GetScene().Remove(actor);
819 application.SendNotification();
820 application.Render();
822 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
823 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
825 tet_infoline("Test that removing last actor deletes it's texture\n");
827 application.GetScene().Remove(actor2);
828 application.SendNotification();
829 application.Render();
831 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
832 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
837 int UtcDaliImageVisualCustomWrapModePixelArea(void)
839 ToolkitTestApplication application;
840 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
842 static std::vector<UniformData> customUniforms =
844 UniformData("pixelArea", Property::Type::VECTOR4),
845 UniformData("wrapMode", Property::Type::VECTOR2),
848 TestGraphicsController& graphics = application.GetGraphicsController();
849 graphics.AddCustomUniforms(customUniforms);
851 VisualFactory factory = VisualFactory::Get();
852 DALI_TEST_CHECK(factory);
854 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
855 const int width = 34;
856 const int height = 34;
857 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
859 Property::Map propertyMap;
860 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
861 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
862 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
863 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
864 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
865 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
866 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
867 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
868 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
870 Visual::Base visual = factory.CreateVisual(propertyMap);
871 DALI_TEST_CHECK(visual);
873 TestGlAbstraction& gl = application.GetGlAbstraction();
874 TraceCallStack& textureTrace = gl.GetTextureTrace();
875 textureTrace.Enable(true);
876 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
877 texParameterTrace.Enable(true);
879 DummyControl actor = DummyControl::New();
880 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
881 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
882 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
883 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
884 application.GetScene().Add(actor);
887 application.SendNotification();
888 application.Render();
890 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
892 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
894 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
895 std::stringstream out;
896 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
897 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
899 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
900 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
902 // test the uniforms which used to handle the wrap mode
903 Renderer renderer = actor.GetRendererAt(0u);
904 DALI_TEST_CHECK(renderer);
906 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
907 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
908 Vector4 pixelAreaUniform;
909 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
910 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
912 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
913 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
914 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
915 Vector2 wrapModeUniform;
916 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
917 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
920 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
925 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
927 ToolkitTestApplication application;
928 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
930 static std::vector<UniformData> customUniforms =
932 UniformData("pixelArea", Property::Type::VECTOR4),
935 TestGraphicsController& graphics = application.GetGraphicsController();
936 graphics.AddCustomUniforms(customUniforms);
938 VisualFactory factory = VisualFactory::Get();
939 DALI_TEST_CHECK(factory);
941 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
942 const int width = 600;
943 const int height = 600;
944 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
946 Property::Map propertyMap;
947 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
948 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
949 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
950 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
951 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
952 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
953 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
954 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
956 Visual::Base visual = factory.CreateVisual(propertyMap);
957 DALI_TEST_CHECK(visual);
959 TestGlAbstraction& gl = application.GetGlAbstraction();
960 TraceCallStack& textureTrace = gl.GetTextureTrace();
961 textureTrace.Enable(true);
962 textureTrace.EnableLogging(true);
963 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
964 texParameterTrace.Enable(true);
965 texParameterTrace.EnableLogging(true);
967 DummyControl actor = DummyControl::New();
968 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
969 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
970 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
971 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
972 application.GetScene().Add(actor);
975 application.SendNotification();
976 application.Render();
977 application.SendNotification();
979 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
981 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
983 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
984 std::stringstream out;
985 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
986 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
988 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
989 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
991 // test the uniforms which used to handle the wrap mode
992 Renderer renderer = actor.GetRendererAt(0u);
993 DALI_TEST_CHECK(renderer);
995 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
996 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
997 Vector4 pixelAreaUniform;
998 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
999 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1001 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1002 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1005 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1010 int UtcDaliImageVisualAnimateMixColor(void)
1012 ToolkitTestApplication application;
1013 tet_infoline("Animate mix color");
1015 static std::vector<UniformData> customUniforms =
1017 UniformData("mixColor", Property::Type::VECTOR3),
1020 TestGraphicsController& graphics = application.GetGraphicsController();
1021 graphics.AddCustomUniforms(customUniforms);
1023 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1025 VisualFactory factory = VisualFactory::Get();
1026 Property::Map propertyMap;
1027 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1028 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1029 propertyMap.Insert("mixColor", Color::BLUE);
1030 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1031 Visual::Base visual = factory.CreateVisual(propertyMap);
1033 DummyControl actor = DummyControl::New(true);
1034 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1035 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1037 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1038 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1039 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1040 application.GetScene().Add(actor);
1042 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1044 Renderer renderer = actor.GetRendererAt(0);
1046 // @todo Should we add API to make this code work again?
1047 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1049 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1050 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1052 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1055 map["target"] = "testVisual";
1056 map["property"] = "mixColor";
1057 map["initialValue"] = Color::MAGENTA;
1058 map["targetValue"] = TARGET_MIX_COLOR;
1059 map["animator"] = Property::Map()
1060 .Add("alphaFunction", "LINEAR")
1061 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1063 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1065 Animation animation = dummyImpl.CreateTransition(transition);
1067 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1070 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1071 glAbstraction.EnableEnableDisableCallTrace(true);
1072 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1073 std::ostringstream blendStr;
1074 blendStr << std::hex << GL_BLEND;
1076 application.SendNotification();
1077 application.Render(0); // Ensure animation starts
1078 application.Render(2000u); // Halfway point
1079 Vector3 testColor(1.0f, 0.0f, 0.5f);
1081 // uColor.a should be actor's alpha * mixColor.a.
1082 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1083 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1085 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1087 glEnableStack.Reset();
1089 application.SendNotification();
1090 application.Render(2000u);
1092 application.SendNotification();
1093 application.Render();
1094 application.SendNotification();
1096 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1097 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1098 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1100 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1102 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1107 int UtcDaliImageVisualAnimateOpacity(void)
1109 ToolkitTestApplication application;
1110 tet_infoline("Animate image visual opacity");
1112 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1114 VisualFactory factory = VisualFactory::Get();
1115 Property::Map propertyMap;
1116 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1117 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1118 propertyMap.Insert("opacity", 0.5f);
1119 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1120 Visual::Base visual = factory.CreateVisual(propertyMap);
1122 DummyControl actor = DummyControl::New(true);
1123 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1124 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1126 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1127 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1128 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1129 application.GetScene().Add(actor);
1131 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1133 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1134 glAbstraction.EnableEnableDisableCallTrace(true);
1135 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1136 std::ostringstream blendStr;
1137 blendStr << std::hex << GL_BLEND;
1139 application.SendNotification();
1140 application.Render();
1142 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1145 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.");
1148 map["target"] = "testVisual";
1149 map["property"] = "opacity";
1150 map["targetValue"] = 1.0f;
1151 map["animator"] = Property::Map()
1152 .Add("alphaFunction", "LINEAR")
1153 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1155 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1156 Animation animation = dummyImpl.CreateTransition(transition);
1159 glEnableStack.Reset();
1161 application.SendNotification();
1162 application.Render(0); // Ensure animation starts
1163 application.Render(2000u); // Halfway point through animation
1164 application.SendNotification(); // Handle any signals
1167 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1168 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1170 application.Render(2001u); // end
1171 application.SendNotification(); // ensure animation finished signal is sent
1173 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1174 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1176 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1177 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1181 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.");
1184 map["target"] = "testVisual";
1185 map["property"] = Visual::Property::OPACITY;
1186 map["targetValue"] = 0.1f;
1187 map["animator"] = Property::Map()
1188 .Add("alphaFunction", "LINEAR")
1189 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1191 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1192 Animation animation = dummyImpl.CreateTransition(transition);
1195 glEnableStack.Reset();
1197 application.SendNotification();
1198 application.Render(0); // Ensure animation starts
1199 application.Render(2000u); // Halfway point
1200 application.SendNotification();
1203 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1204 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1206 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1208 glEnableStack.Reset();
1210 application.Render(2016u); // end
1211 application.SendNotification();
1213 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1214 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1216 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1217 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1223 int UtcDaliImageVisualAnimateOpacity02(void)
1225 ToolkitTestApplication application;
1226 tet_infoline("Animate image visual opacity");
1228 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1230 VisualFactory factory = VisualFactory::Get();
1231 Property::Map propertyMap;
1232 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1233 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1234 propertyMap.Insert("opacity", 0.5f);
1235 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1236 Visual::Base visual = factory.CreateVisual(propertyMap);
1238 DummyControl actor = DummyControl::New(true);
1239 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1240 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1242 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1243 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1244 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1246 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1248 Property::Array array;
1251 map["target"] = "testVisual";
1252 map["property"] = "opacity";
1253 map["initialValue"] = 0.0f;
1254 map["targetValue"] = 1.0f;
1255 map["animator"] = Property::Map()
1256 .Add("alphaFunction", "LINEAR")
1257 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1260 map2["target"] = "testVisual";
1261 map2["property"] = "size";
1262 map2["targetValue"] = Vector2(1.0f, 1.0f);
1264 array.Add(map).Add(map2);
1266 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1267 Animation animation = dummyImpl.CreateTransition(transition);
1269 application.GetScene().Add(actor);
1270 application.SendNotification();
1271 application.Render(0); // Ensure animation starts
1273 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1275 Renderer renderer = actor.GetRendererAt(0);
1276 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1277 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1279 animation = dummyImpl.CreateTransition(transition);
1282 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1283 glAbstraction.EnableEnableDisableCallTrace(true);
1284 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1285 std::ostringstream blendStr;
1286 blendStr << std::hex << GL_BLEND;
1288 application.SendNotification();
1289 application.Render(0); // Ensure animation starts
1290 application.Render(2000u); // Halfway point through animation
1291 application.SendNotification(); // Handle any signals
1293 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1296 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1297 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1299 glEnableStack.Reset();
1301 application.Render(2001u); // end
1302 application.SendNotification(); // ensure animation finished signal is sent
1304 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1305 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1307 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1312 int UtcDaliImageVisualAnimatePixelArea(void)
1314 ToolkitTestApplication application;
1315 tet_infoline("ImageVisual animate pixel area");
1317 static std::vector<UniformData> customUniforms =
1319 UniformData("pixelArea", Property::Type::VECTOR4),
1322 TestGraphicsController& graphics = application.GetGraphicsController();
1323 graphics.AddCustomUniforms(customUniforms);
1325 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1327 VisualFactory factory = VisualFactory::Get();
1328 Property::Map propertyMap;
1329 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1330 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1331 propertyMap.Insert("mixColor", Color::BLUE);
1332 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1333 Visual::Base visual = factory.CreateVisual(propertyMap);
1335 DummyControl actor = DummyControl::New(true);
1336 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1337 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1339 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1340 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1341 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1342 application.GetScene().Add(actor);
1344 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1346 Renderer renderer = actor.GetRendererAt(0);
1347 // @todo Implement this feature?
1348 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1349 //tet_infoline("Test that the renderer has the mixColor property");
1350 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1352 // TransitionData only takes string keys
1354 map["target"] = "testVisual";
1355 map["property"] = "pixelArea";
1356 map["initialValue"] = Vector4(0, 0, 0, 1);
1357 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1358 map["animator"] = Property::Map()
1359 .Add("alphaFunction", "LINEAR")
1360 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1362 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1364 Animation animation = dummyImpl.CreateTransition(transition);
1365 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1368 application.SendNotification();
1369 application.Render(0); // Ensure animation starts
1370 application.Render(2000u); // Halfway point
1372 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1374 application.Render(2000u); // End of animation
1376 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1381 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1383 ToolkitTestApplication application;
1384 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1386 Property::Map propertyMap;
1387 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1388 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1390 TestGlAbstraction& gl = application.GetGlAbstraction();
1391 TraceCallStack& textureTrace = gl.GetTextureTrace();
1392 textureTrace.Enable(true);
1393 TraceCallStack& drawTrace = gl.GetDrawTrace();
1394 drawTrace.Enable(true);
1396 Actor actor = CreateActorWithImageVisual(propertyMap);
1397 application.GetScene().Add(actor);
1398 application.SendNotification();
1400 application.GetScene().Remove(actor);
1401 application.SendNotification();
1403 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1404 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1405 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1406 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1411 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1413 ToolkitTestApplication application;
1414 tet_infoline("Load image asynchronously, cancel loading, then load again");
1416 VisualFactory factory = VisualFactory::Get();
1417 DALI_TEST_CHECK(factory);
1419 Property::Map propertyMap;
1420 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1421 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1423 Visual::Base visual = factory.CreateVisual(propertyMap);
1424 DALI_TEST_CHECK(visual);
1426 TestGlAbstraction& gl = application.GetGlAbstraction();
1427 TraceCallStack& textureTrace = gl.GetTextureTrace();
1428 textureTrace.Enable(true);
1429 TraceCallStack& drawTrace = gl.GetDrawTrace();
1430 drawTrace.Enable(true);
1432 DummyControl actor = DummyControl::New();
1433 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1434 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1436 application.GetScene().Add(actor);
1439 application.GetScene().Remove(actor);
1441 application.GetScene().Add(actor);
1443 // Create another visual with the same image
1444 visual = factory.CreateVisual(propertyMap);
1445 DALI_TEST_CHECK(visual);
1447 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1449 application.SendNotification();
1450 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1452 application.SendNotification();
1453 application.Render();
1455 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1456 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1457 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1458 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1463 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1465 ToolkitTestApplication application;
1466 tet_infoline("Request image visual with invalid images - should draw broken.png");
1468 VisualFactory factory = VisualFactory::Get();
1469 DALI_TEST_CHECK(factory);
1471 Property::Map propertyMap;
1472 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1473 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1475 Visual::Base visual = factory.CreateVisual(propertyMap);
1476 DALI_TEST_CHECK(visual);
1478 TestGlAbstraction& gl = application.GetGlAbstraction();
1479 TraceCallStack& textureTrace = gl.GetTextureTrace();
1480 textureTrace.Enable(true);
1482 DummyControl actor = DummyControl::New();
1483 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1484 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1486 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1487 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1489 application.GetScene().Add(actor);
1491 application.SendNotification();
1492 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1494 application.SendNotification();
1495 application.Render();
1497 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1498 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1500 application.GetScene().Remove(actor);
1501 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1506 int UtcDaliImageVisualSetInvalidSyncImage(void)
1508 ToolkitTestApplication application;
1509 tet_infoline("Request image visual with invalid images - should draw broken.png");
1511 VisualFactory factory = VisualFactory::Get();
1512 DALI_TEST_CHECK(factory);
1514 Property::Map propertyMap;
1515 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1516 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1517 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1519 Visual::Base visual = factory.CreateVisual(propertyMap);
1520 DALI_TEST_CHECK(visual);
1522 TestGlAbstraction& gl = application.GetGlAbstraction();
1523 TraceCallStack& textureTrace = gl.GetTextureTrace();
1524 textureTrace.Enable(true);
1526 DummyControl actor = DummyControl::New();
1527 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1528 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1530 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1531 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1533 application.GetScene().Add(actor);
1535 application.SendNotification();
1536 application.Render();
1538 // Check resource status
1539 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1540 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1542 // The broken image should be shown.
1543 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1544 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1546 application.GetScene().Remove(actor);
1547 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1552 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1554 ToolkitTestApplication application;
1555 tet_infoline("Request image visual with invalid images - should draw broken.png");
1557 VisualFactory factory = VisualFactory::Get();
1558 DALI_TEST_CHECK(factory);
1560 // Local invalid file, asynchronous loading
1561 Property::Map propertyMap;
1562 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1563 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1565 Visual::Base visual = factory.CreateVisual(propertyMap);
1566 DALI_TEST_CHECK(visual);
1568 TestGlAbstraction& gl = application.GetGlAbstraction();
1569 TraceCallStack& textureTrace = gl.GetTextureTrace();
1570 textureTrace.Enable(true);
1572 DummyControl actor = DummyControl::New();
1573 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1574 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1576 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1577 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1579 application.GetScene().Add(actor);
1581 application.SendNotification();
1582 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1584 application.SendNotification();
1585 application.Render();
1587 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1588 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1590 application.GetScene().Remove(actor);
1591 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1596 int UtcDaliImageVisualAlphaMask01(void)
1598 ToolkitTestApplication application;
1599 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1601 VisualFactory factory = VisualFactory::Get();
1602 DALI_TEST_CHECK(factory);
1604 Property::Map propertyMap;
1605 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1606 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1607 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1609 Visual::Base visual = factory.CreateVisual(propertyMap);
1610 DALI_TEST_CHECK(visual);
1612 Property::Map testMap;
1613 visual.CreatePropertyMap(testMap);
1614 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1616 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1617 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1619 TestGlAbstraction& gl = application.GetGlAbstraction();
1620 TraceCallStack& textureTrace = gl.GetTextureTrace();
1621 textureTrace.Enable(true);
1623 DummyControl actor = DummyControl::New();
1624 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1625 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1627 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1628 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1629 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1631 application.GetScene().Add(actor);
1632 application.SendNotification();
1633 application.Render();
1635 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1637 application.SendNotification();
1638 application.Render();
1640 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1641 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1642 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1644 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1645 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1650 int UtcDaliImageVisualAlphaMask02(void)
1652 ToolkitTestApplication application;
1653 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1655 VisualFactory factory = VisualFactory::Get();
1656 DALI_TEST_CHECK(factory);
1658 Property::Map propertyMap;
1659 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1660 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1661 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1662 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1664 Visual::Base visual = factory.CreateVisual(propertyMap);
1665 DALI_TEST_CHECK(visual);
1667 Property::Map testMap;
1668 visual.CreatePropertyMap(testMap);
1669 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1670 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1672 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1673 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1675 TestGlAbstraction& gl = application.GetGlAbstraction();
1676 TraceCallStack& textureTrace = gl.GetTextureTrace();
1677 textureTrace.Enable(true);
1679 DummyControl actor = DummyControl::New();
1680 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1681 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1683 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1684 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1685 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1687 application.GetScene().Add(actor);
1688 application.SendNotification();
1689 application.Render();
1691 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1693 application.SendNotification();
1694 application.Render();
1696 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1697 Renderer renderer = actor.GetRendererAt(0u);
1698 TextureSet textures = renderer.GetTextures();
1699 DALI_TEST_CHECK(textures);
1700 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1702 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1703 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1705 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1706 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1711 int UtcDaliImageVisualAlphaMask03(void)
1713 ToolkitTestApplication application;
1714 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1716 VisualFactory factory = VisualFactory::Get();
1717 DALI_TEST_CHECK(factory);
1719 Property::Map propertyMap;
1720 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1721 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1722 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1723 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1725 Visual::Base visual = factory.CreateVisual(propertyMap);
1726 DALI_TEST_CHECK(visual);
1728 Property::Map testMap;
1729 visual.CreatePropertyMap(testMap);
1731 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1732 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1734 TestGlAbstraction& gl = application.GetGlAbstraction();
1735 TraceCallStack& textureTrace = gl.GetTextureTrace();
1736 textureTrace.Enable(true);
1738 DummyControl actor = DummyControl::New();
1739 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1740 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1742 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1743 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1744 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1746 application.GetScene().Add(actor);
1747 application.SendNotification();
1748 application.Render();
1750 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1752 application.SendNotification();
1753 application.Render();
1755 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1756 Renderer renderer = actor.GetRendererAt(0u);
1757 TextureSet textures = renderer.GetTextures();
1758 DALI_TEST_CHECK(textures);
1759 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
1761 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1762 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1764 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1765 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1770 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
1772 ToolkitTestApplication application;
1773 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
1775 VisualFactory factory = VisualFactory::Get();
1776 DALI_TEST_CHECK(factory);
1778 Property::Map propertyMap;
1779 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1780 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1781 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1782 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1784 Visual::Base visual = factory.CreateVisual(propertyMap);
1785 DALI_TEST_CHECK(visual);
1787 Property::Map testMap;
1788 visual.CreatePropertyMap(testMap);
1789 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1791 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1792 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1794 TestGlAbstraction& gl = application.GetGlAbstraction();
1795 TraceCallStack& textureTrace = gl.GetTextureTrace();
1796 textureTrace.Enable(true);
1798 DummyControl actor = DummyControl::New();
1799 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1800 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1802 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1803 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1804 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1806 application.GetScene().Add(actor);
1808 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1810 application.SendNotification();
1811 application.Render();
1813 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1814 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1815 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1817 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1818 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1823 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
1825 ToolkitTestApplication application;
1826 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
1828 VisualFactory factory = VisualFactory::Get();
1829 DALI_TEST_CHECK(factory);
1831 Property::Map propertyMap;
1832 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1833 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1834 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1835 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1836 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1838 Visual::Base visual = factory.CreateVisual(propertyMap);
1839 DALI_TEST_CHECK(visual);
1841 Property::Map testMap;
1842 visual.CreatePropertyMap(testMap);
1843 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1845 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1846 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1848 TestGlAbstraction& gl = application.GetGlAbstraction();
1849 TraceCallStack& textureTrace = gl.GetTextureTrace();
1850 textureTrace.Enable(true);
1852 DummyControl actor = DummyControl::New();
1853 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1854 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1856 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1857 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1858 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1860 application.GetScene().Add(actor);
1862 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1864 application.SendNotification();
1865 application.Render();
1867 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1868 Renderer renderer = actor.GetRendererAt(0u);
1869 TextureSet textures = renderer.GetTextures();
1870 DALI_TEST_CHECK(textures);
1871 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1873 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1874 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1876 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1877 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1882 int UtcDaliImageVisualRemoteAlphaMask(void)
1884 ToolkitTestApplication application;
1885 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1887 VisualFactory factory = VisualFactory::Get();
1888 DALI_TEST_CHECK(factory);
1890 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1892 Property::Map propertyMap;
1893 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1894 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1895 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1897 Visual::Base visual = factory.CreateVisual(propertyMap);
1898 DALI_TEST_CHECK(visual);
1900 Property::Map testMap;
1901 visual.CreatePropertyMap(testMap);
1903 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1905 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1906 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1908 TestGlAbstraction& gl = application.GetGlAbstraction();
1909 TraceCallStack& textureTrace = gl.GetTextureTrace();
1910 textureTrace.Enable(true);
1912 DummyControl actor = DummyControl::New();
1913 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1914 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1916 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1918 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1919 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1921 application.GetScene().Add(actor);
1922 application.SendNotification();
1923 application.Render();
1925 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1927 application.SendNotification();
1928 application.Render();
1930 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1931 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1932 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1937 int UtcDaliImageVisualAlphaMaskCrop(void)
1939 ToolkitTestApplication application;
1940 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1942 VisualFactory factory = VisualFactory::Get();
1943 DALI_TEST_CHECK(factory);
1945 Property::Map propertyMap;
1946 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1947 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1948 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1949 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1950 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1952 Visual::Base visual = factory.CreateVisual(propertyMap);
1953 DALI_TEST_CHECK(visual);
1955 Property::Map testMap;
1956 visual.CreatePropertyMap(testMap);
1957 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1958 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1959 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1961 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1962 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1964 TestGlAbstraction& gl = application.GetGlAbstraction();
1965 TraceCallStack& textureTrace = gl.GetTextureTrace();
1966 textureTrace.Enable(true);
1968 DummyControl actor = DummyControl::New();
1969 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1970 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1972 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1973 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1974 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1976 application.GetScene().Add(actor);
1977 application.SendNotification();
1978 application.Render();
1980 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1982 application.SendNotification();
1983 application.Render();
1986 visual.GetNaturalSize(size);
1988 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1989 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1990 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1991 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1996 int UtcDaliImageVisualReleasePolicy01(void)
1998 ToolkitTestApplication application;
1999 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2001 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2002 DALI_TEST_CHECK(imageVisual);
2004 // Set up debug trace
2005 TestGlAbstraction& gl = application.GetGlAbstraction();
2006 TraceCallStack& textureTrace = gl.GetTextureTrace();
2007 textureTrace.Enable(true);
2009 tet_infoline("Register visual with control and ensure it has the only handle");
2010 DummyControl actor = DummyControl::New(true);
2011 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2012 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2013 imageVisual.Reset();
2015 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2017 application.SendNotification();
2018 application.Render(0);
2019 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2020 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2022 application.GetScene().Add(actor);
2024 // Wait for image to load
2025 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2027 application.SendNotification();
2028 application.Render(0);
2029 // Test renderer and texture created
2030 tet_infoline("Confirm texture created");
2031 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2032 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2034 tet_infoline("Disable visual causing the texture to be deleted");
2035 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2037 application.SendNotification();
2038 application.Render(0);
2039 // Test renderer and textures removed.
2040 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2041 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2046 int UtcDaliImageVisualReleasePolicy02(void)
2048 ToolkitTestApplication application;
2049 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2051 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2052 DALI_TEST_CHECK(imageVisual);
2054 // Setup debug trace
2055 TestGlAbstraction& gl = application.GetGlAbstraction();
2056 TraceCallStack& textureTrace = gl.GetTextureTrace();
2057 textureTrace.Enable(true);
2059 tet_infoline("Register visual with control and ensure it has the only handle");
2060 DummyControl actor = DummyControl::New(true);
2061 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2062 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2063 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2065 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2067 application.SendNotification();
2068 application.Render(0);
2069 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2070 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2072 application.GetScene().Add(actor);
2074 // Wait for image to load
2075 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2077 application.SendNotification();
2078 application.Render(0);
2079 // Test renderer and texture created
2080 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2081 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2083 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2084 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2085 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2086 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2087 application.SendNotification();
2088 application.Render();
2090 // Test texture removed after visual destroyed.
2091 tet_infoline("Ensure texture is deleted after visual destroyed");
2092 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2097 int UtcDaliImageVisualReleasePolicy03(void)
2099 ToolkitTestApplication application;
2100 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2102 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2103 DALI_TEST_CHECK(imageVisual);
2105 TestGlAbstraction& gl = application.GetGlAbstraction();
2106 TraceCallStack& textureTrace = gl.GetTextureTrace();
2107 textureTrace.Enable(true);
2109 tet_infoline("Register visual with control and ensure it has the only handle");
2110 DummyControl actor = DummyControl::New(true);
2111 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2112 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2113 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2115 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2117 application.SendNotification();
2118 application.Render(0);
2119 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2120 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2122 application.GetScene().Add(actor);
2124 // Wait for image to load
2125 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2127 application.SendNotification();
2128 application.Render(0);
2129 // Test renderer and texture created
2130 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2131 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2133 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2134 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2135 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2136 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2137 application.SendNotification();
2138 application.Render();
2140 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2141 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2146 int UtcDaliImageVisualReleasePolicy04(void)
2148 ToolkitTestApplication application;
2149 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2151 tet_infoline("Create first visual with Never release policy");
2152 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2154 tet_infoline("Create second visual with Destroyed release policy");
2155 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2157 // Set up trace debug
2158 TestGlAbstraction& gl = application.GetGlAbstraction();
2159 TraceCallStack& textureTrace = gl.GetTextureTrace();
2160 textureTrace.Enable(true);
2162 tet_infoline("Register visuals with control and ensure it has the only handles");
2163 DummyControl actor = DummyControl::New(true);
2164 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2165 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2166 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2167 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2168 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2170 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2172 // Test initially zero renderers
2173 application.SendNotification();
2174 application.Render(0);
2175 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2176 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2178 application.GetScene().Add(actor);
2180 // Wait for image to load
2181 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2183 application.SendNotification();
2184 application.Render(0);
2185 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2186 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2187 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2189 // Test renderer removed when visual destroyed
2190 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2191 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2192 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2193 application.SendNotification();
2194 application.Render();
2196 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2197 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2199 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2200 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2201 application.SendNotification();
2202 application.Render();
2204 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2205 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2206 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2211 int UtcDaliImageVisualReleasePolicy05(void)
2213 ToolkitTestApplication application;
2214 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2216 VisualFactory factory = VisualFactory::Get();
2218 Property::Map propertyMapNeverReleasePolicy;
2219 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2220 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2221 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2222 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2223 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2225 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2227 Property::Map resultMap;
2228 imageVisualNever.CreatePropertyMap(resultMap);
2229 DALI_TEST_CHECK(!resultMap.Empty());
2231 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2236 int UtcDaliImageVisualReleasePolicy06(void)
2238 ToolkitTestApplication application;
2239 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2241 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2242 DALI_TEST_CHECK(imageVisual);
2244 TestGlAbstraction& gl = application.GetGlAbstraction();
2245 TraceCallStack& textureTrace = gl.GetTextureTrace();
2246 textureTrace.Enable(true);
2248 tet_infoline("Register visual with control and ensure it has the only handle");
2249 DummyControl actor = DummyControl::New(true);
2250 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2251 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2252 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2254 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2256 application.SendNotification();
2257 application.Render(0);
2258 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2259 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2261 application.GetScene().Add(actor);
2263 // Wait for image to load
2264 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2266 application.SendNotification();
2267 application.Render(0);
2268 // Test renderer and texture created
2269 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2270 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2271 textureTrace.Reset();
2273 tet_infoline("Disable Visual and check texture not affected");
2274 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2275 application.SendNotification();
2276 application.Render(0);
2277 tet_infoline("Check renderer is destroyed when visual off stage");
2278 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2279 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2280 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2281 textureTrace.Reset();
2283 tet_infoline("Re-enable Visual and check texture not affected");
2284 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2285 application.SendNotification();
2286 application.Render(0);
2287 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2288 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2289 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2290 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2295 int UtcDaliImageVisualReleasePolicy07(void)
2297 ToolkitTestApplication application;
2298 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2300 tet_infoline("Create first visual with DESTROYED release policy");
2301 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2303 tet_infoline("Create second visual with DETACHED release policy");
2304 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2306 // Set up trace debug
2307 TestGlAbstraction& gl = application.GetGlAbstraction();
2308 TraceCallStack& textureTrace = gl.GetTextureTrace();
2309 textureTrace.Enable(true);
2311 tet_infoline("Register visuals with control and ensure it has the only handles");
2312 DummyControl actor = DummyControl::New(true);
2313 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2314 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2315 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2316 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2317 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2319 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2321 // Test initially zero renderers
2322 application.SendNotification();
2323 application.Render(0);
2324 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2325 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2327 application.GetScene().Add(actor);
2329 // Wait for image to load
2330 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2332 application.SendNotification();
2333 application.Render(0);
2334 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2335 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2336 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2338 // Test renderer removed when visual destroyed
2339 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2340 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2341 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2342 application.SendNotification();
2343 application.Render();
2345 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2346 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2348 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2349 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2350 application.SendNotification();
2351 application.Render();
2353 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2354 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2359 int UtcDaliImageVisualReleasePolicy08(void)
2361 ToolkitTestApplication application;
2362 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2364 tet_infoline("Create first visual with DESTROYED release policy");
2365 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2367 // Set up trace debug
2368 TestGlAbstraction& gl = application.GetGlAbstraction();
2369 TraceCallStack& textureTrace = gl.GetTextureTrace();
2370 textureTrace.Enable(true);
2372 tet_infoline("Register visuals with control and ensure it has the only handles");
2373 DummyControl actor = DummyControl::New(true);
2374 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2375 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2376 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2378 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2380 // Test initially zero renderers
2381 application.SendNotification();
2382 application.Render(0);
2383 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2384 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2385 textureTrace.Reset();
2387 application.GetScene().Add(actor);
2389 // Wait for image to load
2390 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2392 application.SendNotification();
2393 application.Render(0);
2394 tet_infoline("Ensure a texture is created");
2395 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2396 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2397 textureTrace.Reset();
2399 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2400 // 1. Get TextureSet
2401 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2403 // 2.Remove actor from stage. In this case, renderer also is deleted.
2404 tet_infoline("Remove actor from stage");
2405 application.GetScene().Remove(actor);
2406 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2407 application.SendNotification();
2408 application.Render();
2410 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2411 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2412 textureTrace.Reset();
2414 // 3.Add actor in stage. In this case, renderer is created.
2415 tet_infoline("Add actor in stage");
2416 application.GetScene().Add(actor);
2417 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2418 application.SendNotification();
2419 application.Render();
2420 tet_infoline("Ensure a texture is not created again");
2421 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2422 textureTrace.Reset();
2424 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2425 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2426 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2427 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2428 textureSetBefore.Reset();
2429 textureSetAfter.Reset();
2431 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2432 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2433 application.SendNotification();
2434 application.Render();
2435 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2440 int UtcDaliImageVisualLoadPolicy01(void)
2442 ToolkitTestApplication application;
2443 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2445 // Set up trace debug
2446 TestGlAbstraction& gl = application.GetGlAbstraction();
2447 TraceCallStack& textureTrace = gl.GetTextureTrace();
2448 textureTrace.Enable(true);
2450 tet_infoline("Create visual with IMMEDIATE load policy");
2451 VisualFactory factory = VisualFactory::Get();
2453 Property::Map propertyMap;
2454 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2455 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2456 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2457 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2458 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2460 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2462 Property::Map resultMap;
2463 imageVisual.CreatePropertyMap(resultMap);
2464 DALI_TEST_CHECK(!resultMap.Empty());
2465 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2467 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2469 // Ensure texture has been uploaded
2470 application.SendNotification();
2471 application.Render();
2473 tet_infoline("Ensure texture loading starts after visual created");
2474 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2475 textureTrace.Reset();
2477 tet_infoline("Register visuals with control and ensure it has the only handles");
2478 DummyControl actor = DummyControl::New(true);
2479 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2480 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2481 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2483 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2484 application.GetScene().Add(actor);
2485 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2486 const unsigned int TIME_OUT_3_SECONDS = 3;
2487 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2489 application.SendNotification();
2490 application.Render();
2492 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2493 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2495 // Ensure texture is deleted when no longer needed (ref count was correct )
2496 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2498 application.SendNotification();
2499 application.Render();
2501 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2502 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2507 int UtcDaliImageVisualLoadPolicy02(void)
2509 ToolkitTestApplication application;
2510 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2512 // Set up trace debug
2513 TestGlAbstraction& gl = application.GetGlAbstraction();
2514 TraceCallStack& textureTrace = gl.GetTextureTrace();
2515 textureTrace.Enable(true);
2517 tet_infoline("Create visual with IMMEDIATE load policy");
2518 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2520 const unsigned int TIME_OUT_3_SECONDS = 3;
2521 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2523 // Act on meeage queue even although nothing expected to load
2524 application.SendNotification();
2525 application.Render();
2527 tet_infoline("Ensure texture is not generated yet");
2528 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2529 textureTrace.Reset();
2531 tet_infoline("Register visuals with control and ensure it has the only handles");
2532 DummyControl actor = DummyControl::New(true);
2533 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2534 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2535 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2537 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2538 application.GetScene().Add(actor);
2539 tet_infoline("Allow image time to load");
2540 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2542 application.SendNotification();
2543 application.Render();
2545 tet_infoline("Ensure texture generated and renderer created");
2546 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2547 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2549 // Ensure texture is delete when no longer needed
2550 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2552 application.SendNotification();
2553 application.Render();
2555 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2556 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2561 int UtcDaliImageVisualLoadPolicy03(void)
2563 ToolkitTestApplication application;
2564 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2566 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2568 // Set up trace debug
2569 TestGlAbstraction& gl = application.GetGlAbstraction();
2570 TraceCallStack& textureTrace = gl.GetTextureTrace();
2571 textureTrace.Enable(true);
2573 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2574 DummyControl actor = DummyControl::New(true);
2575 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2576 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2577 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2579 tet_infoline("Create visual with IMMEDIATE load policy");
2580 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2582 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2583 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2584 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2586 tet_infoline("Allow image time to load resource");
2587 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2588 application.SendNotification();
2589 application.Render();
2591 // Ensure texture has been uploaded
2592 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2593 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2598 int UtcDaliImageVisualLoadPolicy04(void)
2600 ToolkitTestApplication application;
2601 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2602 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2604 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2606 // Set up trace debug
2607 TestGlAbstraction& gl = application.GetGlAbstraction();
2608 TraceCallStack& textureTrace = gl.GetTextureTrace();
2609 textureTrace.Enable(true);
2611 tet_infoline("Create a control and connect to resource ready signal");
2612 DummyControl actor = DummyControl::New(true);
2613 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2614 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2615 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2617 tet_infoline("Create visual with IMMEDIATE load policy");
2618 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2620 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2621 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2622 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2624 tet_infoline("Allow image time to load");
2625 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2626 application.SendNotification();
2627 application.Render();
2629 tet_infoline("Testing texture is loaded and resource ready signal fired");
2630 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2631 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2633 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2635 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2636 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2637 DummyControl actor2 = DummyControl::New(true);
2638 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2639 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2641 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2642 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2643 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2644 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2645 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2646 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2651 int UtcDaliImageVisualLoadPolicy05(void)
2653 ToolkitTestApplication application;
2654 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2655 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2656 // Set up trace debug
2657 TestGlAbstraction& gl = application.GetGlAbstraction();
2658 TraceCallStack& textureTrace = gl.GetTextureTrace();
2659 textureTrace.Enable(true);
2661 tet_infoline("Create a control and connect to resource ready signal");
2662 DummyControl actor = DummyControl::New(true);
2663 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2664 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2665 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2666 application.GetScene().Add(actor);
2668 tet_infoline("Create visual with ATTACHED load policy");
2669 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2671 tet_infoline("Registering visual allows control to get a signal once loaded");
2672 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2673 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2675 tet_infoline("Allow image time to load");
2676 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2677 application.SendNotification();
2678 application.Render();
2680 tet_infoline("Testing texture is loaded and resource ready signal fired");
2681 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2682 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2684 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2686 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2687 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2688 DummyControl actor2 = DummyControl::New(true);
2689 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2690 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2692 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2693 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2694 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2695 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2696 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2697 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2702 int UtcDaliImageVisualOrientationCorrection(void)
2704 ToolkitTestApplication application;
2705 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2707 VisualFactory factory = VisualFactory::Get();
2708 tet_infoline("Create visual with Orientation correction set OFF");
2709 Property::Map propertyMap;
2710 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2711 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2712 propertyMap.Insert("orientationCorrection", false);
2713 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2715 tet_infoline("Create control for visual, need to loaded it");
2716 DummyControl actor = DummyControl::New(true);
2717 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2718 application.GetScene().Add(actor);
2720 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2721 // Wait for image to load
2722 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2724 Vector2 originalImageSize;
2725 tet_infoline("Get size of original visual to compare later with rotated image");
2726 imageVisual.GetNaturalSize(originalImageSize);
2727 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2728 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2729 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2730 application.SendNotification();
2731 application.Render();
2733 tet_infoline("Create visual with Orientation correction set ON ");
2734 propertyMap.Clear();
2735 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2736 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2737 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2738 imageVisual = factory.CreateVisual(propertyMap);
2740 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2741 // Wait for image to load
2742 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2744 Vector2 rotatedImageSize;
2745 imageVisual.GetNaturalSize(rotatedImageSize);
2746 tet_infoline("Confirm that visual has rotated");
2747 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2748 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2750 Property::Map resultMap;
2751 imageVisual.CreatePropertyMap(resultMap);
2753 // check the Property::ORIENTATION_CORRECTION value from the returned map
2754 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2755 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2760 int UtcDaliImageVisualCustomShader(void)
2762 ToolkitTestApplication application;
2763 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2765 VisualFactory factory = VisualFactory::Get();
2766 Property::Map properties;
2767 Property::Map shader;
2768 const std::string vertexShader = "Foobar";
2769 const std::string fragmentShader = "Foobar";
2770 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2771 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2773 properties[Visual::Property::TYPE] = Visual::IMAGE;
2774 properties[Visual::Property::SHADER] = shader;
2775 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2777 Visual::Base visual = factory.CreateVisual(properties);
2779 // trigger creation through setting on stage
2780 DummyControl dummy = DummyControl::New(true);
2781 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2782 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2784 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2785 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2786 application.GetScene().Add(dummy);
2788 application.SendNotification();
2789 application.Render();
2791 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2793 Renderer renderer = dummy.GetRendererAt(0);
2794 Shader shader2 = renderer.GetShader();
2795 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2796 Property::Map* map = value.GetMap();
2797 DALI_TEST_CHECK(map);
2799 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2800 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2802 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2803 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2807 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2808 properties[Visual::Property::SHADER] = shader;
2810 Visual::Base visual1 = factory.CreateVisual(properties);
2812 // trigger creation through setting on stage
2813 DummyControl dummy1 = DummyControl::New(true);
2814 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2815 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2816 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2817 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2818 application.GetScene().Add(dummy1);
2820 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2821 glAbstraction.EnableEnableDisableCallTrace(true);
2823 application.SendNotification();
2824 application.Render();
2826 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2827 std::ostringstream blendStr;
2828 blendStr << std::hex << GL_BLEND;
2829 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2834 void ResourceReadyLoadNext(Control control)
2836 static int callNumber = 0;
2838 gResourceReadySignalFired = true;
2839 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2843 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2845 tet_infoline("Create visual with loaded image from within the signal handler");
2846 VisualFactory factory = VisualFactory::Get();
2847 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2849 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2850 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2855 tet_infoline("3rd signal called");
2856 DALI_TEST_CHECK(true);
2860 int UtcDaliImageVisualLoadReady01(void)
2862 ToolkitTestApplication application;
2863 tet_infoline("UtcDaliImageVisualLoadReady01");
2864 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2865 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2866 tet_infoline("Should get a ready signal for all three visuals");
2870 tet_infoline("Create a control and connect to resource ready signal");
2871 DummyControl actor = DummyControl::New(true);
2872 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2873 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2874 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2875 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2876 application.GetScene().Add(actor);
2878 tet_infoline("Create visual with IMMEDIATE load policy");
2879 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2881 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2882 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2884 tet_infoline("Allow image time to load");
2885 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2886 application.SendNotification();
2887 application.Render();
2889 tet_infoline("Testing texture is loaded and resource ready signal fired");
2890 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2891 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2893 tet_infoline("Original control correctly signalled, now testing failing image");
2895 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2898 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2900 DummyControl actor2 = DummyControl::New(true);
2901 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2902 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2903 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2905 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2906 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2908 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2909 application.GetScene().Add(actor2);
2911 tet_infoline("Wait for loading thread to finish");
2912 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2913 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2915 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2917 tet_infoline("Check for 3rd signal");
2918 application.SendNotification();
2919 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2920 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);