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 UtcDaliImageVisualWithPixelDataMasking(void)
621 ToolkitTestApplication application;
622 tet_infoline("Load external texture with mask");
624 TestGlAbstraction& gl = application.GetGlAbstraction();
625 TraceCallStack& textureTrace = gl.GetTextureTrace();
626 textureTrace.Enable(true);
630 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
632 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
633 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
635 DALI_TEST_CHECK(pixelData);
637 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
638 std::string url = imageUrl.GetUrl();
640 VisualFactory factory = VisualFactory::Get();
641 DALI_TEST_CHECK(factory);
643 Property::Map propertyMap;
644 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
645 propertyMap.Insert(ImageVisual::Property::URL, url);
646 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
648 Visual::Base visual = factory.CreateVisual(propertyMap);
649 DALI_TEST_CHECK(visual);
651 Property::Map testMap;
652 visual.CreatePropertyMap(testMap);
653 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
655 DummyControl actor = DummyControl::New();
656 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
657 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
659 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
661 application.GetScene().Add(actor);
662 application.SendNotification();
663 application.Render(16);
664 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
666 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
667 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
668 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
670 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
671 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
676 int UtcDaliImageVisualWithPixelDataMaskingSynchronously(void)
678 ToolkitTestApplication application;
679 tet_infoline("Load synchronously external texture with mask");
683 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
685 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
686 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
688 DALI_TEST_CHECK(pixelData);
690 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
691 std::string url = imageUrl.GetUrl();
693 VisualFactory factory = VisualFactory::Get();
694 DALI_TEST_CHECK(factory);
696 Property::Map propertyMap;
697 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
698 propertyMap.Insert(ImageVisual::Property::URL, url);
699 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
700 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
702 Visual::Base visual = factory.CreateVisual(propertyMap);
703 DALI_TEST_CHECK(visual);
705 Property::Map testMap;
706 visual.CreatePropertyMap(testMap);
707 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
709 DummyControl actor = DummyControl::New();
710 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
711 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
713 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
715 application.GetScene().Add(actor);
717 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
719 application.SendNotification();
720 application.Render(16);
725 int UtcDaliImageVisualWithNativeImage(void)
727 ToolkitTestApplication application;
728 tet_infoline("Use Native Image as url");
730 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
731 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
732 std::string url = imageUrl.GetUrl();
734 VisualFactory factory = VisualFactory::Get();
735 DALI_TEST_CHECK(factory);
737 Property::Map propertyMap;
738 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
739 propertyMap.Insert(ImageVisual::Property::URL, url);
741 Visual::Base visual = factory.CreateVisual(propertyMap);
742 DALI_TEST_CHECK(visual);
744 DummyControl actor = DummyControl::New();
745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
748 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
750 application.GetScene().Add(actor);
752 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
754 application.SendNotification();
755 application.Render(16);
757 Renderer renderer = actor.GetRendererAt(0);
758 Shader shader = renderer.GetShader();
760 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
761 DALI_TEST_CHECK(value.GetType() == Property::MAP);
762 const Property::Map* outMap = value.GetMap();
763 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
765 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
766 size_t pos = fragmentShader.find(fragmentPrefix);
768 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
770 // Check whether preMultipliedAlpha is false.
771 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
772 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
777 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
779 ToolkitTestApplication application;
780 tet_infoline("Use Native Image as url");
782 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
783 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
784 std::string url = imageUrl.GetUrl();
786 VisualFactory factory = VisualFactory::Get();
787 DALI_TEST_CHECK(factory);
789 Property::Map propertyMap;
790 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
791 propertyMap.Insert(ImageVisual::Property::URL, url);
793 Visual::Base visual = factory.CreateVisual(propertyMap);
794 DALI_TEST_CHECK(visual);
796 DummyControl actor = DummyControl::New();
797 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
798 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
800 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
802 application.GetScene().Add(actor);
804 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
806 application.SendNotification();
807 application.Render(16);
809 Renderer renderer = actor.GetRendererAt(0);
810 Shader shader = renderer.GetShader();
812 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
813 DALI_TEST_CHECK(value.GetType() == Property::MAP);
814 const Property::Map* outMap = value.GetMap();
815 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
817 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
818 size_t pos = fragmentShader.find(fragmentPrefix);
820 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
822 // Check whether preMultipliedAlpha is true.
823 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
824 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
829 int UtcDaliImageVisualWithNativeImageCustomShader(void)
831 ToolkitTestApplication application;
832 tet_infoline("Use Native Image as url and Use custom shader");
834 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
835 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
836 std::string url = imageUrl.GetUrl();
838 VisualFactory factory = VisualFactory::Get();
839 DALI_TEST_CHECK(factory);
841 Property::Map propertyMap;
842 Property::Map shaderMap;
843 const std::string customVertexShaderSource = "Foobar";
844 const std::string customFragmentShaderSource = "Foobar";
845 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
846 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
848 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
849 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
850 propertyMap.Insert(ImageVisual::Property::URL, url);
852 Visual::Base visual = factory.CreateVisual(propertyMap);
853 DALI_TEST_CHECK(visual);
855 DummyControl actor = DummyControl::New();
856 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
857 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
859 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
860 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
862 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
864 application.GetScene().Add(actor);
866 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
868 application.SendNotification();
869 application.Render(16);
871 Renderer renderer = actor.GetRendererAt(0);
872 Shader shader = renderer.GetShader();
874 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
875 DALI_TEST_CHECK(value.GetType() == Property::MAP);
876 const Property::Map* outMap = value.GetMap();
877 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
878 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
880 // Compare vertex shader is equal
881 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
883 // Check fragment shader changed
884 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
885 size_t pos = fragmentShaderSource.find(fragmentPrefix);
887 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
889 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
891 // Check whether preMultipliedAlpha is false.
892 // Note : We dont use preMultiplied alpha when app developer using custom shader.
893 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
894 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
899 int UtcDaliImageVisualWithNativeImageRemoved(void)
901 ToolkitTestApplication application;
902 tet_infoline("Use Native Image as url");
904 TestGlAbstraction& gl = application.GetGlAbstraction();
905 TraceCallStack& textureTrace = gl.GetTextureTrace();
906 textureTrace.Enable(true);
908 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
909 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
910 std::string url = imageUrl.GetUrl();
912 VisualFactory factory = VisualFactory::Get();
913 DALI_TEST_CHECK(factory);
915 Property::Map propertyMap;
916 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
917 propertyMap.Insert(ImageVisual::Property::URL, url);
919 Visual::Base visual = factory.CreateVisual(propertyMap);
920 DALI_TEST_CHECK(visual);
922 DummyControl actor = DummyControl::New();
923 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
924 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
926 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
928 application.GetScene().Add(actor);
929 application.SendNotification();
930 application.Render();
932 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
933 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
935 tet_infoline("No delete texture because reference count is not zero");
937 application.GetScene().Remove(actor);
938 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
939 application.SendNotification();
940 application.Render();
942 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
943 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
945 tet_infoline("Delete texture because reference count is zero");
947 application.SendNotification();
948 application.Render();
950 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
955 int UtcDaliImageVisualWithEncodedImageBuffer(void)
957 ToolkitTestApplication application;
958 tet_infoline("Use Encoded Image Buffer as url");
960 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
961 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
963 VisualFactory factory = VisualFactory::Get();
964 DALI_TEST_CHECK(factory);
966 Property::Map propertyMap;
967 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
968 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
970 Visual::Base visual = factory.CreateVisual(propertyMap);
971 DALI_TEST_CHECK(visual);
973 TestGlAbstraction& gl = application.GetGlAbstraction();
974 TraceCallStack& textureTrace = gl.GetTextureTrace();
975 textureTrace.Enable(true);
977 DummyControl actor = DummyControl::New();
978 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
979 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
981 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
982 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
984 application.GetScene().Add(actor);
985 application.SendNotification();
987 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
989 application.SendNotification();
990 application.Render();
992 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
993 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
995 application.GetScene().Remove(actor);
996 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1001 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
1003 ToolkitTestApplication application;
1004 tet_infoline("Use Encoded Image Buffer as url");
1006 TestGlAbstraction& gl = application.GetGlAbstraction();
1007 TraceCallStack& textureTrace = gl.GetTextureTrace();
1008 textureTrace.Enable(true);
1010 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1011 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1012 std::string url = imageUrl.GetUrl();
1014 VisualFactory factory = VisualFactory::Get();
1015 DALI_TEST_CHECK(factory);
1017 Property::Map propertyMap;
1018 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1019 propertyMap.Insert(ImageVisual::Property::URL, url);
1021 Visual::Base visual = factory.CreateVisual(propertyMap);
1022 DALI_TEST_CHECK(visual);
1024 DummyControl actor = DummyControl::New();
1025 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1026 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1028 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1030 application.GetScene().Add(actor);
1031 application.SendNotification();
1033 // Wait for decode buffer and make texture.
1034 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1036 application.SendNotification();
1037 application.Render();
1039 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1040 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1042 tet_infoline("Delete texture because there is no actor to use decoded texture");
1044 application.GetScene().Remove(actor);
1045 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1046 application.SendNotification();
1047 application.Render();
1049 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1050 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1055 int UtcDaliImageVisualTextureReuse1(void)
1057 ToolkitTestApplication application;
1058 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
1060 Property::Map propertyMap;
1061 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1062 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1063 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1065 TestGlAbstraction& gl = application.GetGlAbstraction();
1066 TraceCallStack& textureTrace = gl.GetTextureTrace();
1067 textureTrace.Enable(true);
1068 TraceCallStack& drawTrace = gl.GetDrawTrace();
1069 drawTrace.Enable(true);
1071 Actor actor = CreateActorWithImageVisual(propertyMap);
1072 application.GetScene().Add(actor);
1073 application.SendNotification();
1075 // Wait for image to load
1076 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1078 application.SendNotification();
1079 application.Render();
1081 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1082 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1083 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1084 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1085 textureTrace.Reset();
1088 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1089 application.GetScene().Add(actor2);
1091 application.SendNotification(); // Send messages to update
1092 application.Render(); // process update and render
1093 application.SendNotification(); // process any signals to event
1095 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1097 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
1098 // backend here, but test graphics backend.
1099 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1100 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1102 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
1104 application.GetScene().Remove(actor);
1105 application.SendNotification();
1106 application.Render();
1108 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1109 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1111 tet_infoline("Test that removing last actor does delete the texture\n");
1113 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1114 application.SendNotification();
1115 application.Render();
1117 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1118 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1123 int UtcDaliImageVisualTextureReuse2(void)
1125 ToolkitTestApplication application;
1126 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");
1128 Property::Map propertyMap;
1129 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1130 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1132 TestGlAbstraction& gl = application.GetGlAbstraction();
1133 TraceCallStack& textureTrace = gl.GetTextureTrace();
1134 textureTrace.Enable(true);
1135 TraceCallStack& drawTrace = gl.GetDrawTrace();
1136 drawTrace.Enable(true);
1138 Actor actor = CreateActorWithImageVisual(propertyMap);
1139 application.GetScene().Add(actor);
1140 application.SendNotification();
1142 // Wait for image to load
1143 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1149 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1150 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1151 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1152 textureTrace.Reset();
1155 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1156 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1157 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1158 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1159 application.GetScene().Add(actor2);
1161 application.SendNotification();
1163 // Wait for image to load
1164 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1166 application.SendNotification();
1167 application.Render();
1169 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1172 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1173 "renderers are using different textures\n");
1175 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1176 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1177 TraceCallStack::NamedParams tex1;
1178 tex1["texture"] << 1;
1179 TraceCallStack::NamedParams tex2;
1180 tex2["texture"] << 2;
1181 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1182 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1184 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1186 application.GetScene().Remove(actor);
1187 application.SendNotification();
1188 application.Render();
1190 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1191 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1193 tet_infoline("Test that removing last actor deletes it's texture\n");
1195 application.GetScene().Remove(actor2);
1196 application.SendNotification();
1197 application.Render();
1199 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1200 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1205 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1207 ToolkitTestApplication application;
1208 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1210 static std::vector<UniformData> customUniforms =
1212 UniformData("pixelArea", Property::Type::VECTOR4),
1213 UniformData("wrapMode", Property::Type::VECTOR2),
1216 TestGraphicsController& graphics = application.GetGraphicsController();
1217 graphics.AddCustomUniforms(customUniforms);
1219 VisualFactory factory = VisualFactory::Get();
1220 DALI_TEST_CHECK(factory);
1222 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1223 const int width = 34;
1224 const int height = 34;
1225 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1227 Property::Map propertyMap;
1228 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1229 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1230 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1231 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1232 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1233 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1234 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1235 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1236 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1238 Visual::Base visual = factory.CreateVisual(propertyMap);
1239 DALI_TEST_CHECK(visual);
1241 TestGlAbstraction& gl = application.GetGlAbstraction();
1242 TraceCallStack& textureTrace = gl.GetTextureTrace();
1243 textureTrace.Enable(true);
1244 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1245 texParameterTrace.Enable(true);
1247 DummyControl actor = DummyControl::New();
1248 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1249 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1250 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1251 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1252 application.GetScene().Add(actor);
1255 application.SendNotification();
1256 application.Render();
1258 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1260 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1262 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1263 std::stringstream out;
1264 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1265 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1267 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1268 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1270 // test the uniforms which used to handle the wrap mode
1271 Renderer renderer = actor.GetRendererAt(0u);
1272 DALI_TEST_CHECK(renderer);
1274 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1275 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1276 Vector4 pixelAreaUniform;
1277 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1278 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1280 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1281 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1282 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1283 Vector2 wrapModeUniform;
1284 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1285 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1288 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1293 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1295 ToolkitTestApplication application;
1296 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1298 static std::vector<UniformData> customUniforms =
1300 UniformData("pixelArea", Property::Type::VECTOR4),
1303 TestGraphicsController& graphics = application.GetGraphicsController();
1304 graphics.AddCustomUniforms(customUniforms);
1306 VisualFactory factory = VisualFactory::Get();
1307 DALI_TEST_CHECK(factory);
1309 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1310 const int width = 600;
1311 const int height = 600;
1312 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1314 Property::Map propertyMap;
1315 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1316 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1317 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1318 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1319 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1320 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1321 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1322 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1324 Visual::Base visual = factory.CreateVisual(propertyMap);
1325 DALI_TEST_CHECK(visual);
1327 TestGlAbstraction& gl = application.GetGlAbstraction();
1328 TraceCallStack& textureTrace = gl.GetTextureTrace();
1329 textureTrace.Enable(true);
1330 textureTrace.EnableLogging(true);
1331 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1332 texParameterTrace.Enable(true);
1333 texParameterTrace.EnableLogging(true);
1335 DummyControl actor = DummyControl::New();
1336 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1337 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1338 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1339 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1340 application.GetScene().Add(actor);
1343 application.SendNotification();
1344 application.Render();
1345 application.SendNotification();
1347 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1349 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1351 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1352 std::stringstream out;
1353 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1354 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1356 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1357 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1359 // test the uniforms which used to handle the wrap mode
1360 Renderer renderer = actor.GetRendererAt(0u);
1361 DALI_TEST_CHECK(renderer);
1363 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1364 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1365 Vector4 pixelAreaUniform;
1366 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1367 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1369 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1370 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1373 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1378 int UtcDaliImageVisualAnimateMixColor(void)
1380 ToolkitTestApplication application;
1381 tet_infoline("Animate mix color");
1383 static std::vector<UniformData> customUniforms =
1385 UniformData("mixColor", Property::Type::VECTOR3),
1388 TestGraphicsController& graphics = application.GetGraphicsController();
1389 graphics.AddCustomUniforms(customUniforms);
1391 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1393 VisualFactory factory = VisualFactory::Get();
1394 Property::Map propertyMap;
1395 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1396 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1397 propertyMap.Insert("mixColor", Color::BLUE);
1398 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1399 Visual::Base visual = factory.CreateVisual(propertyMap);
1401 DummyControl actor = DummyControl::New(true);
1402 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1403 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1405 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1406 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1407 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1408 application.GetScene().Add(actor);
1410 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1412 Renderer renderer = actor.GetRendererAt(0);
1414 // @todo Should we add API to make this code work again?
1415 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1417 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1418 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1420 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1423 map["target"] = "testVisual";
1424 map["property"] = "mixColor";
1425 map["initialValue"] = Color::MAGENTA;
1426 map["targetValue"] = TARGET_MIX_COLOR;
1427 map["animator"] = Property::Map()
1428 .Add("alphaFunction", "LINEAR")
1429 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1431 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1433 Animation animation = dummyImpl.CreateTransition(transition);
1435 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1438 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1439 glAbstraction.EnableEnableDisableCallTrace(true);
1440 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1441 std::ostringstream blendStr;
1442 blendStr << std::hex << GL_BLEND;
1444 application.SendNotification();
1445 application.Render(0); // Ensure animation starts
1446 application.Render(2000u); // Halfway point
1447 Vector3 testColor(1.0f, 0.0f, 0.5f);
1449 // uColor.a should be actor's alpha * mixColor.a.
1450 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1451 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1453 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1455 glEnableStack.Reset();
1457 application.SendNotification();
1458 application.Render(2000u);
1460 application.SendNotification();
1461 application.Render();
1462 application.SendNotification();
1464 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1465 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1466 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1468 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1470 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1475 int UtcDaliImageVisualAnimateOpacity(void)
1477 ToolkitTestApplication application;
1478 tet_infoline("Animate image visual opacity");
1480 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1482 VisualFactory factory = VisualFactory::Get();
1483 Property::Map propertyMap;
1484 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1485 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1486 propertyMap.Insert("opacity", 0.5f);
1487 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1488 Visual::Base visual = factory.CreateVisual(propertyMap);
1490 DummyControl actor = DummyControl::New(true);
1491 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1492 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1494 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1495 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1496 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1497 application.GetScene().Add(actor);
1499 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1501 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1502 glAbstraction.EnableEnableDisableCallTrace(true);
1503 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1504 std::ostringstream blendStr;
1505 blendStr << std::hex << GL_BLEND;
1507 application.SendNotification();
1508 application.Render();
1510 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1513 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.");
1516 map["target"] = "testVisual";
1517 map["property"] = "opacity";
1518 map["targetValue"] = 1.0f;
1519 map["animator"] = Property::Map()
1520 .Add("alphaFunction", "LINEAR")
1521 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1523 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1524 Animation animation = dummyImpl.CreateTransition(transition);
1527 glEnableStack.Reset();
1529 application.SendNotification();
1530 application.Render(0); // Ensure animation starts
1531 application.Render(2000u); // Halfway point through animation
1532 application.SendNotification(); // Handle any signals
1535 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1536 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1538 application.Render(2001u); // end
1539 application.SendNotification(); // ensure animation finished signal is sent
1541 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1542 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1544 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1545 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1549 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.");
1552 map["target"] = "testVisual";
1553 map["property"] = Visual::Property::OPACITY;
1554 map["targetValue"] = 0.1f;
1555 map["animator"] = Property::Map()
1556 .Add("alphaFunction", "LINEAR")
1557 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1559 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1560 Animation animation = dummyImpl.CreateTransition(transition);
1563 glEnableStack.Reset();
1565 application.SendNotification();
1566 application.Render(0); // Ensure animation starts
1567 application.Render(2000u); // Halfway point
1568 application.SendNotification();
1571 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1572 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1574 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1576 glEnableStack.Reset();
1578 application.Render(2016u); // end
1579 application.SendNotification();
1581 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1582 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1584 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1585 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1591 int UtcDaliImageVisualAnimateOpacity02(void)
1593 ToolkitTestApplication application;
1594 tet_infoline("Animate image visual opacity");
1596 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1598 VisualFactory factory = VisualFactory::Get();
1599 Property::Map propertyMap;
1600 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1601 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1602 propertyMap.Insert("opacity", 0.5f);
1603 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1604 Visual::Base visual = factory.CreateVisual(propertyMap);
1606 DummyControl actor = DummyControl::New(true);
1607 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1608 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1610 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1611 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1612 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1614 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1616 Property::Array array;
1619 map["target"] = "testVisual";
1620 map["property"] = "opacity";
1621 map["initialValue"] = 0.0f;
1622 map["targetValue"] = 1.0f;
1623 map["animator"] = Property::Map()
1624 .Add("alphaFunction", "LINEAR")
1625 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1628 map2["target"] = "testVisual";
1629 map2["property"] = "size";
1630 map2["targetValue"] = Vector2(1.0f, 1.0f);
1632 array.Add(map).Add(map2);
1634 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1635 Animation animation = dummyImpl.CreateTransition(transition);
1637 application.GetScene().Add(actor);
1638 application.SendNotification();
1639 application.Render(0); // Ensure animation starts
1641 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1643 Renderer renderer = actor.GetRendererAt(0);
1644 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1645 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1647 animation = dummyImpl.CreateTransition(transition);
1650 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1651 glAbstraction.EnableEnableDisableCallTrace(true);
1652 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1653 std::ostringstream blendStr;
1654 blendStr << std::hex << GL_BLEND;
1656 application.SendNotification();
1657 application.Render(0); // Ensure animation starts
1658 application.Render(2000u); // Halfway point through animation
1659 application.SendNotification(); // Handle any signals
1661 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1664 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1665 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1667 glEnableStack.Reset();
1669 application.Render(2001u); // end
1670 application.SendNotification(); // ensure animation finished signal is sent
1672 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1673 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1675 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1680 int UtcDaliImageVisualAnimatePixelArea(void)
1682 ToolkitTestApplication application;
1683 tet_infoline("ImageVisual animate pixel area");
1685 static std::vector<UniformData> customUniforms =
1687 UniformData("pixelArea", Property::Type::VECTOR4),
1690 TestGraphicsController& graphics = application.GetGraphicsController();
1691 graphics.AddCustomUniforms(customUniforms);
1693 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1695 VisualFactory factory = VisualFactory::Get();
1696 Property::Map propertyMap;
1697 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1698 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1699 propertyMap.Insert("mixColor", Color::BLUE);
1700 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1701 Visual::Base visual = factory.CreateVisual(propertyMap);
1703 DummyControl actor = DummyControl::New(true);
1704 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1705 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1707 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1708 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1709 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1710 application.GetScene().Add(actor);
1712 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1714 Renderer renderer = actor.GetRendererAt(0);
1715 // @todo Implement this feature?
1716 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1717 //tet_infoline("Test that the renderer has the mixColor property");
1718 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1720 // TransitionData only takes string keys
1722 map["target"] = "testVisual";
1723 map["property"] = "pixelArea";
1724 map["initialValue"] = Vector4(0, 0, 0, 1);
1725 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1726 map["animator"] = Property::Map()
1727 .Add("alphaFunction", "LINEAR")
1728 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1730 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1732 Animation animation = dummyImpl.CreateTransition(transition);
1733 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1736 application.SendNotification();
1737 application.Render(0); // Ensure animation starts
1738 application.Render(2000u); // Halfway point
1740 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1742 application.Render(2000u); // End of animation
1744 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1749 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1751 ToolkitTestApplication application;
1752 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1754 Property::Map propertyMap;
1755 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1756 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1758 TestGlAbstraction& gl = application.GetGlAbstraction();
1759 TraceCallStack& textureTrace = gl.GetTextureTrace();
1760 textureTrace.Enable(true);
1761 TraceCallStack& drawTrace = gl.GetDrawTrace();
1762 drawTrace.Enable(true);
1764 Actor actor = CreateActorWithImageVisual(propertyMap);
1765 application.GetScene().Add(actor);
1766 application.SendNotification();
1768 application.GetScene().Remove(actor);
1769 application.SendNotification();
1771 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1772 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1773 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1774 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1779 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1781 ToolkitTestApplication application;
1782 tet_infoline("Load image asynchronously, cancel loading, then load again");
1784 VisualFactory factory = VisualFactory::Get();
1785 DALI_TEST_CHECK(factory);
1787 Property::Map propertyMap;
1788 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1789 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1791 Visual::Base visual = factory.CreateVisual(propertyMap);
1792 DALI_TEST_CHECK(visual);
1794 TestGlAbstraction& gl = application.GetGlAbstraction();
1795 TraceCallStack& textureTrace = gl.GetTextureTrace();
1796 textureTrace.Enable(true);
1797 TraceCallStack& drawTrace = gl.GetDrawTrace();
1798 drawTrace.Enable(true);
1800 DummyControl actor = DummyControl::New();
1801 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1802 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1804 application.GetScene().Add(actor);
1807 application.GetScene().Remove(actor);
1809 application.GetScene().Add(actor);
1811 // Create another visual with the same image
1812 visual = factory.CreateVisual(propertyMap);
1813 DALI_TEST_CHECK(visual);
1815 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1817 application.SendNotification();
1818 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1820 application.SendNotification();
1821 application.Render();
1823 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1824 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1825 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1826 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1831 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1833 ToolkitTestApplication application;
1834 tet_infoline("Request image visual with invalid images - should draw broken.png");
1836 VisualFactory factory = VisualFactory::Get();
1837 DALI_TEST_CHECK(factory);
1839 Property::Map propertyMap;
1840 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1841 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1843 Visual::Base visual = factory.CreateVisual(propertyMap);
1844 DALI_TEST_CHECK(visual);
1846 TestGlAbstraction& gl = application.GetGlAbstraction();
1847 TraceCallStack& textureTrace = gl.GetTextureTrace();
1848 textureTrace.Enable(true);
1850 DummyControl actor = DummyControl::New();
1851 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1852 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1854 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1855 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1857 application.GetScene().Add(actor);
1859 application.SendNotification();
1860 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1862 application.SendNotification();
1863 application.Render();
1865 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1866 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1868 application.GetScene().Remove(actor);
1869 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1874 int UtcDaliImageVisualSetInvalidSyncImage(void)
1876 ToolkitTestApplication application;
1877 tet_infoline("Request image visual with invalid images - should draw broken.png");
1879 VisualFactory factory = VisualFactory::Get();
1880 DALI_TEST_CHECK(factory);
1882 Property::Map propertyMap;
1883 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1884 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1885 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1887 Visual::Base visual = factory.CreateVisual(propertyMap);
1888 DALI_TEST_CHECK(visual);
1890 TestGlAbstraction& gl = application.GetGlAbstraction();
1891 TraceCallStack& textureTrace = gl.GetTextureTrace();
1892 textureTrace.Enable(true);
1894 DummyControl actor = DummyControl::New();
1895 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1896 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1898 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1899 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1901 application.GetScene().Add(actor);
1903 application.SendNotification();
1904 application.Render();
1906 // Check resource status
1907 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1908 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1910 // The broken image should be shown.
1911 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1912 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1914 application.GetScene().Remove(actor);
1915 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1920 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1922 ToolkitTestApplication application;
1923 tet_infoline("Request image visual with invalid images - should draw broken.png");
1925 VisualFactory factory = VisualFactory::Get();
1926 DALI_TEST_CHECK(factory);
1928 // Local invalid file, asynchronous loading
1929 Property::Map propertyMap;
1930 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1931 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1933 Visual::Base visual = factory.CreateVisual(propertyMap);
1934 DALI_TEST_CHECK(visual);
1936 TestGlAbstraction& gl = application.GetGlAbstraction();
1937 TraceCallStack& textureTrace = gl.GetTextureTrace();
1938 textureTrace.Enable(true);
1940 DummyControl actor = DummyControl::New();
1941 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1942 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1944 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1945 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1947 application.GetScene().Add(actor);
1949 application.SendNotification();
1950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1952 application.SendNotification();
1953 application.Render();
1955 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1956 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1958 application.GetScene().Remove(actor);
1959 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1964 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
1966 ToolkitTestApplication application;
1967 tet_infoline("Request image visual with invalid images - should draw broken.png");
1969 VisualFactory factory = VisualFactory::Get();
1970 DALI_TEST_CHECK(factory);
1972 // Load invalid file
1973 Property::Map propertyMap;
1974 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1975 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
1977 Visual::Base visual = factory.CreateVisual(propertyMap);
1978 DALI_TEST_CHECK(visual);
1980 TestGlAbstraction& gl = application.GetGlAbstraction();
1981 TraceCallStack& textureTrace = gl.GetTextureTrace();
1982 textureTrace.Enable(true);
1984 DummyControl actor = DummyControl::New();
1985 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1986 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1988 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1989 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1991 application.GetScene().Add(actor);
1993 application.SendNotification();
1994 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1996 application.SendNotification();
1997 application.Render();
1999 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2000 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2002 application.GetScene().Remove(actor);
2003 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2004 textureTrace.Reset();
2006 // Load invalid file with disabled broken
2007 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2008 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2009 propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2011 visual = factory.CreateVisual(propertyMap);
2012 DALI_TEST_CHECK(visual);
2014 actor = DummyControl::New();
2015 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2016 dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2018 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2019 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2021 application.GetScene().Add(actor);
2023 application.SendNotification();
2024 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2026 application.SendNotification();
2027 application.Render();
2029 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2030 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2032 application.GetScene().Remove(actor);
2033 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2038 int UtcDaliImageVisualAlphaMask01(void)
2040 ToolkitTestApplication application;
2041 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2043 VisualFactory factory = VisualFactory::Get();
2044 DALI_TEST_CHECK(factory);
2046 Property::Map propertyMap;
2047 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2048 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2049 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2051 Visual::Base visual = factory.CreateVisual(propertyMap);
2052 DALI_TEST_CHECK(visual);
2054 Property::Map testMap;
2055 visual.CreatePropertyMap(testMap);
2056 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2058 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2059 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2061 TestGlAbstraction& gl = application.GetGlAbstraction();
2062 TraceCallStack& textureTrace = gl.GetTextureTrace();
2063 textureTrace.Enable(true);
2065 DummyControl actor = DummyControl::New();
2066 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2067 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2069 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2070 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2071 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2073 application.GetScene().Add(actor);
2074 application.SendNotification();
2075 application.Render();
2077 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2079 application.SendNotification();
2080 application.Render();
2082 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2083 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2084 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2086 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2087 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2092 int UtcDaliImageVisualAlphaMask02(void)
2094 ToolkitTestApplication application;
2095 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2097 VisualFactory factory = VisualFactory::Get();
2098 DALI_TEST_CHECK(factory);
2100 Property::Map propertyMap;
2101 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2102 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2103 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2104 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2106 Visual::Base visual = factory.CreateVisual(propertyMap);
2107 DALI_TEST_CHECK(visual);
2109 Property::Map testMap;
2110 visual.CreatePropertyMap(testMap);
2111 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2112 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2114 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2115 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2117 TestGlAbstraction& gl = application.GetGlAbstraction();
2118 TraceCallStack& textureTrace = gl.GetTextureTrace();
2119 textureTrace.Enable(true);
2121 DummyControl actor = DummyControl::New();
2122 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2123 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2125 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2126 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2127 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2129 application.GetScene().Add(actor);
2130 application.SendNotification();
2131 application.Render();
2133 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2135 application.SendNotification();
2136 application.Render();
2138 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2139 Renderer renderer = actor.GetRendererAt(0u);
2140 TextureSet textures = renderer.GetTextures();
2141 DALI_TEST_CHECK(textures);
2142 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2144 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2145 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2147 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2148 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2153 int UtcDaliImageVisualAlphaMask03(void)
2155 ToolkitTestApplication application;
2156 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2158 VisualFactory factory = VisualFactory::Get();
2159 DALI_TEST_CHECK(factory);
2161 Property::Map propertyMap;
2162 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2163 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2164 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2165 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2167 Visual::Base visual = factory.CreateVisual(propertyMap);
2168 DALI_TEST_CHECK(visual);
2170 Property::Map testMap;
2171 visual.CreatePropertyMap(testMap);
2173 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2174 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2176 TestGlAbstraction& gl = application.GetGlAbstraction();
2177 TraceCallStack& textureTrace = gl.GetTextureTrace();
2178 textureTrace.Enable(true);
2180 DummyControl actor = DummyControl::New();
2181 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2182 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2184 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2185 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2186 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2188 application.GetScene().Add(actor);
2189 application.SendNotification();
2190 application.Render();
2192 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2194 application.SendNotification();
2195 application.Render();
2197 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2198 Renderer renderer = actor.GetRendererAt(0u);
2199 TextureSet textures = renderer.GetTextures();
2200 DALI_TEST_CHECK(textures);
2201 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2203 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2204 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2206 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2207 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2212 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2214 ToolkitTestApplication application;
2215 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2217 VisualFactory factory = VisualFactory::Get();
2218 DALI_TEST_CHECK(factory);
2220 Property::Map propertyMap;
2221 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2222 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2223 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2224 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2226 Visual::Base visual = factory.CreateVisual(propertyMap);
2227 DALI_TEST_CHECK(visual);
2229 Property::Map testMap;
2230 visual.CreatePropertyMap(testMap);
2231 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2233 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2234 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2236 TestGlAbstraction& gl = application.GetGlAbstraction();
2237 TraceCallStack& textureTrace = gl.GetTextureTrace();
2238 textureTrace.Enable(true);
2240 DummyControl actor = DummyControl::New();
2241 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2242 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2244 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2245 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2246 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2248 application.GetScene().Add(actor);
2250 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2252 application.SendNotification();
2253 application.Render();
2255 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2256 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2257 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2259 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2260 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2265 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2267 ToolkitTestApplication application;
2268 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2270 VisualFactory factory = VisualFactory::Get();
2271 DALI_TEST_CHECK(factory);
2273 Property::Map propertyMap;
2274 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2275 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2276 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2277 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2278 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2280 Visual::Base visual = factory.CreateVisual(propertyMap);
2281 DALI_TEST_CHECK(visual);
2283 Property::Map testMap;
2284 visual.CreatePropertyMap(testMap);
2285 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2287 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2288 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2290 TestGlAbstraction& gl = application.GetGlAbstraction();
2291 TraceCallStack& textureTrace = gl.GetTextureTrace();
2292 textureTrace.Enable(true);
2294 DummyControl actor = DummyControl::New();
2295 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2296 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2298 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2299 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2300 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2302 application.GetScene().Add(actor);
2304 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2306 application.SendNotification();
2307 application.Render();
2309 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2310 Renderer renderer = actor.GetRendererAt(0u);
2311 TextureSet textures = renderer.GetTextures();
2312 DALI_TEST_CHECK(textures);
2313 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2315 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2316 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2318 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2319 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2324 int UtcDaliImageVisualRemoteAlphaMask(void)
2326 ToolkitTestApplication application;
2327 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2329 VisualFactory factory = VisualFactory::Get();
2330 DALI_TEST_CHECK(factory);
2332 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2334 Property::Map propertyMap;
2335 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2336 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2337 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2339 Visual::Base visual = factory.CreateVisual(propertyMap);
2340 DALI_TEST_CHECK(visual);
2342 Property::Map testMap;
2343 visual.CreatePropertyMap(testMap);
2345 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2347 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2348 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2350 TestGlAbstraction& gl = application.GetGlAbstraction();
2351 TraceCallStack& textureTrace = gl.GetTextureTrace();
2352 textureTrace.Enable(true);
2354 DummyControl actor = DummyControl::New();
2355 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2356 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2358 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2360 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2361 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2363 application.GetScene().Add(actor);
2364 application.SendNotification();
2365 application.Render();
2367 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2369 application.SendNotification();
2370 application.Render();
2372 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2373 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2374 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2379 int UtcDaliImageVisualAlphaMaskCrop(void)
2381 ToolkitTestApplication application;
2382 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2384 VisualFactory factory = VisualFactory::Get();
2385 DALI_TEST_CHECK(factory);
2387 Property::Map propertyMap;
2388 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2389 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2390 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2391 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2392 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2394 Visual::Base visual = factory.CreateVisual(propertyMap);
2395 DALI_TEST_CHECK(visual);
2397 Property::Map testMap;
2398 visual.CreatePropertyMap(testMap);
2399 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2400 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2401 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2403 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2404 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2406 TestGlAbstraction& gl = application.GetGlAbstraction();
2407 TraceCallStack& textureTrace = gl.GetTextureTrace();
2408 textureTrace.Enable(true);
2410 DummyControl actor = DummyControl::New();
2411 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2412 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2414 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2415 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2416 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2418 application.GetScene().Add(actor);
2419 application.SendNotification();
2420 application.Render();
2422 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2424 application.SendNotification();
2425 application.Render();
2428 visual.GetNaturalSize(size);
2430 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2431 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2432 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2433 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2438 int UtcDaliImageVisualReleasePolicy01(void)
2440 ToolkitTestApplication application;
2441 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2443 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2444 DALI_TEST_CHECK(imageVisual);
2446 // Set up debug trace
2447 TestGlAbstraction& gl = application.GetGlAbstraction();
2448 TraceCallStack& textureTrace = gl.GetTextureTrace();
2449 textureTrace.Enable(true);
2451 tet_infoline("Register visual with control and ensure it has the only handle");
2452 DummyControl actor = DummyControl::New(true);
2453 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2454 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2455 imageVisual.Reset();
2457 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2459 application.SendNotification();
2460 application.Render(0);
2461 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2462 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2464 application.GetScene().Add(actor);
2466 // Wait for image to load
2467 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2469 application.SendNotification();
2470 application.Render(0);
2471 // Test renderer and texture created
2472 tet_infoline("Confirm texture created");
2473 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2474 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2476 tet_infoline("Disable visual causing the texture to be deleted");
2477 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2479 application.SendNotification();
2480 application.Render(0);
2481 // Test renderer and textures removed.
2482 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2483 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2488 int UtcDaliImageVisualReleasePolicy02(void)
2490 ToolkitTestApplication application;
2491 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2493 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2494 DALI_TEST_CHECK(imageVisual);
2496 // Setup debug trace
2497 TestGlAbstraction& gl = application.GetGlAbstraction();
2498 TraceCallStack& textureTrace = gl.GetTextureTrace();
2499 textureTrace.Enable(true);
2501 tet_infoline("Register visual with control and ensure it has the only handle");
2502 DummyControl actor = DummyControl::New(true);
2503 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2504 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2505 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2507 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2509 application.SendNotification();
2510 application.Render(0);
2511 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2512 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2514 application.GetScene().Add(actor);
2516 // Wait for image to load
2517 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2519 application.SendNotification();
2520 application.Render(0);
2521 // Test renderer and texture created
2522 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2523 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2525 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2526 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2527 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2528 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2529 application.SendNotification();
2530 application.Render();
2532 // Test texture removed after visual destroyed.
2533 tet_infoline("Ensure texture is deleted after visual destroyed");
2534 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2539 int UtcDaliImageVisualReleasePolicy03(void)
2541 ToolkitTestApplication application;
2542 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2544 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2545 DALI_TEST_CHECK(imageVisual);
2547 TestGlAbstraction& gl = application.GetGlAbstraction();
2548 TraceCallStack& textureTrace = gl.GetTextureTrace();
2549 textureTrace.Enable(true);
2551 tet_infoline("Register visual with control and ensure it has the only handle");
2552 DummyControl actor = DummyControl::New(true);
2553 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2554 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2555 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2557 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2559 application.SendNotification();
2560 application.Render(0);
2561 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2562 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2564 application.GetScene().Add(actor);
2566 // Wait for image to load
2567 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2569 application.SendNotification();
2570 application.Render(0);
2571 // Test renderer and texture created
2572 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2573 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2575 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2576 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2577 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2578 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2579 application.SendNotification();
2580 application.Render();
2582 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2583 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2588 int UtcDaliImageVisualReleasePolicy04(void)
2590 ToolkitTestApplication application;
2591 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2593 tet_infoline("Create first visual with Never release policy");
2594 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2596 tet_infoline("Create second visual with Destroyed release policy");
2597 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2599 // Set up trace debug
2600 TestGlAbstraction& gl = application.GetGlAbstraction();
2601 TraceCallStack& textureTrace = gl.GetTextureTrace();
2602 textureTrace.Enable(true);
2604 tet_infoline("Register visuals with control and ensure it has the only handles");
2605 DummyControl actor = DummyControl::New(true);
2606 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2607 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2608 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2609 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2610 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2612 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2614 // Test initially zero renderers
2615 application.SendNotification();
2616 application.Render(0);
2617 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2618 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2620 application.GetScene().Add(actor);
2622 // Wait for image to load
2623 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2625 application.SendNotification();
2626 application.Render(0);
2627 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2628 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2629 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2631 // Test renderer removed when visual destroyed
2632 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2633 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2634 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2635 application.SendNotification();
2636 application.Render();
2638 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2639 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2641 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2642 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2643 application.SendNotification();
2644 application.Render();
2646 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2647 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2648 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2653 int UtcDaliImageVisualReleasePolicy05(void)
2655 ToolkitTestApplication application;
2656 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2658 VisualFactory factory = VisualFactory::Get();
2660 Property::Map propertyMapNeverReleasePolicy;
2661 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2662 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2663 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2664 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2665 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2667 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2669 Property::Map resultMap;
2670 imageVisualNever.CreatePropertyMap(resultMap);
2671 DALI_TEST_CHECK(!resultMap.Empty());
2673 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2678 int UtcDaliImageVisualReleasePolicy06(void)
2680 ToolkitTestApplication application;
2681 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2683 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2684 DALI_TEST_CHECK(imageVisual);
2686 TestGlAbstraction& gl = application.GetGlAbstraction();
2687 TraceCallStack& textureTrace = gl.GetTextureTrace();
2688 textureTrace.Enable(true);
2690 tet_infoline("Register visual with control and ensure it has the only handle");
2691 DummyControl actor = DummyControl::New(true);
2692 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2693 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2694 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2696 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2698 application.SendNotification();
2699 application.Render(0);
2700 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2701 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2703 application.GetScene().Add(actor);
2705 // Wait for image to load
2706 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2708 application.SendNotification();
2709 application.Render(0);
2710 // Test renderer and texture created
2711 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2712 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2713 textureTrace.Reset();
2715 tet_infoline("Disable Visual and check texture not affected");
2716 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2717 application.SendNotification();
2718 application.Render(0);
2719 tet_infoline("Check renderer is destroyed when visual off stage");
2720 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2721 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2722 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2723 textureTrace.Reset();
2725 tet_infoline("Re-enable Visual and check texture not affected");
2726 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2727 application.SendNotification();
2728 application.Render(0);
2729 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2730 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2731 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2732 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2737 int UtcDaliImageVisualReleasePolicy07(void)
2739 ToolkitTestApplication application;
2740 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2742 tet_infoline("Create first visual with DESTROYED release policy");
2743 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2745 tet_infoline("Create second visual with DETACHED release policy");
2746 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2748 // Set up trace debug
2749 TestGlAbstraction& gl = application.GetGlAbstraction();
2750 TraceCallStack& textureTrace = gl.GetTextureTrace();
2751 textureTrace.Enable(true);
2753 tet_infoline("Register visuals with control and ensure it has the only handles");
2754 DummyControl actor = DummyControl::New(true);
2755 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2756 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2757 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2758 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2759 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2761 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2763 // Test initially zero renderers
2764 application.SendNotification();
2765 application.Render(0);
2766 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2767 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2769 application.GetScene().Add(actor);
2771 // Wait for image to load
2772 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2774 application.SendNotification();
2775 application.Render(0);
2776 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2777 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2778 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2780 // Test renderer removed when visual destroyed
2781 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2782 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2783 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2784 application.SendNotification();
2785 application.Render();
2787 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2788 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2790 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2791 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2792 application.SendNotification();
2793 application.Render();
2795 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2796 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2801 int UtcDaliImageVisualReleasePolicy08(void)
2803 ToolkitTestApplication application;
2804 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2806 tet_infoline("Create first visual with DESTROYED release policy");
2807 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2809 // Set up trace debug
2810 TestGlAbstraction& gl = application.GetGlAbstraction();
2811 TraceCallStack& textureTrace = gl.GetTextureTrace();
2812 textureTrace.Enable(true);
2814 tet_infoline("Register visuals with control and ensure it has the only handles");
2815 DummyControl actor = DummyControl::New(true);
2816 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2817 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2818 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2820 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2822 // Test initially zero renderers
2823 application.SendNotification();
2824 application.Render(0);
2825 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2826 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2827 textureTrace.Reset();
2829 application.GetScene().Add(actor);
2831 // Wait for image to load
2832 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2834 application.SendNotification();
2835 application.Render(0);
2836 tet_infoline("Ensure a texture is created");
2837 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2838 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2839 textureTrace.Reset();
2841 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2843 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2845 // 2.Remove actor from stage. In this case, renderer also is deleted.
2846 tet_infoline("Remove actor from stage");
2847 application.GetScene().Remove(actor);
2848 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2849 application.SendNotification();
2850 application.Render();
2852 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2853 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2854 textureTrace.Reset();
2856 // 3.Add actor in stage. In this case, renderer is created.
2857 tet_infoline("Add actor in stage");
2858 application.GetScene().Add(actor);
2859 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2860 application.SendNotification();
2861 application.Render();
2862 tet_infoline("Ensure a texture is not created again");
2863 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2864 textureTrace.Reset();
2866 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2867 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2868 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2869 DALI_TEST_CHECK(textureBefore == textureAfter);
2870 textureBefore.Reset();
2871 textureAfter.Reset();
2873 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2874 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2875 application.SendNotification();
2876 application.Render();
2877 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2882 int UtcDaliImageVisualReleasePolicy09(void)
2884 ToolkitTestApplication application;
2885 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2887 Property::Map propertyMapNPatchReleasePolicy;
2888 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2889 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2890 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2891 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2892 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2894 VisualFactory factory = VisualFactory::Get();
2895 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2896 DALI_TEST_CHECK(imageVisual);
2898 // Setup debug trace
2899 TestGlAbstraction& gl = application.GetGlAbstraction();
2900 TraceCallStack& textureTrace = gl.GetTextureTrace();
2901 textureTrace.Enable(true);
2903 tet_infoline("Register visual with control and ensure it has the only handle");
2904 DummyControl actor = DummyControl::New(true);
2905 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2906 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2907 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2909 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2911 application.SendNotification();
2912 application.Render(0);
2913 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2914 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2916 application.GetScene().Add(actor);
2918 // Wait for image to load
2919 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2921 application.SendNotification();
2922 application.Render(0);
2923 // Test renderer and texture created
2924 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2925 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2927 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2928 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2929 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2930 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2931 application.SendNotification();
2932 application.Render();
2934 // Test texture removed after visual destroyed.
2935 tet_infoline("Ensure texture is deleted after visual destroyed");
2936 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2941 int UtcDaliImageVisualLoadPolicy01(void)
2943 ToolkitTestApplication application;
2944 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2946 // Set up trace debug
2947 TestGlAbstraction& gl = application.GetGlAbstraction();
2948 TraceCallStack& textureTrace = gl.GetTextureTrace();
2949 textureTrace.Enable(true);
2951 tet_infoline("Create visual with IMMEDIATE load policy");
2952 VisualFactory factory = VisualFactory::Get();
2954 Property::Map propertyMap;
2955 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2956 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2957 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2958 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2959 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2961 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2963 Property::Map resultMap;
2964 imageVisual.CreatePropertyMap(resultMap);
2965 DALI_TEST_CHECK(!resultMap.Empty());
2966 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2968 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2970 // Ensure texture has been uploaded
2971 application.SendNotification();
2972 application.Render();
2974 tet_infoline("Ensure texture loading starts after visual created");
2975 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2976 textureTrace.Reset();
2978 tet_infoline("Register visuals with control and ensure it has the only handles");
2979 DummyControl actor = DummyControl::New(true);
2980 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2981 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2982 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2984 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2985 application.GetScene().Add(actor);
2986 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2987 const unsigned int TIME_OUT_3_SECONDS = 3;
2988 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2990 application.SendNotification();
2991 application.Render();
2993 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2994 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2996 // Ensure texture is deleted when no longer needed (ref count was correct )
2997 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2999 application.SendNotification();
3000 application.Render();
3002 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3003 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3008 int UtcDaliImageVisualLoadPolicy02(void)
3010 ToolkitTestApplication application;
3011 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3013 // Set up trace debug
3014 TestGlAbstraction& gl = application.GetGlAbstraction();
3015 TraceCallStack& textureTrace = gl.GetTextureTrace();
3016 textureTrace.Enable(true);
3018 tet_infoline("Create visual with IMMEDIATE load policy");
3019 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3021 const unsigned int TIME_OUT_3_SECONDS = 3;
3022 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3024 // Act on meeage queue even although nothing expected to load
3025 application.SendNotification();
3026 application.Render();
3028 tet_infoline("Ensure texture is not generated yet");
3029 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3030 textureTrace.Reset();
3032 tet_infoline("Register visuals with control and ensure it has the only handles");
3033 DummyControl actor = DummyControl::New(true);
3034 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3035 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3036 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3038 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3039 application.GetScene().Add(actor);
3040 tet_infoline("Allow image time to load");
3041 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3043 application.SendNotification();
3044 application.Render();
3046 tet_infoline("Ensure texture generated and renderer created");
3047 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3048 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3050 // Ensure texture is delete when no longer needed
3051 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3053 application.SendNotification();
3054 application.Render();
3056 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3057 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3062 int UtcDaliImageVisualLoadPolicy03(void)
3064 ToolkitTestApplication application;
3065 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3067 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3069 // Set up trace debug
3070 TestGlAbstraction& gl = application.GetGlAbstraction();
3071 TraceCallStack& textureTrace = gl.GetTextureTrace();
3072 textureTrace.Enable(true);
3074 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3075 DummyControl actor = DummyControl::New(true);
3076 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3077 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3078 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3080 tet_infoline("Create visual with IMMEDIATE load policy");
3081 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3083 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3084 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3085 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3087 tet_infoline("Allow image time to load resource");
3088 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3089 application.SendNotification();
3090 application.Render();
3092 // Ensure texture has been uploaded
3093 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3094 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3099 int UtcDaliImageVisualLoadPolicy04(void)
3101 ToolkitTestApplication application;
3102 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3103 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3105 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3107 // Set up trace debug
3108 TestGlAbstraction& gl = application.GetGlAbstraction();
3109 TraceCallStack& textureTrace = gl.GetTextureTrace();
3110 textureTrace.Enable(true);
3112 tet_infoline("Create a control and connect to resource ready signal");
3113 DummyControl actor = DummyControl::New(true);
3114 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3115 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3116 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3118 tet_infoline("Create visual with IMMEDIATE load policy");
3119 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3121 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3122 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3123 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3125 tet_infoline("Allow image time to load");
3126 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3127 application.SendNotification();
3128 application.Render();
3130 tet_infoline("Testing texture is loaded and resource ready signal fired");
3131 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3132 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3134 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3136 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3137 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3138 DummyControl actor2 = DummyControl::New(true);
3139 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3140 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3142 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3143 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3144 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3145 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3146 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3147 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3152 int UtcDaliImageVisualLoadPolicy05(void)
3154 ToolkitTestApplication application;
3155 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3156 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3157 // Set up trace debug
3158 TestGlAbstraction& gl = application.GetGlAbstraction();
3159 TraceCallStack& textureTrace = gl.GetTextureTrace();
3160 textureTrace.Enable(true);
3162 tet_infoline("Create a control and connect to resource ready signal");
3163 DummyControl actor = DummyControl::New(true);
3164 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3165 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3166 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3167 application.GetScene().Add(actor);
3169 tet_infoline("Create visual with ATTACHED load policy");
3170 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3172 tet_infoline("Registering visual allows control to get a signal once loaded");
3173 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3174 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3176 tet_infoline("Allow image time to load");
3177 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3178 application.SendNotification();
3179 application.Render();
3181 tet_infoline("Testing texture is loaded and resource ready signal fired");
3182 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3183 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3185 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3187 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3188 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3189 DummyControl actor2 = DummyControl::New(true);
3190 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3191 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3193 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3194 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3195 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3196 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3197 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3198 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3203 int UtcDaliImageVisualOrientationCorrection(void)
3205 ToolkitTestApplication application;
3206 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3208 VisualFactory factory = VisualFactory::Get();
3209 tet_infoline("Create visual with Orientation correction set OFF");
3210 Property::Map propertyMap;
3211 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3212 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3213 propertyMap.Insert("orientationCorrection", false);
3214 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3216 tet_infoline("Create control for visual, need to loaded it");
3217 DummyControl actor = DummyControl::New(true);
3218 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3219 application.GetScene().Add(actor);
3221 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3222 // Wait for image to load
3223 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3225 Vector2 originalImageSize;
3226 tet_infoline("Get size of original visual to compare later with rotated image");
3227 imageVisual.GetNaturalSize(originalImageSize);
3228 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3229 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3230 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3231 application.SendNotification();
3232 application.Render();
3234 tet_infoline("Create visual with Orientation correction set ON ");
3235 propertyMap.Clear();
3236 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3237 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3238 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3239 imageVisual = factory.CreateVisual(propertyMap);
3241 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3242 // Wait for image to load
3243 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3245 Vector2 rotatedImageSize;
3246 imageVisual.GetNaturalSize(rotatedImageSize);
3247 tet_infoline("Confirm that visual has rotated");
3248 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3249 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3251 Property::Map resultMap;
3252 imageVisual.CreatePropertyMap(resultMap);
3254 // check the Property::ORIENTATION_CORRECTION value from the returned map
3255 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3256 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3261 int UtcDaliImageVisualCustomShader(void)
3263 ToolkitTestApplication application;
3264 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3266 VisualFactory factory = VisualFactory::Get();
3267 Property::Map properties;
3268 Property::Map shader;
3269 const std::string vertexShader = "Foobar";
3270 const std::string fragmentShader = "Foobar";
3271 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3272 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3274 properties[Visual::Property::TYPE] = Visual::IMAGE;
3275 properties[Visual::Property::SHADER] = shader;
3276 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3278 Visual::Base visual = factory.CreateVisual(properties);
3280 // trigger creation through setting on stage
3281 DummyControl dummy = DummyControl::New(true);
3282 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3283 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3285 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3286 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3287 application.GetScene().Add(dummy);
3289 application.SendNotification();
3290 application.Render();
3292 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3294 Renderer renderer = dummy.GetRendererAt(0);
3295 Shader shader2 = renderer.GetShader();
3296 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3297 Property::Map* map = value.GetMap();
3298 DALI_TEST_CHECK(map);
3300 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3301 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3303 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3304 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3308 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3309 properties[Visual::Property::SHADER] = shader;
3311 Visual::Base visual1 = factory.CreateVisual(properties);
3313 // trigger creation through setting on stage
3314 DummyControl dummy1 = DummyControl::New(true);
3315 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3316 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3317 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3318 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3319 application.GetScene().Add(dummy1);
3321 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3322 glAbstraction.EnableEnableDisableCallTrace(true);
3324 application.SendNotification();
3325 application.Render();
3327 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3328 std::ostringstream blendStr;
3329 blendStr << std::hex << GL_BLEND;
3330 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3335 void ResourceReadyLoadNext(Control control)
3337 static int callNumber = 0;
3339 gResourceReadySignalFired = true;
3340 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3344 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3346 tet_infoline("Create visual with loaded image from within the signal handler");
3347 VisualFactory factory = VisualFactory::Get();
3348 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3350 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3351 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3356 tet_infoline("3rd signal called");
3357 DALI_TEST_CHECK(true);
3361 int UtcDaliImageVisualLoadReady01(void)
3363 ToolkitTestApplication application;
3364 tet_infoline("UtcDaliImageVisualLoadReady01");
3365 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3366 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3367 tet_infoline("Should get a ready signal for all three visuals");
3371 tet_infoline("Create a control and connect to resource ready signal");
3372 DummyControl actor = DummyControl::New(true);
3373 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3374 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3375 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3376 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3377 application.GetScene().Add(actor);
3379 tet_infoline("Create visual with IMMEDIATE load policy");
3380 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3382 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3383 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3385 tet_infoline("Allow image time to load");
3386 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3387 application.SendNotification();
3388 application.Render();
3390 tet_infoline("Testing texture is loaded and resource ready signal fired");
3391 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3392 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3394 tet_infoline("Original control correctly signalled, now testing failing image");
3396 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3399 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3401 DummyControl actor2 = DummyControl::New(true);
3402 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3403 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3404 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3406 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3407 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3409 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3410 application.GetScene().Add(actor2);
3412 tet_infoline("Wait for loading thread to finish");
3413 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3414 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3416 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3418 tet_infoline("Check for 3rd signal");
3419 application.SendNotification();
3420 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3421 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3426 int UtcDaliImageVisualLoadImagePlanes01(void)
3428 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3429 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3431 ToolkitTestApplication application;
3433 VisualFactory factory = VisualFactory::Get();
3434 DALI_TEST_CHECK(factory);
3436 Property::Map propertyMap;
3437 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3438 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3440 Visual::Base visual = factory.CreateVisual(propertyMap);
3441 DALI_TEST_CHECK(visual);
3443 DummyControl actor = DummyControl::New();
3444 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3445 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3446 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3447 application.GetScene().Add(actor);
3449 application.SendNotification();
3450 application.Render();
3452 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3454 TestGlAbstraction& gl = application.GetGlAbstraction();
3455 TraceCallStack& textureTrace = gl.GetTextureTrace();
3456 textureTrace.Enable(true);
3458 application.SendNotification();
3459 application.Render();
3461 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3462 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3463 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3465 Renderer renderer = actor.GetRendererAt(0);
3466 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3467 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3472 int UtcDaliImageVisualLoadImagePlanes02(void)
3474 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3475 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3477 ToolkitTestApplication application;
3479 VisualFactory factory = VisualFactory::Get();
3480 DALI_TEST_CHECK(factory);
3482 // Alpha masking case - not support yuv planes
3483 Property::Map propertyMap;
3484 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3485 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3486 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3488 Visual::Base visual = factory.CreateVisual(propertyMap);
3489 DALI_TEST_CHECK(visual);
3491 DummyControl actor = DummyControl::New();
3492 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3493 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3494 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3495 application.GetScene().Add(actor);
3497 application.SendNotification();
3498 application.Render();
3500 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3502 TestGlAbstraction& gl = application.GetGlAbstraction();
3503 TraceCallStack& textureTrace = gl.GetTextureTrace();
3504 textureTrace.Enable(true);
3506 application.SendNotification();
3507 application.Render();
3509 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3510 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3511 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3516 int UtcDaliImageVisualLoadImagePlanes03(void)
3518 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3519 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3521 ToolkitTestApplication application;
3523 VisualFactory factory = VisualFactory::Get();
3524 DALI_TEST_CHECK(factory);
3526 TestGlAbstraction& gl = application.GetGlAbstraction();
3527 TraceCallStack& textureTrace = gl.GetTextureTrace();
3528 textureTrace.Enable(true);
3530 Property::Map propertyMap;
3531 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3532 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3533 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3535 Visual::Base visual = factory.CreateVisual(propertyMap);
3536 DALI_TEST_CHECK(visual);
3538 DummyControl actor = DummyControl::New();
3539 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3540 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3541 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3542 application.GetScene().Add(actor);
3544 application.SendNotification();
3545 application.Render();
3547 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3548 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3549 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);