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/dali-toolkit.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
46 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
47 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
48 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
49 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
50 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
51 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
52 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
53 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
56 bool gResourceReadySignalFired = false;
57 std::vector<int> gReadyIds = {};
58 void ResourceReadySignal( Control control )
60 gResourceReadySignalFired = true;
61 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
68 Actor CreateActorWithImageVisual(const Property::Map& map)
70 VisualFactory factory = VisualFactory::Get();
71 DummyControl actor = DummyControl::New();
72 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
73 Visual::Base visual = factory.CreateVisual( map );
74 DALI_TEST_CHECK( visual );
75 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
76 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
77 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
82 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
84 VisualFactory factory = VisualFactory::Get();
86 Property::Map propertyMap;
87 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
88 propertyMap.Insert( ImageVisual::Property::URL, url );
89 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
90 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
91 propertyMap.Insert( key , value );
93 return factory.CreateVisual( propertyMap );
98 void TestVisualRender( ToolkitTestApplication& application,
100 Visual::Base& visual,
101 std::size_t expectedSamplers = 0,
102 ImageDimensions imageDimensions = ImageDimensions(),
103 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
105 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
106 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
110 // set the image size, for test case, this needs to be set before loading started
111 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
114 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
115 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
117 application.GetScene().Add( actor );
119 application.SendNotification(); // Send messages to update
120 application.Render(); // process update and render
121 application.SendNotification(); // process any signals to event
125 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
128 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
131 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
134 visual.CreatePropertyMap(map);
135 Property::Value* value = map.Find( mixColorIndex );
136 DALI_TEST_CHECK( value );
138 DALI_TEST_CHECK( value->Get( mixColor1 ) );
139 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
141 value = map.Find( Visual::Property::MIX_COLOR );
142 DALI_TEST_CHECK( value );
144 DALI_TEST_CHECK( value->Get( mixColor2 ) );
145 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
147 value = map.Find( Visual::Property::OPACITY );
148 DALI_TEST_CHECK( value );
150 DALI_TEST_CHECK( value->Get( opacity ) );
151 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
156 int UtcDaliImageVisualPropertyMap(void)
158 ToolkitTestApplication application;
159 tet_infoline( "Request image visual with a Property::Map" );
161 VisualFactory factory = VisualFactory::Get();
162 DALI_TEST_CHECK( factory );
163 factory.SetPreMultiplyOnLoad( true );
165 Property::Map propertyMap;
166 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
167 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
169 Visual::Base visual = factory.CreateVisual( propertyMap );
170 DALI_TEST_CHECK( visual );
172 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
173 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
175 TestGlAbstraction& gl = application.GetGlAbstraction();
176 TraceCallStack& textureTrace = gl.GetTextureTrace();
177 textureTrace.Enable(true);
179 DummyControl actor = DummyControl::New();
180 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
181 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
183 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
184 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
186 application.GetScene().Add( actor );
187 application.SendNotification();
188 application.Render();
190 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
192 application.SendNotification();
193 application.Render();
195 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
196 auto renderer = actor.GetRendererAt(0);
197 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
198 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
199 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
200 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
201 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
202 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
203 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
205 application.GetScene().Remove( actor );
206 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
212 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
214 ToolkitTestApplication application;
215 tet_infoline( "Request image visual without pre-multiplied alpha" );
217 VisualFactory factory = VisualFactory::Get();
218 DALI_TEST_CHECK( factory );
219 factory.SetPreMultiplyOnLoad( false );
221 Property::Map propertyMap;
222 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
223 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
225 Visual::Base visual = factory.CreateVisual( propertyMap );
226 DALI_TEST_CHECK( visual );
228 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
229 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
231 TestGlAbstraction& gl = application.GetGlAbstraction();
232 TraceCallStack& textureTrace = gl.GetTextureTrace();
233 textureTrace.Enable(true);
235 DummyControl actor = DummyControl::New();
236 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
237 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
239 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
240 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
242 application.GetScene().Add( actor );
243 application.SendNotification();
244 application.Render();
246 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
248 application.SendNotification();
249 application.Render();
251 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
252 auto renderer = actor.GetRendererAt(0);
253 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
254 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
255 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
256 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
258 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
259 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
261 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
263 application.GetScene().Remove( actor );
264 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
270 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
272 ToolkitTestApplication application;
273 tet_infoline( "Request image visual with no alpha channel" );
275 VisualFactory factory = VisualFactory::Get();
276 DALI_TEST_CHECK( factory );
278 Property::Map propertyMap;
279 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
280 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
282 Visual::Base visual = factory.CreateVisual( propertyMap );
283 DALI_TEST_CHECK( visual );
285 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
286 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
288 TestGlAbstraction& gl = application.GetGlAbstraction();
289 TraceCallStack& textureTrace = gl.GetTextureTrace();
290 textureTrace.Enable(true);
292 DummyControl actor = DummyControl::New();
293 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
294 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
296 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
297 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
299 application.GetScene().Add( actor );
300 application.SendNotification();
301 application.Render();
303 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
305 application.SendNotification();
306 application.Render();
308 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
309 auto renderer = actor.GetRendererAt(0);
310 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
311 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
312 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
313 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
315 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
316 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
318 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
320 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
321 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
322 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
323 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
324 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
325 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
326 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
327 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
329 textureTrace.Reset();
331 // Make a new visual with the same image
332 Visual::Base newVisual = factory.CreateVisual( propertyMap );
333 DALI_TEST_CHECK( newVisual );
335 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
336 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
338 DummyControl newActor = DummyControl::New();
339 DummyControlImpl& newDummyImpl = static_cast< DummyControlImpl& >( newActor.GetImplementation() );
340 newDummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual );
342 newActor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
343 DALI_TEST_EQUALS( newActor.GetRendererCount(), 0u, TEST_LOCATION );
345 application.GetScene().Add( newActor );
347 application.SendNotification();
348 application.Render();
350 DALI_TEST_EQUALS( newActor.GetRendererCount(), 1u, TEST_LOCATION );
351 auto newRenderer = newActor.GetRendererAt( 0 );
352 preMultipliedIndex = newRenderer.GetPropertyIndex( "preMultipliedAlpha" );
353 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
354 preMultipliedAlpha = newRenderer.GetProperty< bool >( preMultipliedIndex );
355 preMultipliedAlpha2 = newRenderer.GetProperty< bool >( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
357 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
358 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
360 srcFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
361 destFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
362 srcFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
363 destFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
364 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
365 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
366 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
367 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
369 application.GetScene().Remove( actor );
370 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
376 int UtcDaliImageVisualRemoteImageLoad(void)
378 ToolkitTestApplication application;
379 tet_infoline( "Request remote image visual with a Property::Map" );
381 VisualFactory factory = VisualFactory::Get();
382 DALI_TEST_CHECK( factory );
384 Property::Map propertyMap;
385 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
386 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
388 Visual::Base visual = factory.CreateVisual( propertyMap );
389 DALI_TEST_CHECK( visual );
391 TestGlAbstraction& gl = application.GetGlAbstraction();
392 TraceCallStack& textureTrace = gl.GetTextureTrace();
393 textureTrace.Enable(true);
395 DummyControl actor = DummyControl::New();
396 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
397 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
399 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
400 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
402 application.GetScene().Add( actor );
403 application.SendNotification();
405 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
407 application.SendNotification();
408 application.Render();
410 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
411 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
413 application.GetScene().Remove( actor );
414 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
419 int UtcDaliImageVisualTextureReuse1(void)
421 ToolkitTestApplication application;
422 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
424 Property::Map propertyMap;
425 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
426 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
427 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
429 TestGlAbstraction& gl = application.GetGlAbstraction();
430 TraceCallStack& textureTrace = gl.GetTextureTrace();
431 textureTrace.Enable(true);
432 TraceCallStack& drawTrace = gl.GetDrawTrace();
433 drawTrace.Enable(true);
435 Actor actor = CreateActorWithImageVisual( propertyMap );
436 application.GetScene().Add( actor );
437 application.SendNotification();
439 // Wait for image to load
440 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
442 application.SendNotification();
443 application.Render();
445 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
446 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
447 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
448 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
449 textureTrace.Reset();
452 Actor actor2 = CreateActorWithImageVisual( propertyMap );
453 application.GetScene().Add(actor2);
455 application.SendNotification(); // Send messages to update
456 application.Render(); // process update and render
457 application.SendNotification(); // process any signals to event
459 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
461 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
462 "draw calls use the same texture as the previous draw call\n" );
464 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
465 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
466 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
467 // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
469 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
471 application.GetScene().Remove( actor );
472 application.SendNotification();
473 application.Render();
475 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
476 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
478 tet_infoline("Test that removing last actor does delete the texture\n");
480 application.GetScene().Remove( actor2 ); // Detaches remaining ImageVisual
481 application.SendNotification();
482 application.Render();
484 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
485 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
491 int UtcDaliImageVisualTextureReuse2(void)
493 ToolkitTestApplication application;
494 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" );
496 Property::Map propertyMap;
497 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
498 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
500 TestGlAbstraction& gl = application.GetGlAbstraction();
501 TraceCallStack& textureTrace = gl.GetTextureTrace();
502 textureTrace.Enable(true);
503 TraceCallStack& drawTrace = gl.GetDrawTrace();
504 drawTrace.Enable(true);
506 Actor actor = CreateActorWithImageVisual( propertyMap );
507 application.GetScene().Add( actor );
508 application.SendNotification();
510 // Wait for image to load
511 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
513 application.SendNotification();
514 application.Render();
516 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
517 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
518 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
519 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
520 textureTrace.Reset();
523 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
524 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
525 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
526 Actor actor2 = CreateActorWithImageVisual( propertyMap );
527 application.GetScene().Add(actor2);
529 application.SendNotification();
531 // Wait for image to load
532 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
534 application.SendNotification();
535 application.Render();
537 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
539 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
540 "renderers are using different textures\n" );
542 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
543 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
544 TraceCallStack::NamedParams tex1;
545 tex1["texture"] << 1;
546 TraceCallStack::NamedParams tex2;
547 tex2["texture"] << 2;
548 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
549 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
551 tet_infoline("Test that removing 1 actor deletes it's texture\n");
553 application.GetScene().Remove( actor );
554 application.SendNotification();
555 application.Render();
557 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
558 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
560 tet_infoline("Test that removing last actor deletes it's texture\n");
562 application.GetScene().Remove( actor2 );
563 application.SendNotification();
564 application.Render();
566 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
567 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
573 int UtcDaliImageVisualCustomWrapModePixelArea(void)
575 ToolkitTestApplication application;
576 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
578 VisualFactory factory = VisualFactory::Get();
579 DALI_TEST_CHECK( factory );
581 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
584 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
586 Property::Map propertyMap;
587 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
588 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
589 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
590 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
591 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
592 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
593 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
594 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
595 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
597 Visual::Base visual = factory.CreateVisual( propertyMap );
598 DALI_TEST_CHECK( visual );
600 TestGlAbstraction& gl = application.GetGlAbstraction();
601 TraceCallStack& textureTrace = gl.GetTextureTrace();
602 textureTrace.Enable(true);
603 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
604 texParameterTrace.Enable( true );
606 DummyControl actor = DummyControl::New();
607 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
608 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
609 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
610 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
611 application.GetScene().Add( actor );
614 application.SendNotification();
615 application.Render();
617 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
619 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
621 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
622 std::stringstream out;
623 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
624 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
626 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
627 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
629 // test the uniforms which used to handle the wrap mode
630 Renderer renderer = actor.GetRendererAt( 0u );
631 DALI_TEST_CHECK( renderer );
633 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
634 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
635 Vector4 pixelAreaUniform;
636 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
637 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
639 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
640 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
641 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
642 Vector2 wrapModeUniform;
643 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
644 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
647 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
652 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
654 ToolkitTestApplication application;
655 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
657 VisualFactory factory = VisualFactory::Get();
658 DALI_TEST_CHECK( factory );
660 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
662 const int height=600;
663 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
665 Property::Map propertyMap;
666 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
667 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
668 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
669 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
670 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
671 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
672 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
673 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
675 Visual::Base visual = factory.CreateVisual( propertyMap );
676 DALI_TEST_CHECK( visual );
678 TestGlAbstraction& gl = application.GetGlAbstraction();
679 TraceCallStack& textureTrace = gl.GetTextureTrace();
680 textureTrace.Enable(true);
681 textureTrace.EnableLogging(true);
682 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
683 texParameterTrace.Enable( true );
684 texParameterTrace.EnableLogging( true );
686 DummyControl actor = DummyControl::New();
687 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
688 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
689 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
690 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
691 application.GetScene().Add( actor );
694 application.SendNotification();
695 application.Render();
696 application.SendNotification();
698 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
700 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
702 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
703 std::stringstream out;
704 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
705 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
707 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
708 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
710 // test the uniforms which used to handle the wrap mode
711 Renderer renderer = actor.GetRendererAt( 0u );
712 DALI_TEST_CHECK( renderer );
714 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
715 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
716 Vector4 pixelAreaUniform;
717 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
718 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
720 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
721 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
724 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
729 int UtcDaliImageVisualAnimateMixColor(void)
731 ToolkitTestApplication application;
732 tet_infoline( "Animate mix color" );
734 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
736 VisualFactory factory = VisualFactory::Get();
737 Property::Map propertyMap;
738 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
739 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
740 propertyMap.Insert("mixColor", Color::BLUE);
741 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
742 Visual::Base visual = factory.CreateVisual( propertyMap );
744 DummyControl actor = DummyControl::New(true);
745 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
746 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
748 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
749 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
750 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
751 application.GetScene().Add(actor);
753 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
755 Renderer renderer = actor.GetRendererAt(0);
756 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
757 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
758 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
760 tet_infoline("Test that the renderer has the mixColor property");
761 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
763 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
766 map["target"] = "testVisual";
767 map["property"] = "mixColor";
768 map["initialValue"] = Color::MAGENTA;
769 map["targetValue"] = TARGET_MIX_COLOR;
770 map["animator"] = Property::Map()
771 .Add("alphaFunction", "LINEAR")
772 .Add("timePeriod", Property::Map()
774 .Add("duration", 4.0f));
776 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
778 Animation animation = dummyImpl.CreateTransition( transition );
780 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
783 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
784 glAbstraction.EnableEnableDisableCallTrace( true );
785 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
786 std::ostringstream blendStr;
787 blendStr << std::hex << GL_BLEND;
789 application.SendNotification();
790 application.Render(0); // Ensure animation starts
791 application.Render(2000u); // Halfway point
792 Vector3 testColor( 1.0f, 0.0f, 0.5f );
794 // uColor.a should be actor's alpha * mixColor.a.
795 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
796 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
798 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
800 glEnableStack.Reset();
802 application.Render(2000u); // Halfway point between blue and white
804 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
805 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
806 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
808 // GL_BLEND should not be changed: Keep enabled
809 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
810 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
811 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
813 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
818 int UtcDaliImageVisualAnimateOpacity(void)
820 ToolkitTestApplication application;
821 tet_infoline( "Animate image visual opacity" );
823 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
825 VisualFactory factory = VisualFactory::Get();
826 Property::Map propertyMap;
827 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
828 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
829 propertyMap.Insert("opacity", 0.5f);
830 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
831 Visual::Base visual = factory.CreateVisual( propertyMap );
833 DummyControl actor = DummyControl::New(true);
834 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
835 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
837 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
838 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
839 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
840 application.GetScene().Add(actor);
842 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
844 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
845 glAbstraction.EnableEnableDisableCallTrace( true );
846 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
847 std::ostringstream blendStr;
848 blendStr << std::hex << GL_BLEND;
850 application.SendNotification();
851 application.Render();
853 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) );
856 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." );
859 map["target"] = "testVisual";
860 map["property"] = "opacity";
861 map["targetValue"] = 1.0f;
862 map["animator"] = Property::Map()
863 .Add("alphaFunction", "LINEAR")
864 .Add("timePeriod", Property::Map()
866 .Add("duration", 4.0f));
868 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
869 Animation animation = dummyImpl.CreateTransition( transition );
872 glEnableStack.Reset();
874 application.SendNotification();
875 application.Render(0); // Ensure animation starts
876 application.Render(2000u); // Halfway point through animation
877 application.SendNotification(); // Handle any signals
880 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
881 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
883 application.Render(2001u); // end
884 application.SendNotification(); // ensure animation finished signal is sent
886 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
887 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
889 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
890 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
891 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
896 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." );
899 map["target"] = "testVisual";
900 map["property"] = Visual::Property::OPACITY;
901 map["targetValue"] = 0.1f;
902 map["animator"] = Property::Map()
903 .Add("alphaFunction", "LINEAR")
904 .Add("timePeriod", Property::Map()
906 .Add("duration", 4.0f));
908 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
909 Animation animation = dummyImpl.CreateTransition( transition );
912 glEnableStack.Reset();
914 application.SendNotification();
915 application.Render(0); // Ensure animation starts
916 application.Render(2000u); // Halfway point
917 application.SendNotification();
920 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
921 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
923 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
925 glEnableStack.Reset();
927 application.Render(2016u); // end
928 application.SendNotification();
930 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
931 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
933 // GL_BLEND should not be changed: Keep enabled
935 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
936 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
937 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
945 int UtcDaliImageVisualAnimateOpacity02(void)
947 ToolkitTestApplication application;
948 tet_infoline( "Animate image visual opacity" );
950 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
952 VisualFactory factory = VisualFactory::Get();
953 Property::Map propertyMap;
954 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
955 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
956 propertyMap.Insert("opacity", 0.5f);
957 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
958 Visual::Base visual = factory.CreateVisual( propertyMap );
960 DummyControl actor = DummyControl::New(true);
961 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
962 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
964 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
965 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
966 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
968 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
970 Property::Array array;
973 map["target"] = "testVisual";
974 map["property"] = "opacity";
975 map["initialValue"] = 0.0f;
976 map["targetValue"] = 1.0f;
977 map["animator"] = Property::Map()
978 .Add("alphaFunction", "LINEAR")
979 .Add("timePeriod", Property::Map()
981 .Add("duration", 4.0f));
984 map2["target"] = "testVisual";
985 map2["property"] = "size";
986 map2["targetValue"] = Vector2(1.0f, 1.0f);
988 array.Add( map ).Add(map2);
990 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
991 Animation animation = dummyImpl.CreateTransition( transition );
993 application.GetScene().Add(actor);
994 application.SendNotification();
995 application.Render(0); // Ensure animation starts
997 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
999 Renderer renderer = actor.GetRendererAt(0);
1000 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1001 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1003 animation = dummyImpl.CreateTransition( transition );
1006 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1007 glAbstraction.EnableEnableDisableCallTrace( true );
1008 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1009 std::ostringstream blendStr;
1010 blendStr << std::hex << GL_BLEND;
1012 application.SendNotification();
1013 application.Render(0); // Ensure animation starts
1014 application.Render(2000u); // Halfway point through animation
1015 application.SendNotification(); // Handle any signals
1017 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1020 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1021 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1023 glEnableStack.Reset();
1025 application.Render(2001u); // end
1026 application.SendNotification(); // ensure animation finished signal is sent
1028 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1029 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1031 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1038 int UtcDaliImageVisualAnimatePixelArea(void)
1040 ToolkitTestApplication application;
1041 tet_infoline( "ImageVisual animate pixel area" );
1043 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1045 VisualFactory factory = VisualFactory::Get();
1046 Property::Map propertyMap;
1047 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1048 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1049 propertyMap.Insert("mixColor", Color::BLUE);
1050 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1051 Visual::Base visual = factory.CreateVisual( propertyMap );
1053 DummyControl actor = DummyControl::New(true);
1054 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1055 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1057 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1058 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1059 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1060 application.GetScene().Add(actor);
1062 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1064 Renderer renderer = actor.GetRendererAt(0);
1065 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1067 tet_infoline("Test that the renderer has the mixColor property");
1068 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1070 // TransitionData only takes string keys
1072 map["target"] = "testVisual";
1073 map["property"] = "pixelArea";
1074 map["initialValue"] = Vector4( 0,0,0,1 );
1075 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1076 map["animator"] = Property::Map()
1077 .Add("alphaFunction", "LINEAR")
1078 .Add("timePeriod", Property::Map()
1080 .Add("duration", 4.0f));
1082 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1084 Animation animation = dummyImpl.CreateTransition( transition );
1085 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1088 application.SendNotification();
1089 application.Render(0); // Ensure animation starts
1090 application.Render(2000u); // Halfway point
1092 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1094 application.Render(2000u); // End of animation
1096 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1101 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1103 ToolkitTestApplication application;
1104 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1106 Property::Map propertyMap;
1107 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1108 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1110 TestGlAbstraction& gl = application.GetGlAbstraction();
1111 TraceCallStack& textureTrace = gl.GetTextureTrace();
1112 textureTrace.Enable(true);
1113 TraceCallStack& drawTrace = gl.GetDrawTrace();
1114 drawTrace.Enable(true);
1116 Actor actor = CreateActorWithImageVisual( propertyMap );
1117 application.GetScene().Add( actor );
1118 application.SendNotification();
1120 application.GetScene().Remove( actor );
1121 application.SendNotification();
1123 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1124 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1125 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1126 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1131 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1133 ToolkitTestApplication application;
1134 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1136 VisualFactory factory = VisualFactory::Get();
1137 DALI_TEST_CHECK( factory );
1139 Property::Map propertyMap;
1140 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1141 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1143 Visual::Base visual = factory.CreateVisual( propertyMap );
1144 DALI_TEST_CHECK( visual );
1146 TestGlAbstraction& gl = application.GetGlAbstraction();
1147 TraceCallStack& textureTrace = gl.GetTextureTrace();
1148 textureTrace.Enable( true );
1149 TraceCallStack& drawTrace = gl.GetDrawTrace();
1150 drawTrace.Enable( true );
1152 DummyControl actor = DummyControl::New();
1153 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1154 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1156 application.GetScene().Add( actor );
1159 application.GetScene().Remove( actor );
1161 application.GetScene().Add( actor );
1163 // Create another visual with the same image
1164 visual = factory.CreateVisual( propertyMap );
1165 DALI_TEST_CHECK( visual );
1167 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1169 application.SendNotification();
1170 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1172 application.SendNotification();
1173 application.Render();
1175 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1176 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1177 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1178 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1183 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1185 ToolkitTestApplication application;
1186 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1188 VisualFactory factory = VisualFactory::Get();
1189 DALI_TEST_CHECK( factory );
1191 Property::Map propertyMap;
1192 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1193 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1195 Visual::Base visual = factory.CreateVisual( propertyMap );
1196 DALI_TEST_CHECK( visual );
1198 TestGlAbstraction& gl = application.GetGlAbstraction();
1199 TraceCallStack& textureTrace = gl.GetTextureTrace();
1200 textureTrace.Enable(true);
1202 DummyControl actor = DummyControl::New();
1203 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1204 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1206 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1207 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1209 application.GetScene().Add( actor );
1211 application.SendNotification();
1212 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1214 application.SendNotification();
1215 application.Render();
1217 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1218 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1220 application.GetScene().Remove( actor );
1221 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1226 int UtcDaliImageVisualSetInvalidSyncImage(void)
1228 ToolkitTestApplication application;
1229 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1231 VisualFactory factory = VisualFactory::Get();
1232 DALI_TEST_CHECK( factory );
1234 Property::Map propertyMap;
1235 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1236 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1237 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1239 Visual::Base visual = factory.CreateVisual( propertyMap );
1240 DALI_TEST_CHECK( visual );
1242 TestGlAbstraction& gl = application.GetGlAbstraction();
1243 TraceCallStack& textureTrace = gl.GetTextureTrace();
1244 textureTrace.Enable(true);
1246 DummyControl actor = DummyControl::New();
1247 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1248 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1250 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1251 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1253 application.GetScene().Add( actor );
1255 application.SendNotification();
1256 application.Render();
1258 // Check resource status
1259 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1260 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1262 // The broken image should be shown.
1263 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1264 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1266 application.GetScene().Remove( actor );
1267 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1272 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1274 ToolkitTestApplication application;
1275 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1277 VisualFactory factory = VisualFactory::Get();
1278 DALI_TEST_CHECK( factory );
1280 // Local invalid file, asynchronous loading
1281 Property::Map propertyMap;
1282 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1283 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1285 Visual::Base visual = factory.CreateVisual( propertyMap );
1286 DALI_TEST_CHECK( visual );
1288 TestGlAbstraction& gl = application.GetGlAbstraction();
1289 TraceCallStack& textureTrace = gl.GetTextureTrace();
1290 textureTrace.Enable(true);
1292 DummyControl actor = DummyControl::New();
1293 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1294 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1296 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1297 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1299 application.GetScene().Add( actor );
1301 application.SendNotification();
1302 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1304 application.SendNotification();
1305 application.Render();
1307 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1308 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1310 application.GetScene().Remove( actor );
1311 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1316 int UtcDaliImageVisualAlphaMask(void)
1318 ToolkitTestApplication application;
1319 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1321 VisualFactory factory = VisualFactory::Get();
1322 DALI_TEST_CHECK( factory );
1324 Property::Map propertyMap;
1325 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1326 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1327 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1329 Visual::Base visual = factory.CreateVisual( propertyMap );
1330 DALI_TEST_CHECK( visual );
1332 Property::Map testMap;
1333 visual.CreatePropertyMap(testMap);
1334 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1336 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1337 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1339 TestGlAbstraction& gl = application.GetGlAbstraction();
1340 TraceCallStack& textureTrace = gl.GetTextureTrace();
1341 textureTrace.Enable(true);
1343 DummyControl actor = DummyControl::New();
1344 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1345 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1347 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1348 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1349 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1351 application.GetScene().Add( actor );
1352 application.SendNotification();
1353 application.Render();
1355 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1357 application.SendNotification();
1358 application.Render();
1360 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1361 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1362 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1364 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1365 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1370 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1372 ToolkitTestApplication application;
1373 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1375 VisualFactory factory = VisualFactory::Get();
1376 DALI_TEST_CHECK( factory );
1378 Property::Map propertyMap;
1379 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1380 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1381 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1382 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1384 Visual::Base visual = factory.CreateVisual( propertyMap );
1385 DALI_TEST_CHECK( visual );
1387 Property::Map testMap;
1388 visual.CreatePropertyMap(testMap);
1389 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1391 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1392 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1394 TestGlAbstraction& gl = application.GetGlAbstraction();
1395 TraceCallStack& textureTrace = gl.GetTextureTrace();
1396 textureTrace.Enable(true);
1398 DummyControl actor = DummyControl::New();
1399 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1400 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1402 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1403 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1404 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1406 application.GetScene().Add( actor );
1408 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1410 application.SendNotification();
1411 application.Render();
1413 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1414 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1415 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1417 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1418 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1423 int UtcDaliImageVisualRemoteAlphaMask(void)
1425 ToolkitTestApplication application;
1426 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1428 VisualFactory factory = VisualFactory::Get();
1429 DALI_TEST_CHECK( factory );
1431 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1433 Property::Map propertyMap;
1434 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1435 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1436 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1438 Visual::Base visual = factory.CreateVisual( propertyMap );
1439 DALI_TEST_CHECK( visual );
1441 Property::Map testMap;
1442 visual.CreatePropertyMap(testMap);
1444 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1446 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1447 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1449 TestGlAbstraction& gl = application.GetGlAbstraction();
1450 TraceCallStack& textureTrace = gl.GetTextureTrace();
1451 textureTrace.Enable(true);
1453 DummyControl actor = DummyControl::New();
1454 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1455 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1457 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1459 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1460 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1462 application.GetScene().Add( actor );
1463 application.SendNotification();
1464 application.Render();
1466 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1468 application.SendNotification();
1469 application.Render();
1471 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1472 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1473 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1478 int UtcDaliImageVisualAlphaMaskCrop(void)
1480 ToolkitTestApplication application;
1481 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1483 VisualFactory factory = VisualFactory::Get();
1484 DALI_TEST_CHECK( factory );
1486 Property::Map propertyMap;
1487 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1488 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1489 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1490 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1491 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1493 Visual::Base visual = factory.CreateVisual( propertyMap );
1494 DALI_TEST_CHECK( visual );
1496 Property::Map testMap;
1497 visual.CreatePropertyMap(testMap);
1498 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1499 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1500 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1502 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1503 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1505 TestGlAbstraction& gl = application.GetGlAbstraction();
1506 TraceCallStack& textureTrace = gl.GetTextureTrace();
1507 textureTrace.Enable(true);
1509 DummyControl actor = DummyControl::New();
1510 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1511 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1513 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1514 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1515 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1517 application.GetScene().Add( actor );
1518 application.SendNotification();
1519 application.Render();
1521 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1523 application.SendNotification();
1524 application.Render();
1527 visual.GetNaturalSize(size);
1529 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1530 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1531 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1532 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1537 int UtcDaliImageVisualReleasePolicy01(void)
1539 ToolkitTestApplication application;
1540 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1542 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1543 DALI_TEST_CHECK( imageVisual );
1545 // Set up debug trace
1546 TestGlAbstraction& gl = application.GetGlAbstraction();
1547 TraceCallStack& textureTrace = gl.GetTextureTrace();
1548 textureTrace.Enable(true);
1550 tet_infoline( "Register visual with control and ensure it has the only handle" );
1551 DummyControl actor = DummyControl::New(true);
1552 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1553 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1554 imageVisual.Reset();
1556 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1558 application.SendNotification();
1559 application.Render(0);
1560 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1561 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1563 application.GetScene().Add( actor );
1565 // Wait for image to load
1566 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1568 application.SendNotification();
1569 application.Render(0);
1570 // Test renderer and texture created
1571 tet_infoline( "Confirm texture created" );
1572 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1573 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1575 tet_infoline( "Disable visual causing the texture to be deleted" );
1576 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1578 application.SendNotification();
1579 application.Render(0);
1580 // Test renderer and textures removed.
1581 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1582 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1587 int UtcDaliImageVisualReleasePolicy02(void)
1589 ToolkitTestApplication application;
1590 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1592 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1593 DALI_TEST_CHECK( imageVisual );
1595 // Setup debug trace
1596 TestGlAbstraction& gl = application.GetGlAbstraction();
1597 TraceCallStack& textureTrace = gl.GetTextureTrace();
1598 textureTrace.Enable(true);
1600 tet_infoline( "Register visual with control and ensure it has the only handle" );
1601 DummyControl actor = DummyControl::New(true);
1602 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1603 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1604 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1606 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1608 application.SendNotification();
1609 application.Render(0);
1610 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1611 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1613 application.GetScene().Add( actor );
1615 // Wait for image to load
1616 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1618 application.SendNotification();
1619 application.Render(0);
1620 // Test renderer and texture created
1621 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1622 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1625 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1626 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1627 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1628 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1629 application.SendNotification();
1630 application.Render();
1632 // Test texture removed after visual destroyed.
1633 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1634 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1639 int UtcDaliImageVisualReleasePolicy03(void)
1641 ToolkitTestApplication application;
1642 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1644 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1645 DALI_TEST_CHECK( imageVisual );
1647 TestGlAbstraction& gl = application.GetGlAbstraction();
1648 TraceCallStack& textureTrace = gl.GetTextureTrace();
1649 textureTrace.Enable(true);
1651 tet_infoline( "Register visual with control and ensure it has the only handle" );
1652 DummyControl actor = DummyControl::New(true);
1653 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1654 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1655 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1657 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1659 application.SendNotification();
1660 application.Render(0);
1661 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1662 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1664 application.GetScene().Add( actor );
1666 // Wait for image to load
1667 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1669 application.SendNotification();
1670 application.Render(0);
1671 // Test renderer and texture created
1672 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1673 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1675 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1676 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1677 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1678 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1679 application.SendNotification();
1680 application.Render();
1682 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1683 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1688 int UtcDaliImageVisualReleasePolicy04(void)
1690 ToolkitTestApplication application;
1691 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1693 tet_infoline( "Create first visual with Never release policy" );
1694 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1696 tet_infoline( "Create second visual with Destroyed release policy");
1697 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1699 // Set up trace debug
1700 TestGlAbstraction& gl = application.GetGlAbstraction();
1701 TraceCallStack& textureTrace = gl.GetTextureTrace();
1702 textureTrace.Enable(true);
1704 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1705 DummyControl actor = DummyControl::New(true);
1706 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1707 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1708 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1709 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1710 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1712 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1714 // Test initially zero renderers
1715 application.SendNotification();
1716 application.Render(0);
1717 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1718 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1720 application.GetScene().Add( actor );
1722 // Wait for image to load
1723 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1725 application.SendNotification();
1726 application.Render(0);
1727 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1728 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1729 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1731 // Test renderer removed when visual destroyed
1732 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1733 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1734 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1735 application.SendNotification();
1736 application.Render();
1738 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1739 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1741 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1742 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1743 application.SendNotification();
1744 application.Render();
1746 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1747 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1748 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1753 int UtcDaliImageVisualReleasePolicy05(void)
1755 ToolkitTestApplication application;
1756 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1758 VisualFactory factory = VisualFactory::Get();
1760 Property::Map propertyMapNeverReleasePolicy;
1761 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1762 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1763 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1764 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1765 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1767 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1769 Property::Map resultMap;
1770 imageVisualNever.CreatePropertyMap( resultMap );
1771 DALI_TEST_CHECK( ! resultMap.Empty() );
1773 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1778 int UtcDaliImageVisualReleasePolicy06(void)
1780 ToolkitTestApplication application;
1781 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1783 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1784 DALI_TEST_CHECK( imageVisual );
1786 TestGlAbstraction& gl = application.GetGlAbstraction();
1787 TraceCallStack& textureTrace = gl.GetTextureTrace();
1788 textureTrace.Enable(true);
1790 tet_infoline( "Register visual with control and ensure it has the only handle" );
1791 DummyControl actor = DummyControl::New(true);
1792 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1793 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1794 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1796 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1798 application.SendNotification();
1799 application.Render(0);
1800 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1801 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1803 application.GetScene().Add( actor );
1805 // Wait for image to load
1806 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1808 application.SendNotification();
1809 application.Render(0);
1810 // Test renderer and texture created
1811 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1812 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1813 textureTrace.Reset();
1815 tet_infoline( "Disable Visual and check texture not affected" );
1816 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1817 application.SendNotification();
1818 application.Render(0);
1819 tet_infoline( "Check renderer is destroyed when visual off stage" );
1820 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1821 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1822 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1823 textureTrace.Reset();
1825 tet_infoline( "Re-enable Visual and check texture not affected" );
1826 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1827 application.SendNotification();
1828 application.Render(0);
1829 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1830 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1831 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1832 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1837 int UtcDaliImageVisualReleasePolicy07(void)
1839 ToolkitTestApplication application;
1840 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1842 tet_infoline( "Create first visual with DESTROYED release policy" );
1843 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1846 tet_infoline( "Create second visual with DETACHED release policy");
1847 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1849 // Set up trace debug
1850 TestGlAbstraction& gl = application.GetGlAbstraction();
1851 TraceCallStack& textureTrace = gl.GetTextureTrace();
1852 textureTrace.Enable(true);
1854 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1855 DummyControl actor = DummyControl::New(true);
1856 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1857 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1858 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1859 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1860 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1862 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1864 // Test initially zero renderers
1865 application.SendNotification();
1866 application.Render(0);
1867 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1868 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1870 application.GetScene().Add( actor );
1872 // Wait for image to load
1873 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1875 application.SendNotification();
1876 application.Render(0);
1877 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1878 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1879 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1881 // Test renderer removed when visual destroyed
1882 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1883 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1884 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1885 application.SendNotification();
1886 application.Render();
1888 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1889 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1891 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1892 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1893 application.SendNotification();
1894 application.Render();
1896 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1897 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1902 int UtcDaliImageVisualReleasePolicy08(void)
1904 ToolkitTestApplication application;
1905 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
1907 tet_infoline( "Create first visual with DESTROYED release policy" );
1908 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1910 // Set up trace debug
1911 TestGlAbstraction& gl = application.GetGlAbstraction();
1912 TraceCallStack& textureTrace = gl.GetTextureTrace();
1913 textureTrace.Enable(true);
1915 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1916 DummyControl actor = DummyControl::New(true);
1917 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1918 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1919 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1921 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1923 // Test initially zero renderers
1924 application.SendNotification();
1925 application.Render(0);
1926 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1927 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1928 textureTrace.Reset();
1930 application.GetScene().Add( actor );
1932 // Wait for image to load
1933 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1935 application.SendNotification();
1936 application.Render(0);
1937 tet_infoline( "Ensure a texture is created" );
1938 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1939 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1940 textureTrace.Reset();
1942 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
1943 // 1. Get TextureSet
1944 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
1946 // 2.Remove actor from stage. In this case, renderer also is deleted.
1947 tet_infoline( "Remove actor from stage" );
1948 application.GetScene().Remove( actor );
1949 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1950 application.SendNotification();
1951 application.Render();
1953 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
1954 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1955 textureTrace.Reset();
1957 // 3.Add actor in stage. In this case, renderer is created.
1958 tet_infoline( "Add actor in stage" );
1959 application.GetScene().Add( actor );
1960 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1961 application.SendNotification();
1962 application.Render();
1963 tet_infoline( "Ensure a texture is not created again" );
1964 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
1965 textureTrace.Reset();
1967 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
1968 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
1969 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
1970 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
1971 textureSetBefore.Reset();
1972 textureSetAfter.Reset();
1974 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1975 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1976 application.SendNotification();
1977 application.Render();
1978 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1983 int UtcDaliImageVisualLoadPolicy01(void)
1985 ToolkitTestApplication application;
1986 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1988 // Set up trace debug
1989 TestGlAbstraction& gl = application.GetGlAbstraction();
1990 TraceCallStack& textureTrace = gl.GetTextureTrace();
1991 textureTrace.Enable(true);
1993 tet_infoline( "Create visual with IMMEDIATE load policy" );
1994 VisualFactory factory = VisualFactory::Get();
1996 Property::Map propertyMap;
1997 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1998 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1999 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
2000 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
2001 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
2003 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2005 Property::Map resultMap;
2006 imageVisual.CreatePropertyMap( resultMap );
2007 DALI_TEST_CHECK( ! resultMap.Empty() );
2008 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
2010 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2012 // Ensure texture has been uploaded
2013 application.SendNotification();
2014 application.Render();
2016 tet_infoline( "Ensure texture loading starts after visual created" );
2017 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2018 textureTrace.Reset();
2020 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2021 DummyControl actor = DummyControl::New(true);
2022 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2023 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2024 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2026 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2027 application.GetScene().Add( actor );
2028 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2029 const unsigned int TIME_OUT_3_SECONDS = 3;
2030 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2032 application.SendNotification();
2033 application.Render();
2035 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2036 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2038 // Ensure texture is deleted when no longer needed (ref count was correct )
2039 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2041 application.SendNotification();
2042 application.Render();
2044 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2045 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2050 int UtcDaliImageVisualLoadPolicy02(void)
2052 ToolkitTestApplication application;
2053 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2055 // Set up trace debug
2056 TestGlAbstraction& gl = application.GetGlAbstraction();
2057 TraceCallStack& textureTrace = gl.GetTextureTrace();
2058 textureTrace.Enable(true);
2060 tet_infoline( "Create visual with IMMEDIATE load policy" );
2061 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2063 const unsigned int TIME_OUT_3_SECONDS = 3;
2064 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2066 // Act on meeage queue even although nothing expected to load
2067 application.SendNotification();
2068 application.Render();
2070 tet_infoline( "Ensure texture is not generated yet" );
2071 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2072 textureTrace.Reset();
2074 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2075 DummyControl actor = DummyControl::New(true);
2076 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2077 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2078 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2080 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2081 application.GetScene().Add( actor );
2082 tet_infoline( "Allow image time to load" );
2083 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2085 application.SendNotification();
2086 application.Render();
2088 tet_infoline( "Ensure texture generated and renderer created" );
2089 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2090 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2092 // Ensure texture is delete when no longer needed
2093 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2095 application.SendNotification();
2096 application.Render();
2098 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2099 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2104 int UtcDaliImageVisualLoadPolicy03(void)
2106 ToolkitTestApplication application;
2107 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2109 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2111 // Set up trace debug
2112 TestGlAbstraction& gl = application.GetGlAbstraction();
2113 TraceCallStack& textureTrace = gl.GetTextureTrace();
2114 textureTrace.Enable(true);
2116 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2117 DummyControl actor = DummyControl::New(true);
2118 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2119 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2120 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2122 tet_infoline( "Create visual with IMMEDIATE load policy" );
2123 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2125 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2126 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2127 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2129 tet_infoline( "Allow image time to load resource" );
2130 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2131 application.SendNotification();
2132 application.Render();
2134 // Ensure texture has been uploaded
2135 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2136 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2141 int UtcDaliImageVisualLoadPolicy04(void)
2143 ToolkitTestApplication application;
2144 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2145 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2147 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2149 // Set up trace debug
2150 TestGlAbstraction& gl = application.GetGlAbstraction();
2151 TraceCallStack& textureTrace = gl.GetTextureTrace();
2152 textureTrace.Enable(true);
2154 tet_infoline( "Create a control and connect to resource ready signal" );
2155 DummyControl actor = DummyControl::New(true);
2156 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2157 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2158 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2160 tet_infoline( "Create visual with IMMEDIATE load policy" );
2161 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2163 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2164 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2165 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2167 tet_infoline( "Allow image time to load" );
2168 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2169 application.SendNotification();
2170 application.Render();
2172 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2173 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2174 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2176 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2178 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2179 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2180 DummyControl actor2 = DummyControl::New(true);
2181 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2182 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2184 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2185 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2186 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2187 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2188 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2189 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2194 int UtcDaliImageVisualLoadPolicy05(void)
2196 ToolkitTestApplication application;
2197 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2198 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2199 // Set up trace debug
2200 TestGlAbstraction& gl = application.GetGlAbstraction();
2201 TraceCallStack& textureTrace = gl.GetTextureTrace();
2202 textureTrace.Enable(true);
2204 tet_infoline( "Create a control and connect to resource ready signal" );
2205 DummyControl actor = DummyControl::New(true);
2206 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2207 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2208 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2209 application.GetScene().Add( actor );
2211 tet_infoline( "Create visual with ATTACHED load policy" );
2212 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2214 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2215 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2216 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2218 tet_infoline( "Allow image time to load" );
2219 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2220 application.SendNotification();
2221 application.Render();
2223 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2224 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2225 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2227 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2229 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2230 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2231 DummyControl actor2 = DummyControl::New(true);
2232 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2233 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2235 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2236 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2237 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2238 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2239 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2240 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2246 int UtcDaliImageVisualOrientationCorrection(void)
2248 ToolkitTestApplication application;
2249 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2251 VisualFactory factory = VisualFactory::Get();
2252 tet_infoline( "Create visual with Orientation correction set OFF" );
2253 Property::Map propertyMap;
2254 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2255 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2256 propertyMap.Insert( "orientationCorrection", false );
2257 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2259 tet_infoline( "Create control for visual, need to loaded it" );
2260 DummyControl actor = DummyControl::New(true);
2261 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2262 application.GetScene().Add( actor );
2264 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2265 // Wait for image to load
2266 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2268 Vector2 originalImageSize;
2269 tet_infoline( "Get size of original visual to compare later with rotated image" );
2270 imageVisual.GetNaturalSize( originalImageSize );
2271 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2272 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2273 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2274 application.SendNotification();
2275 application.Render();
2277 tet_infoline( "Create visual with Orientation correction set ON " );
2278 propertyMap.Clear();
2279 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2280 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2281 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2282 imageVisual = factory.CreateVisual( propertyMap );
2284 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2285 // Wait for image to load
2286 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2288 Vector2 rotatedImageSize;
2289 imageVisual.GetNaturalSize( rotatedImageSize );
2290 tet_infoline( "Confirm that visual has rotated" );
2291 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2292 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2294 Property::Map resultMap;
2295 imageVisual.CreatePropertyMap( resultMap );
2297 // check the Property::ORIENTATION_CORRECTION value from the returned map
2298 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2299 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2304 int UtcDaliImageVisualCustomShader(void)
2306 ToolkitTestApplication application;
2307 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2309 VisualFactory factory = VisualFactory::Get();
2310 Property::Map properties;
2311 Property::Map shader;
2312 const std::string vertexShader = "Foobar";
2313 const std::string fragmentShader = "Foobar";
2314 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2315 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2317 properties[Visual::Property::TYPE] = Visual::IMAGE;
2318 properties[Visual::Property::SHADER] = shader;
2319 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2321 Visual::Base visual = factory.CreateVisual( properties );
2323 // trigger creation through setting on stage
2324 DummyControl dummy = DummyControl::New( true );
2325 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2326 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2328 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2329 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2330 application.GetScene().Add( dummy );
2332 application.SendNotification();
2333 application.Render();
2335 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2337 Renderer renderer = dummy.GetRendererAt( 0 );
2338 Shader shader2 = renderer.GetShader();
2339 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2340 Property::Map* map = value.GetMap();
2341 DALI_TEST_CHECK( map );
2343 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2344 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2346 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2347 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2351 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2352 properties[Visual::Property::SHADER] = shader;
2354 Visual::Base visual1 = factory.CreateVisual( properties );
2356 // trigger creation through setting on stage
2357 DummyControl dummy1 = DummyControl::New( true );
2358 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2359 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2360 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2361 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2362 application.GetScene().Add( dummy1 );
2364 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2365 glAbstraction.EnableEnableDisableCallTrace( true );
2367 application.SendNotification();
2368 application.Render();
2370 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2371 std::ostringstream blendStr;
2372 blendStr << std::hex << GL_BLEND;
2373 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
2379 void ResourceReadyLoadNext( Control control )
2381 static int callNumber = 0;
2383 gResourceReadySignalFired = true;
2384 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2386 if( callNumber == 0 )
2388 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2390 tet_infoline( "Create visual with loaded image from within the signal handler" );
2391 VisualFactory factory = VisualFactory::Get();
2392 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2394 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2395 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2400 tet_infoline( "3rd signal called" );
2401 DALI_TEST_CHECK(true);
2405 int UtcDaliImageVisualLoadReady01(void)
2407 ToolkitTestApplication application;
2408 tet_infoline( "UtcDaliImageVisualLoadReady01");
2409 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2410 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2411 tet_infoline( "Should get a ready signal for all three visuals");
2415 tet_infoline( "Create a control and connect to resource ready signal" );
2416 DummyControl actor = DummyControl::New(true);
2417 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2418 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2419 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2420 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2421 application.GetScene().Add(actor);
2423 tet_infoline( "Create visual with IMMEDIATE load policy" );
2424 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2426 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2427 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2430 tet_infoline( "Allow image time to load" );
2431 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2432 application.SendNotification();
2433 application.Render();
2435 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2436 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2437 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2440 tet_infoline( "Original control correctly signalled, now testing failing image" );
2442 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2445 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2447 DummyControl actor2 = DummyControl::New(true);
2448 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2449 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2450 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2452 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2453 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2455 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2456 application.GetScene().Add(actor2);
2458 tet_infoline( "Wait for loading thread to finish");
2459 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2460 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2462 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2464 tet_infoline( "Check for 3rd signal");
2465 application.SendNotification();
2466 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2467 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);