2 * Copyright (c) 2023 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-texture-upload-manager.h>
29 #include <toolkit-timer.h>
31 #include <dali-toolkit/dali-toolkit.h>
32 #include <dali-toolkit/devel-api/controls/control-devel.h>
33 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
34 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
35 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
36 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
37 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
38 #include <dali-toolkit/public-api/image-loader/image-url.h>
39 #include <dali-toolkit/public-api/image-loader/image.h>
41 #include <dali/devel-api/adaptor-framework/texture-upload-manager.h>
43 #include "dummy-control.h"
44 #include "test-encoded-image-buffer.h"
45 #include "test-native-image-source.h"
48 using namespace Dali::Toolkit;
50 void dali_image_visual_startup(void)
52 test_return_value = TET_UNDEF;
55 void dali_image_visual_cleanup(void)
57 test_return_value = TET_PASS;
62 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
63 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
64 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
65 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
66 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
67 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
68 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
69 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
70 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
71 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
72 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
74 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
75 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
77 bool gResourceReadySignalFired = false;
78 std::vector<int> gReadyIds = {};
79 void ResourceReadySignal(Control control)
81 gResourceReadySignalFired = true;
82 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
89 Actor CreateActorWithImageVisual(const Property::Map& map)
91 VisualFactory factory = VisualFactory::Get();
92 DummyControl actor = DummyControl::New();
93 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
94 Visual::Base visual = factory.CreateVisual(map);
95 DALI_TEST_CHECK(visual);
96 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
97 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
98 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
102 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
104 VisualFactory factory = VisualFactory::Get();
106 Property::Map propertyMap;
107 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
108 propertyMap.Insert(ImageVisual::Property::URL, url);
109 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
110 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
111 propertyMap.Insert(key, value);
113 return factory.CreateVisual(propertyMap);
118 void TestVisualRender(ToolkitTestApplication& application,
120 Visual::Base& visual,
121 std::size_t expectedSamplers = 0,
122 ImageDimensions imageDimensions = ImageDimensions(),
123 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
125 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
126 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
130 // set the image size, for test case, this needs to be set before loading started
131 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
134 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
135 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
137 application.GetScene().Add(actor);
139 application.SendNotification(); // Send messages to update
140 application.Render(); // process update and render
141 application.SendNotification(); // process any signals to event
145 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
148 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
151 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
154 visual.CreatePropertyMap(map);
155 Property::Value* value = map.Find(mixColorIndex);
156 DALI_TEST_CHECK(value);
158 DALI_TEST_CHECK(value->Get(mixColor1));
159 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
161 value = map.Find(Visual::Property::MIX_COLOR);
162 DALI_TEST_CHECK(value);
164 DALI_TEST_CHECK(value->Get(mixColor2));
165 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
167 value = map.Find(Visual::Property::OPACITY);
168 DALI_TEST_CHECK(value);
170 DALI_TEST_CHECK(value->Get(opacity));
171 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
174 int UtcDaliImageVisualPropertyMap(void)
176 ToolkitTestApplication application;
177 tet_infoline("Request image visual with a Property::Map");
179 VisualFactory factory = VisualFactory::Get();
180 DALI_TEST_CHECK(factory);
181 factory.SetPreMultiplyOnLoad(true);
183 Property::Map propertyMap;
184 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
185 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
187 Visual::Base visual = factory.CreateVisual(propertyMap);
188 DALI_TEST_CHECK(visual);
190 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
191 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
193 TestGlAbstraction& gl = application.GetGlAbstraction();
194 TraceCallStack& textureTrace = gl.GetTextureTrace();
195 textureTrace.Enable(true);
197 DummyControl actor = DummyControl::New();
198 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
199 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
201 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
202 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
204 application.GetScene().Add(actor);
205 application.SendNotification();
206 application.Render();
208 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
210 application.SendNotification();
211 application.Render();
213 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
214 auto renderer = actor.GetRendererAt(0);
215 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
216 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
217 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
218 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
219 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
220 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
221 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
223 application.GetScene().Remove(actor);
224 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
229 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
231 ToolkitTestApplication application;
232 tet_infoline("Request image visual without pre-multiplied alpha");
234 VisualFactory factory = VisualFactory::Get();
235 DALI_TEST_CHECK(factory);
236 factory.SetPreMultiplyOnLoad(false);
238 Property::Map propertyMap;
239 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
240 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
242 Visual::Base visual = factory.CreateVisual(propertyMap);
243 DALI_TEST_CHECK(visual);
245 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
246 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
248 TestGlAbstraction& gl = application.GetGlAbstraction();
249 TraceCallStack& textureTrace = gl.GetTextureTrace();
250 textureTrace.Enable(true);
252 DummyControl actor = DummyControl::New();
253 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
254 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
256 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
257 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
259 application.GetScene().Add(actor);
260 application.SendNotification();
261 application.Render();
263 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
265 application.SendNotification();
266 application.Render();
268 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
269 auto renderer = actor.GetRendererAt(0);
270 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
271 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
272 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
273 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
275 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
276 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
278 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
280 application.GetScene().Remove(actor);
281 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
286 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
288 ToolkitTestApplication application;
289 tet_infoline("Request image visual with no alpha channel");
291 VisualFactory factory = VisualFactory::Get();
292 DALI_TEST_CHECK(factory);
294 Property::Map propertyMap;
295 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
296 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
298 Visual::Base visual = factory.CreateVisual(propertyMap);
299 DALI_TEST_CHECK(visual);
301 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
302 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
304 TestGlAbstraction& gl = application.GetGlAbstraction();
305 TraceCallStack& textureTrace = gl.GetTextureTrace();
306 textureTrace.Enable(true);
308 DummyControl actor = DummyControl::New();
309 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
310 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
312 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
313 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
315 application.GetScene().Add(actor);
316 application.SendNotification();
317 application.Render();
319 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
321 application.SendNotification();
322 application.Render();
324 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
325 auto renderer = actor.GetRendererAt(0);
326 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
327 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
328 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
329 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
331 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
332 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
334 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
336 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
337 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
338 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
339 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
340 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
341 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
342 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
343 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
345 textureTrace.Reset();
347 // Make a new visual with the same image
348 Visual::Base newVisual = factory.CreateVisual(propertyMap);
349 DALI_TEST_CHECK(newVisual);
351 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
352 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
354 DummyControl newActor = DummyControl::New();
355 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
356 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
358 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
359 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
361 application.GetScene().Add(newActor);
363 application.SendNotification();
364 application.Render();
366 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
367 auto newRenderer = newActor.GetRendererAt(0);
368 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
369 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
370 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
371 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
373 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
374 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
376 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
377 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
378 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
379 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
380 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
381 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
382 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
383 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
385 application.GetScene().Remove(actor);
386 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
391 int UtcDaliImageVisualRemoteImageLoad(void)
393 ToolkitTestApplication application;
394 tet_infoline("Request remote image visual with a Property::Map");
396 VisualFactory factory = VisualFactory::Get();
397 DALI_TEST_CHECK(factory);
399 Property::Map propertyMap;
400 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
401 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
403 Visual::Base visual = factory.CreateVisual(propertyMap);
404 DALI_TEST_CHECK(visual);
406 TestGlAbstraction& gl = application.GetGlAbstraction();
407 TraceCallStack& textureTrace = gl.GetTextureTrace();
408 textureTrace.Enable(true);
410 DummyControl actor = DummyControl::New();
411 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
412 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
414 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
415 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
417 application.GetScene().Add(actor);
418 application.SendNotification();
420 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
422 application.SendNotification();
423 application.Render();
425 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
426 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
428 application.GetScene().Remove(actor);
429 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
434 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
436 ToolkitTestApplication application;
437 tet_infoline("Use FrameBuffer as url");
441 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
443 DALI_TEST_CHECK(frameBuffer);
444 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
445 std::string url = imageUrl.GetUrl();
447 VisualFactory factory = VisualFactory::Get();
448 DALI_TEST_CHECK(factory);
450 Property::Map propertyMap;
451 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
452 propertyMap.Insert(ImageVisual::Property::URL, url);
454 Visual::Base visual = factory.CreateVisual(propertyMap);
455 DALI_TEST_CHECK(visual);
457 DummyControl actor = DummyControl::New();
458 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
459 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
461 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
463 application.GetScene().Add(actor);
465 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
467 application.SendNotification();
468 application.Render(16);
470 Renderer renderer = actor.GetRendererAt(0);
472 // Check whether preMultipliedAlpha is true.
473 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
474 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
479 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
481 ToolkitTestApplication application;
482 tet_infoline("Use FrameBuffer as url");
486 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
488 DALI_TEST_CHECK(frameBuffer);
490 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
491 frameBuffer.AttachColorTexture(texture);
493 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
494 std::string url = imageUrl.GetUrl();
496 VisualFactory factory = VisualFactory::Get();
497 DALI_TEST_CHECK(factory);
499 Property::Map propertyMap;
500 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
501 propertyMap.Insert(ImageVisual::Property::URL, url);
503 Visual::Base visual = factory.CreateVisual(propertyMap);
504 DALI_TEST_CHECK(visual);
506 DummyControl actor = DummyControl::New();
507 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
508 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
510 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
512 application.GetScene().Add(actor);
514 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
516 application.SendNotification();
517 application.Render(16);
519 Renderer renderer = actor.GetRendererAt(0);
521 // Check whether preMultipliedAlpha is true.
522 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
523 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
528 int UtcDaliImageVisualWithPixelData(void)
530 ToolkitTestApplication application;
531 tet_infoline("Use PixelData as url");
535 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
537 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
538 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
540 DALI_TEST_CHECK(pixelData);
542 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
543 std::string url = imageUrl.GetUrl();
545 VisualFactory factory = VisualFactory::Get();
546 DALI_TEST_CHECK(factory);
548 Property::Map propertyMap;
549 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
550 propertyMap.Insert(ImageVisual::Property::URL, url);
552 Visual::Base visual = factory.CreateVisual(propertyMap);
553 DALI_TEST_CHECK(visual);
555 DummyControl actor = DummyControl::New();
556 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
557 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
559 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
561 application.GetScene().Add(actor);
563 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
565 application.SendNotification();
566 application.Render(16);
568 Renderer renderer = actor.GetRendererAt(0);
570 // Check whether preMultipliedAlpha is false.
571 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
572 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
577 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
579 ToolkitTestApplication application;
580 tet_infoline("Use PixelData as url");
584 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
586 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
587 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
589 DALI_TEST_CHECK(pixelData);
591 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
592 std::string url = imageUrl.GetUrl();
594 VisualFactory factory = VisualFactory::Get();
595 DALI_TEST_CHECK(factory);
597 Property::Map propertyMap;
598 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
599 propertyMap.Insert(ImageVisual::Property::URL, url);
601 Visual::Base visual = factory.CreateVisual(propertyMap);
602 DALI_TEST_CHECK(visual);
604 DummyControl actor = DummyControl::New();
605 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
606 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
608 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
610 application.GetScene().Add(actor);
612 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
614 application.SendNotification();
615 application.Render(16);
617 Renderer renderer = actor.GetRendererAt(0);
619 // Check whether preMultipliedAlpha is true.
620 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
621 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
626 int UtcDaliImageVisualWithPixelDataMasking(void)
628 ToolkitTestApplication application;
629 tet_infoline("Load external texture with mask");
631 TestGlAbstraction& gl = application.GetGlAbstraction();
632 TraceCallStack& textureTrace = gl.GetTextureTrace();
633 textureTrace.Enable(true);
637 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
639 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
640 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
642 DALI_TEST_CHECK(pixelData);
644 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
645 std::string url = imageUrl.GetUrl();
647 VisualFactory factory = VisualFactory::Get();
648 DALI_TEST_CHECK(factory);
650 Property::Map propertyMap;
651 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
652 propertyMap.Insert(ImageVisual::Property::URL, url);
653 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
655 Visual::Base visual = factory.CreateVisual(propertyMap);
656 DALI_TEST_CHECK(visual);
658 Property::Map testMap;
659 visual.CreatePropertyMap(testMap);
660 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
662 DummyControl actor = DummyControl::New();
663 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
664 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
666 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
668 application.GetScene().Add(actor);
669 application.SendNotification();
670 application.Render(16);
671 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
673 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
674 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
675 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
677 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
678 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
683 int UtcDaliImageVisualWithPixelDataMaskingSynchronously(void)
685 ToolkitTestApplication application;
686 tet_infoline("Load synchronously external texture with mask");
690 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
692 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
693 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
695 DALI_TEST_CHECK(pixelData);
697 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
698 std::string url = imageUrl.GetUrl();
700 VisualFactory factory = VisualFactory::Get();
701 DALI_TEST_CHECK(factory);
703 Property::Map propertyMap;
704 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
705 propertyMap.Insert(ImageVisual::Property::URL, url);
706 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
707 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
709 Visual::Base visual = factory.CreateVisual(propertyMap);
710 DALI_TEST_CHECK(visual);
712 Property::Map testMap;
713 visual.CreatePropertyMap(testMap);
714 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
716 DummyControl actor = DummyControl::New();
717 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
718 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
720 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
722 application.GetScene().Add(actor);
724 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
726 application.SendNotification();
727 application.Render(16);
732 int UtcDaliImageVisualWithNativeImage(void)
734 ToolkitTestApplication application;
735 tet_infoline("Use Native Image as url");
737 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
738 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
739 std::string url = imageUrl.GetUrl();
741 VisualFactory factory = VisualFactory::Get();
742 DALI_TEST_CHECK(factory);
744 Property::Map propertyMap;
745 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
746 propertyMap.Insert(ImageVisual::Property::URL, url);
748 Visual::Base visual = factory.CreateVisual(propertyMap);
749 DALI_TEST_CHECK(visual);
751 DummyControl actor = DummyControl::New();
752 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
753 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
755 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
757 application.GetScene().Add(actor);
759 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
761 application.SendNotification();
762 application.Render(16);
764 Renderer renderer = actor.GetRendererAt(0);
765 Shader shader = renderer.GetShader();
767 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
768 DALI_TEST_CHECK(value.GetType() == Property::MAP);
769 const Property::Map* outMap = value.GetMap();
770 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
772 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
773 size_t pos = fragmentShader.find(fragmentPrefix);
775 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
777 // Check whether preMultipliedAlpha is false.
778 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
779 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
784 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
786 ToolkitTestApplication application;
787 tet_infoline("Use Native Image as url");
789 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
790 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
791 std::string url = imageUrl.GetUrl();
793 VisualFactory factory = VisualFactory::Get();
794 DALI_TEST_CHECK(factory);
796 Property::Map propertyMap;
797 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
798 propertyMap.Insert(ImageVisual::Property::URL, url);
800 Visual::Base visual = factory.CreateVisual(propertyMap);
801 DALI_TEST_CHECK(visual);
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);
816 Renderer renderer = actor.GetRendererAt(0);
817 Shader shader = renderer.GetShader();
819 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
820 DALI_TEST_CHECK(value.GetType() == Property::MAP);
821 const Property::Map* outMap = value.GetMap();
822 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
824 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
825 size_t pos = fragmentShader.find(fragmentPrefix);
827 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
829 // Check whether preMultipliedAlpha is true.
830 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
831 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
836 int UtcDaliImageVisualWithNativeImageCustomShader(void)
838 ToolkitTestApplication application;
839 tet_infoline("Use Native Image as url and Use custom shader");
841 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
842 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
843 std::string url = imageUrl.GetUrl();
845 VisualFactory factory = VisualFactory::Get();
846 DALI_TEST_CHECK(factory);
848 Property::Map propertyMap;
849 Property::Map shaderMap;
850 const std::string customVertexShaderSource = "Foobar";
851 const std::string customFragmentShaderSource = "Foobar";
852 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
853 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
855 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
856 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
857 propertyMap.Insert(ImageVisual::Property::URL, url);
859 Visual::Base visual = factory.CreateVisual(propertyMap);
860 DALI_TEST_CHECK(visual);
862 DummyControl actor = DummyControl::New();
863 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
864 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
866 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
867 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
869 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
871 application.GetScene().Add(actor);
873 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
875 application.SendNotification();
876 application.Render(16);
878 Renderer renderer = actor.GetRendererAt(0);
879 Shader shader = renderer.GetShader();
881 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
882 DALI_TEST_CHECK(value.GetType() == Property::MAP);
883 const Property::Map* outMap = value.GetMap();
884 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
885 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
887 // Compare vertex shader is equal
888 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
890 // Check fragment shader changed
891 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
892 size_t pos = fragmentShaderSource.find(fragmentPrefix);
894 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
896 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
898 // Check whether preMultipliedAlpha is false.
899 // Note : We dont use preMultiplied alpha when app developer using custom shader.
900 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
901 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
906 int UtcDaliImageVisualWithNativeImageRemoved(void)
908 ToolkitTestApplication application;
909 tet_infoline("Use Native Image as url");
911 TestGlAbstraction& gl = application.GetGlAbstraction();
912 TraceCallStack& textureTrace = gl.GetTextureTrace();
913 textureTrace.Enable(true);
915 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
916 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
917 std::string url = imageUrl.GetUrl();
919 VisualFactory factory = VisualFactory::Get();
920 DALI_TEST_CHECK(factory);
922 Property::Map propertyMap;
923 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
924 propertyMap.Insert(ImageVisual::Property::URL, url);
926 Visual::Base visual = factory.CreateVisual(propertyMap);
927 DALI_TEST_CHECK(visual);
929 DummyControl actor = DummyControl::New();
930 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
931 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
933 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
935 application.GetScene().Add(actor);
936 application.SendNotification();
937 application.Render();
939 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
940 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
942 tet_infoline("No delete texture because reference count is not zero");
944 application.GetScene().Remove(actor);
945 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
946 application.SendNotification();
947 application.Render();
949 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
950 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
952 tet_infoline("Delete texture because reference count is zero");
954 application.SendNotification();
955 application.Render();
957 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
962 int UtcDaliImageVisualWithEncodedImageBuffer(void)
964 ToolkitTestApplication application;
965 tet_infoline("Use Encoded Image Buffer as url");
967 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
968 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
970 VisualFactory factory = VisualFactory::Get();
971 DALI_TEST_CHECK(factory);
973 Property::Map propertyMap;
974 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
975 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
977 Visual::Base visual = factory.CreateVisual(propertyMap);
978 DALI_TEST_CHECK(visual);
980 TestGlAbstraction& gl = application.GetGlAbstraction();
981 TraceCallStack& textureTrace = gl.GetTextureTrace();
982 textureTrace.Enable(true);
984 DummyControl actor = DummyControl::New();
985 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
986 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
988 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
989 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
991 application.GetScene().Add(actor);
992 application.SendNotification();
994 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
996 application.SendNotification();
997 application.Render();
999 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1000 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1002 application.GetScene().Remove(actor);
1003 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1008 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
1010 ToolkitTestApplication application;
1011 tet_infoline("Use Encoded Image Buffer as url");
1013 TestGlAbstraction& gl = application.GetGlAbstraction();
1014 TraceCallStack& textureTrace = gl.GetTextureTrace();
1015 textureTrace.Enable(true);
1017 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1018 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1019 std::string url = imageUrl.GetUrl();
1021 VisualFactory factory = VisualFactory::Get();
1022 DALI_TEST_CHECK(factory);
1024 Property::Map propertyMap;
1025 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1026 propertyMap.Insert(ImageVisual::Property::URL, url);
1028 Visual::Base visual = factory.CreateVisual(propertyMap);
1029 DALI_TEST_CHECK(visual);
1031 DummyControl actor = DummyControl::New();
1032 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1033 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1035 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1037 application.GetScene().Add(actor);
1038 application.SendNotification();
1040 // Wait for decode buffer and make texture.
1041 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1043 application.SendNotification();
1044 application.Render();
1046 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1047 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1049 tet_infoline("Delete texture because there is no actor to use decoded texture");
1051 application.GetScene().Remove(actor);
1052 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1053 application.SendNotification();
1054 application.Render();
1056 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1057 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1062 int UtcDaliImageVisualTextureReuse1(void)
1064 ToolkitTestApplication application;
1065 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
1067 Property::Map propertyMap;
1068 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1069 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1070 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1072 TestGlAbstraction& gl = application.GetGlAbstraction();
1073 TraceCallStack& textureTrace = gl.GetTextureTrace();
1074 textureTrace.Enable(true);
1075 TraceCallStack& drawTrace = gl.GetDrawTrace();
1076 drawTrace.Enable(true);
1078 Actor actor = CreateActorWithImageVisual(propertyMap);
1079 application.GetScene().Add(actor);
1080 application.SendNotification();
1082 // Wait for image to load
1083 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1085 application.SendNotification();
1086 application.Render();
1088 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1089 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1090 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1091 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1092 textureTrace.Reset();
1095 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1096 application.GetScene().Add(actor2);
1098 application.SendNotification(); // Send messages to update
1099 application.Render(); // process update and render
1100 application.SendNotification(); // process any signals to event
1102 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1104 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
1105 // backend here, but test graphics backend.
1106 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1107 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1109 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
1111 application.GetScene().Remove(actor);
1112 application.SendNotification();
1113 application.Render();
1115 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1116 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1118 tet_infoline("Test that removing last actor does delete the texture\n");
1120 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1121 application.SendNotification();
1122 application.Render();
1124 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1125 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1130 int UtcDaliImageVisualTextureReuse2(void)
1132 ToolkitTestApplication application;
1133 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");
1135 Property::Map propertyMap;
1136 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1137 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1139 TestGlAbstraction& gl = application.GetGlAbstraction();
1140 TraceCallStack& textureTrace = gl.GetTextureTrace();
1141 textureTrace.Enable(true);
1142 TraceCallStack& drawTrace = gl.GetDrawTrace();
1143 drawTrace.Enable(true);
1145 Actor actor = CreateActorWithImageVisual(propertyMap);
1146 application.GetScene().Add(actor);
1147 application.SendNotification();
1149 // Wait for image to load
1150 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1152 application.SendNotification();
1153 application.Render();
1155 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1156 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1157 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1158 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1159 textureTrace.Reset();
1162 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1163 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1164 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1165 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1166 application.GetScene().Add(actor2);
1168 application.SendNotification();
1170 // Wait for image to load
1171 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1173 application.SendNotification();
1174 application.Render();
1176 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1179 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1180 "renderers are using different textures\n");
1182 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1183 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1184 TraceCallStack::NamedParams tex1;
1185 tex1["texture"] << 1;
1186 TraceCallStack::NamedParams tex2;
1187 tex2["texture"] << 2;
1188 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1189 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1191 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1193 application.GetScene().Remove(actor);
1194 application.SendNotification();
1195 application.Render();
1197 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1198 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1200 tet_infoline("Test that removing last actor deletes it's texture\n");
1202 application.GetScene().Remove(actor2);
1203 application.SendNotification();
1204 application.Render();
1206 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1207 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1212 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1214 ToolkitTestApplication application;
1215 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1217 static std::vector<UniformData> customUniforms =
1219 UniformData("pixelArea", Property::Type::VECTOR4),
1220 UniformData("wrapMode", Property::Type::VECTOR2),
1223 TestGraphicsController& graphics = application.GetGraphicsController();
1224 graphics.AddCustomUniforms(customUniforms);
1226 VisualFactory factory = VisualFactory::Get();
1227 DALI_TEST_CHECK(factory);
1229 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1230 const int width = 34;
1231 const int height = 34;
1232 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1234 Property::Map propertyMap;
1235 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1236 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1237 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1238 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1239 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1240 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1241 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1242 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1243 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1245 Visual::Base visual = factory.CreateVisual(propertyMap);
1246 DALI_TEST_CHECK(visual);
1248 TestGlAbstraction& gl = application.GetGlAbstraction();
1249 TraceCallStack& textureTrace = gl.GetTextureTrace();
1250 textureTrace.Enable(true);
1251 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1252 texParameterTrace.Enable(true);
1254 DummyControl actor = DummyControl::New();
1255 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1256 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1257 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1258 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1259 application.GetScene().Add(actor);
1262 application.SendNotification();
1263 application.Render();
1265 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1267 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1269 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1270 std::stringstream out;
1271 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1272 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1274 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1275 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1277 // test the uniforms which used to handle the wrap mode
1278 Renderer renderer = actor.GetRendererAt(0u);
1279 DALI_TEST_CHECK(renderer);
1281 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1282 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1283 Vector4 pixelAreaUniform;
1284 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1285 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1287 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1288 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1289 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1290 Vector2 wrapModeUniform;
1291 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1292 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1295 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1300 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1302 ToolkitTestApplication application;
1303 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1305 static std::vector<UniformData> customUniforms =
1307 UniformData("pixelArea", Property::Type::VECTOR4),
1310 TestGraphicsController& graphics = application.GetGraphicsController();
1311 graphics.AddCustomUniforms(customUniforms);
1313 VisualFactory factory = VisualFactory::Get();
1314 DALI_TEST_CHECK(factory);
1316 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1317 const int width = 600;
1318 const int height = 600;
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_LARGE_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);
1331 Visual::Base visual = factory.CreateVisual(propertyMap);
1332 DALI_TEST_CHECK(visual);
1334 TestGlAbstraction& gl = application.GetGlAbstraction();
1335 TraceCallStack& textureTrace = gl.GetTextureTrace();
1336 textureTrace.Enable(true);
1337 textureTrace.EnableLogging(true);
1338 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1339 texParameterTrace.Enable(true);
1340 texParameterTrace.EnableLogging(true);
1342 DummyControl actor = DummyControl::New();
1343 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1344 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1345 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1346 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1347 application.GetScene().Add(actor);
1350 application.SendNotification();
1351 application.Render();
1352 application.SendNotification();
1354 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1356 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1358 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1359 std::stringstream out;
1360 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1361 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1363 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1364 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1366 // test the uniforms which used to handle the wrap mode
1367 Renderer renderer = actor.GetRendererAt(0u);
1368 DALI_TEST_CHECK(renderer);
1370 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1371 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1372 Vector4 pixelAreaUniform;
1373 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1374 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1376 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1377 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1380 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1385 int UtcDaliImageVisualAnimateMixColor(void)
1387 ToolkitTestApplication application;
1388 tet_infoline("Animate mix color");
1390 static std::vector<UniformData> customUniforms =
1392 UniformData("mixColor", Property::Type::VECTOR3),
1395 TestGraphicsController& graphics = application.GetGraphicsController();
1396 graphics.AddCustomUniforms(customUniforms);
1398 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1400 VisualFactory factory = VisualFactory::Get();
1401 Property::Map propertyMap;
1402 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1403 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1404 propertyMap.Insert("mixColor", Color::BLUE);
1405 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1406 Visual::Base visual = factory.CreateVisual(propertyMap);
1408 DummyControl actor = DummyControl::New(true);
1409 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1410 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1412 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1413 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1414 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1415 application.GetScene().Add(actor);
1417 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1419 Renderer renderer = actor.GetRendererAt(0);
1421 // @todo Should we add API to make this code work again?
1422 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1424 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1425 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1427 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1430 map["target"] = "testVisual";
1431 map["property"] = "mixColor";
1432 map["initialValue"] = Color::MAGENTA;
1433 map["targetValue"] = TARGET_MIX_COLOR;
1434 map["animator"] = Property::Map()
1435 .Add("alphaFunction", "LINEAR")
1436 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1438 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1440 Animation animation = dummyImpl.CreateTransition(transition);
1442 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1445 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1446 glAbstraction.EnableEnableDisableCallTrace(true);
1447 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1448 std::ostringstream blendStr;
1449 blendStr << std::hex << GL_BLEND;
1451 application.SendNotification();
1452 application.Render(0); // Ensure animation starts
1453 application.Render(2000u); // Halfway point
1454 Vector3 testColor(1.0f, 0.0f, 0.5f);
1456 // uColor.a should be actor's alpha * mixColor.a.
1457 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1458 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1460 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1462 glEnableStack.Reset();
1464 application.SendNotification();
1465 application.Render(2000u);
1467 application.SendNotification();
1468 application.Render();
1469 application.SendNotification();
1471 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1472 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1473 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1475 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1477 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1482 int UtcDaliImageVisualAnimateOpacity(void)
1484 ToolkitTestApplication application;
1485 tet_infoline("Animate image visual opacity");
1487 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1489 VisualFactory factory = VisualFactory::Get();
1490 Property::Map propertyMap;
1491 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1492 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1493 propertyMap.Insert("opacity", 0.5f);
1494 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1495 Visual::Base visual = factory.CreateVisual(propertyMap);
1497 DummyControl actor = DummyControl::New(true);
1498 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1499 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1501 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1502 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1503 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1504 application.GetScene().Add(actor);
1506 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1508 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1509 glAbstraction.EnableEnableDisableCallTrace(true);
1510 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1511 std::ostringstream blendStr;
1512 blendStr << std::hex << GL_BLEND;
1514 application.SendNotification();
1515 application.Render();
1517 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1520 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.");
1523 map["target"] = "testVisual";
1524 map["property"] = "opacity";
1525 map["targetValue"] = 1.0f;
1526 map["animator"] = Property::Map()
1527 .Add("alphaFunction", "LINEAR")
1528 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1530 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1531 Animation animation = dummyImpl.CreateTransition(transition);
1534 glEnableStack.Reset();
1536 application.SendNotification();
1537 application.Render(0); // Ensure animation starts
1538 application.Render(2000u); // Halfway point through animation
1539 application.SendNotification(); // Handle any signals
1542 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1543 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1545 application.Render(2001u); // end
1546 application.SendNotification(); // ensure animation finished signal is sent
1548 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1549 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1551 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1552 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1556 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.");
1559 map["target"] = "testVisual";
1560 map["property"] = Visual::Property::OPACITY;
1561 map["targetValue"] = 0.1f;
1562 map["animator"] = Property::Map()
1563 .Add("alphaFunction", "LINEAR")
1564 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1566 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1567 Animation animation = dummyImpl.CreateTransition(transition);
1570 glEnableStack.Reset();
1572 application.SendNotification();
1573 application.Render(0); // Ensure animation starts
1574 application.Render(2000u); // Halfway point
1575 application.SendNotification();
1578 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1579 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1581 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1583 glEnableStack.Reset();
1585 application.Render(2016u); // end
1586 application.SendNotification();
1588 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1589 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1591 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1592 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1598 int UtcDaliImageVisualAnimateOpacity02(void)
1600 ToolkitTestApplication application;
1601 tet_infoline("Animate image visual opacity");
1603 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1605 VisualFactory factory = VisualFactory::Get();
1606 Property::Map propertyMap;
1607 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1608 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1609 propertyMap.Insert("opacity", 0.5f);
1610 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1611 Visual::Base visual = factory.CreateVisual(propertyMap);
1613 DummyControl actor = DummyControl::New(true);
1614 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1615 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1617 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1618 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1619 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1621 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1623 Property::Array array;
1626 map["target"] = "testVisual";
1627 map["property"] = "opacity";
1628 map["initialValue"] = 0.0f;
1629 map["targetValue"] = 1.0f;
1630 map["animator"] = Property::Map()
1631 .Add("alphaFunction", "LINEAR")
1632 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1635 map2["target"] = "testVisual";
1636 map2["property"] = "size";
1637 map2["targetValue"] = Vector2(1.0f, 1.0f);
1639 array.Add(map).Add(map2);
1641 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1642 Animation animation = dummyImpl.CreateTransition(transition);
1644 application.GetScene().Add(actor);
1645 application.SendNotification();
1646 application.Render(0); // Ensure animation starts
1648 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1650 Renderer renderer = actor.GetRendererAt(0);
1651 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1652 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1654 animation = dummyImpl.CreateTransition(transition);
1657 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1658 glAbstraction.EnableEnableDisableCallTrace(true);
1659 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1660 std::ostringstream blendStr;
1661 blendStr << std::hex << GL_BLEND;
1663 application.SendNotification();
1664 application.Render(0); // Ensure animation starts
1665 application.Render(2000u); // Halfway point through animation
1666 application.SendNotification(); // Handle any signals
1668 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1671 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1672 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1674 glEnableStack.Reset();
1676 application.Render(2001u); // end
1677 application.SendNotification(); // ensure animation finished signal is sent
1679 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1680 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1682 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1687 int UtcDaliImageVisualAnimatePixelArea(void)
1689 ToolkitTestApplication application;
1690 tet_infoline("ImageVisual animate pixel area");
1692 static std::vector<UniformData> customUniforms =
1694 UniformData("pixelArea", Property::Type::VECTOR4),
1697 TestGraphicsController& graphics = application.GetGraphicsController();
1698 graphics.AddCustomUniforms(customUniforms);
1700 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1702 VisualFactory factory = VisualFactory::Get();
1703 Property::Map propertyMap;
1704 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1705 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1706 propertyMap.Insert("mixColor", Color::BLUE);
1707 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1708 Visual::Base visual = factory.CreateVisual(propertyMap);
1710 DummyControl actor = DummyControl::New(true);
1711 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1712 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1714 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1715 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1716 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1717 application.GetScene().Add(actor);
1719 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1721 Renderer renderer = actor.GetRendererAt(0);
1722 // @todo Implement this feature?
1723 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1724 //tet_infoline("Test that the renderer has the mixColor property");
1725 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1727 // TransitionData only takes string keys
1729 map["target"] = "testVisual";
1730 map["property"] = "pixelArea";
1731 map["initialValue"] = Vector4(0, 0, 0, 1);
1732 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1733 map["animator"] = Property::Map()
1734 .Add("alphaFunction", "LINEAR")
1735 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1737 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1739 Animation animation = dummyImpl.CreateTransition(transition);
1740 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1743 application.SendNotification();
1744 application.Render(0); // Ensure animation starts
1745 application.Render(2000u); // Halfway point
1747 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1749 application.Render(2000u); // End of animation
1751 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1756 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1758 ToolkitTestApplication application;
1759 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1761 Property::Map propertyMap;
1762 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1763 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1765 TestGlAbstraction& gl = application.GetGlAbstraction();
1766 TraceCallStack& textureTrace = gl.GetTextureTrace();
1767 textureTrace.Enable(true);
1768 TraceCallStack& drawTrace = gl.GetDrawTrace();
1769 drawTrace.Enable(true);
1771 Actor actor = CreateActorWithImageVisual(propertyMap);
1772 application.GetScene().Add(actor);
1773 application.SendNotification();
1775 application.GetScene().Remove(actor);
1776 application.SendNotification();
1778 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1779 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1780 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1781 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1786 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1788 ToolkitTestApplication application;
1789 tet_infoline("Load image asynchronously, cancel loading, then load again");
1791 VisualFactory factory = VisualFactory::Get();
1792 DALI_TEST_CHECK(factory);
1794 Property::Map propertyMap;
1795 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1796 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1798 Visual::Base visual = factory.CreateVisual(propertyMap);
1799 DALI_TEST_CHECK(visual);
1801 TestGlAbstraction& gl = application.GetGlAbstraction();
1802 TraceCallStack& textureTrace = gl.GetTextureTrace();
1803 textureTrace.Enable(true);
1804 TraceCallStack& drawTrace = gl.GetDrawTrace();
1805 drawTrace.Enable(true);
1807 DummyControl actor = DummyControl::New();
1808 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1809 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1811 application.GetScene().Add(actor);
1814 application.GetScene().Remove(actor);
1816 application.GetScene().Add(actor);
1818 // Create another visual with the same image
1819 visual = factory.CreateVisual(propertyMap);
1820 DALI_TEST_CHECK(visual);
1822 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1824 application.SendNotification();
1825 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1827 application.SendNotification();
1828 application.Render();
1830 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1831 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1832 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1833 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1838 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1840 ToolkitTestApplication application;
1841 tet_infoline("Request image visual with invalid images - should draw broken.png");
1843 VisualFactory factory = VisualFactory::Get();
1844 DALI_TEST_CHECK(factory);
1846 Property::Map propertyMap;
1847 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1848 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1850 Visual::Base visual = factory.CreateVisual(propertyMap);
1851 DALI_TEST_CHECK(visual);
1853 TestGlAbstraction& gl = application.GetGlAbstraction();
1854 TraceCallStack& textureTrace = gl.GetTextureTrace();
1855 textureTrace.Enable(true);
1857 DummyControl actor = DummyControl::New();
1858 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1859 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1861 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1862 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1864 application.GetScene().Add(actor);
1866 application.SendNotification();
1867 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1869 application.SendNotification();
1870 application.Render();
1872 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1873 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1875 application.GetScene().Remove(actor);
1876 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1881 int UtcDaliImageVisualSetInvalidSyncImage(void)
1883 ToolkitTestApplication application;
1884 tet_infoline("Request image visual with invalid images - should draw broken.png");
1886 VisualFactory factory = VisualFactory::Get();
1887 DALI_TEST_CHECK(factory);
1889 Property::Map propertyMap;
1890 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1891 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1892 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1894 Visual::Base visual = factory.CreateVisual(propertyMap);
1895 DALI_TEST_CHECK(visual);
1897 TestGlAbstraction& gl = application.GetGlAbstraction();
1898 TraceCallStack& textureTrace = gl.GetTextureTrace();
1899 textureTrace.Enable(true);
1901 DummyControl actor = DummyControl::New();
1902 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1903 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1905 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1906 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1908 application.GetScene().Add(actor);
1910 application.SendNotification();
1911 application.Render();
1913 // Check resource status
1914 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1915 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1917 // The broken image should be shown.
1918 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1919 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1921 application.GetScene().Remove(actor);
1922 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1927 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1929 ToolkitTestApplication application;
1930 tet_infoline("Request image visual with invalid images - should draw broken.png");
1932 VisualFactory factory = VisualFactory::Get();
1933 DALI_TEST_CHECK(factory);
1935 // Local invalid file, asynchronous loading
1936 Property::Map propertyMap;
1937 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1938 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1940 Visual::Base visual = factory.CreateVisual(propertyMap);
1941 DALI_TEST_CHECK(visual);
1943 TestGlAbstraction& gl = application.GetGlAbstraction();
1944 TraceCallStack& textureTrace = gl.GetTextureTrace();
1945 textureTrace.Enable(true);
1947 DummyControl actor = DummyControl::New();
1948 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1949 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1951 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1952 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1954 application.GetScene().Add(actor);
1956 application.SendNotification();
1957 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1959 application.SendNotification();
1960 application.Render();
1962 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1963 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1965 application.GetScene().Remove(actor);
1966 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1971 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
1973 ToolkitTestApplication application;
1974 tet_infoline("Request image visual with invalid images - should draw broken.png");
1976 VisualFactory factory = VisualFactory::Get();
1977 DALI_TEST_CHECK(factory);
1979 // Load invalid file
1980 Property::Map propertyMap;
1981 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1982 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
1984 Visual::Base visual = factory.CreateVisual(propertyMap);
1985 DALI_TEST_CHECK(visual);
1987 TestGlAbstraction& gl = application.GetGlAbstraction();
1988 TraceCallStack& textureTrace = gl.GetTextureTrace();
1989 textureTrace.Enable(true);
1991 DummyControl actor = DummyControl::New();
1992 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1993 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1995 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1996 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1998 application.GetScene().Add(actor);
2000 application.SendNotification();
2001 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2003 application.SendNotification();
2004 application.Render();
2006 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2007 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2009 application.GetScene().Remove(actor);
2010 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2011 textureTrace.Reset();
2013 // Load invalid file with disabled broken
2014 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2015 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2016 propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2018 visual = factory.CreateVisual(propertyMap);
2019 DALI_TEST_CHECK(visual);
2021 actor = DummyControl::New();
2022 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2023 dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2025 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2026 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2028 application.GetScene().Add(actor);
2030 application.SendNotification();
2031 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2033 application.SendNotification();
2034 application.Render();
2036 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2037 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2039 application.GetScene().Remove(actor);
2040 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2045 int UtcDaliImageVisualAlphaMask01(void)
2047 ToolkitTestApplication application;
2048 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2050 VisualFactory factory = VisualFactory::Get();
2051 DALI_TEST_CHECK(factory);
2053 Property::Map propertyMap;
2054 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2055 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2056 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2058 Visual::Base visual = factory.CreateVisual(propertyMap);
2059 DALI_TEST_CHECK(visual);
2061 Property::Map testMap;
2062 visual.CreatePropertyMap(testMap);
2063 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2065 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2066 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2068 TestGlAbstraction& gl = application.GetGlAbstraction();
2069 TraceCallStack& textureTrace = gl.GetTextureTrace();
2070 textureTrace.Enable(true);
2072 DummyControl actor = DummyControl::New();
2073 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2074 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2076 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2077 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2078 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2080 application.GetScene().Add(actor);
2081 application.SendNotification();
2082 application.Render();
2084 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2086 application.SendNotification();
2087 application.Render();
2089 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2090 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2091 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2093 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2094 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2099 int UtcDaliImageVisualAlphaMask02(void)
2101 ToolkitTestApplication application;
2102 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2104 VisualFactory factory = VisualFactory::Get();
2105 DALI_TEST_CHECK(factory);
2107 Property::Map propertyMap;
2108 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2109 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2110 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2111 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2113 Visual::Base visual = factory.CreateVisual(propertyMap);
2114 DALI_TEST_CHECK(visual);
2116 Property::Map testMap;
2117 visual.CreatePropertyMap(testMap);
2118 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2119 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2121 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2122 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2124 TestGlAbstraction& gl = application.GetGlAbstraction();
2125 TraceCallStack& textureTrace = gl.GetTextureTrace();
2126 textureTrace.Enable(true);
2128 DummyControl actor = DummyControl::New();
2129 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2130 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2132 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2133 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2134 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2136 application.GetScene().Add(actor);
2137 application.SendNotification();
2138 application.Render();
2140 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2142 application.SendNotification();
2143 application.Render();
2145 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2146 Renderer renderer = actor.GetRendererAt(0u);
2147 TextureSet textures = renderer.GetTextures();
2148 DALI_TEST_CHECK(textures);
2149 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2151 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2152 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2154 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2155 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2160 int UtcDaliImageVisualAlphaMask03(void)
2162 ToolkitTestApplication application;
2163 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2165 VisualFactory factory = VisualFactory::Get();
2166 DALI_TEST_CHECK(factory);
2168 Property::Map propertyMap;
2169 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2170 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2171 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2172 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2174 Visual::Base visual = factory.CreateVisual(propertyMap);
2175 DALI_TEST_CHECK(visual);
2177 Property::Map testMap;
2178 visual.CreatePropertyMap(testMap);
2180 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2181 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2183 TestGlAbstraction& gl = application.GetGlAbstraction();
2184 TraceCallStack& textureTrace = gl.GetTextureTrace();
2185 textureTrace.Enable(true);
2187 DummyControl actor = DummyControl::New();
2188 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2189 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2191 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2192 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2193 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2195 application.GetScene().Add(actor);
2196 application.SendNotification();
2197 application.Render();
2199 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2201 application.SendNotification();
2202 application.Render();
2204 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2205 Renderer renderer = actor.GetRendererAt(0u);
2206 TextureSet textures = renderer.GetTextures();
2207 DALI_TEST_CHECK(textures);
2208 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2210 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2211 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2213 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2214 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2219 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2221 ToolkitTestApplication application;
2222 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
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);
2231 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2233 Visual::Base visual = factory.CreateVisual(propertyMap);
2234 DALI_TEST_CHECK(visual);
2236 Property::Map testMap;
2237 visual.CreatePropertyMap(testMap);
2238 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2240 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2241 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2243 TestGlAbstraction& gl = application.GetGlAbstraction();
2244 TraceCallStack& textureTrace = gl.GetTextureTrace();
2245 textureTrace.Enable(true);
2247 DummyControl actor = DummyControl::New();
2248 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2249 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2251 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2252 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2253 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2255 application.GetScene().Add(actor);
2257 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2259 application.SendNotification();
2260 application.Render();
2262 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2263 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2264 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2266 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2267 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2272 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2274 ToolkitTestApplication application;
2275 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2277 VisualFactory factory = VisualFactory::Get();
2278 DALI_TEST_CHECK(factory);
2280 Property::Map propertyMap;
2281 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2282 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2283 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2284 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2285 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2287 Visual::Base visual = factory.CreateVisual(propertyMap);
2288 DALI_TEST_CHECK(visual);
2290 Property::Map testMap;
2291 visual.CreatePropertyMap(testMap);
2292 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2294 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2295 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2297 TestGlAbstraction& gl = application.GetGlAbstraction();
2298 TraceCallStack& textureTrace = gl.GetTextureTrace();
2299 textureTrace.Enable(true);
2301 DummyControl actor = DummyControl::New();
2302 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2303 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2305 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2306 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2307 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2309 application.GetScene().Add(actor);
2311 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2313 application.SendNotification();
2314 application.Render();
2316 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2317 Renderer renderer = actor.GetRendererAt(0u);
2318 TextureSet textures = renderer.GetTextures();
2319 DALI_TEST_CHECK(textures);
2320 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2322 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2323 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2325 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2326 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2331 int UtcDaliImageVisualRemoteAlphaMask(void)
2333 ToolkitTestApplication application;
2334 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2336 VisualFactory factory = VisualFactory::Get();
2337 DALI_TEST_CHECK(factory);
2339 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2341 Property::Map propertyMap;
2342 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2343 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2344 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2346 Visual::Base visual = factory.CreateVisual(propertyMap);
2347 DALI_TEST_CHECK(visual);
2349 Property::Map testMap;
2350 visual.CreatePropertyMap(testMap);
2352 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2354 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2355 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2357 TestGlAbstraction& gl = application.GetGlAbstraction();
2358 TraceCallStack& textureTrace = gl.GetTextureTrace();
2359 textureTrace.Enable(true);
2361 DummyControl actor = DummyControl::New();
2362 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2363 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2365 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2367 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2368 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2370 application.GetScene().Add(actor);
2371 application.SendNotification();
2372 application.Render();
2374 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2376 application.SendNotification();
2377 application.Render();
2379 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2380 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2381 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2386 int UtcDaliImageVisualAlphaMaskCrop(void)
2388 ToolkitTestApplication application;
2389 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2391 VisualFactory factory = VisualFactory::Get();
2392 DALI_TEST_CHECK(factory);
2394 Property::Map propertyMap;
2395 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2396 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2397 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2398 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2399 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2401 Visual::Base visual = factory.CreateVisual(propertyMap);
2402 DALI_TEST_CHECK(visual);
2404 Property::Map testMap;
2405 visual.CreatePropertyMap(testMap);
2406 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2407 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2408 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2410 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2411 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2413 TestGlAbstraction& gl = application.GetGlAbstraction();
2414 TraceCallStack& textureTrace = gl.GetTextureTrace();
2415 textureTrace.Enable(true);
2417 DummyControl actor = DummyControl::New();
2418 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2419 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2421 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2422 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2423 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2425 application.GetScene().Add(actor);
2426 application.SendNotification();
2427 application.Render();
2429 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2431 application.SendNotification();
2432 application.Render();
2435 visual.GetNaturalSize(size);
2437 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2438 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2439 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2440 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2445 int UtcDaliImageVisualReleasePolicy01(void)
2447 ToolkitTestApplication application;
2448 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2450 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2451 DALI_TEST_CHECK(imageVisual);
2453 // Set up debug trace
2454 TestGlAbstraction& gl = application.GetGlAbstraction();
2455 TraceCallStack& textureTrace = gl.GetTextureTrace();
2456 textureTrace.Enable(true);
2458 tet_infoline("Register visual with control and ensure it has the only handle");
2459 DummyControl actor = DummyControl::New(true);
2460 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2461 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2462 imageVisual.Reset();
2464 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2466 application.SendNotification();
2467 application.Render(0);
2468 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2469 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2471 application.GetScene().Add(actor);
2473 // Wait for image to load
2474 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2476 application.SendNotification();
2477 application.Render(0);
2478 // Test renderer and texture created
2479 tet_infoline("Confirm texture created");
2480 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2481 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2483 tet_infoline("Disable visual causing the texture to be deleted");
2484 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2486 application.SendNotification();
2487 application.Render(0);
2488 // Test renderer and textures removed.
2489 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2490 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2495 int UtcDaliImageVisualReleasePolicy02(void)
2497 ToolkitTestApplication application;
2498 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2500 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2501 DALI_TEST_CHECK(imageVisual);
2503 // Setup debug trace
2504 TestGlAbstraction& gl = application.GetGlAbstraction();
2505 TraceCallStack& textureTrace = gl.GetTextureTrace();
2506 textureTrace.Enable(true);
2508 tet_infoline("Register visual with control and ensure it has the only handle");
2509 DummyControl actor = DummyControl::New(true);
2510 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2511 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2512 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2514 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2516 application.SendNotification();
2517 application.Render(0);
2518 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2519 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2521 application.GetScene().Add(actor);
2523 // Wait for image to load
2524 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2526 application.SendNotification();
2527 application.Render(0);
2528 // Test renderer and texture created
2529 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2530 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2532 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2533 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2534 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2535 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2536 application.SendNotification();
2537 application.Render();
2539 // Test texture removed after visual destroyed.
2540 tet_infoline("Ensure texture is deleted after visual destroyed");
2541 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2546 int UtcDaliImageVisualReleasePolicy03(void)
2548 ToolkitTestApplication application;
2549 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2551 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2552 DALI_TEST_CHECK(imageVisual);
2554 TestGlAbstraction& gl = application.GetGlAbstraction();
2555 TraceCallStack& textureTrace = gl.GetTextureTrace();
2556 textureTrace.Enable(true);
2558 tet_infoline("Register visual with control and ensure it has the only handle");
2559 DummyControl actor = DummyControl::New(true);
2560 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2561 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2562 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2564 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2566 application.SendNotification();
2567 application.Render(0);
2568 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2569 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2571 application.GetScene().Add(actor);
2573 // Wait for image to load
2574 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2576 application.SendNotification();
2577 application.Render(0);
2578 // Test renderer and texture created
2579 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2580 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2582 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2583 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2584 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2585 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2586 application.SendNotification();
2587 application.Render();
2589 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2590 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2595 int UtcDaliImageVisualReleasePolicy04(void)
2597 ToolkitTestApplication application;
2598 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2600 tet_infoline("Create first visual with Never release policy");
2601 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2603 tet_infoline("Create second visual with Destroyed release policy");
2604 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2606 // Set up trace debug
2607 TestGlAbstraction& gl = application.GetGlAbstraction();
2608 TraceCallStack& textureTrace = gl.GetTextureTrace();
2609 textureTrace.Enable(true);
2611 tet_infoline("Register visuals with control and ensure it has the only handles");
2612 DummyControl actor = DummyControl::New(true);
2613 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2614 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2615 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2616 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2617 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2619 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2621 // Test initially zero renderers
2622 application.SendNotification();
2623 application.Render(0);
2624 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2625 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2627 application.GetScene().Add(actor);
2629 // Wait for image to load
2630 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2632 application.SendNotification();
2633 application.Render(0);
2634 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2635 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2636 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2638 // Test renderer removed when visual destroyed
2639 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2640 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2641 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2642 application.SendNotification();
2643 application.Render();
2645 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2646 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2648 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2649 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2650 application.SendNotification();
2651 application.Render();
2653 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2654 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2655 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2660 int UtcDaliImageVisualReleasePolicy05(void)
2662 ToolkitTestApplication application;
2663 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2665 VisualFactory factory = VisualFactory::Get();
2667 Property::Map propertyMapNeverReleasePolicy;
2668 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2669 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2670 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2671 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2672 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2674 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2676 Property::Map resultMap;
2677 imageVisualNever.CreatePropertyMap(resultMap);
2678 DALI_TEST_CHECK(!resultMap.Empty());
2680 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2685 int UtcDaliImageVisualReleasePolicy06(void)
2687 ToolkitTestApplication application;
2688 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2690 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2691 DALI_TEST_CHECK(imageVisual);
2693 TestGlAbstraction& gl = application.GetGlAbstraction();
2694 TraceCallStack& textureTrace = gl.GetTextureTrace();
2695 textureTrace.Enable(true);
2697 tet_infoline("Register visual with control and ensure it has the only handle");
2698 DummyControl actor = DummyControl::New(true);
2699 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2700 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2701 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2703 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2705 application.SendNotification();
2706 application.Render(0);
2707 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2708 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2710 application.GetScene().Add(actor);
2712 // Wait for image to load
2713 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2715 application.SendNotification();
2716 application.Render(0);
2717 // Test renderer and texture created
2718 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2719 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2720 textureTrace.Reset();
2722 tet_infoline("Disable Visual and check texture not affected");
2723 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2724 application.SendNotification();
2725 application.Render(0);
2726 tet_infoline("Check renderer is destroyed when visual off stage");
2727 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2728 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2729 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2730 textureTrace.Reset();
2732 tet_infoline("Re-enable Visual and check texture not affected");
2733 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2734 application.SendNotification();
2735 application.Render(0);
2736 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2737 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2738 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2739 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2744 int UtcDaliImageVisualReleasePolicy07(void)
2746 ToolkitTestApplication application;
2747 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2749 tet_infoline("Create first visual with DESTROYED release policy");
2750 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2752 tet_infoline("Create second visual with DETACHED release policy");
2753 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2755 // Set up trace debug
2756 TestGlAbstraction& gl = application.GetGlAbstraction();
2757 TraceCallStack& textureTrace = gl.GetTextureTrace();
2758 textureTrace.Enable(true);
2760 tet_infoline("Register visuals with control and ensure it has the only handles");
2761 DummyControl actor = DummyControl::New(true);
2762 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2763 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2764 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2765 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2766 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2768 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2770 // Test initially zero renderers
2771 application.SendNotification();
2772 application.Render(0);
2773 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2774 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2776 application.GetScene().Add(actor);
2778 // Wait for image to load
2779 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2781 application.SendNotification();
2782 application.Render(0);
2783 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2784 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2785 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2787 // Test renderer removed when visual destroyed
2788 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2789 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2790 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2791 application.SendNotification();
2792 application.Render();
2794 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2795 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2797 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2798 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2799 application.SendNotification();
2800 application.Render();
2802 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2803 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2808 int UtcDaliImageVisualReleasePolicy08(void)
2810 ToolkitTestApplication application;
2811 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2813 tet_infoline("Create first visual with DESTROYED release policy");
2814 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2816 // Set up trace debug
2817 TestGlAbstraction& gl = application.GetGlAbstraction();
2818 TraceCallStack& textureTrace = gl.GetTextureTrace();
2819 textureTrace.Enable(true);
2821 tet_infoline("Register visuals with control and ensure it has the only handles");
2822 DummyControl actor = DummyControl::New(true);
2823 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2824 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2825 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2827 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2829 // Test initially zero renderers
2830 application.SendNotification();
2831 application.Render(0);
2832 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2833 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2834 textureTrace.Reset();
2836 application.GetScene().Add(actor);
2838 // Wait for image to load
2839 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2841 application.SendNotification();
2842 application.Render(0);
2843 tet_infoline("Ensure a texture is created");
2844 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2845 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2846 textureTrace.Reset();
2848 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2850 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2852 // 2.Remove actor from stage. In this case, renderer also is deleted.
2853 tet_infoline("Remove actor from stage");
2854 application.GetScene().Remove(actor);
2855 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2856 application.SendNotification();
2857 application.Render();
2859 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2860 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2861 textureTrace.Reset();
2863 // 3.Add actor in stage. In this case, renderer is created.
2864 tet_infoline("Add actor in stage");
2865 application.GetScene().Add(actor);
2866 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2867 application.SendNotification();
2868 application.Render();
2869 tet_infoline("Ensure a texture is not created again");
2870 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2871 textureTrace.Reset();
2873 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2874 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2875 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2876 DALI_TEST_CHECK(textureBefore == textureAfter);
2877 textureBefore.Reset();
2878 textureAfter.Reset();
2880 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2881 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2882 application.SendNotification();
2883 application.Render();
2884 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2889 int UtcDaliImageVisualReleasePolicy09(void)
2891 ToolkitTestApplication application;
2892 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2894 Property::Map propertyMapNPatchReleasePolicy;
2895 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2896 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2897 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2898 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2899 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2901 VisualFactory factory = VisualFactory::Get();
2902 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2903 DALI_TEST_CHECK(imageVisual);
2905 // Setup debug trace
2906 TestGlAbstraction& gl = application.GetGlAbstraction();
2907 TraceCallStack& textureTrace = gl.GetTextureTrace();
2908 textureTrace.Enable(true);
2910 tet_infoline("Register visual with control and ensure it has the only handle");
2911 DummyControl actor = DummyControl::New(true);
2912 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2913 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2914 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2916 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2918 application.SendNotification();
2919 application.Render(0);
2920 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2921 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2923 application.GetScene().Add(actor);
2925 // Wait for image to load
2926 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2928 application.SendNotification();
2929 application.Render(0);
2930 // Test renderer and texture created
2931 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2932 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2934 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2935 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2936 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2937 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2938 application.SendNotification();
2939 application.Render();
2941 // Test texture removed after visual destroyed.
2942 tet_infoline("Ensure texture is deleted after visual destroyed");
2943 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2948 int UtcDaliImageVisualLoadPolicy01(void)
2950 ToolkitTestApplication application;
2951 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2953 // Set up trace debug
2954 TestGlAbstraction& gl = application.GetGlAbstraction();
2955 TraceCallStack& textureTrace = gl.GetTextureTrace();
2956 textureTrace.Enable(true);
2958 tet_infoline("Create visual with IMMEDIATE load policy");
2959 VisualFactory factory = VisualFactory::Get();
2961 Property::Map propertyMap;
2962 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2963 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2964 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2965 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2966 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2968 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2970 Property::Map resultMap;
2971 imageVisual.CreatePropertyMap(resultMap);
2972 DALI_TEST_CHECK(!resultMap.Empty());
2973 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2975 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2977 // Ensure texture has been uploaded
2978 application.SendNotification();
2979 application.Render();
2981 tet_infoline("Ensure texture loading starts after visual created");
2982 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2983 textureTrace.Reset();
2985 tet_infoline("Register visuals with control and ensure it has the only handles");
2986 DummyControl actor = DummyControl::New(true);
2987 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2988 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2989 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2991 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2992 application.GetScene().Add(actor);
2993 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2994 const unsigned int TIME_OUT_3_SECONDS = 3;
2995 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2997 application.SendNotification();
2998 application.Render();
3000 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3001 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3003 // Ensure texture is deleted when no longer needed (ref count was correct )
3004 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3006 application.SendNotification();
3007 application.Render();
3009 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3010 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3015 int UtcDaliImageVisualLoadPolicy02(void)
3017 ToolkitTestApplication application;
3018 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3020 // Set up trace debug
3021 TestGlAbstraction& gl = application.GetGlAbstraction();
3022 TraceCallStack& textureTrace = gl.GetTextureTrace();
3023 textureTrace.Enable(true);
3025 tet_infoline("Create visual with IMMEDIATE load policy");
3026 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3028 const unsigned int TIME_OUT_3_SECONDS = 3;
3029 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3031 // Act on meeage queue even although nothing expected to load
3032 application.SendNotification();
3033 application.Render();
3035 tet_infoline("Ensure texture is not generated yet");
3036 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3037 textureTrace.Reset();
3039 tet_infoline("Register visuals with control and ensure it has the only handles");
3040 DummyControl actor = DummyControl::New(true);
3041 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3042 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3043 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3045 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3046 application.GetScene().Add(actor);
3047 tet_infoline("Allow image time to load");
3048 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3050 application.SendNotification();
3051 application.Render();
3053 tet_infoline("Ensure texture generated and renderer created");
3054 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3055 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3057 // Ensure texture is delete when no longer needed
3058 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3060 application.SendNotification();
3061 application.Render();
3063 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3064 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3069 int UtcDaliImageVisualLoadPolicy03(void)
3071 ToolkitTestApplication application;
3072 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3074 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3076 // Set up trace debug
3077 TestGlAbstraction& gl = application.GetGlAbstraction();
3078 TraceCallStack& textureTrace = gl.GetTextureTrace();
3079 textureTrace.Enable(true);
3081 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3082 DummyControl actor = DummyControl::New(true);
3083 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3084 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3085 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3087 tet_infoline("Create visual with IMMEDIATE load policy");
3088 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3090 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3091 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3092 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3094 tet_infoline("Allow image time to load resource");
3095 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3096 application.SendNotification();
3097 application.Render();
3099 // Ensure texture has been uploaded
3100 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3101 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3106 int UtcDaliImageVisualLoadPolicy04(void)
3108 ToolkitTestApplication application;
3109 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3110 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3112 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3114 // Set up trace debug
3115 TestGlAbstraction& gl = application.GetGlAbstraction();
3116 TraceCallStack& textureTrace = gl.GetTextureTrace();
3117 textureTrace.Enable(true);
3119 tet_infoline("Create a control and connect to resource ready signal");
3120 DummyControl actor = DummyControl::New(true);
3121 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3122 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3123 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3125 tet_infoline("Create visual with IMMEDIATE load policy");
3126 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3128 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3129 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3130 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3132 tet_infoline("Allow image time to load");
3133 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3134 application.SendNotification();
3135 application.Render();
3137 tet_infoline("Testing texture is loaded and resource ready signal fired");
3138 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3139 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3141 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3143 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3144 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3145 DummyControl actor2 = DummyControl::New(true);
3146 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3147 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3149 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3150 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3151 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3152 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3153 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3154 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3159 int UtcDaliImageVisualLoadPolicy05(void)
3161 ToolkitTestApplication application;
3162 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3163 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3164 // Set up trace debug
3165 TestGlAbstraction& gl = application.GetGlAbstraction();
3166 TraceCallStack& textureTrace = gl.GetTextureTrace();
3167 textureTrace.Enable(true);
3169 tet_infoline("Create a control and connect to resource ready signal");
3170 DummyControl actor = DummyControl::New(true);
3171 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3172 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3173 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3174 application.GetScene().Add(actor);
3176 tet_infoline("Create visual with ATTACHED load policy");
3177 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3179 tet_infoline("Registering visual allows control to get a signal once loaded");
3180 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3181 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3183 tet_infoline("Allow image time to load");
3184 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3185 application.SendNotification();
3186 application.Render();
3188 tet_infoline("Testing texture is loaded and resource ready signal fired");
3189 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3190 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3192 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3194 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3195 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3196 DummyControl actor2 = DummyControl::New(true);
3197 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3198 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3200 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3201 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3202 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3203 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3204 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3205 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3210 int UtcDaliImageVisualOrientationCorrection(void)
3212 ToolkitTestApplication application;
3213 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3215 VisualFactory factory = VisualFactory::Get();
3216 tet_infoline("Create visual with Orientation correction set OFF");
3217 Property::Map propertyMap;
3218 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3219 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3220 propertyMap.Insert("orientationCorrection", false);
3221 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3223 tet_infoline("Create control for visual, need to loaded it");
3224 DummyControl actor = DummyControl::New(true);
3225 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3226 application.GetScene().Add(actor);
3228 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3229 // Wait for image to load
3230 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3232 Vector2 originalImageSize;
3233 tet_infoline("Get size of original visual to compare later with rotated image");
3234 imageVisual.GetNaturalSize(originalImageSize);
3235 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3236 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3237 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3238 application.SendNotification();
3239 application.Render();
3241 tet_infoline("Create visual with Orientation correction set ON ");
3242 propertyMap.Clear();
3243 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3244 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3245 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3246 imageVisual = factory.CreateVisual(propertyMap);
3248 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3249 // Wait for image to load
3250 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3252 Vector2 rotatedImageSize;
3253 imageVisual.GetNaturalSize(rotatedImageSize);
3254 tet_infoline("Confirm that visual has rotated");
3255 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3256 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3258 Property::Map resultMap;
3259 imageVisual.CreatePropertyMap(resultMap);
3261 // check the Property::ORIENTATION_CORRECTION value from the returned map
3262 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3263 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3268 int UtcDaliImageVisualCustomShader(void)
3270 ToolkitTestApplication application;
3271 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3273 VisualFactory factory = VisualFactory::Get();
3274 Property::Map properties;
3275 Property::Map shader;
3276 const std::string vertexShader = "Foobar";
3277 const std::string fragmentShader = "Foobar";
3278 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3279 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3281 properties[Visual::Property::TYPE] = Visual::IMAGE;
3282 properties[Visual::Property::SHADER] = shader;
3283 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3285 Visual::Base visual = factory.CreateVisual(properties);
3287 // trigger creation through setting on stage
3288 DummyControl dummy = DummyControl::New(true);
3289 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3290 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3292 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3293 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3294 application.GetScene().Add(dummy);
3296 application.SendNotification();
3297 application.Render();
3299 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3301 Renderer renderer = dummy.GetRendererAt(0);
3302 Shader shader2 = renderer.GetShader();
3303 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3304 Property::Map* map = value.GetMap();
3305 DALI_TEST_CHECK(map);
3307 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3308 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3310 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3311 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3315 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3316 properties[Visual::Property::SHADER] = shader;
3318 Visual::Base visual1 = factory.CreateVisual(properties);
3320 // trigger creation through setting on stage
3321 DummyControl dummy1 = DummyControl::New(true);
3322 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3323 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3324 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3325 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3326 application.GetScene().Add(dummy1);
3328 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3329 glAbstraction.EnableEnableDisableCallTrace(true);
3331 application.SendNotification();
3332 application.Render();
3334 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3335 std::ostringstream blendStr;
3336 blendStr << std::hex << GL_BLEND;
3337 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3342 void ResourceReadyLoadNext(Control control)
3344 static int callNumber = 0;
3346 gResourceReadySignalFired = true;
3347 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3351 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3353 tet_infoline("Create visual with loaded image from within the signal handler");
3354 VisualFactory factory = VisualFactory::Get();
3355 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3357 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3358 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3363 tet_infoline("3rd signal called");
3364 DALI_TEST_CHECK(true);
3368 int UtcDaliImageVisualLoadReady01(void)
3370 ToolkitTestApplication application;
3371 tet_infoline("UtcDaliImageVisualLoadReady01");
3372 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3373 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3374 tet_infoline("Should get a ready signal for all three visuals");
3378 tet_infoline("Create a control and connect to resource ready signal");
3379 DummyControl actor = DummyControl::New(true);
3380 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3381 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3382 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3383 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3384 application.GetScene().Add(actor);
3386 tet_infoline("Create visual with IMMEDIATE load policy");
3387 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3389 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3390 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3392 tet_infoline("Allow image time to load");
3393 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3394 application.SendNotification();
3395 application.Render();
3397 tet_infoline("Testing texture is loaded and resource ready signal fired");
3398 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3399 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3401 tet_infoline("Original control correctly signalled, now testing failing image");
3403 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3406 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3408 DummyControl actor2 = DummyControl::New(true);
3409 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3410 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3411 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3413 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3414 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3416 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3417 application.GetScene().Add(actor2);
3419 tet_infoline("Wait for loading thread to finish");
3420 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3421 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3423 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3425 tet_infoline("Check for 3rd signal");
3426 application.SendNotification();
3427 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3428 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3433 int UtcDaliImageVisualLoadImagePlanes01(void)
3435 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3436 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3438 ToolkitTestApplication application;
3440 VisualFactory factory = VisualFactory::Get();
3441 DALI_TEST_CHECK(factory);
3443 Property::Map propertyMap;
3444 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3445 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3447 Visual::Base visual = factory.CreateVisual(propertyMap);
3448 DALI_TEST_CHECK(visual);
3450 DummyControl actor = DummyControl::New();
3451 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3452 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3453 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3454 application.GetScene().Add(actor);
3456 application.SendNotification();
3457 application.Render();
3459 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3461 TestGlAbstraction& gl = application.GetGlAbstraction();
3462 TraceCallStack& textureTrace = gl.GetTextureTrace();
3463 textureTrace.Enable(true);
3465 application.SendNotification();
3466 application.Render();
3468 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3469 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3470 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3472 Renderer renderer = actor.GetRendererAt(0);
3473 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3474 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3479 int UtcDaliImageVisualLoadImagePlanes02(void)
3481 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3482 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3484 ToolkitTestApplication application;
3486 VisualFactory factory = VisualFactory::Get();
3487 DALI_TEST_CHECK(factory);
3489 // Alpha masking case - not support yuv planes
3490 Property::Map propertyMap;
3491 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3492 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3493 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3495 Visual::Base visual = factory.CreateVisual(propertyMap);
3496 DALI_TEST_CHECK(visual);
3498 DummyControl actor = DummyControl::New();
3499 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3500 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3501 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3502 application.GetScene().Add(actor);
3504 application.SendNotification();
3505 application.Render();
3507 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3509 TestGlAbstraction& gl = application.GetGlAbstraction();
3510 TraceCallStack& textureTrace = gl.GetTextureTrace();
3511 textureTrace.Enable(true);
3513 application.SendNotification();
3514 application.Render();
3516 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3517 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3518 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3523 int UtcDaliImageVisualLoadImagePlanes03(void)
3525 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3526 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3528 ToolkitTestApplication application;
3530 VisualFactory factory = VisualFactory::Get();
3531 DALI_TEST_CHECK(factory);
3533 TestGlAbstraction& gl = application.GetGlAbstraction();
3534 TraceCallStack& textureTrace = gl.GetTextureTrace();
3535 textureTrace.Enable(true);
3537 Property::Map propertyMap;
3538 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3539 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3540 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3542 Visual::Base visual = factory.CreateVisual(propertyMap);
3543 DALI_TEST_CHECK(visual);
3545 DummyControl actor = DummyControl::New();
3546 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3547 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3548 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3549 application.GetScene().Add(actor);
3551 application.SendNotification();
3552 application.Render();
3554 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3555 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3556 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3561 int UtcDaliImageVisualLoadFastTrackImage01(void)
3563 tet_infoline("Test worker thread uploading with Local URL");
3564 ToolkitTestApplication application;
3566 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3568 VisualFactory factory = VisualFactory::Get();
3569 DALI_TEST_CHECK(factory);
3571 // Pair of filename - expect GenTextures count.
3572 std::vector<std::pair<std::string, int>> testCases = {
3573 {TEST_IMAGE_FILE_NAME, 1},
3574 {TEST_REMOTE_IMAGE_FILE_NAME, 1},
3575 {TEST_INVALID_FILE_NAME, 0},
3578 for(auto&& tc : testCases)
3580 auto& filename = tc.first;
3581 auto& expectValue = tc.second;
3583 tet_printf("Test %s\n", filename.c_str());
3585 Property::Map propertyMap;
3586 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3587 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3588 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3590 Visual::Base visual = factory.CreateVisual(propertyMap);
3591 DALI_TEST_CHECK(visual);
3593 DummyControl actor = DummyControl::New();
3594 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3595 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3596 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3598 TestGlAbstraction& gl = application.GetGlAbstraction();
3599 TraceCallStack& textureTrace = gl.GetTextureTrace();
3600 textureTrace.Enable(true);
3602 application.GetScene().Add(actor);
3604 application.SendNotification();
3605 application.Render();
3607 // EventThread without callback
3608 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3610 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3613 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3614 // How can we make it? Should it be integration-api?
3615 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3616 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3618 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3619 application.Render();
3621 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3623 application.SendNotification();
3624 application.Render();
3626 textureTrace.Reset();
3632 int UtcDaliImageVisualLoadFastTrackImage02(void)
3634 tet_infoline("Test worker thread uploading with Local URL");
3635 ToolkitTestApplication application;
3637 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3639 VisualFactory factory = VisualFactory::Get();
3640 DALI_TEST_CHECK(factory);
3643 auto filename = std::string(TEST_IMAGE_FILE_NAME);
3644 auto expectValue = 1;
3646 tet_printf("Test %s\n", filename.c_str());
3648 Property::Map propertyMap;
3649 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3650 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3651 propertyMap.Insert("fastTrackUploading", true);
3653 Visual::Base visual = factory.CreateVisual(propertyMap);
3654 DALI_TEST_CHECK(visual);
3656 DummyControl actor = DummyControl::New();
3657 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3658 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3659 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3661 TestGlAbstraction& gl = application.GetGlAbstraction();
3662 TraceCallStack& textureTrace = gl.GetTextureTrace();
3663 textureTrace.Enable(true);
3665 application.GetScene().Add(actor);
3667 application.SendNotification();
3668 application.Render();
3670 // EventThread without callback
3671 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3673 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3676 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3677 // How can we make it? Should it be integration-api?
3678 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3679 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3681 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3682 application.Render();
3684 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3686 application.SendNotification();
3687 application.Render();
3689 textureTrace.Reset();
3695 int UtcDaliImageVisualLoadFastTrackImageResourceReady(void)
3697 tet_infoline("Test worker thread uploading with Local URL");
3698 ToolkitTestApplication application;
3700 VisualFactory factory = VisualFactory::Get();
3701 DALI_TEST_CHECK(factory);
3703 Property::Map propertyMap;
3704 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3705 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3706 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3708 Visual::Base visual = factory.CreateVisual(propertyMap);
3709 DALI_TEST_CHECK(visual);
3711 DummyControl actor = DummyControl::New();
3712 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3713 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3714 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3716 TestGlAbstraction& gl = application.GetGlAbstraction();
3717 TraceCallStack& textureTrace = gl.GetTextureTrace();
3718 textureTrace.Enable(true);
3720 application.GetScene().Add(actor);
3722 application.SendNotification();
3723 application.Render();
3725 // EventThread with callback
3726 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3728 // Check resource ready comes after
3729 application.SendNotification();
3730 application.Render();
3732 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3733 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3738 int UtcDaliImageVisualLoadFastTrackImageReload(void)
3740 tet_infoline("Test worker thread uploading with Local URL");
3741 ToolkitTestApplication application;
3743 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3745 VisualFactory factory = VisualFactory::Get();
3746 DALI_TEST_CHECK(factory);
3748 Property::Map propertyMap;
3749 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3750 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3751 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3753 Visual::Base visual = factory.CreateVisual(propertyMap);
3754 DALI_TEST_CHECK(visual);
3756 DummyControl actor = DummyControl::New();
3757 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3758 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3759 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3761 TestGlAbstraction& gl = application.GetGlAbstraction();
3762 TraceCallStack& textureTrace = gl.GetTextureTrace();
3763 textureTrace.Enable(true);
3765 application.GetScene().Add(actor);
3767 application.SendNotification();
3768 application.Render();
3770 // EventThread without callback
3771 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3773 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3776 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3777 // How can we make it? Should it be integration-api?
3778 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3779 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), true, TEST_LOCATION);
3781 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3782 application.Render();
3784 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3787 Property::Map attributes;
3788 DevelControl::DoAction(actor, Control::CONTROL_PROPERTY_END_INDEX + 1, DevelImageVisual::Action::RELOAD, attributes);
3790 // EventThread with callback
3791 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3793 // Check resource ready comes after
3794 application.SendNotification();
3795 application.Render();
3797 // Check whether renderer count is 1 or not.
3798 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3799 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3804 int UtcDaliImageVisualLoadFastTrackImagePlanes01(void)
3806 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3807 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3809 ToolkitTestApplication application;
3811 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3813 VisualFactory factory = VisualFactory::Get();
3814 DALI_TEST_CHECK(factory);
3816 Property::Map propertyMap;
3817 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3818 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3819 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3821 Visual::Base visual = factory.CreateVisual(propertyMap);
3822 DALI_TEST_CHECK(visual);
3824 DummyControl actor = DummyControl::New();
3825 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3826 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3827 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3829 TestGlAbstraction& gl = application.GetGlAbstraction();
3830 TraceCallStack& textureTrace = gl.GetTextureTrace();
3831 textureTrace.Enable(true);
3833 application.GetScene().Add(actor);
3835 application.SendNotification();
3836 application.Render();
3838 // EventThread without callback
3839 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3841 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3844 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3845 // How can we make it? Should it be integration-api?
3846 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3847 textureUploadManager.ResourceUpload();
3848 application.Render();
3850 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3851 application.Render();
3853 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3855 application.SendNotification();
3856 application.Render();
3861 int UtcDaliImageVisualLoadFastTrackImagePlanes02(void)
3863 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3864 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3866 ToolkitTestApplication application;
3868 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3870 VisualFactory factory = VisualFactory::Get();
3871 DALI_TEST_CHECK(factory);
3873 Property::Map propertyMap;
3874 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3875 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3876 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3878 Visual::Base visual = factory.CreateVisual(propertyMap);
3879 DALI_TEST_CHECK(visual);
3881 DummyControl actor = DummyControl::New();
3882 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3883 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3884 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3886 TestGlAbstraction& gl = application.GetGlAbstraction();
3887 TraceCallStack& textureTrace = gl.GetTextureTrace();
3888 textureTrace.Enable(true);
3890 application.GetScene().Add(actor);
3892 application.SendNotification();
3893 application.Render();
3895 // EventThread without callback
3896 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3898 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3901 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3902 // How can we make it? Should it be integration-api?
3903 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3904 textureUploadManager.ResourceUpload();
3905 application.Render();
3907 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3908 application.Render();
3910 DALI_TEST_GREATER(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3912 application.SendNotification();
3913 application.Render();