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);
1388 int UtcDaliImageVisualCustomWrapModePixelArea02(void)
1390 ToolkitTestApplication application;
1391 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area");
1393 static std::vector<UniformData> customUniforms =
1395 UniformData("pixelArea", Property::Type::VECTOR4),
1396 UniformData("wrapMode", Property::Type::VECTOR2),
1399 TestGraphicsController& graphics = application.GetGraphicsController();
1400 graphics.AddCustomUniforms(customUniforms);
1402 VisualFactory factory = VisualFactory::Get();
1403 DALI_TEST_CHECK(factory);
1405 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1406 const int width = 34;
1407 const int height = 34;
1408 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1410 Property::Map propertyMap;
1411 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1412 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1413 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1414 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1415 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
1416 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1417 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1418 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::CLAMP_TO_EDGE);
1420 Visual::Base visual = factory.CreateVisual(propertyMap);
1421 DALI_TEST_CHECK(visual);
1423 TestGlAbstraction& gl = application.GetGlAbstraction();
1424 TraceCallStack& textureTrace = gl.GetTextureTrace();
1425 textureTrace.Enable(true);
1426 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1427 texParameterTrace.Enable(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();
1440 // Wait image load complete.
1441 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1443 application.SendNotification();
1444 application.Render();
1446 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1448 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1450 // Following gl function should not be called
1451 std::stringstream out;
1452 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1453 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1455 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE;
1456 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1458 // test the uniforms which used to handle the wrap mode
1459 Renderer renderer = actor.GetRendererAt(0u);
1460 DALI_TEST_CHECK(renderer);
1462 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1463 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1464 Vector4 pixelAreaUniform;
1465 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1466 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1469 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1474 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1476 ToolkitTestApplication application;
1477 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1479 static std::vector<UniformData> customUniforms =
1481 UniformData("pixelArea", Property::Type::VECTOR4),
1484 TestGraphicsController& graphics = application.GetGraphicsController();
1485 graphics.AddCustomUniforms(customUniforms);
1487 VisualFactory factory = VisualFactory::Get();
1488 DALI_TEST_CHECK(factory);
1490 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1491 const int width = 600;
1492 const int height = 600;
1493 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1495 Property::Map propertyMap;
1496 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1497 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1498 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1499 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1500 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1501 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1502 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1503 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1505 Visual::Base visual = factory.CreateVisual(propertyMap);
1506 DALI_TEST_CHECK(visual);
1508 TestGlAbstraction& gl = application.GetGlAbstraction();
1509 TraceCallStack& textureTrace = gl.GetTextureTrace();
1510 textureTrace.Enable(true);
1511 textureTrace.EnableLogging(true);
1512 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1513 texParameterTrace.Enable(true);
1514 texParameterTrace.EnableLogging(true);
1516 DummyControl actor = DummyControl::New();
1517 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1518 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1519 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1520 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1521 application.GetScene().Add(actor);
1524 application.SendNotification();
1525 application.Render();
1526 application.SendNotification();
1528 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1530 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1532 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1533 std::stringstream out;
1534 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1535 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1537 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1538 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1540 // test the uniforms which used to handle the wrap mode
1541 Renderer renderer = actor.GetRendererAt(0u);
1542 DALI_TEST_CHECK(renderer);
1544 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1545 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1546 Vector4 pixelAreaUniform;
1547 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1548 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1550 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1551 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1554 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1559 int UtcDaliImageVisualAnimateMixColor(void)
1561 ToolkitTestApplication application;
1562 tet_infoline("Animate mix color");
1564 static std::vector<UniformData> customUniforms =
1566 UniformData("mixColor", Property::Type::VECTOR3),
1569 TestGraphicsController& graphics = application.GetGraphicsController();
1570 graphics.AddCustomUniforms(customUniforms);
1572 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1574 VisualFactory factory = VisualFactory::Get();
1575 Property::Map propertyMap;
1576 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1577 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1578 propertyMap.Insert("mixColor", Color::BLUE);
1579 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1580 Visual::Base visual = factory.CreateVisual(propertyMap);
1582 DummyControl actor = DummyControl::New(true);
1583 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1584 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1586 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1587 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1588 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1589 application.GetScene().Add(actor);
1591 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1593 Renderer renderer = actor.GetRendererAt(0);
1595 // @todo Should we add API to make this code work again?
1596 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1598 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1599 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1601 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1604 map["target"] = "testVisual";
1605 map["property"] = "mixColor";
1606 map["initialValue"] = Color::MAGENTA;
1607 map["targetValue"] = TARGET_MIX_COLOR;
1608 map["animator"] = Property::Map()
1609 .Add("alphaFunction", "LINEAR")
1610 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1612 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1614 Animation animation = dummyImpl.CreateTransition(transition);
1616 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1619 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1620 glAbstraction.EnableEnableDisableCallTrace(true);
1621 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1622 std::ostringstream blendStr;
1623 blendStr << std::hex << GL_BLEND;
1625 application.SendNotification();
1626 application.Render(0); // Ensure animation starts
1627 application.Render(2000u); // Halfway point
1628 Vector3 testColor(1.0f, 0.0f, 0.5f);
1630 // uColor.a should be actor's alpha * mixColor.a.
1631 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1632 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1634 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1636 glEnableStack.Reset();
1638 application.SendNotification();
1639 application.Render(2000u);
1641 application.SendNotification();
1642 application.Render();
1643 application.SendNotification();
1645 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1646 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1647 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1649 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1651 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1656 int UtcDaliImageVisualAnimateOpacity(void)
1658 ToolkitTestApplication application;
1659 tet_infoline("Animate image visual opacity");
1661 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1663 VisualFactory factory = VisualFactory::Get();
1664 Property::Map propertyMap;
1665 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1666 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1667 propertyMap.Insert("opacity", 0.5f);
1668 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1669 Visual::Base visual = factory.CreateVisual(propertyMap);
1671 DummyControl actor = DummyControl::New(true);
1672 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1673 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1675 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1676 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1677 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1678 application.GetScene().Add(actor);
1680 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1682 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1683 glAbstraction.EnableEnableDisableCallTrace(true);
1684 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1685 std::ostringstream blendStr;
1686 blendStr << std::hex << GL_BLEND;
1688 application.SendNotification();
1689 application.Render();
1691 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1694 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.");
1697 map["target"] = "testVisual";
1698 map["property"] = "opacity";
1699 map["targetValue"] = 1.0f;
1700 map["animator"] = Property::Map()
1701 .Add("alphaFunction", "LINEAR")
1702 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1704 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1705 Animation animation = dummyImpl.CreateTransition(transition);
1708 glEnableStack.Reset();
1710 application.SendNotification();
1711 application.Render(0); // Ensure animation starts
1712 application.Render(2000u); // Halfway point through animation
1713 application.SendNotification(); // Handle any signals
1716 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1717 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1719 application.Render(2001u); // end
1720 application.SendNotification(); // ensure animation finished signal is sent
1722 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1723 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1725 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1726 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1730 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.");
1733 map["target"] = "testVisual";
1734 map["property"] = Visual::Property::OPACITY;
1735 map["targetValue"] = 0.1f;
1736 map["animator"] = Property::Map()
1737 .Add("alphaFunction", "LINEAR")
1738 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1740 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1741 Animation animation = dummyImpl.CreateTransition(transition);
1744 glEnableStack.Reset();
1746 application.SendNotification();
1747 application.Render(0); // Ensure animation starts
1748 application.Render(2000u); // Halfway point
1749 application.SendNotification();
1752 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1753 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1755 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1757 glEnableStack.Reset();
1759 application.Render(2016u); // end
1760 application.SendNotification();
1762 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1763 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1765 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1766 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1772 int UtcDaliImageVisualAnimateOpacity02(void)
1774 ToolkitTestApplication application;
1775 tet_infoline("Animate image visual opacity");
1777 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1779 VisualFactory factory = VisualFactory::Get();
1780 Property::Map propertyMap;
1781 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1782 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1783 propertyMap.Insert("opacity", 0.5f);
1784 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1785 Visual::Base visual = factory.CreateVisual(propertyMap);
1787 DummyControl actor = DummyControl::New(true);
1788 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1789 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1791 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1792 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1793 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1795 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1797 Property::Array array;
1800 map["target"] = "testVisual";
1801 map["property"] = "opacity";
1802 map["initialValue"] = 0.0f;
1803 map["targetValue"] = 1.0f;
1804 map["animator"] = Property::Map()
1805 .Add("alphaFunction", "LINEAR")
1806 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1809 map2["target"] = "testVisual";
1810 map2["property"] = "size";
1811 map2["targetValue"] = Vector2(1.0f, 1.0f);
1813 array.Add(map).Add(map2);
1815 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1816 Animation animation = dummyImpl.CreateTransition(transition);
1818 application.GetScene().Add(actor);
1819 application.SendNotification();
1820 application.Render(0); // Ensure animation starts
1822 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1824 Renderer renderer = actor.GetRendererAt(0);
1825 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1826 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1828 animation = dummyImpl.CreateTransition(transition);
1831 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1832 glAbstraction.EnableEnableDisableCallTrace(true);
1833 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1834 std::ostringstream blendStr;
1835 blendStr << std::hex << GL_BLEND;
1837 application.SendNotification();
1838 application.Render(0); // Ensure animation starts
1839 application.Render(2000u); // Halfway point through animation
1840 application.SendNotification(); // Handle any signals
1842 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1845 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1846 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1848 glEnableStack.Reset();
1850 application.Render(2001u); // end
1851 application.SendNotification(); // ensure animation finished signal is sent
1853 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1854 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1856 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1861 int UtcDaliImageVisualAnimatePixelArea(void)
1863 ToolkitTestApplication application;
1864 tet_infoline("ImageVisual animate pixel area");
1866 static std::vector<UniformData> customUniforms =
1868 UniformData("pixelArea", Property::Type::VECTOR4),
1871 TestGraphicsController& graphics = application.GetGraphicsController();
1872 graphics.AddCustomUniforms(customUniforms);
1874 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1876 VisualFactory factory = VisualFactory::Get();
1877 Property::Map propertyMap;
1878 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1879 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1880 propertyMap.Insert("mixColor", Color::BLUE);
1881 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1882 Visual::Base visual = factory.CreateVisual(propertyMap);
1884 DummyControl actor = DummyControl::New(true);
1885 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1886 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1888 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1889 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1890 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1891 application.GetScene().Add(actor);
1893 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1895 Renderer renderer = actor.GetRendererAt(0);
1896 // @todo Implement this feature?
1897 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1898 //tet_infoline("Test that the renderer has the mixColor property");
1899 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1901 // TransitionData only takes string keys
1903 map["target"] = "testVisual";
1904 map["property"] = "pixelArea";
1905 map["initialValue"] = Vector4(0, 0, 0, 1);
1906 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1907 map["animator"] = Property::Map()
1908 .Add("alphaFunction", "LINEAR")
1909 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1911 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1913 Animation animation = dummyImpl.CreateTransition(transition);
1914 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1917 application.SendNotification();
1918 application.Render(0); // Ensure animation starts
1919 application.Render(2000u); // Halfway point
1921 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1923 application.Render(2000u); // End of animation
1925 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1930 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1932 ToolkitTestApplication application;
1933 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1935 Property::Map propertyMap;
1936 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1937 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1939 TestGlAbstraction& gl = application.GetGlAbstraction();
1940 TraceCallStack& textureTrace = gl.GetTextureTrace();
1941 textureTrace.Enable(true);
1942 TraceCallStack& drawTrace = gl.GetDrawTrace();
1943 drawTrace.Enable(true);
1945 Actor actor = CreateActorWithImageVisual(propertyMap);
1946 application.GetScene().Add(actor);
1947 application.SendNotification();
1949 application.GetScene().Remove(actor);
1950 application.SendNotification();
1952 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1953 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1954 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1955 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1960 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1962 ToolkitTestApplication application;
1963 tet_infoline("Load image asynchronously, cancel loading, then load again");
1965 VisualFactory factory = VisualFactory::Get();
1966 DALI_TEST_CHECK(factory);
1968 Property::Map propertyMap;
1969 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1970 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1972 Visual::Base visual = factory.CreateVisual(propertyMap);
1973 DALI_TEST_CHECK(visual);
1975 TestGlAbstraction& gl = application.GetGlAbstraction();
1976 TraceCallStack& textureTrace = gl.GetTextureTrace();
1977 textureTrace.Enable(true);
1978 TraceCallStack& drawTrace = gl.GetDrawTrace();
1979 drawTrace.Enable(true);
1981 DummyControl actor = DummyControl::New();
1982 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1983 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1985 application.GetScene().Add(actor);
1988 application.GetScene().Remove(actor);
1990 application.GetScene().Add(actor);
1992 // Create another visual with the same image
1993 visual = factory.CreateVisual(propertyMap);
1994 DALI_TEST_CHECK(visual);
1996 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1998 application.SendNotification();
1999 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2001 application.SendNotification();
2002 application.Render();
2004 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2005 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2006 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2007 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
2012 int UtcDaliImageVisualSetInvalidAsyncImage(void)
2014 ToolkitTestApplication application;
2015 tet_infoline("Request image visual with invalid images - should draw broken.png");
2017 VisualFactory factory = VisualFactory::Get();
2018 DALI_TEST_CHECK(factory);
2020 Property::Map propertyMap;
2021 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2022 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
2024 Visual::Base visual = factory.CreateVisual(propertyMap);
2025 DALI_TEST_CHECK(visual);
2027 TestGlAbstraction& gl = application.GetGlAbstraction();
2028 TraceCallStack& textureTrace = gl.GetTextureTrace();
2029 textureTrace.Enable(true);
2031 DummyControl actor = DummyControl::New();
2032 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2033 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2035 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2036 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2038 application.GetScene().Add(actor);
2040 application.SendNotification();
2041 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2043 application.SendNotification();
2044 application.Render();
2046 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2047 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2049 application.GetScene().Remove(actor);
2050 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2055 int UtcDaliImageVisualSetInvalidSyncImage(void)
2057 ToolkitTestApplication application;
2058 tet_infoline("Request image visual with invalid images - should draw broken.png");
2060 VisualFactory factory = VisualFactory::Get();
2061 DALI_TEST_CHECK(factory);
2063 Property::Map propertyMap;
2064 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2065 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
2066 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2068 Visual::Base visual = factory.CreateVisual(propertyMap);
2069 DALI_TEST_CHECK(visual);
2071 TestGlAbstraction& gl = application.GetGlAbstraction();
2072 TraceCallStack& textureTrace = gl.GetTextureTrace();
2073 textureTrace.Enable(true);
2075 DummyControl actor = DummyControl::New();
2076 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2077 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2079 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2080 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2082 application.GetScene().Add(actor);
2084 application.SendNotification();
2085 application.Render();
2087 // Check resource status
2088 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
2089 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2091 // The broken image should be shown.
2092 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2093 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2095 application.GetScene().Remove(actor);
2096 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2101 int UtcDaliImageVisualSetInvalidRemoteImage(void)
2103 ToolkitTestApplication application;
2104 tet_infoline("Request image visual with invalid images - should draw broken.png");
2106 VisualFactory factory = VisualFactory::Get();
2107 DALI_TEST_CHECK(factory);
2109 // Local invalid file, asynchronous loading
2110 Property::Map propertyMap;
2111 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2112 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
2114 Visual::Base visual = factory.CreateVisual(propertyMap);
2115 DALI_TEST_CHECK(visual);
2117 TestGlAbstraction& gl = application.GetGlAbstraction();
2118 TraceCallStack& textureTrace = gl.GetTextureTrace();
2119 textureTrace.Enable(true);
2121 DummyControl actor = DummyControl::New();
2122 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2123 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2125 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2126 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2128 application.GetScene().Add(actor);
2130 application.SendNotification();
2131 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2133 application.SendNotification();
2134 application.Render();
2136 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2137 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2139 application.GetScene().Remove(actor);
2140 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2145 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
2147 ToolkitTestApplication application;
2148 tet_infoline("Request image visual with invalid images - should draw broken.png");
2150 VisualFactory factory = VisualFactory::Get();
2151 DALI_TEST_CHECK(factory);
2153 // Load invalid file
2154 Property::Map propertyMap;
2155 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2156 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2158 Visual::Base visual = factory.CreateVisual(propertyMap);
2159 DALI_TEST_CHECK(visual);
2161 TestGlAbstraction& gl = application.GetGlAbstraction();
2162 TraceCallStack& textureTrace = gl.GetTextureTrace();
2163 textureTrace.Enable(true);
2165 DummyControl actor = DummyControl::New();
2166 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2167 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2169 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2170 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2172 application.GetScene().Add(actor);
2174 application.SendNotification();
2175 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2177 application.SendNotification();
2178 application.Render();
2180 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2181 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2183 application.GetScene().Remove(actor);
2184 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2185 textureTrace.Reset();
2187 // Load invalid file with disabled broken
2188 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2189 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2190 propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2192 visual = factory.CreateVisual(propertyMap);
2193 DALI_TEST_CHECK(visual);
2195 actor = DummyControl::New();
2196 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2197 dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2199 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2200 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2202 application.GetScene().Add(actor);
2204 application.SendNotification();
2205 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2207 application.SendNotification();
2208 application.Render();
2210 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2211 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2213 application.GetScene().Remove(actor);
2214 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2219 int UtcDaliImageVisualAlphaMask01(void)
2221 ToolkitTestApplication application;
2222 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2224 VisualFactory factory = VisualFactory::Get();
2225 DALI_TEST_CHECK(factory);
2227 Property::Map propertyMap;
2228 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2229 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2230 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2232 Visual::Base visual = factory.CreateVisual(propertyMap);
2233 DALI_TEST_CHECK(visual);
2235 Property::Map testMap;
2236 visual.CreatePropertyMap(testMap);
2237 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2239 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2240 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2242 TestGlAbstraction& gl = application.GetGlAbstraction();
2243 TraceCallStack& textureTrace = gl.GetTextureTrace();
2244 textureTrace.Enable(true);
2246 DummyControl actor = DummyControl::New();
2247 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2248 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2250 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2251 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2252 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2254 application.GetScene().Add(actor);
2255 application.SendNotification();
2256 application.Render();
2258 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2260 application.SendNotification();
2261 application.Render();
2263 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2264 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2265 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2267 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2268 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2273 int UtcDaliImageVisualAlphaMask02(void)
2275 ToolkitTestApplication application;
2276 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2278 VisualFactory factory = VisualFactory::Get();
2279 DALI_TEST_CHECK(factory);
2281 Property::Map propertyMap;
2282 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2283 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2284 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2285 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2286 propertyMap.Insert(DevelImageVisual::Property::CROP_TO_MASK, false);
2288 Visual::Base visual = factory.CreateVisual(propertyMap);
2289 DALI_TEST_CHECK(visual);
2291 Property::Map testMap;
2292 visual.CreatePropertyMap(testMap);
2293 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2294 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2296 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2297 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2299 TestGlAbstraction& gl = application.GetGlAbstraction();
2300 TraceCallStack& textureTrace = gl.GetTextureTrace();
2301 textureTrace.Enable(true);
2303 DummyControl actor = DummyControl::New();
2304 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2305 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2307 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2308 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2309 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2311 application.GetScene().Add(actor);
2312 application.SendNotification();
2313 application.Render();
2315 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2317 application.SendNotification();
2318 application.Render();
2320 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2321 Renderer renderer = actor.GetRendererAt(0u);
2322 TextureSet textures = renderer.GetTextures();
2323 DALI_TEST_CHECK(textures);
2324 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2326 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2327 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2329 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2330 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2332 auto index = renderer.GetPropertyIndex("maskTextureRatio");
2333 DALI_TEST_NOT_EQUALS(index, Property::INVALID_INDEX, 0.1f, TEST_LOCATION);
2334 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2::ONE, TEST_LOCATION);
2339 int UtcDaliImageVisualAlphaMask03(void)
2341 ToolkitTestApplication application;
2342 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2344 VisualFactory factory = VisualFactory::Get();
2345 DALI_TEST_CHECK(factory);
2347 Property::Map propertyMap;
2348 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2349 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2350 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2351 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2353 Visual::Base visual = factory.CreateVisual(propertyMap);
2354 DALI_TEST_CHECK(visual);
2356 Property::Map testMap;
2357 visual.CreatePropertyMap(testMap);
2359 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2360 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2362 TestGlAbstraction& gl = application.GetGlAbstraction();
2363 TraceCallStack& textureTrace = gl.GetTextureTrace();
2364 textureTrace.Enable(true);
2366 DummyControl actor = DummyControl::New();
2367 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2368 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2370 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2371 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2372 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2374 application.GetScene().Add(actor);
2375 application.SendNotification();
2376 application.Render();
2378 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2380 application.SendNotification();
2381 application.Render();
2383 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2384 Renderer renderer = actor.GetRendererAt(0u);
2385 TextureSet textures = renderer.GetTextures();
2386 DALI_TEST_CHECK(textures);
2387 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2389 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2390 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2392 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2393 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2398 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2400 ToolkitTestApplication application;
2401 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2403 VisualFactory factory = VisualFactory::Get();
2404 DALI_TEST_CHECK(factory);
2406 Property::Map propertyMap;
2407 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2408 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2409 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2410 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2412 Visual::Base visual = factory.CreateVisual(propertyMap);
2413 DALI_TEST_CHECK(visual);
2415 Property::Map testMap;
2416 visual.CreatePropertyMap(testMap);
2417 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2419 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2420 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2422 TestGlAbstraction& gl = application.GetGlAbstraction();
2423 TraceCallStack& textureTrace = gl.GetTextureTrace();
2424 textureTrace.Enable(true);
2426 DummyControl actor = DummyControl::New();
2427 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2428 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2430 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2431 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2432 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2434 application.GetScene().Add(actor);
2436 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2438 application.SendNotification();
2439 application.Render();
2441 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2442 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2443 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2445 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2446 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2451 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2453 ToolkitTestApplication application;
2454 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2456 VisualFactory factory = VisualFactory::Get();
2457 DALI_TEST_CHECK(factory);
2459 Property::Map propertyMap;
2460 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2461 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2462 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2463 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2464 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2466 Visual::Base visual = factory.CreateVisual(propertyMap);
2467 DALI_TEST_CHECK(visual);
2469 Property::Map testMap;
2470 visual.CreatePropertyMap(testMap);
2471 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2473 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2474 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2476 TestGlAbstraction& gl = application.GetGlAbstraction();
2477 TraceCallStack& textureTrace = gl.GetTextureTrace();
2478 textureTrace.Enable(true);
2480 DummyControl actor = DummyControl::New();
2481 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2482 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2484 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2485 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2486 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2488 application.GetScene().Add(actor);
2490 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2492 application.SendNotification();
2493 application.Render();
2495 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2496 Renderer renderer = actor.GetRendererAt(0u);
2497 TextureSet textures = renderer.GetTextures();
2498 DALI_TEST_CHECK(textures);
2499 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2501 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2502 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2504 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2505 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2510 int UtcDaliImageVisualRemoteAlphaMask(void)
2512 ToolkitTestApplication application;
2513 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2515 VisualFactory factory = VisualFactory::Get();
2516 DALI_TEST_CHECK(factory);
2518 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2520 Property::Map propertyMap;
2521 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2522 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2523 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2525 Visual::Base visual = factory.CreateVisual(propertyMap);
2526 DALI_TEST_CHECK(visual);
2528 Property::Map testMap;
2529 visual.CreatePropertyMap(testMap);
2531 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2533 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2534 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2536 TestGlAbstraction& gl = application.GetGlAbstraction();
2537 TraceCallStack& textureTrace = gl.GetTextureTrace();
2538 textureTrace.Enable(true);
2540 DummyControl actor = DummyControl::New();
2541 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2542 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2544 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2546 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2547 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2549 application.GetScene().Add(actor);
2550 application.SendNotification();
2551 application.Render();
2553 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2555 application.SendNotification();
2556 application.Render();
2558 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2559 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2560 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2565 int UtcDaliImageVisualAlphaMaskCrop(void)
2567 ToolkitTestApplication application;
2568 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2570 VisualFactory factory = VisualFactory::Get();
2571 DALI_TEST_CHECK(factory);
2573 Property::Map propertyMap;
2574 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2575 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2576 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2577 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2578 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2580 Visual::Base visual = factory.CreateVisual(propertyMap);
2581 DALI_TEST_CHECK(visual);
2583 Property::Map testMap;
2584 visual.CreatePropertyMap(testMap);
2585 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2586 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2587 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2589 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2590 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2592 TestGlAbstraction& gl = application.GetGlAbstraction();
2593 TraceCallStack& textureTrace = gl.GetTextureTrace();
2594 textureTrace.Enable(true);
2596 DummyControl actor = DummyControl::New();
2597 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2598 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2600 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2601 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2602 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2604 application.GetScene().Add(actor);
2605 application.SendNotification();
2606 application.Render();
2608 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2610 application.SendNotification();
2611 application.Render();
2614 visual.GetNaturalSize(size);
2616 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2617 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2618 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2619 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2624 int UtcDaliImageVisualReleasePolicy01(void)
2626 ToolkitTestApplication application;
2627 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2629 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2630 DALI_TEST_CHECK(imageVisual);
2632 // Set up debug trace
2633 TestGlAbstraction& gl = application.GetGlAbstraction();
2634 TraceCallStack& textureTrace = gl.GetTextureTrace();
2635 textureTrace.Enable(true);
2637 tet_infoline("Register visual with control and ensure it has the only handle");
2638 DummyControl actor = DummyControl::New(true);
2639 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2640 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2641 imageVisual.Reset();
2643 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2645 application.SendNotification();
2646 application.Render(0);
2647 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2648 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2650 application.GetScene().Add(actor);
2652 // Wait for image to load
2653 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2655 application.SendNotification();
2656 application.Render(0);
2657 // Test renderer and texture created
2658 tet_infoline("Confirm texture created");
2659 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2660 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2662 tet_infoline("Disable visual causing the texture to be deleted");
2663 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2665 application.SendNotification();
2666 application.Render(0);
2667 // Test renderer and textures removed.
2668 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2669 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2674 int UtcDaliImageVisualReleasePolicy02(void)
2676 ToolkitTestApplication application;
2677 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2679 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2680 DALI_TEST_CHECK(imageVisual);
2682 // Setup debug trace
2683 TestGlAbstraction& gl = application.GetGlAbstraction();
2684 TraceCallStack& textureTrace = gl.GetTextureTrace();
2685 textureTrace.Enable(true);
2687 tet_infoline("Register visual with control and ensure it has the only handle");
2688 DummyControl actor = DummyControl::New(true);
2689 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2690 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2691 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2693 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2695 application.SendNotification();
2696 application.Render(0);
2697 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2698 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2700 application.GetScene().Add(actor);
2702 // Wait for image to load
2703 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2705 application.SendNotification();
2706 application.Render(0);
2707 // Test renderer and texture created
2708 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2709 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2711 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2712 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2713 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2714 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2715 application.SendNotification();
2716 application.Render();
2718 // Test texture removed after visual destroyed.
2719 tet_infoline("Ensure texture is deleted after visual destroyed");
2720 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2725 int UtcDaliImageVisualReleasePolicy03(void)
2727 ToolkitTestApplication application;
2728 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2730 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2731 DALI_TEST_CHECK(imageVisual);
2733 TestGlAbstraction& gl = application.GetGlAbstraction();
2734 TraceCallStack& textureTrace = gl.GetTextureTrace();
2735 textureTrace.Enable(true);
2737 tet_infoline("Register visual with control and ensure it has the only handle");
2738 DummyControl actor = DummyControl::New(true);
2739 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2740 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2741 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2743 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2745 application.SendNotification();
2746 application.Render(0);
2747 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2748 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2750 application.GetScene().Add(actor);
2752 // Wait for image to load
2753 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2755 application.SendNotification();
2756 application.Render(0);
2757 // Test renderer and texture created
2758 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2759 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2761 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2762 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2763 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2764 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2765 application.SendNotification();
2766 application.Render();
2768 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2769 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2774 int UtcDaliImageVisualReleasePolicy04(void)
2776 ToolkitTestApplication application;
2777 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2779 tet_infoline("Create first visual with Never release policy");
2780 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2782 tet_infoline("Create second visual with Destroyed release policy");
2783 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2785 // Set up trace debug
2786 TestGlAbstraction& gl = application.GetGlAbstraction();
2787 TraceCallStack& textureTrace = gl.GetTextureTrace();
2788 textureTrace.Enable(true);
2790 tet_infoline("Register visuals with control and ensure it has the only handles");
2791 DummyControl actor = DummyControl::New(true);
2792 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2793 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2794 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2795 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2796 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2798 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2800 // Test initially zero renderers
2801 application.SendNotification();
2802 application.Render(0);
2803 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2804 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2806 application.GetScene().Add(actor);
2808 // Wait for image to load
2809 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2811 application.SendNotification();
2812 application.Render(0);
2813 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2814 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2815 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2817 // Test renderer removed when visual destroyed
2818 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2819 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2820 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2821 application.SendNotification();
2822 application.Render();
2824 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2825 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2827 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2828 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2829 application.SendNotification();
2830 application.Render();
2832 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2833 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2834 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2839 int UtcDaliImageVisualReleasePolicy05(void)
2841 ToolkitTestApplication application;
2842 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2844 VisualFactory factory = VisualFactory::Get();
2846 Property::Map propertyMapNeverReleasePolicy;
2847 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2848 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2849 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2850 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2851 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2853 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2855 Property::Map resultMap;
2856 imageVisualNever.CreatePropertyMap(resultMap);
2857 DALI_TEST_CHECK(!resultMap.Empty());
2859 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2864 int UtcDaliImageVisualReleasePolicy06(void)
2866 ToolkitTestApplication application;
2867 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2869 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2870 DALI_TEST_CHECK(imageVisual);
2872 TestGlAbstraction& gl = application.GetGlAbstraction();
2873 TraceCallStack& textureTrace = gl.GetTextureTrace();
2874 textureTrace.Enable(true);
2876 tet_infoline("Register visual with control and ensure it has the only handle");
2877 DummyControl actor = DummyControl::New(true);
2878 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2879 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2880 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2882 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2884 application.SendNotification();
2885 application.Render(0);
2886 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2887 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2889 application.GetScene().Add(actor);
2891 // Wait for image to load
2892 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2894 application.SendNotification();
2895 application.Render(0);
2896 // Test renderer and texture created
2897 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2898 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2899 textureTrace.Reset();
2901 tet_infoline("Disable Visual and check texture not affected");
2902 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2903 application.SendNotification();
2904 application.Render(0);
2905 tet_infoline("Check renderer is destroyed when visual off stage");
2906 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2907 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2908 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2909 textureTrace.Reset();
2911 tet_infoline("Re-enable Visual and check texture not affected");
2912 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2913 application.SendNotification();
2914 application.Render(0);
2915 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2916 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2917 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2918 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2923 int UtcDaliImageVisualReleasePolicy07(void)
2925 ToolkitTestApplication application;
2926 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2928 tet_infoline("Create first visual with DESTROYED release policy");
2929 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2931 tet_infoline("Create second visual with DETACHED release policy");
2932 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2934 // Set up trace debug
2935 TestGlAbstraction& gl = application.GetGlAbstraction();
2936 TraceCallStack& textureTrace = gl.GetTextureTrace();
2937 textureTrace.Enable(true);
2939 tet_infoline("Register visuals with control and ensure it has the only handles");
2940 DummyControl actor = DummyControl::New(true);
2941 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2942 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2943 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2944 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2945 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2947 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2949 // Test initially zero renderers
2950 application.SendNotification();
2951 application.Render(0);
2952 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2953 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2955 application.GetScene().Add(actor);
2957 // Wait for image to load
2958 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2960 application.SendNotification();
2961 application.Render(0);
2962 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2963 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2964 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2966 // Test renderer removed when visual destroyed
2967 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2968 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2969 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2970 application.SendNotification();
2971 application.Render();
2973 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2974 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2976 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2977 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2978 application.SendNotification();
2979 application.Render();
2981 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2982 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2987 int UtcDaliImageVisualReleasePolicy08(void)
2989 ToolkitTestApplication application;
2990 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2992 tet_infoline("Create first visual with DESTROYED release policy");
2993 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2995 // Set up trace debug
2996 TestGlAbstraction& gl = application.GetGlAbstraction();
2997 TraceCallStack& textureTrace = gl.GetTextureTrace();
2998 textureTrace.Enable(true);
3000 tet_infoline("Register visuals with control and ensure it has the only handles");
3001 DummyControl actor = DummyControl::New(true);
3002 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3003 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
3004 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
3006 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3008 // Test initially zero renderers
3009 application.SendNotification();
3010 application.Render(0);
3011 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3012 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3013 textureTrace.Reset();
3015 application.GetScene().Add(actor);
3017 // Wait for image to load
3018 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3020 application.SendNotification();
3021 application.Render(0);
3022 tet_infoline("Ensure a texture is created");
3023 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3024 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3025 textureTrace.Reset();
3027 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
3029 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
3031 // 2.Remove actor from stage. In this case, renderer also is deleted.
3032 tet_infoline("Remove actor from stage");
3033 application.GetScene().Remove(actor);
3034 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3035 application.SendNotification();
3036 application.Render();
3038 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
3039 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
3040 textureTrace.Reset();
3042 // 3.Add actor in stage. In this case, renderer is created.
3043 tet_infoline("Add actor in stage");
3044 application.GetScene().Add(actor);
3045 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
3046 application.SendNotification();
3047 application.Render();
3048 tet_infoline("Ensure a texture is not created again");
3049 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3050 textureTrace.Reset();
3052 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
3053 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
3054 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
3055 DALI_TEST_CHECK(textureBefore == textureAfter);
3056 textureBefore.Reset();
3057 textureAfter.Reset();
3059 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3060 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3061 application.SendNotification();
3062 application.Render();
3063 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3068 int UtcDaliImageVisualReleasePolicy09(void)
3070 ToolkitTestApplication application;
3071 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
3073 Property::Map propertyMapNPatchReleasePolicy;
3074 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
3075 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
3076 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
3077 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
3078 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
3080 VisualFactory factory = VisualFactory::Get();
3081 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
3082 DALI_TEST_CHECK(imageVisual);
3084 // Setup debug trace
3085 TestGlAbstraction& gl = application.GetGlAbstraction();
3086 TraceCallStack& textureTrace = gl.GetTextureTrace();
3087 textureTrace.Enable(true);
3089 tet_infoline("Register visual with control and ensure it has the only handle");
3090 DummyControl actor = DummyControl::New(true);
3091 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3092 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3093 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3095 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3097 application.SendNotification();
3098 application.Render(0);
3099 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3100 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3102 application.GetScene().Add(actor);
3104 // Wait for image to load
3105 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3107 application.SendNotification();
3108 application.Render(0);
3109 // Test renderer and texture created
3110 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3111 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3113 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
3114 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
3115 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3116 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3117 application.SendNotification();
3118 application.Render();
3120 // Test texture removed after visual destroyed.
3121 tet_infoline("Ensure texture is deleted after visual destroyed");
3122 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
3127 int UtcDaliImageVisualLoadPolicy01(void)
3129 ToolkitTestApplication application;
3130 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
3132 // Set up trace debug
3133 TestGlAbstraction& gl = application.GetGlAbstraction();
3134 TraceCallStack& textureTrace = gl.GetTextureTrace();
3135 textureTrace.Enable(true);
3137 tet_infoline("Create visual with IMMEDIATE load policy");
3138 VisualFactory factory = VisualFactory::Get();
3140 Property::Map propertyMap;
3141 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3142 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3143 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
3144 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
3145 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
3147 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3149 Property::Map resultMap;
3150 imageVisual.CreatePropertyMap(resultMap);
3151 DALI_TEST_CHECK(!resultMap.Empty());
3152 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
3154 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3156 // Ensure texture has been uploaded
3157 application.SendNotification();
3158 application.Render();
3160 tet_infoline("Ensure texture loading starts after visual created");
3161 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3162 textureTrace.Reset();
3164 tet_infoline("Register visuals with control and ensure it has the only handles");
3165 DummyControl actor = DummyControl::New(true);
3166 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3167 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3168 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3170 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3171 application.GetScene().Add(actor);
3172 tet_infoline("Ensure nothing triggers another load as texure already loaded");
3173 const unsigned int TIME_OUT_3_SECONDS = 3;
3174 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3176 application.SendNotification();
3177 application.Render();
3179 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3180 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3182 // Ensure texture is deleted when no longer needed (ref count was correct )
3183 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3185 application.SendNotification();
3186 application.Render();
3188 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3189 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3194 int UtcDaliImageVisualLoadPolicy02(void)
3196 ToolkitTestApplication application;
3197 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3199 // Set up trace debug
3200 TestGlAbstraction& gl = application.GetGlAbstraction();
3201 TraceCallStack& textureTrace = gl.GetTextureTrace();
3202 textureTrace.Enable(true);
3204 tet_infoline("Create visual with IMMEDIATE load policy");
3205 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3207 const unsigned int TIME_OUT_3_SECONDS = 3;
3208 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3210 // Act on meeage queue even although nothing expected to load
3211 application.SendNotification();
3212 application.Render();
3214 tet_infoline("Ensure texture is not generated yet");
3215 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3216 textureTrace.Reset();
3218 tet_infoline("Register visuals with control and ensure it has the only handles");
3219 DummyControl actor = DummyControl::New(true);
3220 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3221 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3222 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3224 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3225 application.GetScene().Add(actor);
3226 tet_infoline("Allow image time to load");
3227 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3229 application.SendNotification();
3230 application.Render();
3232 tet_infoline("Ensure texture generated and renderer created");
3233 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3234 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3236 // Ensure texture is delete when no longer needed
3237 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3239 application.SendNotification();
3240 application.Render();
3242 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3243 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3248 int UtcDaliImageVisualLoadPolicy03(void)
3250 ToolkitTestApplication application;
3251 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3253 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3255 // Set up trace debug
3256 TestGlAbstraction& gl = application.GetGlAbstraction();
3257 TraceCallStack& textureTrace = gl.GetTextureTrace();
3258 textureTrace.Enable(true);
3260 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3261 DummyControl actor = DummyControl::New(true);
3262 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3263 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3264 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3266 tet_infoline("Create visual with IMMEDIATE load policy");
3267 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3269 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3270 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3271 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3273 tet_infoline("Allow image time to load resource");
3274 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3275 application.SendNotification();
3276 application.Render();
3278 // Ensure texture has been uploaded
3279 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3280 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3285 int UtcDaliImageVisualLoadPolicy04(void)
3287 ToolkitTestApplication application;
3288 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3289 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3291 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3293 // Set up trace debug
3294 TestGlAbstraction& gl = application.GetGlAbstraction();
3295 TraceCallStack& textureTrace = gl.GetTextureTrace();
3296 textureTrace.Enable(true);
3298 tet_infoline("Create a control and connect to resource ready signal");
3299 DummyControl actor = DummyControl::New(true);
3300 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3301 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3302 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3304 tet_infoline("Create visual with IMMEDIATE load policy");
3305 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3307 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3308 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3309 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3311 tet_infoline("Allow image time to load");
3312 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3313 application.SendNotification();
3314 application.Render();
3316 tet_infoline("Testing texture is loaded and resource ready signal fired");
3317 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3318 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3320 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3322 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3323 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3324 DummyControl actor2 = DummyControl::New(true);
3325 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3326 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3328 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3329 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3330 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3331 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3332 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3333 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3338 int UtcDaliImageVisualLoadPolicy05(void)
3340 ToolkitTestApplication application;
3341 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3342 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3343 // Set up trace debug
3344 TestGlAbstraction& gl = application.GetGlAbstraction();
3345 TraceCallStack& textureTrace = gl.GetTextureTrace();
3346 textureTrace.Enable(true);
3348 tet_infoline("Create a control and connect to resource ready signal");
3349 DummyControl actor = DummyControl::New(true);
3350 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3351 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3352 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3353 application.GetScene().Add(actor);
3355 tet_infoline("Create visual with ATTACHED load policy");
3356 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3358 tet_infoline("Registering visual allows control to get a signal once loaded");
3359 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3360 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3362 tet_infoline("Allow image time to load");
3363 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3364 application.SendNotification();
3365 application.Render();
3367 tet_infoline("Testing texture is loaded and resource ready signal fired");
3368 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3369 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3371 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3373 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3374 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3375 DummyControl actor2 = DummyControl::New(true);
3376 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3377 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3379 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3380 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3381 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3382 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3383 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3384 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3389 int UtcDaliImageVisualOrientationCorrection(void)
3391 ToolkitTestApplication application;
3392 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3394 VisualFactory factory = VisualFactory::Get();
3395 tet_infoline("Create visual with Orientation correction set OFF");
3396 Property::Map propertyMap;
3397 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3398 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3399 propertyMap.Insert("orientationCorrection", false);
3400 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3402 tet_infoline("Create control for visual, need to loaded it");
3403 DummyControl actor = DummyControl::New(true);
3404 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3405 application.GetScene().Add(actor);
3407 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3408 // Wait for image to load
3409 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3411 Vector2 originalImageSize;
3412 tet_infoline("Get size of original visual to compare later with rotated image");
3413 imageVisual.GetNaturalSize(originalImageSize);
3414 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3415 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3416 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3417 application.SendNotification();
3418 application.Render();
3420 tet_infoline("Create visual with Orientation correction set ON ");
3421 propertyMap.Clear();
3422 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3423 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3424 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3425 imageVisual = factory.CreateVisual(propertyMap);
3427 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3428 // Wait for image to load
3429 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3431 Vector2 rotatedImageSize;
3432 imageVisual.GetNaturalSize(rotatedImageSize);
3433 tet_infoline("Confirm that visual has rotated");
3434 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3435 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3437 Property::Map resultMap;
3438 imageVisual.CreatePropertyMap(resultMap);
3440 // check the Property::ORIENTATION_CORRECTION value from the returned map
3441 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3442 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3447 int UtcDaliImageVisualCustomShader(void)
3449 ToolkitTestApplication application;
3450 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3452 VisualFactory factory = VisualFactory::Get();
3453 Property::Map properties;
3454 Property::Map shader;
3455 const std::string vertexShader = "Foobar";
3456 const std::string fragmentShader = "Foobar";
3457 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3458 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3460 properties[Visual::Property::TYPE] = Visual::IMAGE;
3461 properties[Visual::Property::SHADER] = shader;
3462 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3464 Visual::Base visual = factory.CreateVisual(properties);
3466 // trigger creation through setting on stage
3467 DummyControl dummy = DummyControl::New(true);
3468 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3469 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3471 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3472 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3473 application.GetScene().Add(dummy);
3475 application.SendNotification();
3476 application.Render();
3478 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3480 Renderer renderer = dummy.GetRendererAt(0);
3481 Shader shader2 = renderer.GetShader();
3482 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3483 Property::Map* map = value.GetMap();
3484 DALI_TEST_CHECK(map);
3486 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3487 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3489 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3490 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3494 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3495 properties[Visual::Property::SHADER] = shader;
3497 Visual::Base visual1 = factory.CreateVisual(properties);
3499 // trigger creation through setting on stage
3500 DummyControl dummy1 = DummyControl::New(true);
3501 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3502 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3503 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3504 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3505 application.GetScene().Add(dummy1);
3507 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3508 glAbstraction.EnableEnableDisableCallTrace(true);
3510 application.SendNotification();
3511 application.Render();
3513 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3514 std::ostringstream blendStr;
3515 blendStr << std::hex << GL_BLEND;
3516 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3521 void ResourceReadyLoadNext(Control control)
3523 static int callNumber = 0;
3525 gResourceReadySignalFired = true;
3526 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3530 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3532 tet_infoline("Create visual with loaded image from within the signal handler");
3533 VisualFactory factory = VisualFactory::Get();
3534 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3536 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3537 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3542 tet_infoline("3rd signal called");
3543 DALI_TEST_CHECK(true);
3547 int UtcDaliImageVisualLoadReady01(void)
3549 ToolkitTestApplication application;
3550 tet_infoline("UtcDaliImageVisualLoadReady01");
3551 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3552 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3553 tet_infoline("Should get a ready signal for all three visuals");
3557 tet_infoline("Create a control and connect to resource ready signal");
3558 DummyControl actor = DummyControl::New(true);
3559 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3560 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3561 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3562 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3563 application.GetScene().Add(actor);
3565 tet_infoline("Create visual with IMMEDIATE load policy");
3566 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3568 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3569 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3571 tet_infoline("Allow image time to load");
3572 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3573 application.SendNotification();
3574 application.Render();
3576 tet_infoline("Testing texture is loaded and resource ready signal fired");
3577 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3578 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3580 tet_infoline("Original control correctly signalled, now testing failing image");
3582 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3585 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3587 DummyControl actor2 = DummyControl::New(true);
3588 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3589 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3590 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3592 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3593 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3595 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3596 application.GetScene().Add(actor2);
3598 tet_infoline("Wait for loading thread to finish");
3599 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3600 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3602 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3604 tet_infoline("Check for 3rd signal");
3605 application.SendNotification();
3606 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3607 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3612 int UtcDaliImageVisualLoadImagePlanes01(void)
3614 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3615 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3617 ToolkitTestApplication application;
3619 VisualFactory factory = VisualFactory::Get();
3620 DALI_TEST_CHECK(factory);
3622 Property::Map propertyMap;
3623 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3624 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3626 Visual::Base visual = factory.CreateVisual(propertyMap);
3627 DALI_TEST_CHECK(visual);
3629 DummyControl actor = DummyControl::New();
3630 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3631 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3632 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3633 application.GetScene().Add(actor);
3635 application.SendNotification();
3636 application.Render();
3638 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3640 TestGlAbstraction& gl = application.GetGlAbstraction();
3641 TraceCallStack& textureTrace = gl.GetTextureTrace();
3642 textureTrace.Enable(true);
3644 application.SendNotification();
3645 application.Render();
3647 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3648 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3649 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3651 Renderer renderer = actor.GetRendererAt(0);
3652 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3653 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3658 int UtcDaliImageVisualLoadImagePlanes02(void)
3660 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3661 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3663 ToolkitTestApplication application;
3665 VisualFactory factory = VisualFactory::Get();
3666 DALI_TEST_CHECK(factory);
3668 // Alpha masking case - not support yuv planes
3669 Property::Map propertyMap;
3670 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3671 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3672 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3674 Visual::Base visual = factory.CreateVisual(propertyMap);
3675 DALI_TEST_CHECK(visual);
3677 DummyControl actor = DummyControl::New();
3678 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3679 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3680 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3681 application.GetScene().Add(actor);
3683 application.SendNotification();
3684 application.Render();
3686 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3688 TestGlAbstraction& gl = application.GetGlAbstraction();
3689 TraceCallStack& textureTrace = gl.GetTextureTrace();
3690 textureTrace.Enable(true);
3692 application.SendNotification();
3693 application.Render();
3695 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3696 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3697 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3702 int UtcDaliImageVisualLoadImagePlanes03(void)
3704 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3705 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3707 ToolkitTestApplication application;
3709 VisualFactory factory = VisualFactory::Get();
3710 DALI_TEST_CHECK(factory);
3712 TestGlAbstraction& gl = application.GetGlAbstraction();
3713 TraceCallStack& textureTrace = gl.GetTextureTrace();
3714 textureTrace.Enable(true);
3716 Property::Map propertyMap;
3717 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3718 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3719 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3721 Visual::Base visual = factory.CreateVisual(propertyMap);
3722 DALI_TEST_CHECK(visual);
3724 DummyControl actor = DummyControl::New();
3725 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3726 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3727 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3728 application.GetScene().Add(actor);
3730 application.SendNotification();
3731 application.Render();
3733 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3734 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3735 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3740 int UtcDaliImageVisualLoadFastTrackImage01(void)
3742 tet_infoline("Test worker thread uploading with Local URL");
3743 ToolkitTestApplication application;
3745 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3747 VisualFactory factory = VisualFactory::Get();
3748 DALI_TEST_CHECK(factory);
3750 // Pair of filename - expect GenTextures count.
3751 std::vector<std::pair<std::string, int>> testCases = {
3752 {TEST_IMAGE_FILE_NAME, 1},
3753 {TEST_REMOTE_IMAGE_FILE_NAME, 1},
3754 {TEST_INVALID_FILE_NAME, 0},
3757 for(auto&& tc : testCases)
3759 auto& filename = tc.first;
3760 auto& expectValue = tc.second;
3762 tet_printf("Test %s\n", filename.c_str());
3764 Property::Map propertyMap;
3765 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3766 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3767 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3769 Visual::Base visual = factory.CreateVisual(propertyMap);
3770 DALI_TEST_CHECK(visual);
3772 DummyControl actor = DummyControl::New();
3773 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3774 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3775 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3777 TestGlAbstraction& gl = application.GetGlAbstraction();
3778 TraceCallStack& textureTrace = gl.GetTextureTrace();
3779 textureTrace.Enable(true);
3781 application.GetScene().Add(actor);
3783 application.SendNotification();
3784 application.Render();
3786 // EventThread without callback
3787 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3789 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3792 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3793 // How can we make it? Should it be integration-api?
3794 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3795 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3797 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3798 application.Render();
3800 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3802 application.SendNotification();
3803 application.Render();
3805 textureTrace.Reset();
3811 int UtcDaliImageVisualLoadFastTrackImage02(void)
3813 tet_infoline("Test worker thread uploading with Local URL");
3814 ToolkitTestApplication application;
3816 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3818 VisualFactory factory = VisualFactory::Get();
3819 DALI_TEST_CHECK(factory);
3822 auto filename = std::string(TEST_IMAGE_FILE_NAME);
3823 auto expectValue = 1;
3825 tet_printf("Test %s\n", filename.c_str());
3827 Property::Map propertyMap;
3828 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3829 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3830 propertyMap.Insert("fastTrackUploading", true);
3832 Visual::Base visual = factory.CreateVisual(propertyMap);
3833 DALI_TEST_CHECK(visual);
3835 DummyControl actor = DummyControl::New();
3836 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3837 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3838 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3840 TestGlAbstraction& gl = application.GetGlAbstraction();
3841 TraceCallStack& textureTrace = gl.GetTextureTrace();
3842 textureTrace.Enable(true);
3844 application.GetScene().Add(actor);
3846 application.SendNotification();
3847 application.Render();
3849 // EventThread without callback
3850 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3852 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3855 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3856 // How can we make it? Should it be integration-api?
3857 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3858 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3860 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3861 application.Render();
3863 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3865 application.SendNotification();
3866 application.Render();
3868 textureTrace.Reset();
3874 int UtcDaliImageVisualLoadFastTrackImageResourceReady(void)
3876 tet_infoline("Test worker thread uploading with Local URL");
3877 ToolkitTestApplication application;
3879 VisualFactory factory = VisualFactory::Get();
3880 DALI_TEST_CHECK(factory);
3882 Property::Map propertyMap;
3883 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3884 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3885 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3887 Visual::Base visual = factory.CreateVisual(propertyMap);
3888 DALI_TEST_CHECK(visual);
3890 DummyControl actor = DummyControl::New();
3891 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3892 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3893 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3895 TestGlAbstraction& gl = application.GetGlAbstraction();
3896 TraceCallStack& textureTrace = gl.GetTextureTrace();
3897 textureTrace.Enable(true);
3899 application.GetScene().Add(actor);
3901 application.SendNotification();
3902 application.Render();
3904 // EventThread with callback
3905 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3907 // Check resource ready comes after
3908 application.SendNotification();
3909 application.Render();
3911 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3912 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3917 int UtcDaliImageVisualLoadFastTrackImageReload(void)
3919 tet_infoline("Test worker thread uploading with Local URL");
3920 ToolkitTestApplication application;
3922 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3924 VisualFactory factory = VisualFactory::Get();
3925 DALI_TEST_CHECK(factory);
3927 Property::Map propertyMap;
3928 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3929 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3930 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3932 Visual::Base visual = factory.CreateVisual(propertyMap);
3933 DALI_TEST_CHECK(visual);
3935 DummyControl actor = DummyControl::New();
3936 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3937 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3938 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3940 TestGlAbstraction& gl = application.GetGlAbstraction();
3941 TraceCallStack& textureTrace = gl.GetTextureTrace();
3942 textureTrace.Enable(true);
3944 application.GetScene().Add(actor);
3946 application.SendNotification();
3947 application.Render();
3949 // EventThread without callback
3950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3952 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3955 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3956 // How can we make it? Should it be integration-api?
3957 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3958 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), true, TEST_LOCATION);
3960 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3961 application.Render();
3963 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3966 Property::Map attributes;
3967 DevelControl::DoAction(actor, Control::CONTROL_PROPERTY_END_INDEX + 1, DevelImageVisual::Action::RELOAD, attributes);
3969 // EventThread with callback
3970 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3972 // Check resource ready comes after
3973 application.SendNotification();
3974 application.Render();
3976 // Check whether renderer count is 1 or not.
3977 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3978 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3983 int UtcDaliImageVisualLoadFastTrackImagePlanes01(void)
3985 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3986 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3988 ToolkitTestApplication application;
3990 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3992 VisualFactory factory = VisualFactory::Get();
3993 DALI_TEST_CHECK(factory);
3995 Property::Map propertyMap;
3996 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3997 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3998 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
4000 Visual::Base visual = factory.CreateVisual(propertyMap);
4001 DALI_TEST_CHECK(visual);
4003 DummyControl actor = DummyControl::New();
4004 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4005 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4006 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4008 TestGlAbstraction& gl = application.GetGlAbstraction();
4009 TraceCallStack& textureTrace = gl.GetTextureTrace();
4010 textureTrace.Enable(true);
4012 application.GetScene().Add(actor);
4014 application.SendNotification();
4015 application.Render();
4017 // EventThread without callback
4018 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
4020 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4023 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
4024 // How can we make it? Should it be integration-api?
4025 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
4026 textureUploadManager.ResourceUpload();
4027 application.Render();
4029 // Render only without SendNotification(). And check whether glTexImage2D called or not.
4030 application.Render();
4032 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
4034 application.SendNotification();
4035 application.Render();
4040 int UtcDaliImageVisualLoadFastTrackImagePlanes02(void)
4042 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
4043 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
4045 ToolkitTestApplication application;
4047 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
4049 VisualFactory factory = VisualFactory::Get();
4050 DALI_TEST_CHECK(factory);
4052 Property::Map propertyMap;
4053 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4054 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4055 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
4057 Visual::Base visual = factory.CreateVisual(propertyMap);
4058 DALI_TEST_CHECK(visual);
4060 DummyControl actor = DummyControl::New();
4061 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4062 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4063 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4065 TestGlAbstraction& gl = application.GetGlAbstraction();
4066 TraceCallStack& textureTrace = gl.GetTextureTrace();
4067 textureTrace.Enable(true);
4069 application.GetScene().Add(actor);
4071 application.SendNotification();
4072 application.Render();
4074 // EventThread without callback
4075 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
4077 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4080 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
4081 // How can we make it? Should it be integration-api?
4082 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
4083 textureUploadManager.ResourceUpload();
4084 application.Render();
4086 // Render only without SendNotification(). And check whether glTexImage2D called or not.
4087 application.Render();
4089 DALI_TEST_GREATER(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4091 application.SendNotification();
4092 application.Render();
4097 int UtcDaliImageVisualDebugImageVisualShaderP1(void)
4099 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4100 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "validFile"); // Try to load not exist file.
4102 // Set valid script file
4103 Test::StyleMonitor::SetThemeFileOutput("validFile", VALID_DEBUG_SHADER_SCRIPT);
4105 ToolkitTestApplication application;
4107 VisualFactory factory = VisualFactory::Get();
4108 DALI_TEST_CHECK(factory);
4110 Property::Map propertyMap;
4111 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4112 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4114 Visual::Base visual = factory.CreateVisual(propertyMap);
4115 DALI_TEST_CHECK(visual);
4117 DummyControl actor = DummyControl::New();
4118 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4119 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4120 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4121 application.GetScene().Add(actor);
4123 application.SendNotification();
4124 application.Render();
4126 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4128 TestGlAbstraction& gl = application.GetGlAbstraction();
4129 TraceCallStack& textureTrace = gl.GetTextureTrace();
4130 textureTrace.Enable(true);
4132 application.SendNotification();
4133 application.Render();
4135 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4136 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4137 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4142 int UtcDaliImageVisualDebugImageVisualShaderN1(void)
4144 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4145 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "notJsonFile"); // Try to load exist file, but not a json
4147 // Set invalid script file
4148 Test::StyleMonitor::SetThemeFileOutput("notJsonFile", "1");
4150 ToolkitTestApplication application;
4152 VisualFactory factory = VisualFactory::Get();
4153 DALI_TEST_CHECK(factory);
4155 Property::Map propertyMap;
4156 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4157 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4159 Visual::Base visual = factory.CreateVisual(propertyMap);
4160 DALI_TEST_CHECK(visual);
4162 DummyControl actor = DummyControl::New();
4163 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4164 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4165 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4166 application.GetScene().Add(actor);
4168 application.SendNotification();
4169 application.Render();
4171 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4173 TestGlAbstraction& gl = application.GetGlAbstraction();
4174 TraceCallStack& textureTrace = gl.GetTextureTrace();
4175 textureTrace.Enable(true);
4177 application.SendNotification();
4178 application.Render();
4180 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4181 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4182 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4187 int UtcDaliImageVisualDebugImageVisualShaderN2(void)
4189 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4190 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
4192 // Set throw exception script file
4193 Test::StyleMonitor::SetThemeFileOutput(std::string(THROW_EXCEPTION_STYLE_FILE_NAME), "1");
4195 ToolkitTestApplication application;
4197 VisualFactory factory = VisualFactory::Get();
4198 DALI_TEST_CHECK(factory);
4200 Property::Map propertyMap;
4201 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4202 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4204 Visual::Base visual = factory.CreateVisual(propertyMap);
4205 DALI_TEST_CHECK(visual);
4207 DummyControl actor = DummyControl::New();
4208 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4209 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4210 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4211 application.GetScene().Add(actor);
4213 application.SendNotification();
4214 application.Render();
4216 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4218 TestGlAbstraction& gl = application.GetGlAbstraction();
4219 TraceCallStack& textureTrace = gl.GetTextureTrace();
4220 textureTrace.Enable(true);
4222 application.SendNotification();
4223 application.Render();
4225 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4226 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4227 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);