2 * Copyright (c) 2021 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/public-api/image-loader/image.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include "dummy-control.h"
32 using namespace Dali::Toolkit;
34 void dali_image_visual_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_image_visual_cleanup(void)
41 test_return_value = TET_PASS;
46 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
47 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
48 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
49 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
50 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
51 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
52 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
53 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
54 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
57 bool gResourceReadySignalFired = false;
58 std::vector<int> gReadyIds = {};
59 void ResourceReadySignal( Control control )
61 gResourceReadySignalFired = true;
62 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
69 Actor CreateActorWithImageVisual(const Property::Map& map)
71 VisualFactory factory = VisualFactory::Get();
72 DummyControl actor = DummyControl::New();
73 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
74 Visual::Base visual = factory.CreateVisual( map );
75 DALI_TEST_CHECK( visual );
76 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
77 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
78 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
83 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
85 VisualFactory factory = VisualFactory::Get();
87 Property::Map propertyMap;
88 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
89 propertyMap.Insert( ImageVisual::Property::URL, url );
90 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
91 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
92 propertyMap.Insert( key , value );
94 return factory.CreateVisual( propertyMap );
99 void TestVisualRender( ToolkitTestApplication& application,
101 Visual::Base& visual,
102 std::size_t expectedSamplers = 0,
103 ImageDimensions imageDimensions = ImageDimensions(),
104 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
106 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
107 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
111 // set the image size, for test case, this needs to be set before loading started
112 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
115 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
116 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
118 application.GetScene().Add( actor );
120 application.SendNotification(); // Send messages to update
121 application.Render(); // process update and render
122 application.SendNotification(); // process any signals to event
126 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
129 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
132 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
135 visual.CreatePropertyMap(map);
136 Property::Value* value = map.Find( mixColorIndex );
137 DALI_TEST_CHECK( value );
139 DALI_TEST_CHECK( value->Get( mixColor1 ) );
140 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
142 value = map.Find( Visual::Property::MIX_COLOR );
143 DALI_TEST_CHECK( value );
145 DALI_TEST_CHECK( value->Get( mixColor2 ) );
146 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
148 value = map.Find( Visual::Property::OPACITY );
149 DALI_TEST_CHECK( value );
151 DALI_TEST_CHECK( value->Get( opacity ) );
152 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
157 int UtcDaliImageVisualPropertyMap(void)
159 ToolkitTestApplication application;
160 tet_infoline( "Request image visual with a Property::Map" );
162 VisualFactory factory = VisualFactory::Get();
163 DALI_TEST_CHECK( factory );
164 factory.SetPreMultiplyOnLoad( true );
166 Property::Map propertyMap;
167 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
168 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
170 Visual::Base visual = factory.CreateVisual( propertyMap );
171 DALI_TEST_CHECK( visual );
173 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
174 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
176 TestGlAbstraction& gl = application.GetGlAbstraction();
177 TraceCallStack& textureTrace = gl.GetTextureTrace();
178 textureTrace.Enable(true);
180 DummyControl actor = DummyControl::New();
181 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
182 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
184 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
185 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
187 application.GetScene().Add( actor );
188 application.SendNotification();
189 application.Render();
191 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
193 application.SendNotification();
194 application.Render();
196 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
197 auto renderer = actor.GetRendererAt(0);
198 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
199 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
200 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
201 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
202 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
203 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
204 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
206 application.GetScene().Remove( actor );
207 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
213 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
215 ToolkitTestApplication application;
216 tet_infoline( "Request image visual without pre-multiplied alpha" );
218 VisualFactory factory = VisualFactory::Get();
219 DALI_TEST_CHECK( factory );
220 factory.SetPreMultiplyOnLoad( false );
222 Property::Map propertyMap;
223 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
224 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
226 Visual::Base visual = factory.CreateVisual( propertyMap );
227 DALI_TEST_CHECK( visual );
229 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
230 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
232 TestGlAbstraction& gl = application.GetGlAbstraction();
233 TraceCallStack& textureTrace = gl.GetTextureTrace();
234 textureTrace.Enable(true);
236 DummyControl actor = DummyControl::New();
237 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
238 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
240 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
241 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
243 application.GetScene().Add( actor );
244 application.SendNotification();
245 application.Render();
247 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
249 application.SendNotification();
250 application.Render();
252 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
253 auto renderer = actor.GetRendererAt(0);
254 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
255 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
256 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
257 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
259 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
260 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
262 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
264 application.GetScene().Remove( actor );
265 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
271 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
273 ToolkitTestApplication application;
274 tet_infoline( "Request image visual with no alpha channel" );
276 VisualFactory factory = VisualFactory::Get();
277 DALI_TEST_CHECK( factory );
279 Property::Map propertyMap;
280 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
281 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
283 Visual::Base visual = factory.CreateVisual( propertyMap );
284 DALI_TEST_CHECK( visual );
286 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
287 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
289 TestGlAbstraction& gl = application.GetGlAbstraction();
290 TraceCallStack& textureTrace = gl.GetTextureTrace();
291 textureTrace.Enable(true);
293 DummyControl actor = DummyControl::New();
294 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
295 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
297 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
298 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
300 application.GetScene().Add( actor );
301 application.SendNotification();
302 application.Render();
304 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
310 auto renderer = actor.GetRendererAt(0);
311 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
312 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
313 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
314 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
316 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
317 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
319 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
321 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
322 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
323 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
324 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
325 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
326 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
327 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
328 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
330 textureTrace.Reset();
332 // Make a new visual with the same image
333 Visual::Base newVisual = factory.CreateVisual( propertyMap );
334 DALI_TEST_CHECK( newVisual );
336 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
337 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
339 DummyControl newActor = DummyControl::New();
340 DummyControlImpl& newDummyImpl = static_cast< DummyControlImpl& >( newActor.GetImplementation() );
341 newDummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual );
343 newActor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
344 DALI_TEST_EQUALS( newActor.GetRendererCount(), 0u, TEST_LOCATION );
346 application.GetScene().Add( newActor );
348 application.SendNotification();
349 application.Render();
351 DALI_TEST_EQUALS( newActor.GetRendererCount(), 1u, TEST_LOCATION );
352 auto newRenderer = newActor.GetRendererAt( 0 );
353 preMultipliedIndex = newRenderer.GetPropertyIndex( "preMultipliedAlpha" );
354 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
355 preMultipliedAlpha = newRenderer.GetProperty< bool >( preMultipliedIndex );
356 preMultipliedAlpha2 = newRenderer.GetProperty< bool >( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
358 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
359 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
361 srcFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
362 destFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
363 srcFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
364 destFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
365 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
366 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
367 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
368 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
370 application.GetScene().Remove( actor );
371 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
377 int UtcDaliImageVisualRemoteImageLoad(void)
379 ToolkitTestApplication application;
380 tet_infoline( "Request remote image visual with a Property::Map" );
382 VisualFactory factory = VisualFactory::Get();
383 DALI_TEST_CHECK( factory );
385 Property::Map propertyMap;
386 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
387 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
389 Visual::Base visual = factory.CreateVisual( propertyMap );
390 DALI_TEST_CHECK( visual );
392 TestGlAbstraction& gl = application.GetGlAbstraction();
393 TraceCallStack& textureTrace = gl.GetTextureTrace();
394 textureTrace.Enable(true);
396 DummyControl actor = DummyControl::New();
397 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
398 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
400 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
401 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
403 application.GetScene().Add( actor );
404 application.SendNotification();
406 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
408 application.SendNotification();
409 application.Render();
411 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
412 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
414 application.GetScene().Remove( actor );
415 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
421 int UtcDaliImageVisualWithNativeImage(void)
423 ToolkitTestApplication application;
424 tet_infoline( "Use Native Image as url" );
426 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
427 std::string url = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
429 VisualFactory factory = VisualFactory::Get();
430 DALI_TEST_CHECK( factory );
432 Property::Map propertyMap;
433 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
434 propertyMap.Insert( ImageVisual::Property::URL, url );
436 Visual::Base visual = factory.CreateVisual( propertyMap );
437 DALI_TEST_CHECK( visual );
439 DummyControl actor = DummyControl::New();
440 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
441 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
443 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
445 application.GetScene().Add( actor );
447 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
449 Renderer renderer = actor.GetRendererAt(0);
450 Shader shader = renderer.GetShader();
452 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
453 DALI_TEST_CHECK(value.GetType() == Property::MAP);
454 const Property::Map* outMap = value.GetMap();
455 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
457 const char* fragmentPrefix = nativeImageSource->GetCustomFragmentPrefix();
458 size_t pos = fragmentShader.find(fragmentPrefix);
460 DALI_TEST_EQUALS( pos != std::string::npos, true, TEST_LOCATION );
465 int UtcDaliImageVisualTextureReuse1(void)
467 ToolkitTestApplication application;
468 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
470 Property::Map propertyMap;
471 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
472 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
473 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
475 TestGlAbstraction& gl = application.GetGlAbstraction();
476 TraceCallStack& textureTrace = gl.GetTextureTrace();
477 textureTrace.Enable(true);
478 TraceCallStack& drawTrace = gl.GetDrawTrace();
479 drawTrace.Enable(true);
481 Actor actor = CreateActorWithImageVisual( propertyMap );
482 application.GetScene().Add( actor );
483 application.SendNotification();
485 // Wait for image to load
486 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
488 application.SendNotification();
489 application.Render();
491 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
492 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
493 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
494 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
495 textureTrace.Reset();
498 Actor actor2 = CreateActorWithImageVisual( propertyMap );
499 application.GetScene().Add(actor2);
501 application.SendNotification(); // Send messages to update
502 application.Render(); // process update and render
503 application.SendNotification(); // process any signals to event
505 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
507 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
508 "draw calls use the same texture as the previous draw call\n" );
510 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
511 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
512 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
513 // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
515 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
517 application.GetScene().Remove( actor );
518 application.SendNotification();
519 application.Render();
521 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
522 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
524 tet_infoline("Test that removing last actor does delete the texture\n");
526 application.GetScene().Remove( actor2 ); // Detaches remaining ImageVisual
527 application.SendNotification();
528 application.Render();
530 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
531 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
537 int UtcDaliImageVisualTextureReuse2(void)
539 ToolkitTestApplication application;
540 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" );
542 Property::Map propertyMap;
543 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
544 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
546 TestGlAbstraction& gl = application.GetGlAbstraction();
547 TraceCallStack& textureTrace = gl.GetTextureTrace();
548 textureTrace.Enable(true);
549 TraceCallStack& drawTrace = gl.GetDrawTrace();
550 drawTrace.Enable(true);
552 Actor actor = CreateActorWithImageVisual( propertyMap );
553 application.GetScene().Add( actor );
554 application.SendNotification();
556 // Wait for image to load
557 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
559 application.SendNotification();
560 application.Render();
562 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
563 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
564 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
565 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
566 textureTrace.Reset();
569 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
570 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
571 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
572 Actor actor2 = CreateActorWithImageVisual( propertyMap );
573 application.GetScene().Add(actor2);
575 application.SendNotification();
577 // Wait for image to load
578 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
580 application.SendNotification();
581 application.Render();
583 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
585 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
586 "renderers are using different textures\n" );
588 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
589 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
590 TraceCallStack::NamedParams tex1;
591 tex1["texture"] << 1;
592 TraceCallStack::NamedParams tex2;
593 tex2["texture"] << 2;
594 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
595 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
597 tet_infoline("Test that removing 1 actor deletes it's texture\n");
599 application.GetScene().Remove( actor );
600 application.SendNotification();
601 application.Render();
603 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
604 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
606 tet_infoline("Test that removing last actor deletes it's texture\n");
608 application.GetScene().Remove( actor2 );
609 application.SendNotification();
610 application.Render();
612 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
613 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
619 int UtcDaliImageVisualCustomWrapModePixelArea(void)
621 ToolkitTestApplication application;
622 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
624 static std::vector<UniformData> customUniforms =
626 UniformData("pixelArea", Property::Type::VECTOR4),
627 UniformData("wrapMode", Property::Type::VECTOR2),
630 TestGraphicsController& graphics = application.GetGraphicsController();
631 graphics.AddCustomUniforms(customUniforms);
633 VisualFactory factory = VisualFactory::Get();
634 DALI_TEST_CHECK( factory );
636 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
639 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
641 Property::Map propertyMap;
642 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
643 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
644 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
645 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
646 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
647 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
648 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
649 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
650 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
652 Visual::Base visual = factory.CreateVisual( propertyMap );
653 DALI_TEST_CHECK( visual );
655 TestGlAbstraction& gl = application.GetGlAbstraction();
656 TraceCallStack& textureTrace = gl.GetTextureTrace();
657 textureTrace.Enable(true);
658 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
659 texParameterTrace.Enable( true );
661 DummyControl actor = DummyControl::New();
662 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
663 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
664 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
665 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
666 application.GetScene().Add( actor );
669 application.SendNotification();
670 application.Render();
672 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
674 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
676 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
677 std::stringstream out;
678 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
679 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
681 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
682 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
684 // test the uniforms which used to handle the wrap mode
685 Renderer renderer = actor.GetRendererAt( 0u );
686 DALI_TEST_CHECK( renderer );
688 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
689 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
690 Vector4 pixelAreaUniform;
691 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
692 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
694 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
695 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
696 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
697 Vector2 wrapModeUniform;
698 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
699 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
702 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
707 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
709 ToolkitTestApplication application;
710 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
712 static std::vector<UniformData> customUniforms =
714 UniformData("pixelArea", Property::Type::VECTOR4),
717 TestGraphicsController& graphics = application.GetGraphicsController();
718 graphics.AddCustomUniforms(customUniforms);
720 VisualFactory factory = VisualFactory::Get();
721 DALI_TEST_CHECK( factory );
723 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
725 const int height=600;
726 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
728 Property::Map propertyMap;
729 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
730 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
731 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
732 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
733 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
734 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
735 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
736 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
738 Visual::Base visual = factory.CreateVisual( propertyMap );
739 DALI_TEST_CHECK( visual );
741 TestGlAbstraction& gl = application.GetGlAbstraction();
742 TraceCallStack& textureTrace = gl.GetTextureTrace();
743 textureTrace.Enable(true);
744 textureTrace.EnableLogging(true);
745 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
746 texParameterTrace.Enable( true );
747 texParameterTrace.EnableLogging( true );
749 DummyControl actor = DummyControl::New();
750 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
751 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
752 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
753 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
754 application.GetScene().Add( actor );
757 application.SendNotification();
758 application.Render();
759 application.SendNotification();
761 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
763 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
765 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
766 std::stringstream out;
767 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
768 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
770 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
771 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
773 // test the uniforms which used to handle the wrap mode
774 Renderer renderer = actor.GetRendererAt( 0u );
775 DALI_TEST_CHECK( renderer );
777 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
778 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
779 Vector4 pixelAreaUniform;
780 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
781 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
783 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
784 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
787 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
792 int UtcDaliImageVisualAnimateMixColor(void)
794 ToolkitTestApplication application;
795 tet_infoline( "Animate mix color" );
797 static std::vector<UniformData> customUniforms =
799 UniformData("mixColor", Property::Type::VECTOR3),
802 TestGraphicsController& graphics = application.GetGraphicsController();
803 graphics.AddCustomUniforms(customUniforms);
805 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
807 VisualFactory factory = VisualFactory::Get();
808 Property::Map propertyMap;
809 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
810 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
811 propertyMap.Insert("mixColor", Color::BLUE);
812 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
813 Visual::Base visual = factory.CreateVisual( propertyMap );
815 DummyControl actor = DummyControl::New(true);
816 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
817 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
819 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
820 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
821 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
822 application.GetScene().Add(actor);
824 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
826 Renderer renderer = actor.GetRendererAt(0);
827 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
828 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
829 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
831 tet_infoline("Test that the renderer has the mixColor property");
832 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
834 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
837 map["target"] = "testVisual";
838 map["property"] = "mixColor";
839 map["initialValue"] = Color::MAGENTA;
840 map["targetValue"] = TARGET_MIX_COLOR;
841 map["animator"] = Property::Map()
842 .Add("alphaFunction", "LINEAR")
843 .Add("timePeriod", Property::Map()
845 .Add("duration", 4.0f));
847 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
849 Animation animation = dummyImpl.CreateTransition( transition );
851 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
854 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
855 glAbstraction.EnableEnableDisableCallTrace( true );
856 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
857 std::ostringstream blendStr;
858 blendStr << std::hex << GL_BLEND;
860 application.SendNotification();
861 application.Render(0); // Ensure animation starts
862 application.Render(2000u); // Halfway point
863 Vector3 testColor( 1.0f, 0.0f, 0.5f );
865 // uColor.a should be actor's alpha * mixColor.a.
866 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
867 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
869 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
871 glEnableStack.Reset();
873 application.Render(2000u); // Halfway point between blue and white
875 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
876 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
877 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
879 // GL_BLEND should not be changed: Keep enabled
880 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
881 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
882 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
884 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
889 int UtcDaliImageVisualAnimateOpacity(void)
891 ToolkitTestApplication application;
892 tet_infoline( "Animate image visual opacity" );
894 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
896 VisualFactory factory = VisualFactory::Get();
897 Property::Map propertyMap;
898 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
899 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
900 propertyMap.Insert("opacity", 0.5f);
901 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
902 Visual::Base visual = factory.CreateVisual( propertyMap );
904 DummyControl actor = DummyControl::New(true);
905 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
906 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
908 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
909 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
910 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
911 application.GetScene().Add(actor);
913 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
915 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
916 glAbstraction.EnableEnableDisableCallTrace( true );
917 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
918 std::ostringstream blendStr;
919 blendStr << std::hex << GL_BLEND;
921 application.SendNotification();
922 application.Render();
924 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) );
927 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." );
930 map["target"] = "testVisual";
931 map["property"] = "opacity";
932 map["targetValue"] = 1.0f;
933 map["animator"] = Property::Map()
934 .Add("alphaFunction", "LINEAR")
935 .Add("timePeriod", Property::Map()
937 .Add("duration", 4.0f));
939 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
940 Animation animation = dummyImpl.CreateTransition( transition );
943 glEnableStack.Reset();
945 application.SendNotification();
946 application.Render(0); // Ensure animation starts
947 application.Render(2000u); // Halfway point through animation
948 application.SendNotification(); // Handle any signals
951 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
952 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
954 application.Render(2001u); // end
955 application.SendNotification(); // ensure animation finished signal is sent
957 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
958 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
960 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
961 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
962 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
967 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." );
970 map["target"] = "testVisual";
971 map["property"] = Visual::Property::OPACITY;
972 map["targetValue"] = 0.1f;
973 map["animator"] = Property::Map()
974 .Add("alphaFunction", "LINEAR")
975 .Add("timePeriod", Property::Map()
977 .Add("duration", 4.0f));
979 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
980 Animation animation = dummyImpl.CreateTransition( transition );
983 glEnableStack.Reset();
985 application.SendNotification();
986 application.Render(0); // Ensure animation starts
987 application.Render(2000u); // Halfway point
988 application.SendNotification();
991 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
992 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
994 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
996 glEnableStack.Reset();
998 application.Render(2016u); // end
999 application.SendNotification();
1001 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1002 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
1004 // GL_BLEND should not be changed: Keep enabled
1006 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1007 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1008 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1016 int UtcDaliImageVisualAnimateOpacity02(void)
1018 ToolkitTestApplication application;
1019 tet_infoline( "Animate image visual opacity" );
1021 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1023 VisualFactory factory = VisualFactory::Get();
1024 Property::Map propertyMap;
1025 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1026 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1027 propertyMap.Insert("opacity", 0.5f);
1028 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1029 Visual::Base visual = factory.CreateVisual( propertyMap );
1031 DummyControl actor = DummyControl::New(true);
1032 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1033 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1035 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1036 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1037 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1039 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
1041 Property::Array array;
1044 map["target"] = "testVisual";
1045 map["property"] = "opacity";
1046 map["initialValue"] = 0.0f;
1047 map["targetValue"] = 1.0f;
1048 map["animator"] = Property::Map()
1049 .Add("alphaFunction", "LINEAR")
1050 .Add("timePeriod", Property::Map()
1052 .Add("duration", 4.0f));
1055 map2["target"] = "testVisual";
1056 map2["property"] = "size";
1057 map2["targetValue"] = Vector2(1.0f, 1.0f);
1059 array.Add( map ).Add(map2);
1061 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1062 Animation animation = dummyImpl.CreateTransition( transition );
1064 application.GetScene().Add(actor);
1065 application.SendNotification();
1066 application.Render(0); // Ensure animation starts
1068 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1070 Renderer renderer = actor.GetRendererAt(0);
1071 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1072 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1074 animation = dummyImpl.CreateTransition( transition );
1077 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1078 glAbstraction.EnableEnableDisableCallTrace( true );
1079 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1080 std::ostringstream blendStr;
1081 blendStr << std::hex << GL_BLEND;
1083 application.SendNotification();
1084 application.Render(0); // Ensure animation starts
1085 application.Render(2000u); // Halfway point through animation
1086 application.SendNotification(); // Handle any signals
1088 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1091 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1092 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1094 glEnableStack.Reset();
1096 application.Render(2001u); // end
1097 application.SendNotification(); // ensure animation finished signal is sent
1099 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1100 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1102 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1109 int UtcDaliImageVisualAnimatePixelArea(void)
1111 ToolkitTestApplication application;
1112 tet_infoline( "ImageVisual animate pixel area" );
1114 static std::vector<UniformData> customUniforms =
1116 UniformData("pixelArea", Property::Type::VECTOR4),
1119 TestGraphicsController& graphics = application.GetGraphicsController();
1120 graphics.AddCustomUniforms(customUniforms);
1122 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1124 VisualFactory factory = VisualFactory::Get();
1125 Property::Map propertyMap;
1126 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1127 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1128 propertyMap.Insert("mixColor", Color::BLUE);
1129 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1130 Visual::Base visual = factory.CreateVisual( propertyMap );
1132 DummyControl actor = DummyControl::New(true);
1133 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1134 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1136 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1137 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1138 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1139 application.GetScene().Add(actor);
1141 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1143 Renderer renderer = actor.GetRendererAt(0);
1144 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1146 tet_infoline("Test that the renderer has the mixColor property");
1147 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1149 // TransitionData only takes string keys
1151 map["target"] = "testVisual";
1152 map["property"] = "pixelArea";
1153 map["initialValue"] = Vector4( 0,0,0,1 );
1154 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1155 map["animator"] = Property::Map()
1156 .Add("alphaFunction", "LINEAR")
1157 .Add("timePeriod", Property::Map()
1159 .Add("duration", 4.0f));
1161 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1163 Animation animation = dummyImpl.CreateTransition( transition );
1164 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1167 application.SendNotification();
1168 application.Render(0); // Ensure animation starts
1169 application.Render(2000u); // Halfway point
1171 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1173 application.Render(2000u); // End of animation
1175 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1180 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1182 ToolkitTestApplication application;
1183 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1185 Property::Map propertyMap;
1186 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1187 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1189 TestGlAbstraction& gl = application.GetGlAbstraction();
1190 TraceCallStack& textureTrace = gl.GetTextureTrace();
1191 textureTrace.Enable(true);
1192 TraceCallStack& drawTrace = gl.GetDrawTrace();
1193 drawTrace.Enable(true);
1195 Actor actor = CreateActorWithImageVisual( propertyMap );
1196 application.GetScene().Add( actor );
1197 application.SendNotification();
1199 application.GetScene().Remove( actor );
1200 application.SendNotification();
1202 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1203 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1204 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1205 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1210 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1212 ToolkitTestApplication application;
1213 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1215 VisualFactory factory = VisualFactory::Get();
1216 DALI_TEST_CHECK( factory );
1218 Property::Map propertyMap;
1219 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1220 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1222 Visual::Base visual = factory.CreateVisual( propertyMap );
1223 DALI_TEST_CHECK( visual );
1225 TestGlAbstraction& gl = application.GetGlAbstraction();
1226 TraceCallStack& textureTrace = gl.GetTextureTrace();
1227 textureTrace.Enable( true );
1228 TraceCallStack& drawTrace = gl.GetDrawTrace();
1229 drawTrace.Enable( true );
1231 DummyControl actor = DummyControl::New();
1232 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1233 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1235 application.GetScene().Add( actor );
1238 application.GetScene().Remove( actor );
1240 application.GetScene().Add( actor );
1242 // Create another visual with the same image
1243 visual = factory.CreateVisual( propertyMap );
1244 DALI_TEST_CHECK( visual );
1246 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1248 application.SendNotification();
1249 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1251 application.SendNotification();
1252 application.Render();
1254 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1255 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1256 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1257 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1262 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1264 ToolkitTestApplication application;
1265 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1267 VisualFactory factory = VisualFactory::Get();
1268 DALI_TEST_CHECK( factory );
1270 Property::Map propertyMap;
1271 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1272 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1274 Visual::Base visual = factory.CreateVisual( propertyMap );
1275 DALI_TEST_CHECK( visual );
1277 TestGlAbstraction& gl = application.GetGlAbstraction();
1278 TraceCallStack& textureTrace = gl.GetTextureTrace();
1279 textureTrace.Enable(true);
1281 DummyControl actor = DummyControl::New();
1282 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1283 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1285 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1286 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1288 application.GetScene().Add( actor );
1290 application.SendNotification();
1291 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1293 application.SendNotification();
1294 application.Render();
1296 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1297 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1299 application.GetScene().Remove( actor );
1300 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1305 int UtcDaliImageVisualSetInvalidSyncImage(void)
1307 ToolkitTestApplication application;
1308 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1310 VisualFactory factory = VisualFactory::Get();
1311 DALI_TEST_CHECK( factory );
1313 Property::Map propertyMap;
1314 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1315 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1316 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1318 Visual::Base visual = factory.CreateVisual( propertyMap );
1319 DALI_TEST_CHECK( visual );
1321 TestGlAbstraction& gl = application.GetGlAbstraction();
1322 TraceCallStack& textureTrace = gl.GetTextureTrace();
1323 textureTrace.Enable(true);
1325 DummyControl actor = DummyControl::New();
1326 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1327 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1329 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1330 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1332 application.GetScene().Add( actor );
1334 application.SendNotification();
1335 application.Render();
1337 // Check resource status
1338 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1339 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1341 // The broken image should be shown.
1342 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1343 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1345 application.GetScene().Remove( actor );
1346 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1351 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1353 ToolkitTestApplication application;
1354 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1356 VisualFactory factory = VisualFactory::Get();
1357 DALI_TEST_CHECK( factory );
1359 // Local invalid file, asynchronous loading
1360 Property::Map propertyMap;
1361 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1362 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1364 Visual::Base visual = factory.CreateVisual( propertyMap );
1365 DALI_TEST_CHECK( visual );
1367 TestGlAbstraction& gl = application.GetGlAbstraction();
1368 TraceCallStack& textureTrace = gl.GetTextureTrace();
1369 textureTrace.Enable(true);
1371 DummyControl actor = DummyControl::New();
1372 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1373 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1375 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1376 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1378 application.GetScene().Add( actor );
1380 application.SendNotification();
1381 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1383 application.SendNotification();
1384 application.Render();
1386 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1387 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1389 application.GetScene().Remove( actor );
1390 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1395 int UtcDaliImageVisualAlphaMask(void)
1397 ToolkitTestApplication application;
1398 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1400 VisualFactory factory = VisualFactory::Get();
1401 DALI_TEST_CHECK( factory );
1403 Property::Map propertyMap;
1404 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1405 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1406 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1408 Visual::Base visual = factory.CreateVisual( propertyMap );
1409 DALI_TEST_CHECK( visual );
1411 Property::Map testMap;
1412 visual.CreatePropertyMap(testMap);
1413 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1415 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1416 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1418 TestGlAbstraction& gl = application.GetGlAbstraction();
1419 TraceCallStack& textureTrace = gl.GetTextureTrace();
1420 textureTrace.Enable(true);
1422 DummyControl actor = DummyControl::New();
1423 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1424 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1426 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1427 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1428 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1430 application.GetScene().Add( actor );
1431 application.SendNotification();
1432 application.Render();
1434 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1436 application.SendNotification();
1437 application.Render();
1439 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1440 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1441 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1443 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1444 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1449 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1451 ToolkitTestApplication application;
1452 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1454 VisualFactory factory = VisualFactory::Get();
1455 DALI_TEST_CHECK( factory );
1457 Property::Map propertyMap;
1458 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1459 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1460 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1461 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1463 Visual::Base visual = factory.CreateVisual( propertyMap );
1464 DALI_TEST_CHECK( visual );
1466 Property::Map testMap;
1467 visual.CreatePropertyMap(testMap);
1468 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1470 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1471 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1473 TestGlAbstraction& gl = application.GetGlAbstraction();
1474 TraceCallStack& textureTrace = gl.GetTextureTrace();
1475 textureTrace.Enable(true);
1477 DummyControl actor = DummyControl::New();
1478 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1479 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1481 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1482 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1483 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1485 application.GetScene().Add( actor );
1487 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1489 application.SendNotification();
1490 application.Render();
1492 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1493 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1494 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1496 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1497 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1502 int UtcDaliImageVisualRemoteAlphaMask(void)
1504 ToolkitTestApplication application;
1505 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1507 VisualFactory factory = VisualFactory::Get();
1508 DALI_TEST_CHECK( factory );
1510 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1512 Property::Map propertyMap;
1513 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1514 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1515 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1517 Visual::Base visual = factory.CreateVisual( propertyMap );
1518 DALI_TEST_CHECK( visual );
1520 Property::Map testMap;
1521 visual.CreatePropertyMap(testMap);
1523 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1525 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1526 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1528 TestGlAbstraction& gl = application.GetGlAbstraction();
1529 TraceCallStack& textureTrace = gl.GetTextureTrace();
1530 textureTrace.Enable(true);
1532 DummyControl actor = DummyControl::New();
1533 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1534 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1536 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1538 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1539 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1541 application.GetScene().Add( actor );
1542 application.SendNotification();
1543 application.Render();
1545 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1547 application.SendNotification();
1548 application.Render();
1550 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1551 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1552 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1557 int UtcDaliImageVisualAlphaMaskCrop(void)
1559 ToolkitTestApplication application;
1560 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1562 VisualFactory factory = VisualFactory::Get();
1563 DALI_TEST_CHECK( factory );
1565 Property::Map propertyMap;
1566 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1567 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1568 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1569 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1570 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1572 Visual::Base visual = factory.CreateVisual( propertyMap );
1573 DALI_TEST_CHECK( visual );
1575 Property::Map testMap;
1576 visual.CreatePropertyMap(testMap);
1577 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1578 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1579 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1581 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1582 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1584 TestGlAbstraction& gl = application.GetGlAbstraction();
1585 TraceCallStack& textureTrace = gl.GetTextureTrace();
1586 textureTrace.Enable(true);
1588 DummyControl actor = DummyControl::New();
1589 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1590 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1592 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1593 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1594 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1596 application.GetScene().Add( actor );
1597 application.SendNotification();
1598 application.Render();
1600 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1602 application.SendNotification();
1603 application.Render();
1606 visual.GetNaturalSize(size);
1608 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1609 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1610 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1611 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1616 int UtcDaliImageVisualReleasePolicy01(void)
1618 ToolkitTestApplication application;
1619 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1621 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1622 DALI_TEST_CHECK( imageVisual );
1624 // Set up debug trace
1625 TestGlAbstraction& gl = application.GetGlAbstraction();
1626 TraceCallStack& textureTrace = gl.GetTextureTrace();
1627 textureTrace.Enable(true);
1629 tet_infoline( "Register visual with control and ensure it has the only handle" );
1630 DummyControl actor = DummyControl::New(true);
1631 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1632 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1633 imageVisual.Reset();
1635 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1637 application.SendNotification();
1638 application.Render(0);
1639 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1640 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1642 application.GetScene().Add( actor );
1644 // Wait for image to load
1645 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1647 application.SendNotification();
1648 application.Render(0);
1649 // Test renderer and texture created
1650 tet_infoline( "Confirm texture created" );
1651 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1652 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1654 tet_infoline( "Disable visual causing the texture to be deleted" );
1655 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1657 application.SendNotification();
1658 application.Render(0);
1659 // Test renderer and textures removed.
1660 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1661 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1666 int UtcDaliImageVisualReleasePolicy02(void)
1668 ToolkitTestApplication application;
1669 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1671 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1672 DALI_TEST_CHECK( imageVisual );
1674 // Setup debug trace
1675 TestGlAbstraction& gl = application.GetGlAbstraction();
1676 TraceCallStack& textureTrace = gl.GetTextureTrace();
1677 textureTrace.Enable(true);
1679 tet_infoline( "Register visual with control and ensure it has the only handle" );
1680 DummyControl actor = DummyControl::New(true);
1681 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1682 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1683 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1685 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1687 application.SendNotification();
1688 application.Render(0);
1689 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1690 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1692 application.GetScene().Add( actor );
1694 // Wait for image to load
1695 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1697 application.SendNotification();
1698 application.Render(0);
1699 // Test renderer and texture created
1700 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1701 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1704 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1705 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1706 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1707 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1708 application.SendNotification();
1709 application.Render();
1711 // Test texture removed after visual destroyed.
1712 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1713 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1718 int UtcDaliImageVisualReleasePolicy03(void)
1720 ToolkitTestApplication application;
1721 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1723 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1724 DALI_TEST_CHECK( imageVisual );
1726 TestGlAbstraction& gl = application.GetGlAbstraction();
1727 TraceCallStack& textureTrace = gl.GetTextureTrace();
1728 textureTrace.Enable(true);
1730 tet_infoline( "Register visual with control and ensure it has the only handle" );
1731 DummyControl actor = DummyControl::New(true);
1732 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1733 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1734 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1736 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1738 application.SendNotification();
1739 application.Render(0);
1740 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1741 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1743 application.GetScene().Add( actor );
1745 // Wait for image to load
1746 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1748 application.SendNotification();
1749 application.Render(0);
1750 // Test renderer and texture created
1751 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1752 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1754 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1755 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1756 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1757 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1758 application.SendNotification();
1759 application.Render();
1761 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1762 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1767 int UtcDaliImageVisualReleasePolicy04(void)
1769 ToolkitTestApplication application;
1770 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1772 tet_infoline( "Create first visual with Never release policy" );
1773 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1775 tet_infoline( "Create second visual with Destroyed release policy");
1776 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1778 // Set up trace debug
1779 TestGlAbstraction& gl = application.GetGlAbstraction();
1780 TraceCallStack& textureTrace = gl.GetTextureTrace();
1781 textureTrace.Enable(true);
1783 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1784 DummyControl actor = DummyControl::New(true);
1785 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1786 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1787 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1788 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1789 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1791 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1793 // Test initially zero renderers
1794 application.SendNotification();
1795 application.Render(0);
1796 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1797 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1799 application.GetScene().Add( actor );
1801 // Wait for image to load
1802 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1804 application.SendNotification();
1805 application.Render(0);
1806 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1807 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1808 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1810 // Test renderer removed when visual destroyed
1811 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1812 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1813 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1814 application.SendNotification();
1815 application.Render();
1817 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1818 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1820 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1821 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1822 application.SendNotification();
1823 application.Render();
1825 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1826 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1827 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1832 int UtcDaliImageVisualReleasePolicy05(void)
1834 ToolkitTestApplication application;
1835 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1837 VisualFactory factory = VisualFactory::Get();
1839 Property::Map propertyMapNeverReleasePolicy;
1840 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1841 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1842 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1843 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1844 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1846 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1848 Property::Map resultMap;
1849 imageVisualNever.CreatePropertyMap( resultMap );
1850 DALI_TEST_CHECK( ! resultMap.Empty() );
1852 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1857 int UtcDaliImageVisualReleasePolicy06(void)
1859 ToolkitTestApplication application;
1860 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1862 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1863 DALI_TEST_CHECK( imageVisual );
1865 TestGlAbstraction& gl = application.GetGlAbstraction();
1866 TraceCallStack& textureTrace = gl.GetTextureTrace();
1867 textureTrace.Enable(true);
1869 tet_infoline( "Register visual with control and ensure it has the only handle" );
1870 DummyControl actor = DummyControl::New(true);
1871 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1872 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1873 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1875 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1877 application.SendNotification();
1878 application.Render(0);
1879 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1880 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1882 application.GetScene().Add( actor );
1884 // Wait for image to load
1885 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1887 application.SendNotification();
1888 application.Render(0);
1889 // Test renderer and texture created
1890 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1891 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1892 textureTrace.Reset();
1894 tet_infoline( "Disable Visual and check texture not affected" );
1895 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1896 application.SendNotification();
1897 application.Render(0);
1898 tet_infoline( "Check renderer is destroyed when visual off stage" );
1899 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1900 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1901 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1902 textureTrace.Reset();
1904 tet_infoline( "Re-enable Visual and check texture not affected" );
1905 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1906 application.SendNotification();
1907 application.Render(0);
1908 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1909 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1910 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1911 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1916 int UtcDaliImageVisualReleasePolicy07(void)
1918 ToolkitTestApplication application;
1919 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1921 tet_infoline( "Create first visual with DESTROYED release policy" );
1922 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1925 tet_infoline( "Create second visual with DETACHED release policy");
1926 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1928 // Set up trace debug
1929 TestGlAbstraction& gl = application.GetGlAbstraction();
1930 TraceCallStack& textureTrace = gl.GetTextureTrace();
1931 textureTrace.Enable(true);
1933 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1934 DummyControl actor = DummyControl::New(true);
1935 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1936 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1937 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1938 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1939 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1941 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1943 // Test initially zero renderers
1944 application.SendNotification();
1945 application.Render(0);
1946 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1947 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1949 application.GetScene().Add( actor );
1951 // Wait for image to load
1952 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1954 application.SendNotification();
1955 application.Render(0);
1956 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1957 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1958 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1960 // Test renderer removed when visual destroyed
1961 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1962 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1963 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1964 application.SendNotification();
1965 application.Render();
1967 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1968 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1970 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1971 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1972 application.SendNotification();
1973 application.Render();
1975 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1976 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1981 int UtcDaliImageVisualReleasePolicy08(void)
1983 ToolkitTestApplication application;
1984 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
1986 tet_infoline( "Create first visual with DESTROYED release policy" );
1987 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1989 // Set up trace debug
1990 TestGlAbstraction& gl = application.GetGlAbstraction();
1991 TraceCallStack& textureTrace = gl.GetTextureTrace();
1992 textureTrace.Enable(true);
1994 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1995 DummyControl actor = DummyControl::New(true);
1996 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1997 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1998 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2000 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2002 // Test initially zero renderers
2003 application.SendNotification();
2004 application.Render(0);
2005 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2006 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2007 textureTrace.Reset();
2009 application.GetScene().Add( actor );
2011 // Wait for image to load
2012 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2014 application.SendNotification();
2015 application.Render(0);
2016 tet_infoline( "Ensure a texture is created" );
2017 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2018 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2019 textureTrace.Reset();
2021 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2022 // 1. Get TextureSet
2023 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
2025 // 2.Remove actor from stage. In this case, renderer also is deleted.
2026 tet_infoline( "Remove actor from stage" );
2027 application.GetScene().Remove( actor );
2028 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2029 application.SendNotification();
2030 application.Render();
2032 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
2033 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
2034 textureTrace.Reset();
2036 // 3.Add actor in stage. In this case, renderer is created.
2037 tet_infoline( "Add actor in stage" );
2038 application.GetScene().Add( actor );
2039 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2040 application.SendNotification();
2041 application.Render();
2042 tet_infoline( "Ensure a texture is not created again" );
2043 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
2044 textureTrace.Reset();
2046 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2047 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
2048 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
2049 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
2050 textureSetBefore.Reset();
2051 textureSetAfter.Reset();
2053 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2054 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2055 application.SendNotification();
2056 application.Render();
2057 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2062 int UtcDaliImageVisualLoadPolicy01(void)
2064 ToolkitTestApplication application;
2065 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
2067 // Set up trace debug
2068 TestGlAbstraction& gl = application.GetGlAbstraction();
2069 TraceCallStack& textureTrace = gl.GetTextureTrace();
2070 textureTrace.Enable(true);
2072 tet_infoline( "Create visual with IMMEDIATE load policy" );
2073 VisualFactory factory = VisualFactory::Get();
2075 Property::Map propertyMap;
2076 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2077 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2078 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
2079 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
2080 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
2082 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2084 Property::Map resultMap;
2085 imageVisual.CreatePropertyMap( resultMap );
2086 DALI_TEST_CHECK( ! resultMap.Empty() );
2087 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
2089 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2091 // Ensure texture has been uploaded
2092 application.SendNotification();
2093 application.Render();
2095 tet_infoline( "Ensure texture loading starts after visual created" );
2096 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2097 textureTrace.Reset();
2099 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2100 DummyControl actor = DummyControl::New(true);
2101 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2102 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2103 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2105 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2106 application.GetScene().Add( actor );
2107 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2108 const unsigned int TIME_OUT_3_SECONDS = 3;
2109 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2111 application.SendNotification();
2112 application.Render();
2114 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2115 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2117 // Ensure texture is deleted when no longer needed (ref count was correct )
2118 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2120 application.SendNotification();
2121 application.Render();
2123 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2124 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2129 int UtcDaliImageVisualLoadPolicy02(void)
2131 ToolkitTestApplication application;
2132 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2134 // Set up trace debug
2135 TestGlAbstraction& gl = application.GetGlAbstraction();
2136 TraceCallStack& textureTrace = gl.GetTextureTrace();
2137 textureTrace.Enable(true);
2139 tet_infoline( "Create visual with IMMEDIATE load policy" );
2140 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2142 const unsigned int TIME_OUT_3_SECONDS = 3;
2143 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2145 // Act on meeage queue even although nothing expected to load
2146 application.SendNotification();
2147 application.Render();
2149 tet_infoline( "Ensure texture is not generated yet" );
2150 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2151 textureTrace.Reset();
2153 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2154 DummyControl actor = DummyControl::New(true);
2155 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2156 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2157 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2159 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2160 application.GetScene().Add( actor );
2161 tet_infoline( "Allow image time to load" );
2162 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2164 application.SendNotification();
2165 application.Render();
2167 tet_infoline( "Ensure texture generated and renderer created" );
2168 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2169 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2171 // Ensure texture is delete when no longer needed
2172 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2174 application.SendNotification();
2175 application.Render();
2177 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2178 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2183 int UtcDaliImageVisualLoadPolicy03(void)
2185 ToolkitTestApplication application;
2186 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2188 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2190 // Set up trace debug
2191 TestGlAbstraction& gl = application.GetGlAbstraction();
2192 TraceCallStack& textureTrace = gl.GetTextureTrace();
2193 textureTrace.Enable(true);
2195 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2196 DummyControl actor = DummyControl::New(true);
2197 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2198 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2199 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2201 tet_infoline( "Create visual with IMMEDIATE load policy" );
2202 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2204 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2205 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2206 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2208 tet_infoline( "Allow image time to load resource" );
2209 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2210 application.SendNotification();
2211 application.Render();
2213 // Ensure texture has been uploaded
2214 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2215 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2220 int UtcDaliImageVisualLoadPolicy04(void)
2222 ToolkitTestApplication application;
2223 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2224 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2226 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2228 // Set up trace debug
2229 TestGlAbstraction& gl = application.GetGlAbstraction();
2230 TraceCallStack& textureTrace = gl.GetTextureTrace();
2231 textureTrace.Enable(true);
2233 tet_infoline( "Create a control and connect to resource ready signal" );
2234 DummyControl actor = DummyControl::New(true);
2235 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2236 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2237 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2239 tet_infoline( "Create visual with IMMEDIATE load policy" );
2240 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2242 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2243 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2244 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2246 tet_infoline( "Allow image time to load" );
2247 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2248 application.SendNotification();
2249 application.Render();
2251 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2252 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2253 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2255 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2257 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2258 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2259 DummyControl actor2 = DummyControl::New(true);
2260 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2261 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2263 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2264 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2265 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2266 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2267 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2268 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2273 int UtcDaliImageVisualLoadPolicy05(void)
2275 ToolkitTestApplication application;
2276 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2277 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2278 // Set up trace debug
2279 TestGlAbstraction& gl = application.GetGlAbstraction();
2280 TraceCallStack& textureTrace = gl.GetTextureTrace();
2281 textureTrace.Enable(true);
2283 tet_infoline( "Create a control and connect to resource ready signal" );
2284 DummyControl actor = DummyControl::New(true);
2285 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2286 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2287 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2288 application.GetScene().Add( actor );
2290 tet_infoline( "Create visual with ATTACHED load policy" );
2291 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2293 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2294 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2295 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2297 tet_infoline( "Allow image time to load" );
2298 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2299 application.SendNotification();
2300 application.Render();
2302 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2303 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2304 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2306 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2308 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2309 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2310 DummyControl actor2 = DummyControl::New(true);
2311 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2312 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2314 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2315 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2316 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2317 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2318 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2319 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2325 int UtcDaliImageVisualOrientationCorrection(void)
2327 ToolkitTestApplication application;
2328 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2330 VisualFactory factory = VisualFactory::Get();
2331 tet_infoline( "Create visual with Orientation correction set OFF" );
2332 Property::Map propertyMap;
2333 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2334 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2335 propertyMap.Insert( "orientationCorrection", false );
2336 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2338 tet_infoline( "Create control for visual, need to loaded it" );
2339 DummyControl actor = DummyControl::New(true);
2340 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2341 application.GetScene().Add( actor );
2343 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2344 // Wait for image to load
2345 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2347 Vector2 originalImageSize;
2348 tet_infoline( "Get size of original visual to compare later with rotated image" );
2349 imageVisual.GetNaturalSize( originalImageSize );
2350 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2351 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2352 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2353 application.SendNotification();
2354 application.Render();
2356 tet_infoline( "Create visual with Orientation correction set ON " );
2357 propertyMap.Clear();
2358 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2359 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2360 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2361 imageVisual = factory.CreateVisual( propertyMap );
2363 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2364 // Wait for image to load
2365 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2367 Vector2 rotatedImageSize;
2368 imageVisual.GetNaturalSize( rotatedImageSize );
2369 tet_infoline( "Confirm that visual has rotated" );
2370 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2371 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2373 Property::Map resultMap;
2374 imageVisual.CreatePropertyMap( resultMap );
2376 // check the Property::ORIENTATION_CORRECTION value from the returned map
2377 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2378 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2383 int UtcDaliImageVisualCustomShader(void)
2385 ToolkitTestApplication application;
2386 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2388 VisualFactory factory = VisualFactory::Get();
2389 Property::Map properties;
2390 Property::Map shader;
2391 const std::string vertexShader = "Foobar";
2392 const std::string fragmentShader = "Foobar";
2393 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2394 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2396 properties[Visual::Property::TYPE] = Visual::IMAGE;
2397 properties[Visual::Property::SHADER] = shader;
2398 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2400 Visual::Base visual = factory.CreateVisual( properties );
2402 // trigger creation through setting on stage
2403 DummyControl dummy = DummyControl::New( true );
2404 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2405 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2407 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2408 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2409 application.GetScene().Add( dummy );
2411 application.SendNotification();
2412 application.Render();
2414 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2416 Renderer renderer = dummy.GetRendererAt( 0 );
2417 Shader shader2 = renderer.GetShader();
2418 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2419 Property::Map* map = value.GetMap();
2420 DALI_TEST_CHECK( map );
2422 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2423 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2425 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2426 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2430 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2431 properties[Visual::Property::SHADER] = shader;
2433 Visual::Base visual1 = factory.CreateVisual( properties );
2435 // trigger creation through setting on stage
2436 DummyControl dummy1 = DummyControl::New( true );
2437 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2438 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2439 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2440 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2441 application.GetScene().Add( dummy1 );
2443 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2444 glAbstraction.EnableEnableDisableCallTrace( true );
2446 application.SendNotification();
2447 application.Render();
2449 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2450 std::ostringstream blendStr;
2451 blendStr << std::hex << GL_BLEND;
2452 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
2458 void ResourceReadyLoadNext( Control control )
2460 static int callNumber = 0;
2462 gResourceReadySignalFired = true;
2463 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2465 if( callNumber == 0 )
2467 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2469 tet_infoline( "Create visual with loaded image from within the signal handler" );
2470 VisualFactory factory = VisualFactory::Get();
2471 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2473 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2474 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2479 tet_infoline( "3rd signal called" );
2480 DALI_TEST_CHECK(true);
2484 int UtcDaliImageVisualLoadReady01(void)
2486 ToolkitTestApplication application;
2487 tet_infoline( "UtcDaliImageVisualLoadReady01");
2488 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2489 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2490 tet_infoline( "Should get a ready signal for all three visuals");
2494 tet_infoline( "Create a control and connect to resource ready signal" );
2495 DummyControl actor = DummyControl::New(true);
2496 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2497 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2498 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2499 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2500 application.GetScene().Add(actor);
2502 tet_infoline( "Create visual with IMMEDIATE load policy" );
2503 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2505 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2506 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2509 tet_infoline( "Allow image time to load" );
2510 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2511 application.SendNotification();
2512 application.Render();
2514 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2515 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2516 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2519 tet_infoline( "Original control correctly signalled, now testing failing image" );
2521 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2524 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2526 DummyControl actor2 = DummyControl::New(true);
2527 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2528 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2529 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2531 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2532 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2534 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2535 application.GetScene().Add(actor2);
2537 tet_infoline( "Wait for loading thread to finish");
2538 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2539 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2541 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2543 tet_infoline( "Check for 3rd signal");
2544 application.SendNotification();
2545 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2546 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);