2 * Copyright (c) 2020 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 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
468 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
470 application.GetScene().Remove( actor );
471 application.SendNotification();
472 application.Render();
474 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
475 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
477 tet_infoline("Test that removing last actor does delete the texture\n");
479 application.GetScene().Remove( actor2 ); // Detaches remaining ImageVisual
480 application.SendNotification();
481 application.Render();
483 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
484 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
490 int UtcDaliImageVisualTextureReuse2(void)
492 ToolkitTestApplication application;
493 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" );
495 Property::Map propertyMap;
496 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
497 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
499 TestGlAbstraction& gl = application.GetGlAbstraction();
500 TraceCallStack& textureTrace = gl.GetTextureTrace();
501 textureTrace.Enable(true);
502 TraceCallStack& drawTrace = gl.GetDrawTrace();
503 drawTrace.Enable(true);
505 Actor actor = CreateActorWithImageVisual( propertyMap );
506 application.GetScene().Add( actor );
507 application.SendNotification();
509 // Wait for image to load
510 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
512 application.SendNotification();
513 application.Render();
515 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
516 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
517 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
518 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
519 textureTrace.Reset();
522 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
523 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
524 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
525 Actor actor2 = CreateActorWithImageVisual( propertyMap );
526 application.GetScene().Add(actor2);
528 application.SendNotification();
530 // Wait for image to load
531 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
533 application.SendNotification();
534 application.Render();
536 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
538 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
539 "renderers are using different textures\n" );
541 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
542 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
543 TraceCallStack::NamedParams tex1;
544 tex1["texture"] = "1";
545 TraceCallStack::NamedParams tex2;
546 tex1["texture"] = "2";
547 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
548 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
550 tet_infoline("Test that removing 1 actor deletes it's texture\n");
552 application.GetScene().Remove( actor );
553 application.SendNotification();
554 application.Render();
556 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
557 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
559 tet_infoline("Test that removing last actor deletes it's texture\n");
561 application.GetScene().Remove( actor2 );
562 application.SendNotification();
563 application.Render();
565 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
566 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
572 int UtcDaliImageVisualCustomWrapModePixelArea(void)
574 ToolkitTestApplication application;
575 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
577 VisualFactory factory = VisualFactory::Get();
578 DALI_TEST_CHECK( factory );
580 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
583 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
585 Property::Map propertyMap;
586 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
587 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
588 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
589 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
590 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
591 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
592 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
593 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
594 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
596 Visual::Base visual = factory.CreateVisual( propertyMap );
597 DALI_TEST_CHECK( visual );
599 TestGlAbstraction& gl = application.GetGlAbstraction();
600 TraceCallStack& textureTrace = gl.GetTextureTrace();
601 textureTrace.Enable(true);
602 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
603 texParameterTrace.Enable( true );
605 DummyControl actor = DummyControl::New();
606 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
607 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
608 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
609 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
610 application.GetScene().Add( actor );
613 application.SendNotification();
614 application.Render();
616 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
618 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
620 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
621 std::stringstream out;
622 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
623 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
625 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
626 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
628 // test the uniforms which used to handle the wrap mode
629 Renderer renderer = actor.GetRendererAt( 0u );
630 DALI_TEST_CHECK( renderer );
632 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
633 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
634 Vector4 pixelAreaUniform;
635 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
636 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
638 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
639 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
640 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
641 Vector2 wrapModeUniform;
642 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
643 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
646 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
651 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
653 ToolkitTestApplication application;
654 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
656 VisualFactory factory = VisualFactory::Get();
657 DALI_TEST_CHECK( factory );
659 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
661 const int height=600;
662 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
664 Property::Map propertyMap;
665 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
666 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
667 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
668 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
669 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
670 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
671 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
672 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
674 Visual::Base visual = factory.CreateVisual( propertyMap );
675 DALI_TEST_CHECK( visual );
677 TestGlAbstraction& gl = application.GetGlAbstraction();
678 TraceCallStack& textureTrace = gl.GetTextureTrace();
679 textureTrace.Enable(true);
680 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
681 texParameterTrace.Enable( true );
683 DummyControl actor = DummyControl::New();
684 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
685 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
686 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
687 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
688 application.GetScene().Add( actor );
691 application.SendNotification();
692 application.Render();
694 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
696 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
698 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
699 std::stringstream out;
700 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
701 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
703 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
704 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
706 // test the uniforms which used to handle the wrap mode
707 Renderer renderer = actor.GetRendererAt( 0u );
708 DALI_TEST_CHECK( renderer );
710 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
711 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
712 Vector4 pixelAreaUniform;
713 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
714 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
716 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
717 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
720 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
725 int UtcDaliImageVisualAnimateMixColor(void)
727 ToolkitTestApplication application;
728 tet_infoline( "Animate mix color" );
730 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
732 VisualFactory factory = VisualFactory::Get();
733 Property::Map propertyMap;
734 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
735 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
736 propertyMap.Insert("mixColor", Color::BLUE);
737 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
738 Visual::Base visual = factory.CreateVisual( propertyMap );
740 DummyControl actor = DummyControl::New(true);
741 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
742 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
744 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
745 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
746 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
747 application.GetScene().Add(actor);
749 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
751 Renderer renderer = actor.GetRendererAt(0);
752 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
753 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
754 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
756 tet_infoline("Test that the renderer has the mixColor property");
757 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
759 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
762 map["target"] = "testVisual";
763 map["property"] = "mixColor";
764 map["initialValue"] = Color::MAGENTA;
765 map["targetValue"] = TARGET_MIX_COLOR;
766 map["animator"] = Property::Map()
767 .Add("alphaFunction", "LINEAR")
768 .Add("timePeriod", Property::Map()
770 .Add("duration", 4.0f));
772 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
774 Animation animation = dummyImpl.CreateTransition( transition );
776 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
779 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
780 glAbstraction.EnableEnableDisableCallTrace( true );
781 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
782 std::ostringstream blendStr;
783 blendStr << GL_BLEND;
785 application.SendNotification();
786 application.Render(0); // Ensure animation starts
787 application.Render(2000u); // Halfway point
788 Vector3 testColor( 1.0f, 0.0f, 0.5f );
790 // uColor.a should be actor's alpha * mixColor.a.
791 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
792 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
794 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
796 glEnableStack.Reset();
798 application.Render(2000u); // Halfway point between blue and white
800 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
801 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
802 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
804 // GL_BLEND should not be changed: Keep enabled
805 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
806 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
808 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
813 int UtcDaliImageVisualAnimateOpacity(void)
815 ToolkitTestApplication application;
816 tet_infoline( "Animate image visual opacity" );
818 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
820 VisualFactory factory = VisualFactory::Get();
821 Property::Map propertyMap;
822 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
823 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
824 propertyMap.Insert("opacity", 0.5f);
825 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
826 Visual::Base visual = factory.CreateVisual( propertyMap );
828 DummyControl actor = DummyControl::New(true);
829 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
830 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
832 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
833 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
834 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
835 application.GetScene().Add(actor);
837 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
839 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
840 glAbstraction.EnableEnableDisableCallTrace( true );
841 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
842 std::ostringstream blendStr;
843 blendStr << GL_BLEND;
845 application.SendNotification();
846 application.Render();
848 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
851 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." );
854 map["target"] = "testVisual";
855 map["property"] = "opacity";
856 map["targetValue"] = 1.0f;
857 map["animator"] = Property::Map()
858 .Add("alphaFunction", "LINEAR")
859 .Add("timePeriod", Property::Map()
861 .Add("duration", 4.0f));
863 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
864 Animation animation = dummyImpl.CreateTransition( transition );
867 glEnableStack.Reset();
869 application.SendNotification();
870 application.Render(0); // Ensure animation starts
871 application.Render(2000u); // Halfway point through animation
872 application.SendNotification(); // Handle any signals
875 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
876 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
878 application.Render(2001u); // end
879 application.SendNotification(); // ensure animation finished signal is sent
881 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
882 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
884 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
885 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
890 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." );
893 map["target"] = "testVisual";
894 map["property"] = Visual::Property::OPACITY;
895 map["targetValue"] = 0.1f;
896 map["animator"] = Property::Map()
897 .Add("alphaFunction", "LINEAR")
898 .Add("timePeriod", Property::Map()
900 .Add("duration", 4.0f));
902 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
903 Animation animation = dummyImpl.CreateTransition( transition );
906 glEnableStack.Reset();
908 application.SendNotification();
909 application.Render(0); // Ensure animation starts
910 application.Render(2000u); // Halfway point
911 application.SendNotification();
914 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
915 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
917 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
919 glEnableStack.Reset();
921 application.Render(2016u); // end
922 application.SendNotification();
924 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
925 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
927 // GL_BLEND should not be changed: Keep enabled
928 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
929 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
937 int UtcDaliImageVisualAnimateOpacity02(void)
939 ToolkitTestApplication application;
940 tet_infoline( "Animate image visual opacity" );
942 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
944 VisualFactory factory = VisualFactory::Get();
945 Property::Map propertyMap;
946 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
947 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
948 propertyMap.Insert("opacity", 0.5f);
949 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
950 Visual::Base visual = factory.CreateVisual( propertyMap );
952 DummyControl actor = DummyControl::New(true);
953 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
954 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
956 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
957 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
958 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
960 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
962 Property::Array array;
965 map["target"] = "testVisual";
966 map["property"] = "opacity";
967 map["initialValue"] = 0.0f;
968 map["targetValue"] = 1.0f;
969 map["animator"] = Property::Map()
970 .Add("alphaFunction", "LINEAR")
971 .Add("timePeriod", Property::Map()
973 .Add("duration", 4.0f));
976 map2["target"] = "testVisual";
977 map2["property"] = "size";
978 map2["targetValue"] = Vector2(1.0f, 1.0f);
980 array.Add( map ).Add(map2);
982 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
983 Animation animation = dummyImpl.CreateTransition( transition );
985 application.GetScene().Add(actor);
986 application.SendNotification();
987 application.Render(0); // Ensure animation starts
989 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
991 Renderer renderer = actor.GetRendererAt(0);
992 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
993 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
995 animation = dummyImpl.CreateTransition( transition );
998 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
999 glAbstraction.EnableEnableDisableCallTrace( true );
1000 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1001 std::ostringstream blendStr;
1002 blendStr << GL_BLEND;
1004 application.SendNotification();
1005 application.Render(0); // Ensure animation starts
1006 application.Render(2000u); // Halfway point through animation
1007 application.SendNotification(); // Handle any signals
1009 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1012 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1013 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1015 glEnableStack.Reset();
1017 application.Render(2001u); // end
1018 application.SendNotification(); // ensure animation finished signal is sent
1020 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1021 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1023 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
1030 int UtcDaliImageVisualAnimatePixelArea(void)
1032 ToolkitTestApplication application;
1033 tet_infoline( "ImageVisual animate pixel area" );
1035 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1037 VisualFactory factory = VisualFactory::Get();
1038 Property::Map propertyMap;
1039 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1040 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1041 propertyMap.Insert("mixColor", Color::BLUE);
1042 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1043 Visual::Base visual = factory.CreateVisual( propertyMap );
1045 DummyControl actor = DummyControl::New(true);
1046 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1047 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1049 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1050 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1051 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1052 application.GetScene().Add(actor);
1054 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1056 Renderer renderer = actor.GetRendererAt(0);
1057 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1059 tet_infoline("Test that the renderer has the mixColor property");
1060 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1062 // TransitionData only takes string keys
1064 map["target"] = "testVisual";
1065 map["property"] = "pixelArea";
1066 map["initialValue"] = Vector4( 0,0,0,1 );
1067 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1068 map["animator"] = Property::Map()
1069 .Add("alphaFunction", "LINEAR")
1070 .Add("timePeriod", Property::Map()
1072 .Add("duration", 4.0f));
1074 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1076 Animation animation = dummyImpl.CreateTransition( transition );
1077 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1080 application.SendNotification();
1081 application.Render(0); // Ensure animation starts
1082 application.Render(2000u); // Halfway point
1084 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1086 application.Render(2000u); // End of animation
1088 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1093 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1095 ToolkitTestApplication application;
1096 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1098 Property::Map propertyMap;
1099 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1100 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1102 TestGlAbstraction& gl = application.GetGlAbstraction();
1103 TraceCallStack& textureTrace = gl.GetTextureTrace();
1104 textureTrace.Enable(true);
1105 TraceCallStack& drawTrace = gl.GetDrawTrace();
1106 drawTrace.Enable(true);
1108 Actor actor = CreateActorWithImageVisual( propertyMap );
1109 application.GetScene().Add( actor );
1110 application.SendNotification();
1112 application.GetScene().Remove( actor );
1113 application.SendNotification();
1115 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1116 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1117 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1118 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1123 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1125 ToolkitTestApplication application;
1126 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1128 VisualFactory factory = VisualFactory::Get();
1129 DALI_TEST_CHECK( factory );
1131 Property::Map propertyMap;
1132 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1133 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1135 Visual::Base visual = factory.CreateVisual( propertyMap );
1136 DALI_TEST_CHECK( visual );
1138 TestGlAbstraction& gl = application.GetGlAbstraction();
1139 TraceCallStack& textureTrace = gl.GetTextureTrace();
1140 textureTrace.Enable( true );
1141 TraceCallStack& drawTrace = gl.GetDrawTrace();
1142 drawTrace.Enable( true );
1144 DummyControl actor = DummyControl::New();
1145 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1146 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1148 application.GetScene().Add( actor );
1151 application.GetScene().Remove( actor );
1153 application.GetScene().Add( actor );
1155 // Create another visual with the same image
1156 visual = factory.CreateVisual( propertyMap );
1157 DALI_TEST_CHECK( visual );
1159 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1161 application.SendNotification();
1162 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1164 application.SendNotification();
1165 application.Render();
1167 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1168 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1169 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1170 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1175 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1177 ToolkitTestApplication application;
1178 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1180 VisualFactory factory = VisualFactory::Get();
1181 DALI_TEST_CHECK( factory );
1183 Property::Map propertyMap;
1184 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1185 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1187 Visual::Base visual = factory.CreateVisual( propertyMap );
1188 DALI_TEST_CHECK( visual );
1190 TestGlAbstraction& gl = application.GetGlAbstraction();
1191 TraceCallStack& textureTrace = gl.GetTextureTrace();
1192 textureTrace.Enable(true);
1194 DummyControl actor = DummyControl::New();
1195 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1196 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1198 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1199 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1201 application.GetScene().Add( actor );
1203 application.SendNotification();
1204 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1206 application.SendNotification();
1207 application.Render();
1209 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1210 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1212 application.GetScene().Remove( actor );
1213 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1218 int UtcDaliImageVisualSetInvalidSyncImage(void)
1220 ToolkitTestApplication application;
1221 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1223 VisualFactory factory = VisualFactory::Get();
1224 DALI_TEST_CHECK( factory );
1226 Property::Map propertyMap;
1227 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1228 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1229 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1231 Visual::Base visual = factory.CreateVisual( propertyMap );
1232 DALI_TEST_CHECK( visual );
1234 TestGlAbstraction& gl = application.GetGlAbstraction();
1235 TraceCallStack& textureTrace = gl.GetTextureTrace();
1236 textureTrace.Enable(true);
1238 DummyControl actor = DummyControl::New();
1239 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1240 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1242 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1243 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1245 application.GetScene().Add( actor );
1247 application.SendNotification();
1248 application.Render();
1250 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1251 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1253 application.GetScene().Remove( actor );
1254 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1259 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1261 ToolkitTestApplication application;
1262 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1264 VisualFactory factory = VisualFactory::Get();
1265 DALI_TEST_CHECK( factory );
1267 // Local invalid file, asynchronous loading
1268 Property::Map propertyMap;
1269 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1270 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1272 Visual::Base visual = factory.CreateVisual( propertyMap );
1273 DALI_TEST_CHECK( visual );
1275 TestGlAbstraction& gl = application.GetGlAbstraction();
1276 TraceCallStack& textureTrace = gl.GetTextureTrace();
1277 textureTrace.Enable(true);
1279 DummyControl actor = DummyControl::New();
1280 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1281 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1283 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1284 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1286 application.GetScene().Add( actor );
1288 application.SendNotification();
1289 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1291 application.SendNotification();
1292 application.Render();
1294 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1295 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1297 application.GetScene().Remove( actor );
1298 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1303 int UtcDaliImageVisualAlphaMask(void)
1305 ToolkitTestApplication application;
1306 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1308 VisualFactory factory = VisualFactory::Get();
1309 DALI_TEST_CHECK( factory );
1311 Property::Map propertyMap;
1312 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1313 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1314 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1316 Visual::Base visual = factory.CreateVisual( propertyMap );
1317 DALI_TEST_CHECK( visual );
1319 Property::Map testMap;
1320 visual.CreatePropertyMap(testMap);
1321 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1323 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1324 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1326 TestGlAbstraction& gl = application.GetGlAbstraction();
1327 TraceCallStack& textureTrace = gl.GetTextureTrace();
1328 textureTrace.Enable(true);
1330 DummyControl actor = DummyControl::New();
1331 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1332 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1334 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1335 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1336 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1338 application.GetScene().Add( actor );
1339 application.SendNotification();
1340 application.Render();
1342 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1344 application.SendNotification();
1345 application.Render();
1347 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1348 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1349 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1351 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1352 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1357 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1359 ToolkitTestApplication application;
1360 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1362 VisualFactory factory = VisualFactory::Get();
1363 DALI_TEST_CHECK( factory );
1365 Property::Map propertyMap;
1366 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1367 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1368 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1369 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1371 Visual::Base visual = factory.CreateVisual( propertyMap );
1372 DALI_TEST_CHECK( visual );
1374 Property::Map testMap;
1375 visual.CreatePropertyMap(testMap);
1376 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1378 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1379 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1381 TestGlAbstraction& gl = application.GetGlAbstraction();
1382 TraceCallStack& textureTrace = gl.GetTextureTrace();
1383 textureTrace.Enable(true);
1385 DummyControl actor = DummyControl::New();
1386 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1387 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1389 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1390 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1391 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1393 application.GetScene().Add( actor );
1395 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1397 application.SendNotification();
1398 application.Render();
1400 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1401 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1402 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1404 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1405 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1410 int UtcDaliImageVisualRemoteAlphaMask(void)
1412 ToolkitTestApplication application;
1413 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1415 VisualFactory factory = VisualFactory::Get();
1416 DALI_TEST_CHECK( factory );
1418 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1420 Property::Map propertyMap;
1421 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1422 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1423 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1425 Visual::Base visual = factory.CreateVisual( propertyMap );
1426 DALI_TEST_CHECK( visual );
1428 Property::Map testMap;
1429 visual.CreatePropertyMap(testMap);
1431 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1433 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1434 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1436 TestGlAbstraction& gl = application.GetGlAbstraction();
1437 TraceCallStack& textureTrace = gl.GetTextureTrace();
1438 textureTrace.Enable(true);
1440 DummyControl actor = DummyControl::New();
1441 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1442 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1444 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1446 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1447 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1449 application.GetScene().Add( actor );
1450 application.SendNotification();
1451 application.Render();
1453 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1455 application.SendNotification();
1456 application.Render();
1458 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1459 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1460 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1465 int UtcDaliImageVisualAlphaMaskCrop(void)
1467 ToolkitTestApplication application;
1468 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1470 VisualFactory factory = VisualFactory::Get();
1471 DALI_TEST_CHECK( factory );
1473 Property::Map propertyMap;
1474 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1475 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1476 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1477 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1478 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1480 Visual::Base visual = factory.CreateVisual( propertyMap );
1481 DALI_TEST_CHECK( visual );
1483 Property::Map testMap;
1484 visual.CreatePropertyMap(testMap);
1485 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1486 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1487 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1489 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1490 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1492 TestGlAbstraction& gl = application.GetGlAbstraction();
1493 TraceCallStack& textureTrace = gl.GetTextureTrace();
1494 textureTrace.Enable(true);
1496 DummyControl actor = DummyControl::New();
1497 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1498 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1500 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1501 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1502 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1504 application.GetScene().Add( actor );
1505 application.SendNotification();
1506 application.Render();
1508 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1510 application.SendNotification();
1511 application.Render();
1514 visual.GetNaturalSize(size);
1516 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1517 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1518 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1519 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1524 int UtcDaliImageVisualReleasePolicy01(void)
1526 ToolkitTestApplication application;
1527 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1529 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1530 DALI_TEST_CHECK( imageVisual );
1532 // Set up debug trace
1533 TestGlAbstraction& gl = application.GetGlAbstraction();
1534 TraceCallStack& textureTrace = gl.GetTextureTrace();
1535 textureTrace.Enable(true);
1537 tet_infoline( "Register visual with control and ensure it has the only handle" );
1538 DummyControl actor = DummyControl::New(true);
1539 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1540 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1541 imageVisual.Reset();
1543 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1545 application.SendNotification();
1546 application.Render(0);
1547 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1548 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1550 application.GetScene().Add( actor );
1552 // Wait for image to load
1553 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1555 application.SendNotification();
1556 application.Render(0);
1557 // Test renderer and texture created
1558 tet_infoline( "Confirm texture created" );
1559 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1560 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1562 tet_infoline( "Disable visual causing the texture to be deleted" );
1563 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1565 application.SendNotification();
1566 application.Render(0);
1567 // Test renderer and textures removed.
1568 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1569 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1574 int UtcDaliImageVisualReleasePolicy02(void)
1576 ToolkitTestApplication application;
1577 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1579 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1580 DALI_TEST_CHECK( imageVisual );
1582 // Setup debug trace
1583 TestGlAbstraction& gl = application.GetGlAbstraction();
1584 TraceCallStack& textureTrace = gl.GetTextureTrace();
1585 textureTrace.Enable(true);
1587 tet_infoline( "Register visual with control and ensure it has the only handle" );
1588 DummyControl actor = DummyControl::New(true);
1589 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1590 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1591 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1593 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1595 application.SendNotification();
1596 application.Render(0);
1597 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1598 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1600 application.GetScene().Add( actor );
1602 // Wait for image to load
1603 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1605 application.SendNotification();
1606 application.Render(0);
1607 // Test renderer and texture created
1608 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1609 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1612 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1613 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1614 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1615 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1616 application.SendNotification();
1617 application.Render();
1619 // Test texture removed after visual destroyed.
1620 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1621 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1626 int UtcDaliImageVisualReleasePolicy03(void)
1628 ToolkitTestApplication application;
1629 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1631 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1632 DALI_TEST_CHECK( imageVisual );
1634 TestGlAbstraction& gl = application.GetGlAbstraction();
1635 TraceCallStack& textureTrace = gl.GetTextureTrace();
1636 textureTrace.Enable(true);
1638 tet_infoline( "Register visual with control and ensure it has the only handle" );
1639 DummyControl actor = DummyControl::New(true);
1640 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1641 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1642 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1644 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1646 application.SendNotification();
1647 application.Render(0);
1648 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1649 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1651 application.GetScene().Add( actor );
1653 // Wait for image to load
1654 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1656 application.SendNotification();
1657 application.Render(0);
1658 // Test renderer and texture created
1659 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1660 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1662 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1663 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1664 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1665 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1666 application.SendNotification();
1667 application.Render();
1669 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1670 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1675 int UtcDaliImageVisualReleasePolicy04(void)
1677 ToolkitTestApplication application;
1678 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1680 tet_infoline( "Create first visual with Never release policy" );
1681 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1683 tet_infoline( "Create second visual with Destroyed release policy");
1684 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1686 // Set up trace debug
1687 TestGlAbstraction& gl = application.GetGlAbstraction();
1688 TraceCallStack& textureTrace = gl.GetTextureTrace();
1689 textureTrace.Enable(true);
1691 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1692 DummyControl actor = DummyControl::New(true);
1693 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1694 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1695 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1696 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1697 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1699 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1701 // Test initially zero renderers
1702 application.SendNotification();
1703 application.Render(0);
1704 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1705 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1707 application.GetScene().Add( actor );
1709 // Wait for image to load
1710 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1712 application.SendNotification();
1713 application.Render(0);
1714 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1715 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1716 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1718 // Test renderer removed when visual destroyed
1719 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1720 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1721 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1722 application.SendNotification();
1723 application.Render();
1725 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1726 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1728 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1729 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1730 application.SendNotification();
1731 application.Render();
1733 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1734 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1735 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1740 int UtcDaliImageVisualReleasePolicy05(void)
1742 ToolkitTestApplication application;
1743 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1745 VisualFactory factory = VisualFactory::Get();
1747 Property::Map propertyMapNeverReleasePolicy;
1748 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1749 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1750 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1751 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1752 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1754 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1756 Property::Map resultMap;
1757 imageVisualNever.CreatePropertyMap( resultMap );
1758 DALI_TEST_CHECK( ! resultMap.Empty() );
1760 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1765 int UtcDaliImageVisualReleasePolicy06(void)
1767 ToolkitTestApplication application;
1768 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1770 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1771 DALI_TEST_CHECK( imageVisual );
1773 TestGlAbstraction& gl = application.GetGlAbstraction();
1774 TraceCallStack& textureTrace = gl.GetTextureTrace();
1775 textureTrace.Enable(true);
1777 tet_infoline( "Register visual with control and ensure it has the only handle" );
1778 DummyControl actor = DummyControl::New(true);
1779 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1780 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1781 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1783 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1785 application.SendNotification();
1786 application.Render(0);
1787 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1788 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1790 application.GetScene().Add( actor );
1792 // Wait for image to load
1793 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1795 application.SendNotification();
1796 application.Render(0);
1797 // Test renderer and texture created
1798 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1799 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1800 textureTrace.Reset();
1802 tet_infoline( "Disable Visual and check texture not affected" );
1803 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1804 application.SendNotification();
1805 application.Render(0);
1806 tet_infoline( "Check renderer is destroyed when visual off stage" );
1807 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1808 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1809 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1810 textureTrace.Reset();
1812 tet_infoline( "Re-enable Visual and check texture not affected" );
1813 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1814 application.SendNotification();
1815 application.Render(0);
1816 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1817 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1818 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1819 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1824 int UtcDaliImageVisualReleasePolicy07(void)
1826 ToolkitTestApplication application;
1827 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1829 tet_infoline( "Create first visual with DESTROYED release policy" );
1830 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1833 tet_infoline( "Create second visual with DETACHED release policy");
1834 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1836 // Set up trace debug
1837 TestGlAbstraction& gl = application.GetGlAbstraction();
1838 TraceCallStack& textureTrace = gl.GetTextureTrace();
1839 textureTrace.Enable(true);
1841 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1842 DummyControl actor = DummyControl::New(true);
1843 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1844 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1845 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1846 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1847 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1849 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1851 // Test initially zero renderers
1852 application.SendNotification();
1853 application.Render(0);
1854 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1855 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1857 application.GetScene().Add( actor );
1859 // Wait for image to load
1860 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1862 application.SendNotification();
1863 application.Render(0);
1864 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1865 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1866 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1868 // Test renderer removed when visual destroyed
1869 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1870 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1871 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1872 application.SendNotification();
1873 application.Render();
1875 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1876 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1878 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1879 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1880 application.SendNotification();
1881 application.Render();
1883 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1884 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1889 int UtcDaliImageVisualReleasePolicy08(void)
1891 ToolkitTestApplication application;
1892 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
1894 tet_infoline( "Create first visual with DESTROYED release policy" );
1895 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1897 // Set up trace debug
1898 TestGlAbstraction& gl = application.GetGlAbstraction();
1899 TraceCallStack& textureTrace = gl.GetTextureTrace();
1900 textureTrace.Enable(true);
1902 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1903 DummyControl actor = DummyControl::New(true);
1904 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1905 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1906 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1908 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1910 // Test initially zero renderers
1911 application.SendNotification();
1912 application.Render(0);
1913 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1914 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1915 textureTrace.Reset();
1917 application.GetScene().Add( actor );
1919 // Wait for image to load
1920 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1922 application.SendNotification();
1923 application.Render(0);
1924 tet_infoline( "Ensure a texture is created" );
1925 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1926 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1927 textureTrace.Reset();
1929 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
1930 // 1. Get TextureSet
1931 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
1933 // 2.Remove actor from stage. In this case, renderer also is deleted.
1934 tet_infoline( "Remove actor from stage" );
1935 application.GetScene().Remove( actor );
1936 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1937 application.SendNotification();
1938 application.Render();
1940 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
1941 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1942 textureTrace.Reset();
1944 // 3.Add actor in stage. In this case, renderer is created.
1945 tet_infoline( "Add actor in stage" );
1946 application.GetScene().Add( actor );
1947 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1948 application.SendNotification();
1949 application.Render();
1950 tet_infoline( "Ensure a texture is not created again" );
1951 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
1952 textureTrace.Reset();
1954 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
1955 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
1956 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
1957 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
1958 textureSetBefore.Reset();
1959 textureSetAfter.Reset();
1961 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1962 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1963 application.SendNotification();
1964 application.Render();
1965 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1970 int UtcDaliImageVisualLoadPolicy01(void)
1972 ToolkitTestApplication application;
1973 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1975 // Set up trace debug
1976 TestGlAbstraction& gl = application.GetGlAbstraction();
1977 TraceCallStack& textureTrace = gl.GetTextureTrace();
1978 textureTrace.Enable(true);
1980 tet_infoline( "Create visual with IMMEDIATE load policy" );
1981 VisualFactory factory = VisualFactory::Get();
1983 Property::Map propertyMap;
1984 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1985 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1986 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1987 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1988 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
1990 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1992 Property::Map resultMap;
1993 imageVisual.CreatePropertyMap( resultMap );
1994 DALI_TEST_CHECK( ! resultMap.Empty() );
1995 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
1997 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1999 // Ensure texture has been uploaded
2000 application.SendNotification();
2001 application.Render();
2003 tet_infoline( "Ensure texture loading starts after visual created" );
2004 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2005 textureTrace.Reset();
2007 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2008 DummyControl actor = DummyControl::New(true);
2009 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2010 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2011 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2013 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2014 application.GetScene().Add( actor );
2015 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2016 const unsigned int TIME_OUT_3_SECONDS = 3;
2017 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2019 application.SendNotification();
2020 application.Render();
2022 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2023 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2025 // Ensure texture is deleted when no longer needed (ref count was correct )
2026 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2028 application.SendNotification();
2029 application.Render();
2031 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2032 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2037 int UtcDaliImageVisualLoadPolicy02(void)
2039 ToolkitTestApplication application;
2040 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2042 // Set up trace debug
2043 TestGlAbstraction& gl = application.GetGlAbstraction();
2044 TraceCallStack& textureTrace = gl.GetTextureTrace();
2045 textureTrace.Enable(true);
2047 tet_infoline( "Create visual with IMMEDIATE load policy" );
2048 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2050 const unsigned int TIME_OUT_3_SECONDS = 3;
2051 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2053 // Act on meeage queue even although nothing expected to load
2054 application.SendNotification();
2055 application.Render();
2057 tet_infoline( "Ensure texture is not generated yet" );
2058 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2059 textureTrace.Reset();
2061 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2062 DummyControl actor = DummyControl::New(true);
2063 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2064 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2065 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2067 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2068 application.GetScene().Add( actor );
2069 tet_infoline( "Allow image time to load" );
2070 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2072 application.SendNotification();
2073 application.Render();
2075 tet_infoline( "Ensure texture generated and renderer created" );
2076 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2077 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2079 // Ensure texture is delete when no longer needed
2080 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2082 application.SendNotification();
2083 application.Render();
2085 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2086 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2091 int UtcDaliImageVisualLoadPolicy03(void)
2093 ToolkitTestApplication application;
2094 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2096 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2098 // Set up trace debug
2099 TestGlAbstraction& gl = application.GetGlAbstraction();
2100 TraceCallStack& textureTrace = gl.GetTextureTrace();
2101 textureTrace.Enable(true);
2103 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2104 DummyControl actor = DummyControl::New(true);
2105 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2106 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2107 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2109 tet_infoline( "Create visual with IMMEDIATE load policy" );
2110 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2112 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2113 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2114 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2116 tet_infoline( "Allow image time to load resource" );
2117 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2118 application.SendNotification();
2119 application.Render();
2121 // Ensure texture has been uploaded
2122 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2123 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2128 int UtcDaliImageVisualLoadPolicy04(void)
2130 ToolkitTestApplication application;
2131 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2132 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2134 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2136 // Set up trace debug
2137 TestGlAbstraction& gl = application.GetGlAbstraction();
2138 TraceCallStack& textureTrace = gl.GetTextureTrace();
2139 textureTrace.Enable(true);
2141 tet_infoline( "Create a control and connect to resource ready signal" );
2142 DummyControl actor = DummyControl::New(true);
2143 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2144 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2145 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2147 tet_infoline( "Create visual with IMMEDIATE load policy" );
2148 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2150 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2151 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2152 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2154 tet_infoline( "Allow image time to load" );
2155 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2156 application.SendNotification();
2157 application.Render();
2159 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2160 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2161 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2163 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2165 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2166 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2167 DummyControl actor2 = DummyControl::New(true);
2168 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2169 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2171 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2172 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2173 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2174 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2175 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2176 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2181 int UtcDaliImageVisualLoadPolicy05(void)
2183 ToolkitTestApplication application;
2184 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2185 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2186 // Set up trace debug
2187 TestGlAbstraction& gl = application.GetGlAbstraction();
2188 TraceCallStack& textureTrace = gl.GetTextureTrace();
2189 textureTrace.Enable(true);
2191 tet_infoline( "Create a control and connect to resource ready signal" );
2192 DummyControl actor = DummyControl::New(true);
2193 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2194 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2195 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2196 application.GetScene().Add( actor );
2198 tet_infoline( "Create visual with ATTACHED load policy" );
2199 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2201 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2202 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2203 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2205 tet_infoline( "Allow image time to load" );
2206 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2207 application.SendNotification();
2208 application.Render();
2210 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2211 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2212 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2214 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2216 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2217 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2218 DummyControl actor2 = DummyControl::New(true);
2219 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2220 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2222 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2223 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2224 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2225 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2226 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2227 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2233 int UtcDaliImageVisualOrientationCorrection(void)
2235 ToolkitTestApplication application;
2236 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2238 VisualFactory factory = VisualFactory::Get();
2239 tet_infoline( "Create visual with Orientation correction set OFF" );
2240 Property::Map propertyMap;
2241 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2242 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2243 propertyMap.Insert( "orientationCorrection", false );
2244 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2246 tet_infoline( "Create control for visual, need to loaded it" );
2247 DummyControl actor = DummyControl::New(true);
2248 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2249 application.GetScene().Add( actor );
2251 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2252 // Wait for image to load
2253 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2255 Vector2 originalImageSize;
2256 tet_infoline( "Get size of original visual to compare later with rotated image" );
2257 imageVisual.GetNaturalSize( originalImageSize );
2258 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2259 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2260 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2261 application.SendNotification();
2262 application.Render();
2264 tet_infoline( "Create visual with Orientation correction set ON " );
2265 propertyMap.Clear();
2266 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2267 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2268 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2269 imageVisual = factory.CreateVisual( propertyMap );
2271 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2272 // Wait for image to load
2273 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2275 Vector2 rotatedImageSize;
2276 imageVisual.GetNaturalSize( rotatedImageSize );
2277 tet_infoline( "Confirm that visual has rotated" );
2278 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2279 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2281 Property::Map resultMap;
2282 imageVisual.CreatePropertyMap( resultMap );
2284 // check the Property::ORIENTATION_CORRECTION value from the returned map
2285 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2286 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2291 int UtcDaliImageVisualCustomShader(void)
2293 ToolkitTestApplication application;
2294 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2296 VisualFactory factory = VisualFactory::Get();
2297 Property::Map properties;
2298 Property::Map shader;
2299 const std::string vertexShader = "Foobar";
2300 const std::string fragmentShader = "Foobar";
2301 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2302 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2304 properties[Visual::Property::TYPE] = Visual::IMAGE;
2305 properties[Visual::Property::SHADER] = shader;
2306 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2308 Visual::Base visual = factory.CreateVisual( properties );
2310 // trigger creation through setting on stage
2311 DummyControl dummy = DummyControl::New( true );
2312 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2313 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2315 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2316 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2317 application.GetScene().Add( dummy );
2319 application.SendNotification();
2320 application.Render();
2322 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2324 Renderer renderer = dummy.GetRendererAt( 0 );
2325 Shader shader2 = renderer.GetShader();
2326 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2327 Property::Map* map = value.GetMap();
2328 DALI_TEST_CHECK( map );
2330 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2331 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2333 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2334 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2338 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2339 properties[Visual::Property::SHADER] = shader;
2341 Visual::Base visual1 = factory.CreateVisual( properties );
2343 // trigger creation through setting on stage
2344 DummyControl dummy1 = DummyControl::New( true );
2345 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2346 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2347 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2348 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2349 application.GetScene().Add( dummy1 );
2351 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2352 glAbstraction.EnableEnableDisableCallTrace( true );
2354 application.SendNotification();
2355 application.Render();
2357 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2358 std::ostringstream blendStr;
2359 blendStr << GL_BLEND;
2360 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
2366 void ResourceReadyLoadNext( Control control )
2368 static int callNumber = 0;
2370 gResourceReadySignalFired = true;
2371 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2373 if( callNumber == 0 )
2375 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2377 tet_infoline( "Create visual with loaded image from within the signal handler" );
2378 VisualFactory factory = VisualFactory::Get();
2379 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2381 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2382 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2387 tet_infoline( "3rd signal called" );
2388 DALI_TEST_CHECK(true);
2392 int UtcDaliImageVisualLoadReady01(void)
2394 ToolkitTestApplication application;
2395 tet_infoline( "UtcDaliImageVisualLoadReady01");
2396 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2397 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2398 tet_infoline( "Should get a ready signal for all three visuals");
2402 tet_infoline( "Create a control and connect to resource ready signal" );
2403 DummyControl actor = DummyControl::New(true);
2404 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2405 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2406 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2407 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2408 application.GetScene().Add(actor);
2410 tet_infoline( "Create visual with IMMEDIATE load policy" );
2411 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2413 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2414 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2417 tet_infoline( "Allow image time to load" );
2418 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2419 application.SendNotification();
2420 application.Render();
2422 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2423 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2424 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2427 tet_infoline( "Original control correctly signalled, now testing failing image" );
2429 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2432 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2434 DummyControl actor2 = DummyControl::New(true);
2435 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2436 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2437 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2439 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2440 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2442 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2443 application.GetScene().Add(actor2);
2445 tet_infoline( "Wait for loading thread to finish");
2446 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2447 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2449 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2451 tet_infoline( "Check for 3rd signal");
2452 application.SendNotification();
2453 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2454 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);