2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <dali-toolkit-test-suite-utils.h>
26 #include <toolkit-environment-variable.h>
27 #include <toolkit-event-thread-callback.h>
28 #include <toolkit-style-monitor.h>
29 #include <toolkit-texture-upload-manager.h>
30 #include <toolkit-timer.h>
32 #include <dali-toolkit/dali-toolkit.h>
33 #include <dali-toolkit/devel-api/controls/control-devel.h>
34 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
35 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
36 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
37 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
38 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
39 #include <dali-toolkit/public-api/image-loader/image-url.h>
40 #include <dali-toolkit/public-api/image-loader/image.h>
42 #include <dali/devel-api/adaptor-framework/texture-upload-manager.h>
44 #include "dummy-control.h"
45 #include "test-encoded-image-buffer.h"
46 #include "test-native-image-source.h"
49 using namespace Dali::Toolkit;
51 void dali_image_visual_startup(void)
53 test_return_value = TET_UNDEF;
56 void dali_image_visual_cleanup(void)
58 test_return_value = TET_PASS;
63 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
64 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
65 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
66 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
67 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
68 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
69 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
70 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
71 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
72 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
73 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
75 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
76 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
78 constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER";
80 constexpr auto DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV = "DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME";
82 const char* VALID_DEBUG_SHADER_SCRIPT =
84 " \"maximumColorRate\": 0.5,\n"
85 " \"redChannelCodes\":\n"
87 " \"triggerCode\":[\"return\",\" false;\"],\n"
88 " \"ratioCode\":\"return 0.0;\"\n"
92 constexpr std::string_view THROW_EXCEPTION_STYLE_FILE_NAME = "throwException";
94 bool gResourceReadySignalFired = false;
95 std::vector<int> gReadyIds = {};
96 void ResourceReadySignal(Control control)
98 gResourceReadySignalFired = true;
99 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
106 Actor CreateActorWithImageVisual(const Property::Map& map)
108 VisualFactory factory = VisualFactory::Get();
109 DummyControl actor = DummyControl::New();
110 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
111 Visual::Base visual = factory.CreateVisual(map);
112 DALI_TEST_CHECK(visual);
113 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
114 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
115 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
119 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
121 VisualFactory factory = VisualFactory::Get();
123 Property::Map propertyMap;
124 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
125 propertyMap.Insert(ImageVisual::Property::URL, url);
126 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
127 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
128 propertyMap.Insert(key, value);
130 return factory.CreateVisual(propertyMap);
135 void TestVisualRender(ToolkitTestApplication& application,
137 Visual::Base& visual,
138 std::size_t expectedSamplers = 0,
139 ImageDimensions imageDimensions = ImageDimensions(),
140 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
142 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
143 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
147 // set the image size, for test case, this needs to be set before loading started
148 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
151 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
152 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
154 application.GetScene().Add(actor);
156 application.SendNotification(); // Send messages to update
157 application.Render(); // process update and render
158 application.SendNotification(); // process any signals to event
162 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
165 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
168 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
171 visual.CreatePropertyMap(map);
172 Property::Value* value = map.Find(mixColorIndex);
173 DALI_TEST_CHECK(value);
175 DALI_TEST_CHECK(value->Get(mixColor1));
176 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
178 value = map.Find(Visual::Property::MIX_COLOR);
179 DALI_TEST_CHECK(value);
181 DALI_TEST_CHECK(value->Get(mixColor2));
182 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
184 value = map.Find(Visual::Property::OPACITY);
185 DALI_TEST_CHECK(value);
187 DALI_TEST_CHECK(value->Get(opacity));
188 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
191 int UtcDaliImageVisualPropertyMap(void)
193 ToolkitTestApplication application;
194 tet_infoline("Request image visual with a Property::Map");
196 VisualFactory factory = VisualFactory::Get();
197 DALI_TEST_CHECK(factory);
198 factory.SetPreMultiplyOnLoad(true);
200 Property::Map propertyMap;
201 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
202 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
204 Visual::Base visual = factory.CreateVisual(propertyMap);
205 DALI_TEST_CHECK(visual);
207 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
208 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
210 TestGlAbstraction& gl = application.GetGlAbstraction();
211 TraceCallStack& textureTrace = gl.GetTextureTrace();
212 textureTrace.Enable(true);
214 DummyControl actor = DummyControl::New();
215 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
216 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
218 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
219 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
221 application.GetScene().Add(actor);
222 application.SendNotification();
223 application.Render();
225 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
227 application.SendNotification();
228 application.Render();
230 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
231 auto renderer = actor.GetRendererAt(0);
232 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
233 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
234 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
235 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
236 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
237 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
238 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
240 application.GetScene().Remove(actor);
241 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
246 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
248 ToolkitTestApplication application;
249 tet_infoline("Request image visual without pre-multiplied alpha");
251 VisualFactory factory = VisualFactory::Get();
252 DALI_TEST_CHECK(factory);
253 factory.SetPreMultiplyOnLoad(false);
255 Property::Map propertyMap;
256 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
257 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
259 Visual::Base visual = factory.CreateVisual(propertyMap);
260 DALI_TEST_CHECK(visual);
262 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
263 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
265 TestGlAbstraction& gl = application.GetGlAbstraction();
266 TraceCallStack& textureTrace = gl.GetTextureTrace();
267 textureTrace.Enable(true);
269 DummyControl actor = DummyControl::New();
270 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
271 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
273 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
274 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
276 application.GetScene().Add(actor);
277 application.SendNotification();
278 application.Render();
280 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
282 application.SendNotification();
283 application.Render();
285 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
286 auto renderer = actor.GetRendererAt(0);
287 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
288 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
289 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
290 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
292 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
293 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
295 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
297 application.GetScene().Remove(actor);
298 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
303 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
305 ToolkitTestApplication application;
306 tet_infoline("Request image visual with no alpha channel");
308 VisualFactory factory = VisualFactory::Get();
309 DALI_TEST_CHECK(factory);
311 Property::Map propertyMap;
312 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
313 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
315 Visual::Base visual = factory.CreateVisual(propertyMap);
316 DALI_TEST_CHECK(visual);
318 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
319 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
321 TestGlAbstraction& gl = application.GetGlAbstraction();
322 TraceCallStack& textureTrace = gl.GetTextureTrace();
323 textureTrace.Enable(true);
325 DummyControl actor = DummyControl::New();
326 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
327 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
329 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
330 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
332 application.GetScene().Add(actor);
333 application.SendNotification();
334 application.Render();
336 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
338 application.SendNotification();
339 application.Render();
341 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
342 auto renderer = actor.GetRendererAt(0);
343 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
344 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
345 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
346 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
348 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
349 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
351 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
353 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
354 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
355 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
356 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
357 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
358 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
359 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
360 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
362 textureTrace.Reset();
364 // Make a new visual with the same image
365 Visual::Base newVisual = factory.CreateVisual(propertyMap);
366 DALI_TEST_CHECK(newVisual);
368 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
369 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
371 DummyControl newActor = DummyControl::New();
372 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
373 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
375 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
376 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
378 application.GetScene().Add(newActor);
380 application.SendNotification();
381 application.Render();
383 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
384 auto newRenderer = newActor.GetRendererAt(0);
385 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
386 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
387 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
388 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
390 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
391 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
393 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
394 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
395 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
396 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
397 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
398 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
399 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
400 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
402 application.GetScene().Remove(actor);
403 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
408 int UtcDaliImageVisualRemoteImageLoad(void)
410 ToolkitTestApplication application;
411 tet_infoline("Request remote image visual with a Property::Map");
413 VisualFactory factory = VisualFactory::Get();
414 DALI_TEST_CHECK(factory);
416 Property::Map propertyMap;
417 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
418 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
420 Visual::Base visual = factory.CreateVisual(propertyMap);
421 DALI_TEST_CHECK(visual);
423 TestGlAbstraction& gl = application.GetGlAbstraction();
424 TraceCallStack& textureTrace = gl.GetTextureTrace();
425 textureTrace.Enable(true);
427 DummyControl actor = DummyControl::New();
428 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
429 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
431 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
432 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
434 application.GetScene().Add(actor);
435 application.SendNotification();
437 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
439 application.SendNotification();
440 application.Render();
442 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
443 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
445 application.GetScene().Remove(actor);
446 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
451 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
453 ToolkitTestApplication application;
454 tet_infoline("Use FrameBuffer as url");
458 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
460 DALI_TEST_CHECK(frameBuffer);
461 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
462 std::string url = imageUrl.GetUrl();
464 VisualFactory factory = VisualFactory::Get();
465 DALI_TEST_CHECK(factory);
467 Property::Map propertyMap;
468 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
469 propertyMap.Insert(ImageVisual::Property::URL, url);
471 Visual::Base visual = factory.CreateVisual(propertyMap);
472 DALI_TEST_CHECK(visual);
474 DummyControl actor = DummyControl::New();
475 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
476 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
478 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
480 application.GetScene().Add(actor);
482 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
484 application.SendNotification();
485 application.Render(16);
487 Renderer renderer = actor.GetRendererAt(0);
489 // Check whether preMultipliedAlpha is true.
490 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
491 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
496 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
498 ToolkitTestApplication application;
499 tet_infoline("Use FrameBuffer as url");
503 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
505 DALI_TEST_CHECK(frameBuffer);
507 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
508 frameBuffer.AttachColorTexture(texture);
510 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
511 std::string url = imageUrl.GetUrl();
513 VisualFactory factory = VisualFactory::Get();
514 DALI_TEST_CHECK(factory);
516 Property::Map propertyMap;
517 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
518 propertyMap.Insert(ImageVisual::Property::URL, url);
520 Visual::Base visual = factory.CreateVisual(propertyMap);
521 DALI_TEST_CHECK(visual);
523 DummyControl actor = DummyControl::New();
524 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
525 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
527 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
529 application.GetScene().Add(actor);
531 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
533 application.SendNotification();
534 application.Render(16);
536 Renderer renderer = actor.GetRendererAt(0);
538 // Check whether preMultipliedAlpha is true.
539 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
540 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
545 int UtcDaliImageVisualWithPixelData(void)
547 ToolkitTestApplication application;
548 tet_infoline("Use PixelData as url");
552 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
554 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
555 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
557 DALI_TEST_CHECK(pixelData);
559 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
560 std::string url = imageUrl.GetUrl();
562 VisualFactory factory = VisualFactory::Get();
563 DALI_TEST_CHECK(factory);
565 Property::Map propertyMap;
566 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
567 propertyMap.Insert(ImageVisual::Property::URL, url);
569 Visual::Base visual = factory.CreateVisual(propertyMap);
570 DALI_TEST_CHECK(visual);
572 DummyControl actor = DummyControl::New();
573 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
574 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
576 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
578 application.GetScene().Add(actor);
580 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
582 application.SendNotification();
583 application.Render(16);
585 Renderer renderer = actor.GetRendererAt(0);
587 // Check whether preMultipliedAlpha is false.
588 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
589 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
594 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
596 ToolkitTestApplication application;
597 tet_infoline("Use PixelData as url");
601 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
603 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
604 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
606 DALI_TEST_CHECK(pixelData);
608 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
609 std::string url = imageUrl.GetUrl();
611 VisualFactory factory = VisualFactory::Get();
612 DALI_TEST_CHECK(factory);
614 Property::Map propertyMap;
615 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
616 propertyMap.Insert(ImageVisual::Property::URL, url);
618 Visual::Base visual = factory.CreateVisual(propertyMap);
619 DALI_TEST_CHECK(visual);
621 DummyControl actor = DummyControl::New();
622 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
623 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
625 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
627 application.GetScene().Add(actor);
629 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
631 application.SendNotification();
632 application.Render(16);
634 Renderer renderer = actor.GetRendererAt(0);
636 // Check whether preMultipliedAlpha is true.
637 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
638 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
643 int UtcDaliImageVisualWithPixelDataMasking(void)
645 ToolkitTestApplication application;
646 tet_infoline("Load external texture with mask");
648 TestGlAbstraction& gl = application.GetGlAbstraction();
649 TraceCallStack& textureTrace = gl.GetTextureTrace();
650 textureTrace.Enable(true);
654 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
656 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
657 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
659 DALI_TEST_CHECK(pixelData);
661 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
662 std::string url = imageUrl.GetUrl();
664 VisualFactory factory = VisualFactory::Get();
665 DALI_TEST_CHECK(factory);
667 Property::Map propertyMap;
668 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
669 propertyMap.Insert(ImageVisual::Property::URL, url);
670 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
672 Visual::Base visual = factory.CreateVisual(propertyMap);
673 DALI_TEST_CHECK(visual);
675 Property::Map testMap;
676 visual.CreatePropertyMap(testMap);
677 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
679 DummyControl actor = DummyControl::New();
680 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
681 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
683 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
685 application.GetScene().Add(actor);
686 application.SendNotification();
687 application.Render(16);
688 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
690 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
691 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
692 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
694 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
695 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
700 int UtcDaliImageVisualWithPixelDataMasking02(void)
702 ToolkitTestApplication application;
703 tet_infoline("Load premultiplied external texture with mask");
705 TestGlAbstraction& gl = application.GetGlAbstraction();
706 TraceCallStack& textureTrace = gl.GetTextureTrace();
707 textureTrace.Enable(true);
711 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
713 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
714 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
716 DALI_TEST_CHECK(pixelData);
718 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
719 std::string url = imageUrl.GetUrl();
721 VisualFactory factory = VisualFactory::Get();
722 DALI_TEST_CHECK(factory);
724 Property::Map propertyMap;
725 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
726 propertyMap.Insert(ImageVisual::Property::URL, url);
727 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
729 Visual::Base visual = factory.CreateVisual(propertyMap);
730 DALI_TEST_CHECK(visual);
732 Property::Map testMap;
733 visual.CreatePropertyMap(testMap);
734 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
736 DummyControl actor = DummyControl::New();
737 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
738 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
740 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
742 application.GetScene().Add(actor);
743 application.SendNotification();
744 application.Render(16);
745 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
747 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
748 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
749 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
751 Renderer renderer = actor.GetRendererAt(0);
753 //Check visual property
754 DALI_TEST_EQUALS(*testMap.Find(Visual::Property::PREMULTIPLIED_ALPHA), Property::Value(true), TEST_LOCATION);
756 // Check whether preMultipliedAlpha is true.
757 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
758 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
760 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
761 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
766 int UtcDaliImageVisualWithPixelDataMaskingSynchronously(void)
768 ToolkitTestApplication application;
769 tet_infoline("Load synchronously external texture with mask");
773 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
775 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
776 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
778 DALI_TEST_CHECK(pixelData);
780 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
781 std::string url = imageUrl.GetUrl();
783 VisualFactory factory = VisualFactory::Get();
784 DALI_TEST_CHECK(factory);
786 Property::Map propertyMap;
787 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
788 propertyMap.Insert(ImageVisual::Property::URL, url);
789 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
790 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
792 Visual::Base visual = factory.CreateVisual(propertyMap);
793 DALI_TEST_CHECK(visual);
795 Property::Map testMap;
796 visual.CreatePropertyMap(testMap);
797 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
799 DummyControl actor = DummyControl::New();
800 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
801 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
803 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
805 application.GetScene().Add(actor);
807 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
809 application.SendNotification();
810 application.Render(16);
815 int UtcDaliImageVisualWithNativeImage(void)
817 ToolkitTestApplication application;
818 tet_infoline("Use Native Image as url");
820 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
821 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
822 std::string url = imageUrl.GetUrl();
824 VisualFactory factory = VisualFactory::Get();
825 DALI_TEST_CHECK(factory);
827 Property::Map propertyMap;
828 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
829 propertyMap.Insert(ImageVisual::Property::URL, url);
831 Visual::Base visual = factory.CreateVisual(propertyMap);
832 DALI_TEST_CHECK(visual);
834 DummyControl actor = DummyControl::New();
835 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
836 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
838 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
840 application.GetScene().Add(actor);
842 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
844 application.SendNotification();
845 application.Render(16);
847 Renderer renderer = actor.GetRendererAt(0);
848 Shader shader = renderer.GetShader();
850 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
851 DALI_TEST_CHECK(value.GetType() == Property::MAP);
852 const Property::Map* outMap = value.GetMap();
853 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
855 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
856 size_t pos = fragmentShader.find(fragmentPrefix);
858 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
860 // Check whether preMultipliedAlpha is false.
861 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
862 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
867 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
869 ToolkitTestApplication application;
870 tet_infoline("Use Native Image as url");
872 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
873 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
874 std::string url = imageUrl.GetUrl();
876 VisualFactory factory = VisualFactory::Get();
877 DALI_TEST_CHECK(factory);
879 Property::Map propertyMap;
880 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
881 propertyMap.Insert(ImageVisual::Property::URL, url);
883 Visual::Base visual = factory.CreateVisual(propertyMap);
884 DALI_TEST_CHECK(visual);
886 DummyControl actor = DummyControl::New();
887 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
888 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
890 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
892 application.GetScene().Add(actor);
894 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
896 application.SendNotification();
897 application.Render(16);
899 Renderer renderer = actor.GetRendererAt(0);
900 Shader shader = renderer.GetShader();
902 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
903 DALI_TEST_CHECK(value.GetType() == Property::MAP);
904 const Property::Map* outMap = value.GetMap();
905 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
907 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
908 size_t pos = fragmentShader.find(fragmentPrefix);
910 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
912 // Check whether preMultipliedAlpha is true.
913 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
914 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
919 int UtcDaliImageVisualWithNativeImageCustomShader(void)
921 ToolkitTestApplication application;
922 tet_infoline("Use Native Image as url and Use custom shader");
924 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
925 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
926 std::string url = imageUrl.GetUrl();
928 VisualFactory factory = VisualFactory::Get();
929 DALI_TEST_CHECK(factory);
931 Property::Map propertyMap;
932 Property::Map shaderMap;
933 const std::string customVertexShaderSource = "Foobar";
934 const std::string customFragmentShaderSource = "Foobar";
935 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
936 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
938 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
939 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
940 propertyMap.Insert(ImageVisual::Property::URL, url);
942 Visual::Base visual = factory.CreateVisual(propertyMap);
943 DALI_TEST_CHECK(visual);
945 DummyControl actor = DummyControl::New();
946 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
947 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
949 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
950 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
952 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
954 application.GetScene().Add(actor);
956 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
958 application.SendNotification();
959 application.Render(16);
961 Renderer renderer = actor.GetRendererAt(0);
962 Shader shader = renderer.GetShader();
964 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
965 DALI_TEST_CHECK(value.GetType() == Property::MAP);
966 const Property::Map* outMap = value.GetMap();
967 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
968 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
970 // Compare vertex shader is equal
971 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
973 // Check fragment shader changed
974 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
975 size_t pos = fragmentShaderSource.find(fragmentPrefix);
977 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
979 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
981 // Check whether preMultipliedAlpha is false.
982 // Note : We dont use preMultiplied alpha when app developer using custom shader.
983 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
984 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
989 int UtcDaliImageVisualWithNativeImageRemoved(void)
991 ToolkitTestApplication application;
992 tet_infoline("Use Native Image as url");
994 TestGlAbstraction& gl = application.GetGlAbstraction();
995 TraceCallStack& textureTrace = gl.GetTextureTrace();
996 textureTrace.Enable(true);
998 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
999 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
1000 std::string url = imageUrl.GetUrl();
1002 VisualFactory factory = VisualFactory::Get();
1003 DALI_TEST_CHECK(factory);
1005 Property::Map propertyMap;
1006 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1007 propertyMap.Insert(ImageVisual::Property::URL, url);
1009 Visual::Base visual = factory.CreateVisual(propertyMap);
1010 DALI_TEST_CHECK(visual);
1012 DummyControl actor = DummyControl::New();
1013 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1014 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1016 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1018 application.GetScene().Add(actor);
1019 application.SendNotification();
1020 application.Render();
1022 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1023 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1025 tet_infoline("No delete texture because reference count is not zero");
1027 application.GetScene().Remove(actor);
1028 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1029 application.SendNotification();
1030 application.Render();
1032 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1033 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1035 tet_infoline("Delete texture because reference count is zero");
1037 application.SendNotification();
1038 application.Render();
1040 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1045 int UtcDaliImageVisualWithEncodedImageBuffer(void)
1047 ToolkitTestApplication application;
1048 tet_infoline("Use Encoded Image Buffer as url");
1050 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1051 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1053 VisualFactory factory = VisualFactory::Get();
1054 DALI_TEST_CHECK(factory);
1056 Property::Map propertyMap;
1057 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1058 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
1060 Visual::Base visual = factory.CreateVisual(propertyMap);
1061 DALI_TEST_CHECK(visual);
1063 TestGlAbstraction& gl = application.GetGlAbstraction();
1064 TraceCallStack& textureTrace = gl.GetTextureTrace();
1065 textureTrace.Enable(true);
1067 DummyControl actor = DummyControl::New();
1068 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1069 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1071 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1072 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1074 application.GetScene().Add(actor);
1075 application.SendNotification();
1077 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1079 application.SendNotification();
1080 application.Render();
1082 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1083 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1085 application.GetScene().Remove(actor);
1086 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1091 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
1093 ToolkitTestApplication application;
1094 tet_infoline("Use Encoded Image Buffer as url");
1096 TestGlAbstraction& gl = application.GetGlAbstraction();
1097 TraceCallStack& textureTrace = gl.GetTextureTrace();
1098 textureTrace.Enable(true);
1100 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1101 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1102 std::string url = imageUrl.GetUrl();
1104 VisualFactory factory = VisualFactory::Get();
1105 DALI_TEST_CHECK(factory);
1107 Property::Map propertyMap;
1108 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1109 propertyMap.Insert(ImageVisual::Property::URL, url);
1111 Visual::Base visual = factory.CreateVisual(propertyMap);
1112 DALI_TEST_CHECK(visual);
1114 DummyControl actor = DummyControl::New();
1115 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1116 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1118 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1120 application.GetScene().Add(actor);
1121 application.SendNotification();
1123 // Wait for decode buffer and make texture.
1124 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1126 application.SendNotification();
1127 application.Render();
1129 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1130 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1132 tet_infoline("Delete texture because there is no actor to use decoded texture");
1134 application.GetScene().Remove(actor);
1135 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1136 application.SendNotification();
1137 application.Render();
1139 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1140 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1145 int UtcDaliImageVisualTextureReuse1(void)
1147 ToolkitTestApplication application;
1148 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
1150 Property::Map propertyMap;
1151 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1152 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1153 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1155 TestGlAbstraction& gl = application.GetGlAbstraction();
1156 TraceCallStack& textureTrace = gl.GetTextureTrace();
1157 textureTrace.Enable(true);
1158 TraceCallStack& drawTrace = gl.GetDrawTrace();
1159 drawTrace.Enable(true);
1161 Actor actor = CreateActorWithImageVisual(propertyMap);
1162 application.GetScene().Add(actor);
1163 application.SendNotification();
1165 // Wait for image to load
1166 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1168 application.SendNotification();
1169 application.Render();
1171 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1172 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1173 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1174 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1175 textureTrace.Reset();
1178 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1179 application.GetScene().Add(actor2);
1181 application.SendNotification(); // Send messages to update
1182 application.Render(); // process update and render
1183 application.SendNotification(); // process any signals to event
1185 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1187 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
1188 // backend here, but test graphics backend.
1189 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1190 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1192 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
1194 application.GetScene().Remove(actor);
1195 application.SendNotification();
1196 application.Render();
1198 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1199 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1201 tet_infoline("Test that removing last actor does delete the texture\n");
1203 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1204 application.SendNotification();
1205 application.Render();
1207 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1208 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1213 int UtcDaliImageVisualTextureReuse2(void)
1215 ToolkitTestApplication application;
1216 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");
1218 Property::Map propertyMap;
1219 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1220 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1222 TestGlAbstraction& gl = application.GetGlAbstraction();
1223 TraceCallStack& textureTrace = gl.GetTextureTrace();
1224 textureTrace.Enable(true);
1225 TraceCallStack& drawTrace = gl.GetDrawTrace();
1226 drawTrace.Enable(true);
1228 Actor actor = CreateActorWithImageVisual(propertyMap);
1229 application.GetScene().Add(actor);
1230 application.SendNotification();
1232 // Wait for image to load
1233 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1235 application.SendNotification();
1236 application.Render();
1238 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1239 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1240 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1241 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1242 textureTrace.Reset();
1245 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1246 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1247 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1248 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1249 application.GetScene().Add(actor2);
1251 application.SendNotification();
1253 // Wait for image to load
1254 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1256 application.SendNotification();
1257 application.Render();
1259 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1262 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1263 "renderers are using different textures\n");
1265 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1266 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1267 TraceCallStack::NamedParams tex1;
1268 tex1["texture"] << 1;
1269 TraceCallStack::NamedParams tex2;
1270 tex2["texture"] << 2;
1271 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1272 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1274 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1276 application.GetScene().Remove(actor);
1277 application.SendNotification();
1278 application.Render();
1280 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1281 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1283 tet_infoline("Test that removing last actor deletes it's texture\n");
1285 application.GetScene().Remove(actor2);
1286 application.SendNotification();
1287 application.Render();
1289 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1290 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1295 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1297 ToolkitTestApplication application;
1298 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1300 static std::vector<UniformData> customUniforms =
1302 UniformData("pixelArea", Property::Type::VECTOR4),
1303 UniformData("wrapMode", Property::Type::VECTOR2),
1306 TestGraphicsController& graphics = application.GetGraphicsController();
1307 graphics.AddCustomUniforms(customUniforms);
1309 VisualFactory factory = VisualFactory::Get();
1310 DALI_TEST_CHECK(factory);
1312 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1313 const int width = 34;
1314 const int height = 34;
1315 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1317 Property::Map propertyMap;
1318 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1319 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1320 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1321 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1322 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1323 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1324 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1325 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1326 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1328 Visual::Base visual = factory.CreateVisual(propertyMap);
1329 DALI_TEST_CHECK(visual);
1331 TestGlAbstraction& gl = application.GetGlAbstraction();
1332 TraceCallStack& textureTrace = gl.GetTextureTrace();
1333 textureTrace.Enable(true);
1334 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1335 texParameterTrace.Enable(true);
1337 DummyControl actor = DummyControl::New();
1338 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1339 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1340 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1341 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1342 application.GetScene().Add(actor);
1345 application.SendNotification();
1346 application.Render();
1348 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1350 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1352 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1353 std::stringstream out;
1354 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1355 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1357 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1358 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1360 // test the uniforms which used to handle the wrap mode
1361 Renderer renderer = actor.GetRendererAt(0u);
1362 DALI_TEST_CHECK(renderer);
1364 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1365 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1366 Vector4 pixelAreaUniform;
1367 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1368 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1370 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1371 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1372 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1373 Vector2 wrapModeUniform;
1374 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1375 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1378 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1383 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1385 ToolkitTestApplication application;
1386 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1388 static std::vector<UniformData> customUniforms =
1390 UniformData("pixelArea", Property::Type::VECTOR4),
1393 TestGraphicsController& graphics = application.GetGraphicsController();
1394 graphics.AddCustomUniforms(customUniforms);
1396 VisualFactory factory = VisualFactory::Get();
1397 DALI_TEST_CHECK(factory);
1399 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1400 const int width = 600;
1401 const int height = 600;
1402 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1404 Property::Map propertyMap;
1405 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1406 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1407 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1408 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1409 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1410 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1411 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1412 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1414 Visual::Base visual = factory.CreateVisual(propertyMap);
1415 DALI_TEST_CHECK(visual);
1417 TestGlAbstraction& gl = application.GetGlAbstraction();
1418 TraceCallStack& textureTrace = gl.GetTextureTrace();
1419 textureTrace.Enable(true);
1420 textureTrace.EnableLogging(true);
1421 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1422 texParameterTrace.Enable(true);
1423 texParameterTrace.EnableLogging(true);
1425 DummyControl actor = DummyControl::New();
1426 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1427 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1428 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1429 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1430 application.GetScene().Add(actor);
1433 application.SendNotification();
1434 application.Render();
1435 application.SendNotification();
1437 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1439 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1441 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1442 std::stringstream out;
1443 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1444 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1446 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1447 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1449 // test the uniforms which used to handle the wrap mode
1450 Renderer renderer = actor.GetRendererAt(0u);
1451 DALI_TEST_CHECK(renderer);
1453 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1454 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1455 Vector4 pixelAreaUniform;
1456 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1457 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1459 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1460 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1463 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1468 int UtcDaliImageVisualAnimateMixColor(void)
1470 ToolkitTestApplication application;
1471 tet_infoline("Animate mix color");
1473 static std::vector<UniformData> customUniforms =
1475 UniformData("mixColor", Property::Type::VECTOR3),
1478 TestGraphicsController& graphics = application.GetGraphicsController();
1479 graphics.AddCustomUniforms(customUniforms);
1481 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1483 VisualFactory factory = VisualFactory::Get();
1484 Property::Map propertyMap;
1485 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1486 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1487 propertyMap.Insert("mixColor", Color::BLUE);
1488 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1489 Visual::Base visual = factory.CreateVisual(propertyMap);
1491 DummyControl actor = DummyControl::New(true);
1492 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1493 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1495 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1496 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1497 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1498 application.GetScene().Add(actor);
1500 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1502 Renderer renderer = actor.GetRendererAt(0);
1504 // @todo Should we add API to make this code work again?
1505 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1507 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1508 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1510 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1513 map["target"] = "testVisual";
1514 map["property"] = "mixColor";
1515 map["initialValue"] = Color::MAGENTA;
1516 map["targetValue"] = TARGET_MIX_COLOR;
1517 map["animator"] = Property::Map()
1518 .Add("alphaFunction", "LINEAR")
1519 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1521 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1523 Animation animation = dummyImpl.CreateTransition(transition);
1525 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1528 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1529 glAbstraction.EnableEnableDisableCallTrace(true);
1530 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1531 std::ostringstream blendStr;
1532 blendStr << std::hex << GL_BLEND;
1534 application.SendNotification();
1535 application.Render(0); // Ensure animation starts
1536 application.Render(2000u); // Halfway point
1537 Vector3 testColor(1.0f, 0.0f, 0.5f);
1539 // uColor.a should be actor's alpha * mixColor.a.
1540 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1541 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1543 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1545 glEnableStack.Reset();
1547 application.SendNotification();
1548 application.Render(2000u);
1550 application.SendNotification();
1551 application.Render();
1552 application.SendNotification();
1554 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1555 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1556 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1558 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1560 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1565 int UtcDaliImageVisualAnimateOpacity(void)
1567 ToolkitTestApplication application;
1568 tet_infoline("Animate image visual opacity");
1570 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1572 VisualFactory factory = VisualFactory::Get();
1573 Property::Map propertyMap;
1574 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1575 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1576 propertyMap.Insert("opacity", 0.5f);
1577 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1578 Visual::Base visual = factory.CreateVisual(propertyMap);
1580 DummyControl actor = DummyControl::New(true);
1581 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1582 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1584 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1585 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1586 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1587 application.GetScene().Add(actor);
1589 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1591 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1592 glAbstraction.EnableEnableDisableCallTrace(true);
1593 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1594 std::ostringstream blendStr;
1595 blendStr << std::hex << GL_BLEND;
1597 application.SendNotification();
1598 application.Render();
1600 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1603 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.");
1606 map["target"] = "testVisual";
1607 map["property"] = "opacity";
1608 map["targetValue"] = 1.0f;
1609 map["animator"] = Property::Map()
1610 .Add("alphaFunction", "LINEAR")
1611 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1613 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1614 Animation animation = dummyImpl.CreateTransition(transition);
1617 glEnableStack.Reset();
1619 application.SendNotification();
1620 application.Render(0); // Ensure animation starts
1621 application.Render(2000u); // Halfway point through animation
1622 application.SendNotification(); // Handle any signals
1625 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1626 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1628 application.Render(2001u); // end
1629 application.SendNotification(); // ensure animation finished signal is sent
1631 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1632 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1634 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1635 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1639 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.");
1642 map["target"] = "testVisual";
1643 map["property"] = Visual::Property::OPACITY;
1644 map["targetValue"] = 0.1f;
1645 map["animator"] = Property::Map()
1646 .Add("alphaFunction", "LINEAR")
1647 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1649 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1650 Animation animation = dummyImpl.CreateTransition(transition);
1653 glEnableStack.Reset();
1655 application.SendNotification();
1656 application.Render(0); // Ensure animation starts
1657 application.Render(2000u); // Halfway point
1658 application.SendNotification();
1661 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1662 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1664 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1666 glEnableStack.Reset();
1668 application.Render(2016u); // end
1669 application.SendNotification();
1671 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1672 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1674 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1675 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1681 int UtcDaliImageVisualAnimateOpacity02(void)
1683 ToolkitTestApplication application;
1684 tet_infoline("Animate image visual opacity");
1686 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1688 VisualFactory factory = VisualFactory::Get();
1689 Property::Map propertyMap;
1690 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1691 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1692 propertyMap.Insert("opacity", 0.5f);
1693 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1694 Visual::Base visual = factory.CreateVisual(propertyMap);
1696 DummyControl actor = DummyControl::New(true);
1697 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1698 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1700 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1701 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1702 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1704 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1706 Property::Array array;
1709 map["target"] = "testVisual";
1710 map["property"] = "opacity";
1711 map["initialValue"] = 0.0f;
1712 map["targetValue"] = 1.0f;
1713 map["animator"] = Property::Map()
1714 .Add("alphaFunction", "LINEAR")
1715 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1718 map2["target"] = "testVisual";
1719 map2["property"] = "size";
1720 map2["targetValue"] = Vector2(1.0f, 1.0f);
1722 array.Add(map).Add(map2);
1724 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1725 Animation animation = dummyImpl.CreateTransition(transition);
1727 application.GetScene().Add(actor);
1728 application.SendNotification();
1729 application.Render(0); // Ensure animation starts
1731 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1733 Renderer renderer = actor.GetRendererAt(0);
1734 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1735 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1737 animation = dummyImpl.CreateTransition(transition);
1740 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1741 glAbstraction.EnableEnableDisableCallTrace(true);
1742 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1743 std::ostringstream blendStr;
1744 blendStr << std::hex << GL_BLEND;
1746 application.SendNotification();
1747 application.Render(0); // Ensure animation starts
1748 application.Render(2000u); // Halfway point through animation
1749 application.SendNotification(); // Handle any signals
1751 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1754 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1755 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1757 glEnableStack.Reset();
1759 application.Render(2001u); // end
1760 application.SendNotification(); // ensure animation finished signal is sent
1762 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1763 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1765 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1770 int UtcDaliImageVisualAnimatePixelArea(void)
1772 ToolkitTestApplication application;
1773 tet_infoline("ImageVisual animate pixel area");
1775 static std::vector<UniformData> customUniforms =
1777 UniformData("pixelArea", Property::Type::VECTOR4),
1780 TestGraphicsController& graphics = application.GetGraphicsController();
1781 graphics.AddCustomUniforms(customUniforms);
1783 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1785 VisualFactory factory = VisualFactory::Get();
1786 Property::Map propertyMap;
1787 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1788 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1789 propertyMap.Insert("mixColor", Color::BLUE);
1790 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1791 Visual::Base visual = factory.CreateVisual(propertyMap);
1793 DummyControl actor = DummyControl::New(true);
1794 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1795 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1797 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1798 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1799 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1800 application.GetScene().Add(actor);
1802 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1804 Renderer renderer = actor.GetRendererAt(0);
1805 // @todo Implement this feature?
1806 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1807 //tet_infoline("Test that the renderer has the mixColor property");
1808 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1810 // TransitionData only takes string keys
1812 map["target"] = "testVisual";
1813 map["property"] = "pixelArea";
1814 map["initialValue"] = Vector4(0, 0, 0, 1);
1815 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1816 map["animator"] = Property::Map()
1817 .Add("alphaFunction", "LINEAR")
1818 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1820 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1822 Animation animation = dummyImpl.CreateTransition(transition);
1823 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1826 application.SendNotification();
1827 application.Render(0); // Ensure animation starts
1828 application.Render(2000u); // Halfway point
1830 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1832 application.Render(2000u); // End of animation
1834 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1839 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1841 ToolkitTestApplication application;
1842 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1844 Property::Map propertyMap;
1845 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1846 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1848 TestGlAbstraction& gl = application.GetGlAbstraction();
1849 TraceCallStack& textureTrace = gl.GetTextureTrace();
1850 textureTrace.Enable(true);
1851 TraceCallStack& drawTrace = gl.GetDrawTrace();
1852 drawTrace.Enable(true);
1854 Actor actor = CreateActorWithImageVisual(propertyMap);
1855 application.GetScene().Add(actor);
1856 application.SendNotification();
1858 application.GetScene().Remove(actor);
1859 application.SendNotification();
1861 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1862 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1863 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1864 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1869 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1871 ToolkitTestApplication application;
1872 tet_infoline("Load image asynchronously, cancel loading, then load again");
1874 VisualFactory factory = VisualFactory::Get();
1875 DALI_TEST_CHECK(factory);
1877 Property::Map propertyMap;
1878 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1879 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1881 Visual::Base visual = factory.CreateVisual(propertyMap);
1882 DALI_TEST_CHECK(visual);
1884 TestGlAbstraction& gl = application.GetGlAbstraction();
1885 TraceCallStack& textureTrace = gl.GetTextureTrace();
1886 textureTrace.Enable(true);
1887 TraceCallStack& drawTrace = gl.GetDrawTrace();
1888 drawTrace.Enable(true);
1890 DummyControl actor = DummyControl::New();
1891 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1892 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1894 application.GetScene().Add(actor);
1897 application.GetScene().Remove(actor);
1899 application.GetScene().Add(actor);
1901 // Create another visual with the same image
1902 visual = factory.CreateVisual(propertyMap);
1903 DALI_TEST_CHECK(visual);
1905 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1907 application.SendNotification();
1908 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1910 application.SendNotification();
1911 application.Render();
1913 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1914 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1915 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1916 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1921 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1923 ToolkitTestApplication application;
1924 tet_infoline("Request image visual with invalid images - should draw broken.png");
1926 VisualFactory factory = VisualFactory::Get();
1927 DALI_TEST_CHECK(factory);
1929 Property::Map propertyMap;
1930 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1931 propertyMap.Insert(ImageVisual::Property::URL, TEST_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 UtcDaliImageVisualSetInvalidSyncImage(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 Property::Map propertyMap;
1973 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1974 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1975 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
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 application.Render();
1996 // Check resource status
1997 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1998 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
2000 // The broken image should be shown.
2001 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2002 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2004 application.GetScene().Remove(actor);
2005 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2010 int UtcDaliImageVisualSetInvalidRemoteImage(void)
2012 ToolkitTestApplication application;
2013 tet_infoline("Request image visual with invalid images - should draw broken.png");
2015 VisualFactory factory = VisualFactory::Get();
2016 DALI_TEST_CHECK(factory);
2018 // Local invalid file, asynchronous loading
2019 Property::Map propertyMap;
2020 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2021 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
2023 Visual::Base visual = factory.CreateVisual(propertyMap);
2024 DALI_TEST_CHECK(visual);
2026 TestGlAbstraction& gl = application.GetGlAbstraction();
2027 TraceCallStack& textureTrace = gl.GetTextureTrace();
2028 textureTrace.Enable(true);
2030 DummyControl actor = DummyControl::New();
2031 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2032 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2034 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2035 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2037 application.GetScene().Add(actor);
2039 application.SendNotification();
2040 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2042 application.SendNotification();
2043 application.Render();
2045 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2046 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2048 application.GetScene().Remove(actor);
2049 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2054 int UtcDaliImageVisualSetInvalidImageWithDisabledBroken(void)
2056 ToolkitTestApplication application;
2057 tet_infoline("Request image visual with invalid images - should draw broken.png");
2059 VisualFactory factory = VisualFactory::Get();
2060 DALI_TEST_CHECK(factory);
2062 // Load invalid file
2063 Property::Map propertyMap;
2064 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2065 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2067 Visual::Base visual = factory.CreateVisual(propertyMap);
2068 DALI_TEST_CHECK(visual);
2070 TestGlAbstraction& gl = application.GetGlAbstraction();
2071 TraceCallStack& textureTrace = gl.GetTextureTrace();
2072 textureTrace.Enable(true);
2074 DummyControl actor = DummyControl::New();
2075 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2076 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2078 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2079 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2081 application.GetScene().Add(actor);
2083 application.SendNotification();
2084 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2086 application.SendNotification();
2087 application.Render();
2089 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2090 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2092 application.GetScene().Remove(actor);
2093 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2094 textureTrace.Reset();
2096 // Load invalid file with disabled broken
2097 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2098 propertyMap.Insert(ImageVisual::Property::URL, "InvalidImage.png");
2099 propertyMap.Insert(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, false);
2101 visual = factory.CreateVisual(propertyMap);
2102 DALI_TEST_CHECK(visual);
2104 actor = DummyControl::New();
2105 DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor.GetImplementation());
2106 dummyImpl2.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2108 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2109 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2111 application.GetScene().Add(actor);
2113 application.SendNotification();
2114 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2116 application.SendNotification();
2117 application.Render();
2119 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2120 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
2122 application.GetScene().Remove(actor);
2123 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2128 int UtcDaliImageVisualAlphaMask01(void)
2130 ToolkitTestApplication application;
2131 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2133 VisualFactory factory = VisualFactory::Get();
2134 DALI_TEST_CHECK(factory);
2136 Property::Map propertyMap;
2137 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2138 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2139 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2141 Visual::Base visual = factory.CreateVisual(propertyMap);
2142 DALI_TEST_CHECK(visual);
2144 Property::Map testMap;
2145 visual.CreatePropertyMap(testMap);
2146 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2148 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2149 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2151 TestGlAbstraction& gl = application.GetGlAbstraction();
2152 TraceCallStack& textureTrace = gl.GetTextureTrace();
2153 textureTrace.Enable(true);
2155 DummyControl actor = DummyControl::New();
2156 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2157 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2159 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2160 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2161 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2163 application.GetScene().Add(actor);
2164 application.SendNotification();
2165 application.Render();
2167 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2169 application.SendNotification();
2170 application.Render();
2172 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2173 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2174 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2176 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2177 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2182 int UtcDaliImageVisualAlphaMask02(void)
2184 ToolkitTestApplication application;
2185 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2187 VisualFactory factory = VisualFactory::Get();
2188 DALI_TEST_CHECK(factory);
2190 Property::Map propertyMap;
2191 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2192 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2193 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2194 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2195 propertyMap.Insert(DevelImageVisual::Property::CROP_TO_MASK, false);
2197 Visual::Base visual = factory.CreateVisual(propertyMap);
2198 DALI_TEST_CHECK(visual);
2200 Property::Map testMap;
2201 visual.CreatePropertyMap(testMap);
2202 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2203 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2205 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2206 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2208 TestGlAbstraction& gl = application.GetGlAbstraction();
2209 TraceCallStack& textureTrace = gl.GetTextureTrace();
2210 textureTrace.Enable(true);
2212 DummyControl actor = DummyControl::New();
2213 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2214 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2216 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2217 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2218 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2220 application.GetScene().Add(actor);
2221 application.SendNotification();
2222 application.Render();
2224 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2226 application.SendNotification();
2227 application.Render();
2229 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2230 Renderer renderer = actor.GetRendererAt(0u);
2231 TextureSet textures = renderer.GetTextures();
2232 DALI_TEST_CHECK(textures);
2233 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2235 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2236 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2238 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2239 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2241 auto index = renderer.GetPropertyIndex("maskTextureRatio");
2242 DALI_TEST_NOT_EQUALS(index, Property::INVALID_INDEX, 0.1f, TEST_LOCATION);
2243 DALI_TEST_EQUALS(renderer.GetProperty<Vector2>(index), Vector2::ONE, TEST_LOCATION);
2248 int UtcDaliImageVisualAlphaMask03(void)
2250 ToolkitTestApplication application;
2251 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2253 VisualFactory factory = VisualFactory::Get();
2254 DALI_TEST_CHECK(factory);
2256 Property::Map propertyMap;
2257 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2258 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2259 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2260 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2262 Visual::Base visual = factory.CreateVisual(propertyMap);
2263 DALI_TEST_CHECK(visual);
2265 Property::Map testMap;
2266 visual.CreatePropertyMap(testMap);
2268 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2269 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2271 TestGlAbstraction& gl = application.GetGlAbstraction();
2272 TraceCallStack& textureTrace = gl.GetTextureTrace();
2273 textureTrace.Enable(true);
2275 DummyControl actor = DummyControl::New();
2276 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2277 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2279 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2280 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2281 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2283 application.GetScene().Add(actor);
2284 application.SendNotification();
2285 application.Render();
2287 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2289 application.SendNotification();
2290 application.Render();
2292 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2293 Renderer renderer = actor.GetRendererAt(0u);
2294 TextureSet textures = renderer.GetTextures();
2295 DALI_TEST_CHECK(textures);
2296 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2298 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2299 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2301 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2302 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2307 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2309 ToolkitTestApplication application;
2310 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2312 VisualFactory factory = VisualFactory::Get();
2313 DALI_TEST_CHECK(factory);
2315 Property::Map propertyMap;
2316 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2317 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2318 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2319 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2321 Visual::Base visual = factory.CreateVisual(propertyMap);
2322 DALI_TEST_CHECK(visual);
2324 Property::Map testMap;
2325 visual.CreatePropertyMap(testMap);
2326 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2328 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2329 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2331 TestGlAbstraction& gl = application.GetGlAbstraction();
2332 TraceCallStack& textureTrace = gl.GetTextureTrace();
2333 textureTrace.Enable(true);
2335 DummyControl actor = DummyControl::New();
2336 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2337 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2339 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2340 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2341 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2343 application.GetScene().Add(actor);
2345 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2347 application.SendNotification();
2348 application.Render();
2350 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2351 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2352 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2354 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2355 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2360 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2362 ToolkitTestApplication application;
2363 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2365 VisualFactory factory = VisualFactory::Get();
2366 DALI_TEST_CHECK(factory);
2368 Property::Map propertyMap;
2369 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2370 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2371 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2372 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2373 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2375 Visual::Base visual = factory.CreateVisual(propertyMap);
2376 DALI_TEST_CHECK(visual);
2378 Property::Map testMap;
2379 visual.CreatePropertyMap(testMap);
2380 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2382 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2383 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2385 TestGlAbstraction& gl = application.GetGlAbstraction();
2386 TraceCallStack& textureTrace = gl.GetTextureTrace();
2387 textureTrace.Enable(true);
2389 DummyControl actor = DummyControl::New();
2390 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2391 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2393 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2394 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2395 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2397 application.GetScene().Add(actor);
2399 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2401 application.SendNotification();
2402 application.Render();
2404 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2405 Renderer renderer = actor.GetRendererAt(0u);
2406 TextureSet textures = renderer.GetTextures();
2407 DALI_TEST_CHECK(textures);
2408 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2410 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2411 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2413 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2414 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2419 int UtcDaliImageVisualRemoteAlphaMask(void)
2421 ToolkitTestApplication application;
2422 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2424 VisualFactory factory = VisualFactory::Get();
2425 DALI_TEST_CHECK(factory);
2427 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2429 Property::Map propertyMap;
2430 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2431 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2432 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2434 Visual::Base visual = factory.CreateVisual(propertyMap);
2435 DALI_TEST_CHECK(visual);
2437 Property::Map testMap;
2438 visual.CreatePropertyMap(testMap);
2440 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2442 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2443 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2445 TestGlAbstraction& gl = application.GetGlAbstraction();
2446 TraceCallStack& textureTrace = gl.GetTextureTrace();
2447 textureTrace.Enable(true);
2449 DummyControl actor = DummyControl::New();
2450 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2451 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2453 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2455 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2456 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2458 application.GetScene().Add(actor);
2459 application.SendNotification();
2460 application.Render();
2462 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2464 application.SendNotification();
2465 application.Render();
2467 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2468 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2469 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2474 int UtcDaliImageVisualAlphaMaskCrop(void)
2476 ToolkitTestApplication application;
2477 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2479 VisualFactory factory = VisualFactory::Get();
2480 DALI_TEST_CHECK(factory);
2482 Property::Map propertyMap;
2483 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2484 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2485 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2486 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2487 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2489 Visual::Base visual = factory.CreateVisual(propertyMap);
2490 DALI_TEST_CHECK(visual);
2492 Property::Map testMap;
2493 visual.CreatePropertyMap(testMap);
2494 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2495 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2496 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2498 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2499 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2501 TestGlAbstraction& gl = application.GetGlAbstraction();
2502 TraceCallStack& textureTrace = gl.GetTextureTrace();
2503 textureTrace.Enable(true);
2505 DummyControl actor = DummyControl::New();
2506 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2507 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2509 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2510 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2511 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2513 application.GetScene().Add(actor);
2514 application.SendNotification();
2515 application.Render();
2517 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2519 application.SendNotification();
2520 application.Render();
2523 visual.GetNaturalSize(size);
2525 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2526 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2527 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2528 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2533 int UtcDaliImageVisualReleasePolicy01(void)
2535 ToolkitTestApplication application;
2536 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2538 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2539 DALI_TEST_CHECK(imageVisual);
2541 // Set up debug trace
2542 TestGlAbstraction& gl = application.GetGlAbstraction();
2543 TraceCallStack& textureTrace = gl.GetTextureTrace();
2544 textureTrace.Enable(true);
2546 tet_infoline("Register visual with control and ensure it has the only handle");
2547 DummyControl actor = DummyControl::New(true);
2548 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2549 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2550 imageVisual.Reset();
2552 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2554 application.SendNotification();
2555 application.Render(0);
2556 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2557 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2559 application.GetScene().Add(actor);
2561 // Wait for image to load
2562 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2564 application.SendNotification();
2565 application.Render(0);
2566 // Test renderer and texture created
2567 tet_infoline("Confirm texture created");
2568 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2569 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2571 tet_infoline("Disable visual causing the texture to be deleted");
2572 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2574 application.SendNotification();
2575 application.Render(0);
2576 // Test renderer and textures removed.
2577 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2578 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2583 int UtcDaliImageVisualReleasePolicy02(void)
2585 ToolkitTestApplication application;
2586 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2588 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2589 DALI_TEST_CHECK(imageVisual);
2591 // Setup debug trace
2592 TestGlAbstraction& gl = application.GetGlAbstraction();
2593 TraceCallStack& textureTrace = gl.GetTextureTrace();
2594 textureTrace.Enable(true);
2596 tet_infoline("Register visual with control and ensure it has the only handle");
2597 DummyControl actor = DummyControl::New(true);
2598 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2599 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2600 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2602 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2604 application.SendNotification();
2605 application.Render(0);
2606 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2607 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2609 application.GetScene().Add(actor);
2611 // Wait for image to load
2612 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2614 application.SendNotification();
2615 application.Render(0);
2616 // Test renderer and texture created
2617 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2618 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2620 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2621 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2622 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2623 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2624 application.SendNotification();
2625 application.Render();
2627 // Test texture removed after visual destroyed.
2628 tet_infoline("Ensure texture is deleted after visual destroyed");
2629 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2634 int UtcDaliImageVisualReleasePolicy03(void)
2636 ToolkitTestApplication application;
2637 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2639 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2640 DALI_TEST_CHECK(imageVisual);
2642 TestGlAbstraction& gl = application.GetGlAbstraction();
2643 TraceCallStack& textureTrace = gl.GetTextureTrace();
2644 textureTrace.Enable(true);
2646 tet_infoline("Register visual with control and ensure it has the only handle");
2647 DummyControl actor = DummyControl::New(true);
2648 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2649 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2650 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2652 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2654 application.SendNotification();
2655 application.Render(0);
2656 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2657 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2659 application.GetScene().Add(actor);
2661 // Wait for image to load
2662 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2664 application.SendNotification();
2665 application.Render(0);
2666 // Test renderer and texture created
2667 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2668 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2670 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2671 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2672 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2673 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2674 application.SendNotification();
2675 application.Render();
2677 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2678 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2683 int UtcDaliImageVisualReleasePolicy04(void)
2685 ToolkitTestApplication application;
2686 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2688 tet_infoline("Create first visual with Never release policy");
2689 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2691 tet_infoline("Create second visual with Destroyed release policy");
2692 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2694 // Set up trace debug
2695 TestGlAbstraction& gl = application.GetGlAbstraction();
2696 TraceCallStack& textureTrace = gl.GetTextureTrace();
2697 textureTrace.Enable(true);
2699 tet_infoline("Register visuals with control and ensure it has the only handles");
2700 DummyControl actor = DummyControl::New(true);
2701 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2702 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2703 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2704 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2705 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2707 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2709 // Test initially zero renderers
2710 application.SendNotification();
2711 application.Render(0);
2712 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2713 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2715 application.GetScene().Add(actor);
2717 // Wait for image to load
2718 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2720 application.SendNotification();
2721 application.Render(0);
2722 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2723 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2724 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2726 // Test renderer removed when visual destroyed
2727 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2728 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2729 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2730 application.SendNotification();
2731 application.Render();
2733 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2734 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2736 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2737 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2738 application.SendNotification();
2739 application.Render();
2741 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2742 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2743 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2748 int UtcDaliImageVisualReleasePolicy05(void)
2750 ToolkitTestApplication application;
2751 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2753 VisualFactory factory = VisualFactory::Get();
2755 Property::Map propertyMapNeverReleasePolicy;
2756 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2757 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2758 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2759 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2760 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2762 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2764 Property::Map resultMap;
2765 imageVisualNever.CreatePropertyMap(resultMap);
2766 DALI_TEST_CHECK(!resultMap.Empty());
2768 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2773 int UtcDaliImageVisualReleasePolicy06(void)
2775 ToolkitTestApplication application;
2776 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2778 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2779 DALI_TEST_CHECK(imageVisual);
2781 TestGlAbstraction& gl = application.GetGlAbstraction();
2782 TraceCallStack& textureTrace = gl.GetTextureTrace();
2783 textureTrace.Enable(true);
2785 tet_infoline("Register visual with control and ensure it has the only handle");
2786 DummyControl actor = DummyControl::New(true);
2787 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2788 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2789 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2791 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2793 application.SendNotification();
2794 application.Render(0);
2795 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2796 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2798 application.GetScene().Add(actor);
2800 // Wait for image to load
2801 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2803 application.SendNotification();
2804 application.Render(0);
2805 // Test renderer and texture created
2806 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2807 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2808 textureTrace.Reset();
2810 tet_infoline("Disable Visual and check texture not affected");
2811 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2812 application.SendNotification();
2813 application.Render(0);
2814 tet_infoline("Check renderer is destroyed when visual off stage");
2815 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2816 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2817 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2818 textureTrace.Reset();
2820 tet_infoline("Re-enable Visual and check texture not affected");
2821 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2822 application.SendNotification();
2823 application.Render(0);
2824 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2825 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2826 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2827 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2832 int UtcDaliImageVisualReleasePolicy07(void)
2834 ToolkitTestApplication application;
2835 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2837 tet_infoline("Create first visual with DESTROYED release policy");
2838 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2840 tet_infoline("Create second visual with DETACHED release policy");
2841 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2843 // Set up trace debug
2844 TestGlAbstraction& gl = application.GetGlAbstraction();
2845 TraceCallStack& textureTrace = gl.GetTextureTrace();
2846 textureTrace.Enable(true);
2848 tet_infoline("Register visuals with control and ensure it has the only handles");
2849 DummyControl actor = DummyControl::New(true);
2850 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2851 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2852 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2853 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2854 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2856 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2858 // Test initially zero renderers
2859 application.SendNotification();
2860 application.Render(0);
2861 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2862 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2864 application.GetScene().Add(actor);
2866 // Wait for image to load
2867 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2869 application.SendNotification();
2870 application.Render(0);
2871 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2872 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2873 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2875 // Test renderer removed when visual destroyed
2876 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2877 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2878 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2879 application.SendNotification();
2880 application.Render();
2882 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2883 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2885 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2886 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2887 application.SendNotification();
2888 application.Render();
2890 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2891 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2896 int UtcDaliImageVisualReleasePolicy08(void)
2898 ToolkitTestApplication application;
2899 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2901 tet_infoline("Create first visual with DESTROYED release policy");
2902 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2904 // Set up trace debug
2905 TestGlAbstraction& gl = application.GetGlAbstraction();
2906 TraceCallStack& textureTrace = gl.GetTextureTrace();
2907 textureTrace.Enable(true);
2909 tet_infoline("Register visuals with control and ensure it has the only handles");
2910 DummyControl actor = DummyControl::New(true);
2911 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2912 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2913 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2915 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2917 // Test initially zero renderers
2918 application.SendNotification();
2919 application.Render(0);
2920 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2921 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2922 textureTrace.Reset();
2924 application.GetScene().Add(actor);
2926 // Wait for image to load
2927 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2929 application.SendNotification();
2930 application.Render(0);
2931 tet_infoline("Ensure a texture is created");
2932 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2933 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2934 textureTrace.Reset();
2936 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2938 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2940 // 2.Remove actor from stage. In this case, renderer also is deleted.
2941 tet_infoline("Remove actor from stage");
2942 application.GetScene().Remove(actor);
2943 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2944 application.SendNotification();
2945 application.Render();
2947 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2948 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2949 textureTrace.Reset();
2951 // 3.Add actor in stage. In this case, renderer is created.
2952 tet_infoline("Add actor in stage");
2953 application.GetScene().Add(actor);
2954 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2955 application.SendNotification();
2956 application.Render();
2957 tet_infoline("Ensure a texture is not created again");
2958 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2959 textureTrace.Reset();
2961 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2962 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2963 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2964 DALI_TEST_CHECK(textureBefore == textureAfter);
2965 textureBefore.Reset();
2966 textureAfter.Reset();
2968 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2969 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2970 application.SendNotification();
2971 application.Render();
2972 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2977 int UtcDaliImageVisualReleasePolicy09(void)
2979 ToolkitTestApplication application;
2980 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2982 Property::Map propertyMapNPatchReleasePolicy;
2983 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2984 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2985 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2986 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2987 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2989 VisualFactory factory = VisualFactory::Get();
2990 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2991 DALI_TEST_CHECK(imageVisual);
2993 // Setup debug trace
2994 TestGlAbstraction& gl = application.GetGlAbstraction();
2995 TraceCallStack& textureTrace = gl.GetTextureTrace();
2996 textureTrace.Enable(true);
2998 tet_infoline("Register visual with control and ensure it has the only handle");
2999 DummyControl actor = DummyControl::New(true);
3000 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3001 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3002 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3004 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3006 application.SendNotification();
3007 application.Render(0);
3008 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3009 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3011 application.GetScene().Add(actor);
3013 // Wait for image to load
3014 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3016 application.SendNotification();
3017 application.Render(0);
3018 // Test renderer and texture created
3019 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3020 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3022 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
3023 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
3024 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3025 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
3026 application.SendNotification();
3027 application.Render();
3029 // Test texture removed after visual destroyed.
3030 tet_infoline("Ensure texture is deleted after visual destroyed");
3031 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
3036 int UtcDaliImageVisualLoadPolicy01(void)
3038 ToolkitTestApplication application;
3039 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
3041 // Set up trace debug
3042 TestGlAbstraction& gl = application.GetGlAbstraction();
3043 TraceCallStack& textureTrace = gl.GetTextureTrace();
3044 textureTrace.Enable(true);
3046 tet_infoline("Create visual with IMMEDIATE load policy");
3047 VisualFactory factory = VisualFactory::Get();
3049 Property::Map propertyMap;
3050 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3051 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3052 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
3053 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
3054 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
3056 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3058 Property::Map resultMap;
3059 imageVisual.CreatePropertyMap(resultMap);
3060 DALI_TEST_CHECK(!resultMap.Empty());
3061 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
3063 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3065 // Ensure texture has been uploaded
3066 application.SendNotification();
3067 application.Render();
3069 tet_infoline("Ensure texture loading starts after visual created");
3070 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3071 textureTrace.Reset();
3073 tet_infoline("Register visuals with control and ensure it has the only handles");
3074 DummyControl actor = DummyControl::New(true);
3075 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3076 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3077 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3079 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3080 application.GetScene().Add(actor);
3081 tet_infoline("Ensure nothing triggers another load as texure already loaded");
3082 const unsigned int TIME_OUT_3_SECONDS = 3;
3083 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3085 application.SendNotification();
3086 application.Render();
3088 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3089 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3091 // Ensure texture is deleted when no longer needed (ref count was correct )
3092 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3094 application.SendNotification();
3095 application.Render();
3097 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3098 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3103 int UtcDaliImageVisualLoadPolicy02(void)
3105 ToolkitTestApplication application;
3106 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
3108 // Set up trace debug
3109 TestGlAbstraction& gl = application.GetGlAbstraction();
3110 TraceCallStack& textureTrace = gl.GetTextureTrace();
3111 textureTrace.Enable(true);
3113 tet_infoline("Create visual with IMMEDIATE load policy");
3114 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3116 const unsigned int TIME_OUT_3_SECONDS = 3;
3117 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
3119 // Act on meeage queue even although nothing expected to load
3120 application.SendNotification();
3121 application.Render();
3123 tet_infoline("Ensure texture is not generated yet");
3124 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
3125 textureTrace.Reset();
3127 tet_infoline("Register visuals with control and ensure it has the only handles");
3128 DummyControl actor = DummyControl::New(true);
3129 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3130 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3131 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3133 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3134 application.GetScene().Add(actor);
3135 tet_infoline("Allow image time to load");
3136 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3138 application.SendNotification();
3139 application.Render();
3141 tet_infoline("Ensure texture generated and renderer created");
3142 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3143 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3145 // Ensure texture is delete when no longer needed
3146 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3148 application.SendNotification();
3149 application.Render();
3151 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
3152 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
3157 int UtcDaliImageVisualLoadPolicy03(void)
3159 ToolkitTestApplication application;
3160 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
3162 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
3164 // Set up trace debug
3165 TestGlAbstraction& gl = application.GetGlAbstraction();
3166 TraceCallStack& textureTrace = gl.GetTextureTrace();
3167 textureTrace.Enable(true);
3169 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3170 DummyControl actor = DummyControl::New(true);
3171 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3172 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3173 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3175 tet_infoline("Create visual with IMMEDIATE load policy");
3176 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3178 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3179 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3180 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3182 tet_infoline("Allow image time to load resource");
3183 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3184 application.SendNotification();
3185 application.Render();
3187 // Ensure texture has been uploaded
3188 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3189 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3194 int UtcDaliImageVisualLoadPolicy04(void)
3196 ToolkitTestApplication application;
3197 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3198 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3200 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3202 // Set up trace debug
3203 TestGlAbstraction& gl = application.GetGlAbstraction();
3204 TraceCallStack& textureTrace = gl.GetTextureTrace();
3205 textureTrace.Enable(true);
3207 tet_infoline("Create a control and connect to resource ready signal");
3208 DummyControl actor = DummyControl::New(true);
3209 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3210 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3211 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3213 tet_infoline("Create visual with IMMEDIATE load policy");
3214 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3216 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3217 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3218 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3220 tet_infoline("Allow image time to load");
3221 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3222 application.SendNotification();
3223 application.Render();
3225 tet_infoline("Testing texture is loaded and resource ready signal fired");
3226 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3227 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3229 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3231 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3232 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3233 DummyControl actor2 = DummyControl::New(true);
3234 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3235 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3237 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3238 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3239 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3240 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3241 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3242 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3247 int UtcDaliImageVisualLoadPolicy05(void)
3249 ToolkitTestApplication application;
3250 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3251 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3252 // Set up trace debug
3253 TestGlAbstraction& gl = application.GetGlAbstraction();
3254 TraceCallStack& textureTrace = gl.GetTextureTrace();
3255 textureTrace.Enable(true);
3257 tet_infoline("Create a control and connect to resource ready signal");
3258 DummyControl actor = DummyControl::New(true);
3259 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3260 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3261 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3262 application.GetScene().Add(actor);
3264 tet_infoline("Create visual with ATTACHED load policy");
3265 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3267 tet_infoline("Registering visual allows control to get a signal once loaded");
3268 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3269 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3271 tet_infoline("Allow image time to load");
3272 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3273 application.SendNotification();
3274 application.Render();
3276 tet_infoline("Testing texture is loaded and resource ready signal fired");
3277 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3278 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3280 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3282 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3283 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3284 DummyControl actor2 = DummyControl::New(true);
3285 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3286 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3288 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3289 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3290 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3291 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3292 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3293 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3298 int UtcDaliImageVisualOrientationCorrection(void)
3300 ToolkitTestApplication application;
3301 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3303 VisualFactory factory = VisualFactory::Get();
3304 tet_infoline("Create visual with Orientation correction set OFF");
3305 Property::Map propertyMap;
3306 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3307 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3308 propertyMap.Insert("orientationCorrection", false);
3309 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3311 tet_infoline("Create control for visual, need to loaded it");
3312 DummyControl actor = DummyControl::New(true);
3313 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3314 application.GetScene().Add(actor);
3316 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3317 // Wait for image to load
3318 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3320 Vector2 originalImageSize;
3321 tet_infoline("Get size of original visual to compare later with rotated image");
3322 imageVisual.GetNaturalSize(originalImageSize);
3323 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3324 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3325 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3326 application.SendNotification();
3327 application.Render();
3329 tet_infoline("Create visual with Orientation correction set ON ");
3330 propertyMap.Clear();
3331 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3332 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3333 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3334 imageVisual = factory.CreateVisual(propertyMap);
3336 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3337 // Wait for image to load
3338 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3340 Vector2 rotatedImageSize;
3341 imageVisual.GetNaturalSize(rotatedImageSize);
3342 tet_infoline("Confirm that visual has rotated");
3343 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3344 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3346 Property::Map resultMap;
3347 imageVisual.CreatePropertyMap(resultMap);
3349 // check the Property::ORIENTATION_CORRECTION value from the returned map
3350 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3351 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3356 int UtcDaliImageVisualCustomShader(void)
3358 ToolkitTestApplication application;
3359 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3361 VisualFactory factory = VisualFactory::Get();
3362 Property::Map properties;
3363 Property::Map shader;
3364 const std::string vertexShader = "Foobar";
3365 const std::string fragmentShader = "Foobar";
3366 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3367 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3369 properties[Visual::Property::TYPE] = Visual::IMAGE;
3370 properties[Visual::Property::SHADER] = shader;
3371 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3373 Visual::Base visual = factory.CreateVisual(properties);
3375 // trigger creation through setting on stage
3376 DummyControl dummy = DummyControl::New(true);
3377 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3378 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3380 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3381 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3382 application.GetScene().Add(dummy);
3384 application.SendNotification();
3385 application.Render();
3387 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3389 Renderer renderer = dummy.GetRendererAt(0);
3390 Shader shader2 = renderer.GetShader();
3391 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3392 Property::Map* map = value.GetMap();
3393 DALI_TEST_CHECK(map);
3395 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3396 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3398 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3399 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3403 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3404 properties[Visual::Property::SHADER] = shader;
3406 Visual::Base visual1 = factory.CreateVisual(properties);
3408 // trigger creation through setting on stage
3409 DummyControl dummy1 = DummyControl::New(true);
3410 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3411 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3412 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3413 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3414 application.GetScene().Add(dummy1);
3416 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3417 glAbstraction.EnableEnableDisableCallTrace(true);
3419 application.SendNotification();
3420 application.Render();
3422 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3423 std::ostringstream blendStr;
3424 blendStr << std::hex << GL_BLEND;
3425 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3430 void ResourceReadyLoadNext(Control control)
3432 static int callNumber = 0;
3434 gResourceReadySignalFired = true;
3435 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3439 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3441 tet_infoline("Create visual with loaded image from within the signal handler");
3442 VisualFactory factory = VisualFactory::Get();
3443 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3445 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3446 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3451 tet_infoline("3rd signal called");
3452 DALI_TEST_CHECK(true);
3456 int UtcDaliImageVisualLoadReady01(void)
3458 ToolkitTestApplication application;
3459 tet_infoline("UtcDaliImageVisualLoadReady01");
3460 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3461 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3462 tet_infoline("Should get a ready signal for all three visuals");
3466 tet_infoline("Create a control and connect to resource ready signal");
3467 DummyControl actor = DummyControl::New(true);
3468 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3469 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3470 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3471 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3472 application.GetScene().Add(actor);
3474 tet_infoline("Create visual with IMMEDIATE load policy");
3475 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3477 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3478 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3480 tet_infoline("Allow image time to load");
3481 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3482 application.SendNotification();
3483 application.Render();
3485 tet_infoline("Testing texture is loaded and resource ready signal fired");
3486 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3487 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3489 tet_infoline("Original control correctly signalled, now testing failing image");
3491 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3494 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3496 DummyControl actor2 = DummyControl::New(true);
3497 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3498 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3499 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3501 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3502 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3504 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3505 application.GetScene().Add(actor2);
3507 tet_infoline("Wait for loading thread to finish");
3508 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3509 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3511 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3513 tet_infoline("Check for 3rd signal");
3514 application.SendNotification();
3515 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3516 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3521 int UtcDaliImageVisualLoadImagePlanes01(void)
3523 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3524 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3526 ToolkitTestApplication application;
3528 VisualFactory factory = VisualFactory::Get();
3529 DALI_TEST_CHECK(factory);
3531 Property::Map propertyMap;
3532 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3533 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
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(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3549 TestGlAbstraction& gl = application.GetGlAbstraction();
3550 TraceCallStack& textureTrace = gl.GetTextureTrace();
3551 textureTrace.Enable(true);
3553 application.SendNotification();
3554 application.Render();
3556 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3557 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3558 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3560 Renderer renderer = actor.GetRendererAt(0);
3561 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3562 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3567 int UtcDaliImageVisualLoadImagePlanes02(void)
3569 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3570 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3572 ToolkitTestApplication application;
3574 VisualFactory factory = VisualFactory::Get();
3575 DALI_TEST_CHECK(factory);
3577 // Alpha masking case - not support yuv planes
3578 Property::Map propertyMap;
3579 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3580 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3581 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3583 Visual::Base visual = factory.CreateVisual(propertyMap);
3584 DALI_TEST_CHECK(visual);
3586 DummyControl actor = DummyControl::New();
3587 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3588 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3589 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3590 application.GetScene().Add(actor);
3592 application.SendNotification();
3593 application.Render();
3595 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3597 TestGlAbstraction& gl = application.GetGlAbstraction();
3598 TraceCallStack& textureTrace = gl.GetTextureTrace();
3599 textureTrace.Enable(true);
3601 application.SendNotification();
3602 application.Render();
3604 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3605 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3606 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3611 int UtcDaliImageVisualLoadImagePlanes03(void)
3613 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3614 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3616 ToolkitTestApplication application;
3618 VisualFactory factory = VisualFactory::Get();
3619 DALI_TEST_CHECK(factory);
3621 TestGlAbstraction& gl = application.GetGlAbstraction();
3622 TraceCallStack& textureTrace = gl.GetTextureTrace();
3623 textureTrace.Enable(true);
3625 Property::Map propertyMap;
3626 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3627 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3628 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3630 Visual::Base visual = factory.CreateVisual(propertyMap);
3631 DALI_TEST_CHECK(visual);
3633 DummyControl actor = DummyControl::New();
3634 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3635 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3636 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3637 application.GetScene().Add(actor);
3639 application.SendNotification();
3640 application.Render();
3642 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3643 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3644 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3649 int UtcDaliImageVisualLoadFastTrackImage01(void)
3651 tet_infoline("Test worker thread uploading with Local URL");
3652 ToolkitTestApplication application;
3654 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3656 VisualFactory factory = VisualFactory::Get();
3657 DALI_TEST_CHECK(factory);
3659 // Pair of filename - expect GenTextures count.
3660 std::vector<std::pair<std::string, int>> testCases = {
3661 {TEST_IMAGE_FILE_NAME, 1},
3662 {TEST_REMOTE_IMAGE_FILE_NAME, 1},
3663 {TEST_INVALID_FILE_NAME, 0},
3666 for(auto&& tc : testCases)
3668 auto& filename = tc.first;
3669 auto& expectValue = tc.second;
3671 tet_printf("Test %s\n", filename.c_str());
3673 Property::Map propertyMap;
3674 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3675 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3676 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3678 Visual::Base visual = factory.CreateVisual(propertyMap);
3679 DALI_TEST_CHECK(visual);
3681 DummyControl actor = DummyControl::New();
3682 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3683 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3684 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3686 TestGlAbstraction& gl = application.GetGlAbstraction();
3687 TraceCallStack& textureTrace = gl.GetTextureTrace();
3688 textureTrace.Enable(true);
3690 application.GetScene().Add(actor);
3692 application.SendNotification();
3693 application.Render();
3695 // EventThread without callback
3696 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3698 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3701 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3702 // How can we make it? Should it be integration-api?
3703 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3704 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3706 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3707 application.Render();
3709 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3711 application.SendNotification();
3712 application.Render();
3714 textureTrace.Reset();
3720 int UtcDaliImageVisualLoadFastTrackImage02(void)
3722 tet_infoline("Test worker thread uploading with Local URL");
3723 ToolkitTestApplication application;
3725 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3727 VisualFactory factory = VisualFactory::Get();
3728 DALI_TEST_CHECK(factory);
3731 auto filename = std::string(TEST_IMAGE_FILE_NAME);
3732 auto expectValue = 1;
3734 tet_printf("Test %s\n", filename.c_str());
3736 Property::Map propertyMap;
3737 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3738 propertyMap.Insert(ImageVisual::Property::URL, filename.c_str());
3739 propertyMap.Insert("fastTrackUploading", true);
3741 Visual::Base visual = factory.CreateVisual(propertyMap);
3742 DALI_TEST_CHECK(visual);
3744 DummyControl actor = DummyControl::New();
3745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3747 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3749 TestGlAbstraction& gl = application.GetGlAbstraction();
3750 TraceCallStack& textureTrace = gl.GetTextureTrace();
3751 textureTrace.Enable(true);
3753 application.GetScene().Add(actor);
3755 application.SendNotification();
3756 application.Render();
3758 // EventThread without callback
3759 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3761 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3764 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3765 // How can we make it? Should it be integration-api?
3766 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3767 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), expectValue > 0, TEST_LOCATION);
3769 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3770 application.Render();
3772 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), expectValue, TEST_LOCATION);
3774 application.SendNotification();
3775 application.Render();
3777 textureTrace.Reset();
3783 int UtcDaliImageVisualLoadFastTrackImageResourceReady(void)
3785 tet_infoline("Test worker thread uploading with Local URL");
3786 ToolkitTestApplication application;
3788 VisualFactory factory = VisualFactory::Get();
3789 DALI_TEST_CHECK(factory);
3791 Property::Map propertyMap;
3792 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3793 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3794 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3796 Visual::Base visual = factory.CreateVisual(propertyMap);
3797 DALI_TEST_CHECK(visual);
3799 DummyControl actor = DummyControl::New();
3800 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3801 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3802 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3804 TestGlAbstraction& gl = application.GetGlAbstraction();
3805 TraceCallStack& textureTrace = gl.GetTextureTrace();
3806 textureTrace.Enable(true);
3808 application.GetScene().Add(actor);
3810 application.SendNotification();
3811 application.Render();
3813 // EventThread with callback
3814 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3816 // Check resource ready comes after
3817 application.SendNotification();
3818 application.Render();
3820 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3821 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3826 int UtcDaliImageVisualLoadFastTrackImageReload(void)
3828 tet_infoline("Test worker thread uploading with Local URL");
3829 ToolkitTestApplication application;
3831 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3833 VisualFactory factory = VisualFactory::Get();
3834 DALI_TEST_CHECK(factory);
3836 Property::Map propertyMap;
3837 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3838 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3839 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3841 Visual::Base visual = factory.CreateVisual(propertyMap);
3842 DALI_TEST_CHECK(visual);
3844 DummyControl actor = DummyControl::New();
3845 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3846 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3847 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3849 TestGlAbstraction& gl = application.GetGlAbstraction();
3850 TraceCallStack& textureTrace = gl.GetTextureTrace();
3851 textureTrace.Enable(true);
3853 application.GetScene().Add(actor);
3855 application.SendNotification();
3856 application.Render();
3858 // EventThread without callback
3859 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3861 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3864 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3865 // How can we make it? Should it be integration-api?
3866 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3867 DALI_TEST_EQUALS(textureUploadManager.ResourceUpload(), true, TEST_LOCATION);
3869 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3870 application.Render();
3872 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3875 Property::Map attributes;
3876 DevelControl::DoAction(actor, Control::CONTROL_PROPERTY_END_INDEX + 1, DevelImageVisual::Action::RELOAD, attributes);
3878 // EventThread with callback
3879 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3881 // Check resource ready comes after
3882 application.SendNotification();
3883 application.Render();
3885 // Check whether renderer count is 1 or not.
3886 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3887 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3892 int UtcDaliImageVisualLoadFastTrackImagePlanes01(void)
3894 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3895 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3897 ToolkitTestApplication application;
3899 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3901 VisualFactory factory = VisualFactory::Get();
3902 DALI_TEST_CHECK(factory);
3904 Property::Map propertyMap;
3905 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3906 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3907 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3909 Visual::Base visual = factory.CreateVisual(propertyMap);
3910 DALI_TEST_CHECK(visual);
3912 DummyControl actor = DummyControl::New();
3913 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3914 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3915 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3917 TestGlAbstraction& gl = application.GetGlAbstraction();
3918 TraceCallStack& textureTrace = gl.GetTextureTrace();
3919 textureTrace.Enable(true);
3921 application.GetScene().Add(actor);
3923 application.SendNotification();
3924 application.Render();
3926 // EventThread without callback
3927 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3929 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3932 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3933 // How can we make it? Should it be integration-api?
3934 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3935 textureUploadManager.ResourceUpload();
3936 application.Render();
3938 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3939 application.Render();
3941 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3943 application.SendNotification();
3944 application.Render();
3949 int UtcDaliImageVisualLoadFastTrackImagePlanes02(void)
3951 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3952 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3954 ToolkitTestApplication application;
3956 Test::TextureUploadManager::InitalizeGraphicsController(application.GetGraphicsController());
3958 VisualFactory factory = VisualFactory::Get();
3959 DALI_TEST_CHECK(factory);
3961 Property::Map propertyMap;
3962 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3963 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
3964 propertyMap.Insert(DevelImageVisual::Property::FAST_TRACK_UPLOADING, true);
3966 Visual::Base visual = factory.CreateVisual(propertyMap);
3967 DALI_TEST_CHECK(visual);
3969 DummyControl actor = DummyControl::New();
3970 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3971 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3972 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3974 TestGlAbstraction& gl = application.GetGlAbstraction();
3975 TraceCallStack& textureTrace = gl.GetTextureTrace();
3976 textureTrace.Enable(true);
3978 application.GetScene().Add(actor);
3980 application.SendNotification();
3981 application.Render();
3983 // EventThread without callback
3984 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
3986 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
3989 // TODO : There is no way to flush TextureUploadManager in test-application's Render() now.
3990 // How can we make it? Should it be integration-api?
3991 auto textureUploadManager = Dali::Devel::TextureUploadManager::Get();
3992 textureUploadManager.ResourceUpload();
3993 application.Render();
3995 // Render only without SendNotification(). And check whether glTexImage2D called or not.
3996 application.Render();
3998 DALI_TEST_GREATER(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
4000 application.SendNotification();
4001 application.Render();
4006 int UtcDaliImageVisualDebugImageVisualShaderP1(void)
4008 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4009 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "validFile"); // Try to load not exist file.
4011 // Set valid script file
4012 Test::StyleMonitor::SetThemeFileOutput("validFile", VALID_DEBUG_SHADER_SCRIPT);
4014 ToolkitTestApplication application;
4016 VisualFactory factory = VisualFactory::Get();
4017 DALI_TEST_CHECK(factory);
4019 Property::Map propertyMap;
4020 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4021 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4023 Visual::Base visual = factory.CreateVisual(propertyMap);
4024 DALI_TEST_CHECK(visual);
4026 DummyControl actor = DummyControl::New();
4027 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4028 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4029 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4030 application.GetScene().Add(actor);
4032 application.SendNotification();
4033 application.Render();
4035 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4037 TestGlAbstraction& gl = application.GetGlAbstraction();
4038 TraceCallStack& textureTrace = gl.GetTextureTrace();
4039 textureTrace.Enable(true);
4041 application.SendNotification();
4042 application.Render();
4044 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4045 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4046 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4051 int UtcDaliImageVisualDebugImageVisualShaderN1(void)
4053 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4054 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, "notJsonFile"); // Try to load exist file, but not a json
4056 // Set invalid script file
4057 Test::StyleMonitor::SetThemeFileOutput("notJsonFile", "1");
4059 ToolkitTestApplication application;
4061 VisualFactory factory = VisualFactory::Get();
4062 DALI_TEST_CHECK(factory);
4064 Property::Map propertyMap;
4065 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4066 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4068 Visual::Base visual = factory.CreateVisual(propertyMap);
4069 DALI_TEST_CHECK(visual);
4071 DummyControl actor = DummyControl::New();
4072 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4073 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4074 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4075 application.GetScene().Add(actor);
4077 application.SendNotification();
4078 application.Render();
4080 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4082 TestGlAbstraction& gl = application.GetGlAbstraction();
4083 TraceCallStack& textureTrace = gl.GetTextureTrace();
4084 textureTrace.Enable(true);
4086 application.SendNotification();
4087 application.Render();
4089 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4090 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4091 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
4096 int UtcDaliImageVisualDebugImageVisualShaderN2(void)
4098 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_ENV, "1");
4099 EnvironmentVariable::SetTestEnvironmentVariable(DALI_DEBUG_IMAGE_VISUAL_SHADER_SCRIPT_FILE_NAME_ENV, std::string(THROW_EXCEPTION_STYLE_FILE_NAME).c_str()); // Try to load file that throw some exception
4101 // Set throw exception script file
4102 Test::StyleMonitor::SetThemeFileOutput(std::string(THROW_EXCEPTION_STYLE_FILE_NAME), "1");
4104 ToolkitTestApplication application;
4106 VisualFactory factory = VisualFactory::Get();
4107 DALI_TEST_CHECK(factory);
4109 Property::Map propertyMap;
4110 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
4111 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
4113 Visual::Base visual = factory.CreateVisual(propertyMap);
4114 DALI_TEST_CHECK(visual);
4116 DummyControl actor = DummyControl::New();
4117 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
4118 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
4119 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
4120 application.GetScene().Add(actor);
4122 application.SendNotification();
4123 application.Render();
4125 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4127 TestGlAbstraction& gl = application.GetGlAbstraction();
4128 TraceCallStack& textureTrace = gl.GetTextureTrace();
4129 textureTrace.Enable(true);
4131 application.SendNotification();
4132 application.Render();
4134 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4135 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
4136 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);