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( 3 ), 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 UtcDaliImageVisualJpgAlphaMask(void)
1318 ToolkitTestApplication application;
1319 tet_infoline( "Request image visual with a Property::Map containing 24 bit image and an Alpha mask" );
1321 VisualFactory factory = VisualFactory::Get();
1322 DALI_TEST_CHECK( factory );
1324 Property::Map propertyMap;
1325 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1326 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1327 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1329 Visual::Base visual = factory.CreateVisual( propertyMap );
1330 DALI_TEST_CHECK( visual );
1332 Property::Map testMap;
1333 visual.CreatePropertyMap( testMap );
1334 DALI_TEST_EQUALS( *testMap.Find( ImageVisual::Property::ALPHA_MASK_URL ), Property::Value( TEST_MASK_IMAGE_FILE_NAME ), TEST_LOCATION );
1336 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1337 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1339 TestGlAbstraction& gl = application.GetGlAbstraction();
1340 TraceCallStack& textureTrace = gl.GetTextureTrace();
1341 textureTrace.Enable( true );
1343 DummyControl actor = DummyControl::New();
1344 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1345 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1347 actor.SetSize( 200.f, 200.f );
1348 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1349 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1351 Stage::GetCurrent().Add( actor );
1352 application.SendNotification();
1353 application.Render();
1355 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1357 application.SendNotification();
1358 application.Render();
1360 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1361 DALI_TEST_EQUALS( textureTrace.FindMethod( "BindTexture" ), true, TEST_LOCATION );
1362 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1364 // Should not be pre-multiplied
1365 Renderer renderer = actor.GetRendererAt( 0 );
1366 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1369 DALI_TEST_CHECK( value.Get( enable ) );
1370 DALI_TEST_CHECK( !enable );
1372 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1373 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1374 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1375 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1376 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
1377 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
1378 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
1379 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
1381 // Make a new visual with the same image
1382 Visual::Base newVisual = factory.CreateVisual( propertyMap );
1383 DALI_TEST_CHECK( newVisual );
1385 DummyControl newActor = DummyControl::New();
1386 DummyControlImpl& newDummyImpl = static_cast< DummyControlImpl& >( newActor.GetImplementation() );
1387 newDummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual );
1389 newActor.SetSize( 200.f, 200.f );
1390 DALI_TEST_EQUALS( newActor.GetRendererCount(), 0u, TEST_LOCATION );
1391 DALI_TEST_EQUALS( newActor.IsResourceReady(), false, TEST_LOCATION );
1393 Stage::GetCurrent().Add( newActor );
1395 application.SendNotification();
1396 application.Render();
1398 DALI_TEST_EQUALS( newActor.GetRendererCount(), 1u, TEST_LOCATION );
1399 DALI_TEST_EQUALS( textureTrace.FindMethod( "BindTexture" ), true, TEST_LOCATION );
1400 DALI_TEST_EQUALS( newActor.IsResourceReady(), true, TEST_LOCATION );
1402 // Should not be pre-multiplied
1403 renderer = newActor.GetRendererAt( 0 );
1404 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1405 DALI_TEST_CHECK( value.Get( enable ) );
1406 DALI_TEST_CHECK( !enable );
1408 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1409 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1410 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1411 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1412 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
1413 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
1414 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
1415 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
1417 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1418 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1423 int UtcDaliImageVisualRemoteAlphaMask(void)
1425 ToolkitTestApplication application;
1426 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1428 VisualFactory factory = VisualFactory::Get();
1429 DALI_TEST_CHECK( factory );
1431 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1433 Property::Map propertyMap;
1434 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1435 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1436 propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1438 Visual::Base visual = factory.CreateVisual( propertyMap );
1439 DALI_TEST_CHECK( visual );
1441 Property::Map testMap;
1442 visual.CreatePropertyMap(testMap);
1443 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1445 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1446 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1448 TestGlAbstraction& gl = application.GetGlAbstraction();
1449 TraceCallStack& textureTrace = gl.GetTextureTrace();
1450 textureTrace.Enable(true);
1452 DummyControl actor = DummyControl::New();
1453 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1454 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1455 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1457 actor.SetSize( 200.f, 200.f );
1458 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1460 Stage::GetCurrent().Add( actor );
1461 application.SendNotification();
1462 application.Render();
1464 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1466 application.SendNotification();
1467 application.Render();
1469 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1470 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1471 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1477 int UtcDaliImageVisualAlphaMaskCrop(void)
1479 ToolkitTestApplication application;
1480 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1482 VisualFactory factory = VisualFactory::Get();
1483 DALI_TEST_CHECK( factory );
1485 Property::Map propertyMap;
1486 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1487 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1488 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1489 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1490 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1492 Visual::Base visual = factory.CreateVisual( propertyMap );
1493 DALI_TEST_CHECK( visual );
1495 Property::Map testMap;
1496 visual.CreatePropertyMap(testMap);
1497 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1498 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1499 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1501 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1502 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1504 TestGlAbstraction& gl = application.GetGlAbstraction();
1505 TraceCallStack& textureTrace = gl.GetTextureTrace();
1506 textureTrace.Enable(true);
1508 DummyControl actor = DummyControl::New();
1509 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1510 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1512 actor.SetSize( 200.f, 200.f );
1513 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1514 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1516 Stage::GetCurrent().Add( actor );
1517 application.SendNotification();
1518 application.Render();
1520 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1522 application.SendNotification();
1523 application.Render();
1526 visual.GetNaturalSize(size);
1528 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1529 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1530 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1531 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1536 int UtcDaliImageVisualReleasePolicy01(void)
1538 ToolkitTestApplication application;
1539 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1541 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1542 DALI_TEST_CHECK( imageVisual );
1544 // Set up debug trace
1545 TestGlAbstraction& gl = application.GetGlAbstraction();
1546 TraceCallStack& textureTrace = gl.GetTextureTrace();
1547 textureTrace.Enable(true);
1549 tet_infoline( "Register visual with control and ensure it has the only handle" );
1550 DummyControl actor = DummyControl::New(true);
1551 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1552 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1553 imageVisual.Reset();
1555 actor.SetSize(200.f, 200.f);
1557 application.SendNotification();
1558 application.Render(0);
1559 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1560 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1562 Stage::GetCurrent().Add( actor );
1564 // Wait for image to load
1565 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1567 application.SendNotification();
1568 application.Render(0);
1569 // Test renderer and texture created
1570 tet_infoline( "Confirm texture created" );
1571 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1572 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1574 tet_infoline( "Disable visual causing the texture to be deleted" );
1575 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1577 application.SendNotification();
1578 application.Render(0);
1579 // Test renderer and textures removed.
1580 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1581 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1586 int UtcDaliImageVisualReleasePolicy02(void)
1588 ToolkitTestApplication application;
1589 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1591 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1592 DALI_TEST_CHECK( imageVisual );
1594 // Setup debug trace
1595 TestGlAbstraction& gl = application.GetGlAbstraction();
1596 TraceCallStack& textureTrace = gl.GetTextureTrace();
1597 textureTrace.Enable(true);
1599 tet_infoline( "Register visual with control and ensure it has the only handle" );
1600 DummyControl actor = DummyControl::New(true);
1601 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1602 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1603 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1605 actor.SetSize(200.f, 200.f);
1607 application.SendNotification();
1608 application.Render(0);
1609 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1610 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1612 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 // Test renderer and texture created
1620 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1621 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1624 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1625 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1626 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1627 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1628 application.SendNotification();
1629 application.Render();
1631 // Test texture removed after visual destroyed.
1632 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1633 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1638 int UtcDaliImageVisualReleasePolicy03(void)
1640 ToolkitTestApplication application;
1641 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1643 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1644 DALI_TEST_CHECK( imageVisual );
1646 TestGlAbstraction& gl = application.GetGlAbstraction();
1647 TraceCallStack& textureTrace = gl.GetTextureTrace();
1648 textureTrace.Enable(true);
1650 tet_infoline( "Register visual with control and ensure it has the only handle" );
1651 DummyControl actor = DummyControl::New(true);
1652 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1653 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1654 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1656 actor.SetSize(200.f, 200.f);
1658 application.SendNotification();
1659 application.Render(0);
1660 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1661 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1663 Stage::GetCurrent().Add( actor );
1665 // Wait for image to load
1666 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1668 application.SendNotification();
1669 application.Render(0);
1670 // Test renderer and texture created
1671 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1672 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1674 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1675 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1676 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1677 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1678 application.SendNotification();
1679 application.Render();
1681 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1682 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1687 int UtcDaliImageVisualReleasePolicy04(void)
1689 ToolkitTestApplication application;
1690 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1692 tet_infoline( "Create first visual with Never release policy" );
1693 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1695 tet_infoline( "Create second visual with Destroyed release policy");
1696 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1698 // Set up trace debug
1699 TestGlAbstraction& gl = application.GetGlAbstraction();
1700 TraceCallStack& textureTrace = gl.GetTextureTrace();
1701 textureTrace.Enable(true);
1703 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1704 DummyControl actor = DummyControl::New(true);
1705 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1706 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1707 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1708 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1709 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1711 actor.SetSize(200.f, 200.f);
1713 // Test initially zero renderers
1714 application.SendNotification();
1715 application.Render(0);
1716 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1717 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1719 Stage::GetCurrent().Add( actor );
1721 // Wait for image to load
1722 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1724 application.SendNotification();
1725 application.Render(0);
1726 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1727 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1728 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1730 // Test renderer removed when visual destroyed
1731 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1732 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1733 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1734 application.SendNotification();
1735 application.Render();
1737 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1738 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1740 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1741 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1742 application.SendNotification();
1743 application.Render();
1745 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1746 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1747 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1752 int UtcDaliImageVisualReleasePolicy05(void)
1754 ToolkitTestApplication application;
1755 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1757 VisualFactory factory = VisualFactory::Get();
1759 Property::Map propertyMapNeverReleasePolicy;
1760 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1761 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1762 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1763 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1764 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1766 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1768 Property::Map resultMap;
1769 imageVisualNever.CreatePropertyMap( resultMap );
1770 DALI_TEST_CHECK( ! resultMap.Empty() );
1772 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1777 int UtcDaliImageVisualReleasePolicy06(void)
1779 ToolkitTestApplication application;
1780 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1782 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1783 DALI_TEST_CHECK( imageVisual );
1785 TestGlAbstraction& gl = application.GetGlAbstraction();
1786 TraceCallStack& textureTrace = gl.GetTextureTrace();
1787 textureTrace.Enable(true);
1789 tet_infoline( "Register visual with control and ensure it has the only handle" );
1790 DummyControl actor = DummyControl::New(true);
1791 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1792 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1793 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1795 actor.SetSize(200.f, 200.f);
1797 application.SendNotification();
1798 application.Render(0);
1799 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1800 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1802 Stage::GetCurrent().Add( actor );
1804 // Wait for image to load
1805 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1807 application.SendNotification();
1808 application.Render(0);
1809 // Test renderer and texture created
1810 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1811 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1812 textureTrace.Reset();
1814 tet_infoline( "Disable Visual and check texture not affected" );
1815 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1816 application.SendNotification();
1817 application.Render(0);
1818 tet_infoline( "Check renderer is destroyed when visual off stage" );
1819 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1820 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1821 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1822 textureTrace.Reset();
1824 tet_infoline( "Re-enable Visual and check texture not affected" );
1825 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1826 application.SendNotification();
1827 application.Render(0);
1828 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1829 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1830 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1831 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1836 int UtcDaliImageVisualReleasePolicy07(void)
1838 ToolkitTestApplication application;
1839 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1841 tet_infoline( "Create first visual with DESTROYED release policy" );
1842 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1845 tet_infoline( "Create second visual with DETACHED release policy");
1846 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1848 // Set up trace debug
1849 TestGlAbstraction& gl = application.GetGlAbstraction();
1850 TraceCallStack& textureTrace = gl.GetTextureTrace();
1851 textureTrace.Enable(true);
1853 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1854 DummyControl actor = DummyControl::New(true);
1855 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1856 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1857 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1858 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1859 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1861 actor.SetSize(200.f, 200.f);
1863 // Test initially zero renderers
1864 application.SendNotification();
1865 application.Render(0);
1866 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1867 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1869 Stage::GetCurrent().Add( actor );
1871 // Wait for image to load
1872 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1874 application.SendNotification();
1875 application.Render(0);
1876 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1877 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1878 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1880 // Test renderer removed when visual destroyed
1881 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1882 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1883 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1884 application.SendNotification();
1885 application.Render();
1887 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1888 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1890 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1891 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1892 application.SendNotification();
1893 application.Render();
1895 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1896 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1901 int UtcDaliImageVisualLoadPolicy01(void)
1903 ToolkitTestApplication application;
1904 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1906 // Set up trace debug
1907 TestGlAbstraction& gl = application.GetGlAbstraction();
1908 TraceCallStack& textureTrace = gl.GetTextureTrace();
1909 textureTrace.Enable(true);
1911 tet_infoline( "Create visual with IMMEDIATE load policy" );
1912 VisualFactory factory = VisualFactory::Get();
1914 Property::Map propertyMap;
1915 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1916 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1917 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1918 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1919 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
1921 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1923 Property::Map resultMap;
1924 imageVisual.CreatePropertyMap( resultMap );
1925 DALI_TEST_CHECK( ! resultMap.Empty() );
1926 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
1928 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1930 // Ensure texture has been uploaded
1931 application.SendNotification();
1932 application.Render();
1934 tet_infoline( "Ensure texture loading starts after visual created" );
1935 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1936 textureTrace.Reset();
1938 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1939 DummyControl actor = DummyControl::New(true);
1940 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1941 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1942 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1944 actor.SetSize(200.f, 200.f);
1945 Stage::GetCurrent().Add( actor );
1946 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1947 const unsigned int TIME_OUT_3_SECONDS = 3;
1948 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1950 application.SendNotification();
1951 application.Render();
1953 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1954 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1956 // Ensure texture is deleted when no longer needed (ref count was correct )
1957 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1959 application.SendNotification();
1960 application.Render();
1962 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1963 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1968 int UtcDaliImageVisualLoadPolicy02(void)
1970 ToolkitTestApplication application;
1971 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1973 // Set up trace debug
1974 TestGlAbstraction& gl = application.GetGlAbstraction();
1975 TraceCallStack& textureTrace = gl.GetTextureTrace();
1976 textureTrace.Enable(true);
1978 tet_infoline( "Create visual with IMMEDIATE load policy" );
1979 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
1981 const unsigned int TIME_OUT_3_SECONDS = 3;
1982 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1984 // Act on meeage queue even although nothing expected to load
1985 application.SendNotification();
1986 application.Render();
1988 tet_infoline( "Ensure texture is not generated yet" );
1989 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1990 textureTrace.Reset();
1992 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1993 DummyControl actor = DummyControl::New(true);
1994 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1995 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1996 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1998 actor.SetSize(200.f, 200.f);
1999 Stage::GetCurrent().Add( actor );
2000 tet_infoline( "Allow image time to load" );
2001 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2003 application.SendNotification();
2004 application.Render();
2006 tet_infoline( "Ensure texture generated and renderer created" );
2007 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2008 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2010 // Ensure texture is delete when no longer needed
2011 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2013 application.SendNotification();
2014 application.Render();
2016 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2017 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2022 int UtcDaliImageVisualLoadPolicy03(void)
2024 ToolkitTestApplication application;
2025 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2027 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2029 // Set up trace debug
2030 TestGlAbstraction& gl = application.GetGlAbstraction();
2031 TraceCallStack& textureTrace = gl.GetTextureTrace();
2032 textureTrace.Enable(true);
2034 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2035 DummyControl actor = DummyControl::New(true);
2036 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2037 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2038 actor.SetSize(200.f, 200.f);
2040 tet_infoline( "Create visual with IMMEDIATE load policy" );
2041 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2043 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2044 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2045 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2047 tet_infoline( "Allow image time to load resource" );
2048 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2049 application.SendNotification();
2050 application.Render();
2052 // Ensure texture has been uploaded
2053 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2054 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2059 int UtcDaliImageVisualLoadPolicy04(void)
2061 ToolkitTestApplication application;
2062 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2063 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2065 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2067 // Set up trace debug
2068 TestGlAbstraction& gl = application.GetGlAbstraction();
2069 TraceCallStack& textureTrace = gl.GetTextureTrace();
2070 textureTrace.Enable(true);
2072 tet_infoline( "Create a control and connect to resource ready signal" );
2073 DummyControl actor = DummyControl::New(true);
2074 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2075 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2076 actor.SetSize(200.f, 200.f);
2078 tet_infoline( "Create visual with IMMEDIATE load policy" );
2079 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2081 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2082 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2083 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2085 tet_infoline( "Allow image time to load" );
2086 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2087 application.SendNotification();
2088 application.Render();
2090 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2091 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2092 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2094 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2096 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2097 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2098 DummyControl actor2 = DummyControl::New(true);
2099 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2100 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2102 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2103 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2104 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2105 actor2.SetSize(200.f, 200.f);
2106 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2107 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2112 int UtcDaliImageVisualLoadPolicy05(void)
2114 ToolkitTestApplication application;
2115 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2116 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2117 // Set up trace debug
2118 TestGlAbstraction& gl = application.GetGlAbstraction();
2119 TraceCallStack& textureTrace = gl.GetTextureTrace();
2120 textureTrace.Enable(true);
2122 tet_infoline( "Create a control and connect to resource ready signal" );
2123 DummyControl actor = DummyControl::New(true);
2124 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2125 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2126 actor.SetSize(200.f, 200.f);
2127 Stage::GetCurrent().Add( actor );
2129 tet_infoline( "Create visual with ATTACHED load policy" );
2130 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2132 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2133 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2134 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2136 tet_infoline( "Allow image time to load" );
2137 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2138 application.SendNotification();
2139 application.Render();
2141 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2142 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2143 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2145 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2147 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2148 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2149 DummyControl actor2 = DummyControl::New(true);
2150 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2151 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2153 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2154 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2155 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2156 actor2.SetSize(200.f, 200.f);
2157 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2158 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2164 int UtcDaliImageVisualOrientationCorrection(void)
2166 ToolkitTestApplication application;
2167 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2169 VisualFactory factory = VisualFactory::Get();
2170 tet_infoline( "Create visual with Orientation correction set OFF" );
2171 Property::Map propertyMap;
2172 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2173 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2174 propertyMap.Insert( "orientationCorrection", false );
2175 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2177 tet_infoline( "Create control for visual, need to loaded it" );
2178 DummyControl actor = DummyControl::New(true);
2179 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2180 Stage::GetCurrent().Add( actor );
2182 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2183 // Wait for image to load
2184 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2186 Vector2 originalImageSize;
2187 tet_infoline( "Get size of original visual to compare later with rotated image" );
2188 imageVisual.GetNaturalSize( originalImageSize );
2189 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2190 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2191 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2192 application.SendNotification();
2193 application.Render();
2195 tet_infoline( "Create visual with Orientation correction set ON " );
2196 propertyMap.Clear();
2197 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2198 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2199 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2200 imageVisual = factory.CreateVisual( propertyMap );
2202 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2203 // Wait for image to load
2204 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2206 Vector2 rotatedImageSize;
2207 imageVisual.GetNaturalSize( rotatedImageSize );
2208 tet_infoline( "Confirm that visual has rotated" );
2209 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2210 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2212 Property::Map resultMap;
2213 imageVisual.CreatePropertyMap( resultMap );
2215 // check the Property::ORIENTATION_CORRECTION value from the returned map
2216 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2217 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2222 int UtcDaliImageVisualCustomShader(void)
2224 ToolkitTestApplication application;
2225 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2227 VisualFactory factory = VisualFactory::Get();
2228 Property::Map properties;
2229 Property::Map shader;
2230 const std::string vertexShader = "Foobar";
2231 const std::string fragmentShader = "Foobar";
2232 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2233 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2235 properties[Visual::Property::TYPE] = Visual::IMAGE;
2236 properties[Visual::Property::SHADER] = shader;
2237 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2239 Visual::Base visual = factory.CreateVisual( properties );
2241 // trigger creation through setting on stage
2242 DummyControl dummy = DummyControl::New( true );
2243 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2244 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2246 dummy.SetSize( 200.f, 200.f );
2247 dummy.SetParentOrigin( ParentOrigin::CENTER );
2248 Stage::GetCurrent().Add( dummy );
2250 application.SendNotification();
2251 application.Render();
2253 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2255 Renderer renderer = dummy.GetRendererAt( 0 );
2256 Shader shader2 = renderer.GetShader();
2257 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2258 Property::Map* map = value.GetMap();
2259 DALI_TEST_CHECK( map );
2261 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2262 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2264 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2265 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2269 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2270 properties[Visual::Property::SHADER] = shader;
2272 Visual::Base visual1 = factory.CreateVisual( properties );
2274 // trigger creation through setting on stage
2275 DummyControl dummy1 = DummyControl::New( true );
2276 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2277 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2278 dummy1.SetSize( 200, 200 );
2279 dummy1.SetParentOrigin( ParentOrigin::CENTER );
2280 Stage::GetCurrent().Add( dummy1 );
2282 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2283 glAbstraction.EnableEnableDisableCallTrace( true );
2285 application.SendNotification();
2286 application.Render();
2288 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2289 std::ostringstream blendStr;
2290 blendStr << GL_BLEND;
2291 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
2297 void ResourceReadyLoadNext( Control control )
2299 static int callNumber = 0;
2301 gResourceReadySignalFired = true;
2302 gReadyIds.push_back(control.GetId());
2304 if( callNumber == 0 )
2306 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2308 tet_infoline( "Create visual with loaded image from within the signal handler" );
2309 VisualFactory factory = VisualFactory::Get();
2310 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2312 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2313 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2318 tet_infoline( "3rd signal called" );
2319 DALI_TEST_CHECK(true);
2323 int UtcDaliImageVisualLoadReady01(void)
2325 ToolkitTestApplication application;
2326 tet_infoline( "UtcDaliImageVisualLoadReady01");
2327 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2328 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2329 tet_infoline( "Should get a ready signal for all three visuals");
2333 tet_infoline( "Create a control and connect to resource ready signal" );
2334 DummyControl actor = DummyControl::New(true);
2335 int actor1Id = actor.GetId();
2336 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2337 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2338 actor.SetSize(200.f, 200.f);
2339 Stage::GetCurrent().Add(actor);
2341 tet_infoline( "Create visual with IMMEDIATE load policy" );
2342 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2344 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2345 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2348 tet_infoline( "Allow image time to load" );
2349 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2350 application.SendNotification();
2351 application.Render();
2353 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2354 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2355 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2358 tet_infoline( "Original control correctly signalled, now testing failing image" );
2360 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2363 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2365 DummyControl actor2 = DummyControl::New(true);
2366 int actor2Id = actor2.GetId();
2367 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2368 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2370 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2371 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2373 actor2.SetSize(200.f, 200.f);
2374 Stage::GetCurrent().Add(actor2);
2376 tet_infoline( "Wait for loading thread to finish");
2377 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2378 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2380 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2382 tet_infoline( "Check for 3rd signal");
2383 application.SendNotification();
2384 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2385 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);