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.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-environment-variable.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <toolkit-timer.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
30 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
33 #include <dali-toolkit/public-api/image-loader/image-url.h>
34 #include <dali-toolkit/public-api/image-loader/image.h>
36 #include "dummy-control.h"
37 #include "test-encoded-image-buffer.h"
38 #include "test-native-image-source.h"
41 using namespace Dali::Toolkit;
43 void dali_image_visual_startup(void)
45 test_return_value = TET_UNDEF;
48 void dali_image_visual_cleanup(void)
50 test_return_value = TET_PASS;
55 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
56 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
57 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
58 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
59 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
60 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
61 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
62 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
63 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
65 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
67 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
68 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
70 bool gResourceReadySignalFired = false;
71 std::vector<int> gReadyIds = {};
72 void ResourceReadySignal(Control control)
74 gResourceReadySignalFired = true;
75 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
82 Actor CreateActorWithImageVisual(const Property::Map& map)
84 VisualFactory factory = VisualFactory::Get();
85 DummyControl actor = DummyControl::New();
86 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
87 Visual::Base visual = factory.CreateVisual(map);
88 DALI_TEST_CHECK(visual);
89 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
90 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
91 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
95 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
97 VisualFactory factory = VisualFactory::Get();
99 Property::Map propertyMap;
100 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
101 propertyMap.Insert(ImageVisual::Property::URL, url);
102 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
103 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
104 propertyMap.Insert(key, value);
106 return factory.CreateVisual(propertyMap);
111 void TestVisualRender(ToolkitTestApplication& application,
113 Visual::Base& visual,
114 std::size_t expectedSamplers = 0,
115 ImageDimensions imageDimensions = ImageDimensions(),
116 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
118 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
119 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
123 // set the image size, for test case, this needs to be set before loading started
124 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
127 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
128 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
130 application.GetScene().Add(actor);
132 application.SendNotification(); // Send messages to update
133 application.Render(); // process update and render
134 application.SendNotification(); // process any signals to event
138 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
141 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
144 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
147 visual.CreatePropertyMap(map);
148 Property::Value* value = map.Find(mixColorIndex);
149 DALI_TEST_CHECK(value);
151 DALI_TEST_CHECK(value->Get(mixColor1));
152 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
154 value = map.Find(Visual::Property::MIX_COLOR);
155 DALI_TEST_CHECK(value);
157 DALI_TEST_CHECK(value->Get(mixColor2));
158 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
160 value = map.Find(Visual::Property::OPACITY);
161 DALI_TEST_CHECK(value);
163 DALI_TEST_CHECK(value->Get(opacity));
164 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
167 int UtcDaliImageVisualPropertyMap(void)
169 ToolkitTestApplication application;
170 tet_infoline("Request image visual with a Property::Map");
172 VisualFactory factory = VisualFactory::Get();
173 DALI_TEST_CHECK(factory);
174 factory.SetPreMultiplyOnLoad(true);
176 Property::Map propertyMap;
177 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
178 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
180 Visual::Base visual = factory.CreateVisual(propertyMap);
181 DALI_TEST_CHECK(visual);
183 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
184 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
186 TestGlAbstraction& gl = application.GetGlAbstraction();
187 TraceCallStack& textureTrace = gl.GetTextureTrace();
188 textureTrace.Enable(true);
190 DummyControl actor = DummyControl::New();
191 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
194 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
195 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
197 application.GetScene().Add(actor);
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
203 application.SendNotification();
204 application.Render();
206 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
207 auto renderer = actor.GetRendererAt(0);
208 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
209 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
210 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
211 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
212 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
213 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
214 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
216 application.GetScene().Remove(actor);
217 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
222 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
224 ToolkitTestApplication application;
225 tet_infoline("Request image visual without pre-multiplied alpha");
227 VisualFactory factory = VisualFactory::Get();
228 DALI_TEST_CHECK(factory);
229 factory.SetPreMultiplyOnLoad(false);
231 Property::Map propertyMap;
232 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
233 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
235 Visual::Base visual = factory.CreateVisual(propertyMap);
236 DALI_TEST_CHECK(visual);
238 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
239 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
241 TestGlAbstraction& gl = application.GetGlAbstraction();
242 TraceCallStack& textureTrace = gl.GetTextureTrace();
243 textureTrace.Enable(true);
245 DummyControl actor = DummyControl::New();
246 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
247 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
249 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
250 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
252 application.GetScene().Add(actor);
253 application.SendNotification();
254 application.Render();
256 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
258 application.SendNotification();
259 application.Render();
261 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
262 auto renderer = actor.GetRendererAt(0);
263 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
264 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
265 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
266 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
268 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
269 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
271 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
273 application.GetScene().Remove(actor);
274 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
279 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
281 ToolkitTestApplication application;
282 tet_infoline("Request image visual with no alpha channel");
284 VisualFactory factory = VisualFactory::Get();
285 DALI_TEST_CHECK(factory);
287 Property::Map propertyMap;
288 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
289 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
291 Visual::Base visual = factory.CreateVisual(propertyMap);
292 DALI_TEST_CHECK(visual);
294 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
295 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
297 TestGlAbstraction& gl = application.GetGlAbstraction();
298 TraceCallStack& textureTrace = gl.GetTextureTrace();
299 textureTrace.Enable(true);
301 DummyControl actor = DummyControl::New();
302 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
303 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
305 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
306 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
308 application.GetScene().Add(actor);
309 application.SendNotification();
310 application.Render();
312 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
318 auto renderer = actor.GetRendererAt(0);
319 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
320 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
321 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
322 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
324 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
325 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
327 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
329 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
330 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
331 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
332 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
333 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
334 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
335 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
336 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
338 textureTrace.Reset();
340 // Make a new visual with the same image
341 Visual::Base newVisual = factory.CreateVisual(propertyMap);
342 DALI_TEST_CHECK(newVisual);
344 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
345 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
347 DummyControl newActor = DummyControl::New();
348 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
349 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
351 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
352 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
354 application.GetScene().Add(newActor);
356 application.SendNotification();
357 application.Render();
359 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
360 auto newRenderer = newActor.GetRendererAt(0);
361 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
362 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
363 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
364 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
366 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
367 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
369 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
370 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
371 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
372 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
373 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
374 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
375 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
376 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
378 application.GetScene().Remove(actor);
379 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
384 int UtcDaliImageVisualRemoteImageLoad(void)
386 ToolkitTestApplication application;
387 tet_infoline("Request remote image visual with a Property::Map");
389 VisualFactory factory = VisualFactory::Get();
390 DALI_TEST_CHECK(factory);
392 Property::Map propertyMap;
393 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
394 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
396 Visual::Base visual = factory.CreateVisual(propertyMap);
397 DALI_TEST_CHECK(visual);
399 TestGlAbstraction& gl = application.GetGlAbstraction();
400 TraceCallStack& textureTrace = gl.GetTextureTrace();
401 textureTrace.Enable(true);
403 DummyControl actor = DummyControl::New();
404 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
405 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
407 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
408 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
410 application.GetScene().Add(actor);
411 application.SendNotification();
413 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
415 application.SendNotification();
416 application.Render();
418 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
419 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
421 application.GetScene().Remove(actor);
422 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
427 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
429 ToolkitTestApplication application;
430 tet_infoline("Use FrameBuffer as url");
434 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
436 DALI_TEST_CHECK(frameBuffer);
437 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
438 std::string url = imageUrl.GetUrl();
440 VisualFactory factory = VisualFactory::Get();
441 DALI_TEST_CHECK(factory);
443 Property::Map propertyMap;
444 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
445 propertyMap.Insert(ImageVisual::Property::URL, url);
447 Visual::Base visual = factory.CreateVisual(propertyMap);
448 DALI_TEST_CHECK(visual);
450 DummyControl actor = DummyControl::New();
451 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
452 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
454 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
456 application.GetScene().Add(actor);
458 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
460 application.SendNotification();
461 application.Render(16);
463 Renderer renderer = actor.GetRendererAt(0);
465 // Check whether preMultipliedAlpha is true.
466 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
467 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
472 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
474 ToolkitTestApplication application;
475 tet_infoline("Use FrameBuffer as url");
479 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
481 DALI_TEST_CHECK(frameBuffer);
483 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
484 frameBuffer.AttachColorTexture(texture);
486 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
487 std::string url = imageUrl.GetUrl();
489 VisualFactory factory = VisualFactory::Get();
490 DALI_TEST_CHECK(factory);
492 Property::Map propertyMap;
493 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
494 propertyMap.Insert(ImageVisual::Property::URL, url);
496 Visual::Base visual = factory.CreateVisual(propertyMap);
497 DALI_TEST_CHECK(visual);
499 DummyControl actor = DummyControl::New();
500 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
501 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
503 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
505 application.GetScene().Add(actor);
507 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
509 application.SendNotification();
510 application.Render(16);
512 Renderer renderer = actor.GetRendererAt(0);
514 // Check whether preMultipliedAlpha is true.
515 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
516 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
521 int UtcDaliImageVisualWithPixelData(void)
523 ToolkitTestApplication application;
524 tet_infoline("Use PixelData as url");
528 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
530 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
531 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
533 DALI_TEST_CHECK(pixelData);
535 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
536 std::string url = imageUrl.GetUrl();
538 VisualFactory factory = VisualFactory::Get();
539 DALI_TEST_CHECK(factory);
541 Property::Map propertyMap;
542 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
543 propertyMap.Insert(ImageVisual::Property::URL, url);
545 Visual::Base visual = factory.CreateVisual(propertyMap);
546 DALI_TEST_CHECK(visual);
548 DummyControl actor = DummyControl::New();
549 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
550 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
552 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
554 application.GetScene().Add(actor);
556 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
558 application.SendNotification();
559 application.Render(16);
561 Renderer renderer = actor.GetRendererAt(0);
563 // Check whether preMultipliedAlpha is false.
564 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
565 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
570 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
572 ToolkitTestApplication application;
573 tet_infoline("Use PixelData as url");
577 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
579 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
580 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
582 DALI_TEST_CHECK(pixelData);
584 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
585 std::string url = imageUrl.GetUrl();
587 VisualFactory factory = VisualFactory::Get();
588 DALI_TEST_CHECK(factory);
590 Property::Map propertyMap;
591 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
592 propertyMap.Insert(ImageVisual::Property::URL, url);
594 Visual::Base visual = factory.CreateVisual(propertyMap);
595 DALI_TEST_CHECK(visual);
597 DummyControl actor = DummyControl::New();
598 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
599 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
601 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
603 application.GetScene().Add(actor);
605 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
607 application.SendNotification();
608 application.Render(16);
610 Renderer renderer = actor.GetRendererAt(0);
612 // Check whether preMultipliedAlpha is true.
613 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
614 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
619 int UtcDaliImageVisualWithNativeImage(void)
621 ToolkitTestApplication application;
622 tet_infoline("Use Native Image as url");
624 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
625 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
626 std::string url = imageUrl.GetUrl();
628 VisualFactory factory = VisualFactory::Get();
629 DALI_TEST_CHECK(factory);
631 Property::Map propertyMap;
632 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
633 propertyMap.Insert(ImageVisual::Property::URL, url);
635 Visual::Base visual = factory.CreateVisual(propertyMap);
636 DALI_TEST_CHECK(visual);
638 DummyControl actor = DummyControl::New();
639 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
640 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
642 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
644 application.GetScene().Add(actor);
646 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
648 application.SendNotification();
649 application.Render(16);
651 Renderer renderer = actor.GetRendererAt(0);
652 Shader shader = renderer.GetShader();
654 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
655 DALI_TEST_CHECK(value.GetType() == Property::MAP);
656 const Property::Map* outMap = value.GetMap();
657 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
659 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
660 size_t pos = fragmentShader.find(fragmentPrefix);
662 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
664 // Check whether preMultipliedAlpha is false.
665 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
666 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
671 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
673 ToolkitTestApplication application;
674 tet_infoline("Use Native Image as url");
676 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
677 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
678 std::string url = imageUrl.GetUrl();
680 VisualFactory factory = VisualFactory::Get();
681 DALI_TEST_CHECK(factory);
683 Property::Map propertyMap;
684 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
685 propertyMap.Insert(ImageVisual::Property::URL, url);
687 Visual::Base visual = factory.CreateVisual(propertyMap);
688 DALI_TEST_CHECK(visual);
690 DummyControl actor = DummyControl::New();
691 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
692 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
694 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
696 application.GetScene().Add(actor);
698 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
700 application.SendNotification();
701 application.Render(16);
703 Renderer renderer = actor.GetRendererAt(0);
704 Shader shader = renderer.GetShader();
706 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
707 DALI_TEST_CHECK(value.GetType() == Property::MAP);
708 const Property::Map* outMap = value.GetMap();
709 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
711 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
712 size_t pos = fragmentShader.find(fragmentPrefix);
714 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
716 // Check whether preMultipliedAlpha is true.
717 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
718 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
723 int UtcDaliImageVisualWithNativeImageCustomShader(void)
725 ToolkitTestApplication application;
726 tet_infoline("Use Native Image as url and Use custom shader");
728 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
729 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
730 std::string url = imageUrl.GetUrl();
732 VisualFactory factory = VisualFactory::Get();
733 DALI_TEST_CHECK(factory);
735 Property::Map propertyMap;
736 Property::Map shaderMap;
737 const std::string customVertexShaderSource = "Foobar";
738 const std::string customFragmentShaderSource = "Foobar";
739 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
740 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
742 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
743 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
744 propertyMap.Insert(ImageVisual::Property::URL, url);
746 Visual::Base visual = factory.CreateVisual(propertyMap);
747 DALI_TEST_CHECK(visual);
749 DummyControl actor = DummyControl::New();
750 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
751 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
753 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
754 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
756 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
758 application.GetScene().Add(actor);
760 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
762 application.SendNotification();
763 application.Render(16);
765 Renderer renderer = actor.GetRendererAt(0);
766 Shader shader = renderer.GetShader();
768 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
769 DALI_TEST_CHECK(value.GetType() == Property::MAP);
770 const Property::Map* outMap = value.GetMap();
771 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
772 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
774 // Compare vertex shader is equal
775 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
777 // Check fragment shader changed
778 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
779 size_t pos = fragmentShaderSource.find(fragmentPrefix);
781 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
783 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
785 // Check whether preMultipliedAlpha is false.
786 // Note : We dont use preMultiplied alpha when app developer using custom shader.
787 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
788 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
793 int UtcDaliImageVisualWithNativeImageRemoved(void)
795 ToolkitTestApplication application;
796 tet_infoline("Use Native Image as url");
798 TestGlAbstraction& gl = application.GetGlAbstraction();
799 TraceCallStack& textureTrace = gl.GetTextureTrace();
800 textureTrace.Enable(true);
802 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
803 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
804 std::string url = imageUrl.GetUrl();
806 VisualFactory factory = VisualFactory::Get();
807 DALI_TEST_CHECK(factory);
809 Property::Map propertyMap;
810 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
811 propertyMap.Insert(ImageVisual::Property::URL, url);
813 Visual::Base visual = factory.CreateVisual(propertyMap);
814 DALI_TEST_CHECK(visual);
816 DummyControl actor = DummyControl::New();
817 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
818 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
820 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
822 application.GetScene().Add(actor);
823 application.SendNotification();
824 application.Render();
826 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
827 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
829 tet_infoline("No delete texture because reference count is not zero");
831 application.GetScene().Remove(actor);
832 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
837 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
839 tet_infoline("Delete texture because reference count is zero");
841 application.SendNotification();
842 application.Render();
844 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
849 int UtcDaliImageVisualWithEncodedImageBuffer(void)
851 ToolkitTestApplication application;
852 tet_infoline("Use Encoded Image Buffer as url");
854 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
855 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
857 VisualFactory factory = VisualFactory::Get();
858 DALI_TEST_CHECK(factory);
860 Property::Map propertyMap;
861 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
862 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
864 Visual::Base visual = factory.CreateVisual(propertyMap);
865 DALI_TEST_CHECK(visual);
867 TestGlAbstraction& gl = application.GetGlAbstraction();
868 TraceCallStack& textureTrace = gl.GetTextureTrace();
869 textureTrace.Enable(true);
871 DummyControl actor = DummyControl::New();
872 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
873 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
875 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
876 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
878 application.GetScene().Add(actor);
879 application.SendNotification();
881 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
883 application.SendNotification();
884 application.Render();
886 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
887 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
889 application.GetScene().Remove(actor);
890 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
895 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
897 ToolkitTestApplication application;
898 tet_infoline("Use Encoded Image Buffer as url");
900 TestGlAbstraction& gl = application.GetGlAbstraction();
901 TraceCallStack& textureTrace = gl.GetTextureTrace();
902 textureTrace.Enable(true);
904 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
905 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
906 std::string url = imageUrl.GetUrl();
908 VisualFactory factory = VisualFactory::Get();
909 DALI_TEST_CHECK(factory);
911 Property::Map propertyMap;
912 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
913 propertyMap.Insert(ImageVisual::Property::URL, url);
915 Visual::Base visual = factory.CreateVisual(propertyMap);
916 DALI_TEST_CHECK(visual);
918 DummyControl actor = DummyControl::New();
919 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
920 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
922 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
924 application.GetScene().Add(actor);
925 application.SendNotification();
927 // Wait for decode buffer and make texture.
928 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
930 application.SendNotification();
931 application.Render();
933 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
934 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
936 tet_infoline("Delete texture because there is no actor to use decoded texture");
938 application.GetScene().Remove(actor);
939 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
940 application.SendNotification();
941 application.Render();
943 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
944 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
949 int UtcDaliImageVisualTextureReuse1(void)
951 ToolkitTestApplication application;
952 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
954 Property::Map propertyMap;
955 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
956 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
957 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
959 TestGlAbstraction& gl = application.GetGlAbstraction();
960 TraceCallStack& textureTrace = gl.GetTextureTrace();
961 textureTrace.Enable(true);
962 TraceCallStack& drawTrace = gl.GetDrawTrace();
963 drawTrace.Enable(true);
965 Actor actor = CreateActorWithImageVisual(propertyMap);
966 application.GetScene().Add(actor);
967 application.SendNotification();
969 // Wait for image to load
970 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
972 application.SendNotification();
973 application.Render();
975 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
976 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
977 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
978 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
979 textureTrace.Reset();
982 Actor actor2 = CreateActorWithImageVisual(propertyMap);
983 application.GetScene().Add(actor2);
985 application.SendNotification(); // Send messages to update
986 application.Render(); // process update and render
987 application.SendNotification(); // process any signals to event
989 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
991 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
992 // backend here, but test graphics backend.
993 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
994 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
996 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
998 application.GetScene().Remove(actor);
999 application.SendNotification();
1000 application.Render();
1002 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1003 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1005 tet_infoline("Test that removing last actor does delete the texture\n");
1007 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1008 application.SendNotification();
1009 application.Render();
1011 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1012 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1017 int UtcDaliImageVisualTextureReuse2(void)
1019 ToolkitTestApplication application;
1020 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");
1022 Property::Map propertyMap;
1023 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1024 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1026 TestGlAbstraction& gl = application.GetGlAbstraction();
1027 TraceCallStack& textureTrace = gl.GetTextureTrace();
1028 textureTrace.Enable(true);
1029 TraceCallStack& drawTrace = gl.GetDrawTrace();
1030 drawTrace.Enable(true);
1032 Actor actor = CreateActorWithImageVisual(propertyMap);
1033 application.GetScene().Add(actor);
1034 application.SendNotification();
1036 // Wait for image to load
1037 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1039 application.SendNotification();
1040 application.Render();
1042 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1043 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1044 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1045 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1046 textureTrace.Reset();
1049 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1050 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1051 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1052 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1053 application.GetScene().Add(actor2);
1055 application.SendNotification();
1057 // Wait for image to load
1058 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1060 application.SendNotification();
1061 application.Render();
1063 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1066 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1067 "renderers are using different textures\n");
1069 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1070 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1071 TraceCallStack::NamedParams tex1;
1072 tex1["texture"] << 1;
1073 TraceCallStack::NamedParams tex2;
1074 tex2["texture"] << 2;
1075 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1076 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1078 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1080 application.GetScene().Remove(actor);
1081 application.SendNotification();
1082 application.Render();
1084 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1085 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1087 tet_infoline("Test that removing last actor deletes it's texture\n");
1089 application.GetScene().Remove(actor2);
1090 application.SendNotification();
1091 application.Render();
1093 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1094 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1099 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1101 ToolkitTestApplication application;
1102 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1104 static std::vector<UniformData> customUniforms =
1106 UniformData("pixelArea", Property::Type::VECTOR4),
1107 UniformData("wrapMode", Property::Type::VECTOR2),
1110 TestGraphicsController& graphics = application.GetGraphicsController();
1111 graphics.AddCustomUniforms(customUniforms);
1113 VisualFactory factory = VisualFactory::Get();
1114 DALI_TEST_CHECK(factory);
1116 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1117 const int width = 34;
1118 const int height = 34;
1119 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1121 Property::Map propertyMap;
1122 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1123 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1124 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1125 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1126 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1127 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1128 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1129 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1130 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1132 Visual::Base visual = factory.CreateVisual(propertyMap);
1133 DALI_TEST_CHECK(visual);
1135 TestGlAbstraction& gl = application.GetGlAbstraction();
1136 TraceCallStack& textureTrace = gl.GetTextureTrace();
1137 textureTrace.Enable(true);
1138 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1139 texParameterTrace.Enable(true);
1141 DummyControl actor = DummyControl::New();
1142 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1143 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1144 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1145 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1146 application.GetScene().Add(actor);
1149 application.SendNotification();
1150 application.Render();
1152 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1154 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1156 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1157 std::stringstream out;
1158 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1159 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1161 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1162 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1164 // test the uniforms which used to handle the wrap mode
1165 Renderer renderer = actor.GetRendererAt(0u);
1166 DALI_TEST_CHECK(renderer);
1168 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1169 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1170 Vector4 pixelAreaUniform;
1171 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1172 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1174 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1175 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1176 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1177 Vector2 wrapModeUniform;
1178 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1179 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1182 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1187 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1189 ToolkitTestApplication application;
1190 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1192 static std::vector<UniformData> customUniforms =
1194 UniformData("pixelArea", Property::Type::VECTOR4),
1197 TestGraphicsController& graphics = application.GetGraphicsController();
1198 graphics.AddCustomUniforms(customUniforms);
1200 VisualFactory factory = VisualFactory::Get();
1201 DALI_TEST_CHECK(factory);
1203 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1204 const int width = 600;
1205 const int height = 600;
1206 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1208 Property::Map propertyMap;
1209 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1210 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1211 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1212 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1213 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1214 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1215 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1216 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1218 Visual::Base visual = factory.CreateVisual(propertyMap);
1219 DALI_TEST_CHECK(visual);
1221 TestGlAbstraction& gl = application.GetGlAbstraction();
1222 TraceCallStack& textureTrace = gl.GetTextureTrace();
1223 textureTrace.Enable(true);
1224 textureTrace.EnableLogging(true);
1225 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1226 texParameterTrace.Enable(true);
1227 texParameterTrace.EnableLogging(true);
1229 DummyControl actor = DummyControl::New();
1230 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1231 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1232 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1233 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1234 application.GetScene().Add(actor);
1237 application.SendNotification();
1238 application.Render();
1239 application.SendNotification();
1241 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1243 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1245 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1246 std::stringstream out;
1247 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1248 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1250 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1251 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1253 // test the uniforms which used to handle the wrap mode
1254 Renderer renderer = actor.GetRendererAt(0u);
1255 DALI_TEST_CHECK(renderer);
1257 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1258 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1259 Vector4 pixelAreaUniform;
1260 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1261 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1263 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1264 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1267 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1272 int UtcDaliImageVisualAnimateMixColor(void)
1274 ToolkitTestApplication application;
1275 tet_infoline("Animate mix color");
1277 static std::vector<UniformData> customUniforms =
1279 UniformData("mixColor", Property::Type::VECTOR3),
1282 TestGraphicsController& graphics = application.GetGraphicsController();
1283 graphics.AddCustomUniforms(customUniforms);
1285 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1287 VisualFactory factory = VisualFactory::Get();
1288 Property::Map propertyMap;
1289 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1290 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1291 propertyMap.Insert("mixColor", Color::BLUE);
1292 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1293 Visual::Base visual = factory.CreateVisual(propertyMap);
1295 DummyControl actor = DummyControl::New(true);
1296 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1297 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1299 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1300 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1301 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1302 application.GetScene().Add(actor);
1304 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1306 Renderer renderer = actor.GetRendererAt(0);
1308 // @todo Should we add API to make this code work again?
1309 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1311 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1312 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1314 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1317 map["target"] = "testVisual";
1318 map["property"] = "mixColor";
1319 map["initialValue"] = Color::MAGENTA;
1320 map["targetValue"] = TARGET_MIX_COLOR;
1321 map["animator"] = Property::Map()
1322 .Add("alphaFunction", "LINEAR")
1323 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1325 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1327 Animation animation = dummyImpl.CreateTransition(transition);
1329 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1332 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1333 glAbstraction.EnableEnableDisableCallTrace(true);
1334 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1335 std::ostringstream blendStr;
1336 blendStr << std::hex << GL_BLEND;
1338 application.SendNotification();
1339 application.Render(0); // Ensure animation starts
1340 application.Render(2000u); // Halfway point
1341 Vector3 testColor(1.0f, 0.0f, 0.5f);
1343 // uColor.a should be actor's alpha * mixColor.a.
1344 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1345 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1347 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1349 glEnableStack.Reset();
1351 application.SendNotification();
1352 application.Render(2000u);
1354 application.SendNotification();
1355 application.Render();
1356 application.SendNotification();
1358 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1359 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1360 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1362 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1364 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1369 int UtcDaliImageVisualAnimateOpacity(void)
1371 ToolkitTestApplication application;
1372 tet_infoline("Animate image visual opacity");
1374 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1376 VisualFactory factory = VisualFactory::Get();
1377 Property::Map propertyMap;
1378 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1379 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1380 propertyMap.Insert("opacity", 0.5f);
1381 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1382 Visual::Base visual = factory.CreateVisual(propertyMap);
1384 DummyControl actor = DummyControl::New(true);
1385 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1386 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1388 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1389 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1390 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1391 application.GetScene().Add(actor);
1393 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1395 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1396 glAbstraction.EnableEnableDisableCallTrace(true);
1397 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1398 std::ostringstream blendStr;
1399 blendStr << std::hex << GL_BLEND;
1401 application.SendNotification();
1402 application.Render();
1404 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1407 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.");
1410 map["target"] = "testVisual";
1411 map["property"] = "opacity";
1412 map["targetValue"] = 1.0f;
1413 map["animator"] = Property::Map()
1414 .Add("alphaFunction", "LINEAR")
1415 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1417 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1418 Animation animation = dummyImpl.CreateTransition(transition);
1421 glEnableStack.Reset();
1423 application.SendNotification();
1424 application.Render(0); // Ensure animation starts
1425 application.Render(2000u); // Halfway point through animation
1426 application.SendNotification(); // Handle any signals
1429 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1430 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1432 application.Render(2001u); // end
1433 application.SendNotification(); // ensure animation finished signal is sent
1435 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1436 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1438 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1439 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1443 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.");
1446 map["target"] = "testVisual";
1447 map["property"] = Visual::Property::OPACITY;
1448 map["targetValue"] = 0.1f;
1449 map["animator"] = Property::Map()
1450 .Add("alphaFunction", "LINEAR")
1451 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1453 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1454 Animation animation = dummyImpl.CreateTransition(transition);
1457 glEnableStack.Reset();
1459 application.SendNotification();
1460 application.Render(0); // Ensure animation starts
1461 application.Render(2000u); // Halfway point
1462 application.SendNotification();
1465 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1466 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1468 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1470 glEnableStack.Reset();
1472 application.Render(2016u); // end
1473 application.SendNotification();
1475 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1476 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1478 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1479 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1485 int UtcDaliImageVisualAnimateOpacity02(void)
1487 ToolkitTestApplication application;
1488 tet_infoline("Animate image visual opacity");
1490 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1492 VisualFactory factory = VisualFactory::Get();
1493 Property::Map propertyMap;
1494 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1495 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1496 propertyMap.Insert("opacity", 0.5f);
1497 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1498 Visual::Base visual = factory.CreateVisual(propertyMap);
1500 DummyControl actor = DummyControl::New(true);
1501 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1502 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1504 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1505 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1506 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1508 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1510 Property::Array array;
1513 map["target"] = "testVisual";
1514 map["property"] = "opacity";
1515 map["initialValue"] = 0.0f;
1516 map["targetValue"] = 1.0f;
1517 map["animator"] = Property::Map()
1518 .Add("alphaFunction", "LINEAR")
1519 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1522 map2["target"] = "testVisual";
1523 map2["property"] = "size";
1524 map2["targetValue"] = Vector2(1.0f, 1.0f);
1526 array.Add(map).Add(map2);
1528 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1529 Animation animation = dummyImpl.CreateTransition(transition);
1531 application.GetScene().Add(actor);
1532 application.SendNotification();
1533 application.Render(0); // Ensure animation starts
1535 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1537 Renderer renderer = actor.GetRendererAt(0);
1538 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1539 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1541 animation = dummyImpl.CreateTransition(transition);
1544 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1545 glAbstraction.EnableEnableDisableCallTrace(true);
1546 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1547 std::ostringstream blendStr;
1548 blendStr << std::hex << GL_BLEND;
1550 application.SendNotification();
1551 application.Render(0); // Ensure animation starts
1552 application.Render(2000u); // Halfway point through animation
1553 application.SendNotification(); // Handle any signals
1555 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1558 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1559 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1561 glEnableStack.Reset();
1563 application.Render(2001u); // end
1564 application.SendNotification(); // ensure animation finished signal is sent
1566 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1567 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1569 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1574 int UtcDaliImageVisualAnimatePixelArea(void)
1576 ToolkitTestApplication application;
1577 tet_infoline("ImageVisual animate pixel area");
1579 static std::vector<UniformData> customUniforms =
1581 UniformData("pixelArea", Property::Type::VECTOR4),
1584 TestGraphicsController& graphics = application.GetGraphicsController();
1585 graphics.AddCustomUniforms(customUniforms);
1587 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1589 VisualFactory factory = VisualFactory::Get();
1590 Property::Map propertyMap;
1591 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1592 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1593 propertyMap.Insert("mixColor", Color::BLUE);
1594 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1595 Visual::Base visual = factory.CreateVisual(propertyMap);
1597 DummyControl actor = DummyControl::New(true);
1598 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1599 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1601 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1602 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1603 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1604 application.GetScene().Add(actor);
1606 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1608 Renderer renderer = actor.GetRendererAt(0);
1609 // @todo Implement this feature?
1610 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1611 //tet_infoline("Test that the renderer has the mixColor property");
1612 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1614 // TransitionData only takes string keys
1616 map["target"] = "testVisual";
1617 map["property"] = "pixelArea";
1618 map["initialValue"] = Vector4(0, 0, 0, 1);
1619 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1620 map["animator"] = Property::Map()
1621 .Add("alphaFunction", "LINEAR")
1622 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1624 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1626 Animation animation = dummyImpl.CreateTransition(transition);
1627 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1630 application.SendNotification();
1631 application.Render(0); // Ensure animation starts
1632 application.Render(2000u); // Halfway point
1634 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1636 application.Render(2000u); // End of animation
1638 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1643 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1645 ToolkitTestApplication application;
1646 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1648 Property::Map propertyMap;
1649 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1650 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1652 TestGlAbstraction& gl = application.GetGlAbstraction();
1653 TraceCallStack& textureTrace = gl.GetTextureTrace();
1654 textureTrace.Enable(true);
1655 TraceCallStack& drawTrace = gl.GetDrawTrace();
1656 drawTrace.Enable(true);
1658 Actor actor = CreateActorWithImageVisual(propertyMap);
1659 application.GetScene().Add(actor);
1660 application.SendNotification();
1662 application.GetScene().Remove(actor);
1663 application.SendNotification();
1665 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1666 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1667 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1668 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1673 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1675 ToolkitTestApplication application;
1676 tet_infoline("Load image asynchronously, cancel loading, then load again");
1678 VisualFactory factory = VisualFactory::Get();
1679 DALI_TEST_CHECK(factory);
1681 Property::Map propertyMap;
1682 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1683 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1685 Visual::Base visual = factory.CreateVisual(propertyMap);
1686 DALI_TEST_CHECK(visual);
1688 TestGlAbstraction& gl = application.GetGlAbstraction();
1689 TraceCallStack& textureTrace = gl.GetTextureTrace();
1690 textureTrace.Enable(true);
1691 TraceCallStack& drawTrace = gl.GetDrawTrace();
1692 drawTrace.Enable(true);
1694 DummyControl actor = DummyControl::New();
1695 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1696 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1698 application.GetScene().Add(actor);
1701 application.GetScene().Remove(actor);
1703 application.GetScene().Add(actor);
1705 // Create another visual with the same image
1706 visual = factory.CreateVisual(propertyMap);
1707 DALI_TEST_CHECK(visual);
1709 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1711 application.SendNotification();
1712 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1714 application.SendNotification();
1715 application.Render();
1717 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1718 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1719 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1720 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1725 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1727 ToolkitTestApplication application;
1728 tet_infoline("Request image visual with invalid images - should draw broken.png");
1730 VisualFactory factory = VisualFactory::Get();
1731 DALI_TEST_CHECK(factory);
1733 Property::Map propertyMap;
1734 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1735 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1737 Visual::Base visual = factory.CreateVisual(propertyMap);
1738 DALI_TEST_CHECK(visual);
1740 TestGlAbstraction& gl = application.GetGlAbstraction();
1741 TraceCallStack& textureTrace = gl.GetTextureTrace();
1742 textureTrace.Enable(true);
1744 DummyControl actor = DummyControl::New();
1745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1748 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1749 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1751 application.GetScene().Add(actor);
1753 application.SendNotification();
1754 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1756 application.SendNotification();
1757 application.Render();
1759 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1760 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1762 application.GetScene().Remove(actor);
1763 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1768 int UtcDaliImageVisualSetInvalidSyncImage(void)
1770 ToolkitTestApplication application;
1771 tet_infoline("Request image visual with invalid images - should draw broken.png");
1773 VisualFactory factory = VisualFactory::Get();
1774 DALI_TEST_CHECK(factory);
1776 Property::Map propertyMap;
1777 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1778 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1779 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1781 Visual::Base visual = factory.CreateVisual(propertyMap);
1782 DALI_TEST_CHECK(visual);
1784 TestGlAbstraction& gl = application.GetGlAbstraction();
1785 TraceCallStack& textureTrace = gl.GetTextureTrace();
1786 textureTrace.Enable(true);
1788 DummyControl actor = DummyControl::New();
1789 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1790 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1792 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1793 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1795 application.GetScene().Add(actor);
1797 application.SendNotification();
1798 application.Render();
1800 // Check resource status
1801 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1802 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1804 // The broken image should be shown.
1805 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1806 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1808 application.GetScene().Remove(actor);
1809 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1814 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1816 ToolkitTestApplication application;
1817 tet_infoline("Request image visual with invalid images - should draw broken.png");
1819 VisualFactory factory = VisualFactory::Get();
1820 DALI_TEST_CHECK(factory);
1822 // Local invalid file, asynchronous loading
1823 Property::Map propertyMap;
1824 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1825 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1827 Visual::Base visual = factory.CreateVisual(propertyMap);
1828 DALI_TEST_CHECK(visual);
1830 TestGlAbstraction& gl = application.GetGlAbstraction();
1831 TraceCallStack& textureTrace = gl.GetTextureTrace();
1832 textureTrace.Enable(true);
1834 DummyControl actor = DummyControl::New();
1835 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1836 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1838 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1839 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1841 application.GetScene().Add(actor);
1843 application.SendNotification();
1844 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1846 application.SendNotification();
1847 application.Render();
1849 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1850 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1852 application.GetScene().Remove(actor);
1853 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1858 int UtcDaliImageVisualAlphaMask01(void)
1860 ToolkitTestApplication application;
1861 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
1863 VisualFactory factory = VisualFactory::Get();
1864 DALI_TEST_CHECK(factory);
1866 Property::Map propertyMap;
1867 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1868 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1869 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1871 Visual::Base visual = factory.CreateVisual(propertyMap);
1872 DALI_TEST_CHECK(visual);
1874 Property::Map testMap;
1875 visual.CreatePropertyMap(testMap);
1876 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1878 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1879 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1881 TestGlAbstraction& gl = application.GetGlAbstraction();
1882 TraceCallStack& textureTrace = gl.GetTextureTrace();
1883 textureTrace.Enable(true);
1885 DummyControl actor = DummyControl::New();
1886 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1887 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1889 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1890 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1891 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1893 application.GetScene().Add(actor);
1894 application.SendNotification();
1895 application.Render();
1897 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1899 application.SendNotification();
1900 application.Render();
1902 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1903 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1904 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1906 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1907 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1912 int UtcDaliImageVisualAlphaMask02(void)
1914 ToolkitTestApplication application;
1915 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
1917 VisualFactory factory = VisualFactory::Get();
1918 DALI_TEST_CHECK(factory);
1920 Property::Map propertyMap;
1921 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1922 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1923 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1924 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1926 Visual::Base visual = factory.CreateVisual(propertyMap);
1927 DALI_TEST_CHECK(visual);
1929 Property::Map testMap;
1930 visual.CreatePropertyMap(testMap);
1931 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1932 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
1934 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1935 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1937 TestGlAbstraction& gl = application.GetGlAbstraction();
1938 TraceCallStack& textureTrace = gl.GetTextureTrace();
1939 textureTrace.Enable(true);
1941 DummyControl actor = DummyControl::New();
1942 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1943 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1945 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1946 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1947 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1949 application.GetScene().Add(actor);
1950 application.SendNotification();
1951 application.Render();
1953 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1955 application.SendNotification();
1956 application.Render();
1958 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1959 Renderer renderer = actor.GetRendererAt(0u);
1960 TextureSet textures = renderer.GetTextures();
1961 DALI_TEST_CHECK(textures);
1962 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
1964 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1965 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
1967 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
1968 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1973 int UtcDaliImageVisualAlphaMask03(void)
1975 ToolkitTestApplication application;
1976 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
1978 VisualFactory factory = VisualFactory::Get();
1979 DALI_TEST_CHECK(factory);
1981 Property::Map propertyMap;
1982 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1983 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1984 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
1985 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
1987 Visual::Base visual = factory.CreateVisual(propertyMap);
1988 DALI_TEST_CHECK(visual);
1990 Property::Map testMap;
1991 visual.CreatePropertyMap(testMap);
1993 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1994 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1996 TestGlAbstraction& gl = application.GetGlAbstraction();
1997 TraceCallStack& textureTrace = gl.GetTextureTrace();
1998 textureTrace.Enable(true);
2000 DummyControl actor = DummyControl::New();
2001 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2002 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2004 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2005 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2006 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2008 application.GetScene().Add(actor);
2009 application.SendNotification();
2010 application.Render();
2012 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2014 application.SendNotification();
2015 application.Render();
2017 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2018 Renderer renderer = actor.GetRendererAt(0u);
2019 TextureSet textures = renderer.GetTextures();
2020 DALI_TEST_CHECK(textures);
2021 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2023 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2024 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2026 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2027 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2032 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2034 ToolkitTestApplication application;
2035 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2037 VisualFactory factory = VisualFactory::Get();
2038 DALI_TEST_CHECK(factory);
2040 Property::Map propertyMap;
2041 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2042 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2043 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2044 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2046 Visual::Base visual = factory.CreateVisual(propertyMap);
2047 DALI_TEST_CHECK(visual);
2049 Property::Map testMap;
2050 visual.CreatePropertyMap(testMap);
2051 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2053 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2054 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2056 TestGlAbstraction& gl = application.GetGlAbstraction();
2057 TraceCallStack& textureTrace = gl.GetTextureTrace();
2058 textureTrace.Enable(true);
2060 DummyControl actor = DummyControl::New();
2061 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2062 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2064 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2065 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2066 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2068 application.GetScene().Add(actor);
2070 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2072 application.SendNotification();
2073 application.Render();
2075 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2076 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2077 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2079 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2080 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2085 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2087 ToolkitTestApplication application;
2088 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2090 VisualFactory factory = VisualFactory::Get();
2091 DALI_TEST_CHECK(factory);
2093 Property::Map propertyMap;
2094 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2095 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2096 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2097 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2098 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2100 Visual::Base visual = factory.CreateVisual(propertyMap);
2101 DALI_TEST_CHECK(visual);
2103 Property::Map testMap;
2104 visual.CreatePropertyMap(testMap);
2105 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2107 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2108 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2110 TestGlAbstraction& gl = application.GetGlAbstraction();
2111 TraceCallStack& textureTrace = gl.GetTextureTrace();
2112 textureTrace.Enable(true);
2114 DummyControl actor = DummyControl::New();
2115 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2116 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2118 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2119 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2120 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2122 application.GetScene().Add(actor);
2124 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2126 application.SendNotification();
2127 application.Render();
2129 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2130 Renderer renderer = actor.GetRendererAt(0u);
2131 TextureSet textures = renderer.GetTextures();
2132 DALI_TEST_CHECK(textures);
2133 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2135 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2136 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2138 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2139 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2144 int UtcDaliImageVisualRemoteAlphaMask(void)
2146 ToolkitTestApplication application;
2147 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2149 VisualFactory factory = VisualFactory::Get();
2150 DALI_TEST_CHECK(factory);
2152 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2154 Property::Map propertyMap;
2155 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2156 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2157 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2159 Visual::Base visual = factory.CreateVisual(propertyMap);
2160 DALI_TEST_CHECK(visual);
2162 Property::Map testMap;
2163 visual.CreatePropertyMap(testMap);
2165 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2167 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2168 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2170 TestGlAbstraction& gl = application.GetGlAbstraction();
2171 TraceCallStack& textureTrace = gl.GetTextureTrace();
2172 textureTrace.Enable(true);
2174 DummyControl actor = DummyControl::New();
2175 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2176 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2178 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2180 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2181 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2183 application.GetScene().Add(actor);
2184 application.SendNotification();
2185 application.Render();
2187 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2189 application.SendNotification();
2190 application.Render();
2192 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2193 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2194 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2199 int UtcDaliImageVisualAlphaMaskCrop(void)
2201 ToolkitTestApplication application;
2202 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2204 VisualFactory factory = VisualFactory::Get();
2205 DALI_TEST_CHECK(factory);
2207 Property::Map propertyMap;
2208 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2209 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2210 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2211 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2212 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2214 Visual::Base visual = factory.CreateVisual(propertyMap);
2215 DALI_TEST_CHECK(visual);
2217 Property::Map testMap;
2218 visual.CreatePropertyMap(testMap);
2219 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2220 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2221 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2223 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2224 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2226 TestGlAbstraction& gl = application.GetGlAbstraction();
2227 TraceCallStack& textureTrace = gl.GetTextureTrace();
2228 textureTrace.Enable(true);
2230 DummyControl actor = DummyControl::New();
2231 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2232 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2234 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2235 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2236 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2238 application.GetScene().Add(actor);
2239 application.SendNotification();
2240 application.Render();
2242 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2244 application.SendNotification();
2245 application.Render();
2248 visual.GetNaturalSize(size);
2250 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2251 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2252 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2253 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2258 int UtcDaliImageVisualReleasePolicy01(void)
2260 ToolkitTestApplication application;
2261 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2263 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2264 DALI_TEST_CHECK(imageVisual);
2266 // Set up debug trace
2267 TestGlAbstraction& gl = application.GetGlAbstraction();
2268 TraceCallStack& textureTrace = gl.GetTextureTrace();
2269 textureTrace.Enable(true);
2271 tet_infoline("Register visual with control and ensure it has the only handle");
2272 DummyControl actor = DummyControl::New(true);
2273 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2274 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2275 imageVisual.Reset();
2277 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2279 application.SendNotification();
2280 application.Render(0);
2281 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2282 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2284 application.GetScene().Add(actor);
2286 // Wait for image to load
2287 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2289 application.SendNotification();
2290 application.Render(0);
2291 // Test renderer and texture created
2292 tet_infoline("Confirm texture created");
2293 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2294 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2296 tet_infoline("Disable visual causing the texture to be deleted");
2297 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2299 application.SendNotification();
2300 application.Render(0);
2301 // Test renderer and textures removed.
2302 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2303 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2308 int UtcDaliImageVisualReleasePolicy02(void)
2310 ToolkitTestApplication application;
2311 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2313 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2314 DALI_TEST_CHECK(imageVisual);
2316 // Setup debug trace
2317 TestGlAbstraction& gl = application.GetGlAbstraction();
2318 TraceCallStack& textureTrace = gl.GetTextureTrace();
2319 textureTrace.Enable(true);
2321 tet_infoline("Register visual with control and ensure it has the only handle");
2322 DummyControl actor = DummyControl::New(true);
2323 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2324 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2325 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2327 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2329 application.SendNotification();
2330 application.Render(0);
2331 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2332 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2334 application.GetScene().Add(actor);
2336 // Wait for image to load
2337 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2339 application.SendNotification();
2340 application.Render(0);
2341 // Test renderer and texture created
2342 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2343 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2345 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2346 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2347 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2348 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2349 application.SendNotification();
2350 application.Render();
2352 // Test texture removed after visual destroyed.
2353 tet_infoline("Ensure texture is deleted after visual destroyed");
2354 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2359 int UtcDaliImageVisualReleasePolicy03(void)
2361 ToolkitTestApplication application;
2362 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2364 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2365 DALI_TEST_CHECK(imageVisual);
2367 TestGlAbstraction& gl = application.GetGlAbstraction();
2368 TraceCallStack& textureTrace = gl.GetTextureTrace();
2369 textureTrace.Enable(true);
2371 tet_infoline("Register visual with control and ensure it has the only handle");
2372 DummyControl actor = DummyControl::New(true);
2373 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2374 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2375 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2377 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2379 application.SendNotification();
2380 application.Render(0);
2381 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2382 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2384 application.GetScene().Add(actor);
2386 // Wait for image to load
2387 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2389 application.SendNotification();
2390 application.Render(0);
2391 // Test renderer and texture created
2392 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2393 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2395 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2396 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2397 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2398 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2399 application.SendNotification();
2400 application.Render();
2402 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2403 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2408 int UtcDaliImageVisualReleasePolicy04(void)
2410 ToolkitTestApplication application;
2411 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2413 tet_infoline("Create first visual with Never release policy");
2414 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2416 tet_infoline("Create second visual with Destroyed release policy");
2417 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2419 // Set up trace debug
2420 TestGlAbstraction& gl = application.GetGlAbstraction();
2421 TraceCallStack& textureTrace = gl.GetTextureTrace();
2422 textureTrace.Enable(true);
2424 tet_infoline("Register visuals with control and ensure it has the only handles");
2425 DummyControl actor = DummyControl::New(true);
2426 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2427 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2428 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2429 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2430 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2432 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2434 // Test initially zero renderers
2435 application.SendNotification();
2436 application.Render(0);
2437 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2438 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2440 application.GetScene().Add(actor);
2442 // Wait for image to load
2443 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2445 application.SendNotification();
2446 application.Render(0);
2447 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2448 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2449 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2451 // Test renderer removed when visual destroyed
2452 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2453 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2454 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2455 application.SendNotification();
2456 application.Render();
2458 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2459 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2461 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2462 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2463 application.SendNotification();
2464 application.Render();
2466 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2467 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2468 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2473 int UtcDaliImageVisualReleasePolicy05(void)
2475 ToolkitTestApplication application;
2476 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2478 VisualFactory factory = VisualFactory::Get();
2480 Property::Map propertyMapNeverReleasePolicy;
2481 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2482 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2483 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2484 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2485 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2487 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2489 Property::Map resultMap;
2490 imageVisualNever.CreatePropertyMap(resultMap);
2491 DALI_TEST_CHECK(!resultMap.Empty());
2493 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2498 int UtcDaliImageVisualReleasePolicy06(void)
2500 ToolkitTestApplication application;
2501 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2503 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2504 DALI_TEST_CHECK(imageVisual);
2506 TestGlAbstraction& gl = application.GetGlAbstraction();
2507 TraceCallStack& textureTrace = gl.GetTextureTrace();
2508 textureTrace.Enable(true);
2510 tet_infoline("Register visual with control and ensure it has the only handle");
2511 DummyControl actor = DummyControl::New(true);
2512 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2513 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2514 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2516 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2518 application.SendNotification();
2519 application.Render(0);
2520 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2521 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2523 application.GetScene().Add(actor);
2525 // Wait for image to load
2526 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2528 application.SendNotification();
2529 application.Render(0);
2530 // Test renderer and texture created
2531 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2532 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2533 textureTrace.Reset();
2535 tet_infoline("Disable Visual and check texture not affected");
2536 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2537 application.SendNotification();
2538 application.Render(0);
2539 tet_infoline("Check renderer is destroyed when visual off stage");
2540 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2541 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2542 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2543 textureTrace.Reset();
2545 tet_infoline("Re-enable Visual and check texture not affected");
2546 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2547 application.SendNotification();
2548 application.Render(0);
2549 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2550 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2551 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2552 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2557 int UtcDaliImageVisualReleasePolicy07(void)
2559 ToolkitTestApplication application;
2560 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2562 tet_infoline("Create first visual with DESTROYED release policy");
2563 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2565 tet_infoline("Create second visual with DETACHED release policy");
2566 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2568 // Set up trace debug
2569 TestGlAbstraction& gl = application.GetGlAbstraction();
2570 TraceCallStack& textureTrace = gl.GetTextureTrace();
2571 textureTrace.Enable(true);
2573 tet_infoline("Register visuals with control and ensure it has the only handles");
2574 DummyControl actor = DummyControl::New(true);
2575 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2576 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2577 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2578 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2579 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2581 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2583 // Test initially zero renderers
2584 application.SendNotification();
2585 application.Render(0);
2586 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2587 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2589 application.GetScene().Add(actor);
2591 // Wait for image to load
2592 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2594 application.SendNotification();
2595 application.Render(0);
2596 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2597 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2598 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2600 // Test renderer removed when visual destroyed
2601 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2602 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2603 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2604 application.SendNotification();
2605 application.Render();
2607 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2608 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2610 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2611 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2612 application.SendNotification();
2613 application.Render();
2615 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2616 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2621 int UtcDaliImageVisualReleasePolicy08(void)
2623 ToolkitTestApplication application;
2624 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2626 tet_infoline("Create first visual with DESTROYED release policy");
2627 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2629 // Set up trace debug
2630 TestGlAbstraction& gl = application.GetGlAbstraction();
2631 TraceCallStack& textureTrace = gl.GetTextureTrace();
2632 textureTrace.Enable(true);
2634 tet_infoline("Register visuals with control and ensure it has the only handles");
2635 DummyControl actor = DummyControl::New(true);
2636 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2637 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2638 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2640 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2642 // Test initially zero renderers
2643 application.SendNotification();
2644 application.Render(0);
2645 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2646 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2647 textureTrace.Reset();
2649 application.GetScene().Add(actor);
2651 // Wait for image to load
2652 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2654 application.SendNotification();
2655 application.Render(0);
2656 tet_infoline("Ensure a texture is created");
2657 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2658 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2659 textureTrace.Reset();
2661 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2663 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2665 // 2.Remove actor from stage. In this case, renderer also is deleted.
2666 tet_infoline("Remove actor from stage");
2667 application.GetScene().Remove(actor);
2668 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2669 application.SendNotification();
2670 application.Render();
2672 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2673 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2674 textureTrace.Reset();
2676 // 3.Add actor in stage. In this case, renderer is created.
2677 tet_infoline("Add actor in stage");
2678 application.GetScene().Add(actor);
2679 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2680 application.SendNotification();
2681 application.Render();
2682 tet_infoline("Ensure a texture is not created again");
2683 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2684 textureTrace.Reset();
2686 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2687 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2688 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2689 DALI_TEST_CHECK(textureBefore == textureAfter);
2690 textureBefore.Reset();
2691 textureAfter.Reset();
2693 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2694 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2695 application.SendNotification();
2696 application.Render();
2697 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2702 int UtcDaliImageVisualReleasePolicy09(void)
2704 ToolkitTestApplication application;
2705 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2707 Property::Map propertyMapNPatchReleasePolicy;
2708 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2709 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2710 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2711 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2712 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2714 VisualFactory factory = VisualFactory::Get();
2715 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2716 DALI_TEST_CHECK(imageVisual);
2718 // Setup debug trace
2719 TestGlAbstraction& gl = application.GetGlAbstraction();
2720 TraceCallStack& textureTrace = gl.GetTextureTrace();
2721 textureTrace.Enable(true);
2723 tet_infoline("Register visual with control and ensure it has the only handle");
2724 DummyControl actor = DummyControl::New(true);
2725 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2726 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2727 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2729 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2731 application.SendNotification();
2732 application.Render(0);
2733 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2734 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2736 application.GetScene().Add(actor);
2738 // Wait for image to load
2739 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2741 application.SendNotification();
2742 application.Render(0);
2743 // Test renderer and texture created
2744 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2745 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2747 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2748 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2749 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2750 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2751 application.SendNotification();
2752 application.Render();
2754 // Test texture removed after visual destroyed.
2755 tet_infoline("Ensure texture is deleted after visual destroyed");
2756 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2761 int UtcDaliImageVisualLoadPolicy01(void)
2763 ToolkitTestApplication application;
2764 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2766 // Set up trace debug
2767 TestGlAbstraction& gl = application.GetGlAbstraction();
2768 TraceCallStack& textureTrace = gl.GetTextureTrace();
2769 textureTrace.Enable(true);
2771 tet_infoline("Create visual with IMMEDIATE load policy");
2772 VisualFactory factory = VisualFactory::Get();
2774 Property::Map propertyMap;
2775 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2776 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2777 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2778 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2779 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2781 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2783 Property::Map resultMap;
2784 imageVisual.CreatePropertyMap(resultMap);
2785 DALI_TEST_CHECK(!resultMap.Empty());
2786 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2788 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2790 // Ensure texture has been uploaded
2791 application.SendNotification();
2792 application.Render();
2794 tet_infoline("Ensure texture loading starts after visual created");
2795 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2796 textureTrace.Reset();
2798 tet_infoline("Register visuals with control and ensure it has the only handles");
2799 DummyControl actor = DummyControl::New(true);
2800 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2801 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2802 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2804 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2805 application.GetScene().Add(actor);
2806 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2807 const unsigned int TIME_OUT_3_SECONDS = 3;
2808 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2810 application.SendNotification();
2811 application.Render();
2813 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2814 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2816 // Ensure texture is deleted when no longer needed (ref count was correct )
2817 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2819 application.SendNotification();
2820 application.Render();
2822 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2823 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2828 int UtcDaliImageVisualLoadPolicy02(void)
2830 ToolkitTestApplication application;
2831 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2833 // Set up trace debug
2834 TestGlAbstraction& gl = application.GetGlAbstraction();
2835 TraceCallStack& textureTrace = gl.GetTextureTrace();
2836 textureTrace.Enable(true);
2838 tet_infoline("Create visual with IMMEDIATE load policy");
2839 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2841 const unsigned int TIME_OUT_3_SECONDS = 3;
2842 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2844 // Act on meeage queue even although nothing expected to load
2845 application.SendNotification();
2846 application.Render();
2848 tet_infoline("Ensure texture is not generated yet");
2849 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2850 textureTrace.Reset();
2852 tet_infoline("Register visuals with control and ensure it has the only handles");
2853 DummyControl actor = DummyControl::New(true);
2854 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2855 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2856 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2858 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2859 application.GetScene().Add(actor);
2860 tet_infoline("Allow image time to load");
2861 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2863 application.SendNotification();
2864 application.Render();
2866 tet_infoline("Ensure texture generated and renderer created");
2867 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2868 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2870 // Ensure texture is delete when no longer needed
2871 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2873 application.SendNotification();
2874 application.Render();
2876 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2877 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2882 int UtcDaliImageVisualLoadPolicy03(void)
2884 ToolkitTestApplication application;
2885 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2887 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2889 // Set up trace debug
2890 TestGlAbstraction& gl = application.GetGlAbstraction();
2891 TraceCallStack& textureTrace = gl.GetTextureTrace();
2892 textureTrace.Enable(true);
2894 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
2895 DummyControl actor = DummyControl::New(true);
2896 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2897 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2898 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2900 tet_infoline("Create visual with IMMEDIATE load policy");
2901 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2903 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
2904 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2905 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2907 tet_infoline("Allow image time to load resource");
2908 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2909 application.SendNotification();
2910 application.Render();
2912 // Ensure texture has been uploaded
2913 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2914 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2919 int UtcDaliImageVisualLoadPolicy04(void)
2921 ToolkitTestApplication application;
2922 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2923 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2925 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
2927 // Set up trace debug
2928 TestGlAbstraction& gl = application.GetGlAbstraction();
2929 TraceCallStack& textureTrace = gl.GetTextureTrace();
2930 textureTrace.Enable(true);
2932 tet_infoline("Create a control and connect to resource ready signal");
2933 DummyControl actor = DummyControl::New(true);
2934 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2935 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2936 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2938 tet_infoline("Create visual with IMMEDIATE load policy");
2939 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2941 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
2942 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
2943 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2945 tet_infoline("Allow image time to load");
2946 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2947 application.SendNotification();
2948 application.Render();
2950 tet_infoline("Testing texture is loaded and resource ready signal fired");
2951 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2952 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2954 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
2956 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2957 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
2958 DummyControl actor2 = DummyControl::New(true);
2959 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2960 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
2962 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
2963 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
2964 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2965 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2966 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
2967 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2972 int UtcDaliImageVisualLoadPolicy05(void)
2974 ToolkitTestApplication application;
2975 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2976 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
2977 // Set up trace debug
2978 TestGlAbstraction& gl = application.GetGlAbstraction();
2979 TraceCallStack& textureTrace = gl.GetTextureTrace();
2980 textureTrace.Enable(true);
2982 tet_infoline("Create a control and connect to resource ready signal");
2983 DummyControl actor = DummyControl::New(true);
2984 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
2985 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2986 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2987 application.GetScene().Add(actor);
2989 tet_infoline("Create visual with ATTACHED load policy");
2990 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2992 tet_infoline("Registering visual allows control to get a signal once loaded");
2993 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2994 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2996 tet_infoline("Allow image time to load");
2997 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2998 application.SendNotification();
2999 application.Render();
3001 tet_infoline("Testing texture is loaded and resource ready signal fired");
3002 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3003 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3005 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3007 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3008 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3009 DummyControl actor2 = DummyControl::New(true);
3010 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3011 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3013 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3014 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3015 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3016 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3017 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3018 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3023 int UtcDaliImageVisualOrientationCorrection(void)
3025 ToolkitTestApplication application;
3026 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3028 VisualFactory factory = VisualFactory::Get();
3029 tet_infoline("Create visual with Orientation correction set OFF");
3030 Property::Map propertyMap;
3031 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3032 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3033 propertyMap.Insert("orientationCorrection", false);
3034 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3036 tet_infoline("Create control for visual, need to loaded it");
3037 DummyControl actor = DummyControl::New(true);
3038 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3039 application.GetScene().Add(actor);
3041 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3042 // Wait for image to load
3043 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3045 Vector2 originalImageSize;
3046 tet_infoline("Get size of original visual to compare later with rotated image");
3047 imageVisual.GetNaturalSize(originalImageSize);
3048 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3049 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3050 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3051 application.SendNotification();
3052 application.Render();
3054 tet_infoline("Create visual with Orientation correction set ON ");
3055 propertyMap.Clear();
3056 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3057 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3058 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3059 imageVisual = factory.CreateVisual(propertyMap);
3061 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3062 // Wait for image to load
3063 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3065 Vector2 rotatedImageSize;
3066 imageVisual.GetNaturalSize(rotatedImageSize);
3067 tet_infoline("Confirm that visual has rotated");
3068 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3069 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3071 Property::Map resultMap;
3072 imageVisual.CreatePropertyMap(resultMap);
3074 // check the Property::ORIENTATION_CORRECTION value from the returned map
3075 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3076 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3081 int UtcDaliImageVisualCustomShader(void)
3083 ToolkitTestApplication application;
3084 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3086 VisualFactory factory = VisualFactory::Get();
3087 Property::Map properties;
3088 Property::Map shader;
3089 const std::string vertexShader = "Foobar";
3090 const std::string fragmentShader = "Foobar";
3091 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3092 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3094 properties[Visual::Property::TYPE] = Visual::IMAGE;
3095 properties[Visual::Property::SHADER] = shader;
3096 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3098 Visual::Base visual = factory.CreateVisual(properties);
3100 // trigger creation through setting on stage
3101 DummyControl dummy = DummyControl::New(true);
3102 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3103 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3105 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3106 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3107 application.GetScene().Add(dummy);
3109 application.SendNotification();
3110 application.Render();
3112 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3114 Renderer renderer = dummy.GetRendererAt(0);
3115 Shader shader2 = renderer.GetShader();
3116 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3117 Property::Map* map = value.GetMap();
3118 DALI_TEST_CHECK(map);
3120 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3121 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3123 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3124 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3128 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3129 properties[Visual::Property::SHADER] = shader;
3131 Visual::Base visual1 = factory.CreateVisual(properties);
3133 // trigger creation through setting on stage
3134 DummyControl dummy1 = DummyControl::New(true);
3135 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3136 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3137 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3138 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3139 application.GetScene().Add(dummy1);
3141 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3142 glAbstraction.EnableEnableDisableCallTrace(true);
3144 application.SendNotification();
3145 application.Render();
3147 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3148 std::ostringstream blendStr;
3149 blendStr << std::hex << GL_BLEND;
3150 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3155 void ResourceReadyLoadNext(Control control)
3157 static int callNumber = 0;
3159 gResourceReadySignalFired = true;
3160 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3164 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3166 tet_infoline("Create visual with loaded image from within the signal handler");
3167 VisualFactory factory = VisualFactory::Get();
3168 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3170 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3171 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3176 tet_infoline("3rd signal called");
3177 DALI_TEST_CHECK(true);
3181 int UtcDaliImageVisualLoadReady01(void)
3183 ToolkitTestApplication application;
3184 tet_infoline("UtcDaliImageVisualLoadReady01");
3185 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3186 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3187 tet_infoline("Should get a ready signal for all three visuals");
3191 tet_infoline("Create a control and connect to resource ready signal");
3192 DummyControl actor = DummyControl::New(true);
3193 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3194 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3195 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3196 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3197 application.GetScene().Add(actor);
3199 tet_infoline("Create visual with IMMEDIATE load policy");
3200 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3202 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3203 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3205 tet_infoline("Allow image time to load");
3206 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3207 application.SendNotification();
3208 application.Render();
3210 tet_infoline("Testing texture is loaded and resource ready signal fired");
3211 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3212 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3214 tet_infoline("Original control correctly signalled, now testing failing image");
3216 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3219 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3221 DummyControl actor2 = DummyControl::New(true);
3222 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3223 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3224 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3226 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3227 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3229 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3230 application.GetScene().Add(actor2);
3232 tet_infoline("Wait for loading thread to finish");
3233 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3234 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3236 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3238 tet_infoline("Check for 3rd signal");
3239 application.SendNotification();
3240 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3241 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3246 int UtcDaliImageVisualLoadImagePlanes01(void)
3248 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3249 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3251 ToolkitTestApplication application;
3253 VisualFactory factory = VisualFactory::Get();
3254 DALI_TEST_CHECK(factory);
3256 Property::Map propertyMap;
3257 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3258 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3260 Visual::Base visual = factory.CreateVisual(propertyMap);
3261 DALI_TEST_CHECK(visual);
3263 DummyControl actor = DummyControl::New();
3264 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3265 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3266 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3267 application.GetScene().Add(actor);
3269 application.SendNotification();
3270 application.Render();
3272 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3274 TestGlAbstraction& gl = application.GetGlAbstraction();
3275 TraceCallStack& textureTrace = gl.GetTextureTrace();
3276 textureTrace.Enable(true);
3278 application.SendNotification();
3279 application.Render();
3281 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3282 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3283 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3285 Renderer renderer = actor.GetRendererAt(0);
3286 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3287 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3292 int UtcDaliImageVisualLoadImagePlanes02(void)
3294 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3295 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3297 ToolkitTestApplication application;
3299 VisualFactory factory = VisualFactory::Get();
3300 DALI_TEST_CHECK(factory);
3302 // Alpha masking case - not support yuv planes
3303 Property::Map propertyMap;
3304 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3305 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3306 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3308 Visual::Base visual = factory.CreateVisual(propertyMap);
3309 DALI_TEST_CHECK(visual);
3311 DummyControl actor = DummyControl::New();
3312 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3313 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3314 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3315 application.GetScene().Add(actor);
3317 application.SendNotification();
3318 application.Render();
3320 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3322 TestGlAbstraction& gl = application.GetGlAbstraction();
3323 TraceCallStack& textureTrace = gl.GetTextureTrace();
3324 textureTrace.Enable(true);
3326 application.SendNotification();
3327 application.Render();
3329 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3330 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3331 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3336 int UtcDaliImageVisualLoadImagePlanes03(void)
3338 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3339 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3341 ToolkitTestApplication application;
3343 VisualFactory factory = VisualFactory::Get();
3344 DALI_TEST_CHECK(factory);
3346 TestGlAbstraction& gl = application.GetGlAbstraction();
3347 TraceCallStack& textureTrace = gl.GetTextureTrace();
3348 textureTrace.Enable(true);
3350 Property::Map propertyMap;
3351 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3352 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3353 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3355 Visual::Base visual = factory.CreateVisual(propertyMap);
3356 DALI_TEST_CHECK(visual);
3358 DummyControl actor = DummyControl::New();
3359 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3360 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3361 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3362 application.GetScene().Add(actor);
3364 application.SendNotification();
3365 application.Render();
3367 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3368 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3369 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);