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 << 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().c_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().c_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 << GL_BLEND;
850 application.SendNotification();
851 application.Render();
853 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_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().c_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().c_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
934 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
935 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
936 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
944 int UtcDaliImageVisualAnimateOpacity02(void)
946 ToolkitTestApplication application;
947 tet_infoline( "Animate image visual opacity" );
949 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
951 VisualFactory factory = VisualFactory::Get();
952 Property::Map propertyMap;
953 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
954 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
955 propertyMap.Insert("opacity", 0.5f);
956 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
957 Visual::Base visual = factory.CreateVisual( propertyMap );
959 DummyControl actor = DummyControl::New(true);
960 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
961 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
963 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
964 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
965 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
967 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
969 Property::Array array;
972 map["target"] = "testVisual";
973 map["property"] = "opacity";
974 map["initialValue"] = 0.0f;
975 map["targetValue"] = 1.0f;
976 map["animator"] = Property::Map()
977 .Add("alphaFunction", "LINEAR")
978 .Add("timePeriod", Property::Map()
980 .Add("duration", 4.0f));
983 map2["target"] = "testVisual";
984 map2["property"] = "size";
985 map2["targetValue"] = Vector2(1.0f, 1.0f);
987 array.Add( map ).Add(map2);
989 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
990 Animation animation = dummyImpl.CreateTransition( transition );
992 application.GetScene().Add(actor);
993 application.SendNotification();
994 application.Render(0); // Ensure animation starts
996 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
998 Renderer renderer = actor.GetRendererAt(0);
999 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1000 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1002 animation = dummyImpl.CreateTransition( transition );
1005 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1006 glAbstraction.EnableEnableDisableCallTrace( true );
1007 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1008 std::ostringstream blendStr;
1009 blendStr << GL_BLEND;
1011 application.SendNotification();
1012 application.Render(0); // Ensure animation starts
1013 application.Render(2000u); // Halfway point through animation
1014 application.SendNotification(); // Handle any signals
1016 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1019 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1020 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1022 glEnableStack.Reset();
1024 application.Render(2001u); // end
1025 application.SendNotification(); // ensure animation finished signal is sent
1027 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1028 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1030 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
1037 int UtcDaliImageVisualAnimatePixelArea(void)
1039 ToolkitTestApplication application;
1040 tet_infoline( "ImageVisual animate pixel area" );
1042 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1044 VisualFactory factory = VisualFactory::Get();
1045 Property::Map propertyMap;
1046 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1047 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1048 propertyMap.Insert("mixColor", Color::BLUE);
1049 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1050 Visual::Base visual = factory.CreateVisual( propertyMap );
1052 DummyControl actor = DummyControl::New(true);
1053 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1054 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1056 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1057 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1058 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1059 application.GetScene().Add(actor);
1061 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1063 Renderer renderer = actor.GetRendererAt(0);
1064 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1066 tet_infoline("Test that the renderer has the mixColor property");
1067 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1069 // TransitionData only takes string keys
1071 map["target"] = "testVisual";
1072 map["property"] = "pixelArea";
1073 map["initialValue"] = Vector4( 0,0,0,1 );
1074 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1075 map["animator"] = Property::Map()
1076 .Add("alphaFunction", "LINEAR")
1077 .Add("timePeriod", Property::Map()
1079 .Add("duration", 4.0f));
1081 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1083 Animation animation = dummyImpl.CreateTransition( transition );
1084 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1087 application.SendNotification();
1088 application.Render(0); // Ensure animation starts
1089 application.Render(2000u); // Halfway point
1091 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1093 application.Render(2000u); // End of animation
1095 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1100 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1102 ToolkitTestApplication application;
1103 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1105 Property::Map propertyMap;
1106 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1107 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1109 TestGlAbstraction& gl = application.GetGlAbstraction();
1110 TraceCallStack& textureTrace = gl.GetTextureTrace();
1111 textureTrace.Enable(true);
1112 TraceCallStack& drawTrace = gl.GetDrawTrace();
1113 drawTrace.Enable(true);
1115 Actor actor = CreateActorWithImageVisual( propertyMap );
1116 application.GetScene().Add( actor );
1117 application.SendNotification();
1119 application.GetScene().Remove( actor );
1120 application.SendNotification();
1122 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1123 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1124 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1125 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1130 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1132 ToolkitTestApplication application;
1133 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1135 VisualFactory factory = VisualFactory::Get();
1136 DALI_TEST_CHECK( factory );
1138 Property::Map propertyMap;
1139 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1140 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1142 Visual::Base visual = factory.CreateVisual( propertyMap );
1143 DALI_TEST_CHECK( visual );
1145 TestGlAbstraction& gl = application.GetGlAbstraction();
1146 TraceCallStack& textureTrace = gl.GetTextureTrace();
1147 textureTrace.Enable( true );
1148 TraceCallStack& drawTrace = gl.GetDrawTrace();
1149 drawTrace.Enable( true );
1151 DummyControl actor = DummyControl::New();
1152 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1153 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1155 application.GetScene().Add( actor );
1158 application.GetScene().Remove( actor );
1160 application.GetScene().Add( actor );
1162 // Create another visual with the same image
1163 visual = factory.CreateVisual( propertyMap );
1164 DALI_TEST_CHECK( visual );
1166 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1168 application.SendNotification();
1169 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1171 application.SendNotification();
1172 application.Render();
1174 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1175 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1176 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1177 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1182 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1184 ToolkitTestApplication application;
1185 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1187 VisualFactory factory = VisualFactory::Get();
1188 DALI_TEST_CHECK( factory );
1190 Property::Map propertyMap;
1191 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1192 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1194 Visual::Base visual = factory.CreateVisual( propertyMap );
1195 DALI_TEST_CHECK( visual );
1197 TestGlAbstraction& gl = application.GetGlAbstraction();
1198 TraceCallStack& textureTrace = gl.GetTextureTrace();
1199 textureTrace.Enable(true);
1201 DummyControl actor = DummyControl::New();
1202 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1203 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1205 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1206 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1208 application.GetScene().Add( actor );
1210 application.SendNotification();
1211 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1213 application.SendNotification();
1214 application.Render();
1216 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1217 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1219 application.GetScene().Remove( actor );
1220 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1225 int UtcDaliImageVisualSetInvalidSyncImage(void)
1227 ToolkitTestApplication application;
1228 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1230 VisualFactory factory = VisualFactory::Get();
1231 DALI_TEST_CHECK( factory );
1233 Property::Map propertyMap;
1234 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1235 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1236 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1238 Visual::Base visual = factory.CreateVisual( propertyMap );
1239 DALI_TEST_CHECK( visual );
1241 TestGlAbstraction& gl = application.GetGlAbstraction();
1242 TraceCallStack& textureTrace = gl.GetTextureTrace();
1243 textureTrace.Enable(true);
1245 DummyControl actor = DummyControl::New();
1246 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1247 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1249 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1250 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1252 application.GetScene().Add( actor );
1254 application.SendNotification();
1255 application.Render();
1257 // Check resource status
1258 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1259 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1261 // The broken image should be shown.
1262 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1263 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1265 application.GetScene().Remove( actor );
1266 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1271 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1273 ToolkitTestApplication application;
1274 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1276 VisualFactory factory = VisualFactory::Get();
1277 DALI_TEST_CHECK( factory );
1279 // Local invalid file, asynchronous loading
1280 Property::Map propertyMap;
1281 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1282 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1284 Visual::Base visual = factory.CreateVisual( propertyMap );
1285 DALI_TEST_CHECK( visual );
1287 TestGlAbstraction& gl = application.GetGlAbstraction();
1288 TraceCallStack& textureTrace = gl.GetTextureTrace();
1289 textureTrace.Enable(true);
1291 DummyControl actor = DummyControl::New();
1292 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1293 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1295 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1296 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1298 application.GetScene().Add( actor );
1300 application.SendNotification();
1301 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1303 application.SendNotification();
1304 application.Render();
1306 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1307 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1309 application.GetScene().Remove( actor );
1310 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1315 int UtcDaliImageVisualAlphaMask(void)
1317 ToolkitTestApplication application;
1318 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1320 VisualFactory factory = VisualFactory::Get();
1321 DALI_TEST_CHECK( factory );
1323 Property::Map propertyMap;
1324 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1325 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1326 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1328 Visual::Base visual = factory.CreateVisual( propertyMap );
1329 DALI_TEST_CHECK( visual );
1331 Property::Map testMap;
1332 visual.CreatePropertyMap(testMap);
1333 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1335 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1336 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1338 TestGlAbstraction& gl = application.GetGlAbstraction();
1339 TraceCallStack& textureTrace = gl.GetTextureTrace();
1340 textureTrace.Enable(true);
1342 DummyControl actor = DummyControl::New();
1343 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1344 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1346 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1347 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1348 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1350 application.GetScene().Add( actor );
1351 application.SendNotification();
1352 application.Render();
1354 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1356 application.SendNotification();
1357 application.Render();
1359 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1360 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1361 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1363 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1364 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1369 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1371 ToolkitTestApplication application;
1372 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1374 VisualFactory factory = VisualFactory::Get();
1375 DALI_TEST_CHECK( factory );
1377 Property::Map propertyMap;
1378 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1379 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1380 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1381 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1383 Visual::Base visual = factory.CreateVisual( propertyMap );
1384 DALI_TEST_CHECK( visual );
1386 Property::Map testMap;
1387 visual.CreatePropertyMap(testMap);
1388 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1390 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1391 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1393 TestGlAbstraction& gl = application.GetGlAbstraction();
1394 TraceCallStack& textureTrace = gl.GetTextureTrace();
1395 textureTrace.Enable(true);
1397 DummyControl actor = DummyControl::New();
1398 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1399 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1401 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1402 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1403 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1405 application.GetScene().Add( actor );
1407 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1409 application.SendNotification();
1410 application.Render();
1412 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1413 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1414 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1416 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1417 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1422 int UtcDaliImageVisualRemoteAlphaMask(void)
1424 ToolkitTestApplication application;
1425 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1427 VisualFactory factory = VisualFactory::Get();
1428 DALI_TEST_CHECK( factory );
1430 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1432 Property::Map propertyMap;
1433 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1434 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1435 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1437 Visual::Base visual = factory.CreateVisual( propertyMap );
1438 DALI_TEST_CHECK( visual );
1440 Property::Map testMap;
1441 visual.CreatePropertyMap(testMap);
1443 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1445 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1446 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1448 TestGlAbstraction& gl = application.GetGlAbstraction();
1449 TraceCallStack& textureTrace = gl.GetTextureTrace();
1450 textureTrace.Enable(true);
1452 DummyControl actor = DummyControl::New();
1453 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1454 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1456 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1458 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1459 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1461 application.GetScene().Add( actor );
1462 application.SendNotification();
1463 application.Render();
1465 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1467 application.SendNotification();
1468 application.Render();
1470 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1471 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1472 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1477 int UtcDaliImageVisualAlphaMaskCrop(void)
1479 ToolkitTestApplication application;
1480 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1482 VisualFactory factory = VisualFactory::Get();
1483 DALI_TEST_CHECK( factory );
1485 Property::Map propertyMap;
1486 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1487 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1488 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1489 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1490 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1492 Visual::Base visual = factory.CreateVisual( propertyMap );
1493 DALI_TEST_CHECK( visual );
1495 Property::Map testMap;
1496 visual.CreatePropertyMap(testMap);
1497 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1498 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1499 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1501 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1502 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1504 TestGlAbstraction& gl = application.GetGlAbstraction();
1505 TraceCallStack& textureTrace = gl.GetTextureTrace();
1506 textureTrace.Enable(true);
1508 DummyControl actor = DummyControl::New();
1509 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1510 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1512 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1513 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1514 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1516 application.GetScene().Add( actor );
1517 application.SendNotification();
1518 application.Render();
1520 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1522 application.SendNotification();
1523 application.Render();
1526 visual.GetNaturalSize(size);
1528 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1529 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1530 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1531 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1536 int UtcDaliImageVisualReleasePolicy01(void)
1538 ToolkitTestApplication application;
1539 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1541 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1542 DALI_TEST_CHECK( imageVisual );
1544 // Set up debug trace
1545 TestGlAbstraction& gl = application.GetGlAbstraction();
1546 TraceCallStack& textureTrace = gl.GetTextureTrace();
1547 textureTrace.Enable(true);
1549 tet_infoline( "Register visual with control and ensure it has the only handle" );
1550 DummyControl actor = DummyControl::New(true);
1551 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1552 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1553 imageVisual.Reset();
1555 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1557 application.SendNotification();
1558 application.Render(0);
1559 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1560 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1562 application.GetScene().Add( actor );
1564 // Wait for image to load
1565 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1567 application.SendNotification();
1568 application.Render(0);
1569 // Test renderer and texture created
1570 tet_infoline( "Confirm texture created" );
1571 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1572 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1574 tet_infoline( "Disable visual causing the texture to be deleted" );
1575 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1577 application.SendNotification();
1578 application.Render(0);
1579 // Test renderer and textures removed.
1580 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1581 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1586 int UtcDaliImageVisualReleasePolicy02(void)
1588 ToolkitTestApplication application;
1589 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1591 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1592 DALI_TEST_CHECK( imageVisual );
1594 // Setup debug trace
1595 TestGlAbstraction& gl = application.GetGlAbstraction();
1596 TraceCallStack& textureTrace = gl.GetTextureTrace();
1597 textureTrace.Enable(true);
1599 tet_infoline( "Register visual with control and ensure it has the only handle" );
1600 DummyControl actor = DummyControl::New(true);
1601 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1602 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1603 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1605 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1607 application.SendNotification();
1608 application.Render(0);
1609 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1610 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1612 application.GetScene().Add( actor );
1614 // Wait for image to load
1615 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1617 application.SendNotification();
1618 application.Render(0);
1619 // Test renderer and texture created
1620 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1621 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1624 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1625 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1626 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1627 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1628 application.SendNotification();
1629 application.Render();
1631 // Test texture removed after visual destroyed.
1632 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1633 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1638 int UtcDaliImageVisualReleasePolicy03(void)
1640 ToolkitTestApplication application;
1641 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1643 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1644 DALI_TEST_CHECK( imageVisual );
1646 TestGlAbstraction& gl = application.GetGlAbstraction();
1647 TraceCallStack& textureTrace = gl.GetTextureTrace();
1648 textureTrace.Enable(true);
1650 tet_infoline( "Register visual with control and ensure it has the only handle" );
1651 DummyControl actor = DummyControl::New(true);
1652 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1653 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1654 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1656 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1658 application.SendNotification();
1659 application.Render(0);
1660 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1661 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1663 application.GetScene().Add( actor );
1665 // Wait for image to load
1666 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1668 application.SendNotification();
1669 application.Render(0);
1670 // Test renderer and texture created
1671 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1672 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1674 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1675 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1676 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1677 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1678 application.SendNotification();
1679 application.Render();
1681 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1682 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1687 int UtcDaliImageVisualReleasePolicy04(void)
1689 ToolkitTestApplication application;
1690 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1692 tet_infoline( "Create first visual with Never release policy" );
1693 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1695 tet_infoline( "Create second visual with Destroyed release policy");
1696 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1698 // Set up trace debug
1699 TestGlAbstraction& gl = application.GetGlAbstraction();
1700 TraceCallStack& textureTrace = gl.GetTextureTrace();
1701 textureTrace.Enable(true);
1703 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1704 DummyControl actor = DummyControl::New(true);
1705 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1706 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1707 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1708 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1709 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1711 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1713 // Test initially zero renderers
1714 application.SendNotification();
1715 application.Render(0);
1716 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1717 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1719 application.GetScene().Add( actor );
1721 // Wait for image to load
1722 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1724 application.SendNotification();
1725 application.Render(0);
1726 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1727 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1728 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1730 // Test renderer removed when visual destroyed
1731 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1732 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1733 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1734 application.SendNotification();
1735 application.Render();
1737 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1738 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1740 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1741 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1742 application.SendNotification();
1743 application.Render();
1745 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1746 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1747 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1752 int UtcDaliImageVisualReleasePolicy05(void)
1754 ToolkitTestApplication application;
1755 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1757 VisualFactory factory = VisualFactory::Get();
1759 Property::Map propertyMapNeverReleasePolicy;
1760 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1761 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1762 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1763 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1764 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1766 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1768 Property::Map resultMap;
1769 imageVisualNever.CreatePropertyMap( resultMap );
1770 DALI_TEST_CHECK( ! resultMap.Empty() );
1772 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1777 int UtcDaliImageVisualReleasePolicy06(void)
1779 ToolkitTestApplication application;
1780 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1782 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1783 DALI_TEST_CHECK( imageVisual );
1785 TestGlAbstraction& gl = application.GetGlAbstraction();
1786 TraceCallStack& textureTrace = gl.GetTextureTrace();
1787 textureTrace.Enable(true);
1789 tet_infoline( "Register visual with control and ensure it has the only handle" );
1790 DummyControl actor = DummyControl::New(true);
1791 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1792 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1793 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1795 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1797 application.SendNotification();
1798 application.Render(0);
1799 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1800 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1802 application.GetScene().Add( actor );
1804 // Wait for image to load
1805 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1807 application.SendNotification();
1808 application.Render(0);
1809 // Test renderer and texture created
1810 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1811 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1812 textureTrace.Reset();
1814 tet_infoline( "Disable Visual and check texture not affected" );
1815 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1816 application.SendNotification();
1817 application.Render(0);
1818 tet_infoline( "Check renderer is destroyed when visual off stage" );
1819 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1820 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1821 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1822 textureTrace.Reset();
1824 tet_infoline( "Re-enable Visual and check texture not affected" );
1825 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1826 application.SendNotification();
1827 application.Render(0);
1828 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1829 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1830 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1831 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1836 int UtcDaliImageVisualReleasePolicy07(void)
1838 ToolkitTestApplication application;
1839 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1841 tet_infoline( "Create first visual with DESTROYED release policy" );
1842 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1845 tet_infoline( "Create second visual with DETACHED release policy");
1846 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1848 // Set up trace debug
1849 TestGlAbstraction& gl = application.GetGlAbstraction();
1850 TraceCallStack& textureTrace = gl.GetTextureTrace();
1851 textureTrace.Enable(true);
1853 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1854 DummyControl actor = DummyControl::New(true);
1855 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1856 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1857 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1858 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1859 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1861 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1863 // Test initially zero renderers
1864 application.SendNotification();
1865 application.Render(0);
1866 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1867 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1869 application.GetScene().Add( actor );
1871 // Wait for image to load
1872 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1874 application.SendNotification();
1875 application.Render(0);
1876 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1877 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1878 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1880 // Test renderer removed when visual destroyed
1881 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1882 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1883 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1884 application.SendNotification();
1885 application.Render();
1887 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1888 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1890 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1891 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1892 application.SendNotification();
1893 application.Render();
1895 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1896 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1901 int UtcDaliImageVisualReleasePolicy08(void)
1903 ToolkitTestApplication application;
1904 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
1906 tet_infoline( "Create first visual with DESTROYED release policy" );
1907 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1909 // Set up trace debug
1910 TestGlAbstraction& gl = application.GetGlAbstraction();
1911 TraceCallStack& textureTrace = gl.GetTextureTrace();
1912 textureTrace.Enable(true);
1914 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1915 DummyControl actor = DummyControl::New(true);
1916 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1917 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1918 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1920 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1922 // Test initially zero renderers
1923 application.SendNotification();
1924 application.Render(0);
1925 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1926 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1927 textureTrace.Reset();
1929 application.GetScene().Add( actor );
1931 // Wait for image to load
1932 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1934 application.SendNotification();
1935 application.Render(0);
1936 tet_infoline( "Ensure a texture is created" );
1937 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1938 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1939 textureTrace.Reset();
1941 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
1942 // 1. Get TextureSet
1943 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
1945 // 2.Remove actor from stage. In this case, renderer also is deleted.
1946 tet_infoline( "Remove actor from stage" );
1947 application.GetScene().Remove( actor );
1948 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1949 application.SendNotification();
1950 application.Render();
1952 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
1953 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1954 textureTrace.Reset();
1956 // 3.Add actor in stage. In this case, renderer is created.
1957 tet_infoline( "Add actor in stage" );
1958 application.GetScene().Add( actor );
1959 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1960 application.SendNotification();
1961 application.Render();
1962 tet_infoline( "Ensure a texture is not created again" );
1963 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
1964 textureTrace.Reset();
1966 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
1967 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
1968 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
1969 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
1970 textureSetBefore.Reset();
1971 textureSetAfter.Reset();
1973 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1974 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1975 application.SendNotification();
1976 application.Render();
1977 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1982 int UtcDaliImageVisualLoadPolicy01(void)
1984 ToolkitTestApplication application;
1985 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1987 // Set up trace debug
1988 TestGlAbstraction& gl = application.GetGlAbstraction();
1989 TraceCallStack& textureTrace = gl.GetTextureTrace();
1990 textureTrace.Enable(true);
1992 tet_infoline( "Create visual with IMMEDIATE load policy" );
1993 VisualFactory factory = VisualFactory::Get();
1995 Property::Map propertyMap;
1996 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1997 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1998 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1999 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
2000 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
2002 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2004 Property::Map resultMap;
2005 imageVisual.CreatePropertyMap( resultMap );
2006 DALI_TEST_CHECK( ! resultMap.Empty() );
2007 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
2009 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2011 // Ensure texture has been uploaded
2012 application.SendNotification();
2013 application.Render();
2015 tet_infoline( "Ensure texture loading starts after visual created" );
2016 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2017 textureTrace.Reset();
2019 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2020 DummyControl actor = DummyControl::New(true);
2021 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2022 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2023 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2025 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2026 application.GetScene().Add( actor );
2027 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2028 const unsigned int TIME_OUT_3_SECONDS = 3;
2029 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2031 application.SendNotification();
2032 application.Render();
2034 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2035 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2037 // Ensure texture is deleted when no longer needed (ref count was correct )
2038 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2040 application.SendNotification();
2041 application.Render();
2043 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2044 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2049 int UtcDaliImageVisualLoadPolicy02(void)
2051 ToolkitTestApplication application;
2052 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2054 // Set up trace debug
2055 TestGlAbstraction& gl = application.GetGlAbstraction();
2056 TraceCallStack& textureTrace = gl.GetTextureTrace();
2057 textureTrace.Enable(true);
2059 tet_infoline( "Create visual with IMMEDIATE load policy" );
2060 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2062 const unsigned int TIME_OUT_3_SECONDS = 3;
2063 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2065 // Act on meeage queue even although nothing expected to load
2066 application.SendNotification();
2067 application.Render();
2069 tet_infoline( "Ensure texture is not generated yet" );
2070 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2071 textureTrace.Reset();
2073 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2074 DummyControl actor = DummyControl::New(true);
2075 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2076 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2077 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2079 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2080 application.GetScene().Add( actor );
2081 tet_infoline( "Allow image time to load" );
2082 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2084 application.SendNotification();
2085 application.Render();
2087 tet_infoline( "Ensure texture generated and renderer created" );
2088 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2089 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2091 // Ensure texture is delete when no longer needed
2092 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2094 application.SendNotification();
2095 application.Render();
2097 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2098 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2103 int UtcDaliImageVisualLoadPolicy03(void)
2105 ToolkitTestApplication application;
2106 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2108 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2110 // Set up trace debug
2111 TestGlAbstraction& gl = application.GetGlAbstraction();
2112 TraceCallStack& textureTrace = gl.GetTextureTrace();
2113 textureTrace.Enable(true);
2115 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2116 DummyControl actor = DummyControl::New(true);
2117 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2118 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2119 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2121 tet_infoline( "Create visual with IMMEDIATE load policy" );
2122 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2124 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2125 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2126 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2128 tet_infoline( "Allow image time to load resource" );
2129 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2130 application.SendNotification();
2131 application.Render();
2133 // Ensure texture has been uploaded
2134 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2135 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2140 int UtcDaliImageVisualLoadPolicy04(void)
2142 ToolkitTestApplication application;
2143 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2144 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2146 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2148 // Set up trace debug
2149 TestGlAbstraction& gl = application.GetGlAbstraction();
2150 TraceCallStack& textureTrace = gl.GetTextureTrace();
2151 textureTrace.Enable(true);
2153 tet_infoline( "Create a control and connect to resource ready signal" );
2154 DummyControl actor = DummyControl::New(true);
2155 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2156 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2157 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2159 tet_infoline( "Create visual with IMMEDIATE load policy" );
2160 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2162 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2163 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2164 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2166 tet_infoline( "Allow image time to load" );
2167 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2168 application.SendNotification();
2169 application.Render();
2171 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2172 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2173 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2175 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2177 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2178 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2179 DummyControl actor2 = DummyControl::New(true);
2180 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2181 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2183 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2184 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2185 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2186 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2187 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2188 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2193 int UtcDaliImageVisualLoadPolicy05(void)
2195 ToolkitTestApplication application;
2196 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2197 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2198 // Set up trace debug
2199 TestGlAbstraction& gl = application.GetGlAbstraction();
2200 TraceCallStack& textureTrace = gl.GetTextureTrace();
2201 textureTrace.Enable(true);
2203 tet_infoline( "Create a control and connect to resource ready signal" );
2204 DummyControl actor = DummyControl::New(true);
2205 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2206 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2207 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2208 application.GetScene().Add( actor );
2210 tet_infoline( "Create visual with ATTACHED load policy" );
2211 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2213 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2214 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2215 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2217 tet_infoline( "Allow image time to load" );
2218 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2219 application.SendNotification();
2220 application.Render();
2222 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2223 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2224 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2226 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2228 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2229 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2230 DummyControl actor2 = DummyControl::New(true);
2231 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2232 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2234 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2235 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2236 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2237 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2238 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2239 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2245 int UtcDaliImageVisualOrientationCorrection(void)
2247 ToolkitTestApplication application;
2248 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2250 VisualFactory factory = VisualFactory::Get();
2251 tet_infoline( "Create visual with Orientation correction set OFF" );
2252 Property::Map propertyMap;
2253 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2254 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2255 propertyMap.Insert( "orientationCorrection", false );
2256 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2258 tet_infoline( "Create control for visual, need to loaded it" );
2259 DummyControl actor = DummyControl::New(true);
2260 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2261 application.GetScene().Add( actor );
2263 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2264 // Wait for image to load
2265 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2267 Vector2 originalImageSize;
2268 tet_infoline( "Get size of original visual to compare later with rotated image" );
2269 imageVisual.GetNaturalSize( originalImageSize );
2270 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2271 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2272 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2273 application.SendNotification();
2274 application.Render();
2276 tet_infoline( "Create visual with Orientation correction set ON " );
2277 propertyMap.Clear();
2278 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2279 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2280 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2281 imageVisual = factory.CreateVisual( propertyMap );
2283 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2284 // Wait for image to load
2285 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2287 Vector2 rotatedImageSize;
2288 imageVisual.GetNaturalSize( rotatedImageSize );
2289 tet_infoline( "Confirm that visual has rotated" );
2290 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2291 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2293 Property::Map resultMap;
2294 imageVisual.CreatePropertyMap( resultMap );
2296 // check the Property::ORIENTATION_CORRECTION value from the returned map
2297 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2298 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2303 int UtcDaliImageVisualCustomShader(void)
2305 ToolkitTestApplication application;
2306 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2308 VisualFactory factory = VisualFactory::Get();
2309 Property::Map properties;
2310 Property::Map shader;
2311 const std::string vertexShader = "Foobar";
2312 const std::string fragmentShader = "Foobar";
2313 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2314 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2316 properties[Visual::Property::TYPE] = Visual::IMAGE;
2317 properties[Visual::Property::SHADER] = shader;
2318 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2320 Visual::Base visual = factory.CreateVisual( properties );
2322 // trigger creation through setting on stage
2323 DummyControl dummy = DummyControl::New( true );
2324 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2325 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2327 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2328 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2329 application.GetScene().Add( dummy );
2331 application.SendNotification();
2332 application.Render();
2334 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2336 Renderer renderer = dummy.GetRendererAt( 0 );
2337 Shader shader2 = renderer.GetShader();
2338 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2339 Property::Map* map = value.GetMap();
2340 DALI_TEST_CHECK( map );
2342 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2343 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2345 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2346 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2350 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2351 properties[Visual::Property::SHADER] = shader;
2353 Visual::Base visual1 = factory.CreateVisual( properties );
2355 // trigger creation through setting on stage
2356 DummyControl dummy1 = DummyControl::New( true );
2357 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2358 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2359 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2360 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2361 application.GetScene().Add( dummy1 );
2363 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2364 glAbstraction.EnableEnableDisableCallTrace( true );
2366 application.SendNotification();
2367 application.Render();
2369 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2370 std::ostringstream blendStr;
2371 blendStr << GL_BLEND;
2372 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
2378 void ResourceReadyLoadNext( Control control )
2380 static int callNumber = 0;
2382 gResourceReadySignalFired = true;
2383 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2385 if( callNumber == 0 )
2387 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2389 tet_infoline( "Create visual with loaded image from within the signal handler" );
2390 VisualFactory factory = VisualFactory::Get();
2391 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2393 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2394 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2399 tet_infoline( "3rd signal called" );
2400 DALI_TEST_CHECK(true);
2404 int UtcDaliImageVisualLoadReady01(void)
2406 ToolkitTestApplication application;
2407 tet_infoline( "UtcDaliImageVisualLoadReady01");
2408 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2409 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2410 tet_infoline( "Should get a ready signal for all three visuals");
2414 tet_infoline( "Create a control and connect to resource ready signal" );
2415 DummyControl actor = DummyControl::New(true);
2416 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2417 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2418 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2419 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2420 application.GetScene().Add(actor);
2422 tet_infoline( "Create visual with IMMEDIATE load policy" );
2423 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2425 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2426 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2429 tet_infoline( "Allow image time to load" );
2430 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2431 application.SendNotification();
2432 application.Render();
2434 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2435 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2436 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2439 tet_infoline( "Original control correctly signalled, now testing failing image" );
2441 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2444 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2446 DummyControl actor2 = DummyControl::New(true);
2447 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2448 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2449 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2451 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2452 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2454 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2455 application.GetScene().Add(actor2);
2457 tet_infoline( "Wait for loading thread to finish");
2458 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2459 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2461 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2463 tet_infoline( "Check for 3rd signal");
2464 application.SendNotification();
2465 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2466 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);