2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
46 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
47 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
48 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
49 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
50 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
51 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
52 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
53 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
56 bool gResourceReadySignalFired = false;
57 std::vector<int> gReadyIds = {};
58 void ResourceReadySignal( Control control )
60 gResourceReadySignalFired = true;
61 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
68 Actor CreateActorWithImageVisual(const Property::Map& map)
70 VisualFactory factory = VisualFactory::Get();
71 DummyControl actor = DummyControl::New();
72 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
73 Visual::Base visual = factory.CreateVisual( map );
74 DALI_TEST_CHECK( visual );
75 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
76 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
77 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
82 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
84 VisualFactory factory = VisualFactory::Get();
86 Property::Map propertyMap;
87 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
88 propertyMap.Insert( ImageVisual::Property::URL, url );
89 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
90 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
91 propertyMap.Insert( key , value );
93 return factory.CreateVisual( propertyMap );
98 void TestVisualRender( ToolkitTestApplication& application,
100 Visual::Base& visual,
101 std::size_t expectedSamplers = 0,
102 ImageDimensions imageDimensions = ImageDimensions(),
103 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
105 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
106 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
110 // set the image size, for test case, this needs to be set before loading started
111 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
114 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
115 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
117 application.GetScene().Add( actor );
119 application.SendNotification(); // Send messages to update
120 application.Render(); // process update and render
121 application.SendNotification(); // process any signals to event
125 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
128 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
131 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
134 visual.CreatePropertyMap(map);
135 Property::Value* value = map.Find( mixColorIndex );
136 DALI_TEST_CHECK( value );
138 DALI_TEST_CHECK( value->Get( mixColor1 ) );
139 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
141 value = map.Find( Visual::Property::MIX_COLOR );
142 DALI_TEST_CHECK( value );
144 DALI_TEST_CHECK( value->Get( mixColor2 ) );
145 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
147 value = map.Find( Visual::Property::OPACITY );
148 DALI_TEST_CHECK( value );
150 DALI_TEST_CHECK( value->Get( opacity ) );
151 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
156 int UtcDaliImageVisualPropertyMap(void)
158 ToolkitTestApplication application;
159 tet_infoline( "Request image visual with a Property::Map" );
161 VisualFactory factory = VisualFactory::Get();
162 DALI_TEST_CHECK( factory );
163 factory.SetPreMultiplyOnLoad( true );
165 Property::Map propertyMap;
166 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
167 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
169 Visual::Base visual = factory.CreateVisual( propertyMap );
170 DALI_TEST_CHECK( visual );
172 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
173 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
175 TestGlAbstraction& gl = application.GetGlAbstraction();
176 TraceCallStack& textureTrace = gl.GetTextureTrace();
177 textureTrace.Enable(true);
179 DummyControl actor = DummyControl::New();
180 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
181 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
183 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
184 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
186 application.GetScene().Add( actor );
187 application.SendNotification();
188 application.Render();
190 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
192 application.SendNotification();
193 application.Render();
195 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
196 auto renderer = actor.GetRendererAt(0);
197 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
198 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
199 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
200 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
201 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
202 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
203 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
205 application.GetScene().Remove( actor );
206 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
212 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
214 ToolkitTestApplication application;
215 tet_infoline( "Request image visual without pre-multiplied alpha" );
217 VisualFactory factory = VisualFactory::Get();
218 DALI_TEST_CHECK( factory );
219 factory.SetPreMultiplyOnLoad( false );
221 Property::Map propertyMap;
222 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
223 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
225 Visual::Base visual = factory.CreateVisual( propertyMap );
226 DALI_TEST_CHECK( visual );
228 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
229 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
231 TestGlAbstraction& gl = application.GetGlAbstraction();
232 TraceCallStack& textureTrace = gl.GetTextureTrace();
233 textureTrace.Enable(true);
235 DummyControl actor = DummyControl::New();
236 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
237 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
239 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
240 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
242 application.GetScene().Add( actor );
243 application.SendNotification();
244 application.Render();
246 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
248 application.SendNotification();
249 application.Render();
251 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
252 auto renderer = actor.GetRendererAt(0);
253 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
254 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
255 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
256 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
258 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
259 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
261 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
263 application.GetScene().Remove( actor );
264 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
270 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
272 ToolkitTestApplication application;
273 tet_infoline( "Request image visual with no alpha channel" );
275 VisualFactory factory = VisualFactory::Get();
276 DALI_TEST_CHECK( factory );
278 Property::Map propertyMap;
279 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
280 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
282 Visual::Base visual = factory.CreateVisual( propertyMap );
283 DALI_TEST_CHECK( visual );
285 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
286 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
288 TestGlAbstraction& gl = application.GetGlAbstraction();
289 TraceCallStack& textureTrace = gl.GetTextureTrace();
290 textureTrace.Enable(true);
292 DummyControl actor = DummyControl::New();
293 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
294 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
296 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
297 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
299 application.GetScene().Add( actor );
300 application.SendNotification();
301 application.Render();
303 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
305 application.SendNotification();
306 application.Render();
308 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
309 auto renderer = actor.GetRendererAt(0);
310 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
311 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
312 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
313 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
315 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
316 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
318 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
320 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
321 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
322 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
323 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
324 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
325 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
326 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
327 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
329 textureTrace.Reset();
331 // Make a new visual with the same image
332 Visual::Base newVisual = factory.CreateVisual( propertyMap );
333 DALI_TEST_CHECK( newVisual );
335 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
336 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
338 DummyControl newActor = DummyControl::New();
339 DummyControlImpl& newDummyImpl = static_cast< DummyControlImpl& >( newActor.GetImplementation() );
340 newDummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual );
342 newActor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
343 DALI_TEST_EQUALS( newActor.GetRendererCount(), 0u, TEST_LOCATION );
345 application.GetScene().Add( newActor );
347 application.SendNotification();
348 application.Render();
350 DALI_TEST_EQUALS( newActor.GetRendererCount(), 1u, TEST_LOCATION );
351 auto newRenderer = newActor.GetRendererAt( 0 );
352 preMultipliedIndex = newRenderer.GetPropertyIndex( "preMultipliedAlpha" );
353 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
354 preMultipliedAlpha = newRenderer.GetProperty< bool >( preMultipliedIndex );
355 preMultipliedAlpha2 = newRenderer.GetProperty< bool >( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
357 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
358 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
360 srcFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
361 destFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
362 srcFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
363 destFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
364 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
365 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
366 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
367 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
369 application.GetScene().Remove( actor );
370 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
376 int UtcDaliImageVisualRemoteImageLoad(void)
378 ToolkitTestApplication application;
379 tet_infoline( "Request remote image visual with a Property::Map" );
381 VisualFactory factory = VisualFactory::Get();
382 DALI_TEST_CHECK( factory );
384 Property::Map propertyMap;
385 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
386 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
388 Visual::Base visual = factory.CreateVisual( propertyMap );
389 DALI_TEST_CHECK( visual );
391 TestGlAbstraction& gl = application.GetGlAbstraction();
392 TraceCallStack& textureTrace = gl.GetTextureTrace();
393 textureTrace.Enable(true);
395 DummyControl actor = DummyControl::New();
396 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
397 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
399 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
400 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
402 application.GetScene().Add( actor );
403 application.SendNotification();
405 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
407 application.SendNotification();
408 application.Render();
410 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
411 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
413 application.GetScene().Remove( actor );
414 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
419 int UtcDaliImageVisualTextureReuse1(void)
421 ToolkitTestApplication application;
422 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
424 Property::Map propertyMap;
425 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
426 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
427 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
429 TestGlAbstraction& gl = application.GetGlAbstraction();
430 TraceCallStack& textureTrace = gl.GetTextureTrace();
431 textureTrace.Enable(true);
432 TraceCallStack& drawTrace = gl.GetDrawTrace();
433 drawTrace.Enable(true);
435 Actor actor = CreateActorWithImageVisual( propertyMap );
436 application.GetScene().Add( actor );
437 application.SendNotification();
439 // Wait for image to load
440 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
442 application.SendNotification();
443 application.Render();
445 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
446 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
447 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
448 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
449 textureTrace.Reset();
452 Actor actor2 = CreateActorWithImageVisual( propertyMap );
453 application.GetScene().Add(actor2);
455 application.SendNotification(); // Send messages to update
456 application.Render(); // process update and render
457 application.SendNotification(); // process any signals to event
459 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
461 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
462 "draw calls use the same texture as the previous draw call\n" );
464 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
465 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
466 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
467 // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
469 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
471 application.GetScene().Remove( actor );
472 application.SendNotification();
473 application.Render();
475 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
476 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
478 tet_infoline("Test that removing last actor does delete the texture\n");
480 application.GetScene().Remove( actor2 ); // Detaches remaining ImageVisual
481 application.SendNotification();
482 application.Render();
484 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
485 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
491 int UtcDaliImageVisualTextureReuse2(void)
493 ToolkitTestApplication application;
494 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture" );
496 Property::Map propertyMap;
497 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
498 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
500 TestGlAbstraction& gl = application.GetGlAbstraction();
501 TraceCallStack& textureTrace = gl.GetTextureTrace();
502 textureTrace.Enable(true);
503 TraceCallStack& drawTrace = gl.GetDrawTrace();
504 drawTrace.Enable(true);
506 Actor actor = CreateActorWithImageVisual( propertyMap );
507 application.GetScene().Add( actor );
508 application.SendNotification();
510 // Wait for image to load
511 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
513 application.SendNotification();
514 application.Render();
516 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
517 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
518 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
519 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
520 textureTrace.Reset();
523 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
524 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
525 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
526 Actor actor2 = CreateActorWithImageVisual( propertyMap );
527 application.GetScene().Add(actor2);
529 application.SendNotification();
531 // Wait for image to load
532 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
534 application.SendNotification();
535 application.Render();
537 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
539 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
540 "renderers are using different textures\n" );
542 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
543 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
544 TraceCallStack::NamedParams tex1;
545 tex1["texture"] << 1;
546 TraceCallStack::NamedParams tex2;
547 tex2["texture"] << 2;
548 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
549 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
551 tet_infoline("Test that removing 1 actor deletes it's texture\n");
553 application.GetScene().Remove( actor );
554 application.SendNotification();
555 application.Render();
557 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
558 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
560 tet_infoline("Test that removing last actor deletes it's texture\n");
562 application.GetScene().Remove( actor2 );
563 application.SendNotification();
564 application.Render();
566 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
567 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
573 int UtcDaliImageVisualCustomWrapModePixelArea(void)
575 ToolkitTestApplication application;
576 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
578 static std::vector<UniformData> customUniforms =
580 UniformData("pixelArea", Property::Type::VECTOR4),
581 UniformData("wrapMode", Property::Type::VECTOR2),
584 TestGraphicsController& graphics = application.GetGraphicsController();
585 graphics.AddCustomUniforms(customUniforms);
587 VisualFactory factory = VisualFactory::Get();
588 DALI_TEST_CHECK( factory );
590 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
593 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
595 Property::Map propertyMap;
596 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
597 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
598 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
599 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
600 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
601 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
602 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
603 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
604 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
606 Visual::Base visual = factory.CreateVisual( propertyMap );
607 DALI_TEST_CHECK( visual );
609 TestGlAbstraction& gl = application.GetGlAbstraction();
610 TraceCallStack& textureTrace = gl.GetTextureTrace();
611 textureTrace.Enable(true);
612 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
613 texParameterTrace.Enable( true );
615 DummyControl actor = DummyControl::New();
616 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
617 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
618 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
619 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
620 application.GetScene().Add( actor );
623 application.SendNotification();
624 application.Render();
626 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
628 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
630 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
631 std::stringstream out;
632 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
633 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
635 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
636 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
638 // test the uniforms which used to handle the wrap mode
639 Renderer renderer = actor.GetRendererAt( 0u );
640 DALI_TEST_CHECK( renderer );
642 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
643 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
644 Vector4 pixelAreaUniform;
645 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
646 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
648 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
649 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
650 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
651 Vector2 wrapModeUniform;
652 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
653 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
656 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
661 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
663 ToolkitTestApplication application;
664 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
666 static std::vector<UniformData> customUniforms =
668 UniformData("pixelArea", Property::Type::VECTOR4),
671 TestGraphicsController& graphics = application.GetGraphicsController();
672 graphics.AddCustomUniforms(customUniforms);
674 VisualFactory factory = VisualFactory::Get();
675 DALI_TEST_CHECK( factory );
677 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
679 const int height=600;
680 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
682 Property::Map propertyMap;
683 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
684 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
685 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
686 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
687 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
688 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
689 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
690 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
692 Visual::Base visual = factory.CreateVisual( propertyMap );
693 DALI_TEST_CHECK( visual );
695 TestGlAbstraction& gl = application.GetGlAbstraction();
696 TraceCallStack& textureTrace = gl.GetTextureTrace();
697 textureTrace.Enable(true);
698 textureTrace.EnableLogging(true);
699 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
700 texParameterTrace.Enable( true );
701 texParameterTrace.EnableLogging( true );
703 DummyControl actor = DummyControl::New();
704 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
705 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
706 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
707 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
708 application.GetScene().Add( actor );
711 application.SendNotification();
712 application.Render();
713 application.SendNotification();
715 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
717 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
719 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
720 std::stringstream out;
721 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
722 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
724 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
725 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
727 // test the uniforms which used to handle the wrap mode
728 Renderer renderer = actor.GetRendererAt( 0u );
729 DALI_TEST_CHECK( renderer );
731 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
732 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
733 Vector4 pixelAreaUniform;
734 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
735 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
737 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
738 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
741 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
746 int UtcDaliImageVisualAnimateMixColor(void)
748 ToolkitTestApplication application;
749 tet_infoline( "Animate mix color" );
751 static std::vector<UniformData> customUniforms =
753 UniformData("mixColor", Property::Type::VECTOR3),
756 TestGraphicsController& graphics = application.GetGraphicsController();
757 graphics.AddCustomUniforms(customUniforms);
759 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
761 VisualFactory factory = VisualFactory::Get();
762 Property::Map propertyMap;
763 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
764 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
765 propertyMap.Insert("mixColor", Color::BLUE);
766 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
767 Visual::Base visual = factory.CreateVisual( propertyMap );
769 DummyControl actor = DummyControl::New(true);
770 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
771 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
773 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
774 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
775 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
776 application.GetScene().Add(actor);
778 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
780 Renderer renderer = actor.GetRendererAt(0);
781 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
782 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
783 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
785 tet_infoline("Test that the renderer has the mixColor property");
786 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
788 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
791 map["target"] = "testVisual";
792 map["property"] = "mixColor";
793 map["initialValue"] = Color::MAGENTA;
794 map["targetValue"] = TARGET_MIX_COLOR;
795 map["animator"] = Property::Map()
796 .Add("alphaFunction", "LINEAR")
797 .Add("timePeriod", Property::Map()
799 .Add("duration", 4.0f));
801 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
803 Animation animation = dummyImpl.CreateTransition( transition );
805 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
808 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
809 glAbstraction.EnableEnableDisableCallTrace( true );
810 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
811 std::ostringstream blendStr;
812 blendStr << std::hex << GL_BLEND;
814 application.SendNotification();
815 application.Render(0); // Ensure animation starts
816 application.Render(2000u); // Halfway point
817 Vector3 testColor( 1.0f, 0.0f, 0.5f );
819 // uColor.a should be actor's alpha * mixColor.a.
820 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
821 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
823 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
825 glEnableStack.Reset();
827 application.Render(2000u); // Halfway point between blue and white
829 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
830 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
831 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
833 // GL_BLEND should not be changed: Keep enabled
834 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
835 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
836 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
838 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
843 int UtcDaliImageVisualAnimateOpacity(void)
845 ToolkitTestApplication application;
846 tet_infoline( "Animate image visual opacity" );
848 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
850 VisualFactory factory = VisualFactory::Get();
851 Property::Map propertyMap;
852 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
853 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
854 propertyMap.Insert("opacity", 0.5f);
855 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
856 Visual::Base visual = factory.CreateVisual( propertyMap );
858 DummyControl actor = DummyControl::New(true);
859 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
860 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
862 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
863 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
864 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
865 application.GetScene().Add(actor);
867 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
869 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
870 glAbstraction.EnableEnableDisableCallTrace( true );
871 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
872 std::ostringstream blendStr;
873 blendStr << std::hex << GL_BLEND;
875 application.SendNotification();
876 application.Render();
878 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) );
881 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." );
884 map["target"] = "testVisual";
885 map["property"] = "opacity";
886 map["targetValue"] = 1.0f;
887 map["animator"] = Property::Map()
888 .Add("alphaFunction", "LINEAR")
889 .Add("timePeriod", Property::Map()
891 .Add("duration", 4.0f));
893 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
894 Animation animation = dummyImpl.CreateTransition( transition );
897 glEnableStack.Reset();
899 application.SendNotification();
900 application.Render(0); // Ensure animation starts
901 application.Render(2000u); // Halfway point through animation
902 application.SendNotification(); // Handle any signals
905 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
906 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
908 application.Render(2001u); // end
909 application.SendNotification(); // ensure animation finished signal is sent
911 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
912 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
914 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
915 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
916 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
921 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." );
924 map["target"] = "testVisual";
925 map["property"] = Visual::Property::OPACITY;
926 map["targetValue"] = 0.1f;
927 map["animator"] = Property::Map()
928 .Add("alphaFunction", "LINEAR")
929 .Add("timePeriod", Property::Map()
931 .Add("duration", 4.0f));
933 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
934 Animation animation = dummyImpl.CreateTransition( transition );
937 glEnableStack.Reset();
939 application.SendNotification();
940 application.Render(0); // Ensure animation starts
941 application.Render(2000u); // Halfway point
942 application.SendNotification();
945 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
946 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
948 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
950 glEnableStack.Reset();
952 application.Render(2016u); // end
953 application.SendNotification();
955 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
956 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
958 // GL_BLEND should not be changed: Keep enabled
960 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
961 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
962 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
970 int UtcDaliImageVisualAnimateOpacity02(void)
972 ToolkitTestApplication application;
973 tet_infoline( "Animate image visual opacity" );
975 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
977 VisualFactory factory = VisualFactory::Get();
978 Property::Map propertyMap;
979 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
980 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
981 propertyMap.Insert("opacity", 0.5f);
982 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
983 Visual::Base visual = factory.CreateVisual( propertyMap );
985 DummyControl actor = DummyControl::New(true);
986 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
987 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
989 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
990 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
991 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
993 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
995 Property::Array array;
998 map["target"] = "testVisual";
999 map["property"] = "opacity";
1000 map["initialValue"] = 0.0f;
1001 map["targetValue"] = 1.0f;
1002 map["animator"] = Property::Map()
1003 .Add("alphaFunction", "LINEAR")
1004 .Add("timePeriod", Property::Map()
1006 .Add("duration", 4.0f));
1009 map2["target"] = "testVisual";
1010 map2["property"] = "size";
1011 map2["targetValue"] = Vector2(1.0f, 1.0f);
1013 array.Add( map ).Add(map2);
1015 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1016 Animation animation = dummyImpl.CreateTransition( transition );
1018 application.GetScene().Add(actor);
1019 application.SendNotification();
1020 application.Render(0); // Ensure animation starts
1022 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1024 Renderer renderer = actor.GetRendererAt(0);
1025 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1026 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1028 animation = dummyImpl.CreateTransition( transition );
1031 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1032 glAbstraction.EnableEnableDisableCallTrace( true );
1033 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1034 std::ostringstream blendStr;
1035 blendStr << std::hex << GL_BLEND;
1037 application.SendNotification();
1038 application.Render(0); // Ensure animation starts
1039 application.Render(2000u); // Halfway point through animation
1040 application.SendNotification(); // Handle any signals
1042 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1045 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1046 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1048 glEnableStack.Reset();
1050 application.Render(2001u); // end
1051 application.SendNotification(); // ensure animation finished signal is sent
1053 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1054 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1056 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1063 int UtcDaliImageVisualAnimatePixelArea(void)
1065 ToolkitTestApplication application;
1066 tet_infoline( "ImageVisual animate pixel area" );
1068 static std::vector<UniformData> customUniforms =
1070 UniformData("pixelArea", Property::Type::VECTOR4),
1073 TestGraphicsController& graphics = application.GetGraphicsController();
1074 graphics.AddCustomUniforms(customUniforms);
1076 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1078 VisualFactory factory = VisualFactory::Get();
1079 Property::Map propertyMap;
1080 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1081 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1082 propertyMap.Insert("mixColor", Color::BLUE);
1083 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1084 Visual::Base visual = factory.CreateVisual( propertyMap );
1086 DummyControl actor = DummyControl::New(true);
1087 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1088 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1090 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1091 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1092 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1093 application.GetScene().Add(actor);
1095 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1097 Renderer renderer = actor.GetRendererAt(0);
1098 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1100 tet_infoline("Test that the renderer has the mixColor property");
1101 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1103 // TransitionData only takes string keys
1105 map["target"] = "testVisual";
1106 map["property"] = "pixelArea";
1107 map["initialValue"] = Vector4( 0,0,0,1 );
1108 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1109 map["animator"] = Property::Map()
1110 .Add("alphaFunction", "LINEAR")
1111 .Add("timePeriod", Property::Map()
1113 .Add("duration", 4.0f));
1115 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1117 Animation animation = dummyImpl.CreateTransition( transition );
1118 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1121 application.SendNotification();
1122 application.Render(0); // Ensure animation starts
1123 application.Render(2000u); // Halfway point
1125 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1127 application.Render(2000u); // End of animation
1129 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1134 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1136 ToolkitTestApplication application;
1137 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1139 Property::Map propertyMap;
1140 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1141 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1143 TestGlAbstraction& gl = application.GetGlAbstraction();
1144 TraceCallStack& textureTrace = gl.GetTextureTrace();
1145 textureTrace.Enable(true);
1146 TraceCallStack& drawTrace = gl.GetDrawTrace();
1147 drawTrace.Enable(true);
1149 Actor actor = CreateActorWithImageVisual( propertyMap );
1150 application.GetScene().Add( actor );
1151 application.SendNotification();
1153 application.GetScene().Remove( actor );
1154 application.SendNotification();
1156 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1157 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1158 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1159 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1164 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1166 ToolkitTestApplication application;
1167 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1169 VisualFactory factory = VisualFactory::Get();
1170 DALI_TEST_CHECK( factory );
1172 Property::Map propertyMap;
1173 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1174 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1176 Visual::Base visual = factory.CreateVisual( propertyMap );
1177 DALI_TEST_CHECK( visual );
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1180 TraceCallStack& textureTrace = gl.GetTextureTrace();
1181 textureTrace.Enable( true );
1182 TraceCallStack& drawTrace = gl.GetDrawTrace();
1183 drawTrace.Enable( true );
1185 DummyControl actor = DummyControl::New();
1186 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1187 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1189 application.GetScene().Add( actor );
1192 application.GetScene().Remove( actor );
1194 application.GetScene().Add( actor );
1196 // Create another visual with the same image
1197 visual = factory.CreateVisual( propertyMap );
1198 DALI_TEST_CHECK( visual );
1200 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1202 application.SendNotification();
1203 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1205 application.SendNotification();
1206 application.Render();
1208 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1209 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1210 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1211 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1216 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1218 ToolkitTestApplication application;
1219 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1221 VisualFactory factory = VisualFactory::Get();
1222 DALI_TEST_CHECK( factory );
1224 Property::Map propertyMap;
1225 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1226 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1228 Visual::Base visual = factory.CreateVisual( propertyMap );
1229 DALI_TEST_CHECK( visual );
1231 TestGlAbstraction& gl = application.GetGlAbstraction();
1232 TraceCallStack& textureTrace = gl.GetTextureTrace();
1233 textureTrace.Enable(true);
1235 DummyControl actor = DummyControl::New();
1236 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1237 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1239 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1240 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1242 application.GetScene().Add( actor );
1244 application.SendNotification();
1245 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
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 UtcDaliImageVisualSetInvalidSyncImage(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 Property::Map propertyMap;
1268 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1269 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1270 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
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 application.Render();
1291 // Check resource status
1292 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1293 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1295 // The broken image should be shown.
1296 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1297 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1299 application.GetScene().Remove( actor );
1300 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1305 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1307 ToolkitTestApplication application;
1308 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1310 VisualFactory factory = VisualFactory::Get();
1311 DALI_TEST_CHECK( factory );
1313 // Local invalid file, asynchronous loading
1314 Property::Map propertyMap;
1315 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1316 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1318 Visual::Base visual = factory.CreateVisual( propertyMap );
1319 DALI_TEST_CHECK( visual );
1321 TestGlAbstraction& gl = application.GetGlAbstraction();
1322 TraceCallStack& textureTrace = gl.GetTextureTrace();
1323 textureTrace.Enable(true);
1325 DummyControl actor = DummyControl::New();
1326 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1327 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1329 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1330 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1332 application.GetScene().Add( actor );
1334 application.SendNotification();
1335 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1337 application.SendNotification();
1338 application.Render();
1340 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1341 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1343 application.GetScene().Remove( actor );
1344 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1349 int UtcDaliImageVisualAlphaMask(void)
1351 ToolkitTestApplication application;
1352 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1354 VisualFactory factory = VisualFactory::Get();
1355 DALI_TEST_CHECK( factory );
1357 Property::Map propertyMap;
1358 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1359 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1360 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1362 Visual::Base visual = factory.CreateVisual( propertyMap );
1363 DALI_TEST_CHECK( visual );
1365 Property::Map testMap;
1366 visual.CreatePropertyMap(testMap);
1367 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1369 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1370 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1372 TestGlAbstraction& gl = application.GetGlAbstraction();
1373 TraceCallStack& textureTrace = gl.GetTextureTrace();
1374 textureTrace.Enable(true);
1376 DummyControl actor = DummyControl::New();
1377 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1378 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1380 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1381 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1382 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1384 application.GetScene().Add( actor );
1385 application.SendNotification();
1386 application.Render();
1388 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1390 application.SendNotification();
1391 application.Render();
1393 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1394 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1395 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1397 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1398 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1403 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1405 ToolkitTestApplication application;
1406 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1408 VisualFactory factory = VisualFactory::Get();
1409 DALI_TEST_CHECK( factory );
1411 Property::Map propertyMap;
1412 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1413 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1414 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1415 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1417 Visual::Base visual = factory.CreateVisual( propertyMap );
1418 DALI_TEST_CHECK( visual );
1420 Property::Map testMap;
1421 visual.CreatePropertyMap(testMap);
1422 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1424 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1425 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1427 TestGlAbstraction& gl = application.GetGlAbstraction();
1428 TraceCallStack& textureTrace = gl.GetTextureTrace();
1429 textureTrace.Enable(true);
1431 DummyControl actor = DummyControl::New();
1432 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1433 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1435 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1436 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1437 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1439 application.GetScene().Add( actor );
1441 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1443 application.SendNotification();
1444 application.Render();
1446 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1447 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1448 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1450 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1451 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1456 int UtcDaliImageVisualRemoteAlphaMask(void)
1458 ToolkitTestApplication application;
1459 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1461 VisualFactory factory = VisualFactory::Get();
1462 DALI_TEST_CHECK( factory );
1464 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1466 Property::Map propertyMap;
1467 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1468 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1469 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1471 Visual::Base visual = factory.CreateVisual( propertyMap );
1472 DALI_TEST_CHECK( visual );
1474 Property::Map testMap;
1475 visual.CreatePropertyMap(testMap);
1477 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1479 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1480 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1482 TestGlAbstraction& gl = application.GetGlAbstraction();
1483 TraceCallStack& textureTrace = gl.GetTextureTrace();
1484 textureTrace.Enable(true);
1486 DummyControl actor = DummyControl::New();
1487 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1488 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1490 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1492 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1493 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1495 application.GetScene().Add( actor );
1496 application.SendNotification();
1497 application.Render();
1499 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1501 application.SendNotification();
1502 application.Render();
1504 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1505 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1506 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1511 int UtcDaliImageVisualAlphaMaskCrop(void)
1513 ToolkitTestApplication application;
1514 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1516 VisualFactory factory = VisualFactory::Get();
1517 DALI_TEST_CHECK( factory );
1519 Property::Map propertyMap;
1520 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1521 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1522 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1523 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1524 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1526 Visual::Base visual = factory.CreateVisual( propertyMap );
1527 DALI_TEST_CHECK( visual );
1529 Property::Map testMap;
1530 visual.CreatePropertyMap(testMap);
1531 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1532 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1533 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1535 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1536 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1538 TestGlAbstraction& gl = application.GetGlAbstraction();
1539 TraceCallStack& textureTrace = gl.GetTextureTrace();
1540 textureTrace.Enable(true);
1542 DummyControl actor = DummyControl::New();
1543 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1544 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1546 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1547 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1548 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1550 application.GetScene().Add( actor );
1551 application.SendNotification();
1552 application.Render();
1554 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1556 application.SendNotification();
1557 application.Render();
1560 visual.GetNaturalSize(size);
1562 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1563 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1564 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1565 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1570 int UtcDaliImageVisualReleasePolicy01(void)
1572 ToolkitTestApplication application;
1573 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1575 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1576 DALI_TEST_CHECK( imageVisual );
1578 // Set up debug trace
1579 TestGlAbstraction& gl = application.GetGlAbstraction();
1580 TraceCallStack& textureTrace = gl.GetTextureTrace();
1581 textureTrace.Enable(true);
1583 tet_infoline( "Register visual with control and ensure it has the only handle" );
1584 DummyControl actor = DummyControl::New(true);
1585 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1586 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1587 imageVisual.Reset();
1589 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1591 application.SendNotification();
1592 application.Render(0);
1593 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1594 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1596 application.GetScene().Add( actor );
1598 // Wait for image to load
1599 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1601 application.SendNotification();
1602 application.Render(0);
1603 // Test renderer and texture created
1604 tet_infoline( "Confirm texture created" );
1605 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1606 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1608 tet_infoline( "Disable visual causing the texture to be deleted" );
1609 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1611 application.SendNotification();
1612 application.Render(0);
1613 // Test renderer and textures removed.
1614 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1615 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1620 int UtcDaliImageVisualReleasePolicy02(void)
1622 ToolkitTestApplication application;
1623 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1625 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1626 DALI_TEST_CHECK( imageVisual );
1628 // Setup debug trace
1629 TestGlAbstraction& gl = application.GetGlAbstraction();
1630 TraceCallStack& textureTrace = gl.GetTextureTrace();
1631 textureTrace.Enable(true);
1633 tet_infoline( "Register visual with control and ensure it has the only handle" );
1634 DummyControl actor = DummyControl::New(true);
1635 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1636 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1637 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1639 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1641 application.SendNotification();
1642 application.Render(0);
1643 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1644 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1646 application.GetScene().Add( actor );
1648 // Wait for image to load
1649 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1651 application.SendNotification();
1652 application.Render(0);
1653 // Test renderer and texture created
1654 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1655 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1658 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1659 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1660 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1661 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1662 application.SendNotification();
1663 application.Render();
1665 // Test texture removed after visual destroyed.
1666 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1667 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1672 int UtcDaliImageVisualReleasePolicy03(void)
1674 ToolkitTestApplication application;
1675 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1677 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1678 DALI_TEST_CHECK( imageVisual );
1680 TestGlAbstraction& gl = application.GetGlAbstraction();
1681 TraceCallStack& textureTrace = gl.GetTextureTrace();
1682 textureTrace.Enable(true);
1684 tet_infoline( "Register visual with control and ensure it has the only handle" );
1685 DummyControl actor = DummyControl::New(true);
1686 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1687 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1688 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1690 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1692 application.SendNotification();
1693 application.Render(0);
1694 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1695 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1697 application.GetScene().Add( actor );
1699 // Wait for image to load
1700 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1702 application.SendNotification();
1703 application.Render(0);
1704 // Test renderer and texture created
1705 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1706 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1708 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1709 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1710 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1711 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1712 application.SendNotification();
1713 application.Render();
1715 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1716 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1721 int UtcDaliImageVisualReleasePolicy04(void)
1723 ToolkitTestApplication application;
1724 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1726 tet_infoline( "Create first visual with Never release policy" );
1727 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1729 tet_infoline( "Create second visual with Destroyed release policy");
1730 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1732 // Set up trace debug
1733 TestGlAbstraction& gl = application.GetGlAbstraction();
1734 TraceCallStack& textureTrace = gl.GetTextureTrace();
1735 textureTrace.Enable(true);
1737 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1738 DummyControl actor = DummyControl::New(true);
1739 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1740 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1741 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1742 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1743 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1745 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1747 // Test initially zero renderers
1748 application.SendNotification();
1749 application.Render(0);
1750 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1751 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1753 application.GetScene().Add( actor );
1755 // Wait for image to load
1756 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1758 application.SendNotification();
1759 application.Render(0);
1760 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1761 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1762 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1764 // Test renderer removed when visual destroyed
1765 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1766 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1767 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1768 application.SendNotification();
1769 application.Render();
1771 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1772 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1774 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1775 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1776 application.SendNotification();
1777 application.Render();
1779 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1780 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1781 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1786 int UtcDaliImageVisualReleasePolicy05(void)
1788 ToolkitTestApplication application;
1789 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1791 VisualFactory factory = VisualFactory::Get();
1793 Property::Map propertyMapNeverReleasePolicy;
1794 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1795 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1796 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1797 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1798 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1800 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1802 Property::Map resultMap;
1803 imageVisualNever.CreatePropertyMap( resultMap );
1804 DALI_TEST_CHECK( ! resultMap.Empty() );
1806 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1811 int UtcDaliImageVisualReleasePolicy06(void)
1813 ToolkitTestApplication application;
1814 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1816 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1817 DALI_TEST_CHECK( imageVisual );
1819 TestGlAbstraction& gl = application.GetGlAbstraction();
1820 TraceCallStack& textureTrace = gl.GetTextureTrace();
1821 textureTrace.Enable(true);
1823 tet_infoline( "Register visual with control and ensure it has the only handle" );
1824 DummyControl actor = DummyControl::New(true);
1825 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1826 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1827 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1829 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1831 application.SendNotification();
1832 application.Render(0);
1833 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1834 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1836 application.GetScene().Add( actor );
1838 // Wait for image to load
1839 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1841 application.SendNotification();
1842 application.Render(0);
1843 // Test renderer and texture created
1844 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1845 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1846 textureTrace.Reset();
1848 tet_infoline( "Disable Visual and check texture not affected" );
1849 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1850 application.SendNotification();
1851 application.Render(0);
1852 tet_infoline( "Check renderer is destroyed when visual off stage" );
1853 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1854 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1855 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1856 textureTrace.Reset();
1858 tet_infoline( "Re-enable Visual and check texture not affected" );
1859 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1860 application.SendNotification();
1861 application.Render(0);
1862 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1863 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1864 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1865 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1870 int UtcDaliImageVisualReleasePolicy07(void)
1872 ToolkitTestApplication application;
1873 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1875 tet_infoline( "Create first visual with DESTROYED release policy" );
1876 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1879 tet_infoline( "Create second visual with DETACHED release policy");
1880 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1882 // Set up trace debug
1883 TestGlAbstraction& gl = application.GetGlAbstraction();
1884 TraceCallStack& textureTrace = gl.GetTextureTrace();
1885 textureTrace.Enable(true);
1887 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1888 DummyControl actor = DummyControl::New(true);
1889 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1890 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1891 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1892 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1893 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1895 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1897 // Test initially zero renderers
1898 application.SendNotification();
1899 application.Render(0);
1900 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1901 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1903 application.GetScene().Add( actor );
1905 // Wait for image to load
1906 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1908 application.SendNotification();
1909 application.Render(0);
1910 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1911 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1912 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1914 // Test renderer removed when visual destroyed
1915 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1916 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1917 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1918 application.SendNotification();
1919 application.Render();
1921 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1922 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1924 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1925 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1926 application.SendNotification();
1927 application.Render();
1929 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1930 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1935 int UtcDaliImageVisualReleasePolicy08(void)
1937 ToolkitTestApplication application;
1938 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
1940 tet_infoline( "Create first visual with DESTROYED release policy" );
1941 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1943 // Set up trace debug
1944 TestGlAbstraction& gl = application.GetGlAbstraction();
1945 TraceCallStack& textureTrace = gl.GetTextureTrace();
1946 textureTrace.Enable(true);
1948 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1949 DummyControl actor = DummyControl::New(true);
1950 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1951 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1952 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1954 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1956 // Test initially zero renderers
1957 application.SendNotification();
1958 application.Render(0);
1959 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1960 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1961 textureTrace.Reset();
1963 application.GetScene().Add( actor );
1965 // Wait for image to load
1966 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1968 application.SendNotification();
1969 application.Render(0);
1970 tet_infoline( "Ensure a texture is created" );
1971 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1972 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1973 textureTrace.Reset();
1975 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
1976 // 1. Get TextureSet
1977 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
1979 // 2.Remove actor from stage. In this case, renderer also is deleted.
1980 tet_infoline( "Remove actor from stage" );
1981 application.GetScene().Remove( actor );
1982 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1983 application.SendNotification();
1984 application.Render();
1986 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
1987 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1988 textureTrace.Reset();
1990 // 3.Add actor in stage. In this case, renderer is created.
1991 tet_infoline( "Add actor in stage" );
1992 application.GetScene().Add( actor );
1993 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1994 application.SendNotification();
1995 application.Render();
1996 tet_infoline( "Ensure a texture is not created again" );
1997 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
1998 textureTrace.Reset();
2000 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2001 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
2002 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
2003 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
2004 textureSetBefore.Reset();
2005 textureSetAfter.Reset();
2007 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2008 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2009 application.SendNotification();
2010 application.Render();
2011 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2016 int UtcDaliImageVisualLoadPolicy01(void)
2018 ToolkitTestApplication application;
2019 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
2021 // Set up trace debug
2022 TestGlAbstraction& gl = application.GetGlAbstraction();
2023 TraceCallStack& textureTrace = gl.GetTextureTrace();
2024 textureTrace.Enable(true);
2026 tet_infoline( "Create visual with IMMEDIATE load policy" );
2027 VisualFactory factory = VisualFactory::Get();
2029 Property::Map propertyMap;
2030 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2031 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2032 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
2033 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
2034 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
2036 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2038 Property::Map resultMap;
2039 imageVisual.CreatePropertyMap( resultMap );
2040 DALI_TEST_CHECK( ! resultMap.Empty() );
2041 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
2043 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2045 // Ensure texture has been uploaded
2046 application.SendNotification();
2047 application.Render();
2049 tet_infoline( "Ensure texture loading starts after visual created" );
2050 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2051 textureTrace.Reset();
2053 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2054 DummyControl actor = DummyControl::New(true);
2055 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2056 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2057 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2059 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2060 application.GetScene().Add( actor );
2061 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2062 const unsigned int TIME_OUT_3_SECONDS = 3;
2063 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2065 application.SendNotification();
2066 application.Render();
2068 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2069 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2071 // Ensure texture is deleted when no longer needed (ref count was correct )
2072 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2074 application.SendNotification();
2075 application.Render();
2077 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2078 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2083 int UtcDaliImageVisualLoadPolicy02(void)
2085 ToolkitTestApplication application;
2086 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2088 // Set up trace debug
2089 TestGlAbstraction& gl = application.GetGlAbstraction();
2090 TraceCallStack& textureTrace = gl.GetTextureTrace();
2091 textureTrace.Enable(true);
2093 tet_infoline( "Create visual with IMMEDIATE load policy" );
2094 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2096 const unsigned int TIME_OUT_3_SECONDS = 3;
2097 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2099 // Act on meeage queue even although nothing expected to load
2100 application.SendNotification();
2101 application.Render();
2103 tet_infoline( "Ensure texture is not generated yet" );
2104 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2105 textureTrace.Reset();
2107 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2108 DummyControl actor = DummyControl::New(true);
2109 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2110 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2111 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2113 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2114 application.GetScene().Add( actor );
2115 tet_infoline( "Allow image time to load" );
2116 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2118 application.SendNotification();
2119 application.Render();
2121 tet_infoline( "Ensure texture generated and renderer created" );
2122 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2123 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2125 // Ensure texture is delete when no longer needed
2126 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2128 application.SendNotification();
2129 application.Render();
2131 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2132 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2137 int UtcDaliImageVisualLoadPolicy03(void)
2139 ToolkitTestApplication application;
2140 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2142 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2144 // Set up trace debug
2145 TestGlAbstraction& gl = application.GetGlAbstraction();
2146 TraceCallStack& textureTrace = gl.GetTextureTrace();
2147 textureTrace.Enable(true);
2149 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2150 DummyControl actor = DummyControl::New(true);
2151 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2152 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2153 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2155 tet_infoline( "Create visual with IMMEDIATE load policy" );
2156 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2158 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2159 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2160 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2162 tet_infoline( "Allow image time to load resource" );
2163 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2164 application.SendNotification();
2165 application.Render();
2167 // Ensure texture has been uploaded
2168 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2169 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2174 int UtcDaliImageVisualLoadPolicy04(void)
2176 ToolkitTestApplication application;
2177 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2178 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2180 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2182 // Set up trace debug
2183 TestGlAbstraction& gl = application.GetGlAbstraction();
2184 TraceCallStack& textureTrace = gl.GetTextureTrace();
2185 textureTrace.Enable(true);
2187 tet_infoline( "Create a control and connect to resource ready signal" );
2188 DummyControl actor = DummyControl::New(true);
2189 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2190 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2191 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2193 tet_infoline( "Create visual with IMMEDIATE load policy" );
2194 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2196 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2197 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2198 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2200 tet_infoline( "Allow image time to load" );
2201 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2202 application.SendNotification();
2203 application.Render();
2205 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2206 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2207 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2209 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2211 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2212 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2213 DummyControl actor2 = DummyControl::New(true);
2214 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2215 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2217 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2218 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2219 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2220 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2221 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2222 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2227 int UtcDaliImageVisualLoadPolicy05(void)
2229 ToolkitTestApplication application;
2230 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2231 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2232 // Set up trace debug
2233 TestGlAbstraction& gl = application.GetGlAbstraction();
2234 TraceCallStack& textureTrace = gl.GetTextureTrace();
2235 textureTrace.Enable(true);
2237 tet_infoline( "Create a control and connect to resource ready signal" );
2238 DummyControl actor = DummyControl::New(true);
2239 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2240 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2241 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2242 application.GetScene().Add( actor );
2244 tet_infoline( "Create visual with ATTACHED load policy" );
2245 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2247 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2248 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2249 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2251 tet_infoline( "Allow image time to load" );
2252 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2253 application.SendNotification();
2254 application.Render();
2256 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2257 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2258 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2260 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2262 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2263 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2264 DummyControl actor2 = DummyControl::New(true);
2265 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2266 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2268 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2269 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2270 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2271 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2272 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2273 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2279 int UtcDaliImageVisualOrientationCorrection(void)
2281 ToolkitTestApplication application;
2282 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2284 VisualFactory factory = VisualFactory::Get();
2285 tet_infoline( "Create visual with Orientation correction set OFF" );
2286 Property::Map propertyMap;
2287 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2288 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2289 propertyMap.Insert( "orientationCorrection", false );
2290 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2292 tet_infoline( "Create control for visual, need to loaded it" );
2293 DummyControl actor = DummyControl::New(true);
2294 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2295 application.GetScene().Add( actor );
2297 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2298 // Wait for image to load
2299 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2301 Vector2 originalImageSize;
2302 tet_infoline( "Get size of original visual to compare later with rotated image" );
2303 imageVisual.GetNaturalSize( originalImageSize );
2304 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2305 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2306 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2307 application.SendNotification();
2308 application.Render();
2310 tet_infoline( "Create visual with Orientation correction set ON " );
2311 propertyMap.Clear();
2312 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2313 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2314 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2315 imageVisual = factory.CreateVisual( propertyMap );
2317 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2318 // Wait for image to load
2319 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2321 Vector2 rotatedImageSize;
2322 imageVisual.GetNaturalSize( rotatedImageSize );
2323 tet_infoline( "Confirm that visual has rotated" );
2324 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2325 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2327 Property::Map resultMap;
2328 imageVisual.CreatePropertyMap( resultMap );
2330 // check the Property::ORIENTATION_CORRECTION value from the returned map
2331 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2332 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2337 int UtcDaliImageVisualCustomShader(void)
2339 ToolkitTestApplication application;
2340 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2342 VisualFactory factory = VisualFactory::Get();
2343 Property::Map properties;
2344 Property::Map shader;
2345 const std::string vertexShader = "Foobar";
2346 const std::string fragmentShader = "Foobar";
2347 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2348 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2350 properties[Visual::Property::TYPE] = Visual::IMAGE;
2351 properties[Visual::Property::SHADER] = shader;
2352 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2354 Visual::Base visual = factory.CreateVisual( properties );
2356 // trigger creation through setting on stage
2357 DummyControl dummy = DummyControl::New( true );
2358 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2359 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2361 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2362 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2363 application.GetScene().Add( dummy );
2365 application.SendNotification();
2366 application.Render();
2368 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2370 Renderer renderer = dummy.GetRendererAt( 0 );
2371 Shader shader2 = renderer.GetShader();
2372 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2373 Property::Map* map = value.GetMap();
2374 DALI_TEST_CHECK( map );
2376 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2377 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2379 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2380 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2384 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2385 properties[Visual::Property::SHADER] = shader;
2387 Visual::Base visual1 = factory.CreateVisual( properties );
2389 // trigger creation through setting on stage
2390 DummyControl dummy1 = DummyControl::New( true );
2391 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2392 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2393 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2394 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2395 application.GetScene().Add( dummy1 );
2397 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2398 glAbstraction.EnableEnableDisableCallTrace( true );
2400 application.SendNotification();
2401 application.Render();
2403 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2404 std::ostringstream blendStr;
2405 blendStr << std::hex << GL_BLEND;
2406 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
2412 void ResourceReadyLoadNext( Control control )
2414 static int callNumber = 0;
2416 gResourceReadySignalFired = true;
2417 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2419 if( callNumber == 0 )
2421 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2423 tet_infoline( "Create visual with loaded image from within the signal handler" );
2424 VisualFactory factory = VisualFactory::Get();
2425 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2427 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2428 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2433 tet_infoline( "3rd signal called" );
2434 DALI_TEST_CHECK(true);
2438 int UtcDaliImageVisualLoadReady01(void)
2440 ToolkitTestApplication application;
2441 tet_infoline( "UtcDaliImageVisualLoadReady01");
2442 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2443 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2444 tet_infoline( "Should get a ready signal for all three visuals");
2448 tet_infoline( "Create a control and connect to resource ready signal" );
2449 DummyControl actor = DummyControl::New(true);
2450 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2451 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2452 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2453 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2454 application.GetScene().Add(actor);
2456 tet_infoline( "Create visual with IMMEDIATE load policy" );
2457 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2459 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2460 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2463 tet_infoline( "Allow image time to load" );
2464 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2465 application.SendNotification();
2466 application.Render();
2468 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2469 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2470 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2473 tet_infoline( "Original control correctly signalled, now testing failing image" );
2475 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2478 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2480 DummyControl actor2 = DummyControl::New(true);
2481 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2482 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2483 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2485 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2486 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2488 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2489 application.GetScene().Add(actor2);
2491 tet_infoline( "Wait for loading thread to finish");
2492 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2493 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2495 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2497 tet_infoline( "Check for 3rd signal");
2498 application.SendNotification();
2499 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2500 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);