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 <test-encoded-image-buffer.h>
36 #include "dummy-control.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);
730 "Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
731 "draw calls use the same texture as the previous draw call\n");
733 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
734 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
735 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
736 // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
738 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
740 application.GetScene().Remove(actor);
741 application.SendNotification();
742 application.Render();
744 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
745 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
747 tet_infoline("Test that removing last actor does delete the texture\n");
749 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
750 application.SendNotification();
751 application.Render();
753 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
754 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
759 int UtcDaliImageVisualTextureReuse2(void)
761 ToolkitTestApplication application;
762 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture");
764 Property::Map propertyMap;
765 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
766 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
768 TestGlAbstraction& gl = application.GetGlAbstraction();
769 TraceCallStack& textureTrace = gl.GetTextureTrace();
770 textureTrace.Enable(true);
771 TraceCallStack& drawTrace = gl.GetDrawTrace();
772 drawTrace.Enable(true);
774 Actor actor = CreateActorWithImageVisual(propertyMap);
775 application.GetScene().Add(actor);
776 application.SendNotification();
778 // Wait for image to load
779 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
781 application.SendNotification();
782 application.Render();
784 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
785 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
786 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
787 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
788 textureTrace.Reset();
791 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
792 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
793 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
794 Actor actor2 = CreateActorWithImageVisual(propertyMap);
795 application.GetScene().Add(actor2);
797 application.SendNotification();
799 // Wait for image to load
800 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
802 application.SendNotification();
803 application.Render();
805 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
808 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
809 "renderers are using different textures\n");
811 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
812 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
813 TraceCallStack::NamedParams tex1;
814 tex1["texture"] << 1;
815 TraceCallStack::NamedParams tex2;
816 tex2["texture"] << 2;
817 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
818 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
820 tet_infoline("Test that removing 1 actor deletes it's texture\n");
822 application.GetScene().Remove(actor);
823 application.SendNotification();
824 application.Render();
826 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
827 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
829 tet_infoline("Test that removing last actor deletes it's texture\n");
831 application.GetScene().Remove(actor2);
832 application.SendNotification();
833 application.Render();
835 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
836 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
841 int UtcDaliImageVisualCustomWrapModePixelArea(void)
843 ToolkitTestApplication application;
844 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
846 static std::vector<UniformData> customUniforms =
848 UniformData("pixelArea", Property::Type::VECTOR4),
849 UniformData("wrapMode", Property::Type::VECTOR2),
852 TestGraphicsController& graphics = application.GetGraphicsController();
853 graphics.AddCustomUniforms(customUniforms);
855 VisualFactory factory = VisualFactory::Get();
856 DALI_TEST_CHECK(factory);
858 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
859 const int width = 34;
860 const int height = 34;
861 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
863 Property::Map propertyMap;
864 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
865 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
866 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
867 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
868 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
869 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
870 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
871 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
872 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
874 Visual::Base visual = factory.CreateVisual(propertyMap);
875 DALI_TEST_CHECK(visual);
877 TestGlAbstraction& gl = application.GetGlAbstraction();
878 TraceCallStack& textureTrace = gl.GetTextureTrace();
879 textureTrace.Enable(true);
880 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
881 texParameterTrace.Enable(true);
883 DummyControl actor = DummyControl::New();
884 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
885 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
886 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
887 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
888 application.GetScene().Add(actor);
891 application.SendNotification();
892 application.Render();
894 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
896 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
898 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
899 std::stringstream out;
900 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
901 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
903 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
904 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
906 // test the uniforms which used to handle the wrap mode
907 Renderer renderer = actor.GetRendererAt(0u);
908 DALI_TEST_CHECK(renderer);
910 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
911 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
912 Vector4 pixelAreaUniform;
913 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
914 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
916 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
917 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
918 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
919 Vector2 wrapModeUniform;
920 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
921 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
924 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
929 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
931 ToolkitTestApplication application;
932 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
934 static std::vector<UniformData> customUniforms =
936 UniformData("pixelArea", Property::Type::VECTOR4),
939 TestGraphicsController& graphics = application.GetGraphicsController();
940 graphics.AddCustomUniforms(customUniforms);
942 VisualFactory factory = VisualFactory::Get();
943 DALI_TEST_CHECK(factory);
945 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
946 const int width = 600;
947 const int height = 600;
948 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
950 Property::Map propertyMap;
951 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
952 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
953 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
954 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
955 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
956 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
957 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
958 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
960 Visual::Base visual = factory.CreateVisual(propertyMap);
961 DALI_TEST_CHECK(visual);
963 TestGlAbstraction& gl = application.GetGlAbstraction();
964 TraceCallStack& textureTrace = gl.GetTextureTrace();
965 textureTrace.Enable(true);
966 textureTrace.EnableLogging(true);
967 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
968 texParameterTrace.Enable(true);
969 texParameterTrace.EnableLogging(true);
971 DummyControl actor = DummyControl::New();
972 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
973 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
974 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
975 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
976 application.GetScene().Add(actor);
979 application.SendNotification();
980 application.Render();
981 application.SendNotification();
983 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
985 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
987 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
988 std::stringstream out;
989 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
990 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
992 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
993 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
995 // test the uniforms which used to handle the wrap mode
996 Renderer renderer = actor.GetRendererAt(0u);
997 DALI_TEST_CHECK(renderer);
999 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1000 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1001 Vector4 pixelAreaUniform;
1002 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1003 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1005 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1006 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1009 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1014 int UtcDaliImageVisualAnimateMixColor(void)
1016 ToolkitTestApplication application;
1017 tet_infoline("Animate mix color");
1019 static std::vector<UniformData> customUniforms =
1021 UniformData("mixColor", Property::Type::VECTOR3),
1024 TestGraphicsController& graphics = application.GetGraphicsController();
1025 graphics.AddCustomUniforms(customUniforms);
1027 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1029 VisualFactory factory = VisualFactory::Get();
1030 Property::Map propertyMap;
1031 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1032 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1033 propertyMap.Insert("mixColor", Color::BLUE);
1034 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1035 Visual::Base visual = factory.CreateVisual(propertyMap);
1037 DummyControl actor = DummyControl::New(true);
1038 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1039 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1041 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1042 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1043 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1044 application.GetScene().Add(actor);
1046 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1048 Renderer renderer = actor.GetRendererAt(0);
1050 // @todo Should we add API to make this code work again?
1051 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1053 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1054 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1056 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1059 map["target"] = "testVisual";
1060 map["property"] = "mixColor";
1061 map["initialValue"] = Color::MAGENTA;
1062 map["targetValue"] = TARGET_MIX_COLOR;
1063 map["animator"] = Property::Map()
1064 .Add("alphaFunction", "LINEAR")
1065 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1067 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1069 Animation animation = dummyImpl.CreateTransition(transition);
1071 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1074 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1075 glAbstraction.EnableEnableDisableCallTrace(true);
1076 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1077 std::ostringstream blendStr;
1078 blendStr << std::hex << GL_BLEND;
1080 application.SendNotification();
1081 application.Render(0); // Ensure animation starts
1082 application.Render(2000u); // Halfway point
1083 Vector3 testColor(1.0f, 0.0f, 0.5f);
1085 // uColor.a should be actor's alpha * mixColor.a.
1086 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1087 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1089 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1091 glEnableStack.Reset();
1093 application.SendNotification();
1094 application.Render(2000u);
1096 application.SendNotification();
1097 application.Render();
1098 application.SendNotification();
1100 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1101 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1102 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1104 // GL_BLEND should not be changed: Keep enabled
1105 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1106 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1107 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1109 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1114 int UtcDaliImageVisualAnimateOpacity(void)
1116 ToolkitTestApplication application;
1117 tet_infoline("Animate image visual opacity");
1119 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1121 VisualFactory factory = VisualFactory::Get();
1122 Property::Map propertyMap;
1123 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1124 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1125 propertyMap.Insert("opacity", 0.5f);
1126 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1127 Visual::Base visual = factory.CreateVisual(propertyMap);
1129 DummyControl actor = DummyControl::New(true);
1130 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1131 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1133 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1134 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1135 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1136 application.GetScene().Add(actor);
1138 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1140 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1141 glAbstraction.EnableEnableDisableCallTrace(true);
1142 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1143 std::ostringstream blendStr;
1144 blendStr << std::hex << GL_BLEND;
1146 application.SendNotification();
1147 application.Render();
1149 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1152 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.");
1155 map["target"] = "testVisual";
1156 map["property"] = "opacity";
1157 map["targetValue"] = 1.0f;
1158 map["animator"] = Property::Map()
1159 .Add("alphaFunction", "LINEAR")
1160 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1162 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1163 Animation animation = dummyImpl.CreateTransition(transition);
1166 glEnableStack.Reset();
1168 application.SendNotification();
1169 application.Render(0); // Ensure animation starts
1170 application.Render(2000u); // Halfway point through animation
1171 application.SendNotification(); // Handle any signals
1174 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1175 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1177 application.Render(2001u); // end
1178 application.SendNotification(); // ensure animation finished signal is sent
1180 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1181 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1183 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1184 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1185 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1189 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.");
1192 map["target"] = "testVisual";
1193 map["property"] = Visual::Property::OPACITY;
1194 map["targetValue"] = 0.1f;
1195 map["animator"] = Property::Map()
1196 .Add("alphaFunction", "LINEAR")
1197 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1199 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1200 Animation animation = dummyImpl.CreateTransition(transition);
1203 glEnableStack.Reset();
1205 application.SendNotification();
1206 application.Render(0); // Ensure animation starts
1207 application.Render(2000u); // Halfway point
1208 application.SendNotification();
1211 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1212 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1214 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1216 glEnableStack.Reset();
1218 application.Render(2016u); // end
1219 application.SendNotification();
1221 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1222 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1224 // GL_BLEND should not be changed: Keep enabled
1226 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1227 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1228 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1234 int UtcDaliImageVisualAnimateOpacity02(void)
1236 ToolkitTestApplication application;
1237 tet_infoline("Animate image visual opacity");
1239 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1241 VisualFactory factory = VisualFactory::Get();
1242 Property::Map propertyMap;
1243 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1244 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1245 propertyMap.Insert("opacity", 0.5f);
1246 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1247 Visual::Base visual = factory.CreateVisual(propertyMap);
1249 DummyControl actor = DummyControl::New(true);
1250 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1251 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1253 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1254 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1255 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1257 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1259 Property::Array array;
1262 map["target"] = "testVisual";
1263 map["property"] = "opacity";
1264 map["initialValue"] = 0.0f;
1265 map["targetValue"] = 1.0f;
1266 map["animator"] = Property::Map()
1267 .Add("alphaFunction", "LINEAR")
1268 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1271 map2["target"] = "testVisual";
1272 map2["property"] = "size";
1273 map2["targetValue"] = Vector2(1.0f, 1.0f);
1275 array.Add(map).Add(map2);
1277 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1278 Animation animation = dummyImpl.CreateTransition(transition);
1280 application.GetScene().Add(actor);
1281 application.SendNotification();
1282 application.Render(0); // Ensure animation starts
1284 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1286 Renderer renderer = actor.GetRendererAt(0);
1287 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1288 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1290 animation = dummyImpl.CreateTransition(transition);
1293 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1294 glAbstraction.EnableEnableDisableCallTrace(true);
1295 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1296 std::ostringstream blendStr;
1297 blendStr << std::hex << GL_BLEND;
1299 application.SendNotification();
1300 application.Render(0); // Ensure animation starts
1301 application.Render(2000u); // Halfway point through animation
1302 application.SendNotification(); // Handle any signals
1304 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1307 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1308 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1310 glEnableStack.Reset();
1312 application.Render(2001u); // end
1313 application.SendNotification(); // ensure animation finished signal is sent
1315 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1316 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1318 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1323 int UtcDaliImageVisualAnimatePixelArea(void)
1325 ToolkitTestApplication application;
1326 tet_infoline("ImageVisual animate pixel area");
1328 static std::vector<UniformData> customUniforms =
1330 UniformData("pixelArea", Property::Type::VECTOR4),
1333 TestGraphicsController& graphics = application.GetGraphicsController();
1334 graphics.AddCustomUniforms(customUniforms);
1336 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1338 VisualFactory factory = VisualFactory::Get();
1339 Property::Map propertyMap;
1340 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1341 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1342 propertyMap.Insert("mixColor", Color::BLUE);
1343 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1344 Visual::Base visual = factory.CreateVisual(propertyMap);
1346 DummyControl actor = DummyControl::New(true);
1347 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1348 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1350 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1351 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1352 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1353 application.GetScene().Add(actor);
1355 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1357 Renderer renderer = actor.GetRendererAt(0);
1358 // @todo Implement this feature?
1359 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1360 //tet_infoline("Test that the renderer has the mixColor property");
1361 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1363 // TransitionData only takes string keys
1365 map["target"] = "testVisual";
1366 map["property"] = "pixelArea";
1367 map["initialValue"] = Vector4(0, 0, 0, 1);
1368 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1369 map["animator"] = Property::Map()
1370 .Add("alphaFunction", "LINEAR")
1371 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1373 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1375 Animation animation = dummyImpl.CreateTransition(transition);
1376 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1379 application.SendNotification();
1380 application.Render(0); // Ensure animation starts
1381 application.Render(2000u); // Halfway point
1383 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1385 application.Render(2000u); // End of animation
1387 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1392 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1394 ToolkitTestApplication application;
1395 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1397 Property::Map propertyMap;
1398 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1399 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1401 TestGlAbstraction& gl = application.GetGlAbstraction();
1402 TraceCallStack& textureTrace = gl.GetTextureTrace();
1403 textureTrace.Enable(true);
1404 TraceCallStack& drawTrace = gl.GetDrawTrace();
1405 drawTrace.Enable(true);
1407 Actor actor = CreateActorWithImageVisual(propertyMap);
1408 application.GetScene().Add(actor);
1409 application.SendNotification();
1411 application.GetScene().Remove(actor);
1412 application.SendNotification();
1414 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1415 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1416 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1417 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1422 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1424 ToolkitTestApplication application;
1425 tet_infoline("Load image asynchronously, cancel loading, then load again");
1427 VisualFactory factory = VisualFactory::Get();
1428 DALI_TEST_CHECK(factory);
1430 Property::Map propertyMap;
1431 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1432 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1434 Visual::Base visual = factory.CreateVisual(propertyMap);
1435 DALI_TEST_CHECK(visual);
1437 TestGlAbstraction& gl = application.GetGlAbstraction();
1438 TraceCallStack& textureTrace = gl.GetTextureTrace();
1439 textureTrace.Enable(true);
1440 TraceCallStack& drawTrace = gl.GetDrawTrace();
1441 drawTrace.Enable(true);
1443 DummyControl actor = DummyControl::New();
1444 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1445 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1447 application.GetScene().Add(actor);
1450 application.GetScene().Remove(actor);
1452 application.GetScene().Add(actor);
1454 // Create another visual with the same image
1455 visual = factory.CreateVisual(propertyMap);
1456 DALI_TEST_CHECK(visual);
1458 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1460 application.SendNotification();
1461 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1463 application.SendNotification();
1464 application.Render();
1466 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1467 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1468 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1469 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1474 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1476 ToolkitTestApplication application;
1477 tet_infoline("Request image visual with invalid images - should draw broken.png");
1479 VisualFactory factory = VisualFactory::Get();
1480 DALI_TEST_CHECK(factory);
1482 Property::Map propertyMap;
1483 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1484 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1486 Visual::Base visual = factory.CreateVisual(propertyMap);
1487 DALI_TEST_CHECK(visual);
1489 TestGlAbstraction& gl = application.GetGlAbstraction();
1490 TraceCallStack& textureTrace = gl.GetTextureTrace();
1491 textureTrace.Enable(true);
1493 DummyControl actor = DummyControl::New();
1494 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1495 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1497 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1498 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1500 application.GetScene().Add(actor);
1502 application.SendNotification();
1503 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1505 application.SendNotification();
1506 application.Render();
1508 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1509 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1511 application.GetScene().Remove(actor);
1512 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1517 int UtcDaliImageVisualSetInvalidSyncImage(void)
1519 ToolkitTestApplication application;
1520 tet_infoline("Request image visual with invalid images - should draw broken.png");
1522 VisualFactory factory = VisualFactory::Get();
1523 DALI_TEST_CHECK(factory);
1525 Property::Map propertyMap;
1526 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1527 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1528 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1530 Visual::Base visual = factory.CreateVisual(propertyMap);
1531 DALI_TEST_CHECK(visual);
1533 TestGlAbstraction& gl = application.GetGlAbstraction();
1534 TraceCallStack& textureTrace = gl.GetTextureTrace();
1535 textureTrace.Enable(true);
1537 DummyControl actor = DummyControl::New();
1538 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1539 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1541 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1542 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1544 application.GetScene().Add(actor);
1546 application.SendNotification();
1547 application.Render();
1549 // Check resource status
1550 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1551 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1553 // The broken image should be shown.
1554 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1555 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1557 application.GetScene().Remove(actor);
1558 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1563 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1565 ToolkitTestApplication application;
1566 tet_infoline("Request image visual with invalid images - should draw broken.png");
1568 VisualFactory factory = VisualFactory::Get();
1569 DALI_TEST_CHECK(factory);
1571 // Local invalid file, asynchronous loading
1572 Property::Map propertyMap;
1573 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1574 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1576 Visual::Base visual = factory.CreateVisual(propertyMap);
1577 DALI_TEST_CHECK(visual);
1579 TestGlAbstraction& gl = application.GetGlAbstraction();
1580 TraceCallStack& textureTrace = gl.GetTextureTrace();
1581 textureTrace.Enable(true);
1583 DummyControl actor = DummyControl::New();
1584 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1585 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1587 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1588 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1590 application.GetScene().Add(actor);
1592 application.SendNotification();
1593 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1595 application.SendNotification();
1596 application.Render();
1598 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1599 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1601 application.GetScene().Remove(actor);
1602 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1607 int UtcDaliImageVisualAlphaMask(void)
1609 ToolkitTestApplication application;
1610 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1612 VisualFactory factory = VisualFactory::Get();
1613 DALI_TEST_CHECK(factory);
1615 Property::Map propertyMap;
1616 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1617 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1618 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1620 Visual::Base visual = factory.CreateVisual(propertyMap);
1621 DALI_TEST_CHECK(visual);
1623 Property::Map testMap;
1624 visual.CreatePropertyMap(testMap);
1625 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1627 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1628 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1630 TestGlAbstraction& gl = application.GetGlAbstraction();
1631 TraceCallStack& textureTrace = gl.GetTextureTrace();
1632 textureTrace.Enable(true);
1634 DummyControl actor = DummyControl::New();
1635 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1636 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1638 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1639 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1640 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1642 application.GetScene().Add(actor);
1643 application.SendNotification();
1644 application.Render();
1646 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1648 application.SendNotification();
1649 application.Render();
1651 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1652 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1653 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1655 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1656 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1661 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1663 ToolkitTestApplication application;
1664 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
1666 VisualFactory factory = VisualFactory::Get();
1667 DALI_TEST_CHECK(factory);
1669 Property::Map propertyMap;
1670 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1671 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1672 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1673 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1675 Visual::Base visual = factory.CreateVisual(propertyMap);
1676 DALI_TEST_CHECK(visual);
1678 Property::Map testMap;
1679 visual.CreatePropertyMap(testMap);
1680 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1682 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1683 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1685 TestGlAbstraction& gl = application.GetGlAbstraction();
1686 TraceCallStack& textureTrace = gl.GetTextureTrace();
1687 textureTrace.Enable(true);
1689 DummyControl actor = DummyControl::New();
1690 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1691 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1693 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1694 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1695 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1697 application.GetScene().Add(actor);
1699 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1701 application.SendNotification();
1702 application.Render();
1704 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1705 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1706 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1708 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1709 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1714 int UtcDaliImageVisualRemoteAlphaMask(void)
1716 ToolkitTestApplication application;
1717 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1719 VisualFactory factory = VisualFactory::Get();
1720 DALI_TEST_CHECK(factory);
1722 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1724 Property::Map propertyMap;
1725 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1726 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1727 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
1729 Visual::Base visual = factory.CreateVisual(propertyMap);
1730 DALI_TEST_CHECK(visual);
1732 Property::Map testMap;
1733 visual.CreatePropertyMap(testMap);
1735 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
1737 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1738 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1740 TestGlAbstraction& gl = application.GetGlAbstraction();
1741 TraceCallStack& textureTrace = gl.GetTextureTrace();
1742 textureTrace.Enable(true);
1744 DummyControl actor = DummyControl::New();
1745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1748 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1750 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1751 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1753 application.GetScene().Add(actor);
1754 application.SendNotification();
1755 application.Render();
1757 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1759 application.SendNotification();
1760 application.Render();
1762 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1763 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1764 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1769 int UtcDaliImageVisualAlphaMaskCrop(void)
1771 ToolkitTestApplication application;
1772 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
1774 VisualFactory factory = VisualFactory::Get();
1775 DALI_TEST_CHECK(factory);
1777 Property::Map propertyMap;
1778 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1779 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1780 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1781 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
1782 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
1784 Visual::Base visual = factory.CreateVisual(propertyMap);
1785 DALI_TEST_CHECK(visual);
1787 Property::Map testMap;
1788 visual.CreatePropertyMap(testMap);
1789 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1790 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
1791 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
1793 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1794 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1796 TestGlAbstraction& gl = application.GetGlAbstraction();
1797 TraceCallStack& textureTrace = gl.GetTextureTrace();
1798 textureTrace.Enable(true);
1800 DummyControl actor = DummyControl::New();
1801 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1802 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1804 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1805 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1806 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1808 application.GetScene().Add(actor);
1809 application.SendNotification();
1810 application.Render();
1812 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1814 application.SendNotification();
1815 application.Render();
1818 visual.GetNaturalSize(size);
1820 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
1821 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1822 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1823 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1828 int UtcDaliImageVisualReleasePolicy01(void)
1830 ToolkitTestApplication application;
1831 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
1833 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1834 DALI_TEST_CHECK(imageVisual);
1836 // Set up debug trace
1837 TestGlAbstraction& gl = application.GetGlAbstraction();
1838 TraceCallStack& textureTrace = gl.GetTextureTrace();
1839 textureTrace.Enable(true);
1841 tet_infoline("Register visual with control and ensure it has the only handle");
1842 DummyControl actor = DummyControl::New(true);
1843 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1844 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1845 imageVisual.Reset();
1847 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1849 application.SendNotification();
1850 application.Render(0);
1851 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1852 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1854 application.GetScene().Add(actor);
1856 // Wait for image to load
1857 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1859 application.SendNotification();
1860 application.Render(0);
1861 // Test renderer and texture created
1862 tet_infoline("Confirm texture created");
1863 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1864 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1866 tet_infoline("Disable visual causing the texture to be deleted");
1867 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
1869 application.SendNotification();
1870 application.Render(0);
1871 // Test renderer and textures removed.
1872 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1873 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1878 int UtcDaliImageVisualReleasePolicy02(void)
1880 ToolkitTestApplication application;
1881 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
1883 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
1884 DALI_TEST_CHECK(imageVisual);
1886 // Setup debug trace
1887 TestGlAbstraction& gl = application.GetGlAbstraction();
1888 TraceCallStack& textureTrace = gl.GetTextureTrace();
1889 textureTrace.Enable(true);
1891 tet_infoline("Register visual with control and ensure it has the only handle");
1892 DummyControl actor = DummyControl::New(true);
1893 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1894 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1895 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1897 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1899 application.SendNotification();
1900 application.Render(0);
1901 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1902 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1904 application.GetScene().Add(actor);
1906 // Wait for image to load
1907 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1909 application.SendNotification();
1910 application.Render(0);
1911 // Test renderer and texture created
1912 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1913 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1915 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1916 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
1917 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1918 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1919 application.SendNotification();
1920 application.Render();
1922 // Test texture removed after visual destroyed.
1923 tet_infoline("Ensure texture is deleted after visual destroyed");
1924 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1929 int UtcDaliImageVisualReleasePolicy03(void)
1931 ToolkitTestApplication application;
1932 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
1934 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
1935 DALI_TEST_CHECK(imageVisual);
1937 TestGlAbstraction& gl = application.GetGlAbstraction();
1938 TraceCallStack& textureTrace = gl.GetTextureTrace();
1939 textureTrace.Enable(true);
1941 tet_infoline("Register visual with control and ensure it has the only handle");
1942 DummyControl actor = DummyControl::New(true);
1943 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1944 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
1945 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1947 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1949 application.SendNotification();
1950 application.Render(0);
1951 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1952 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1954 application.GetScene().Add(actor);
1956 // Wait for image to load
1957 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1959 application.SendNotification();
1960 application.Render(0);
1961 // Test renderer and texture created
1962 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1963 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1965 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
1966 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1967 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1968 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1969 application.SendNotification();
1970 application.Render();
1972 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
1973 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1978 int UtcDaliImageVisualReleasePolicy04(void)
1980 ToolkitTestApplication application;
1981 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
1983 tet_infoline("Create first visual with Never release policy");
1984 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
1986 tet_infoline("Create second visual with Destroyed release policy");
1987 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
1989 // Set up trace debug
1990 TestGlAbstraction& gl = application.GetGlAbstraction();
1991 TraceCallStack& textureTrace = gl.GetTextureTrace();
1992 textureTrace.Enable(true);
1994 tet_infoline("Register visuals with control and ensure it has the only handles");
1995 DummyControl actor = DummyControl::New(true);
1996 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1997 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
1998 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
1999 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2000 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2002 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2004 // Test initially zero renderers
2005 application.SendNotification();
2006 application.Render(0);
2007 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2008 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2010 application.GetScene().Add(actor);
2012 // Wait for image to load
2013 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2015 application.SendNotification();
2016 application.Render(0);
2017 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2018 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2019 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2021 // Test renderer removed when visual destroyed
2022 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2023 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2024 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2025 application.SendNotification();
2026 application.Render();
2028 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2029 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2031 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2032 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2033 application.SendNotification();
2034 application.Render();
2036 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2037 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2038 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2043 int UtcDaliImageVisualReleasePolicy05(void)
2045 ToolkitTestApplication application;
2046 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2048 VisualFactory factory = VisualFactory::Get();
2050 Property::Map propertyMapNeverReleasePolicy;
2051 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2052 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2053 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2054 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2055 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2057 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2059 Property::Map resultMap;
2060 imageVisualNever.CreatePropertyMap(resultMap);
2061 DALI_TEST_CHECK(!resultMap.Empty());
2063 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2068 int UtcDaliImageVisualReleasePolicy06(void)
2070 ToolkitTestApplication application;
2071 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2073 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2074 DALI_TEST_CHECK(imageVisual);
2076 TestGlAbstraction& gl = application.GetGlAbstraction();
2077 TraceCallStack& textureTrace = gl.GetTextureTrace();
2078 textureTrace.Enable(true);
2080 tet_infoline("Register visual with control and ensure it has the only handle");
2081 DummyControl actor = DummyControl::New(true);
2082 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2083 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2084 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2086 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2088 application.SendNotification();
2089 application.Render(0);
2090 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2091 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2093 application.GetScene().Add(actor);
2095 // Wait for image to load
2096 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2098 application.SendNotification();
2099 application.Render(0);
2100 // Test renderer and texture created
2101 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2102 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2103 textureTrace.Reset();
2105 tet_infoline("Disable Visual and check texture not affected");
2106 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2107 application.SendNotification();
2108 application.Render(0);
2109 tet_infoline("Check renderer is destroyed when visual off stage");
2110 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2111 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2112 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2113 textureTrace.Reset();
2115 tet_infoline("Re-enable Visual and check texture not affected");
2116 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2117 application.SendNotification();
2118 application.Render(0);
2119 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2120 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2121 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2122 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2127 int UtcDaliImageVisualReleasePolicy07(void)
2129 ToolkitTestApplication application;
2130 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2132 tet_infoline("Create first visual with DESTROYED release policy");
2133 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2135 tet_infoline("Create second visual with DETACHED release policy");
2136 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2138 // Set up trace debug
2139 TestGlAbstraction& gl = application.GetGlAbstraction();
2140 TraceCallStack& textureTrace = gl.GetTextureTrace();
2141 textureTrace.Enable(true);
2143 tet_infoline("Register visuals with control and ensure it has the only handles");
2144 DummyControl actor = DummyControl::New(true);
2145 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2146 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2147 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2148 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2149 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2151 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2153 // Test initially zero renderers
2154 application.SendNotification();
2155 application.Render(0);
2156 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2157 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2159 application.GetScene().Add(actor);
2161 // Wait for image to load
2162 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2164 application.SendNotification();
2165 application.Render(0);
2166 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2167 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2168 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2170 // Test renderer removed when visual destroyed
2171 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2172 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2173 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2174 application.SendNotification();
2175 application.Render();
2177 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2178 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2180 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2181 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2182 application.SendNotification();
2183 application.Render();
2185 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2186 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2191 int UtcDaliImageVisualReleasePolicy08(void)
2193 ToolkitTestApplication application;
2194 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2196 tet_infoline("Create first visual with DESTROYED release policy");
2197 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2199 // Set up trace debug
2200 TestGlAbstraction& gl = application.GetGlAbstraction();
2201 TraceCallStack& textureTrace = gl.GetTextureTrace();
2202 textureTrace.Enable(true);
2204 tet_infoline("Register visuals with control and ensure it has the only handles");
2205 DummyControl actor = DummyControl::New(true);
2206 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2207 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2208 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2210 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2212 // Test initially zero renderers
2213 application.SendNotification();
2214 application.Render(0);
2215 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2216 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2217 textureTrace.Reset();
2219 application.GetScene().Add(actor);
2221 // Wait for image to load
2222 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2224 application.SendNotification();
2225 application.Render(0);
2226 tet_infoline("Ensure a texture is created");
2227 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2228 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2229 textureTrace.Reset();
2231 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2232 // 1. Get TextureSet
2233 TextureSet textureSetBefore = actor.GetRendererAt(0u).GetTextures();
2235 // 2.Remove actor from stage. In this case, renderer also is deleted.
2236 tet_infoline("Remove actor from stage");
2237 application.GetScene().Remove(actor);
2238 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2239 application.SendNotification();
2240 application.Render();
2242 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2243 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2244 textureTrace.Reset();
2246 // 3.Add actor in stage. In this case, renderer is created.
2247 tet_infoline("Add actor in stage");
2248 application.GetScene().Add(actor);
2249 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2250 application.SendNotification();
2251 application.Render();
2252 tet_infoline("Ensure a texture is not created again");
2253 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2254 textureTrace.Reset();
2256 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2257 tet_infoline("Ensure a textureSet is not deleted because it is used the DESTROYED release policy");
2258 TextureSet textureSetAfter = actor.GetRendererAt(0u).GetTextures();
2259 DALI_TEST_CHECK(textureSetBefore == textureSetAfter);
2260 textureSetBefore.Reset();
2261 textureSetAfter.Reset();
2263 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2264 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2265 application.SendNotification();
2266 application.Render();
2267 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2272 int UtcDaliImageVisualLoadPolicy01(void)
2274 ToolkitTestApplication application;
2275 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2277 // Set up trace debug
2278 TestGlAbstraction& gl = application.GetGlAbstraction();
2279 TraceCallStack& textureTrace = gl.GetTextureTrace();
2280 textureTrace.Enable(true);
2282 tet_infoline("Create visual with IMMEDIATE load policy");
2283 VisualFactory factory = VisualFactory::Get();
2285 Property::Map propertyMap;
2286 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2287 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2288 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2289 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2290 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2292 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2294 Property::Map resultMap;
2295 imageVisual.CreatePropertyMap(resultMap);
2296 DALI_TEST_CHECK(!resultMap.Empty());
2297 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2299 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2301 // Ensure texture has been uploaded
2302 application.SendNotification();
2303 application.Render();
2305 tet_infoline("Ensure texture loading starts after visual created");
2306 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2307 textureTrace.Reset();
2309 tet_infoline("Register visuals with control and ensure it has the only handles");
2310 DummyControl actor = DummyControl::New(true);
2311 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2312 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2313 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2315 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2316 application.GetScene().Add(actor);
2317 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2318 const unsigned int TIME_OUT_3_SECONDS = 3;
2319 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2321 application.SendNotification();
2322 application.Render();
2324 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2325 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2327 // Ensure texture is deleted when no longer needed (ref count was correct )
2328 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2330 application.SendNotification();
2331 application.Render();
2333 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2334 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2339 int UtcDaliImageVisualLoadPolicy02(void)
2341 ToolkitTestApplication application;
2342 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2344 // Set up trace debug
2345 TestGlAbstraction& gl = application.GetGlAbstraction();
2346 TraceCallStack& textureTrace = gl.GetTextureTrace();
2347 textureTrace.Enable(true);
2349 tet_infoline("Create visual with IMMEDIATE load policy");
2350 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2352 const unsigned int TIME_OUT_3_SECONDS = 3;
2353 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2355 // Act on meeage queue even although nothing expected to load
2356 application.SendNotification();
2357 application.Render();
2359 tet_infoline("Ensure texture is not generated yet");
2360 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2361 textureTrace.Reset();
2363 tet_infoline("Register visuals with control and ensure it has the only handles");
2364 DummyControl actor = DummyControl::New(true);
2365 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2366 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2367 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2369 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2370 application.GetScene().Add(actor);
2371 tet_infoline("Allow image time to load");
2372 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2374 application.SendNotification();
2375 application.Render();
2377 tet_infoline("Ensure texture generated and renderer created");
2378 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2379 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2381 // Ensure texture is delete when no longer needed
2382 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2384 application.SendNotification();
2385 application.Render();
2387 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2388 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2393 int UtcDaliImageVisualLoadPolicy03(void)
2395 ToolkitTestApplication application;
2396 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2398 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2400 // Set up trace debug
2401 TestGlAbstraction& gl = application.GetGlAbstraction();
2402 TraceCallStack& textureTrace = gl.GetTextureTrace();
2403 textureTrace.Enable(true);
2405 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2406 DummyControl actor = DummyControl::New(true);
2407 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2408 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2409 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2411 tet_infoline("Create visual with IMMEDIATE load policy");
2412 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2414 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2415 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2416 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2418 tet_infoline("Allow image time to load resource");
2419 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2420 application.SendNotification();
2421 application.Render();
2423 // Ensure texture has been uploaded
2424 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2425 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2430 int UtcDaliImageVisualLoadPolicy04(void)
2432 ToolkitTestApplication application;
2433 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2434 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2436 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2438 // Set up trace debug
2439 TestGlAbstraction& gl = application.GetGlAbstraction();
2440 TraceCallStack& textureTrace = gl.GetTextureTrace();
2441 textureTrace.Enable(true);
2443 tet_infoline("Create a control and connect to resource ready signal");
2444 DummyControl actor = DummyControl::New(true);
2445 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2446 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2447 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2449 tet_infoline("Create visual with IMMEDIATE load policy");
2450 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2452 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2453 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2454 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2456 tet_infoline("Allow image time to load");
2457 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2458 application.SendNotification();
2459 application.Render();
2461 tet_infoline("Testing texture is loaded and resource ready signal fired");
2462 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2463 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2465 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2467 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2468 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2469 DummyControl actor2 = DummyControl::New(true);
2470 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2471 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2473 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2474 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2475 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2476 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2477 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2478 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2483 int UtcDaliImageVisualLoadPolicy05(void)
2485 ToolkitTestApplication application;
2486 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2487 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2488 // Set up trace debug
2489 TestGlAbstraction& gl = application.GetGlAbstraction();
2490 TraceCallStack& textureTrace = gl.GetTextureTrace();
2491 textureTrace.Enable(true);
2493 tet_infoline("Create a control and connect to resource ready signal");
2494 DummyControl actor = DummyControl::New(true);
2495 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2496 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2497 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2498 application.GetScene().Add(actor);
2500 tet_infoline("Create visual with ATTACHED load policy");
2501 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2503 tet_infoline("Registering visual allows control to get a signal once loaded");
2504 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2505 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2507 tet_infoline("Allow image time to load");
2508 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2509 application.SendNotification();
2510 application.Render();
2512 tet_infoline("Testing texture is loaded and resource ready signal fired");
2513 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2514 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2516 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2518 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2519 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2520 DummyControl actor2 = DummyControl::New(true);
2521 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2522 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2524 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2525 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2526 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2527 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2528 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2529 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2534 int UtcDaliImageVisualOrientationCorrection(void)
2536 ToolkitTestApplication application;
2537 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
2539 VisualFactory factory = VisualFactory::Get();
2540 tet_infoline("Create visual with Orientation correction set OFF");
2541 Property::Map propertyMap;
2542 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2543 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2544 propertyMap.Insert("orientationCorrection", false);
2545 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2547 tet_infoline("Create control for visual, need to loaded it");
2548 DummyControl actor = DummyControl::New(true);
2549 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2550 application.GetScene().Add(actor);
2552 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2553 // Wait for image to load
2554 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2556 Vector2 originalImageSize;
2557 tet_infoline("Get size of original visual to compare later with rotated image");
2558 imageVisual.GetNaturalSize(originalImageSize);
2559 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
2560 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2561 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2562 application.SendNotification();
2563 application.Render();
2565 tet_infoline("Create visual with Orientation correction set ON ");
2566 propertyMap.Clear();
2567 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2568 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
2569 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
2570 imageVisual = factory.CreateVisual(propertyMap);
2572 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2573 // Wait for image to load
2574 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2576 Vector2 rotatedImageSize;
2577 imageVisual.GetNaturalSize(rotatedImageSize);
2578 tet_infoline("Confirm that visual has rotated");
2579 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
2580 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
2582 Property::Map resultMap;
2583 imageVisual.CreatePropertyMap(resultMap);
2585 // check the Property::ORIENTATION_CORRECTION value from the returned map
2586 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
2587 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
2592 int UtcDaliImageVisualCustomShader(void)
2594 ToolkitTestApplication application;
2595 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
2597 VisualFactory factory = VisualFactory::Get();
2598 Property::Map properties;
2599 Property::Map shader;
2600 const std::string vertexShader = "Foobar";
2601 const std::string fragmentShader = "Foobar";
2602 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2603 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2605 properties[Visual::Property::TYPE] = Visual::IMAGE;
2606 properties[Visual::Property::SHADER] = shader;
2607 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2609 Visual::Base visual = factory.CreateVisual(properties);
2611 // trigger creation through setting on stage
2612 DummyControl dummy = DummyControl::New(true);
2613 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
2614 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
2616 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2617 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2618 application.GetScene().Add(dummy);
2620 application.SendNotification();
2621 application.Render();
2623 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2625 Renderer renderer = dummy.GetRendererAt(0);
2626 Shader shader2 = renderer.GetShader();
2627 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2628 Property::Map* map = value.GetMap();
2629 DALI_TEST_CHECK(map);
2631 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2632 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2634 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2635 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2639 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2640 properties[Visual::Property::SHADER] = shader;
2642 Visual::Base visual1 = factory.CreateVisual(properties);
2644 // trigger creation through setting on stage
2645 DummyControl dummy1 = DummyControl::New(true);
2646 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
2647 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
2648 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
2649 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2650 application.GetScene().Add(dummy1);
2652 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2653 glAbstraction.EnableEnableDisableCallTrace(true);
2655 application.SendNotification();
2656 application.Render();
2658 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2659 std::ostringstream blendStr;
2660 blendStr << std::hex << GL_BLEND;
2661 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
2666 void ResourceReadyLoadNext(Control control)
2668 static int callNumber = 0;
2670 gResourceReadySignalFired = true;
2671 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
2675 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
2677 tet_infoline("Create visual with loaded image from within the signal handler");
2678 VisualFactory factory = VisualFactory::Get();
2679 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
2681 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2682 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
2687 tet_infoline("3rd signal called");
2688 DALI_TEST_CHECK(true);
2692 int UtcDaliImageVisualLoadReady01(void)
2694 ToolkitTestApplication application;
2695 tet_infoline("UtcDaliImageVisualLoadReady01");
2696 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
2697 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
2698 tet_infoline("Should get a ready signal for all three visuals");
2702 tet_infoline("Create a control and connect to resource ready signal");
2703 DummyControl actor = DummyControl::New(true);
2704 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
2705 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2706 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2707 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2708 application.GetScene().Add(actor);
2710 tet_infoline("Create visual with IMMEDIATE load policy");
2711 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2713 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2714 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
2716 tet_infoline("Allow image time to load");
2717 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2718 application.SendNotification();
2719 application.Render();
2721 tet_infoline("Testing texture is loaded and resource ready signal fired");
2722 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2723 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
2725 tet_infoline("Original control correctly signalled, now testing failing image");
2727 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2730 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2732 DummyControl actor2 = DummyControl::New(true);
2733 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
2734 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2735 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
2737 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
2738 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2740 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2741 application.GetScene().Add(actor2);
2743 tet_infoline("Wait for loading thread to finish");
2744 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2745 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2747 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
2749 tet_infoline("Check for 3rd signal");
2750 application.SendNotification();
2751 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
2752 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);