2 * Copyright (c) 2024 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.
24 #include <dali-toolkit-test-suite-utils.h>
26 #include <toolkit-environment-variable.h>
27 #include <toolkit-event-thread-callback.h>
28 #include <toolkit-style-monitor.h>
29 #include <toolkit-texture-upload-manager.h>
30 #include <toolkit-timer.h>
32 #include <dali-toolkit/dali-toolkit.h>
33 #include <dali-toolkit/devel-api/controls/control-devel.h>
34 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
35 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
36 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
37 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
38 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
39 #include <dali-toolkit/public-api/image-loader/image-url.h>
40 #include <dali-toolkit/public-api/image-loader/image.h>
42 #include <dali/devel-api/adaptor-framework/texture-upload-manager.h>
44 #include "dummy-control.h"
45 #include "test-encoded-image-buffer.h"
46 #include "test-native-image-source.h"
49 using namespace Dali::Toolkit;
51 void dali_image_visual_startup(void)
53 test_return_value = TET_UNDEF;
56 void dali_image_visual_cleanup(void)
58 test_return_value = TET_PASS;
63 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
64 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
65 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
66 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
67 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
68 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
69 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
70 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
71 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
72 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
73 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
75 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
76 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
78 constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER";
80 constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME";
82 const char* VALID_DEBUG_SHADER_SCRIPT =
84 " \"version\": \"1.0.0\",\n"
85 " \"maximumColorRate\": 0.5,\n"
86 " \"extraVaryings\": [\"mediump vec3 vDebug;\"],\n"
87 " \"extraUniforms\": \"mediump float uDebug;\",\n"
88 " \"applyVaryingsCode\": \"vDebug = gl_Position.xyz / gl_Position.w;\",\n"
89 " \"redChannelCodes\":\n"
91 " \"triggerCode\":[\"return\",\" false;\"],\n"
92 " \"ratioCode\":\"return 0.0;\"\n"
96 constexpr std::string_view THROW_EXCEPTION_STYLE_FILE_NAME = "throwException";
98 bool gResourceReadySignalFired = false;
99 std::vector<int> gReadyIds = {};
100 void ResourceReadySignal(Control control)
102 gResourceReadySignalFired = true;
103 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
110 Actor CreateActorWithImageVisual(const Property::Map& map)
112 VisualFactory factory = VisualFactory::Get();
113 DummyControl actor = DummyControl::New();
114 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
115 Visual::Base visual = factory.CreateVisual(map);
116 DALI_TEST_CHECK(visual);
117 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
118 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
119 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
123 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
125 VisualFactory factory = VisualFactory::Get();
127 Property::Map propertyMap;
128 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
129 propertyMap.Insert(ImageVisual::Property::URL, url);
130 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
131 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
132 propertyMap.Insert(key, value);
134 return factory.CreateVisual(propertyMap);
139 void TestVisualRender(ToolkitTestApplication& application,
141 Visual::Base& visual,
142 std::size_t expectedSamplers = 0,
143 ImageDimensions imageDimensions = ImageDimensions(),
144 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
146 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
147 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
151 // set the image size, for test case, this needs to be set before loading started
152 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
155 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
156 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
158 application.GetScene().Add(actor);
160 application.SendNotification(); // Send messages to update
161 application.Render(); // process update and render
162 application.SendNotification(); // process any signals to event
166 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
169 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
172 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
175 visual.CreatePropertyMap(map);
176 Property::Value* value = map.Find(mixColorIndex);
177 DALI_TEST_CHECK(value);
179 DALI_TEST_CHECK(value->Get(mixColor1));
180 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
182 value = map.Find(Visual::Property::MIX_COLOR);
183 DALI_TEST_CHECK(value);
185 DALI_TEST_CHECK(value->Get(mixColor2));
186 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
188 value = map.Find(Visual::Property::OPACITY);
189 DALI_TEST_CHECK(value);
191 DALI_TEST_CHECK(value->Get(opacity));
192 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
195 int UtcDaliImageVisualPropertyMap(void)
197 ToolkitTestApplication application;
198 tet_infoline("Request image visual with a Property::Map");
200 VisualFactory factory = VisualFactory::Get();
201 DALI_TEST_CHECK(factory);
202 factory.SetPreMultiplyOnLoad(true);
204 Property::Map propertyMap;
205 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
206 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
208 Visual::Base visual = factory.CreateVisual(propertyMap);
209 DALI_TEST_CHECK(visual);
211 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
212 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
214 TestGlAbstraction& gl = application.GetGlAbstraction();
215 TraceCallStack& textureTrace = gl.GetTextureTrace();
216 textureTrace.Enable(true);
218 DummyControl actor = DummyControl::New();
219 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
220 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
222 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
223 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
225 application.GetScene().Add(actor);
226 application.SendNotification();
227 application.Render();
229 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
231 application.SendNotification();
232 application.Render();
234 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
235 auto renderer = actor.GetRendererAt(0);
236 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
237 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
238 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
239 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
240 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
241 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
242 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
244 application.GetScene().Remove(actor);
245 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
250 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
252 ToolkitTestApplication application;
253 tet_infoline("Request image visual without pre-multiplied alpha");
255 VisualFactory factory = VisualFactory::Get();
256 DALI_TEST_CHECK(factory);
257 factory.SetPreMultiplyOnLoad(false);
259 Property::Map propertyMap;
260 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
261 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
263 Visual::Base visual = factory.CreateVisual(propertyMap);
264 DALI_TEST_CHECK(visual);
266 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
267 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
269 TestGlAbstraction& gl = application.GetGlAbstraction();
270 TraceCallStack& textureTrace = gl.GetTextureTrace();
271 textureTrace.Enable(true);
273 DummyControl actor = DummyControl::New();
274 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
275 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
277 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
278 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
280 application.GetScene().Add(actor);
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
286 application.SendNotification();
287 application.Render();
289 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
290 auto renderer = actor.GetRendererAt(0);
291 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
292 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
293 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
294 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
296 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
297 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
299 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
301 application.GetScene().Remove(actor);
302 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
307 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
309 ToolkitTestApplication application;
310 tet_infoline("Request image visual with no alpha channel");
312 VisualFactory factory = VisualFactory::Get();
313 DALI_TEST_CHECK(factory);
315 Property::Map propertyMap;
316 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
317 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
319 Visual::Base visual = factory.CreateVisual(propertyMap);
320 DALI_TEST_CHECK(visual);
322 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
323 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
325 TestGlAbstraction& gl = application.GetGlAbstraction();
326 TraceCallStack& textureTrace = gl.GetTextureTrace();
327 textureTrace.Enable(true);
329 DummyControl actor = DummyControl::New();
330 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
331 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
333 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
334 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
336 application.GetScene().Add(actor);
337 application.SendNotification();
338 application.Render();
340 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
342 application.SendNotification();
343 application.Render();
345 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
346 auto renderer = actor.GetRendererAt(0);
347 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
348 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
349 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
350 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
352 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
353 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
355 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
357 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
358 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
359 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
360 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
361 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
362 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
363 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
364 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
366 textureTrace.Reset();
368 // Make a new visual with the same image
369 Visual::Base newVisual = factory.CreateVisual(propertyMap);
370 DALI_TEST_CHECK(newVisual);
372 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
373 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
375 DummyControl newActor = DummyControl::New();
376 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
377 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
379 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
380 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
382 application.GetScene().Add(newActor);
384 application.SendNotification();
385 application.Render();
387 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
388 auto newRenderer = newActor.GetRendererAt(0);
389 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
390 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
391 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
392 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
394 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
395 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
397 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
398 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
399 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
400 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
401 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
402 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
403 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
404 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
406 application.GetScene().Remove(actor);
407 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
412 int UtcDaliImageVisualRemoteImageLoad(void)
414 ToolkitTestApplication application;
415 tet_infoline("Request remote image visual with a Property::Map");
417 VisualFactory factory = VisualFactory::Get();
418 DALI_TEST_CHECK(factory);
420 Property::Map propertyMap;
421 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
422 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
424 Visual::Base visual = factory.CreateVisual(propertyMap);
425 DALI_TEST_CHECK(visual);
427 TestGlAbstraction& gl = application.GetGlAbstraction();
428 TraceCallStack& textureTrace = gl.GetTextureTrace();
429 textureTrace.Enable(true);
431 DummyControl actor = DummyControl::New();
432 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
433 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
435 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
436 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
438 application.GetScene().Add(actor);
439 application.SendNotification();
441 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
443 application.SendNotification();
444 application.Render();
446 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
447 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
449 application.GetScene().Remove(actor);
450 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
455 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
457 ToolkitTestApplication application;
458 tet_infoline("Use FrameBuffer as url");
462 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
464 DALI_TEST_CHECK(frameBuffer);
465 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
466 std::string url = imageUrl.GetUrl();
468 VisualFactory factory = VisualFactory::Get();
469 DALI_TEST_CHECK(factory);
471 Property::Map propertyMap;
472 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
473 propertyMap.Insert(ImageVisual::Property::URL, url);
475 Visual::Base visual = factory.CreateVisual(propertyMap);
476 DALI_TEST_CHECK(visual);
478 DummyControl actor = DummyControl::New();
479 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
480 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
482 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
484 application.GetScene().Add(actor);
486 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
488 application.SendNotification();
489 application.Render(16);
491 Renderer renderer = actor.GetRendererAt(0);
493 // Check whether preMultipliedAlpha is true.
494 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
495 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
500 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
502 ToolkitTestApplication application;
503 tet_infoline("Use FrameBuffer as url");
507 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
509 DALI_TEST_CHECK(frameBuffer);
511 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
512 frameBuffer.AttachColorTexture(texture);
514 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
515 std::string url = imageUrl.GetUrl();
517 VisualFactory factory = VisualFactory::Get();
518 DALI_TEST_CHECK(factory);
520 Property::Map propertyMap;
521 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
522 propertyMap.Insert(ImageVisual::Property::URL, url);
524 Visual::Base visual = factory.CreateVisual(propertyMap);
525 DALI_TEST_CHECK(visual);
527 DummyControl actor = DummyControl::New();
528 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
529 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
531 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
533 application.GetScene().Add(actor);
535 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
537 application.SendNotification();
538 application.Render(16);
540 Renderer renderer = actor.GetRendererAt(0);
542 // Check whether preMultipliedAlpha is true.
543 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
544 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
549 int UtcDaliImageVisualWithPixelData(void)
551 ToolkitTestApplication application;
552 tet_infoline("Use PixelData as url");
556 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
558 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
559 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
561 DALI_TEST_CHECK(pixelData);
563 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
564 std::string url = imageUrl.GetUrl();
566 VisualFactory factory = VisualFactory::Get();
567 DALI_TEST_CHECK(factory);
569 Property::Map propertyMap;
570 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
571 propertyMap.Insert(ImageVisual::Property::URL, url);
573 Visual::Base visual = factory.CreateVisual(propertyMap);
574 DALI_TEST_CHECK(visual);
576 DummyControl actor = DummyControl::New();
577 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
578 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
580 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
582 application.GetScene().Add(actor);
584 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
586 application.SendNotification();
587 application.Render(16);
589 Renderer renderer = actor.GetRendererAt(0);
591 // Check whether preMultipliedAlpha is false.
592 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
593 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
598 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
600 ToolkitTestApplication application;
601 tet_infoline("Use PixelData as url");
605 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
607 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
608 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
610 DALI_TEST_CHECK(pixelData);
612 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
613 std::string url = imageUrl.GetUrl();
615 VisualFactory factory = VisualFactory::Get();
616 DALI_TEST_CHECK(factory);
618 Property::Map propertyMap;
619 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
620 propertyMap.Insert(ImageVisual::Property::URL, url);
622 Visual::Base visual = factory.CreateVisual(propertyMap);
623 DALI_TEST_CHECK(visual);
625 DummyControl actor = DummyControl::New();
626 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
627 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
629 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
631 application.GetScene().Add(actor);
633 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
635 application.SendNotification();
636 application.Render(16);
638 Renderer renderer = actor.GetRendererAt(0);
640 // Check whether preMultipliedAlpha is true.
641 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
642 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
647 int UtcDaliImageVisualWithPixelDataMasking(void)
649 ToolkitTestApplication application;
650 tet_infoline("Load external texture with mask");
652 TestGlAbstraction& gl = application.GetGlAbstraction();
653 TraceCallStack& textureTrace = gl.GetTextureTrace();
654 textureTrace.Enable(true);
658 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
660 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
661 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
663 DALI_TEST_CHECK(pixelData);
665 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
666 std::string url = imageUrl.GetUrl();
668 VisualFactory factory = VisualFactory::Get();
669 DALI_TEST_CHECK(factory);
671 Property::Map propertyMap;
672 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
673 propertyMap.Insert(ImageVisual::Property::URL, url);
674 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
676 Visual::Base visual = factory.CreateVisual(propertyMap);
677 DALI_TEST_CHECK(visual);
679 Property::Map testMap;
680 visual.CreatePropertyMap(testMap);
681 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
683 DummyControl actor = DummyControl::New();
684 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
685 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
687 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
689 application.GetScene().Add(actor);
690 application.SendNotification();
691 application.Render(16);
692 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
694 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
695 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
696 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
698 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
699 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
704 int UtcDaliImageVisualWithPixelDataMasking02(void)
706 ToolkitTestApplication application;
707 tet_infoline("Load premultiplied external texture with mask");
709 TestGlAbstraction& gl = application.GetGlAbstraction();
710 TraceCallStack& textureTrace = gl.GetTextureTrace();
711 textureTrace.Enable(true);
715 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
717 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
718 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
720 DALI_TEST_CHECK(pixelData);
722 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
723 std::string url = imageUrl.GetUrl();
725 VisualFactory factory = VisualFactory::Get();
726 DALI_TEST_CHECK(factory);
728 Property::Map propertyMap;
729 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
730 propertyMap.Insert(ImageVisual::Property::URL, url);
731 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
733 Visual::Base visual = factory.CreateVisual(propertyMap);
734 DALI_TEST_CHECK(visual);
736 Property::Map testMap;
737 visual.CreatePropertyMap(testMap);
738 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
740 DummyControl actor = DummyControl::New();
741 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
742 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
744 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
746 application.GetScene().Add(actor);
747 application.SendNotification();
748 application.Render(16);
749 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
751 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
752 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
753 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
755 Renderer renderer = actor.GetRendererAt(0);
757 //Check visual property
758 DALI_TEST_EQUALS(*testMap.Find(Visual::Property::PREMULTIPLIED_ALPHA), Property::Value(true), TEST_LOCATION);
760 // Check whether preMultipliedAlpha is true.
761 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
762 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
764 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
765 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
770 int UtcDaliImageVisualWithPixelDataMaskingSynchronously(void)
772 ToolkitTestApplication application;
773 tet_infoline("Load synchronously external texture with mask");
777 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
779 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
780 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
782 DALI_TEST_CHECK(pixelData);
784 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
785 std::string url = imageUrl.GetUrl();
787 VisualFactory factory = VisualFactory::Get();
788 DALI_TEST_CHECK(factory);
790 Property::Map propertyMap;
791 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
792 propertyMap.Insert(ImageVisual::Property::URL, url);
793 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
794 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
796 Visual::Base visual = factory.CreateVisual(propertyMap);
797 DALI_TEST_CHECK(visual);
799 Property::Map testMap;
800 visual.CreatePropertyMap(testMap);
801 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
803 DummyControl actor = DummyControl::New();
804 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
805 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
807 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
809 application.GetScene().Add(actor);
811 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
813 application.SendNotification();
814 application.Render(16);
819 int UtcDaliImageVisualWithNativeImage(void)
821 ToolkitTestApplication application;
822 tet_infoline("Use Native Image as url");
824 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
825 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
826 std::string url = imageUrl.GetUrl();
828 VisualFactory factory = VisualFactory::Get();
829 DALI_TEST_CHECK(factory);
831 Property::Map propertyMap;
832 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
833 propertyMap.Insert(ImageVisual::Property::URL, url);
835 Visual::Base visual = factory.CreateVisual(propertyMap);
836 DALI_TEST_CHECK(visual);
838 DummyControl actor = DummyControl::New();
839 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
840 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
842 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
844 application.GetScene().Add(actor);
846 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
848 application.SendNotification();
849 application.Render(16);
851 Renderer renderer = actor.GetRendererAt(0);
852 Shader shader = renderer.GetShader();
854 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
855 DALI_TEST_CHECK(value.GetType() == Property::MAP);
856 const Property::Map* outMap = value.GetMap();
857 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
859 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
860 size_t pos = fragmentShader.find(fragmentPrefix);
862 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
864 // Check whether preMultipliedAlpha is false.
865 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
866 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
871 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
873 ToolkitTestApplication application;
874 tet_infoline("Use Native Image as url");
876 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
877 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
878 std::string url = imageUrl.GetUrl();
880 VisualFactory factory = VisualFactory::Get();
881 DALI_TEST_CHECK(factory);
883 Property::Map propertyMap;
884 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
885 propertyMap.Insert(ImageVisual::Property::URL, url);
887 Visual::Base visual = factory.CreateVisual(propertyMap);
888 DALI_TEST_CHECK(visual);
890 DummyControl actor = DummyControl::New();
891 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
892 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
894 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
896 application.GetScene().Add(actor);
898 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
900 application.SendNotification();
901 application.Render(16);
903 Renderer renderer = actor.GetRendererAt(0);
904 Shader shader = renderer.GetShader();
906 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
907 DALI_TEST_CHECK(value.GetType() == Property::MAP);
908 const Property::Map* outMap = value.GetMap();
909 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
911 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
912 size_t pos = fragmentShader.find(fragmentPrefix);
914 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
916 // Check whether preMultipliedAlpha is true.
917 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
918 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
923 int UtcDaliImageVisualWithNativeImageCustomShader(void)
925 ToolkitTestApplication application;
926 tet_infoline("Use Native Image as url and Use custom shader");
928 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
929 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
930 std::string url = imageUrl.GetUrl();
932 VisualFactory factory = VisualFactory::Get();
933 DALI_TEST_CHECK(factory);
935 Property::Map propertyMap;
936 Property::Map shaderMap;
937 const std::string customVertexShaderSource = "Foobar";
938 const std::string customFragmentShaderSource = "Foobar";
939 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
940 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
942 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
943 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
944 propertyMap.Insert(ImageVisual::Property::URL, url);
946 Visual::Base visual = factory.CreateVisual(propertyMap);
947 DALI_TEST_CHECK(visual);
949 DummyControl actor = DummyControl::New();
950 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
951 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
953 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
954 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
956 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
958 application.GetScene().Add(actor);
960 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
962 application.SendNotification();
963 application.Render(16);
965 Renderer renderer = actor.GetRendererAt(0);
966 Shader shader = renderer.GetShader();
968 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
969 DALI_TEST_CHECK(value.GetType() == Property::MAP);
970 const Property::Map* outMap = value.GetMap();
971 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
972 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
974 // Compare vertex shader is equal
975 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
977 // Check fragment shader changed
978 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
979 size_t pos = fragmentShaderSource.find(fragmentPrefix);
981 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
983 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
985 // Check whether preMultipliedAlpha is false.
986 // Note : We dont use preMultiplied alpha when app developer using custom shader.
987 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
988 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
993 int UtcDaliImageVisualWithNativeImageRemoved(void)
995 ToolkitTestApplication application;
996 tet_infoline("Use Native Image as url");
998 TestGlAbstraction& gl = application.GetGlAbstraction();
999 TraceCallStack& textureTrace = gl.GetTextureTrace();
1000 textureTrace.Enable(true);
1002 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
1003 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
1004 std::string url = imageUrl.GetUrl();
1006 VisualFactory factory = VisualFactory::Get();
1007 DALI_TEST_CHECK(factory);
1009 Property::Map propertyMap;
1010 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1011 propertyMap.Insert(ImageVisual::Property::URL, url);
1013 Visual::Base visual = factory.CreateVisual(propertyMap);
1014 DALI_TEST_CHECK(visual);
1016 DummyControl actor = DummyControl::New();
1017 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1018 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1020 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1022 application.GetScene().Add(actor);
1023 application.SendNotification();
1024 application.Render();
1026 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1027 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1029 tet_infoline("No delete texture because reference count is not zero");
1031 application.GetScene().Remove(actor);
1032 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1033 application.SendNotification();
1034 application.Render();
1036 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1037 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1039 tet_infoline("Delete texture because reference count is zero");
1041 application.SendNotification();
1042 application.Render();
1044 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1049 int UtcDaliImageVisualWithEncodedImageBuffer(void)
1051 ToolkitTestApplication application;
1052 tet_infoline("Use Encoded Image Buffer as url");
1054 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1055 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1057 VisualFactory factory = VisualFactory::Get();
1058 DALI_TEST_CHECK(factory);
1060 Property::Map propertyMap;
1061 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1062 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
1064 Visual::Base visual = factory.CreateVisual(propertyMap);
1065 DALI_TEST_CHECK(visual);
1067 TestGlAbstraction& gl = application.GetGlAbstraction();
1068 TraceCallStack& textureTrace = gl.GetTextureTrace();
1069 textureTrace.Enable(true);
1071 DummyControl actor = DummyControl::New();
1072 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1073 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1075 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1076 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1078 application.GetScene().Add(actor);
1079 application.SendNotification();
1081 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1083 application.SendNotification();
1084 application.Render();
1086 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1087 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1089 application.GetScene().Remove(actor);
1090 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1095 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
1097 ToolkitTestApplication application;
1098 tet_infoline("Use Encoded Image Buffer as url");
1100 TestGlAbstraction& gl = application.GetGlAbstraction();
1101 TraceCallStack& textureTrace = gl.GetTextureTrace();
1102 textureTrace.Enable(true);
1104 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1105 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1106 std::string url = imageUrl.GetUrl();
1108 VisualFactory factory = VisualFactory::Get();
1109 DALI_TEST_CHECK(factory);
1111 Property::Map propertyMap;
1112 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1113 propertyMap.Insert(ImageVisual::Property::URL, url);
1115 Visual::Base visual = factory.CreateVisual(propertyMap);
1116 DALI_TEST_CHECK(visual);
1118 DummyControl actor = DummyControl::New();
1119 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1120 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1122 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1124 application.GetScene().Add(actor);
1125 application.SendNotification();
1127 // Wait for decode buffer and make texture.
1128 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1130 application.SendNotification();
1131 application.Render();
1133 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1134 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1136 tet_infoline("Delete texture because there is no actor to use decoded texture");
1138 application.GetScene().Remove(actor);
1139 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1140 application.SendNotification();
1141 application.Render();
1143 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1144 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1149 int UtcDaliImageVisualTextureReuse1(void)
1151 ToolkitTestApplication application;
1152 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
1154 Property::Map propertyMap;
1155 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1156 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1157 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1159 TestGlAbstraction& gl = application.GetGlAbstraction();
1160 TraceCallStack& textureTrace = gl.GetTextureTrace();
1161 textureTrace.Enable(true);
1162 TraceCallStack& drawTrace = gl.GetDrawTrace();
1163 drawTrace.Enable(true);
1165 Actor actor = CreateActorWithImageVisual(propertyMap);
1166 application.GetScene().Add(actor);
1167 application.SendNotification();
1169 // Wait for image to load
1170 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1172 application.SendNotification();
1173 application.Render();
1175 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1176 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1177 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1178 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1179 textureTrace.Reset();
1182 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1183 application.GetScene().Add(actor2);
1185 application.SendNotification(); // Send messages to update
1186 application.Render(); // process update and render
1187 application.SendNotification(); // process any signals to event
1189 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1191 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
1192 // backend here, but test graphics backend.
1193 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1194 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1196 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
1198 application.GetScene().Remove(actor);
1199 application.SendNotification();
1200 application.Render();
1202 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1203 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1205 tet_infoline("Test that removing last actor does delete the texture\n");
1207 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1208 application.SendNotification();
1209 application.Render();
1211 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1212 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1217 int UtcDaliImageVisualTextureReuse2(void)
1219 ToolkitTestApplication application;
1220 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");
1222 Property::Map propertyMap;
1223 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1224 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1226 TestGlAbstraction& gl = application.GetGlAbstraction();
1227 TraceCallStack& textureTrace = gl.GetTextureTrace();
1228 textureTrace.Enable(true);
1229 TraceCallStack& drawTrace = gl.GetDrawTrace();
1230 drawTrace.Enable(true);
1232 Actor actor = CreateActorWithImageVisual(propertyMap);
1233 application.GetScene().Add(actor);
1234 application.SendNotification();
1236 // Wait for image to load
1237 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1239 application.SendNotification();
1240 application.Render();
1242 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1243 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1244 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1245 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1246 textureTrace.Reset();
1249 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1250 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1251 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1252 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1253 application.GetScene().Add(actor2);
1255 application.SendNotification();
1257 // Wait for image to load
1258 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1260 application.SendNotification();
1261 application.Render();
1263 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1266 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1267 "renderers are using different textures\n");
1269 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1270 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1271 TraceCallStack::NamedParams tex1;
1272 tex1["texture"] << 1;
1273 TraceCallStack::NamedParams tex2;
1274 tex2["texture"] << 2;
1275 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1276 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1278 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1280 application.GetScene().Remove(actor);
1281 application.SendNotification();
1282 application.Render();
1284 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1285 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1287 tet_infoline("Test that removing last actor deletes it's texture\n");
1289 application.GetScene().Remove(actor2);
1290 application.SendNotification();
1291 application.Render();
1293 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1294 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1299 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1301 ToolkitTestApplication application;
1302 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1304 static std::vector<UniformData> customUniforms =
1306 UniformData("pixelArea", Property::Type::VECTOR4),
1307 UniformData("wrapMode", Property::Type::VECTOR2),
1310 TestGraphicsController& graphics = application.GetGraphicsController();
1311 graphics.AddCustomUniforms(customUniforms);
1313 VisualFactory factory = VisualFactory::Get();
1314 DALI_TEST_CHECK(factory);
1316 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1317 const int width = 34;
1318 const int height = 34;
1319 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1321 Property::Map propertyMap;
1322 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1323 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1324 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1325 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1326 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1327 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1328 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1329 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1330 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1332 Visual::Base visual = factory.CreateVisual(propertyMap);
1333 DALI_TEST_CHECK(visual);
1335 TestGlAbstraction& gl = application.GetGlAbstraction();
1336 TraceCallStack& textureTrace = gl.GetTextureTrace();
1337 textureTrace.Enable(true);
1338 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1339 texParameterTrace.Enable(true);
1341 DummyControl actor = DummyControl::New();
1342 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1343 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1344 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1345 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1346 application.GetScene().Add(actor);
1349 application.SendNotification();
1350 application.Render();
1352 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1354 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1356 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1357 std::stringstream out;
1358 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1359 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1361 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1362 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1364 // test the uniforms which used to handle the wrap mode
1365 Renderer renderer = actor.GetRendererAt(0u);
1366 DALI_TEST_CHECK(renderer);
1368 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1369 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1370 Vector4 pixelAreaUniform;
1371 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1372 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1374 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1375 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1376 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1377 Vector2 wrapModeUniform;
1378 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1379 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1382 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1387 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1389 ToolkitTestApplication application;
1390 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1392 static std::vector<UniformData> customUniforms =
1394 UniformData("pixelArea", Property::Type::VECTOR4),
1397 TestGraphicsController& graphics = application.GetGraphicsController();
1398 graphics.AddCustomUniforms(customUniforms);
1400 VisualFactory factory = VisualFactory::Get();
1401 DALI_TEST_CHECK(factory);
1403 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1404 const int width = 600;
1405 const int height = 600;
1406 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1408 Property::Map propertyMap;
1409 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1410 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1411 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1412 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1413 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1414 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1415 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1416 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1418 Visual::Base visual = factory.CreateVisual(propertyMap);
1419 DALI_TEST_CHECK(visual);
1421 TestGlAbstraction& gl = application.GetGlAbstraction();
1422 TraceCallStack& textureTrace = gl.GetTextureTrace();
1423 textureTrace.Enable(true);
1424 textureTrace.EnableLogging(true);
1425 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1426 texParameterTrace.Enable(true);
1427 texParameterTrace.EnableLogging(true);
1429 DummyControl actor = DummyControl::New();
1430 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1431 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1432 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1433 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1434 application.GetScene().Add(actor);
1437 application.SendNotification();
1438 application.Render();
1439 application.SendNotification();
1441 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1443 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1445 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1446 std::stringstream out;
1447 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1448 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1450 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1451 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1453 // test the uniforms which used to handle the wrap mode
1454 Renderer renderer = actor.GetRendererAt(0u);
1455 DALI_TEST_CHECK(renderer);
1457 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1458 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1459 Vector4 pixelAreaUniform;
1460 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1461 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1463 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1464 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1467 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1472 int UtcDaliImageVisualAnimateMixColor(void)
1474 ToolkitTestApplication application;
1475 tet_infoline("Animate mix color");
1477 static std::vector<UniformData> customUniforms =
1479 UniformData("mixColor", Property::Type::VECTOR3),
1482 TestGraphicsController& graphics = application.GetGraphicsController();
1483 graphics.AddCustomUniforms(customUniforms);
1485 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1487 VisualFactory factory = VisualFactory::Get();
1488 Property::Map propertyMap;
1489 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1490 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1491 propertyMap.Insert("mixColor", Color::BLUE);
1492 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1493 Visual::Base visual = factory.CreateVisual(propertyMap);
1495 DummyControl actor = DummyControl::New(true);
1496 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1497 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1499 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1500 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1501 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1502 application.GetScene().Add(actor);
1504 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1506 Renderer renderer = actor.GetRendererAt(0);
1508 // @todo Should we add API to make this code work again?
1509 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1511 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1512 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1514 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1517 map["target"] = "testVisual";
1518 map["property"] = "mixColor";
1519 map["initialValue"] = Color::MAGENTA;
1520 map["targetValue"] = TARGET_MIX_COLOR;
1521 map["animator"] = Property::Map()
1522 .Add("alphaFunction", "LINEAR")
1523 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1525 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1527 Animation animation = dummyImpl.CreateTransition(transition);
1529 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1532 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1533 glAbstraction.EnableEnableDisableCallTrace(true);
1534 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1535 std::ostringstream blendStr;
1536 blendStr << std::hex << GL_BLEND;
1538 application.SendNotification();
1539 application.Render(0); // Ensure animation starts
1540 application.Render(2000u); // Halfway point
1541 Vector3 testColor(1.0f, 0.0f, 0.5f);
1543 // uColor.a should be actor's alpha * mixColor.a.
1544 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1545 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1547 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1549 glEnableStack.Reset();
1551 application.SendNotification();
1552 application.Render(2000u);
1554 application.SendNotification();
1555 application.Render();
1556 application.SendNotification();
1558 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1559 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1560 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1562 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1564 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1569 int UtcDaliImageVisualAnimateOpacity(void)
1571 ToolkitTestApplication application;
1572 tet_infoline("Animate image visual opacity");
1574 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1576 VisualFactory factory = VisualFactory::Get();
1577 Property::Map propertyMap;
1578 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1579 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1580 propertyMap.Insert("opacity", 0.5f);
1581 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1582 Visual::Base visual = factory.CreateVisual(propertyMap);
1584 DummyControl actor = DummyControl::New(true);
1585 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1586 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1588 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1589 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1590 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1591 application.GetScene().Add(actor);
1593 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1595 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1596 glAbstraction.EnableEnableDisableCallTrace(true);
1597 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1598 std::ostringstream blendStr;
1599 blendStr << std::hex << GL_BLEND;
1601 application.SendNotification();
1602 application.Render();
1604 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1607 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.");
1610 map["target"] = "testVisual";
1611 map["property"] = "opacity";
1612 map["targetValue"] = 1.0f;
1613 map["animator"] = Property::Map()
1614 .Add("alphaFunction", "LINEAR")
1615 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1617 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1618 Animation animation = dummyImpl.CreateTransition(transition);
1621 glEnableStack.Reset();
1623 application.SendNotification();
1624 application.Render(0); // Ensure animation starts
1625 application.Render(2000u); // Halfway point through animation
1626 application.SendNotification(); // Handle any signals
1629 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1630 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1632 application.Render(2001u); // end
1633 application.SendNotification(); // ensure animation finished signal is sent
1635 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1636 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1638 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1639 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1643 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.");
1646 map["target"] = "testVisual";
1647 map["property"] = Visual::Property::OPACITY;
1648 map["targetValue"] = 0.1f;
1649 map["animator"] = Property::Map()
1650 .Add("alphaFunction", "LINEAR")
1651 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1653 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1654 Animation animation = dummyImpl.CreateTransition(transition);
1657 glEnableStack.Reset();
1659 application.SendNotification();
1660 application.Render(0); // Ensure animation starts
1661 application.Render(2000u); // Halfway point
1662 application.SendNotification();
1665 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1666 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1668 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1670 glEnableStack.Reset();
1672 application.Render(2016u); // end
1673 application.SendNotification();
1675 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1676 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1678 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1679 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1685 int UtcDaliImageVisualAnimateOpacity02(void)
1687 ToolkitTestApplication application;
1688 tet_infoline("Animate image visual opacity");
1690 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1692 VisualFactory factory = VisualFactory::Get();
1693 Property::Map propertyMap;
1694 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1695 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1696 propertyMap.Insert("opacity", 0.5f);
1697 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1698 Visual::Base visual = factory.CreateVisual(propertyMap);
1700 DummyControl actor = DummyControl::New(true);
1701 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1702 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1704 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1705 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1706 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1708 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1710 Property::Array array;
1713 map["target"] = "testVisual";
1714 map["property"] = "opacity";
1715 map["initialValue"] = 0.0f;
1716 map["targetValue"] = 1.0f;
1717 map["animator"] = Property::Map()
1718 .Add("alphaFunction", "LINEAR")
1719 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1722 map2["target"] = "testVisual";
1723 map2["property"] = "size";
1724 map2["targetValue"] = Vector2(1.0f, 1.0f);
1726 array.Add(map).Add(map2);
1728 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1729 Animation animation = dummyImpl.CreateTransition(transition);
1731 application.GetScene().Add(actor);
1732 application.SendNotification();
1733 application.Render(0); // Ensure animation starts
1735 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1737 Renderer renderer = actor.GetRendererAt(0);
1738 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1739 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1741 animation = dummyImpl.CreateTransition(transition);
1744 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1745 glAbstraction.EnableEnableDisableCallTrace(true);
1746 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1747 std::ostringstream blendStr;
1748 blendStr << std::hex << GL_BLEND;
1750 application.SendNotification();
1751 application.Render(0); // Ensure animation starts
1752 application.Render(2000u); // Halfway point through animation
1753 application.SendNotification(); // Handle any signals
1755 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1758 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1759 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1761 glEnableStack.Reset();
1763 application.Render(2001u); // end
1764 application.SendNotification(); // ensure animation finished signal is sent
1766 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1767 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1769 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1774 int UtcDaliImageVisualAnimatePixelArea(void)
1776 ToolkitTestApplication application;
1777 tet_infoline("ImageVisual animate pixel area");
1779 static std::vector<UniformData> customUniforms =
1781 UniformData("pixelArea", Property::Type::VECTOR4),
1784 TestGraphicsController& graphics = application.GetGraphicsController();
1785 graphics.AddCustomUniforms(customUniforms);
1787 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1789 VisualFactory factory = VisualFactory::Get();
1790 Property::Map propertyMap;
1791 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1792 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1793 propertyMap.Insert("mixColor", Color::BLUE);
1794 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1795 Visual::Base visual = factory.CreateVisual(propertyMap);
1797 DummyControl actor = DummyControl::New(true);
1798 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1799 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1801 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1802 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1803 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1804 application.GetScene().Add(actor);
1806 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1808 Renderer renderer = actor.GetRendererAt(0);
1809 // @todo Implement this feature?
1810 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1811 //tet_infoline("Test that the renderer has the mixColor property");
1812 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1814 // TransitionData only takes string keys
1816 map["target"] = "testVisual";
1817 map["property"] = "pixelArea";
1818 map["initialValue"] = Vector4(0, 0, 0, 1);
1819 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1820 map["animator"] = Property::Map()
1821 .Add("alphaFunction", "LINEAR")
1822 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1824 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1826 Animation animation = dummyImpl.CreateTransition(transition);
1827 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1830 application.SendNotification();
1831 application.Render(0); // Ensure animation starts
1832 application.Render(2000u); // Halfway point
1834 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1836 application.Render(2000u); // End of animation
1838 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1843 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1845 ToolkitTestApplication application;
1846 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1848 Property::Map propertyMap;
1849 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1850 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1852 TestGlAbstraction& gl = application.GetGlAbstraction();
1853 TraceCallStack& textureTrace = gl.GetTextureTrace();
1854 textureTrace.Enable(true);
1855 TraceCallStack& drawTrace = gl.GetDrawTrace();
1856 drawTrace.Enable(true);
1858 Actor actor = CreateActorWithImageVisual(propertyMap);
1859 application.GetScene().Add(actor);
1860 application.SendNotification();
1862 application.GetScene().Remove(actor);
1863 application.SendNotification();
1865 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1866 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1867 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1868 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1873 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1875 ToolkitTestApplication application;
1876 tet_infoline("Load image asynchronously, cancel loading, then load again");
1878 VisualFactory factory = VisualFactory::Get();
1879 DALI_TEST_CHECK(factory);
1881 Property::Map propertyMap;
1882 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1883 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1885 Visual::Base visual = factory.CreateVisual(propertyMap);
1886 DALI_TEST_CHECK(visual);
1888 TestGlAbstraction& gl = application.GetGlAbstraction();
1889 TraceCallStack& textureTrace = gl.GetTextureTrace();
1890 textureTrace.Enable(true);
1891 TraceCallStack& drawTrace = gl.GetDrawTrace();
1892 drawTrace.Enable(true);
1894 DummyControl actor = DummyControl::New();
1895 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1896 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1898 application.GetScene().Add(actor);
1901 application.GetScene().Remove(actor);
1903 application.GetScene().Add(actor);
1905 // Create another visual with the same image
1906 visual = factory.CreateVisual(propertyMap);
1907 DALI_TEST_CHECK(visual);
1909 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1911 application.SendNotification();
1912 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1914 application.SendNotification();
1915 application.Render();
1917 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1918 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1919 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1920 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1925 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1927 ToolkitTestApplication application;
1928 tet_infoline("Request image visual with invalid images - should draw broken.png");
1930 VisualFactory factory = VisualFactory::Get();
1931 DALI_TEST_CHECK(factory);
1933 Property::Map propertyMap;
1934 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1935 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1937 Visual::Base visual = factory.CreateVisual(propertyMap);
1938 DALI_TEST_CHECK(visual);
1940 TestGlAbstraction& gl = application.GetGlAbstraction();
1941 TraceCallStack& textureTrace = gl.GetTextureTrace();
1942 textureTrace.Enable(true);
1944 DummyControl actor = DummyControl::New();
1945 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1946 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1948 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1949 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1951 application.GetScene().Add(actor);
1953 application.SendNotification();
1954 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1956 application.SendNotification();
1957 application.Render();
1959 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1960 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1962 application.GetScene().Remove(actor);
1963 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1968 int UtcDaliImageVisualSetInvalidSyncImage(void)
1970 ToolkitTestApplication application;
1971 tet_infoline("Request image visual with invalid images - should draw broken.png");
1973 VisualFactory factory = VisualFactory::Get();
1974 DALI_TEST_CHECK(factory);
1976 Property::Map propertyMap;
1977 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1978 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1979 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1981 Visual::Base visual = factory.CreateVisual(propertyMap);
1982 DALI_TEST_CHECK(visual);
1984 TestGlAbstraction& gl = application.GetGlAbstraction();
1985 TraceCallStack& textureTrace = gl.GetTextureTrace();
1986 textureTrace.Enable(true);
1988 DummyControl actor = DummyControl::New();
1989 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1990 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1992 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1993 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1995 application.GetScene().Add(actor);
1997 application.SendNotification();
1998 application.Render();
2000 // Check resource status
2001 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
2002 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2004 // The broken image should be shown.
2005 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2006 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2008 application.GetScene().Remove(actor);
2009 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2014 int UtcDaliImageVisualSetInvalidRemoteImage(void)
2016 ToolkitTestApplication application;
2017 tet_infoline("Request image visual with invalid images - should draw broken.png");
2019 VisualFactory factory = VisualFactory::Get();
2020 DALI_TEST_CHECK(factory);
2022 // Local invalid file, asynchronous loading
2023 Property::Map propertyMap;
2024 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2025 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
2027 Visual::Base visual = factory.CreateVisual(propertyMap);
2028 DALI_TEST_CHECK(visual);
2030 TestGlAbstraction& gl = application.GetGlAbstraction();
2031 TraceCallStack& textureTrace = gl.GetTextureTrace();
2032 textureTrace.Enable(true);
2034 DummyControl actor = DummyControl::New();
2035 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2036 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2038 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2039 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2041 application.GetScene().Add(actor);
2043 application.SendNotification();
2044 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2046 application.SendNotification();
2047 application.Render();
2049 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2050 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2052 application.GetScene().Remove(actor);
2053 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2058 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
2060 ToolkitTestApplication application;
2061 tet_infoline("Request image visual with invalid images - should draw broken.png");
2063 VisualFactory factory = VisualFactory::Get();
2064 DALI_TEST_CHECK(factory);
2066 // Load invalid file
2067 Property::Map propertyMap;
2068 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2069 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2071 Visual::Base visual = factory.CreateVisual(propertyMap);
2072 DALI_TEST_CHECK(visual);
2074 TestGlAbstraction& gl = application.GetGlAbstraction();
2075 TraceCallStack& textureTrace = gl.GetTextureTrace();
2076 textureTrace.Enable(true);
2078 DummyControl actor = DummyControl::New();
2079 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2080 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2082 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2083 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2085 application.GetScene().Add(actor);
2087 application.SendNotification();
2088 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2090 application.SendNotification();
2091 application.Render();
2093 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2094 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2096 application.GetScene().Remove(actor);
2097 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2098 textureTrace.Reset();
2100 // Load invalid file with disabled broken
2101 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2102 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2103 propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2105 visual = factory.CreateVisual(propertyMap);
2106 DALI_TEST_CHECK(visual);
2108 actor = DummyControl::New();
2109 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2110 dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2112 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2113 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2115 application.GetScene().Add(actor);
2117 application.SendNotification();
2118 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2120 application.SendNotification();
2121 application.Render();
2123 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2124 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2126 application.GetScene().Remove(actor);
2127 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2132 int UtcDaliImageVisualAlphaMask01(void)
2134 ToolkitTestApplication application;
2135 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2137 VisualFactory factory = VisualFactory::Get();
2138 DALI_TEST_CHECK(factory);
2140 Property::Map propertyMap;
2141 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2142 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2143 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2145 Visual::Base visual = factory.CreateVisual(propertyMap);
2146 DALI_TEST_CHECK(visual);
2148 Property::Map testMap;
2149 visual.CreatePropertyMap(testMap);
2150 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2152 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2153 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2155 TestGlAbstraction& gl = application.GetGlAbstraction();
2156 TraceCallStack& textureTrace = gl.GetTextureTrace();
2157 textureTrace.Enable(true);
2159 DummyControl actor = DummyControl::New();
2160 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2161 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2163 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2164 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2165 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2167 application.GetScene().Add(actor);
2168 application.SendNotification();
2169 application.Render();
2171 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2173 application.SendNotification();
2174 application.Render();
2176 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2177 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2178 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2180 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2181 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2186 int UtcDaliImageVisualAlphaMask02(void)
2188 ToolkitTestApplication application;
2189 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2191 VisualFactory factory = VisualFactory::Get();
2192 DALI_TEST_CHECK(factory);
2194 Property::Map propertyMap;
2195 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2196 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2197 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2198 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2199 propertyMap.Insert(DevelImageVisual::Property::CROP_TO_MASK, false);
2201 Visual::Base visual = factory.CreateVisual(propertyMap);
2202 DALI_TEST_CHECK(visual);
2204 Property::Map testMap;
2205 visual.CreatePropertyMap(testMap);
2206 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2207 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2209 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2210 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2212 TestGlAbstraction& gl = application.GetGlAbstraction();
2213 TraceCallStack& textureTrace = gl.GetTextureTrace();
2214 textureTrace.Enable(true);
2216 DummyControl actor = DummyControl::New();
2217 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2218 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2220 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2221 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2222 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2224 application.GetScene().Add(actor);
2225 application.SendNotification();
2226 application.Render();
2228 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2230 application.SendNotification();
2231 application.Render();
2233 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2234 Renderer renderer = actor.GetRendererAt(0u);
2235 TextureSet textures = renderer.GetTextures();
2236 DALI_TEST_CHECK(textures);
2237 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2239 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2240 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2242 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2243 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2245 auto index = renderer.GetPropertyIndex("maskTextureRatio");
2246 DALI_TEST_NOT_EQUALS(index, Property::INVALID_INDEX, 0.1f, TEST_LOCATION);
2247 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2::ONE, TEST_LOCATION);
2252 int UtcDaliImageVisualAlphaMask03(void)
2254 ToolkitTestApplication application;
2255 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2257 VisualFactory factory = VisualFactory::Get();
2258 DALI_TEST_CHECK(factory);
2260 Property::Map propertyMap;
2261 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2262 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2263 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2264 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2266 Visual::Base visual = factory.CreateVisual(propertyMap);
2267 DALI_TEST_CHECK(visual);
2269 Property::Map testMap;
2270 visual.CreatePropertyMap(testMap);
2272 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2273 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2275 TestGlAbstraction& gl = application.GetGlAbstraction();
2276 TraceCallStack& textureTrace = gl.GetTextureTrace();
2277 textureTrace.Enable(true);
2279 DummyControl actor = DummyControl::New();
2280 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2281 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2283 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2284 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2285 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2287 application.GetScene().Add(actor);
2288 application.SendNotification();
2289 application.Render();
2291 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2293 application.SendNotification();
2294 application.Render();
2296 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2297 Renderer renderer = actor.GetRendererAt(0u);
2298 TextureSet textures = renderer.GetTextures();
2299 DALI_TEST_CHECK(textures);
2300 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2302 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2303 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2305 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2306 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2311 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2313 ToolkitTestApplication application;
2314 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2316 VisualFactory factory = VisualFactory::Get();
2317 DALI_TEST_CHECK(factory);
2319 Property::Map propertyMap;
2320 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2321 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2322 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2323 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2325 Visual::Base visual = factory.CreateVisual(propertyMap);
2326 DALI_TEST_CHECK(visual);
2328 Property::Map testMap;
2329 visual.CreatePropertyMap(testMap);
2330 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2332 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2333 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2335 TestGlAbstraction& gl = application.GetGlAbstraction();
2336 TraceCallStack& textureTrace = gl.GetTextureTrace();
2337 textureTrace.Enable(true);
2339 DummyControl actor = DummyControl::New();
2340 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2341 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2343 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2344 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2345 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2347 application.GetScene().Add(actor);
2349 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2351 application.SendNotification();
2352 application.Render();
2354 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2355 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2356 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2358 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2359 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2364 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2366 ToolkitTestApplication application;
2367 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2369 VisualFactory factory = VisualFactory::Get();
2370 DALI_TEST_CHECK(factory);
2372 Property::Map propertyMap;
2373 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2374 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2375 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2376 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2377 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2379 Visual::Base visual = factory.CreateVisual(propertyMap);
2380 DALI_TEST_CHECK(visual);
2382 Property::Map testMap;
2383 visual.CreatePropertyMap(testMap);
2384 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2386 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2387 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2389 TestGlAbstraction& gl = application.GetGlAbstraction();
2390 TraceCallStack& textureTrace = gl.GetTextureTrace();
2391 textureTrace.Enable(true);
2393 DummyControl actor = DummyControl::New();
2394 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2395 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2397 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2398 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2399 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2401 application.GetScene().Add(actor);
2403 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2405 application.SendNotification();
2406 application.Render();
2408 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2409 Renderer renderer = actor.GetRendererAt(0u);
2410 TextureSet textures = renderer.GetTextures();
2411 DALI_TEST_CHECK(textures);
2412 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2414 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2415 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2417 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2418 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2423 int UtcDaliImageVisualRemoteAlphaMask(void)
2425 ToolkitTestApplication application;
2426 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2428 VisualFactory factory = VisualFactory::Get();
2429 DALI_TEST_CHECK(factory);
2431 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2433 Property::Map propertyMap;
2434 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2435 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2436 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2438 Visual::Base visual = factory.CreateVisual(propertyMap);
2439 DALI_TEST_CHECK(visual);
2441 Property::Map testMap;
2442 visual.CreatePropertyMap(testMap);
2444 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2446 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2447 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2449 TestGlAbstraction& gl = application.GetGlAbstraction();
2450 TraceCallStack& textureTrace = gl.GetTextureTrace();
2451 textureTrace.Enable(true);
2453 DummyControl actor = DummyControl::New();
2454 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2455 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2457 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2459 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2460 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2462 application.GetScene().Add(actor);
2463 application.SendNotification();
2464 application.Render();
2466 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2468 application.SendNotification();
2469 application.Render();
2471 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2472 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2473 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2478 int UtcDaliImageVisualAlphaMaskCrop(void)
2480 ToolkitTestApplication application;
2481 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2483 VisualFactory factory = VisualFactory::Get();
2484 DALI_TEST_CHECK(factory);
2486 Property::Map propertyMap;
2487 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2488 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2489 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2490 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2491 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2493 Visual::Base visual = factory.CreateVisual(propertyMap);
2494 DALI_TEST_CHECK(visual);
2496 Property::Map testMap;
2497 visual.CreatePropertyMap(testMap);
2498 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2499 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2500 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2502 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2503 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2505 TestGlAbstraction& gl = application.GetGlAbstraction();
2506 TraceCallStack& textureTrace = gl.GetTextureTrace();
2507 textureTrace.Enable(true);
2509 DummyControl actor = DummyControl::New();
2510 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2511 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2513 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2514 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2515 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2517 application.GetScene().Add(actor);
2518 application.SendNotification();
2519 application.Render();
2521 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2523 application.SendNotification();
2524 application.Render();
2527 visual.GetNaturalSize(size);
2529 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2530 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2531 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2532 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2537 int UtcDaliImageVisualReleasePolicy01(void)
2539 ToolkitTestApplication application;
2540 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2542 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2543 DALI_TEST_CHECK(imageVisual);
2545 // Set up debug trace
2546 TestGlAbstraction& gl = application.GetGlAbstraction();
2547 TraceCallStack& textureTrace = gl.GetTextureTrace();
2548 textureTrace.Enable(true);
2550 tet_infoline("Register visual with control and ensure it has the only handle");
2551 DummyControl actor = DummyControl::New(true);
2552 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2553 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2554 imageVisual.Reset();
2556 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2558 application.SendNotification();
2559 application.Render(0);
2560 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2561 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2563 application.GetScene().Add(actor);
2565 // Wait for image to load
2566 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2568 application.SendNotification();
2569 application.Render(0);
2570 // Test renderer and texture created
2571 tet_infoline("Confirm texture created");
2572 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2573 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2575 tet_infoline("Disable visual causing the texture to be deleted");
2576 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2578 application.SendNotification();
2579 application.Render(0);
2580 // Test renderer and textures removed.
2581 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2582 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2587 int UtcDaliImageVisualReleasePolicy02(void)
2589 ToolkitTestApplication application;
2590 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2592 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2593 DALI_TEST_CHECK(imageVisual);
2595 // Setup debug trace
2596 TestGlAbstraction& gl = application.GetGlAbstraction();
2597 TraceCallStack& textureTrace = gl.GetTextureTrace();
2598 textureTrace.Enable(true);
2600 tet_infoline("Register visual with control and ensure it has the only handle");
2601 DummyControl actor = DummyControl::New(true);
2602 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2603 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2604 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2606 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2608 application.SendNotification();
2609 application.Render(0);
2610 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2611 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2613 application.GetScene().Add(actor);
2615 // Wait for image to load
2616 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2618 application.SendNotification();
2619 application.Render(0);
2620 // Test renderer and texture created
2621 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2622 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2624 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2625 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2626 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2627 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2628 application.SendNotification();
2629 application.Render();
2631 // Test texture removed after visual destroyed.
2632 tet_infoline("Ensure texture is deleted after visual destroyed");
2633 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2638 int UtcDaliImageVisualReleasePolicy03(void)
2640 ToolkitTestApplication application;
2641 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2643 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2644 DALI_TEST_CHECK(imageVisual);
2646 TestGlAbstraction& gl = application.GetGlAbstraction();
2647 TraceCallStack& textureTrace = gl.GetTextureTrace();
2648 textureTrace.Enable(true);
2650 tet_infoline("Register visual with control and ensure it has the only handle");
2651 DummyControl actor = DummyControl::New(true);
2652 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2653 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2654 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2656 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2658 application.SendNotification();
2659 application.Render(0);
2660 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2661 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2663 application.GetScene().Add(actor);
2665 // Wait for image to load
2666 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2668 application.SendNotification();
2669 application.Render(0);
2670 // Test renderer and texture created
2671 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2672 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2674 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2675 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2676 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2677 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2678 application.SendNotification();
2679 application.Render();
2681 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2682 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2687 int UtcDaliImageVisualReleasePolicy04(void)
2689 ToolkitTestApplication application;
2690 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2692 tet_infoline("Create first visual with Never release policy");
2693 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2695 tet_infoline("Create second visual with Destroyed release policy");
2696 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2698 // Set up trace debug
2699 TestGlAbstraction& gl = application.GetGlAbstraction();
2700 TraceCallStack& textureTrace = gl.GetTextureTrace();
2701 textureTrace.Enable(true);
2703 tet_infoline("Register visuals with control and ensure it has the only handles");
2704 DummyControl actor = DummyControl::New(true);
2705 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2706 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2707 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2708 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2709 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2711 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2713 // Test initially zero renderers
2714 application.SendNotification();
2715 application.Render(0);
2716 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2717 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2719 application.GetScene().Add(actor);
2721 // Wait for image to load
2722 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2724 application.SendNotification();
2725 application.Render(0);
2726 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2727 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2728 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2730 // Test renderer removed when visual destroyed
2731 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2732 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2733 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2734 application.SendNotification();
2735 application.Render();
2737 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2738 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2740 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2741 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2742 application.SendNotification();
2743 application.Render();
2745 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2746 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2747 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2752 int UtcDaliImageVisualReleasePolicy05(void)
2754 ToolkitTestApplication application;
2755 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2757 VisualFactory factory = VisualFactory::Get();
2759 Property::Map propertyMapNeverReleasePolicy;
2760 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2761 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2762 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2763 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2764 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2766 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2768 Property::Map resultMap;
2769 imageVisualNever.CreatePropertyMap(resultMap);
2770 DALI_TEST_CHECK(!resultMap.Empty());
2772 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2777 int UtcDaliImageVisualReleasePolicy06(void)
2779 ToolkitTestApplication application;
2780 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2782 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2783 DALI_TEST_CHECK(imageVisual);
2785 TestGlAbstraction& gl = application.GetGlAbstraction();
2786 TraceCallStack& textureTrace = gl.GetTextureTrace();
2787 textureTrace.Enable(true);
2789 tet_infoline("Register visual with control and ensure it has the only handle");
2790 DummyControl actor = DummyControl::New(true);
2791 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2792 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2793 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2795 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2797 application.SendNotification();
2798 application.Render(0);
2799 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2800 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2802 application.GetScene().Add(actor);
2804 // Wait for image to load
2805 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2807 application.SendNotification();
2808 application.Render(0);
2809 // Test renderer and texture created
2810 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2811 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2812 textureTrace.Reset();
2814 tet_infoline("Disable Visual and check texture not affected");
2815 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2816 application.SendNotification();
2817 application.Render(0);
2818 tet_infoline("Check renderer is destroyed when visual off stage");
2819 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2820 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2821 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2822 textureTrace.Reset();
2824 tet_infoline("Re-enable Visual and check texture not affected");
2825 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2826 application.SendNotification();
2827 application.Render(0);
2828 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2829 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2830 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2831 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2836 int UtcDaliImageVisualReleasePolicy07(void)
2838 ToolkitTestApplication application;
2839 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2841 tet_infoline("Create first visual with DESTROYED release policy");
2842 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2844 tet_infoline("Create second visual with DETACHED release policy");
2845 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2847 // Set up trace debug
2848 TestGlAbstraction& gl = application.GetGlAbstraction();
2849 TraceCallStack& textureTrace = gl.GetTextureTrace();
2850 textureTrace.Enable(true);
2852 tet_infoline("Register visuals with control and ensure it has the only handles");
2853 DummyControl actor = DummyControl::New(true);
2854 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2855 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2856 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2857 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2858 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2860 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2862 // Test initially zero renderers
2863 application.SendNotification();
2864 application.Render(0);
2865 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2866 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2868 application.GetScene().Add(actor);
2870 // Wait for image to load
2871 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2873 application.SendNotification();
2874 application.Render(0);
2875 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2876 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2877 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2879 // Test renderer removed when visual destroyed
2880 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2881 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2882 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2883 application.SendNotification();
2884 application.Render();
2886 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2887 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2889 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2890 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2891 application.SendNotification();
2892 application.Render();
2894 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2895 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2900 int UtcDaliImageVisualReleasePolicy08(void)
2902 ToolkitTestApplication application;
2903 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2905 tet_infoline("Create first visual with DESTROYED release policy");
2906 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2908 // Set up trace debug
2909 TestGlAbstraction& gl = application.GetGlAbstraction();
2910 TraceCallStack& textureTrace = gl.GetTextureTrace();
2911 textureTrace.Enable(true);
2913 tet_infoline("Register visuals with control and ensure it has the only handles");
2914 DummyControl actor = DummyControl::New(true);
2915 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2916 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2917 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2919 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2921 // Test initially zero renderers
2922 application.SendNotification();
2923 application.Render(0);
2924 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2925 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2926 textureTrace.Reset();
2928 application.GetScene().Add(actor);
2930 // Wait for image to load
2931 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2933 application.SendNotification();
2934 application.Render(0);
2935 tet_infoline("Ensure a texture is created");
2936 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2937 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2938 textureTrace.Reset();
2940 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2942 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2944 // 2.Remove actor from stage. In this case, renderer also is deleted.
2945 tet_infoline("Remove actor from stage");
2946 application.GetScene().Remove(actor);
2947 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2948 application.SendNotification();
2949 application.Render();
2951 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2952 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2953 textureTrace.Reset();
2955 // 3.Add actor in stage. In this case, renderer is created.
2956 tet_infoline("Add actor in stage");
2957 application.GetScene().Add(actor);
2958 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2959 application.SendNotification();
2960 application.Render();
2961 tet_infoline("Ensure a texture is not created again");
2962 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2963 textureTrace.Reset();
2965 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2966 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2967 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2968 DALI_TEST_CHECK(textureBefore == textureAfter);
2969 textureBefore.Reset();
2970 textureAfter.Reset();
2972 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2973 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2974 application.SendNotification();
2975 application.Render();
2976 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2981 int UtcDaliImageVisualReleasePolicy09(void)
2983 ToolkitTestApplication application;
2984 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2986 Property::Map propertyMapNPatchReleasePolicy;
2987 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2988 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2989 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2990 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2991 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2993 VisualFactory factory = VisualFactory::Get();
2994 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2995 DALI_TEST_CHECK(imageVisual);
2997 // Setup debug trace
2998 TestGlAbstraction& gl = application.GetGlAbstraction();
2999 TraceCallStack& textureTrace = gl.GetTextureTrace();
3000 textureTrace.Enable(true);
3002 tet_infoline("Register visual with control and ensure it has the only handle");
3003 DummyControl actor = DummyControl::New(true);
3004 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3005 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3006 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3008 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3010 application.SendNotification();
3011 application.Render(0);
3012 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3013 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3015 application.GetScene().Add(actor);
3017 // Wait for image to load
3018 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3020 application.SendNotification();
3021 application.Render(0);
3022 // Test renderer and texture created
3023 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3024 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3026 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
3027 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
3028 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3029 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3030 application.SendNotification();
3031 application.Render();
3033 // Test texture removed after visual destroyed.
3034 tet_infoline("Ensure texture is deleted after visual destroyed");
3035 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
3040 int UtcDaliImageVisualLoadPolicy01(void)
3042 ToolkitTestApplication application;
3043 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
3045 // Set up trace debug
3046 TestGlAbstraction& gl = application.GetGlAbstraction();
3047 TraceCallStack& textureTrace = gl.GetTextureTrace();
3048 textureTrace.Enable(true);
3050 tet_infoline("Create visual with IMMEDIATE load policy");
3051 VisualFactory factory = VisualFactory::Get();
3053 Property::Map propertyMap;
3054 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3055 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3056 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
3057 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
3058 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
3060 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3062 Property::Map resultMap;
3063 imageVisual.CreatePropertyMap(resultMap);
3064 DALI_TEST_CHECK(!resultMap.Empty());
3065 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
3067 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3069 // Ensure texture has been uploaded
3070 application.SendNotification();
3071 application.Render();
3073 tet_infoline("Ensure texture loading starts after visual created");
3074 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3075 textureTrace.Reset();
3077 tet_infoline("Register visuals with control and ensure it has the only handles");
3078 DummyControl actor = DummyControl::New(true);
3079 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3080 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3081 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3083 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3084 application.GetScene().Add(actor);
3085 tet_infoline("Ensure nothing triggers another load as texure already loaded");
3086 const unsigned int TIME_OUT_3_SECONDS = 3;
3087 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3089 application.SendNotification();
3090 application.Render();
3092 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3093 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3095 // Ensure texture is deleted when no longer needed (ref count was correct )
3096 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3098 application.SendNotification();
3099 application.Render();
3101 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3102 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3107 int UtcDaliImageVisualLoadPolicy02(void)
3109 ToolkitTestApplication application;
3110 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3112 // Set up trace debug
3113 TestGlAbstraction& gl = application.GetGlAbstraction();
3114 TraceCallStack& textureTrace = gl.GetTextureTrace();
3115 textureTrace.Enable(true);
3117 tet_infoline("Create visual with IMMEDIATE load policy");
3118 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3120 const unsigned int TIME_OUT_3_SECONDS = 3;
3121 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3123 // Act on meeage queue even although nothing expected to load
3124 application.SendNotification();
3125 application.Render();
3127 tet_infoline("Ensure texture is not generated yet");
3128 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3129 textureTrace.Reset();
3131 tet_infoline("Register visuals with control and ensure it has the only handles");
3132 DummyControl actor = DummyControl::New(true);
3133 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3134 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3135 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3137 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3138 application.GetScene().Add(actor);
3139 tet_infoline("Allow image time to load");
3140 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3142 application.SendNotification();
3143 application.Render();
3145 tet_infoline("Ensure texture generated and renderer created");
3146 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3147 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3149 // Ensure texture is delete when no longer needed
3150 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3152 application.SendNotification();
3153 application.Render();
3155 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3156 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3161 int UtcDaliImageVisualLoadPolicy03(void)
3163 ToolkitTestApplication application;
3164 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3166 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3168 // Set up trace debug
3169 TestGlAbstraction& gl = application.GetGlAbstraction();
3170 TraceCallStack& textureTrace = gl.GetTextureTrace();
3171 textureTrace.Enable(true);
3173 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3174 DummyControl actor = DummyControl::New(true);
3175 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3176 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3177 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3179 tet_infoline("Create visual with IMMEDIATE load policy");
3180 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3182 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3183 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3184 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3186 tet_infoline("Allow image time to load resource");
3187 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3188 application.SendNotification();
3189 application.Render();
3191 // Ensure texture has been uploaded
3192 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3193 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3198 int UtcDaliImageVisualLoadPolicy04(void)
3200 ToolkitTestApplication application;
3201 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3202 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3204 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3206 // Set up trace debug
3207 TestGlAbstraction& gl = application.GetGlAbstraction();
3208 TraceCallStack& textureTrace = gl.GetTextureTrace();
3209 textureTrace.Enable(true);
3211 tet_infoline("Create a control and connect to resource ready signal");
3212 DummyControl actor = DummyControl::New(true);
3213 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3214 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3215 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3217 tet_infoline("Create visual with IMMEDIATE load policy");
3218 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3220 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3221 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3222 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3224 tet_infoline("Allow image time to load");
3225 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3226 application.SendNotification();
3227 application.Render();
3229 tet_infoline("Testing texture is loaded and resource ready signal fired");
3230 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3231 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3233 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3235 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3236 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3237 DummyControl actor2 = DummyControl::New(true);
3238 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3239 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3241 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3242 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3243 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3244 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3245 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3246 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3251 int UtcDaliImageVisualLoadPolicy05(void)
3253 ToolkitTestApplication application;
3254 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3255 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3256 // Set up trace debug
3257 TestGlAbstraction& gl = application.GetGlAbstraction();
3258 TraceCallStack& textureTrace = gl.GetTextureTrace();
3259 textureTrace.Enable(true);
3261 tet_infoline("Create a control and connect to resource ready signal");
3262 DummyControl actor = DummyControl::New(true);
3263 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3264 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3265 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3266 application.GetScene().Add(actor);
3268 tet_infoline("Create visual with ATTACHED load policy");
3269 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3271 tet_infoline("Registering visual allows control to get a signal once loaded");
3272 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3273 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3275 tet_infoline("Allow image time to load");
3276 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3277 application.SendNotification();
3278 application.Render();
3280 tet_infoline("Testing texture is loaded and resource ready signal fired");
3281 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3282 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3284 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3286 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3287 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3288 DummyControl actor2 = DummyControl::New(true);
3289 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3290 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3292 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3293 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3294 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3295 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3296 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3297 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3302 int UtcDaliImageVisualOrientationCorrection(void)
3304 ToolkitTestApplication application;
3305 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3307 VisualFactory factory = VisualFactory::Get();
3308 tet_infoline("Create visual with Orientation correction set OFF");
3309 Property::Map propertyMap;
3310 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3311 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3312 propertyMap.Insert("orientationCorrection", false);
3313 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3315 tet_infoline("Create control for visual, need to loaded it");
3316 DummyControl actor = DummyControl::New(true);
3317 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3318 application.GetScene().Add(actor);
3320 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3321 // Wait for image to load
3322 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3324 Vector2 originalImageSize;
3325 tet_infoline("Get size of original visual to compare later with rotated image");
3326 imageVisual.GetNaturalSize(originalImageSize);
3327 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3328 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3329 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3330 application.SendNotification();
3331 application.Render();
3333 tet_infoline("Create visual with Orientation correction set ON ");
3334 propertyMap.Clear();
3335 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3336 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3337 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3338 imageVisual = factory.CreateVisual(propertyMap);
3340 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3341 // Wait for image to load
3342 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3344 Vector2 rotatedImageSize;
3345 imageVisual.GetNaturalSize(rotatedImageSize);
3346 tet_infoline("Confirm that visual has rotated");
3347 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3348 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3350 Property::Map resultMap;
3351 imageVisual.CreatePropertyMap(resultMap);
3353 // check the Property::ORIENTATION_CORRECTION value from the returned map
3354 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3355 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3360 int UtcDaliImageVisualCustomShader(void)
3362 ToolkitTestApplication application;
3363 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3365 VisualFactory factory = VisualFactory::Get();
3366 Property::Map properties;
3367 Property::Map shader;
3368 const std::string vertexShader = "Foobar";
3369 const std::string fragmentShader = "Foobar";
3370 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3371 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3373 properties[Visual::Property::TYPE] = Visual::IMAGE;
3374 properties[Visual::Property::SHADER] = shader;
3375 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3377 Visual::Base visual = factory.CreateVisual(properties);
3379 // trigger creation through setting on stage
3380 DummyControl dummy = DummyControl::New(true);
3381 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3382 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3384 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3385 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3386 application.GetScene().Add(dummy);
3388 application.SendNotification();
3389 application.Render();
3391 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3393 Renderer renderer = dummy.GetRendererAt(0);
3394 Shader shader2 = renderer.GetShader();
3395 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3396 Property::Map* map = value.GetMap();
3397 DALI_TEST_CHECK(map);
3399 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3400 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3402 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3403 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3407 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3408 properties[Visual::Property::SHADER] = shader;
3410 Visual::Base visual1 = factory.CreateVisual(properties);
3412 // trigger creation through setting on stage
3413 DummyControl dummy1 = DummyControl::New(true);
3414 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3415 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3416 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3417 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3418 application.GetScene().Add(dummy1);
3420 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3421 glAbstraction.EnableEnableDisableCallTrace(true);
3423 application.SendNotification();
3424 application.Render();
3426 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3427 std::ostringstream blendStr;
3428 blendStr << std::hex << GL_BLEND;
3429 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3434 void ResourceReadyLoadNext(Control control)
3436 static int callNumber = 0;
3438 gResourceReadySignalFired = true;
3439 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3443 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3445 tet_infoline("Create visual with loaded image from within the signal handler");
3446 VisualFactory factory = VisualFactory::Get();
3447 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3449 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3450 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3455 tet_infoline("3rd signal called");
3456 DALI_TEST_CHECK(true);
3460 int UtcDaliImageVisualLoadReady01(void)
3462 ToolkitTestApplication application;
3463 tet_infoline("UtcDaliImageVisualLoadReady01");
3464 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3465 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3466 tet_infoline("Should get a ready signal for all three visuals");
3470 tet_infoline("Create a control and connect to resource ready signal");
3471 DummyControl actor = DummyControl::New(true);
3472 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3473 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3474 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3475 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3476 application.GetScene().Add(actor);
3478 tet_infoline("Create visual with IMMEDIATE load policy");
3479 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3481 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3482 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3484 tet_infoline("Allow image time to load");
3485 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3486 application.SendNotification();
3487 application.Render();
3489 tet_infoline("Testing texture is loaded and resource ready signal fired");
3490 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3491 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3493 tet_infoline("Original control correctly signalled, now testing failing image");
3495 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3498 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3500 DummyControl actor2 = DummyControl::New(true);
3501 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3502 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3503 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3505 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3506 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3508 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3509 application.GetScene().Add(actor2);
3511 tet_infoline("Wait for loading thread to finish");
3512 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3513 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3515 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3517 tet_infoline("Check for 3rd signal");
3518 application.SendNotification();
3519 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3520 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3525 int UtcDaliImageVisualLoadImagePlanes01(void)
3527 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3528 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3530 ToolkitTestApplication application;
3532 VisualFactory factory = VisualFactory::Get();
3533 DALI_TEST_CHECK(factory);
3535 Property::Map propertyMap;
3536 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3537 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3539 Visual::Base visual = factory.CreateVisual(propertyMap);
3540 DALI_TEST_CHECK(visual);
3542 DummyControl actor = DummyControl::New();
3543 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3544 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3545 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3546 application.GetScene().Add(actor);
3548 application.SendNotification();
3549 application.Render();
3551 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3553 TestGlAbstraction& gl = application.GetGlAbstraction();
3554 TraceCallStack& textureTrace = gl.GetTextureTrace();
3555 textureTrace.Enable(true);
3557 application.SendNotification();
3558 application.Render();
3560 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3561 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3562 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3564 Renderer renderer = actor.GetRendererAt(0);
3565 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3566 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3571 int UtcDaliImageVisualLoadImagePlanes02(void)
3573 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3574 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3576 ToolkitTestApplication application;
3578 VisualFactory factory = VisualFactory::Get();
3579 DALI_TEST_CHECK(factory);
3581 // Alpha masking case - not support yuv planes
3582 Property::Map propertyMap;
3583 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3584 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3585 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3587 Visual::Base visual = factory.CreateVisual(propertyMap);
3588 DALI_TEST_CHECK(visual);
3590 DummyControl actor = DummyControl::New();
3591 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3592 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3593 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3594 application.GetScene().Add(actor);
3596 application.SendNotification();
3597 application.Render();
3599 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3601 TestGlAbstraction& gl = application.GetGlAbstraction();
3602 TraceCallStack& textureTrace = gl.GetTextureTrace();
3603 textureTrace.Enable(true);
3605 application.SendNotification();
3606 application.Render();
3608 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3609 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3610 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3615 int UtcDaliImageVisualLoadImagePlanes03(void)
3617 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3618 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3620 ToolkitTestApplication application;
3622 VisualFactory factory = VisualFactory::Get();
3623 DALI_TEST_CHECK(factory);
3625 TestGlAbstraction& gl = application.GetGlAbstraction();
3626 TraceCallStack& textureTrace = gl.GetTextureTrace();
3627 textureTrace.Enable(true);
3629 Property::Map propertyMap;
3630 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3631 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3632 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3634 Visual::Base visual = factory.CreateVisual(propertyMap);
3635 DALI_TEST_CHECK(visual);
3637 DummyControl actor = DummyControl::New();
3638 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3639 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3640 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3641 application.GetScene().Add(actor);
3643 application.SendNotification();
3644 application.Render();
3646 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3647 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3648 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3653 int UtcDaliImageVisualLoadFastTrackImage01(void)
3655 tet_infoline("Test worker thread uploading with Local URL");
3656 ToolkitTestApplication application;
3658 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3660 VisualFactory factory = VisualFactory::Get();
3661 DALI_TEST_CHECK(factory);
3663 // Pair of filename - expect GenTextures count.
3664 std::vector<std::pair<std::string, int>> testCases = {
3665 {TEST_IMAGE_FILE_NAME, 1},
3666 {TEST_REMOTE_IMAGE_FILE_NAME, 1},
3667 {TEST_INVALID_FILE_NAME, 0},
3670 for(auto&& tc : testCases)
3672 auto& filename = tc.first;
3673 auto& expectValue = tc.second;
3675 tet_printf("Test %s\n", filename.c_str());
3677 Property::Map propertyMap;
3678 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3679 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3680 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3682 Visual::Base visual = factory.CreateVisual(propertyMap);
3683 DALI_TEST_CHECK(visual);
3685 DummyControl actor = DummyControl::New();
3686 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3687 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3688 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3690 TestGlAbstraction& gl = application.GetGlAbstraction();
3691 TraceCallStack& textureTrace = gl.GetTextureTrace();
3692 textureTrace.Enable(true);
3694 application.GetScene().Add(actor);
3696 application.SendNotification();
3697 application.Render();
3699 // EventThread without callback
3700 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3702 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3705 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3706 // How can we make it? Should it be integration-api?
3707 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3708 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3710 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3711 application.Render();
3713 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3715 application.SendNotification();
3716 application.Render();
3718 textureTrace.Reset();
3724 int UtcDaliImageVisualLoadFastTrackImage02(void)
3726 tet_infoline("Test worker thread uploading with Local URL");
3727 ToolkitTestApplication application;
3729 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3731 VisualFactory factory = VisualFactory::Get();
3732 DALI_TEST_CHECK(factory);
3735 auto filename = std::string(TEST_IMAGE_FILE_NAME);
3736 auto expectValue = 1;
3738 tet_printf("Test %s\n", filename.c_str());
3740 Property::Map propertyMap;
3741 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3742 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3743 propertyMap.Insert("fastTrackUploading", true);
3745 Visual::Base visual = factory.CreateVisual(propertyMap);
3746 DALI_TEST_CHECK(visual);
3748 DummyControl actor = DummyControl::New();
3749 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3750 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3751 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3753 TestGlAbstraction& gl = application.GetGlAbstraction();
3754 TraceCallStack& textureTrace = gl.GetTextureTrace();
3755 textureTrace.Enable(true);
3757 application.GetScene().Add(actor);
3759 application.SendNotification();
3760 application.Render();
3762 // EventThread without callback
3763 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3765 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3768 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3769 // How can we make it? Should it be integration-api?
3770 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3771 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3773 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3774 application.Render();
3776 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3778 application.SendNotification();
3779 application.Render();
3781 textureTrace.Reset();
3787 int UtcDaliImageVisualLoadFastTrackImageResourceReady(void)
3789 tet_infoline("Test worker thread uploading with Local URL");
3790 ToolkitTestApplication application;
3792 VisualFactory factory = VisualFactory::Get();
3793 DALI_TEST_CHECK(factory);
3795 Property::Map propertyMap;
3796 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3797 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3798 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3800 Visual::Base visual = factory.CreateVisual(propertyMap);
3801 DALI_TEST_CHECK(visual);
3803 DummyControl actor = DummyControl::New();
3804 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3805 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3806 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3808 TestGlAbstraction& gl = application.GetGlAbstraction();
3809 TraceCallStack& textureTrace = gl.GetTextureTrace();
3810 textureTrace.Enable(true);
3812 application.GetScene().Add(actor);
3814 application.SendNotification();
3815 application.Render();
3817 // EventThread with callback
3818 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3820 // Check resource ready comes after
3821 application.SendNotification();
3822 application.Render();
3824 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3825 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3830 int UtcDaliImageVisualLoadFastTrackImageReload(void)
3832 tet_infoline("Test worker thread uploading with Local URL");
3833 ToolkitTestApplication application;
3835 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3837 VisualFactory factory = VisualFactory::Get();
3838 DALI_TEST_CHECK(factory);
3840 Property::Map propertyMap;
3841 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3842 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3843 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3845 Visual::Base visual = factory.CreateVisual(propertyMap);
3846 DALI_TEST_CHECK(visual);
3848 DummyControl actor = DummyControl::New();
3849 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3850 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3851 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3853 TestGlAbstraction& gl = application.GetGlAbstraction();
3854 TraceCallStack& textureTrace = gl.GetTextureTrace();
3855 textureTrace.Enable(true);
3857 application.GetScene().Add(actor);
3859 application.SendNotification();
3860 application.Render();
3862 // EventThread without callback
3863 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3865 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3868 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3869 // How can we make it? Should it be integration-api?
3870 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3871 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), true, TEST_LOCATION);
3873 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3874 application.Render();
3876 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3879 Property::Map attributes;
3880 DevelControl::DoAction(actor, Control::CONTROL_PROPERTY_END_INDEX + 1, DevelImageVisual::Action::RELOAD, attributes);
3882 // EventThread with callback
3883 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3885 // Check resource ready comes after
3886 application.SendNotification();
3887 application.Render();
3889 // Check whether renderer count is 1 or not.
3890 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3891 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3896 int UtcDaliImageVisualLoadFastTrackImagePlanes01(void)
3898 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3899 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3901 ToolkitTestApplication application;
3903 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3905 VisualFactory factory = VisualFactory::Get();
3906 DALI_TEST_CHECK(factory);
3908 Property::Map propertyMap;
3909 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3910 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3911 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3913 Visual::Base visual = factory.CreateVisual(propertyMap);
3914 DALI_TEST_CHECK(visual);
3916 DummyControl actor = DummyControl::New();
3917 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3918 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3919 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3921 TestGlAbstraction& gl = application.GetGlAbstraction();
3922 TraceCallStack& textureTrace = gl.GetTextureTrace();
3923 textureTrace.Enable(true);
3925 application.GetScene().Add(actor);
3927 application.SendNotification();
3928 application.Render();
3930 // EventThread without callback
3931 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3933 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3936 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3937 // How can we make it? Should it be integration-api?
3938 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3939 textureUploadManager.ResourceUpload();
3940 application.Render();
3942 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3943 application.Render();
3945 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3947 application.SendNotification();
3948 application.Render();
3953 int UtcDaliImageVisualLoadFastTrackImagePlanes02(void)
3955 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3956 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3958 ToolkitTestApplication application;
3960 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3962 VisualFactory factory = VisualFactory::Get();
3963 DALI_TEST_CHECK(factory);
3965 Property::Map propertyMap;
3966 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3967 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3968 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3970 Visual::Base visual = factory.CreateVisual(propertyMap);
3971 DALI_TEST_CHECK(visual);
3973 DummyControl actor = DummyControl::New();
3974 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3975 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3976 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3978 TestGlAbstraction& gl = application.GetGlAbstraction();
3979 TraceCallStack& textureTrace = gl.GetTextureTrace();
3980 textureTrace.Enable(true);
3982 application.GetScene().Add(actor);
3984 application.SendNotification();
3985 application.Render();
3987 // EventThread without callback
3988 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3990 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3993 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3994 // How can we make it? Should it be integration-api?
3995 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3996 textureUploadManager.ResourceUpload();
3997 application.Render();
3999 // Render only without SendNotification(). And check whether glTexImage2D called or not.
4000 application.Render();
4002 DALI_TEST_GREATER(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4004 application.SendNotification();
4005 application.Render();
4010 int UtcDaliImageVisualDebugImageVisualShaderP1(void)
4012 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4013 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "validFile"); // Try to load not exist file.
4015 // Set valid script file
4016 Test::StyleMonitor::SetThemeFileOutput("validFile", VALID_DEBUG_SHADER_SCRIPT);
4018 ToolkitTestApplication application;
4020 VisualFactory factory = VisualFactory::Get();
4021 DALI_TEST_CHECK(factory);
4023 Property::Map propertyMap;
4024 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4025 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4027 Visual::Base visual = factory.CreateVisual(propertyMap);
4028 DALI_TEST_CHECK(visual);
4030 DummyControl actor = DummyControl::New();
4031 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4032 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4033 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4034 application.GetScene().Add(actor);
4036 application.SendNotification();
4037 application.Render();
4039 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4041 TestGlAbstraction& gl = application.GetGlAbstraction();
4042 TraceCallStack& textureTrace = gl.GetTextureTrace();
4043 textureTrace.Enable(true);
4045 application.SendNotification();
4046 application.Render();
4048 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4049 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4050 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4055 int UtcDaliImageVisualDebugImageVisualShaderN1(void)
4057 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4058 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "notJsonFile"); // Try to load exist file, but not a json
4060 // Set invalid script file
4061 Test::StyleMonitor::SetThemeFileOutput("notJsonFile", "1");
4063 ToolkitTestApplication application;
4065 VisualFactory factory = VisualFactory::Get();
4066 DALI_TEST_CHECK(factory);
4068 Property::Map propertyMap;
4069 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4070 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4072 Visual::Base visual = factory.CreateVisual(propertyMap);
4073 DALI_TEST_CHECK(visual);
4075 DummyControl actor = DummyControl::New();
4076 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4077 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4078 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4079 application.GetScene().Add(actor);
4081 application.SendNotification();
4082 application.Render();
4084 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4086 TestGlAbstraction& gl = application.GetGlAbstraction();
4087 TraceCallStack& textureTrace = gl.GetTextureTrace();
4088 textureTrace.Enable(true);
4090 application.SendNotification();
4091 application.Render();
4093 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4094 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4095 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4100 int UtcDaliImageVisualDebugImageVisualShaderN2(void)
4102 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4103 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, std::string(THROW_EXCEPTION_STYLE_FILE_NAME).c_str()); // Try to load file that throw some exception
4105 // Set throw exception script file
4106 Test::StyleMonitor::SetThemeFileOutput(std::string(THROW_EXCEPTION_STYLE_FILE_NAME), "1");
4108 ToolkitTestApplication application;
4110 VisualFactory factory = VisualFactory::Get();
4111 DALI_TEST_CHECK(factory);
4113 Property::Map propertyMap;
4114 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4115 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4117 Visual::Base visual = factory.CreateVisual(propertyMap);
4118 DALI_TEST_CHECK(visual);
4120 DummyControl actor = DummyControl::New();
4121 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4122 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4123 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4124 application.GetScene().Add(actor);
4126 application.SendNotification();
4127 application.Render();
4129 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4131 TestGlAbstraction& gl = application.GetGlAbstraction();
4132 TraceCallStack& textureTrace = gl.GetTextureTrace();
4133 textureTrace.Enable(true);
4135 application.SendNotification();
4136 application.Render();
4138 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4139 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4140 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);