2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-environment-variable.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <toolkit-timer.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
30 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
33 #include <dali-toolkit/public-api/image-loader/image-url.h>
34 #include <dali-toolkit/public-api/image-loader/image.h>
36 #include "dummy-control.h"
37 #include "test-encoded-image-buffer.h"
38 #include "test-native-image-source.h"
41 using namespace Dali::Toolkit;
43 void dali_image_visual_startup(void)
45 test_return_value = TET_UNDEF;
48 void dali_image_visual_cleanup(void)
50 test_return_value = TET_PASS;
55 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
56 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
57 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
58 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
59 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
60 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
61 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
62 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
63 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
64 const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg";
65 const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png";
67 constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
68 constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420";
70 bool gResourceReadySignalFired = false;
71 std::vector<int> gReadyIds = {};
72 void ResourceReadySignal(Control control)
74 gResourceReadySignalFired = true;
75 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
82 Actor CreateActorWithImageVisual(const Property::Map& map)
84 VisualFactory factory = VisualFactory::Get();
85 DummyControl actor = DummyControl::New();
86 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
87 Visual::Base visual = factory.CreateVisual(map);
88 DALI_TEST_CHECK(visual);
89 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
90 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
91 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
95 Visual::Base CreateVisualWithPolicy(const char* url, Property::Index key, const Property::Value& value)
97 VisualFactory factory = VisualFactory::Get();
99 Property::Map propertyMap;
100 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
101 propertyMap.Insert(ImageVisual::Property::URL, url);
102 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
103 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
104 propertyMap.Insert(key, value);
106 return factory.CreateVisual(propertyMap);
111 void TestVisualRender(ToolkitTestApplication& application,
113 Visual::Base& visual,
114 std::size_t expectedSamplers = 0,
115 ImageDimensions imageDimensions = ImageDimensions(),
116 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
118 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
119 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
123 // set the image size, for test case, this needs to be set before loading started
124 application.GetPlatform().SetClosestImageSize(Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()));
127 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
128 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
130 application.GetScene().Add(actor);
132 application.SendNotification(); // Send messages to update
133 application.Render(); // process update and render
134 application.SendNotification(); // process any signals to event
138 DALI_TEST_EQUALS(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc), true, TEST_LOCATION);
141 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
144 static void TestMixColor(Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor)
147 visual.CreatePropertyMap(map);
148 Property::Value* value = map.Find(mixColorIndex);
149 DALI_TEST_CHECK(value);
151 DALI_TEST_CHECK(value->Get(mixColor1));
152 DALI_TEST_EQUALS(mixColor1, Vector3(testColor), 0.001, TEST_LOCATION);
154 value = map.Find(Visual::Property::MIX_COLOR);
155 DALI_TEST_CHECK(value);
157 DALI_TEST_CHECK(value->Get(mixColor2));
158 DALI_TEST_EQUALS(mixColor2, testColor, 0.001, TEST_LOCATION);
160 value = map.Find(Visual::Property::OPACITY);
161 DALI_TEST_CHECK(value);
163 DALI_TEST_CHECK(value->Get(opacity));
164 DALI_TEST_EQUALS(opacity, testColor.a, 0.001, TEST_LOCATION);
167 int UtcDaliImageVisualPropertyMap(void)
169 ToolkitTestApplication application;
170 tet_infoline("Request image visual with a Property::Map");
172 VisualFactory factory = VisualFactory::Get();
173 DALI_TEST_CHECK(factory);
174 factory.SetPreMultiplyOnLoad(true);
176 Property::Map propertyMap;
177 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
178 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
180 Visual::Base visual = factory.CreateVisual(propertyMap);
181 DALI_TEST_CHECK(visual);
183 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
184 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
186 TestGlAbstraction& gl = application.GetGlAbstraction();
187 TraceCallStack& textureTrace = gl.GetTextureTrace();
188 textureTrace.Enable(true);
190 DummyControl actor = DummyControl::New();
191 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
194 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
195 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
197 application.GetScene().Add(actor);
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
203 application.SendNotification();
204 application.Render();
206 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
207 auto renderer = actor.GetRendererAt(0);
208 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
209 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
210 auto preMultipliedAlpha = renderer.GetProperty<float>(preMultipliedIndex);
211 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
212 DALI_TEST_EQUALS(preMultipliedAlpha, 1.0f, TEST_LOCATION);
213 DALI_TEST_EQUALS(preMultipliedAlpha2, true, TEST_LOCATION);
214 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
216 application.GetScene().Remove(actor);
217 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
222 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
224 ToolkitTestApplication application;
225 tet_infoline("Request image visual without pre-multiplied alpha");
227 VisualFactory factory = VisualFactory::Get();
228 DALI_TEST_CHECK(factory);
229 factory.SetPreMultiplyOnLoad(false);
231 Property::Map propertyMap;
232 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
233 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
235 Visual::Base visual = factory.CreateVisual(propertyMap);
236 DALI_TEST_CHECK(visual);
238 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
239 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
241 TestGlAbstraction& gl = application.GetGlAbstraction();
242 TraceCallStack& textureTrace = gl.GetTextureTrace();
243 textureTrace.Enable(true);
245 DummyControl actor = DummyControl::New();
246 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
247 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
249 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
250 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
252 application.GetScene().Add(actor);
253 application.SendNotification();
254 application.Render();
256 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
258 application.SendNotification();
259 application.Render();
261 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
262 auto renderer = actor.GetRendererAt(0);
263 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
264 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
265 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
266 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
268 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
269 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
271 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
273 application.GetScene().Remove(actor);
274 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
279 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
281 ToolkitTestApplication application;
282 tet_infoline("Request image visual with no alpha channel");
284 VisualFactory factory = VisualFactory::Get();
285 DALI_TEST_CHECK(factory);
287 Property::Map propertyMap;
288 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
289 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
291 Visual::Base visual = factory.CreateVisual(propertyMap);
292 DALI_TEST_CHECK(visual);
294 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
295 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
297 TestGlAbstraction& gl = application.GetGlAbstraction();
298 TraceCallStack& textureTrace = gl.GetTextureTrace();
299 textureTrace.Enable(true);
301 DummyControl actor = DummyControl::New();
302 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
303 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
305 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
306 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
308 application.GetScene().Add(actor);
309 application.SendNotification();
310 application.Render();
312 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
318 auto renderer = actor.GetRendererAt(0);
319 auto preMultipliedIndex = renderer.GetPropertyIndex("preMultipliedAlpha");
320 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
321 auto preMultipliedAlpha = renderer.GetProperty<bool>(preMultipliedIndex);
322 auto preMultipliedAlpha2 = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
324 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
325 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
327 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
329 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
330 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
331 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
332 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
333 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
334 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
335 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
336 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
338 textureTrace.Reset();
340 // Make a new visual with the same image
341 Visual::Base newVisual = factory.CreateVisual(propertyMap);
342 DALI_TEST_CHECK(newVisual);
344 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
345 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
347 DummyControl newActor = DummyControl::New();
348 DummyControlImpl& newDummyImpl = static_cast<DummyControlImpl&>(newActor.GetImplementation());
349 newDummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual);
351 newActor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
352 DALI_TEST_EQUALS(newActor.GetRendererCount(), 0u, TEST_LOCATION);
354 application.GetScene().Add(newActor);
356 application.SendNotification();
357 application.Render();
359 DALI_TEST_EQUALS(newActor.GetRendererCount(), 1u, TEST_LOCATION);
360 auto newRenderer = newActor.GetRendererAt(0);
361 preMultipliedIndex = newRenderer.GetPropertyIndex("preMultipliedAlpha");
362 DALI_TEST_CHECK(preMultipliedIndex != Property::INVALID_INDEX);
363 preMultipliedAlpha = newRenderer.GetProperty<bool>(preMultipliedIndex);
364 preMultipliedAlpha2 = newRenderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
366 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
367 DALI_TEST_EQUALS(preMultipliedAlpha2, false, TEST_LOCATION);
369 srcFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
370 destFactorRgb = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
371 srcFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
372 destFactorAlpha = newRenderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
373 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
374 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
375 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
376 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
378 application.GetScene().Remove(actor);
379 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
384 int UtcDaliImageVisualRemoteImageLoad(void)
386 ToolkitTestApplication application;
387 tet_infoline("Request remote image visual with a Property::Map");
389 VisualFactory factory = VisualFactory::Get();
390 DALI_TEST_CHECK(factory);
392 Property::Map propertyMap;
393 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
394 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
396 Visual::Base visual = factory.CreateVisual(propertyMap);
397 DALI_TEST_CHECK(visual);
399 TestGlAbstraction& gl = application.GetGlAbstraction();
400 TraceCallStack& textureTrace = gl.GetTextureTrace();
401 textureTrace.Enable(true);
403 DummyControl actor = DummyControl::New();
404 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
405 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
407 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
408 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
410 application.GetScene().Add(actor);
411 application.SendNotification();
413 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
415 application.SendNotification();
416 application.Render();
418 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
419 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
421 application.GetScene().Remove(actor);
422 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
427 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void)
429 ToolkitTestApplication application;
430 tet_infoline("Use FrameBuffer as url");
434 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
436 DALI_TEST_CHECK(frameBuffer);
437 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
438 std::string url = imageUrl.GetUrl();
440 VisualFactory factory = VisualFactory::Get();
441 DALI_TEST_CHECK(factory);
443 Property::Map propertyMap;
444 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
445 propertyMap.Insert(ImageVisual::Property::URL, url);
447 Visual::Base visual = factory.CreateVisual(propertyMap);
448 DALI_TEST_CHECK(visual);
450 DummyControl actor = DummyControl::New();
451 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
452 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
454 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
456 application.GetScene().Add(actor);
458 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
460 application.SendNotification();
461 application.Render(16);
463 Renderer renderer = actor.GetRendererAt(0);
465 // Check whether preMultipliedAlpha is true.
466 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
467 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
472 int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void)
474 ToolkitTestApplication application;
475 tet_infoline("Use FrameBuffer as url");
479 FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
481 DALI_TEST_CHECK(frameBuffer);
483 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
484 frameBuffer.AttachColorTexture(texture);
486 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u);
487 std::string url = imageUrl.GetUrl();
489 VisualFactory factory = VisualFactory::Get();
490 DALI_TEST_CHECK(factory);
492 Property::Map propertyMap;
493 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
494 propertyMap.Insert(ImageVisual::Property::URL, url);
496 Visual::Base visual = factory.CreateVisual(propertyMap);
497 DALI_TEST_CHECK(visual);
499 DummyControl actor = DummyControl::New();
500 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
501 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
503 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
505 application.GetScene().Add(actor);
507 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
509 application.SendNotification();
510 application.Render(16);
512 Renderer renderer = actor.GetRendererAt(0);
514 // Check whether preMultipliedAlpha is true.
515 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
516 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
521 int UtcDaliImageVisualWithPixelData(void)
523 ToolkitTestApplication application;
524 tet_infoline("Use PixelData as url");
528 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
530 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
531 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
533 DALI_TEST_CHECK(pixelData);
535 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData);
536 std::string url = imageUrl.GetUrl();
538 VisualFactory factory = VisualFactory::Get();
539 DALI_TEST_CHECK(factory);
541 Property::Map propertyMap;
542 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
543 propertyMap.Insert(ImageVisual::Property::URL, url);
545 Visual::Base visual = factory.CreateVisual(propertyMap);
546 DALI_TEST_CHECK(visual);
548 DummyControl actor = DummyControl::New();
549 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
550 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
552 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
554 application.GetScene().Add(actor);
556 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
558 application.SendNotification();
559 application.Render(16);
561 Renderer renderer = actor.GetRendererAt(0);
563 // Check whether preMultipliedAlpha is false.
564 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
565 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
570 int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void)
572 ToolkitTestApplication application;
573 tet_infoline("Use PixelData as url");
577 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
579 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
580 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
582 DALI_TEST_CHECK(pixelData);
584 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
585 std::string url = imageUrl.GetUrl();
587 VisualFactory factory = VisualFactory::Get();
588 DALI_TEST_CHECK(factory);
590 Property::Map propertyMap;
591 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
592 propertyMap.Insert(ImageVisual::Property::URL, url);
594 Visual::Base visual = factory.CreateVisual(propertyMap);
595 DALI_TEST_CHECK(visual);
597 DummyControl actor = DummyControl::New();
598 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
599 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
601 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
603 application.GetScene().Add(actor);
605 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
607 application.SendNotification();
608 application.Render(16);
610 Renderer renderer = actor.GetRendererAt(0);
612 // Check whether preMultipliedAlpha is true.
613 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
614 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
619 int UtcDaliImageVisualWithPixelDataMasking(void)
621 ToolkitTestApplication application;
622 tet_infoline("Load external texture with mask");
624 TestGlAbstraction& gl = application.GetGlAbstraction();
625 TraceCallStack& textureTrace = gl.GetTextureTrace();
626 textureTrace.Enable(true);
630 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
632 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
633 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
635 DALI_TEST_CHECK(pixelData);
637 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
638 std::string url = imageUrl.GetUrl();
640 VisualFactory factory = VisualFactory::Get();
641 DALI_TEST_CHECK(factory);
643 Property::Map propertyMap;
644 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
645 propertyMap.Insert(ImageVisual::Property::URL, url);
646 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
648 Visual::Base visual = factory.CreateVisual(propertyMap);
649 DALI_TEST_CHECK(visual);
651 Property::Map testMap;
652 visual.CreatePropertyMap(testMap);
653 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
655 DummyControl actor = DummyControl::New();
656 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
657 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
659 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
661 application.GetScene().Add(actor);
662 application.SendNotification();
663 application.Render(16);
664 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
666 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
667 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
668 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
670 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
671 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
676 int UtcDaliImageVisualWithPixelDataMaskingSynchronously(void)
678 ToolkitTestApplication application;
679 tet_infoline("Load synchronously external texture with mask");
683 uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
685 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
686 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
688 DALI_TEST_CHECK(pixelData);
690 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true);
691 std::string url = imageUrl.GetUrl();
693 VisualFactory factory = VisualFactory::Get();
694 DALI_TEST_CHECK(factory);
696 Property::Map propertyMap;
697 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
698 propertyMap.Insert(ImageVisual::Property::URL, url);
699 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
700 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
702 Visual::Base visual = factory.CreateVisual(propertyMap);
703 DALI_TEST_CHECK(visual);
705 Property::Map testMap;
706 visual.CreatePropertyMap(testMap);
707 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
709 DummyControl actor = DummyControl::New();
710 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
711 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
713 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
715 application.GetScene().Add(actor);
717 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
719 application.SendNotification();
720 application.Render(16);
725 int UtcDaliImageVisualWithNativeImage(void)
727 ToolkitTestApplication application;
728 tet_infoline("Use Native Image as url");
730 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
731 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
732 std::string url = imageUrl.GetUrl();
734 VisualFactory factory = VisualFactory::Get();
735 DALI_TEST_CHECK(factory);
737 Property::Map propertyMap;
738 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
739 propertyMap.Insert(ImageVisual::Property::URL, url);
741 Visual::Base visual = factory.CreateVisual(propertyMap);
742 DALI_TEST_CHECK(visual);
744 DummyControl actor = DummyControl::New();
745 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
746 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
748 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
750 application.GetScene().Add(actor);
752 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
754 application.SendNotification();
755 application.Render(16);
757 Renderer renderer = actor.GetRendererAt(0);
758 Shader shader = renderer.GetShader();
760 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
761 DALI_TEST_CHECK(value.GetType() == Property::MAP);
762 const Property::Map* outMap = value.GetMap();
763 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
765 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
766 size_t pos = fragmentShader.find(fragmentPrefix);
768 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
770 // Check whether preMultipliedAlpha is false.
771 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
772 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
777 int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void)
779 ToolkitTestApplication application;
780 tet_infoline("Use Native Image as url");
782 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
783 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
784 std::string url = imageUrl.GetUrl();
786 VisualFactory factory = VisualFactory::Get();
787 DALI_TEST_CHECK(factory);
789 Property::Map propertyMap;
790 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
791 propertyMap.Insert(ImageVisual::Property::URL, url);
793 Visual::Base visual = factory.CreateVisual(propertyMap);
794 DALI_TEST_CHECK(visual);
796 DummyControl actor = DummyControl::New();
797 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
798 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
800 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
802 application.GetScene().Add(actor);
804 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
806 application.SendNotification();
807 application.Render(16);
809 Renderer renderer = actor.GetRendererAt(0);
810 Shader shader = renderer.GetShader();
812 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
813 DALI_TEST_CHECK(value.GetType() == Property::MAP);
814 const Property::Map* outMap = value.GetMap();
815 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
817 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
818 size_t pos = fragmentShader.find(fragmentPrefix);
820 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
822 // Check whether preMultipliedAlpha is true.
823 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
824 DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION);
829 int UtcDaliImageVisualWithNativeImageCustomShader(void)
831 ToolkitTestApplication application;
832 tet_infoline("Use Native Image as url and Use custom shader");
834 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
835 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true);
836 std::string url = imageUrl.GetUrl();
838 VisualFactory factory = VisualFactory::Get();
839 DALI_TEST_CHECK(factory);
841 Property::Map propertyMap;
842 Property::Map shaderMap;
843 const std::string customVertexShaderSource = "Foobar";
844 const std::string customFragmentShaderSource = "Foobar";
845 shaderMap[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = customFragmentShaderSource;
846 shaderMap[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = customVertexShaderSource;
848 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
849 propertyMap.Insert(Toolkit::Visual::Property::SHADER, shaderMap);
850 propertyMap.Insert(ImageVisual::Property::URL, url);
852 Visual::Base visual = factory.CreateVisual(propertyMap);
853 DALI_TEST_CHECK(visual);
855 DummyControl actor = DummyControl::New();
856 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
857 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
859 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
860 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
862 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
864 application.GetScene().Add(actor);
866 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
868 application.SendNotification();
869 application.Render(16);
871 Renderer renderer = actor.GetRendererAt(0);
872 Shader shader = renderer.GetShader();
874 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
875 DALI_TEST_CHECK(value.GetType() == Property::MAP);
876 const Property::Map* outMap = value.GetMap();
877 std::string fragmentShaderSource = (*outMap)["fragment"].Get<std::string>();
878 std::string vertexShaderSource = (*outMap)["vertex"].Get<std::string>();
880 // Compare vertex shader is equal
881 DALI_TEST_EQUALS(customVertexShaderSource, vertexShaderSource, TEST_LOCATION);
883 // Check fragment shader changed
884 const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix();
885 size_t pos = fragmentShaderSource.find(fragmentPrefix);
887 DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION);
889 DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION);
891 // Check whether preMultipliedAlpha is false.
892 // Note : We dont use preMultiplied alpha when app developer using custom shader.
893 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
894 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
899 int UtcDaliImageVisualWithNativeImageRemoved(void)
901 ToolkitTestApplication application;
902 tet_infoline("Use Native Image as url");
904 TestGlAbstraction& gl = application.GetGlAbstraction();
905 TraceCallStack& textureTrace = gl.GetTextureTrace();
906 textureTrace.Enable(true);
908 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
909 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
910 std::string url = imageUrl.GetUrl();
912 VisualFactory factory = VisualFactory::Get();
913 DALI_TEST_CHECK(factory);
915 Property::Map propertyMap;
916 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
917 propertyMap.Insert(ImageVisual::Property::URL, url);
919 Visual::Base visual = factory.CreateVisual(propertyMap);
920 DALI_TEST_CHECK(visual);
922 DummyControl actor = DummyControl::New();
923 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
924 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
926 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
928 application.GetScene().Add(actor);
929 application.SendNotification();
930 application.Render();
932 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
933 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
935 tet_infoline("No delete texture because reference count is not zero");
937 application.GetScene().Remove(actor);
938 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
939 application.SendNotification();
940 application.Render();
942 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
943 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
945 tet_infoline("Delete texture because reference count is zero");
947 application.SendNotification();
948 application.Render();
950 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
955 int UtcDaliImageVisualWithEncodedImageBuffer(void)
957 ToolkitTestApplication application;
958 tet_infoline("Use Encoded Image Buffer as url");
960 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
961 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
963 VisualFactory factory = VisualFactory::Get();
964 DALI_TEST_CHECK(factory);
966 Property::Map propertyMap;
967 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
968 propertyMap.Insert(ImageVisual::Property::URL, url.GetUrl());
970 Visual::Base visual = factory.CreateVisual(propertyMap);
971 DALI_TEST_CHECK(visual);
973 TestGlAbstraction& gl = application.GetGlAbstraction();
974 TraceCallStack& textureTrace = gl.GetTextureTrace();
975 textureTrace.Enable(true);
977 DummyControl actor = DummyControl::New();
978 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
979 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
981 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
982 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
984 application.GetScene().Add(actor);
985 application.SendNotification();
987 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
989 application.SendNotification();
990 application.Render();
992 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
993 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
995 application.GetScene().Remove(actor);
996 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1001 int UtcDaliImageVisualWithEncodedImageBufferRemoved(void)
1003 ToolkitTestApplication application;
1004 tet_infoline("Use Encoded Image Buffer as url");
1006 TestGlAbstraction& gl = application.GetGlAbstraction();
1007 TraceCallStack& textureTrace = gl.GetTextureTrace();
1008 textureTrace.Enable(true);
1010 EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME);
1011 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer);
1012 std::string url = imageUrl.GetUrl();
1014 VisualFactory factory = VisualFactory::Get();
1015 DALI_TEST_CHECK(factory);
1017 Property::Map propertyMap;
1018 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1019 propertyMap.Insert(ImageVisual::Property::URL, url);
1021 Visual::Base visual = factory.CreateVisual(propertyMap);
1022 DALI_TEST_CHECK(visual);
1024 DummyControl actor = DummyControl::New();
1025 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1026 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1028 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1030 application.GetScene().Add(actor);
1031 application.SendNotification();
1033 // Wait for decode buffer and make texture.
1034 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1036 application.SendNotification();
1037 application.Render();
1039 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1040 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1042 tet_infoline("Delete texture because there is no actor to use decoded texture");
1044 application.GetScene().Remove(actor);
1045 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
1046 application.SendNotification();
1047 application.Render();
1049 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1050 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1055 int UtcDaliImageVisualTextureReuse1(void)
1057 ToolkitTestApplication application;
1058 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture");
1060 Property::Map propertyMap;
1061 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1062 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1063 propertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
1065 TestGlAbstraction& gl = application.GetGlAbstraction();
1066 TraceCallStack& textureTrace = gl.GetTextureTrace();
1067 textureTrace.Enable(true);
1068 TraceCallStack& drawTrace = gl.GetDrawTrace();
1069 drawTrace.Enable(true);
1071 Actor actor = CreateActorWithImageVisual(propertyMap);
1072 application.GetScene().Add(actor);
1073 application.SendNotification();
1075 // Wait for image to load
1076 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1078 application.SendNotification();
1079 application.Render();
1081 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1082 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1083 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1084 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1085 textureTrace.Reset();
1088 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1089 application.GetScene().Add(actor2);
1091 application.SendNotification(); // Send messages to update
1092 application.Render(); // process update and render
1093 application.SendNotification(); // process any signals to event
1095 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1097 // Testing for texture re-use in gl side is not relevant - we are not using actual graphics
1098 // backend here, but test graphics backend.
1099 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1100 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1102 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
1104 application.GetScene().Remove(actor);
1105 application.SendNotification();
1106 application.Render();
1108 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1109 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
1111 tet_infoline("Test that removing last actor does delete the texture\n");
1113 application.GetScene().Remove(actor2); // Detaches remaining ImageVisual
1114 application.SendNotification();
1115 application.Render();
1117 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1118 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1123 int UtcDaliImageVisualTextureReuse2(void)
1125 ToolkitTestApplication application;
1126 tet_infoline("Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture");
1128 Property::Map propertyMap;
1129 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1130 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1132 TestGlAbstraction& gl = application.GetGlAbstraction();
1133 TraceCallStack& textureTrace = gl.GetTextureTrace();
1134 textureTrace.Enable(true);
1135 TraceCallStack& drawTrace = gl.GetDrawTrace();
1136 drawTrace.Enable(true);
1138 Actor actor = CreateActorWithImageVisual(propertyMap);
1139 application.GetScene().Add(actor);
1140 application.SendNotification();
1142 // Wait for image to load
1143 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1149 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1150 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1151 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1152 textureTrace.Reset();
1155 propertyMap.Insert(ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST);
1156 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 100);
1157 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 100);
1158 Actor actor2 = CreateActorWithImageVisual(propertyMap);
1159 application.GetScene().Add(actor2);
1161 application.SendNotification();
1163 // Wait for image to load
1164 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1166 application.SendNotification();
1167 application.Render();
1169 DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION);
1172 "Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
1173 "renderers are using different textures\n");
1175 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1176 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION);
1177 TraceCallStack::NamedParams tex1;
1178 tex1["texture"] << 1;
1179 TraceCallStack::NamedParams tex2;
1180 tex2["texture"] << 2;
1181 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION);
1182 DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION);
1184 tet_infoline("Test that removing 1 actor deletes it's texture\n");
1186 application.GetScene().Remove(actor);
1187 application.SendNotification();
1188 application.Render();
1190 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1191 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
1193 tet_infoline("Test that removing last actor deletes it's texture\n");
1195 application.GetScene().Remove(actor2);
1196 application.SendNotification();
1197 application.Render();
1199 DALI_TEST_CHECK(actor2.GetRendererCount() == 0u);
1200 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
1205 int UtcDaliImageVisualCustomWrapModePixelArea(void)
1207 ToolkitTestApplication application;
1208 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing");
1210 static std::vector<UniformData> customUniforms =
1212 UniformData("pixelArea", Property::Type::VECTOR4),
1213 UniformData("wrapMode", Property::Type::VECTOR2),
1216 TestGraphicsController& graphics = application.GetGraphicsController();
1217 graphics.AddCustomUniforms(customUniforms);
1219 VisualFactory factory = VisualFactory::Get();
1220 DALI_TEST_CHECK(factory);
1222 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1223 const int width = 34;
1224 const int height = 34;
1225 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1227 Property::Map propertyMap;
1228 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1229 propertyMap.Insert(ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME);
1230 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1231 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1232 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1233 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1234 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1235 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1236 propertyMap.Insert(ImageVisual::Property::ATLASING, true);
1238 Visual::Base visual = factory.CreateVisual(propertyMap);
1239 DALI_TEST_CHECK(visual);
1241 TestGlAbstraction& gl = application.GetGlAbstraction();
1242 TraceCallStack& textureTrace = gl.GetTextureTrace();
1243 textureTrace.Enable(true);
1244 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1245 texParameterTrace.Enable(true);
1247 DummyControl actor = DummyControl::New();
1248 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1249 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1250 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1251 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1252 application.GetScene().Add(actor);
1255 application.SendNotification();
1256 application.Render();
1258 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1260 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1262 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
1263 std::stringstream out;
1264 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1265 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1267 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1268 DALI_TEST_CHECK(!texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1270 // test the uniforms which used to handle the wrap mode
1271 Renderer renderer = actor.GetRendererAt(0u);
1272 DALI_TEST_CHECK(renderer);
1274 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1275 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1276 Vector4 pixelAreaUniform;
1277 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1278 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1280 Property::Value wrapModeValue = renderer.GetProperty(renderer.GetPropertyIndex("wrapMode"));
1281 Vector2 wrapMode(WrapMode::MIRRORED_REPEAT - 1, WrapMode::REPEAT - 1);
1282 DALI_TEST_EQUALS(wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION);
1283 Vector2 wrapModeUniform;
1284 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>("wrapMode", wrapModeUniform));
1285 DALI_TEST_EQUALS(wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1288 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1293 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
1295 ToolkitTestApplication application;
1296 tet_infoline("Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing");
1298 static std::vector<UniformData> customUniforms =
1300 UniformData("pixelArea", Property::Type::VECTOR4),
1303 TestGraphicsController& graphics = application.GetGraphicsController();
1304 graphics.AddCustomUniforms(customUniforms);
1306 VisualFactory factory = VisualFactory::Get();
1307 DALI_TEST_CHECK(factory);
1309 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
1310 const int width = 600;
1311 const int height = 600;
1312 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1314 Property::Map propertyMap;
1315 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1316 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
1317 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, width);
1318 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, height);
1319 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1320 propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea);
1321 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT);
1322 propertyMap.Insert(ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT);
1324 Visual::Base visual = factory.CreateVisual(propertyMap);
1325 DALI_TEST_CHECK(visual);
1327 TestGlAbstraction& gl = application.GetGlAbstraction();
1328 TraceCallStack& textureTrace = gl.GetTextureTrace();
1329 textureTrace.Enable(true);
1330 textureTrace.EnableLogging(true);
1331 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1332 texParameterTrace.Enable(true);
1333 texParameterTrace.EnableLogging(true);
1335 DummyControl actor = DummyControl::New();
1336 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1337 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1338 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1339 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1340 application.GetScene().Add(actor);
1343 application.SendNotification();
1344 application.Render();
1345 application.SendNotification();
1347 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
1349 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1351 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
1352 std::stringstream out;
1353 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1354 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1356 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1357 DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str()));
1359 // test the uniforms which used to handle the wrap mode
1360 Renderer renderer = actor.GetRendererAt(0u);
1361 DALI_TEST_CHECK(renderer);
1363 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
1364 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION);
1365 Vector4 pixelAreaUniform;
1366 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
1367 DALI_TEST_EQUALS(pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
1369 Property::Index wrapModeIndex = renderer.GetPropertyIndex("wrapMode");
1370 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
1373 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1378 int UtcDaliImageVisualAnimateMixColor(void)
1380 ToolkitTestApplication application;
1381 tet_infoline("Animate mix color");
1383 static std::vector<UniformData> customUniforms =
1385 UniformData("mixColor", Property::Type::VECTOR3),
1388 TestGraphicsController& graphics = application.GetGraphicsController();
1389 graphics.AddCustomUniforms(customUniforms);
1391 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1393 VisualFactory factory = VisualFactory::Get();
1394 Property::Map propertyMap;
1395 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1396 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1397 propertyMap.Insert("mixColor", Color::BLUE);
1398 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1399 Visual::Base visual = factory.CreateVisual(propertyMap);
1401 DummyControl actor = DummyControl::New(true);
1402 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1403 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1405 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1406 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1407 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1408 application.GetScene().Add(actor);
1410 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1412 Renderer renderer = actor.GetRendererAt(0);
1414 // @todo Should we add API to make this code work again?
1415 // Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1417 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1418 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1420 const Vector4 TARGET_MIX_COLOR(1.0f, 0.0f, 0.0f, 0.5f);
1423 map["target"] = "testVisual";
1424 map["property"] = "mixColor";
1425 map["initialValue"] = Color::MAGENTA;
1426 map["targetValue"] = TARGET_MIX_COLOR;
1427 map["animator"] = Property::Map()
1428 .Add("alphaFunction", "LINEAR")
1429 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1431 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1433 Animation animation = dummyImpl.CreateTransition(transition);
1435 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1438 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1439 glAbstraction.EnableEnableDisableCallTrace(true);
1440 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1441 std::ostringstream blendStr;
1442 blendStr << std::hex << GL_BLEND;
1444 application.SendNotification();
1445 application.Render(0); // Ensure animation starts
1446 application.Render(2000u); // Halfway point
1447 Vector3 testColor(1.0f, 0.0f, 0.5f);
1449 // uColor.a should be actor's alpha * mixColor.a.
1450 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 0.75f)), true, TEST_LOCATION);
1451 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", testColor), true, TEST_LOCATION);
1453 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1455 glEnableStack.Reset();
1457 application.SendNotification();
1458 application.Render(2000u);
1460 application.SendNotification();
1461 application.Render();
1462 application.SendNotification();
1464 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Color::WHITE, TEST_LOCATION);
1465 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION);
1466 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION);
1468 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1470 TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR);
1475 int UtcDaliImageVisualAnimateOpacity(void)
1477 ToolkitTestApplication application;
1478 tet_infoline("Animate image visual opacity");
1480 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1482 VisualFactory factory = VisualFactory::Get();
1483 Property::Map propertyMap;
1484 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1485 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1486 propertyMap.Insert("opacity", 0.5f);
1487 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1488 Visual::Base visual = factory.CreateVisual(propertyMap);
1490 DummyControl actor = DummyControl::New(true);
1491 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1492 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1494 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1495 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1496 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1497 application.GetScene().Add(actor);
1499 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1501 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1502 glAbstraction.EnableEnableDisableCallTrace(true);
1503 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1504 std::ostringstream blendStr;
1505 blendStr << std::hex << GL_BLEND;
1507 application.SendNotification();
1508 application.Render();
1510 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1513 tet_infoline("Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1516 map["target"] = "testVisual";
1517 map["property"] = "opacity";
1518 map["targetValue"] = 1.0f;
1519 map["animator"] = Property::Map()
1520 .Add("alphaFunction", "LINEAR")
1521 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1523 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1524 Animation animation = dummyImpl.CreateTransition(transition);
1527 glEnableStack.Reset();
1529 application.SendNotification();
1530 application.Render(0); // Ensure animation starts
1531 application.Render(2000u); // Halfway point through animation
1532 application.SendNotification(); // Handle any signals
1535 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1536 DALI_TEST_EQUALS(color.a, 0.75f, TEST_LOCATION);
1538 application.Render(2001u); // end
1539 application.SendNotification(); // ensure animation finished signal is sent
1541 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1542 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1544 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1545 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1549 tet_infoline("Test that the opacity can be reduced via animation, and that the blend mode is set appropriately at the start and end of the animation.");
1552 map["target"] = "testVisual";
1553 map["property"] = Visual::Property::OPACITY;
1554 map["targetValue"] = 0.1f;
1555 map["animator"] = Property::Map()
1556 .Add("alphaFunction", "LINEAR")
1557 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1559 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1560 Animation animation = dummyImpl.CreateTransition(transition);
1563 glEnableStack.Reset();
1565 application.SendNotification();
1566 application.Render(0); // Ensure animation starts
1567 application.Render(2000u); // Halfway point
1568 application.SendNotification();
1571 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1572 DALI_TEST_EQUALS(color.a, 0.55f, TEST_LOCATION);
1574 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1576 glEnableStack.Reset();
1578 application.Render(2016u); // end
1579 application.SendNotification();
1581 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1582 DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION);
1584 // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend)
1585 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1591 int UtcDaliImageVisualAnimateOpacity02(void)
1593 ToolkitTestApplication application;
1594 tet_infoline("Animate image visual opacity");
1596 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1598 VisualFactory factory = VisualFactory::Get();
1599 Property::Map propertyMap;
1600 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1601 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1602 propertyMap.Insert("opacity", 0.5f);
1603 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1604 Visual::Base visual = factory.CreateVisual(propertyMap);
1606 DummyControl actor = DummyControl::New(true);
1607 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1608 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1610 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1611 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1612 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1614 tet_infoline("Test that the opacity doesn't animate when actor not staged");
1616 Property::Array array;
1619 map["target"] = "testVisual";
1620 map["property"] = "opacity";
1621 map["initialValue"] = 0.0f;
1622 map["targetValue"] = 1.0f;
1623 map["animator"] = Property::Map()
1624 .Add("alphaFunction", "LINEAR")
1625 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1628 map2["target"] = "testVisual";
1629 map2["property"] = "size";
1630 map2["targetValue"] = Vector2(1.0f, 1.0f);
1632 array.Add(map).Add(map2);
1634 Dali::Toolkit::TransitionData transition = TransitionData::New(array);
1635 Animation animation = dummyImpl.CreateTransition(transition);
1637 application.GetScene().Add(actor);
1638 application.SendNotification();
1639 application.Render(0); // Ensure animation starts
1641 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1643 Renderer renderer = actor.GetRendererAt(0);
1644 Property::Value blendModeValue = renderer.GetProperty(Renderer::Property::BLEND_MODE);
1645 DALI_TEST_EQUALS(blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION);
1647 animation = dummyImpl.CreateTransition(transition);
1650 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1651 glAbstraction.EnableEnableDisableCallTrace(true);
1652 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1653 std::ostringstream blendStr;
1654 blendStr << std::hex << GL_BLEND;
1656 application.SendNotification();
1657 application.Render(0); // Ensure animation starts
1658 application.Render(2000u); // Halfway point through animation
1659 application.SendNotification(); // Handle any signals
1661 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
1664 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1665 DALI_TEST_EQUALS(color.a, 0.5f, TEST_LOCATION);
1667 glEnableStack.Reset();
1669 application.Render(2001u); // end
1670 application.SendNotification(); // ensure animation finished signal is sent
1672 DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue<Vector4>("uColor", color));
1673 DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION);
1675 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str()));
1680 int UtcDaliImageVisualAnimatePixelArea(void)
1682 ToolkitTestApplication application;
1683 tet_infoline("ImageVisual animate pixel area");
1685 static std::vector<UniformData> customUniforms =
1687 UniformData("pixelArea", Property::Type::VECTOR4),
1690 TestGraphicsController& graphics = application.GetGraphicsController();
1691 graphics.AddCustomUniforms(customUniforms);
1693 application.GetPlatform().SetClosestImageSize(Vector2(100, 100));
1695 VisualFactory factory = VisualFactory::Get();
1696 Property::Map propertyMap;
1697 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1698 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1699 propertyMap.Insert("mixColor", Color::BLUE);
1700 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1701 Visual::Base visual = factory.CreateVisual(propertyMap);
1703 DummyControl actor = DummyControl::New(true);
1704 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1705 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
1707 actor.SetProperty(Actor::Property::SIZE, Vector2(2000, 2000));
1708 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1709 actor.SetProperty(Actor::Property::COLOR, Color::BLACK);
1710 application.GetScene().Add(actor);
1712 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1714 Renderer renderer = actor.GetRendererAt(0);
1715 // @todo Implement this feature?
1716 //Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1717 //tet_infoline("Test that the renderer has the mixColor property");
1718 //DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1720 // TransitionData only takes string keys
1722 map["target"] = "testVisual";
1723 map["property"] = "pixelArea";
1724 map["initialValue"] = Vector4(0, 0, 0, 1);
1725 map["targetValue"] = Vector4(0, 0, 1, 1); // Animate width from zero to full
1726 map["animator"] = Property::Map()
1727 .Add("alphaFunction", "LINEAR")
1728 .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 4.0f));
1730 Dali::Toolkit::TransitionData transition = TransitionData::New(map);
1732 Animation animation = dummyImpl.CreateTransition(transition);
1733 animation.AnimateTo(Property(actor, Actor::Property::COLOR), Color::WHITE);
1736 application.SendNotification();
1737 application.Render(0); // Ensure animation starts
1738 application.Render(2000u); // Halfway point
1740 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f)), true, TEST_LOCATION);
1742 application.Render(2000u); // End of animation
1744 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 1.0f, 1.0f)), true, TEST_LOCATION);
1749 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1751 ToolkitTestApplication application;
1752 tet_infoline("Request remote image visual, then destroy visual to cancel load");
1754 Property::Map propertyMap;
1755 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1756 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME);
1758 TestGlAbstraction& gl = application.GetGlAbstraction();
1759 TraceCallStack& textureTrace = gl.GetTextureTrace();
1760 textureTrace.Enable(true);
1761 TraceCallStack& drawTrace = gl.GetDrawTrace();
1762 drawTrace.Enable(true);
1764 Actor actor = CreateActorWithImageVisual(propertyMap);
1765 application.GetScene().Add(actor);
1766 application.SendNotification();
1768 application.GetScene().Remove(actor);
1769 application.SendNotification();
1771 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1772 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
1773 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION);
1774 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
1779 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1781 ToolkitTestApplication application;
1782 tet_infoline("Load image asynchronously, cancel loading, then load again");
1784 VisualFactory factory = VisualFactory::Get();
1785 DALI_TEST_CHECK(factory);
1787 Property::Map propertyMap;
1788 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1789 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
1791 Visual::Base visual = factory.CreateVisual(propertyMap);
1792 DALI_TEST_CHECK(visual);
1794 TestGlAbstraction& gl = application.GetGlAbstraction();
1795 TraceCallStack& textureTrace = gl.GetTextureTrace();
1796 textureTrace.Enable(true);
1797 TraceCallStack& drawTrace = gl.GetDrawTrace();
1798 drawTrace.Enable(true);
1800 DummyControl actor = DummyControl::New();
1801 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1802 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1804 application.GetScene().Add(actor);
1807 application.GetScene().Remove(actor);
1809 application.GetScene().Add(actor);
1811 // Create another visual with the same image
1812 visual = factory.CreateVisual(propertyMap);
1813 DALI_TEST_CHECK(visual);
1815 dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual);
1817 application.SendNotification();
1818 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1820 application.SendNotification();
1821 application.Render();
1823 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1824 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
1825 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1826 DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
1831 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1833 ToolkitTestApplication application;
1834 tet_infoline("Request image visual with invalid images - should draw broken.png");
1836 VisualFactory factory = VisualFactory::Get();
1837 DALI_TEST_CHECK(factory);
1839 Property::Map propertyMap;
1840 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1841 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1843 Visual::Base visual = factory.CreateVisual(propertyMap);
1844 DALI_TEST_CHECK(visual);
1846 TestGlAbstraction& gl = application.GetGlAbstraction();
1847 TraceCallStack& textureTrace = gl.GetTextureTrace();
1848 textureTrace.Enable(true);
1850 DummyControl actor = DummyControl::New();
1851 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1852 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1854 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1855 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1857 application.GetScene().Add(actor);
1859 application.SendNotification();
1860 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1862 application.SendNotification();
1863 application.Render();
1865 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1866 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1868 application.GetScene().Remove(actor);
1869 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1874 int UtcDaliImageVisualSetInvalidSyncImage(void)
1876 ToolkitTestApplication application;
1877 tet_infoline("Request image visual with invalid images - should draw broken.png");
1879 VisualFactory factory = VisualFactory::Get();
1880 DALI_TEST_CHECK(factory);
1882 Property::Map propertyMap;
1883 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1884 propertyMap.Insert(ImageVisual::Property::URL, TEST_INVALID_FILE_NAME);
1885 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1887 Visual::Base visual = factory.CreateVisual(propertyMap);
1888 DALI_TEST_CHECK(visual);
1890 TestGlAbstraction& gl = application.GetGlAbstraction();
1891 TraceCallStack& textureTrace = gl.GetTextureTrace();
1892 textureTrace.Enable(true);
1894 DummyControl actor = DummyControl::New();
1895 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1896 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1898 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1899 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1901 application.GetScene().Add(actor);
1903 application.SendNotification();
1904 application.Render();
1906 // Check resource status
1907 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1908 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1910 // The broken image should be shown.
1911 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1912 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1914 application.GetScene().Remove(actor);
1915 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1920 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1922 ToolkitTestApplication application;
1923 tet_infoline("Request image visual with invalid images - should draw broken.png");
1925 VisualFactory factory = VisualFactory::Get();
1926 DALI_TEST_CHECK(factory);
1928 // Local invalid file, asynchronous loading
1929 Property::Map propertyMap;
1930 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
1931 propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME);
1933 Visual::Base visual = factory.CreateVisual(propertyMap);
1934 DALI_TEST_CHECK(visual);
1936 TestGlAbstraction& gl = application.GetGlAbstraction();
1937 TraceCallStack& textureTrace = gl.GetTextureTrace();
1938 textureTrace.Enable(true);
1940 DummyControl actor = DummyControl::New();
1941 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1942 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1944 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1945 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1947 application.GetScene().Add(actor);
1949 application.SendNotification();
1950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1952 application.SendNotification();
1953 application.Render();
1955 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
1956 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
1958 application.GetScene().Remove(actor);
1959 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
1964 int UtcDaliImageVisualAlphaMask01(void)
1966 ToolkitTestApplication application;
1967 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
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_LARGE_IMAGE_FILE_NAME);
1975 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1977 Visual::Base visual = factory.CreateVisual(propertyMap);
1978 DALI_TEST_CHECK(visual);
1980 Property::Map testMap;
1981 visual.CreatePropertyMap(testMap);
1982 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
1984 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1985 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1987 TestGlAbstraction& gl = application.GetGlAbstraction();
1988 TraceCallStack& textureTrace = gl.GetTextureTrace();
1989 textureTrace.Enable(true);
1991 DummyControl actor = DummyControl::New();
1992 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1993 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
1995 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
1996 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
1997 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
1999 application.GetScene().Add(actor);
2000 application.SendNotification();
2001 application.Render();
2003 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2005 application.SendNotification();
2006 application.Render();
2008 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2009 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2010 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2012 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2013 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2018 int UtcDaliImageVisualAlphaMask02(void)
2020 ToolkitTestApplication application;
2021 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU");
2023 VisualFactory factory = VisualFactory::Get();
2024 DALI_TEST_CHECK(factory);
2026 Property::Map propertyMap;
2027 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2028 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2029 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2030 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2032 Visual::Base visual = factory.CreateVisual(propertyMap);
2033 DALI_TEST_CHECK(visual);
2035 Property::Map testMap;
2036 visual.CreatePropertyMap(testMap);
2037 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2038 DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), TEST_LOCATION);
2040 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2041 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2043 TestGlAbstraction& gl = application.GetGlAbstraction();
2044 TraceCallStack& textureTrace = gl.GetTextureTrace();
2045 textureTrace.Enable(true);
2047 DummyControl actor = DummyControl::New();
2048 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2049 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2051 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2052 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2053 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2055 application.GetScene().Add(actor);
2056 application.SendNotification();
2057 application.Render();
2059 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2061 application.SendNotification();
2062 application.Render();
2064 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2065 Renderer renderer = actor.GetRendererAt(0u);
2066 TextureSet textures = renderer.GetTextures();
2067 DALI_TEST_CHECK(textures);
2068 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2070 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2071 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2073 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2074 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2079 int UtcDaliImageVisualAlphaMask03(void)
2081 ToolkitTestApplication application;
2082 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case");
2084 VisualFactory factory = VisualFactory::Get();
2085 DALI_TEST_CHECK(factory);
2087 Property::Map propertyMap;
2088 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2089 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2090 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path");
2091 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2093 Visual::Base visual = factory.CreateVisual(propertyMap);
2094 DALI_TEST_CHECK(visual);
2096 Property::Map testMap;
2097 visual.CreatePropertyMap(testMap);
2099 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2100 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2102 TestGlAbstraction& gl = application.GetGlAbstraction();
2103 TraceCallStack& textureTrace = gl.GetTextureTrace();
2104 textureTrace.Enable(true);
2106 DummyControl actor = DummyControl::New();
2107 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2108 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2110 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2111 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2112 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2114 application.GetScene().Add(actor);
2115 application.SendNotification();
2116 application.Render();
2118 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2120 application.SendNotification();
2121 application.Render();
2123 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2124 Renderer renderer = actor.GetRendererAt(0u);
2125 TextureSet textures = renderer.GetTextures();
2126 DALI_TEST_CHECK(textures);
2127 DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION);
2129 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2130 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2132 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2133 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2138 int UtcDaliImageVisualSynchronousLoadAlphaMask01(void)
2140 ToolkitTestApplication application;
2141 tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading");
2143 VisualFactory factory = VisualFactory::Get();
2144 DALI_TEST_CHECK(factory);
2146 Property::Map propertyMap;
2147 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2148 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2149 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2150 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2152 Visual::Base visual = factory.CreateVisual(propertyMap);
2153 DALI_TEST_CHECK(visual);
2155 Property::Map testMap;
2156 visual.CreatePropertyMap(testMap);
2157 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2159 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2160 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2162 TestGlAbstraction& gl = application.GetGlAbstraction();
2163 TraceCallStack& textureTrace = gl.GetTextureTrace();
2164 textureTrace.Enable(true);
2166 DummyControl actor = DummyControl::New();
2167 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2168 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2170 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2171 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2172 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2174 application.GetScene().Add(actor);
2176 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2178 application.SendNotification();
2179 application.Render();
2181 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2182 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2183 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2185 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2186 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2191 int UtcDaliImageVisualSynchronousLoadAlphaMask02(void)
2193 ToolkitTestApplication application;
2194 tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading");
2196 VisualFactory factory = VisualFactory::Get();
2197 DALI_TEST_CHECK(factory);
2199 Property::Map propertyMap;
2200 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2201 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2202 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2203 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2204 propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
2206 Visual::Base visual = factory.CreateVisual(propertyMap);
2207 DALI_TEST_CHECK(visual);
2209 Property::Map testMap;
2210 visual.CreatePropertyMap(testMap);
2211 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2213 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2214 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2216 TestGlAbstraction& gl = application.GetGlAbstraction();
2217 TraceCallStack& textureTrace = gl.GetTextureTrace();
2218 textureTrace.Enable(true);
2220 DummyControl actor = DummyControl::New();
2221 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2222 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2224 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2225 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2226 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2228 application.GetScene().Add(actor);
2230 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
2232 application.SendNotification();
2233 application.Render();
2235 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2236 Renderer renderer = actor.GetRendererAt(0u);
2237 TextureSet textures = renderer.GetTextures();
2238 DALI_TEST_CHECK(textures);
2239 DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION);
2241 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2242 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2244 dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1);
2245 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2250 int UtcDaliImageVisualRemoteAlphaMask(void)
2252 ToolkitTestApplication application;
2253 tet_infoline("Request image visual with a Property::Map containing an Alpha mask");
2255 VisualFactory factory = VisualFactory::Get();
2256 DALI_TEST_CHECK(factory);
2258 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
2260 Property::Map propertyMap;
2261 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2262 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2263 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE);
2265 Visual::Base visual = factory.CreateVisual(propertyMap);
2266 DALI_TEST_CHECK(visual);
2268 Property::Map testMap;
2269 visual.CreatePropertyMap(testMap);
2271 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(MASK_IMAGE), TEST_LOCATION);
2273 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2274 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2276 TestGlAbstraction& gl = application.GetGlAbstraction();
2277 TraceCallStack& textureTrace = gl.GetTextureTrace();
2278 textureTrace.Enable(true);
2280 DummyControl actor = DummyControl::New();
2281 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2282 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2284 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2286 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2287 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2289 application.GetScene().Add(actor);
2290 application.SendNotification();
2291 application.Render();
2293 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2295 application.SendNotification();
2296 application.Render();
2298 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2299 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2300 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2305 int UtcDaliImageVisualAlphaMaskCrop(void)
2307 ToolkitTestApplication application;
2308 tet_infoline("Request image visual with an Alpha mask and scale/cropping");
2310 VisualFactory factory = VisualFactory::Get();
2311 DALI_TEST_CHECK(factory);
2313 Property::Map propertyMap;
2314 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
2315 propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME);
2316 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
2317 propertyMap.Insert(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f);
2318 propertyMap.Insert(ImageVisual::Property::CROP_TO_MASK, true);
2320 Visual::Base visual = factory.CreateVisual(propertyMap);
2321 DALI_TEST_CHECK(visual);
2323 Property::Map testMap;
2324 visual.CreatePropertyMap(testMap);
2325 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL), Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION);
2326 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION);
2327 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::CROP_TO_MASK), Property::Value(true), TEST_LOCATION);
2329 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
2330 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
2332 TestGlAbstraction& gl = application.GetGlAbstraction();
2333 TraceCallStack& textureTrace = gl.GetTextureTrace();
2334 textureTrace.Enable(true);
2336 DummyControl actor = DummyControl::New();
2337 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2338 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
2340 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2341 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2342 DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION);
2344 application.GetScene().Add(actor);
2345 application.SendNotification();
2346 application.Render();
2348 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
2350 application.SendNotification();
2351 application.Render();
2354 visual.GetNaturalSize(size);
2356 DALI_TEST_EQUALS(size, Vector2(100.0f, 100.0f), 0.001f, TEST_LOCATION);
2357 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2358 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2359 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
2364 int UtcDaliImageVisualReleasePolicy01(void)
2366 ToolkitTestApplication application;
2367 tet_infoline("UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture");
2369 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2370 DALI_TEST_CHECK(imageVisual);
2372 // Set up debug trace
2373 TestGlAbstraction& gl = application.GetGlAbstraction();
2374 TraceCallStack& textureTrace = gl.GetTextureTrace();
2375 textureTrace.Enable(true);
2377 tet_infoline("Register visual with control and ensure it has the only handle");
2378 DummyControl actor = DummyControl::New(true);
2379 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2380 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2381 imageVisual.Reset();
2383 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2385 application.SendNotification();
2386 application.Render(0);
2387 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2388 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2390 application.GetScene().Add(actor);
2392 // Wait for image to load
2393 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2395 application.SendNotification();
2396 application.Render(0);
2397 // Test renderer and texture created
2398 tet_infoline("Confirm texture created");
2399 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2400 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2402 tet_infoline("Disable visual causing the texture to be deleted");
2403 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2405 application.SendNotification();
2406 application.Render(0);
2407 // Test renderer and textures removed.
2408 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2409 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2414 int UtcDaliImageVisualReleasePolicy02(void)
2416 ToolkitTestApplication application;
2417 tet_infoline("UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed");
2419 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2420 DALI_TEST_CHECK(imageVisual);
2422 // Setup debug trace
2423 TestGlAbstraction& gl = application.GetGlAbstraction();
2424 TraceCallStack& textureTrace = gl.GetTextureTrace();
2425 textureTrace.Enable(true);
2427 tet_infoline("Register visual with control and ensure it has the only handle");
2428 DummyControl actor = DummyControl::New(true);
2429 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2430 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2431 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2433 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2435 application.SendNotification();
2436 application.Render(0);
2437 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2438 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2440 application.GetScene().Add(actor);
2442 // Wait for image to load
2443 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2445 application.SendNotification();
2446 application.Render(0);
2447 // Test renderer and texture created
2448 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2449 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2451 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2452 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2453 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2454 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2455 application.SendNotification();
2456 application.Render();
2458 // Test texture removed after visual destroyed.
2459 tet_infoline("Ensure texture is deleted after visual destroyed");
2460 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2465 int UtcDaliImageVisualReleasePolicy03(void)
2467 ToolkitTestApplication application;
2468 tet_infoline("UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed");
2470 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2471 DALI_TEST_CHECK(imageVisual);
2473 TestGlAbstraction& gl = application.GetGlAbstraction();
2474 TraceCallStack& textureTrace = gl.GetTextureTrace();
2475 textureTrace.Enable(true);
2477 tet_infoline("Register visual with control and ensure it has the only handle");
2478 DummyControl actor = DummyControl::New(true);
2479 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2480 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2481 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2483 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2485 application.SendNotification();
2486 application.Render(0);
2487 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2488 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2490 application.GetScene().Add(actor);
2492 // Wait for image to load
2493 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2495 application.SendNotification();
2496 application.Render(0);
2497 // Test renderer and texture created
2498 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2499 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2501 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2502 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2503 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2504 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2505 application.SendNotification();
2506 application.Render();
2508 tet_infoline("Ensure texture is not deleted as policy is set to NEVER");
2509 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2514 int UtcDaliImageVisualReleasePolicy04(void)
2516 ToolkitTestApplication application;
2517 tet_infoline("UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture");
2519 tet_infoline("Create first visual with Never release policy");
2520 Visual::Base imageVisualNever = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2522 tet_infoline("Create second visual with Destroyed release policy");
2523 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2525 // Set up trace debug
2526 TestGlAbstraction& gl = application.GetGlAbstraction();
2527 TraceCallStack& textureTrace = gl.GetTextureTrace();
2528 textureTrace.Enable(true);
2530 tet_infoline("Register visuals with control and ensure it has the only handles");
2531 DummyControl actor = DummyControl::New(true);
2532 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2533 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualNever);
2534 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed);
2535 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
2536 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2538 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2540 // Test initially zero renderers
2541 application.SendNotification();
2542 application.Render(0);
2543 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2544 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2546 application.GetScene().Add(actor);
2548 // Wait for image to load
2549 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2551 application.SendNotification();
2552 application.Render(0);
2553 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2554 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2555 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2557 // Test renderer removed when visual destroyed
2558 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2559 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL2); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
2560 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2561 application.SendNotification();
2562 application.Render();
2564 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2565 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2567 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2568 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2569 application.SendNotification();
2570 application.Render();
2572 tet_infoline("Ensure a texture is not deleted as second visual used the NEVER release policy");
2573 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
2574 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2579 int UtcDaliImageVisualReleasePolicy05(void)
2581 ToolkitTestApplication application;
2582 tet_infoline("UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum");
2584 VisualFactory factory = VisualFactory::Get();
2586 Property::Map propertyMapNeverReleasePolicy;
2587 propertyMapNeverReleasePolicy.Insert(Visual::Property::TYPE, Visual::IMAGE);
2588 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2589 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2590 propertyMapNeverReleasePolicy.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2591 propertyMapNeverReleasePolicy.Insert("releasePolicy", "never");
2593 Visual::Base imageVisualNever = factory.CreateVisual(propertyMapNeverReleasePolicy);
2595 Property::Map resultMap;
2596 imageVisualNever.CreatePropertyMap(resultMap);
2597 DALI_TEST_CHECK(!resultMap.Empty());
2599 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::RELEASE_POLICY))->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION);
2604 int UtcDaliImageVisualReleasePolicy06(void)
2606 ToolkitTestApplication application;
2607 tet_infoline("UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual");
2609 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
2610 DALI_TEST_CHECK(imageVisual);
2612 TestGlAbstraction& gl = application.GetGlAbstraction();
2613 TraceCallStack& textureTrace = gl.GetTextureTrace();
2614 textureTrace.Enable(true);
2616 tet_infoline("Register visual with control and ensure it has the only handle");
2617 DummyControl actor = DummyControl::New(true);
2618 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2619 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2620 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2622 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2624 application.SendNotification();
2625 application.Render(0);
2626 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2627 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2629 application.GetScene().Add(actor);
2631 // Wait for image to load
2632 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2634 application.SendNotification();
2635 application.Render(0);
2636 // Test renderer and texture created
2637 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2638 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2639 textureTrace.Reset();
2641 tet_infoline("Disable Visual and check texture not affected");
2642 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2643 application.SendNotification();
2644 application.Render(0);
2645 tet_infoline("Check renderer is destroyed when visual off stage");
2646 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2647 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2648 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2649 textureTrace.Reset();
2651 tet_infoline("Re-enable Visual and check texture not affected");
2652 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, true);
2653 application.SendNotification();
2654 application.Render(0);
2655 tet_infoline("Check texture not affected and renderer is destroyed when visual off stage");
2656 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2657 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2658 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2663 int UtcDaliImageVisualReleasePolicy07(void)
2665 ToolkitTestApplication application;
2666 tet_infoline("UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED");
2668 tet_infoline("Create first visual with DESTROYED release policy");
2669 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2671 tet_infoline("Create second visual with DETACHED release policy");
2672 Visual::Base imageVisualDetached = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED);
2674 // Set up trace debug
2675 TestGlAbstraction& gl = application.GetGlAbstraction();
2676 TraceCallStack& textureTrace = gl.GetTextureTrace();
2677 textureTrace.Enable(true);
2679 tet_infoline("Register visuals with control and ensure it has the only handles");
2680 DummyControl actor = DummyControl::New(true);
2681 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2682 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2683 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL2, imageVisualDetached);
2684 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2685 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
2687 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2689 // Test initially zero renderers
2690 application.SendNotification();
2691 application.Render(0);
2692 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2693 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2695 application.GetScene().Add(actor);
2697 // Wait for image to load
2698 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2700 application.SendNotification();
2701 application.Render(0);
2702 tet_infoline("Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer");
2703 DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
2704 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2706 // Test renderer removed when visual destroyed
2707 DALI_TEST_CHECK(actor.GetRendererCount() == 2u);
2708 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL2, false); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2709 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2710 application.SendNotification();
2711 application.Render();
2713 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2714 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2716 dummyImpl.EnableVisual(DummyControl::Property::TEST_VISUAL, false);
2717 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2718 application.SendNotification();
2719 application.Render();
2721 tet_infoline("Ensure a texture is not deleted as second visual used the DESTROYED release policy");
2722 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2727 int UtcDaliImageVisualReleasePolicy08(void)
2729 ToolkitTestApplication application;
2730 tet_infoline("UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy");
2732 tet_infoline("Create first visual with DESTROYED release policy");
2733 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2735 // Set up trace debug
2736 TestGlAbstraction& gl = application.GetGlAbstraction();
2737 TraceCallStack& textureTrace = gl.GetTextureTrace();
2738 textureTrace.Enable(true);
2740 tet_infoline("Register visuals with control and ensure it has the only handles");
2741 DummyControl actor = DummyControl::New(true);
2742 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2743 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisualDestroyed);
2744 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2746 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2748 // Test initially zero renderers
2749 application.SendNotification();
2750 application.Render(0);
2751 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2752 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2753 textureTrace.Reset();
2755 application.GetScene().Add(actor);
2757 // Wait for image to load
2758 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2760 application.SendNotification();
2761 application.Render(0);
2762 tet_infoline("Ensure a texture is created");
2763 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2764 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2765 textureTrace.Reset();
2767 // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy
2769 Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2771 // 2.Remove actor from stage. In this case, renderer also is deleted.
2772 tet_infoline("Remove actor from stage");
2773 application.GetScene().Remove(actor);
2774 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2775 application.SendNotification();
2776 application.Render();
2778 tet_infoline("Ensure a texture is not deleted as visual used the DESTROYED release policy");
2779 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION);
2780 textureTrace.Reset();
2782 // 3.Add actor in stage. In this case, renderer is created.
2783 tet_infoline("Add actor in stage");
2784 application.GetScene().Add(actor);
2785 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2786 application.SendNotification();
2787 application.Render();
2788 tet_infoline("Ensure a texture is not created again");
2789 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION);
2790 textureTrace.Reset();
2792 // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED.
2793 tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy");
2794 Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u);
2795 DALI_TEST_CHECK(textureBefore == textureAfter);
2796 textureBefore.Reset();
2797 textureAfter.Reset();
2799 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2800 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2801 application.SendNotification();
2802 application.Render();
2803 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2808 int UtcDaliImageVisualReleasePolicy09(void)
2810 ToolkitTestApplication application;
2811 tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed");
2813 Property::Map propertyMapNPatchReleasePolicy;
2814 propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH);
2815 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME);
2816 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME);
2817 propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f);
2818 propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED);
2820 VisualFactory factory = VisualFactory::Get();
2821 Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy);
2822 DALI_TEST_CHECK(imageVisual);
2824 // Setup debug trace
2825 TestGlAbstraction& gl = application.GetGlAbstraction();
2826 TraceCallStack& textureTrace = gl.GetTextureTrace();
2827 textureTrace.Enable(true);
2829 tet_infoline("Register visual with control and ensure it has the only handle");
2830 DummyControl actor = DummyControl::New(true);
2831 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2832 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2833 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2835 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2837 application.SendNotification();
2838 application.Render(0);
2839 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2840 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2842 application.GetScene().Add(actor);
2844 // Wait for image to load
2845 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2847 application.SendNotification();
2848 application.Render(0);
2849 // Test renderer and texture created
2850 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2851 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2853 DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
2854 tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed");
2855 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2856 DALI_TEST_CHECK(actor.GetRendererCount() == 0u);
2857 application.SendNotification();
2858 application.Render();
2860 // Test texture removed after visual destroyed.
2861 tet_infoline("Ensure texture is deleted after visual destroyed");
2862 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION);
2867 int UtcDaliImageVisualLoadPolicy01(void)
2869 ToolkitTestApplication application;
2870 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage");
2872 // Set up trace debug
2873 TestGlAbstraction& gl = application.GetGlAbstraction();
2874 TraceCallStack& textureTrace = gl.GetTextureTrace();
2875 textureTrace.Enable(true);
2877 tet_infoline("Create visual with IMMEDIATE load policy");
2878 VisualFactory factory = VisualFactory::Get();
2880 Property::Map propertyMap;
2881 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
2882 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME);
2883 propertyMap.Insert(ImageVisual::Property::DESIRED_WIDTH, 20);
2884 propertyMap.Insert(ImageVisual::Property::DESIRED_HEIGHT, 30);
2885 propertyMap.Insert("loadPolicy", ImageVisual::LoadPolicy::IMMEDIATE);
2887 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
2889 Property::Map resultMap;
2890 imageVisual.CreatePropertyMap(resultMap);
2891 DALI_TEST_CHECK(!resultMap.Empty());
2892 DALI_TEST_EQUALS((resultMap.Find(ImageVisual::Property::LOAD_POLICY))->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION);
2894 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2896 // Ensure texture has been uploaded
2897 application.SendNotification();
2898 application.Render();
2900 tet_infoline("Ensure texture loading starts after visual created");
2901 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2902 textureTrace.Reset();
2904 tet_infoline("Register visuals with control and ensure it has the only handles");
2905 DummyControl actor = DummyControl::New(true);
2906 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2907 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2908 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2910 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2911 application.GetScene().Add(actor);
2912 tet_infoline("Ensure nothing triggers another load as texure already loaded");
2913 const unsigned int TIME_OUT_3_SECONDS = 3;
2914 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2916 application.SendNotification();
2917 application.Render();
2919 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2920 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2922 // Ensure texture is deleted when no longer needed (ref count was correct )
2923 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2925 application.SendNotification();
2926 application.Render();
2928 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2929 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2934 int UtcDaliImageVisualLoadPolicy02(void)
2936 ToolkitTestApplication application;
2937 tet_infoline("UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage");
2939 // Set up trace debug
2940 TestGlAbstraction& gl = application.GetGlAbstraction();
2941 TraceCallStack& textureTrace = gl.GetTextureTrace();
2942 textureTrace.Enable(true);
2944 tet_infoline("Create visual with IMMEDIATE load policy");
2945 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
2947 const unsigned int TIME_OUT_3_SECONDS = 3;
2948 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, TIME_OUT_3_SECONDS), false, TEST_LOCATION);
2950 // Act on meeage queue even although nothing expected to load
2951 application.SendNotification();
2952 application.Render();
2954 tet_infoline("Ensure texture is not generated yet");
2955 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION);
2956 textureTrace.Reset();
2958 tet_infoline("Register visuals with control and ensure it has the only handles");
2959 DummyControl actor = DummyControl::New(true);
2960 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2961 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
2962 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2964 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2965 application.GetScene().Add(actor);
2966 tet_infoline("Allow image time to load");
2967 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2969 application.SendNotification();
2970 application.Render();
2972 tet_infoline("Ensure texture generated and renderer created");
2973 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
2974 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
2976 // Ensure texture is delete when no longer needed
2977 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
2979 application.SendNotification();
2980 application.Render();
2982 DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
2983 DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION);
2988 int UtcDaliImageVisualLoadPolicy03(void)
2990 ToolkitTestApplication application;
2991 tet_infoline("UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded");
2993 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing 'false' into an API.
2995 // Set up trace debug
2996 TestGlAbstraction& gl = application.GetGlAbstraction();
2997 TraceCallStack& textureTrace = gl.GetTextureTrace();
2998 textureTrace.Enable(true);
3000 tet_infoline("Create a control and connect to resource ready signal without adding to stage");
3001 DummyControl actor = DummyControl::New(true);
3002 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3003 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3004 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3006 tet_infoline("Create visual with IMMEDIATE load policy");
3007 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3009 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )");
3010 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3011 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3013 tet_infoline("Allow image time to load resource");
3014 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3015 application.SendNotification();
3016 application.Render();
3018 // Ensure texture has been uploaded
3019 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3020 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3025 int UtcDaliImageVisualLoadPolicy04(void)
3027 ToolkitTestApplication application;
3028 tet_infoline("UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
3029 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3031 const bool VISUAL_NOT_ENABLED(false); // Instead of just passing false into an API.
3033 // Set up trace debug
3034 TestGlAbstraction& gl = application.GetGlAbstraction();
3035 TraceCallStack& textureTrace = gl.GetTextureTrace();
3036 textureTrace.Enable(true);
3038 tet_infoline("Create a control and connect to resource ready signal");
3039 DummyControl actor = DummyControl::New(true);
3040 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3041 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3042 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3044 tet_infoline("Create visual with IMMEDIATE load policy");
3045 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3047 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3048 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED);
3049 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3051 tet_infoline("Allow image time to load");
3052 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3053 application.SendNotification();
3054 application.Render();
3056 tet_infoline("Testing texture is loaded and resource ready signal fired");
3057 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3058 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
3060 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3062 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3063 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3064 DummyControl actor2 = DummyControl::New(true);
3065 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3066 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3068 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3069 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3070 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3071 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3072 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3073 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3078 int UtcDaliImageVisualLoadPolicy05(void)
3080 ToolkitTestApplication application;
3081 tet_infoline("UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
3082 tet_infoline("Second part, Reuse the same image in aonther control and check resource ready signal fired");
3083 // Set up trace debug
3084 TestGlAbstraction& gl = application.GetGlAbstraction();
3085 TraceCallStack& textureTrace = gl.GetTextureTrace();
3086 textureTrace.Enable(true);
3088 tet_infoline("Create a control and connect to resource ready signal");
3089 DummyControl actor = DummyControl::New(true);
3090 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3091 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3092 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3093 application.GetScene().Add(actor);
3095 tet_infoline("Create visual with ATTACHED load policy");
3096 Visual::Base imageVisual = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3098 tet_infoline("Registering visual allows control to get a signal once loaded");
3099 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3100 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
3102 tet_infoline("Allow image time to load");
3103 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3104 application.SendNotification();
3105 application.Render();
3107 tet_infoline("Testing texture is loaded and resource ready signal fired");
3108 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION);
3109 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3111 tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image");
3113 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3114 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED);
3115 DummyControl actor2 = DummyControl::New(true);
3116 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3117 actor2.ResourceReadySignal().Connect(&ResourceReadySignal);
3119 tet_infoline("Registering visual this should trigger the loading signal as is already image loaded for previous control");
3120 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3121 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
3122 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3123 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(0), true, TEST_LOCATION); // Not expecting any further loading as texture is being reused.
3124 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3129 int UtcDaliImageVisualOrientationCorrection(void)
3131 ToolkitTestApplication application;
3132 tet_infoline("UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested");
3134 VisualFactory factory = VisualFactory::Get();
3135 tet_infoline("Create visual with Orientation correction set OFF");
3136 Property::Map propertyMap;
3137 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3138 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3139 propertyMap.Insert("orientationCorrection", false);
3140 Visual::Base imageVisual = factory.CreateVisual(propertyMap);
3142 tet_infoline("Create control for visual, need to loaded it");
3143 DummyControl actor = DummyControl::New(true);
3144 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3145 application.GetScene().Add(actor);
3147 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3148 // Wait for image to load
3149 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3151 Vector2 originalImageSize;
3152 tet_infoline("Get size of original visual to compare later with rotated image");
3153 imageVisual.GetNaturalSize(originalImageSize);
3154 DALI_TEST_GREATER(originalImageSize.width, originalImageSize.height, TEST_LOCATION); // Width and Height must be different for this test.
3155 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
3156 dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL);
3157 application.SendNotification();
3158 application.Render();
3160 tet_infoline("Create visual with Orientation correction set ON ");
3161 propertyMap.Clear();
3162 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
3163 propertyMap.Insert(ImageVisual::Property::URL, TEST_ROTATED_IMAGE);
3164 propertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, true);
3165 imageVisual = factory.CreateVisual(propertyMap);
3167 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
3168 // Wait for image to load
3169 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3171 Vector2 rotatedImageSize;
3172 imageVisual.GetNaturalSize(rotatedImageSize);
3173 tet_infoline("Confirm that visual has rotated");
3174 DALI_TEST_EQUALS(originalImageSize.width, rotatedImageSize.height, TEST_LOCATION);
3175 DALI_TEST_EQUALS(originalImageSize.height, rotatedImageSize.width, TEST_LOCATION);
3177 Property::Map resultMap;
3178 imageVisual.CreatePropertyMap(resultMap);
3180 // check the Property::ORIENTATION_CORRECTION value from the returned map
3181 Property::Value* typeValue = resultMap.Find(ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN);
3182 DALI_TEST_EQUALS(typeValue->Get<bool>(), true, TEST_LOCATION);
3187 int UtcDaliImageVisualCustomShader(void)
3189 ToolkitTestApplication application;
3190 tet_infoline("UtcDaliImageVisualCustomShader Test custom shader");
3192 VisualFactory factory = VisualFactory::Get();
3193 Property::Map properties;
3194 Property::Map shader;
3195 const std::string vertexShader = "Foobar";
3196 const std::string fragmentShader = "Foobar";
3197 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3198 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3200 properties[Visual::Property::TYPE] = Visual::IMAGE;
3201 properties[Visual::Property::SHADER] = shader;
3202 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3204 Visual::Base visual = factory.CreateVisual(properties);
3206 // trigger creation through setting on stage
3207 DummyControl dummy = DummyControl::New(true);
3208 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummy.GetImplementation());
3209 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
3211 dummy.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3212 dummy.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3213 application.GetScene().Add(dummy);
3215 application.SendNotification();
3216 application.Render();
3218 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3220 Renderer renderer = dummy.GetRendererAt(0);
3221 Shader shader2 = renderer.GetShader();
3222 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
3223 Property::Map* map = value.GetMap();
3224 DALI_TEST_CHECK(map);
3226 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
3227 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
3229 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
3230 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
3234 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
3235 properties[Visual::Property::SHADER] = shader;
3237 Visual::Base visual1 = factory.CreateVisual(properties);
3239 // trigger creation through setting on stage
3240 DummyControl dummy1 = DummyControl::New(true);
3241 Impl::DummyControl& dummyImpl1 = static_cast<Impl::DummyControl&>(dummy1.GetImplementation());
3242 dummyImpl1.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual1);
3243 dummy1.SetProperty(Actor::Property::SIZE, Vector2(200, 200));
3244 dummy1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
3245 application.GetScene().Add(dummy1);
3247 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3248 glAbstraction.EnableEnableDisableCallTrace(true);
3250 application.SendNotification();
3251 application.Render();
3253 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
3254 std::ostringstream blendStr;
3255 blendStr << std::hex << GL_BLEND;
3256 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str()));
3261 void ResourceReadyLoadNext(Control control)
3263 static int callNumber = 0;
3265 gResourceReadySignalFired = true;
3266 gReadyIds.push_back(control.GetProperty<int>(Actor::Property::ID));
3270 DALI_TEST_EQUALS(control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3272 tet_infoline("Create visual with loaded image from within the signal handler");
3273 VisualFactory factory = VisualFactory::Get();
3274 Visual::Base imageVisual = factory.CreateVisual(TEST_IMAGE_FILE_NAME, ImageDimensions{20, 30});
3276 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
3277 controlImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); // This should trigger another signal.
3282 tet_infoline("3rd signal called");
3283 DALI_TEST_CHECK(true);
3287 int UtcDaliImageVisualLoadReady01(void)
3289 ToolkitTestApplication application;
3290 tet_infoline("UtcDaliImageVisualLoadReady01");
3291 tet_infoline("First part: Load an image visual for one resource, then another image visual for a second resource.");
3292 tet_infoline("Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL");
3293 tet_infoline("Should get a ready signal for all three visuals");
3297 tet_infoline("Create a control and connect to resource ready signal");
3298 DummyControl actor = DummyControl::New(true);
3299 int actor1Id = actor.GetProperty<int>(Actor::Property::ID);
3300 actor.ResourceReadySignal().Connect(&ResourceReadySignal);
3301 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
3302 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3303 application.GetScene().Add(actor);
3305 tet_infoline("Create visual with IMMEDIATE load policy");
3306 Visual::Base imageVisual1 = CreateVisualWithPolicy(TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3308 tet_infoline("Registering visual allows control to get a signal once loaded even if visual not enabled( staged )");
3309 dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual1);
3311 tet_infoline("Allow image time to load");
3312 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3313 application.SendNotification();
3314 application.Render();
3316 tet_infoline("Testing texture is loaded and resource ready signal fired");
3317 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3318 DALI_TEST_EQUALS(gReadyIds[0], actor1Id, TEST_LOCATION);
3320 tet_infoline("Original control correctly signalled, now testing failing image");
3322 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
3325 Visual::Base imageVisual2 = CreateVisualWithPolicy(TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE);
3327 DummyControl actor2 = DummyControl::New(true);
3328 int actor2Id = actor2.GetProperty<int>(Actor::Property::ID);
3329 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
3330 actor2.ResourceReadySignal().Connect(&ResourceReadyLoadNext);
3332 tet_infoline("Registering visual this should trigger the ready signal when the image fails to load");
3333 dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual2);
3335 actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3336 application.GetScene().Add(actor2);
3338 tet_infoline("Wait for loading thread to finish");
3339 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3340 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3342 DALI_TEST_EQUALS(gReadyIds[0], actor2Id, TEST_LOCATION);
3344 tet_infoline("Check for 3rd signal");
3345 application.SendNotification();
3346 DALI_TEST_EQUALS(gReadyIds.size(), 2, TEST_LOCATION);
3347 DALI_TEST_EQUALS(gReadyIds[1], actor2Id, TEST_LOCATION);
3352 int UtcDaliImageVisualLoadImagePlanes01(void)
3354 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3355 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3357 ToolkitTestApplication application;
3359 VisualFactory factory = VisualFactory::Get();
3360 DALI_TEST_CHECK(factory);
3362 Property::Map propertyMap;
3363 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3364 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3366 Visual::Base visual = factory.CreateVisual(propertyMap);
3367 DALI_TEST_CHECK(visual);
3369 DummyControl actor = DummyControl::New();
3370 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3371 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3372 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3373 application.GetScene().Add(actor);
3375 application.SendNotification();
3376 application.Render();
3378 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3380 TestGlAbstraction& gl = application.GetGlAbstraction();
3381 TraceCallStack& textureTrace = gl.GetTextureTrace();
3382 textureTrace.Enable(true);
3384 application.SendNotification();
3385 application.Render();
3387 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3388 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3389 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);
3391 Renderer renderer = actor.GetRendererAt(0);
3392 auto preMultipliedAlpha = renderer.GetProperty<bool>(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
3393 DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION);
3398 int UtcDaliImageVisualLoadImagePlanes02(void)
3400 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3401 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3403 ToolkitTestApplication application;
3405 VisualFactory factory = VisualFactory::Get();
3406 DALI_TEST_CHECK(factory);
3408 // Alpha masking case - not support yuv planes
3409 Property::Map propertyMap;
3410 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3411 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3412 propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
3414 Visual::Base visual = factory.CreateVisual(propertyMap);
3415 DALI_TEST_CHECK(visual);
3417 DummyControl actor = DummyControl::New();
3418 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3419 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3420 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3421 application.GetScene().Add(actor);
3423 application.SendNotification();
3424 application.Render();
3426 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
3428 TestGlAbstraction& gl = application.GetGlAbstraction();
3429 TraceCallStack& textureTrace = gl.GetTextureTrace();
3430 textureTrace.Enable(true);
3432 application.SendNotification();
3433 application.Render();
3435 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3436 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3437 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION);
3442 int UtcDaliImageVisualLoadImagePlanes03(void)
3444 EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1");
3445 EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1");
3447 ToolkitTestApplication application;
3449 VisualFactory factory = VisualFactory::Get();
3450 DALI_TEST_CHECK(factory);
3452 TestGlAbstraction& gl = application.GetGlAbstraction();
3453 TraceCallStack& textureTrace = gl.GetTextureTrace();
3454 textureTrace.Enable(true);
3456 Property::Map propertyMap;
3457 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
3458 propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME);
3459 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3461 Visual::Base visual = factory.CreateVisual(propertyMap);
3462 DALI_TEST_CHECK(visual);
3464 DummyControl actor = DummyControl::New();
3465 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
3466 dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual);
3467 actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3468 application.GetScene().Add(actor);
3470 application.SendNotification();
3471 application.Render();
3473 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
3474 DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION);
3475 DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION);