2 * Copyright (c) 2019 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/devel-api/object/handle-devel.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include "dummy-control.h"
32 using namespace Dali::Toolkit;
34 void dali_image_visual_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_image_visual_cleanup(void)
41 test_return_value = TET_PASS;
46 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
47 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
48 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
49 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
50 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
51 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
52 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
53 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
54 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
57 bool gResourceReadySignalFired = false;
58 std::vector<int> gReadyIds = {};
59 void ResourceReadySignal( Control control )
61 gResourceReadySignalFired = true;
62 gReadyIds.push_back(control.GetId());
69 Actor CreateActorWithImageVisual(const Property::Map& map)
71 VisualFactory factory = VisualFactory::Get();
72 DummyControl actor = DummyControl::New();
73 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
74 Visual::Base visual = factory.CreateVisual( map );
75 DALI_TEST_CHECK( visual );
76 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
77 actor.SetSize( 200.f, 200.f );
78 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
83 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
85 VisualFactory factory = VisualFactory::Get();
87 Property::Map propertyMap;
88 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
89 propertyMap.Insert( ImageVisual::Property::URL, url );
90 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
91 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
92 propertyMap.Insert( key , value );
94 return factory.CreateVisual( propertyMap );
99 void TestVisualRender( ToolkitTestApplication& application,
101 Visual::Base& visual,
102 std::size_t expectedSamplers = 0,
103 ImageDimensions imageDimensions = ImageDimensions(),
104 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
106 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
107 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
111 // set the image size, for test case, this needs to be set before loading started
112 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
115 actor.SetSize( 200.f, 200.f );
116 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
118 Stage::GetCurrent().Add( actor );
120 application.SendNotification(); // Send messages to update
121 application.Render(); // process update and render
122 application.SendNotification(); // process any signals to event
126 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
129 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
132 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
135 visual.CreatePropertyMap(map);
136 Property::Value* value = map.Find( mixColorIndex );
137 DALI_TEST_CHECK( value );
139 DALI_TEST_CHECK( value->Get( mixColor1 ) );
140 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
142 value = map.Find( Visual::Property::MIX_COLOR );
143 DALI_TEST_CHECK( value );
145 DALI_TEST_CHECK( value->Get( mixColor2 ) );
146 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
148 value = map.Find( Visual::Property::OPACITY );
149 DALI_TEST_CHECK( value );
151 DALI_TEST_CHECK( value->Get( opacity ) );
152 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
157 int UtcDaliImageVisualPropertyMap(void)
159 ToolkitTestApplication application;
160 tet_infoline( "Request image visual with a Property::Map" );
162 VisualFactory factory = VisualFactory::Get();
163 DALI_TEST_CHECK( factory );
164 factory.SetPreMultiplyOnLoad( true );
166 Property::Map propertyMap;
167 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
168 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
170 Visual::Base visual = factory.CreateVisual( propertyMap );
171 DALI_TEST_CHECK( visual );
173 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
174 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
176 TestGlAbstraction& gl = application.GetGlAbstraction();
177 TraceCallStack& textureTrace = gl.GetTextureTrace();
178 textureTrace.Enable(true);
180 DummyControl actor = DummyControl::New();
181 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
182 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
184 actor.SetSize( 200.f, 200.f );
185 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
187 Stage::GetCurrent().Add( actor );
188 application.SendNotification();
189 application.Render();
191 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
193 application.SendNotification();
194 application.Render();
196 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
197 auto renderer = actor.GetRendererAt(0);
198 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
199 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
200 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
201 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
202 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
203 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
204 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
206 Stage::GetCurrent().Remove( actor );
207 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
213 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
215 ToolkitTestApplication application;
216 tet_infoline( "Request image visual without pre-multiplied alpha" );
218 VisualFactory factory = VisualFactory::Get();
219 DALI_TEST_CHECK( factory );
220 factory.SetPreMultiplyOnLoad( false );
222 Property::Map propertyMap;
223 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
224 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
226 Visual::Base visual = factory.CreateVisual( propertyMap );
227 DALI_TEST_CHECK( visual );
229 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
230 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
232 TestGlAbstraction& gl = application.GetGlAbstraction();
233 TraceCallStack& textureTrace = gl.GetTextureTrace();
234 textureTrace.Enable(true);
236 DummyControl actor = DummyControl::New();
237 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
238 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
240 actor.SetSize( 200.f, 200.f );
241 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
243 Stage::GetCurrent().Add( actor );
244 application.SendNotification();
245 application.Render();
247 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
249 application.SendNotification();
250 application.Render();
252 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
253 auto renderer = actor.GetRendererAt(0);
254 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
255 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
256 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
257 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
259 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
260 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
262 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
264 Stage::GetCurrent().Remove( actor );
265 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
271 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
273 ToolkitTestApplication application;
274 tet_infoline( "Request image visual with no alpha channel" );
276 VisualFactory factory = VisualFactory::Get();
277 DALI_TEST_CHECK( factory );
279 Property::Map propertyMap;
280 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
281 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
283 Visual::Base visual = factory.CreateVisual( propertyMap );
284 DALI_TEST_CHECK( visual );
286 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
287 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
289 TestGlAbstraction& gl = application.GetGlAbstraction();
290 TraceCallStack& textureTrace = gl.GetTextureTrace();
291 textureTrace.Enable(true);
293 DummyControl actor = DummyControl::New();
294 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
295 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
297 actor.SetSize( 200.f, 200.f );
298 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
300 Stage::GetCurrent().Add( actor );
301 application.SendNotification();
302 application.Render();
304 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
310 auto renderer = actor.GetRendererAt(0);
311 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
312 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
313 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
314 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
316 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
317 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
319 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
321 Stage::GetCurrent().Remove( actor );
322 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
328 int UtcDaliImageVisualRemoteImageLoad(void)
330 ToolkitTestApplication application;
331 tet_infoline( "Request remote image visual with a Property::Map" );
333 VisualFactory factory = VisualFactory::Get();
334 DALI_TEST_CHECK( factory );
336 Property::Map propertyMap;
337 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
338 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
340 Visual::Base visual = factory.CreateVisual( propertyMap );
341 DALI_TEST_CHECK( visual );
343 TestGlAbstraction& gl = application.GetGlAbstraction();
344 TraceCallStack& textureTrace = gl.GetTextureTrace();
345 textureTrace.Enable(true);
347 DummyControl actor = DummyControl::New();
348 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
349 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
351 actor.SetSize( 200.f, 200.f );
352 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
354 Stage::GetCurrent().Add( actor );
355 application.SendNotification();
357 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
359 application.SendNotification();
360 application.Render();
362 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
363 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
365 Stage::GetCurrent().Remove( actor );
366 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
371 int UtcDaliImageVisualTextureReuse1(void)
373 ToolkitTestApplication application;
374 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
376 Property::Map propertyMap;
377 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
378 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
379 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
381 TestGlAbstraction& gl = application.GetGlAbstraction();
382 TraceCallStack& textureTrace = gl.GetTextureTrace();
383 textureTrace.Enable(true);
384 TraceCallStack& drawTrace = gl.GetDrawTrace();
385 drawTrace.Enable(true);
387 Actor actor = CreateActorWithImageVisual( propertyMap );
388 Stage::GetCurrent().Add( actor );
389 application.SendNotification();
391 // Wait for image to load
392 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
394 application.SendNotification();
395 application.Render();
397 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
398 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
399 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
400 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
401 textureTrace.Reset();
404 Actor actor2 = CreateActorWithImageVisual( propertyMap );
405 Stage::GetCurrent().Add(actor2);
407 application.SendNotification(); // Send messages to update
408 application.Render(); // process update and render
409 application.SendNotification(); // process any signals to event
411 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
413 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
414 "draw calls use the same texture as the previous draw call\n" );
416 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
417 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
418 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
420 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
422 Stage::GetCurrent().Remove( actor );
423 application.SendNotification();
424 application.Render();
426 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
427 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
429 tet_infoline("Test that removing last actor does delete the texture\n");
431 Stage::GetCurrent().Remove( actor2 ); // Detaches remaining ImageVisual
432 application.SendNotification();
433 application.Render();
435 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
436 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
442 int UtcDaliImageVisualTextureReuse2(void)
444 ToolkitTestApplication application;
445 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" );
447 Property::Map propertyMap;
448 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
449 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
451 TestGlAbstraction& gl = application.GetGlAbstraction();
452 TraceCallStack& textureTrace = gl.GetTextureTrace();
453 textureTrace.Enable(true);
454 TraceCallStack& drawTrace = gl.GetDrawTrace();
455 drawTrace.Enable(true);
457 Actor actor = CreateActorWithImageVisual( propertyMap );
458 Stage::GetCurrent().Add( actor );
459 application.SendNotification();
461 // Wait for image to load
462 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
464 application.SendNotification();
465 application.Render();
467 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
468 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
469 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
470 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
471 textureTrace.Reset();
474 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
475 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
476 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
477 Actor actor2 = CreateActorWithImageVisual( propertyMap );
478 Stage::GetCurrent().Add(actor2);
480 application.SendNotification();
482 // Wait for image to load
483 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
485 application.SendNotification();
486 application.Render();
488 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
490 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
491 "renderers are using different textures\n" );
493 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
494 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
495 TraceCallStack::NamedParams tex1;
496 tex1["texture"] = "1";
497 TraceCallStack::NamedParams tex2;
498 tex1["texture"] = "2";
499 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
500 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
502 tet_infoline("Test that removing 1 actor deletes it's texture\n");
504 Stage::GetCurrent().Remove( actor );
505 application.SendNotification();
506 application.Render();
508 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
509 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
511 tet_infoline("Test that removing last actor deletes it's texture\n");
513 Stage::GetCurrent().Remove( actor2 );
514 application.SendNotification();
515 application.Render();
517 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
518 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
524 int UtcDaliImageVisualImageHandle(void)
526 ToolkitTestApplication application;
527 tet_infoline( "Request image visual with an image handle" );
529 VisualFactory factory = VisualFactory::Get();
530 DALI_TEST_CHECK( factory );
532 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
533 Visual::Base visual = factory.CreateVisual( image );
535 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
536 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
539 const int height=513;
541 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
542 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
544 TestGlAbstraction& gl = application.GetGlAbstraction();
545 TraceCallStack& textureTrace = gl.GetTextureTrace();
546 textureTrace.Enable(true);
548 DummyControl actor = DummyControl::New();
549 TestVisualRender( application, actor, visual, 1u,
550 ImageDimensions(width, height),
551 Integration::ResourcePointer(bitmap) );
553 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
557 int UtcDaliImageVisualCustomWrapModePixelArea(void)
559 ToolkitTestApplication application;
560 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
562 VisualFactory factory = VisualFactory::Get();
563 DALI_TEST_CHECK( factory );
565 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
568 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
570 Property::Map propertyMap;
571 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
572 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
573 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
574 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
575 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
576 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
577 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
578 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
579 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
581 Visual::Base visual = factory.CreateVisual( propertyMap );
582 DALI_TEST_CHECK( visual );
584 TestGlAbstraction& gl = application.GetGlAbstraction();
585 TraceCallStack& textureTrace = gl.GetTextureTrace();
586 textureTrace.Enable(true);
587 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
588 texParameterTrace.Enable( true );
590 DummyControl actor = DummyControl::New();
591 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
592 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
593 actor.SetSize(2000, 2000);
594 actor.SetParentOrigin(ParentOrigin::CENTER);
595 Stage::GetCurrent().Add( actor );
598 application.SendNotification();
599 application.Render();
601 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
603 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
605 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
606 std::stringstream out;
607 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
608 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
610 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
611 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
613 // test the uniforms which used to handle the wrap mode
614 Renderer renderer = actor.GetRendererAt( 0u );
615 DALI_TEST_CHECK( renderer );
617 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
618 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
619 Vector4 pixelAreaUniform;
620 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
621 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
623 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
624 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
625 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
626 Vector2 wrapModeUniform;
627 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
628 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
631 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
636 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
638 ToolkitTestApplication application;
639 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
641 VisualFactory factory = VisualFactory::Get();
642 DALI_TEST_CHECK( factory );
644 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
646 const int height=600;
647 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
649 Property::Map propertyMap;
650 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
651 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
652 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
653 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
654 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
655 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
656 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
657 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
659 Visual::Base visual = factory.CreateVisual( propertyMap );
660 DALI_TEST_CHECK( visual );
662 TestGlAbstraction& gl = application.GetGlAbstraction();
663 TraceCallStack& textureTrace = gl.GetTextureTrace();
664 textureTrace.Enable(true);
665 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
666 texParameterTrace.Enable( true );
668 DummyControl actor = DummyControl::New();
669 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
670 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
671 actor.SetSize(2000, 2000);
672 actor.SetParentOrigin(ParentOrigin::CENTER);
673 Stage::GetCurrent().Add( actor );
676 application.SendNotification();
677 application.Render();
679 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
681 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
683 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
684 std::stringstream out;
685 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
686 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
688 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
689 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
691 // test the uniforms which used to handle the wrap mode
692 Renderer renderer = actor.GetRendererAt( 0u );
693 DALI_TEST_CHECK( renderer );
695 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
696 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
697 Vector4 pixelAreaUniform;
698 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
699 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
701 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
702 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
705 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
710 int UtcDaliImageVisualAnimateMixColor(void)
712 ToolkitTestApplication application;
713 tet_infoline( "Animate mix color" );
715 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
717 VisualFactory factory = VisualFactory::Get();
718 Property::Map propertyMap;
719 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
720 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
721 propertyMap.Insert("mixColor", Color::BLUE);
722 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
723 Visual::Base visual = factory.CreateVisual( propertyMap );
725 DummyControl actor = DummyControl::New(true);
726 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
727 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
729 actor.SetSize(2000, 2000);
730 actor.SetParentOrigin(ParentOrigin::CENTER);
731 actor.SetColor(Color::BLACK);
732 Stage::GetCurrent().Add(actor);
734 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
736 Renderer renderer = actor.GetRendererAt(0);
737 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
738 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
739 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
741 tet_infoline("Test that the renderer has the mixColor property");
742 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
744 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
747 map["target"] = "testVisual";
748 map["property"] = "mixColor";
749 map["initialValue"] = Color::MAGENTA;
750 map["targetValue"] = TARGET_MIX_COLOR;
751 map["animator"] = Property::Map()
752 .Add("alphaFunction", "LINEAR")
753 .Add("timePeriod", Property::Map()
755 .Add("duration", 4.0f));
757 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
759 Animation animation = dummyImpl.CreateTransition( transition );
761 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
762 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
764 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
767 application.SendNotification();
768 application.Render(0); // Ensure animation starts
769 application.Render(2000u); // Halfway point
770 Vector3 testColor( 1.0f, 0.0f, 0.5f );
772 // uColor.a should be actor's alpha * mixColor.a.
773 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
774 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
776 application.Render(2000u); // Halfway point between blue and white
778 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
779 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
780 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
782 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
784 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
785 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
790 int UtcDaliImageVisualAnimateOpacity(void)
792 ToolkitTestApplication application;
793 tet_infoline( "Animate image visual opacity" );
795 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
797 VisualFactory factory = VisualFactory::Get();
798 Property::Map propertyMap;
799 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
800 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
801 propertyMap.Insert("opacity", 0.5f);
802 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
803 Visual::Base visual = factory.CreateVisual( propertyMap );
805 DummyControl actor = DummyControl::New(true);
806 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
807 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
809 actor.SetSize(2000, 2000);
810 actor.SetParentOrigin(ParentOrigin::CENTER);
811 actor.SetColor(Color::BLACK);
812 Stage::GetCurrent().Add(actor);
814 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
816 Renderer renderer = actor.GetRendererAt(0);
817 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
818 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
821 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." );
824 map["target"] = "testVisual";
825 map["property"] = "opacity";
826 map["targetValue"] = 1.0f;
827 map["animator"] = Property::Map()
828 .Add("alphaFunction", "LINEAR")
829 .Add("timePeriod", Property::Map()
831 .Add("duration", 4.0f));
833 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
834 Animation animation = dummyImpl.CreateTransition( transition );
837 application.SendNotification();
838 application.Render(0); // Ensure animation starts
839 application.Render(2000u); // Halfway point through animation
840 application.SendNotification(); // Handle any signals
843 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
844 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
846 application.Render(2001u); // end
847 application.SendNotification(); // ensure animation finished signal is sent
849 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
850 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
852 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
853 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
858 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." );
861 map["target"] = "testVisual";
862 map["property"] = Visual::Property::OPACITY;
863 map["targetValue"] = 0.1f;
864 map["animator"] = Property::Map()
865 .Add("alphaFunction", "LINEAR")
866 .Add("timePeriod", Property::Map()
868 .Add("duration", 4.0f));
870 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
871 Animation animation = dummyImpl.CreateTransition( transition );
874 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
875 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
877 application.SendNotification();
878 application.Render(0); // Ensure animation starts
879 application.Render(2000u); // Halfway point
880 application.SendNotification();
883 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
884 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
886 application.Render(2016u); // end
887 application.SendNotification();
889 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
890 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
892 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
893 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
902 int UtcDaliImageVisualAnimateOpacity02(void)
904 ToolkitTestApplication application;
905 tet_infoline( "Animate image visual opacity" );
907 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
909 VisualFactory factory = VisualFactory::Get();
910 Property::Map propertyMap;
911 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
912 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
913 propertyMap.Insert("opacity", 0.5f);
914 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
915 Visual::Base visual = factory.CreateVisual( propertyMap );
917 DummyControl actor = DummyControl::New(true);
918 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
919 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
921 actor.SetSize(2000, 2000);
922 actor.SetParentOrigin(ParentOrigin::CENTER);
923 actor.SetColor(Color::BLACK);
925 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
927 Property::Array array;
930 map["target"] = "testVisual";
931 map["property"] = "opacity";
932 map["initialValue"] = 0.0f;
933 map["targetValue"] = 1.0f;
934 map["animator"] = Property::Map()
935 .Add("alphaFunction", "LINEAR")
936 .Add("timePeriod", Property::Map()
938 .Add("duration", 4.0f));
941 map2["target"] = "testVisual";
942 map2["property"] = "size";
943 map2["targetValue"] = Vector2(1.0f, 1.0f);
945 array.Add( map ).Add(map2);
947 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
948 Animation animation = dummyImpl.CreateTransition( transition );
950 Stage::GetCurrent().Add(actor);
951 application.SendNotification();
952 application.Render(0); // Ensure animation starts
954 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
956 Renderer renderer = actor.GetRendererAt(0);
957 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
958 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
960 animation = dummyImpl.CreateTransition( transition );
963 application.SendNotification();
964 application.Render(0); // Ensure animation starts
965 application.Render(2000u); // Halfway point through animation
966 application.SendNotification(); // Handle any signals
968 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
969 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
972 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
973 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
975 application.Render(2001u); // end
976 application.SendNotification(); // ensure animation finished signal is sent
978 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
979 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
981 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
982 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
989 int UtcDaliImageVisualAnimatePixelArea(void)
991 ToolkitTestApplication application;
992 tet_infoline( "ImageVisual animate pixel area" );
994 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
996 VisualFactory factory = VisualFactory::Get();
997 Property::Map propertyMap;
998 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
999 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1000 propertyMap.Insert("mixColor", Color::BLUE);
1001 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1002 Visual::Base visual = factory.CreateVisual( propertyMap );
1004 DummyControl actor = DummyControl::New(true);
1005 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1006 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1008 actor.SetSize(2000, 2000);
1009 actor.SetParentOrigin(ParentOrigin::CENTER);
1010 actor.SetColor(Color::BLACK);
1011 Stage::GetCurrent().Add(actor);
1013 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1015 Renderer renderer = actor.GetRendererAt(0);
1016 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
1018 tet_infoline("Test that the renderer has the mixColor property");
1019 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1021 // TransitionData only takes string keys
1023 map["target"] = "testVisual";
1024 map["property"] = "pixelArea";
1025 map["initialValue"] = Vector4( 0,0,0,1 );
1026 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1027 map["animator"] = Property::Map()
1028 .Add("alphaFunction", "LINEAR")
1029 .Add("timePeriod", Property::Map()
1031 .Add("duration", 4.0f));
1033 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1035 Animation animation = dummyImpl.CreateTransition( transition );
1036 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1039 application.SendNotification();
1040 application.Render(0); // Ensure animation starts
1041 application.Render(2000u); // Halfway point
1043 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1045 application.Render(2000u); // End of animation
1047 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1052 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1054 ToolkitTestApplication application;
1055 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1057 Property::Map propertyMap;
1058 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1059 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1061 TestGlAbstraction& gl = application.GetGlAbstraction();
1062 TraceCallStack& textureTrace = gl.GetTextureTrace();
1063 textureTrace.Enable(true);
1064 TraceCallStack& drawTrace = gl.GetDrawTrace();
1065 drawTrace.Enable(true);
1067 Actor actor = CreateActorWithImageVisual( propertyMap );
1068 Stage::GetCurrent().Add( actor );
1069 application.SendNotification();
1071 Stage::GetCurrent().Remove( actor );
1072 application.SendNotification();
1074 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1075 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1076 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1077 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1082 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1084 ToolkitTestApplication application;
1085 tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
1087 VisualFactory factory = VisualFactory::Get();
1088 DALI_TEST_CHECK( factory );
1090 Property::Map propertyMap;
1091 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1092 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1094 Visual::Base visual = factory.CreateVisual( propertyMap );
1095 DALI_TEST_CHECK( visual );
1097 TestGlAbstraction& gl = application.GetGlAbstraction();
1098 TraceCallStack& textureTrace = gl.GetTextureTrace();
1099 textureTrace.Enable( true );
1100 TraceCallStack& drawTrace = gl.GetDrawTrace();
1101 drawTrace.Enable( true );
1103 DummyControl actor = DummyControl::New();
1104 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1105 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1107 Stage::GetCurrent().Add( actor );
1110 Stage::GetCurrent().Remove( actor );
1112 Stage::GetCurrent().Add( actor );
1114 // Create another visual with the same image
1115 visual = factory.CreateVisual( propertyMap );
1116 DALI_TEST_CHECK( visual );
1118 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1120 application.SendNotification();
1121 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1123 application.SendNotification();
1124 application.Render();
1126 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1127 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1128 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1129 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1134 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1136 ToolkitTestApplication application;
1137 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1139 VisualFactory factory = VisualFactory::Get();
1140 DALI_TEST_CHECK( factory );
1142 Property::Map propertyMap;
1143 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1144 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1146 Visual::Base visual = factory.CreateVisual( propertyMap );
1147 DALI_TEST_CHECK( visual );
1149 TestGlAbstraction& gl = application.GetGlAbstraction();
1150 TraceCallStack& textureTrace = gl.GetTextureTrace();
1151 textureTrace.Enable(true);
1153 DummyControl actor = DummyControl::New();
1154 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1155 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1157 actor.SetSize( 200.f, 200.f );
1158 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1160 Stage::GetCurrent().Add( actor );
1162 application.SendNotification();
1163 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1165 application.SendNotification();
1166 application.Render();
1168 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1169 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1171 Stage::GetCurrent().Remove( actor );
1172 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1177 int UtcDaliImageVisualSetInvalidSyncImage(void)
1179 ToolkitTestApplication application;
1180 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1182 VisualFactory factory = VisualFactory::Get();
1183 DALI_TEST_CHECK( factory );
1185 Property::Map propertyMap;
1186 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1187 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1188 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1190 Visual::Base visual = factory.CreateVisual( propertyMap );
1191 DALI_TEST_CHECK( visual );
1193 TestGlAbstraction& gl = application.GetGlAbstraction();
1194 TraceCallStack& textureTrace = gl.GetTextureTrace();
1195 textureTrace.Enable(true);
1197 DummyControl actor = DummyControl::New();
1198 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1199 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1201 actor.SetSize( 200.f, 200.f );
1202 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1204 Stage::GetCurrent().Add( actor );
1206 application.SendNotification();
1207 application.Render();
1209 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1210 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1212 Stage::GetCurrent().Remove( actor );
1213 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1218 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1220 ToolkitTestApplication application;
1221 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1223 VisualFactory factory = VisualFactory::Get();
1224 DALI_TEST_CHECK( factory );
1226 // Local invalid file, asynchronous loading
1227 Property::Map propertyMap;
1228 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1229 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1231 Visual::Base visual = factory.CreateVisual( propertyMap );
1232 DALI_TEST_CHECK( visual );
1234 TestGlAbstraction& gl = application.GetGlAbstraction();
1235 TraceCallStack& textureTrace = gl.GetTextureTrace();
1236 textureTrace.Enable(true);
1238 DummyControl actor = DummyControl::New();
1239 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1240 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1242 actor.SetSize( 200.f, 200.f );
1243 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1245 Stage::GetCurrent().Add( actor );
1247 application.SendNotification();
1248 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1250 application.SendNotification();
1251 application.Render();
1253 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1254 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1256 Stage::GetCurrent().Remove( actor );
1257 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1262 int UtcDaliImageVisualAlphaMask(void)
1264 ToolkitTestApplication application;
1265 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1267 VisualFactory factory = VisualFactory::Get();
1268 DALI_TEST_CHECK( factory );
1270 Property::Map propertyMap;
1271 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1272 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1273 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1275 Visual::Base visual = factory.CreateVisual( propertyMap );
1276 DALI_TEST_CHECK( visual );
1278 Property::Map testMap;
1279 visual.CreatePropertyMap(testMap);
1280 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1282 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1283 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1285 TestGlAbstraction& gl = application.GetGlAbstraction();
1286 TraceCallStack& textureTrace = gl.GetTextureTrace();
1287 textureTrace.Enable(true);
1289 DummyControl actor = DummyControl::New();
1290 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1291 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1293 actor.SetSize( 200.f, 200.f );
1294 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1295 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1297 Stage::GetCurrent().Add( actor );
1298 application.SendNotification();
1299 application.Render();
1301 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1303 application.SendNotification();
1304 application.Render();
1306 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1307 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1308 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1310 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1311 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1316 int UtcDaliImageVisualRemoteAlphaMask(void)
1318 ToolkitTestApplication application;
1319 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1321 VisualFactory factory = VisualFactory::Get();
1322 DALI_TEST_CHECK( factory );
1324 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1326 Property::Map propertyMap;
1327 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1328 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1329 propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1331 Visual::Base visual = factory.CreateVisual( propertyMap );
1332 DALI_TEST_CHECK( visual );
1334 Property::Map testMap;
1335 visual.CreatePropertyMap(testMap);
1336 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1338 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1339 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1341 TestGlAbstraction& gl = application.GetGlAbstraction();
1342 TraceCallStack& textureTrace = gl.GetTextureTrace();
1343 textureTrace.Enable(true);
1345 DummyControl actor = DummyControl::New();
1346 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1347 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1348 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1350 actor.SetSize( 200.f, 200.f );
1351 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1353 Stage::GetCurrent().Add( actor );
1354 application.SendNotification();
1355 application.Render();
1357 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1359 application.SendNotification();
1360 application.Render();
1362 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1363 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1364 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1370 int UtcDaliImageVisualAlphaMaskCrop(void)
1372 ToolkitTestApplication application;
1373 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1375 VisualFactory factory = VisualFactory::Get();
1376 DALI_TEST_CHECK( factory );
1378 Property::Map propertyMap;
1379 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1380 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1381 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1382 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1383 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1385 Visual::Base visual = factory.CreateVisual( propertyMap );
1386 DALI_TEST_CHECK( visual );
1388 Property::Map testMap;
1389 visual.CreatePropertyMap(testMap);
1390 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1391 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1392 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1394 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1395 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1397 TestGlAbstraction& gl = application.GetGlAbstraction();
1398 TraceCallStack& textureTrace = gl.GetTextureTrace();
1399 textureTrace.Enable(true);
1401 DummyControl actor = DummyControl::New();
1402 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1403 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1405 actor.SetSize( 200.f, 200.f );
1406 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1407 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1409 Stage::GetCurrent().Add( actor );
1410 application.SendNotification();
1411 application.Render();
1413 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1415 application.SendNotification();
1416 application.Render();
1419 visual.GetNaturalSize(size);
1421 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1422 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1423 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1424 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1429 int UtcDaliImageVisualReleasePolicy01(void)
1431 ToolkitTestApplication application;
1432 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1434 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1435 DALI_TEST_CHECK( imageVisual );
1437 // Set up debug trace
1438 TestGlAbstraction& gl = application.GetGlAbstraction();
1439 TraceCallStack& textureTrace = gl.GetTextureTrace();
1440 textureTrace.Enable(true);
1442 tet_infoline( "Register visual with control and ensure it has the only handle" );
1443 DummyControl actor = DummyControl::New(true);
1444 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1445 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1446 imageVisual.Reset();
1448 actor.SetSize(200.f, 200.f);
1450 application.SendNotification();
1451 application.Render(0);
1452 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1453 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1455 Stage::GetCurrent().Add( actor );
1457 // Wait for image to load
1458 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1460 application.SendNotification();
1461 application.Render(0);
1462 // Test renderer and texture created
1463 tet_infoline( "Confirm texture created" );
1464 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1465 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1467 tet_infoline( "Disable visual causing the texture to be deleted" );
1468 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1470 application.SendNotification();
1471 application.Render(0);
1472 // Test renderer and textures removed.
1473 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1474 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1479 int UtcDaliImageVisualReleasePolicy02(void)
1481 ToolkitTestApplication application;
1482 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1484 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1485 DALI_TEST_CHECK( imageVisual );
1487 // Setup debug trace
1488 TestGlAbstraction& gl = application.GetGlAbstraction();
1489 TraceCallStack& textureTrace = gl.GetTextureTrace();
1490 textureTrace.Enable(true);
1492 tet_infoline( "Register visual with control and ensure it has the only handle" );
1493 DummyControl actor = DummyControl::New(true);
1494 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1495 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1496 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1498 actor.SetSize(200.f, 200.f);
1500 application.SendNotification();
1501 application.Render(0);
1502 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1503 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1505 Stage::GetCurrent().Add( actor );
1507 // Wait for image to load
1508 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1510 application.SendNotification();
1511 application.Render(0);
1512 // Test renderer and texture created
1513 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1514 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1517 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1518 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1519 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1520 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1521 application.SendNotification();
1522 application.Render();
1524 // Test texture removed after visual destroyed.
1525 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1526 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1531 int UtcDaliImageVisualReleasePolicy03(void)
1533 ToolkitTestApplication application;
1534 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1536 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1537 DALI_TEST_CHECK( imageVisual );
1539 TestGlAbstraction& gl = application.GetGlAbstraction();
1540 TraceCallStack& textureTrace = gl.GetTextureTrace();
1541 textureTrace.Enable(true);
1543 tet_infoline( "Register visual with control and ensure it has the only handle" );
1544 DummyControl actor = DummyControl::New(true);
1545 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1546 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1547 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1549 actor.SetSize(200.f, 200.f);
1551 application.SendNotification();
1552 application.Render(0);
1553 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1554 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1556 Stage::GetCurrent().Add( actor );
1558 // Wait for image to load
1559 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1561 application.SendNotification();
1562 application.Render(0);
1563 // Test renderer and texture created
1564 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1565 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1567 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1568 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1569 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1570 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1571 application.SendNotification();
1572 application.Render();
1574 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1575 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1580 int UtcDaliImageVisualReleasePolicy04(void)
1582 ToolkitTestApplication application;
1583 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1585 tet_infoline( "Create first visual with Never release policy" );
1586 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1588 tet_infoline( "Create second visual with Destroyed release policy");
1589 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1591 // Set up trace debug
1592 TestGlAbstraction& gl = application.GetGlAbstraction();
1593 TraceCallStack& textureTrace = gl.GetTextureTrace();
1594 textureTrace.Enable(true);
1596 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1597 DummyControl actor = DummyControl::New(true);
1598 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1599 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1600 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1601 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1602 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1604 actor.SetSize(200.f, 200.f);
1606 // Test initially zero renderers
1607 application.SendNotification();
1608 application.Render(0);
1609 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1610 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1612 Stage::GetCurrent().Add( actor );
1614 // Wait for image to load
1615 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1617 application.SendNotification();
1618 application.Render(0);
1619 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1620 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1621 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1623 // Test renderer removed when visual destroyed
1624 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1625 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1626 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1627 application.SendNotification();
1628 application.Render();
1630 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1631 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1633 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1634 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1635 application.SendNotification();
1636 application.Render();
1638 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1639 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1640 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1645 int UtcDaliImageVisualReleasePolicy05(void)
1647 ToolkitTestApplication application;
1648 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1650 VisualFactory factory = VisualFactory::Get();
1652 Property::Map propertyMapNeverReleasePolicy;
1653 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1654 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1655 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1656 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1657 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1659 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1661 Property::Map resultMap;
1662 imageVisualNever.CreatePropertyMap( resultMap );
1663 DALI_TEST_CHECK( ! resultMap.Empty() );
1665 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1670 int UtcDaliImageVisualReleasePolicy06(void)
1672 ToolkitTestApplication application;
1673 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1675 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1676 DALI_TEST_CHECK( imageVisual );
1678 TestGlAbstraction& gl = application.GetGlAbstraction();
1679 TraceCallStack& textureTrace = gl.GetTextureTrace();
1680 textureTrace.Enable(true);
1682 tet_infoline( "Register visual with control and ensure it has the only handle" );
1683 DummyControl actor = DummyControl::New(true);
1684 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1685 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1686 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1688 actor.SetSize(200.f, 200.f);
1690 application.SendNotification();
1691 application.Render(0);
1692 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1693 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1695 Stage::GetCurrent().Add( actor );
1697 // Wait for image to load
1698 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1700 application.SendNotification();
1701 application.Render(0);
1702 // Test renderer and texture created
1703 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1704 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1705 textureTrace.Reset();
1707 tet_infoline( "Disable Visual and check texture not affected" );
1708 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1709 application.SendNotification();
1710 application.Render(0);
1711 tet_infoline( "Check renderer is destroyed when visual off stage" );
1712 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1713 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1714 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1715 textureTrace.Reset();
1717 tet_infoline( "Re-enable Visual and check texture not affected" );
1718 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1719 application.SendNotification();
1720 application.Render(0);
1721 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1722 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1723 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1724 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1729 int UtcDaliImageVisualReleasePolicy07(void)
1731 ToolkitTestApplication application;
1732 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1734 tet_infoline( "Create first visual with DESTROYED release policy" );
1735 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1738 tet_infoline( "Create second visual with DETACHED release policy");
1739 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1741 // Set up trace debug
1742 TestGlAbstraction& gl = application.GetGlAbstraction();
1743 TraceCallStack& textureTrace = gl.GetTextureTrace();
1744 textureTrace.Enable(true);
1746 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1747 DummyControl actor = DummyControl::New(true);
1748 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1749 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1750 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1751 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1752 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1754 actor.SetSize(200.f, 200.f);
1756 // Test initially zero renderers
1757 application.SendNotification();
1758 application.Render(0);
1759 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1760 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1762 Stage::GetCurrent().Add( actor );
1764 // Wait for image to load
1765 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1767 application.SendNotification();
1768 application.Render(0);
1769 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1770 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1771 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1773 // Test renderer removed when visual destroyed
1774 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1775 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1776 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1777 application.SendNotification();
1778 application.Render();
1780 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1781 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1783 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1784 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1785 application.SendNotification();
1786 application.Render();
1788 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1789 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1794 int UtcDaliImageVisualLoadPolicy01(void)
1796 ToolkitTestApplication application;
1797 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1799 // Set up trace debug
1800 TestGlAbstraction& gl = application.GetGlAbstraction();
1801 TraceCallStack& textureTrace = gl.GetTextureTrace();
1802 textureTrace.Enable(true);
1804 tet_infoline( "Create visual with IMMEDIATE load policy" );
1805 VisualFactory factory = VisualFactory::Get();
1807 Property::Map propertyMap;
1808 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1809 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1810 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1811 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1812 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
1814 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1816 Property::Map resultMap;
1817 imageVisual.CreatePropertyMap( resultMap );
1818 DALI_TEST_CHECK( ! resultMap.Empty() );
1819 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
1821 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1823 // Ensure texture has been uploaded
1824 application.SendNotification();
1825 application.Render();
1827 tet_infoline( "Ensure texture loading starts after visual created" );
1828 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1829 textureTrace.Reset();
1831 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1832 DummyControl actor = DummyControl::New(true);
1833 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1834 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1835 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1837 actor.SetSize(200.f, 200.f);
1838 Stage::GetCurrent().Add( actor );
1839 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1840 const unsigned int TIME_OUT_3_SECONDS = 3;
1841 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1843 application.SendNotification();
1844 application.Render();
1846 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1847 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1849 // Ensure texture is deleted when no longer needed (ref count was correct )
1850 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1852 application.SendNotification();
1853 application.Render();
1855 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1856 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1861 int UtcDaliImageVisualLoadPolicy02(void)
1863 ToolkitTestApplication application;
1864 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1866 // Set up trace debug
1867 TestGlAbstraction& gl = application.GetGlAbstraction();
1868 TraceCallStack& textureTrace = gl.GetTextureTrace();
1869 textureTrace.Enable(true);
1871 tet_infoline( "Create visual with IMMEDIATE load policy" );
1872 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
1874 const unsigned int TIME_OUT_3_SECONDS = 3;
1875 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1877 // Act on meeage queue even although nothing expected to load
1878 application.SendNotification();
1879 application.Render();
1881 tet_infoline( "Ensure texture is not generated yet" );
1882 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1883 textureTrace.Reset();
1885 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1886 DummyControl actor = DummyControl::New(true);
1887 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1888 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1889 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1891 actor.SetSize(200.f, 200.f);
1892 Stage::GetCurrent().Add( actor );
1893 tet_infoline( "Allow image time to load" );
1894 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1896 application.SendNotification();
1897 application.Render();
1899 tet_infoline( "Ensure texture generated and renderer created" );
1900 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1901 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1903 // Ensure texture is delete when no longer needed
1904 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1906 application.SendNotification();
1907 application.Render();
1909 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1910 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1915 int UtcDaliImageVisualLoadPolicy03(void)
1917 ToolkitTestApplication application;
1918 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
1920 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
1922 // Set up trace debug
1923 TestGlAbstraction& gl = application.GetGlAbstraction();
1924 TraceCallStack& textureTrace = gl.GetTextureTrace();
1925 textureTrace.Enable(true);
1927 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
1928 DummyControl actor = DummyControl::New(true);
1929 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1930 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1931 actor.SetSize(200.f, 200.f);
1933 tet_infoline( "Create visual with IMMEDIATE load policy" );
1934 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1936 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
1937 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1938 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1940 tet_infoline( "Allow image time to load resource" );
1941 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1942 application.SendNotification();
1943 application.Render();
1945 // Ensure texture has been uploaded
1946 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1947 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1952 int UtcDaliImageVisualLoadPolicy04(void)
1954 ToolkitTestApplication application;
1955 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
1956 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1958 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
1960 // Set up trace debug
1961 TestGlAbstraction& gl = application.GetGlAbstraction();
1962 TraceCallStack& textureTrace = gl.GetTextureTrace();
1963 textureTrace.Enable(true);
1965 tet_infoline( "Create a control and connect to resource ready signal" );
1966 DummyControl actor = DummyControl::New(true);
1967 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1968 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1969 actor.SetSize(200.f, 200.f);
1971 tet_infoline( "Create visual with IMMEDIATE load policy" );
1972 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1974 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
1975 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1976 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1978 tet_infoline( "Allow image time to load" );
1979 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1980 application.SendNotification();
1981 application.Render();
1983 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1984 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1985 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1987 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1989 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1990 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1991 DummyControl actor2 = DummyControl::New(true);
1992 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1993 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1995 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1996 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1997 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1998 actor2.SetSize(200.f, 200.f);
1999 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2000 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2005 int UtcDaliImageVisualLoadPolicy05(void)
2007 ToolkitTestApplication application;
2008 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2009 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2010 // Set up trace debug
2011 TestGlAbstraction& gl = application.GetGlAbstraction();
2012 TraceCallStack& textureTrace = gl.GetTextureTrace();
2013 textureTrace.Enable(true);
2015 tet_infoline( "Create a control and connect to resource ready signal" );
2016 DummyControl actor = DummyControl::New(true);
2017 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2018 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2019 actor.SetSize(200.f, 200.f);
2020 Stage::GetCurrent().Add( actor );
2022 tet_infoline( "Create visual with ATTACHED load policy" );
2023 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2025 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2026 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2027 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2029 tet_infoline( "Allow image time to load" );
2030 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2031 application.SendNotification();
2032 application.Render();
2034 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2035 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2036 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2038 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2040 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2041 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2042 DummyControl actor2 = DummyControl::New(true);
2043 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2044 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2046 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2047 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2048 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2049 actor2.SetSize(200.f, 200.f);
2050 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2051 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2057 int UtcDaliImageVisualOrientationCorrection(void)
2059 ToolkitTestApplication application;
2060 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2062 VisualFactory factory = VisualFactory::Get();
2063 tet_infoline( "Create visual with Orientation correction set OFF" );
2064 Property::Map propertyMap;
2065 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2066 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2067 propertyMap.Insert( "orientationCorrection", false );
2068 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2070 tet_infoline( "Create control for visual, need to loaded it" );
2071 DummyControl actor = DummyControl::New(true);
2072 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2073 Stage::GetCurrent().Add( actor );
2075 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2076 // Wait for image to load
2077 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2079 Vector2 originalImageSize;
2080 tet_infoline( "Get size of original visual to compare later with rotated image" );
2081 imageVisual.GetNaturalSize( originalImageSize );
2082 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2083 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2084 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2085 application.SendNotification();
2086 application.Render();
2088 tet_infoline( "Create visual with Orientation correction set ON " );
2089 propertyMap.Clear();
2090 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2091 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2092 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2093 imageVisual = factory.CreateVisual( propertyMap );
2095 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2096 // Wait for image to load
2097 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2099 Vector2 rotatedImageSize;
2100 imageVisual.GetNaturalSize( rotatedImageSize );
2101 tet_infoline( "Confirm that visual has rotated" );
2102 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2103 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2105 Property::Map resultMap;
2106 imageVisual.CreatePropertyMap( resultMap );
2108 // check the Property::ORIENTATION_CORRECTION value from the returned map
2109 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2110 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2115 int UtcDaliImageVisualCustomShader(void)
2117 ToolkitTestApplication application;
2118 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2120 VisualFactory factory = VisualFactory::Get();
2121 Property::Map properties;
2122 Property::Map shader;
2123 const std::string vertexShader = "Foobar";
2124 const std::string fragmentShader = "Foobar";
2125 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2126 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2128 properties[Visual::Property::TYPE] = Visual::IMAGE;
2129 properties[Visual::Property::SHADER] = shader;
2130 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2132 Visual::Base visual = factory.CreateVisual( properties );
2134 // trigger creation through setting on stage
2135 DummyControl dummy = DummyControl::New( true );
2136 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2137 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2139 dummy.SetSize( 200.f, 200.f );
2140 dummy.SetParentOrigin( ParentOrigin::CENTER );
2141 Stage::GetCurrent().Add( dummy );
2143 application.SendNotification();
2144 application.Render();
2146 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2148 Renderer renderer = dummy.GetRendererAt( 0 );
2149 Shader shader2 = renderer.GetShader();
2150 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2151 Property::Map* map = value.GetMap();
2152 DALI_TEST_CHECK( map );
2154 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2155 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2157 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2158 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2162 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2163 properties[Visual::Property::SHADER] = shader;
2165 Visual::Base visual1 = factory.CreateVisual( properties );
2167 // trigger creation through setting on stage
2168 DummyControl dummy1 = DummyControl::New( true );
2169 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2170 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2171 dummy1.SetSize( 200, 200 );
2172 dummy1.SetParentOrigin( ParentOrigin::CENTER );
2173 Stage::GetCurrent().Add( dummy1 );
2175 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2176 glAbstraction.EnableEnableDisableCallTrace( true );
2178 application.SendNotification();
2179 application.Render();
2181 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2182 std::ostringstream blendStr;
2183 blendStr << GL_BLEND;
2184 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
2190 void ResourceReadyLoadNext( Control control )
2192 static int callNumber = 0;
2194 gResourceReadySignalFired = true;
2195 gReadyIds.push_back(control.GetId());
2197 if( callNumber == 0 )
2199 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2201 tet_infoline( "Create visual with loaded image from within the signal handler" );
2202 VisualFactory factory = VisualFactory::Get();
2203 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2205 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2206 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2211 tet_infoline( "3rd signal called" );
2212 DALI_TEST_CHECK(true);
2216 int UtcDaliImageVisualLoadReady01(void)
2218 ToolkitTestApplication application;
2219 tet_infoline( "UtcDaliImageVisualLoadReady01");
2220 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2221 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2222 tet_infoline( "Should get a ready signal for all three visuals");
2226 tet_infoline( "Create a control and connect to resource ready signal" );
2227 DummyControl actor = DummyControl::New(true);
2228 int actor1Id = actor.GetId();
2229 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2230 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2231 actor.SetSize(200.f, 200.f);
2232 Stage::GetCurrent().Add(actor);
2234 tet_infoline( "Create visual with IMMEDIATE load policy" );
2235 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2237 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2238 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2241 tet_infoline( "Allow image time to load" );
2242 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2243 application.SendNotification();
2244 application.Render();
2246 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2247 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2248 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2251 tet_infoline( "Original control correctly signalled, now testing failing image" );
2253 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2256 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2258 DummyControl actor2 = DummyControl::New(true);
2259 int actor2Id = actor2.GetId();
2260 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2261 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2263 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2264 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2266 actor2.SetSize(200.f, 200.f);
2267 Stage::GetCurrent().Add(actor2);
2269 tet_infoline( "Wait for loading thread to finish");
2270 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2271 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2273 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2275 tet_infoline( "Check for 3rd signal");
2276 application.SendNotification();
2277 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2278 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);