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 UtcDaliImageVisualAlphaMask(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 UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1652 ToolkitTestApplication application;
1653 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
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(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
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);
1671 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1672 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1674 TestGlAbstraction& gl = application.GetGlAbstraction();
1675 TraceCallStack& textureTrace = gl.GetTextureTrace();
1676 textureTrace.Enable(true);
1678 DummyControl actor = DummyControl::New();
1679 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1680 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1682 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1683 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1684 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1686 application.GetScene().Add(actor);
1688 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1690 application.SendNotification();
1691 application.Render();
1693 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1694 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1695 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1697 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1698 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1703 int UtcDaliImageVisualRemoteAlphaMask(void)
1705 ToolkitTestApplication application;
1706 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1708 VisualFactory factory = VisualFactory::Get();
1709 DALI_TEST_CHECK(factory);
1711 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1713 Property::Map propertyMap;
1714 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1715 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1716 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1718 Visual::Base visual = factory.CreateVisual(propertyMap);
1719 DALI_TEST_CHECK(visual);
1721 Property::Map testMap;
1722 visual.CreatePropertyMap(testMap);
1724 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1726 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1727 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1729 TestGlAbstraction& gl = application.GetGlAbstraction();
1730 TraceCallStack& textureTrace = gl.GetTextureTrace();
1731 textureTrace.Enable(true);
1733 DummyControl actor = DummyControl::New();
1734 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1735 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1737 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1739 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1740 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1742 application.GetScene().Add(actor);
1743 application.SendNotification();
1744 application.Render();
1746 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1748 application.SendNotification();
1749 application.Render();
1751 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1752 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1753 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1758 int UtcDaliImageVisualAlphaMaskCrop(void)
1760 ToolkitTestApplication application;
1761 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1763 VisualFactory factory = VisualFactory::Get();
1764 DALI_TEST_CHECK(factory);
1766 Property::Map propertyMap;
1767 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1768 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1769 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1770 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1771 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1773 Visual::Base visual = factory.CreateVisual(propertyMap);
1774 DALI_TEST_CHECK(visual);
1776 Property::Map testMap;
1777 visual.CreatePropertyMap(testMap);
1778 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1779 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1780 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1782 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1783 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1785 TestGlAbstraction& gl = application.GetGlAbstraction();
1786 TraceCallStack& textureTrace = gl.GetTextureTrace();
1787 textureTrace.Enable(true);
1789 DummyControl actor = DummyControl::New();
1790 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1791 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1793 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1794 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1795 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1797 application.GetScene().Add(actor);
1798 application.SendNotification();
1799 application.Render();
1801 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1803 application.SendNotification();
1804 application.Render();
1807 visual.GetNaturalSize(size);
1809 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1810 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1811 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1812 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1817 int UtcDaliImageVisualReleasePolicy01(void)
1819 ToolkitTestApplication application;
1820 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
1822 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1823 DALI_TEST_CHECK(imageVisual);
1825 // Set up debug trace
1826 TestGlAbstraction& gl = application.GetGlAbstraction();
1827 TraceCallStack& textureTrace = gl.GetTextureTrace();
1828 textureTrace.Enable(true);
1830 tet_infoline("Register visual with control and ensure it has the only handle");
1831 DummyControl actor = DummyControl::New(true);
1832 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1833 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1834 imageVisual.Reset();
1836 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1838 application.SendNotification();
1839 application.Render(0);
1840 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1841 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1843 application.GetScene().Add(actor);
1845 // Wait for image to load
1846 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1848 application.SendNotification();
1849 application.Render(0);
1850 // Test renderer and texture created
1851 tet_infoline("Confirm texture created");
1852 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1853 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1855 tet_infoline("Disable visual causing the texture to be deleted");
1856 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
1858 application.SendNotification();
1859 application.Render(0);
1860 // Test renderer and textures removed.
1861 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1862 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1867 int UtcDaliImageVisualReleasePolicy02(void)
1869 ToolkitTestApplication application;
1870 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
1872 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
1873 DALI_TEST_CHECK(imageVisual);
1875 // Setup debug trace
1876 TestGlAbstraction& gl = application.GetGlAbstraction();
1877 TraceCallStack& textureTrace = gl.GetTextureTrace();
1878 textureTrace.Enable(true);
1880 tet_infoline("Register visual with control and ensure it has the only handle");
1881 DummyControl actor = DummyControl::New(true);
1882 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1883 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1884 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1886 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1888 application.SendNotification();
1889 application.Render(0);
1890 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1891 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1893 application.GetScene().Add(actor);
1895 // Wait for image to load
1896 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1898 application.SendNotification();
1899 application.Render(0);
1900 // Test renderer and texture created
1901 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1902 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1904 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1905 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
1906 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1907 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1908 application.SendNotification();
1909 application.Render();
1911 // Test texture removed after visual destroyed.
1912 tet_infoline("Ensure texture is deleted after visual destroyed");
1913 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1918 int UtcDaliImageVisualReleasePolicy03(void)
1920 ToolkitTestApplication application;
1921 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
1923 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
1924 DALI_TEST_CHECK(imageVisual);
1926 TestGlAbstraction& gl = application.GetGlAbstraction();
1927 TraceCallStack& textureTrace = gl.GetTextureTrace();
1928 textureTrace.Enable(true);
1930 tet_infoline("Register visual with control and ensure it has the only handle");
1931 DummyControl actor = DummyControl::New(true);
1932 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1933 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1934 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1936 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1938 application.SendNotification();
1939 application.Render(0);
1940 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1941 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1943 application.GetScene().Add(actor);
1945 // Wait for image to load
1946 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1948 application.SendNotification();
1949 application.Render(0);
1950 // Test renderer and texture created
1951 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1952 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1954 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
1955 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1956 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1957 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1958 application.SendNotification();
1959 application.Render();
1961 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
1962 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1967 int UtcDaliImageVisualReleasePolicy04(void)
1969 ToolkitTestApplication application;
1970 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
1972 tet_infoline("Create first visual with Never release policy");
1973 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
1975 tet_infoline("Create second visual with Destroyed release policy");
1976 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
1978 // Set up trace debug
1979 TestGlAbstraction& gl = application.GetGlAbstraction();
1980 TraceCallStack& textureTrace = gl.GetTextureTrace();
1981 textureTrace.Enable(true);
1983 tet_infoline("Register visuals with control and ensure it has the only handles");
1984 DummyControl actor = DummyControl::New(true);
1985 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1986 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
1987 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
1988 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1989 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1991 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1993 // Test initially zero renderers
1994 application.SendNotification();
1995 application.Render(0);
1996 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1997 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1999 application.GetScene().Add(actor);
2001 // Wait for image to load
2002 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2004 application.SendNotification();
2005 application.Render(0);
2006 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2007 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2008 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2010 // Test renderer removed when visual destroyed
2011 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2012 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2013 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2014 application.SendNotification();
2015 application.Render();
2017 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2018 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2020 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2021 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2022 application.SendNotification();
2023 application.Render();
2025 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2026 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2027 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2032 int UtcDaliImageVisualReleasePolicy05(void)
2034 ToolkitTestApplication application;
2035 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2037 VisualFactory factory = VisualFactory::Get();
2039 Property::Map propertyMapNeverReleasePolicy;
2040 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2041 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2042 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2043 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2044 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2046 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2048 Property::Map resultMap;
2049 imageVisualNever.CreatePropertyMap(resultMap);
2050 DALI_TEST_CHECK(!resultMap.Empty());
2052 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2057 int UtcDaliImageVisualReleasePolicy06(void)
2059 ToolkitTestApplication application;
2060 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2062 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2063 DALI_TEST_CHECK(imageVisual);
2065 TestGlAbstraction& gl = application.GetGlAbstraction();
2066 TraceCallStack& textureTrace = gl.GetTextureTrace();
2067 textureTrace.Enable(true);
2069 tet_infoline("Register visual with control and ensure it has the only handle");
2070 DummyControl actor = DummyControl::New(true);
2071 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2072 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2073 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2075 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2077 application.SendNotification();
2078 application.Render(0);
2079 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2080 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2082 application.GetScene().Add(actor);
2084 // Wait for image to load
2085 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2087 application.SendNotification();
2088 application.Render(0);
2089 // Test renderer and texture created
2090 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2091 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2092 textureTrace.Reset();
2094 tet_infoline("Disable Visual and check texture not affected");
2095 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2096 application.SendNotification();
2097 application.Render(0);
2098 tet_infoline("Check renderer is destroyed when visual off stage");
2099 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2100 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2101 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2102 textureTrace.Reset();
2104 tet_infoline("Re-enable Visual and check texture not affected");
2105 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2106 application.SendNotification();
2107 application.Render(0);
2108 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2109 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2110 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2111 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2116 int UtcDaliImageVisualReleasePolicy07(void)
2118 ToolkitTestApplication application;
2119 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2121 tet_infoline("Create first visual with DESTROYED release policy");
2122 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2124 tet_infoline("Create second visual with DETACHED release policy");
2125 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2127 // Set up trace debug
2128 TestGlAbstraction& gl = application.GetGlAbstraction();
2129 TraceCallStack& textureTrace = gl.GetTextureTrace();
2130 textureTrace.Enable(true);
2132 tet_infoline("Register visuals with control and ensure it has the only handles");
2133 DummyControl actor = DummyControl::New(true);
2134 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2135 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2136 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2137 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2138 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2140 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2142 // Test initially zero renderers
2143 application.SendNotification();
2144 application.Render(0);
2145 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2146 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2148 application.GetScene().Add(actor);
2150 // Wait for image to load
2151 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2153 application.SendNotification();
2154 application.Render(0);
2155 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2156 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2157 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2159 // Test renderer removed when visual destroyed
2160 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2161 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2162 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2163 application.SendNotification();
2164 application.Render();
2166 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2167 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2169 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2170 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2171 application.SendNotification();
2172 application.Render();
2174 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2175 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2180 int UtcDaliImageVisualReleasePolicy08(void)
2182 ToolkitTestApplication application;
2183 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2185 tet_infoline("Create first visual with DESTROYED release policy");
2186 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2188 // Set up trace debug
2189 TestGlAbstraction& gl = application.GetGlAbstraction();
2190 TraceCallStack& textureTrace = gl.GetTextureTrace();
2191 textureTrace.Enable(true);
2193 tet_infoline("Register visuals with control and ensure it has the only handles");
2194 DummyControl actor = DummyControl::New(true);
2195 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2196 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2197 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2199 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2201 // Test initially zero renderers
2202 application.SendNotification();
2203 application.Render(0);
2204 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2205 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2206 textureTrace.Reset();
2208 application.GetScene().Add(actor);
2210 // Wait for image to load
2211 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2213 application.SendNotification();
2214 application.Render(0);
2215 tet_infoline("Ensure a texture is created");
2216 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2217 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2218 textureTrace.Reset();
2220 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2221 // 1. Get TextureSet
2222 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2224 // 2.Remove actor from stage. In this case, renderer also is deleted.
2225 tet_infoline("Remove actor from stage");
2226 application.GetScene().Remove(actor);
2227 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2228 application.SendNotification();
2229 application.Render();
2231 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2232 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2233 textureTrace.Reset();
2235 // 3.Add actor in stage. In this case, renderer is created.
2236 tet_infoline("Add actor in stage");
2237 application.GetScene().Add(actor);
2238 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2239 application.SendNotification();
2240 application.Render();
2241 tet_infoline("Ensure a texture is not created again");
2242 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2243 textureTrace.Reset();
2245 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2246 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2247 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2248 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2249 textureSetBefore.Reset();
2250 textureSetAfter.Reset();
2252 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2253 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2254 application.SendNotification();
2255 application.Render();
2256 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2261 int UtcDaliImageVisualLoadPolicy01(void)
2263 ToolkitTestApplication application;
2264 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2266 // Set up trace debug
2267 TestGlAbstraction& gl = application.GetGlAbstraction();
2268 TraceCallStack& textureTrace = gl.GetTextureTrace();
2269 textureTrace.Enable(true);
2271 tet_infoline("Create visual with IMMEDIATE load policy");
2272 VisualFactory factory = VisualFactory::Get();
2274 Property::Map propertyMap;
2275 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2276 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2277 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2278 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2279 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2281 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2283 Property::Map resultMap;
2284 imageVisual.CreatePropertyMap(resultMap);
2285 DALI_TEST_CHECK(!resultMap.Empty());
2286 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2288 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2290 // Ensure texture has been uploaded
2291 application.SendNotification();
2292 application.Render();
2294 tet_infoline("Ensure texture loading starts after visual created");
2295 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2296 textureTrace.Reset();
2298 tet_infoline("Register visuals with control and ensure it has the only handles");
2299 DummyControl actor = DummyControl::New(true);
2300 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2301 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2302 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2304 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2305 application.GetScene().Add(actor);
2306 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2307 const unsigned int TIME_OUT_3_SECONDS = 3;
2308 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2310 application.SendNotification();
2311 application.Render();
2313 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2314 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2316 // Ensure texture is deleted when no longer needed (ref count was correct )
2317 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2319 application.SendNotification();
2320 application.Render();
2322 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2323 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2328 int UtcDaliImageVisualLoadPolicy02(void)
2330 ToolkitTestApplication application;
2331 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2333 // Set up trace debug
2334 TestGlAbstraction& gl = application.GetGlAbstraction();
2335 TraceCallStack& textureTrace = gl.GetTextureTrace();
2336 textureTrace.Enable(true);
2338 tet_infoline("Create visual with IMMEDIATE load policy");
2339 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2341 const unsigned int TIME_OUT_3_SECONDS = 3;
2342 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2344 // Act on meeage queue even although nothing expected to load
2345 application.SendNotification();
2346 application.Render();
2348 tet_infoline("Ensure texture is not generated yet");
2349 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2350 textureTrace.Reset();
2352 tet_infoline("Register visuals with control and ensure it has the only handles");
2353 DummyControl actor = DummyControl::New(true);
2354 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2355 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2356 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2358 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2359 application.GetScene().Add(actor);
2360 tet_infoline("Allow image time to load");
2361 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2363 application.SendNotification();
2364 application.Render();
2366 tet_infoline("Ensure texture generated and renderer created");
2367 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2368 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2370 // Ensure texture is delete when no longer needed
2371 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2373 application.SendNotification();
2374 application.Render();
2376 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2377 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2382 int UtcDaliImageVisualLoadPolicy03(void)
2384 ToolkitTestApplication application;
2385 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2387 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2389 // Set up trace debug
2390 TestGlAbstraction& gl = application.GetGlAbstraction();
2391 TraceCallStack& textureTrace = gl.GetTextureTrace();
2392 textureTrace.Enable(true);
2394 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2395 DummyControl actor = DummyControl::New(true);
2396 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2397 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2398 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2400 tet_infoline("Create visual with IMMEDIATE load policy");
2401 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2403 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2404 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2405 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2407 tet_infoline("Allow image time to load resource");
2408 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2409 application.SendNotification();
2410 application.Render();
2412 // Ensure texture has been uploaded
2413 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2414 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2419 int UtcDaliImageVisualLoadPolicy04(void)
2421 ToolkitTestApplication application;
2422 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2423 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2425 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2427 // Set up trace debug
2428 TestGlAbstraction& gl = application.GetGlAbstraction();
2429 TraceCallStack& textureTrace = gl.GetTextureTrace();
2430 textureTrace.Enable(true);
2432 tet_infoline("Create a control and connect to resource ready signal");
2433 DummyControl actor = DummyControl::New(true);
2434 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2435 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2436 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2438 tet_infoline("Create visual with IMMEDIATE load policy");
2439 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2441 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2442 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2443 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2445 tet_infoline("Allow image time to load");
2446 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2447 application.SendNotification();
2448 application.Render();
2450 tet_infoline("Testing texture is loaded and resource ready signal fired");
2451 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2452 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2454 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2456 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2457 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2458 DummyControl actor2 = DummyControl::New(true);
2459 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2460 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2462 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2463 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2464 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2465 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2466 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2467 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2472 int UtcDaliImageVisualLoadPolicy05(void)
2474 ToolkitTestApplication application;
2475 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2476 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2477 // Set up trace debug
2478 TestGlAbstraction& gl = application.GetGlAbstraction();
2479 TraceCallStack& textureTrace = gl.GetTextureTrace();
2480 textureTrace.Enable(true);
2482 tet_infoline("Create a control and connect to resource ready signal");
2483 DummyControl actor = DummyControl::New(true);
2484 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2485 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2486 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2487 application.GetScene().Add(actor);
2489 tet_infoline("Create visual with ATTACHED load policy");
2490 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2492 tet_infoline("Registering visual allows control to get a signal once loaded");
2493 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2494 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2496 tet_infoline("Allow image time to load");
2497 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2498 application.SendNotification();
2499 application.Render();
2501 tet_infoline("Testing texture is loaded and resource ready signal fired");
2502 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2503 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2505 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2507 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2508 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2509 DummyControl actor2 = DummyControl::New(true);
2510 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2511 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2513 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2514 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2515 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2516 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2517 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2518 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2523 int UtcDaliImageVisualOrientationCorrection(void)
2525 ToolkitTestApplication application;
2526 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2528 VisualFactory factory = VisualFactory::Get();
2529 tet_infoline("Create visual with Orientation correction set OFF");
2530 Property::Map propertyMap;
2531 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2532 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2533 propertyMap.Insert("orientationCorrection", false);
2534 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2536 tet_infoline("Create control for visual, need to loaded it");
2537 DummyControl actor = DummyControl::New(true);
2538 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2539 application.GetScene().Add(actor);
2541 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2542 // Wait for image to load
2543 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2545 Vector2 originalImageSize;
2546 tet_infoline("Get size of original visual to compare later with rotated image");
2547 imageVisual.GetNaturalSize(originalImageSize);
2548 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2549 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2550 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2551 application.SendNotification();
2552 application.Render();
2554 tet_infoline("Create visual with Orientation correction set ON ");
2555 propertyMap.Clear();
2556 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2557 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2558 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2559 imageVisual = factory.CreateVisual(propertyMap);
2561 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2562 // Wait for image to load
2563 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2565 Vector2 rotatedImageSize;
2566 imageVisual.GetNaturalSize(rotatedImageSize);
2567 tet_infoline("Confirm that visual has rotated");
2568 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2569 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2571 Property::Map resultMap;
2572 imageVisual.CreatePropertyMap(resultMap);
2574 // check the Property::ORIENTATION_CORRECTION value from the returned map
2575 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2576 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2581 int UtcDaliImageVisualCustomShader(void)
2583 ToolkitTestApplication application;
2584 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2586 VisualFactory factory = VisualFactory::Get();
2587 Property::Map properties;
2588 Property::Map shader;
2589 const std::string vertexShader = "Foobar";
2590 const std::string fragmentShader = "Foobar";
2591 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2592 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2594 properties[Visual::Property::TYPE] = Visual::IMAGE;
2595 properties[Visual::Property::SHADER] = shader;
2596 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2598 Visual::Base visual = factory.CreateVisual(properties);
2600 // trigger creation through setting on stage
2601 DummyControl dummy = DummyControl::New(true);
2602 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2603 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2605 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2606 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2607 application.GetScene().Add(dummy);
2609 application.SendNotification();
2610 application.Render();
2612 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2614 Renderer renderer = dummy.GetRendererAt(0);
2615 Shader shader2 = renderer.GetShader();
2616 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2617 Property::Map* map = value.GetMap();
2618 DALI_TEST_CHECK(map);
2620 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2621 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2623 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2624 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2628 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2629 properties[Visual::Property::SHADER] = shader;
2631 Visual::Base visual1 = factory.CreateVisual(properties);
2633 // trigger creation through setting on stage
2634 DummyControl dummy1 = DummyControl::New(true);
2635 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2636 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2637 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2638 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2639 application.GetScene().Add(dummy1);
2641 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2642 glAbstraction.EnableEnableDisableCallTrace(true);
2644 application.SendNotification();
2645 application.Render();
2647 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2648 std::ostringstream blendStr;
2649 blendStr << std::hex << GL_BLEND;
2650 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2655 void ResourceReadyLoadNext(Control control)
2657 static int callNumber = 0;
2659 gResourceReadySignalFired = true;
2660 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2664 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2666 tet_infoline("Create visual with loaded image from within the signal handler");
2667 VisualFactory factory = VisualFactory::Get();
2668 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2670 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2671 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2676 tet_infoline("3rd signal called");
2677 DALI_TEST_CHECK(true);
2681 int UtcDaliImageVisualLoadReady01(void)
2683 ToolkitTestApplication application;
2684 tet_infoline("UtcDaliImageVisualLoadReady01");
2685 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2686 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2687 tet_infoline("Should get a ready signal for all three visuals");
2691 tet_infoline("Create a control and connect to resource ready signal");
2692 DummyControl actor = DummyControl::New(true);
2693 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2694 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2695 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2696 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2697 application.GetScene().Add(actor);
2699 tet_infoline("Create visual with IMMEDIATE load policy");
2700 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2702 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2703 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2705 tet_infoline("Allow image time to load");
2706 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2707 application.SendNotification();
2708 application.Render();
2710 tet_infoline("Testing texture is loaded and resource ready signal fired");
2711 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2712 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2714 tet_infoline("Original control correctly signalled, now testing failing image");
2716 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2719 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2721 DummyControl actor2 = DummyControl::New(true);
2722 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2723 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2724 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2726 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2727 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2729 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2730 application.GetScene().Add(actor2);
2732 tet_infoline("Wait for loading thread to finish");
2733 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2734 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2736 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2738 tet_infoline("Check for 3rd signal");
2739 application.SendNotification();
2740 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2741 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);