2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-timer.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/public-api/image-loader/image.h>
28 #include <dali-toolkit/public-api/image-loader/image-url.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include "dummy-control.h"
33 using namespace Dali::Toolkit;
35 void dali_image_visual_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_image_visual_cleanup(void)
42 test_return_value = TET_PASS;
47 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
48 const char* TEST_BROKEN_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/a-random-nonimage.jpg";
49 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
50 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
51 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
52 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
53 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
54 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
55 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
58 bool gResourceReadySignalFired = false;
59 std::vector<int> gReadyIds = {};
60 void ResourceReadySignal( Control control )
62 gResourceReadySignalFired = true;
63 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
70 Actor CreateActorWithImageVisual(const Property::Map& map)
72 VisualFactory factory = VisualFactory::Get();
73 DummyControl actor = DummyControl::New();
74 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
75 Visual::Base visual = factory.CreateVisual( map );
76 DALI_TEST_CHECK( visual );
77 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
78 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
79 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
84 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
86 VisualFactory factory = VisualFactory::Get();
88 Property::Map propertyMap;
89 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
90 propertyMap.Insert( ImageVisual::Property::URL, url );
91 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
92 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
93 propertyMap.Insert( key , value );
95 return factory.CreateVisual( propertyMap );
100 void TestVisualRender( ToolkitTestApplication& application,
102 Visual::Base& visual,
103 std::size_t expectedSamplers = 0,
104 ImageDimensions imageDimensions = ImageDimensions(),
105 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
107 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
108 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
112 // set the image size, for test case, this needs to be set before loading started
113 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
116 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
117 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
119 application.GetScene().Add( actor );
121 application.SendNotification(); // Send messages to update
122 application.Render(); // process update and render
123 application.SendNotification(); // process any signals to event
127 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
130 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
133 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
136 visual.CreatePropertyMap(map);
137 Property::Value* value = map.Find( mixColorIndex );
138 DALI_TEST_CHECK( value );
140 DALI_TEST_CHECK( value->Get( mixColor1 ) );
141 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
143 value = map.Find( Visual::Property::MIX_COLOR );
144 DALI_TEST_CHECK( value );
146 DALI_TEST_CHECK( value->Get( mixColor2 ) );
147 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
149 value = map.Find( Visual::Property::OPACITY );
150 DALI_TEST_CHECK( value );
152 DALI_TEST_CHECK( value->Get( opacity ) );
153 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
158 int UtcDaliImageVisualPropertyMap(void)
160 ToolkitTestApplication application;
161 tet_infoline( "Request image visual with a Property::Map" );
163 VisualFactory factory = VisualFactory::Get();
164 DALI_TEST_CHECK( factory );
165 factory.SetPreMultiplyOnLoad( true );
167 Property::Map propertyMap;
168 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
169 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
171 Visual::Base visual = factory.CreateVisual( propertyMap );
172 DALI_TEST_CHECK( visual );
174 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
175 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
177 TestGlAbstraction& gl = application.GetGlAbstraction();
178 TraceCallStack& textureTrace = gl.GetTextureTrace();
179 textureTrace.Enable(true);
181 DummyControl actor = DummyControl::New();
182 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
183 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
185 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
186 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
188 application.GetScene().Add( actor );
189 application.SendNotification();
190 application.Render();
192 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
194 application.SendNotification();
195 application.Render();
197 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
198 auto renderer = actor.GetRendererAt(0);
199 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
200 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
201 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
202 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
203 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
204 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
205 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
207 application.GetScene().Remove( actor );
208 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
214 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
216 ToolkitTestApplication application;
217 tet_infoline( "Request image visual without pre-multiplied alpha" );
219 VisualFactory factory = VisualFactory::Get();
220 DALI_TEST_CHECK( factory );
221 factory.SetPreMultiplyOnLoad( false );
223 Property::Map propertyMap;
224 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
225 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
227 Visual::Base visual = factory.CreateVisual( propertyMap );
228 DALI_TEST_CHECK( visual );
230 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
231 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
233 TestGlAbstraction& gl = application.GetGlAbstraction();
234 TraceCallStack& textureTrace = gl.GetTextureTrace();
235 textureTrace.Enable(true);
237 DummyControl actor = DummyControl::New();
238 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
239 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
241 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
242 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
244 application.GetScene().Add( actor );
245 application.SendNotification();
246 application.Render();
248 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
250 application.SendNotification();
251 application.Render();
253 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
254 auto renderer = actor.GetRendererAt(0);
255 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
256 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
257 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
258 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
260 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
261 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
263 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
265 application.GetScene().Remove( actor );
266 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
272 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
274 ToolkitTestApplication application;
275 tet_infoline( "Request image visual with no alpha channel" );
277 VisualFactory factory = VisualFactory::Get();
278 DALI_TEST_CHECK( factory );
280 Property::Map propertyMap;
281 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
282 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
284 Visual::Base visual = factory.CreateVisual( propertyMap );
285 DALI_TEST_CHECK( visual );
287 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
288 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
290 TestGlAbstraction& gl = application.GetGlAbstraction();
291 TraceCallStack& textureTrace = gl.GetTextureTrace();
292 textureTrace.Enable(true);
294 DummyControl actor = DummyControl::New();
295 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
296 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
298 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
299 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
301 application.GetScene().Add( actor );
302 application.SendNotification();
303 application.Render();
305 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
307 application.SendNotification();
308 application.Render();
310 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
311 auto renderer = actor.GetRendererAt(0);
312 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
313 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
314 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
315 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
317 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
318 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
320 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
322 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
323 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
324 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
325 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
326 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
327 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
328 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
329 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
331 textureTrace.Reset();
333 // Make a new visual with the same image
334 Visual::Base newVisual = factory.CreateVisual( propertyMap );
335 DALI_TEST_CHECK( newVisual );
337 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
338 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
340 DummyControl newActor = DummyControl::New();
341 DummyControlImpl& newDummyImpl = static_cast< DummyControlImpl& >( newActor.GetImplementation() );
342 newDummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, newVisual );
344 newActor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
345 DALI_TEST_EQUALS( newActor.GetRendererCount(), 0u, TEST_LOCATION );
347 application.GetScene().Add( newActor );
349 application.SendNotification();
350 application.Render();
352 DALI_TEST_EQUALS( newActor.GetRendererCount(), 1u, TEST_LOCATION );
353 auto newRenderer = newActor.GetRendererAt( 0 );
354 preMultipliedIndex = newRenderer.GetPropertyIndex( "preMultipliedAlpha" );
355 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
356 preMultipliedAlpha = newRenderer.GetProperty< bool >( preMultipliedIndex );
357 preMultipliedAlpha2 = newRenderer.GetProperty< bool >( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
359 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
360 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
362 srcFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
363 destFactorRgb = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
364 srcFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
365 destFactorAlpha = newRenderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
366 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
367 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
368 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
369 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
371 application.GetScene().Remove( actor );
372 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
378 int UtcDaliImageVisualRemoteImageLoad(void)
380 ToolkitTestApplication application;
381 tet_infoline( "Request remote image visual with a Property::Map" );
383 VisualFactory factory = VisualFactory::Get();
384 DALI_TEST_CHECK( factory );
386 Property::Map propertyMap;
387 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
388 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
390 Visual::Base visual = factory.CreateVisual( propertyMap );
391 DALI_TEST_CHECK( visual );
393 TestGlAbstraction& gl = application.GetGlAbstraction();
394 TraceCallStack& textureTrace = gl.GetTextureTrace();
395 textureTrace.Enable(true);
397 DummyControl actor = DummyControl::New();
398 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
399 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
401 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
402 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
404 application.GetScene().Add( actor );
405 application.SendNotification();
407 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
409 application.SendNotification();
410 application.Render();
412 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
413 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
415 application.GetScene().Remove( actor );
416 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
422 int UtcDaliImageVisualWithNativeImage(void)
424 ToolkitTestApplication application;
425 tet_infoline( "Use Native Image as url" );
427 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
428 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
429 std::string url = imageUrl.GetUrl();
431 VisualFactory factory = VisualFactory::Get();
432 DALI_TEST_CHECK( factory );
434 Property::Map propertyMap;
435 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
436 propertyMap.Insert( ImageVisual::Property::URL, url );
438 Visual::Base visual = factory.CreateVisual( propertyMap );
439 DALI_TEST_CHECK( visual );
441 DummyControl actor = DummyControl::New();
442 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
443 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
445 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
447 application.GetScene().Add( actor );
449 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
451 Renderer renderer = actor.GetRendererAt(0);
452 Shader shader = renderer.GetShader();
454 Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
455 DALI_TEST_CHECK(value.GetType() == Property::MAP);
456 const Property::Map* outMap = value.GetMap();
457 std::string fragmentShader = (*outMap)["fragment"].Get<std::string>();
459 const char* fragmentPrefix = nativeImageSource->GetCustomFragmentPrefix();
460 size_t pos = fragmentShader.find(fragmentPrefix);
462 DALI_TEST_EQUALS( pos != std::string::npos, true, TEST_LOCATION );
467 int UtcDaliImageVisualWithNativeImageRemoved(void)
469 ToolkitTestApplication application;
470 tet_infoline( "Use Native Image as url" );
472 TestGlAbstraction& gl = application.GetGlAbstraction();
473 TraceCallStack& textureTrace = gl.GetTextureTrace();
474 textureTrace.Enable(true);
476 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT);
477 ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource);
478 std::string url = imageUrl.GetUrl();
480 VisualFactory factory = VisualFactory::Get();
481 DALI_TEST_CHECK( factory );
483 Property::Map propertyMap;
484 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
485 propertyMap.Insert( ImageVisual::Property::URL, url );
487 Visual::Base visual = factory.CreateVisual( propertyMap );
488 DALI_TEST_CHECK( visual );
490 DummyControl actor = DummyControl::New();
491 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
492 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
494 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
496 application.GetScene().Add( actor );
497 application.SendNotification();
498 application.Render();
500 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
501 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
503 tet_infoline( "No delete texture because reference count is not zero" );
505 application.GetScene().Remove( actor );
506 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
507 application.SendNotification();
508 application.Render();
510 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
511 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
513 tet_infoline( "Delete texture because reference count is zero" );
515 application.SendNotification();
516 application.Render();
518 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
523 int UtcDaliImageVisualTextureReuse1(void)
525 ToolkitTestApplication application;
526 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
528 Property::Map propertyMap;
529 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
530 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
531 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
533 TestGlAbstraction& gl = application.GetGlAbstraction();
534 TraceCallStack& textureTrace = gl.GetTextureTrace();
535 textureTrace.Enable(true);
536 TraceCallStack& drawTrace = gl.GetDrawTrace();
537 drawTrace.Enable(true);
539 Actor actor = CreateActorWithImageVisual( propertyMap );
540 application.GetScene().Add( actor );
541 application.SendNotification();
543 // Wait for image to load
544 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
546 application.SendNotification();
547 application.Render();
549 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
550 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
551 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
552 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
553 textureTrace.Reset();
556 Actor actor2 = CreateActorWithImageVisual( propertyMap );
557 application.GetScene().Add(actor2);
559 application.SendNotification(); // Send messages to update
560 application.Render(); // process update and render
561 application.SendNotification(); // process any signals to event
563 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
565 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
566 "draw calls use the same texture as the previous draw call\n" );
568 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
569 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
570 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
571 // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
573 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
575 application.GetScene().Remove( actor );
576 application.SendNotification();
577 application.Render();
579 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
580 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
582 tet_infoline("Test that removing last actor does delete the texture\n");
584 application.GetScene().Remove( actor2 ); // Detaches remaining ImageVisual
585 application.SendNotification();
586 application.Render();
588 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
589 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
595 int UtcDaliImageVisualTextureReuse2(void)
597 ToolkitTestApplication application;
598 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" );
600 Property::Map propertyMap;
601 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
602 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
604 TestGlAbstraction& gl = application.GetGlAbstraction();
605 TraceCallStack& textureTrace = gl.GetTextureTrace();
606 textureTrace.Enable(true);
607 TraceCallStack& drawTrace = gl.GetDrawTrace();
608 drawTrace.Enable(true);
610 Actor actor = CreateActorWithImageVisual( propertyMap );
611 application.GetScene().Add( actor );
612 application.SendNotification();
614 // Wait for image to load
615 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
617 application.SendNotification();
618 application.Render();
620 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
621 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
622 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
623 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
624 textureTrace.Reset();
627 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
628 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
629 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
630 Actor actor2 = CreateActorWithImageVisual( propertyMap );
631 application.GetScene().Add(actor2);
633 application.SendNotification();
635 // Wait for image to load
636 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
638 application.SendNotification();
639 application.Render();
641 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
643 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
644 "renderers are using different textures\n" );
646 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
647 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
648 TraceCallStack::NamedParams tex1;
649 tex1["texture"] << 1;
650 TraceCallStack::NamedParams tex2;
651 tex2["texture"] << 2;
652 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
653 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
655 tet_infoline("Test that removing 1 actor deletes it's texture\n");
657 application.GetScene().Remove( actor );
658 application.SendNotification();
659 application.Render();
661 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
662 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
664 tet_infoline("Test that removing last actor deletes it's texture\n");
666 application.GetScene().Remove( actor2 );
667 application.SendNotification();
668 application.Render();
670 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
671 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
677 int UtcDaliImageVisualCustomWrapModePixelArea(void)
679 ToolkitTestApplication application;
680 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
682 static std::vector<UniformData> customUniforms =
684 UniformData("pixelArea", Property::Type::VECTOR4),
685 UniformData("wrapMode", Property::Type::VECTOR2),
688 TestGraphicsController& graphics = application.GetGraphicsController();
689 graphics.AddCustomUniforms(customUniforms);
691 VisualFactory factory = VisualFactory::Get();
692 DALI_TEST_CHECK( factory );
694 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
697 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
699 Property::Map propertyMap;
700 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
701 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
702 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
703 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
704 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
705 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
706 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
707 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
708 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
710 Visual::Base visual = factory.CreateVisual( propertyMap );
711 DALI_TEST_CHECK( visual );
713 TestGlAbstraction& gl = application.GetGlAbstraction();
714 TraceCallStack& textureTrace = gl.GetTextureTrace();
715 textureTrace.Enable(true);
716 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
717 texParameterTrace.Enable( true );
719 DummyControl actor = DummyControl::New();
720 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
721 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
722 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
723 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
724 application.GetScene().Add( actor );
727 application.SendNotification();
728 application.Render();
730 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
732 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
734 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
735 std::stringstream out;
736 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
737 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
739 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
740 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
742 // test the uniforms which used to handle the wrap mode
743 Renderer renderer = actor.GetRendererAt( 0u );
744 DALI_TEST_CHECK( renderer );
746 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
747 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
748 Vector4 pixelAreaUniform;
749 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
750 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
752 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
753 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
754 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
755 Vector2 wrapModeUniform;
756 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
757 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
760 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
765 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
767 ToolkitTestApplication application;
768 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
770 static std::vector<UniformData> customUniforms =
772 UniformData("pixelArea", Property::Type::VECTOR4),
775 TestGraphicsController& graphics = application.GetGraphicsController();
776 graphics.AddCustomUniforms(customUniforms);
778 VisualFactory factory = VisualFactory::Get();
779 DALI_TEST_CHECK( factory );
781 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
783 const int height=600;
784 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
786 Property::Map propertyMap;
787 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
788 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
789 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
790 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
791 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
792 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
793 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
794 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
796 Visual::Base visual = factory.CreateVisual( propertyMap );
797 DALI_TEST_CHECK( visual );
799 TestGlAbstraction& gl = application.GetGlAbstraction();
800 TraceCallStack& textureTrace = gl.GetTextureTrace();
801 textureTrace.Enable(true);
802 textureTrace.EnableLogging(true);
803 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
804 texParameterTrace.Enable( true );
805 texParameterTrace.EnableLogging( true );
807 DummyControl actor = DummyControl::New();
808 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
809 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
810 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
811 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
812 application.GetScene().Add( actor );
815 application.SendNotification();
816 application.Render();
817 application.SendNotification();
819 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
821 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
823 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
824 std::stringstream out;
825 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
826 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
828 out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
829 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
831 // test the uniforms which used to handle the wrap mode
832 Renderer renderer = actor.GetRendererAt( 0u );
833 DALI_TEST_CHECK( renderer );
835 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
836 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
837 Vector4 pixelAreaUniform;
838 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
839 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
841 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
842 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
845 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
850 int UtcDaliImageVisualAnimateMixColor(void)
852 ToolkitTestApplication application;
853 tet_infoline( "Animate mix color" );
855 static std::vector<UniformData> customUniforms =
857 UniformData("mixColor", Property::Type::VECTOR3),
860 TestGraphicsController& graphics = application.GetGraphicsController();
861 graphics.AddCustomUniforms(customUniforms);
863 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
865 VisualFactory factory = VisualFactory::Get();
866 Property::Map propertyMap;
867 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
868 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
869 propertyMap.Insert("mixColor", Color::BLUE);
870 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
871 Visual::Base visual = factory.CreateVisual( propertyMap );
873 DummyControl actor = DummyControl::New(true);
874 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
875 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
877 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
878 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
879 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
880 application.GetScene().Add(actor);
882 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
884 Renderer renderer = actor.GetRendererAt(0);
885 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
886 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
887 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
889 tet_infoline("Test that the renderer has the mixColor property");
890 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
892 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
895 map["target"] = "testVisual";
896 map["property"] = "mixColor";
897 map["initialValue"] = Color::MAGENTA;
898 map["targetValue"] = TARGET_MIX_COLOR;
899 map["animator"] = Property::Map()
900 .Add("alphaFunction", "LINEAR")
901 .Add("timePeriod", Property::Map()
903 .Add("duration", 4.0f));
905 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
907 Animation animation = dummyImpl.CreateTransition( transition );
909 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
912 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
913 glAbstraction.EnableEnableDisableCallTrace( true );
914 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
915 std::ostringstream blendStr;
916 blendStr << std::hex << GL_BLEND;
918 application.SendNotification();
919 application.Render(0); // Ensure animation starts
920 application.Render(2000u); // Halfway point
921 Vector3 testColor( 1.0f, 0.0f, 0.5f );
923 // uColor.a should be actor's alpha * mixColor.a.
924 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
925 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
927 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
929 glEnableStack.Reset();
931 application.Render(2000u); // Halfway point between blue and white
933 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ), Color::WHITE, TEST_LOCATION );
934 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
935 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
937 // GL_BLEND should not be changed: Keep enabled
938 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
939 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
940 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
942 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
947 int UtcDaliImageVisualAnimateOpacity(void)
949 ToolkitTestApplication application;
950 tet_infoline( "Animate image visual opacity" );
952 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
954 VisualFactory factory = VisualFactory::Get();
955 Property::Map propertyMap;
956 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
957 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
958 propertyMap.Insert("opacity", 0.5f);
959 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
960 Visual::Base visual = factory.CreateVisual( propertyMap );
962 DummyControl actor = DummyControl::New(true);
963 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
964 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
966 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
967 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
968 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
969 application.GetScene().Add(actor);
971 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
973 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
974 glAbstraction.EnableEnableDisableCallTrace( true );
975 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
976 std::ostringstream blendStr;
977 blendStr << std::hex << GL_BLEND;
979 application.SendNotification();
980 application.Render();
982 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) );
985 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." );
988 map["target"] = "testVisual";
989 map["property"] = "opacity";
990 map["targetValue"] = 1.0f;
991 map["animator"] = Property::Map()
992 .Add("alphaFunction", "LINEAR")
993 .Add("timePeriod", Property::Map()
995 .Add("duration", 4.0f));
997 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
998 Animation animation = dummyImpl.CreateTransition( transition );
1001 glEnableStack.Reset();
1003 application.SendNotification();
1004 application.Render(0); // Ensure animation starts
1005 application.Render(2000u); // Halfway point through animation
1006 application.SendNotification(); // Handle any signals
1009 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1010 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
1012 application.Render(2001u); // end
1013 application.SendNotification(); // ensure animation finished signal is sent
1015 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1016 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1018 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1019 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1020 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1025 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." );
1028 map["target"] = "testVisual";
1029 map["property"] = Visual::Property::OPACITY;
1030 map["targetValue"] = 0.1f;
1031 map["animator"] = Property::Map()
1032 .Add("alphaFunction", "LINEAR")
1033 .Add("timePeriod", Property::Map()
1035 .Add("duration", 4.0f));
1037 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1038 Animation animation = dummyImpl.CreateTransition( transition );
1041 glEnableStack.Reset();
1043 application.SendNotification();
1044 application.Render(0); // Ensure animation starts
1045 application.Render(2000u); // Halfway point
1046 application.SendNotification();
1049 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1050 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
1052 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1054 glEnableStack.Reset();
1056 application.Render(2016u); // end
1057 application.SendNotification();
1059 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1060 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
1062 // GL_BLEND should not be changed: Keep enabled
1064 // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
1065 // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1066 DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1074 int UtcDaliImageVisualAnimateOpacity02(void)
1076 ToolkitTestApplication application;
1077 tet_infoline( "Animate image visual opacity" );
1079 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1081 VisualFactory factory = VisualFactory::Get();
1082 Property::Map propertyMap;
1083 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1084 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1085 propertyMap.Insert("opacity", 0.5f);
1086 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1087 Visual::Base visual = factory.CreateVisual( propertyMap );
1089 DummyControl actor = DummyControl::New(true);
1090 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1091 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1093 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1094 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1095 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1097 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
1099 Property::Array array;
1102 map["target"] = "testVisual";
1103 map["property"] = "opacity";
1104 map["initialValue"] = 0.0f;
1105 map["targetValue"] = 1.0f;
1106 map["animator"] = Property::Map()
1107 .Add("alphaFunction", "LINEAR")
1108 .Add("timePeriod", Property::Map()
1110 .Add("duration", 4.0f));
1113 map2["target"] = "testVisual";
1114 map2["property"] = "size";
1115 map2["targetValue"] = Vector2(1.0f, 1.0f);
1117 array.Add( map ).Add(map2);
1119 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
1120 Animation animation = dummyImpl.CreateTransition( transition );
1122 application.GetScene().Add(actor);
1123 application.SendNotification();
1124 application.Render(0); // Ensure animation starts
1126 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1128 Renderer renderer = actor.GetRendererAt(0);
1129 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
1130 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
1132 animation = dummyImpl.CreateTransition( transition );
1135 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1136 glAbstraction.EnableEnableDisableCallTrace( true );
1137 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1138 std::ostringstream blendStr;
1139 blendStr << std::hex << GL_BLEND;
1141 application.SendNotification();
1142 application.Render(0); // Ensure animation starts
1143 application.Render(2000u); // Halfway point through animation
1144 application.SendNotification(); // Handle any signals
1146 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
1149 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1150 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
1152 glEnableStack.Reset();
1154 application.Render(2001u); // end
1155 application.SendNotification(); // ensure animation finished signal is sent
1157 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
1158 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
1160 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
1167 int UtcDaliImageVisualAnimatePixelArea(void)
1169 ToolkitTestApplication application;
1170 tet_infoline( "ImageVisual animate pixel area" );
1172 static std::vector<UniformData> customUniforms =
1174 UniformData("pixelArea", Property::Type::VECTOR4),
1177 TestGraphicsController& graphics = application.GetGraphicsController();
1178 graphics.AddCustomUniforms(customUniforms);
1180 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
1182 VisualFactory factory = VisualFactory::Get();
1183 Property::Map propertyMap;
1184 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
1185 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1186 propertyMap.Insert("mixColor", Color::BLUE);
1187 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
1188 Visual::Base visual = factory.CreateVisual( propertyMap );
1190 DummyControl actor = DummyControl::New(true);
1191 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1192 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1194 actor.SetProperty( Actor::Property::SIZE, Vector2(2000, 2000) );
1195 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1196 actor.SetProperty( Actor::Property::COLOR,Color::BLACK);
1197 application.GetScene().Add(actor);
1199 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1201 Renderer renderer = actor.GetRendererAt(0);
1202 Property::Index index = renderer.GetPropertyIndex( Visual::Property::MIX_COLOR );
1204 tet_infoline("Test that the renderer has the mixColor property");
1205 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1207 // TransitionData only takes string keys
1209 map["target"] = "testVisual";
1210 map["property"] = "pixelArea";
1211 map["initialValue"] = Vector4( 0,0,0,1 );
1212 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1213 map["animator"] = Property::Map()
1214 .Add("alphaFunction", "LINEAR")
1215 .Add("timePeriod", Property::Map()
1217 .Add("duration", 4.0f));
1219 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1221 Animation animation = dummyImpl.CreateTransition( transition );
1222 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1225 application.SendNotification();
1226 application.Render(0); // Ensure animation starts
1227 application.Render(2000u); // Halfway point
1229 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1231 application.Render(2000u); // End of animation
1233 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1238 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1240 ToolkitTestApplication application;
1241 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1243 Property::Map propertyMap;
1244 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1245 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1247 TestGlAbstraction& gl = application.GetGlAbstraction();
1248 TraceCallStack& textureTrace = gl.GetTextureTrace();
1249 textureTrace.Enable(true);
1250 TraceCallStack& drawTrace = gl.GetDrawTrace();
1251 drawTrace.Enable(true);
1253 Actor actor = CreateActorWithImageVisual( propertyMap );
1254 application.GetScene().Add( actor );
1255 application.SendNotification();
1257 application.GetScene().Remove( actor );
1258 application.SendNotification();
1260 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1261 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1262 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1263 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1268 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1270 ToolkitTestApplication application;
1271 tet_infoline( "Load image asynchronously, cancel loading, then load again" );
1273 VisualFactory factory = VisualFactory::Get();
1274 DALI_TEST_CHECK( factory );
1276 Property::Map propertyMap;
1277 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1278 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1280 Visual::Base visual = factory.CreateVisual( propertyMap );
1281 DALI_TEST_CHECK( visual );
1283 TestGlAbstraction& gl = application.GetGlAbstraction();
1284 TraceCallStack& textureTrace = gl.GetTextureTrace();
1285 textureTrace.Enable( true );
1286 TraceCallStack& drawTrace = gl.GetDrawTrace();
1287 drawTrace.Enable( true );
1289 DummyControl actor = DummyControl::New();
1290 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1291 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1293 application.GetScene().Add( actor );
1296 application.GetScene().Remove( actor );
1298 application.GetScene().Add( actor );
1300 // Create another visual with the same image
1301 visual = factory.CreateVisual( propertyMap );
1302 DALI_TEST_CHECK( visual );
1304 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1306 application.SendNotification();
1307 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1309 application.SendNotification();
1310 application.Render();
1312 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1313 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1314 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1315 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1320 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1322 ToolkitTestApplication application;
1323 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1325 VisualFactory factory = VisualFactory::Get();
1326 DALI_TEST_CHECK( factory );
1328 Property::Map propertyMap;
1329 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1330 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1332 Visual::Base visual = factory.CreateVisual( propertyMap );
1333 DALI_TEST_CHECK( visual );
1335 TestGlAbstraction& gl = application.GetGlAbstraction();
1336 TraceCallStack& textureTrace = gl.GetTextureTrace();
1337 textureTrace.Enable(true);
1339 DummyControl actor = DummyControl::New();
1340 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1341 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1343 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1344 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1346 application.GetScene().Add( actor );
1348 application.SendNotification();
1349 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1351 application.SendNotification();
1352 application.Render();
1354 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1355 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1357 application.GetScene().Remove( actor );
1358 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1363 int UtcDaliImageVisualSetInvalidSyncImage(void)
1365 ToolkitTestApplication application;
1366 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1368 VisualFactory factory = VisualFactory::Get();
1369 DALI_TEST_CHECK( factory );
1371 Property::Map propertyMap;
1372 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1373 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1374 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1376 Visual::Base visual = factory.CreateVisual( propertyMap );
1377 DALI_TEST_CHECK( visual );
1379 TestGlAbstraction& gl = application.GetGlAbstraction();
1380 TraceCallStack& textureTrace = gl.GetTextureTrace();
1381 textureTrace.Enable(true);
1383 DummyControl actor = DummyControl::New();
1384 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1385 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1387 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1388 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1390 application.GetScene().Add( actor );
1392 application.SendNotification();
1393 application.Render();
1395 // Check resource status
1396 Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1);
1397 DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION);
1399 // The broken image should be shown.
1400 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1401 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1403 application.GetScene().Remove( actor );
1404 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1409 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1411 ToolkitTestApplication application;
1412 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1414 VisualFactory factory = VisualFactory::Get();
1415 DALI_TEST_CHECK( factory );
1417 // Local invalid file, asynchronous loading
1418 Property::Map propertyMap;
1419 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1420 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1422 Visual::Base visual = factory.CreateVisual( propertyMap );
1423 DALI_TEST_CHECK( visual );
1425 TestGlAbstraction& gl = application.GetGlAbstraction();
1426 TraceCallStack& textureTrace = gl.GetTextureTrace();
1427 textureTrace.Enable(true);
1429 DummyControl actor = DummyControl::New();
1430 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1431 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1433 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1434 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1436 application.GetScene().Add( actor );
1438 application.SendNotification();
1439 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1441 application.SendNotification();
1442 application.Render();
1444 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1445 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1447 application.GetScene().Remove( actor );
1448 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1453 int UtcDaliImageVisualAlphaMask(void)
1455 ToolkitTestApplication application;
1456 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1458 VisualFactory factory = VisualFactory::Get();
1459 DALI_TEST_CHECK( factory );
1461 Property::Map propertyMap;
1462 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1463 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1464 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1466 Visual::Base visual = factory.CreateVisual( propertyMap );
1467 DALI_TEST_CHECK( visual );
1469 Property::Map testMap;
1470 visual.CreatePropertyMap(testMap);
1471 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1473 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1474 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1476 TestGlAbstraction& gl = application.GetGlAbstraction();
1477 TraceCallStack& textureTrace = gl.GetTextureTrace();
1478 textureTrace.Enable(true);
1480 DummyControl actor = DummyControl::New();
1481 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1482 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1484 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1485 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1486 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1488 application.GetScene().Add( actor );
1489 application.SendNotification();
1490 application.Render();
1492 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1494 application.SendNotification();
1495 application.Render();
1497 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1498 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1499 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1501 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1502 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1507 int UtcDaliImageVisualSynchronousLoadAlphaMask(void)
1509 ToolkitTestApplication application;
1510 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" );
1512 VisualFactory factory = VisualFactory::Get();
1513 DALI_TEST_CHECK( factory );
1515 Property::Map propertyMap;
1516 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1517 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1518 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1519 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1521 Visual::Base visual = factory.CreateVisual( propertyMap );
1522 DALI_TEST_CHECK( visual );
1524 Property::Map testMap;
1525 visual.CreatePropertyMap(testMap);
1526 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1528 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1529 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1531 TestGlAbstraction& gl = application.GetGlAbstraction();
1532 TraceCallStack& textureTrace = gl.GetTextureTrace();
1533 textureTrace.Enable(true);
1535 DummyControl actor = DummyControl::New();
1536 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1537 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1539 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1540 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1541 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1543 application.GetScene().Add( actor );
1545 // Do not wait for any EventThreadTrigger in synchronous alpha mask.
1547 application.SendNotification();
1548 application.Render();
1550 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1551 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1552 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1554 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1555 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1560 int UtcDaliImageVisualRemoteAlphaMask(void)
1562 ToolkitTestApplication application;
1563 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1565 VisualFactory factory = VisualFactory::Get();
1566 DALI_TEST_CHECK( factory );
1568 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1570 Property::Map propertyMap;
1571 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1572 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1573 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE );
1575 Visual::Base visual = factory.CreateVisual( propertyMap );
1576 DALI_TEST_CHECK( visual );
1578 Property::Map testMap;
1579 visual.CreatePropertyMap(testMap);
1581 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1583 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1584 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1586 TestGlAbstraction& gl = application.GetGlAbstraction();
1587 TraceCallStack& textureTrace = gl.GetTextureTrace();
1588 textureTrace.Enable(true);
1590 DummyControl actor = DummyControl::New();
1591 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1592 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1594 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1596 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1597 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1599 application.GetScene().Add( actor );
1600 application.SendNotification();
1601 application.Render();
1603 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1605 application.SendNotification();
1606 application.Render();
1608 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1609 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1610 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1615 int UtcDaliImageVisualAlphaMaskCrop(void)
1617 ToolkitTestApplication application;
1618 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
1620 VisualFactory factory = VisualFactory::Get();
1621 DALI_TEST_CHECK( factory );
1623 Property::Map propertyMap;
1624 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1625 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1626 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1627 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1628 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1630 Visual::Base visual = factory.CreateVisual( propertyMap );
1631 DALI_TEST_CHECK( visual );
1633 Property::Map testMap;
1634 visual.CreatePropertyMap(testMap);
1635 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1636 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1637 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1639 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1640 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1642 TestGlAbstraction& gl = application.GetGlAbstraction();
1643 TraceCallStack& textureTrace = gl.GetTextureTrace();
1644 textureTrace.Enable(true);
1646 DummyControl actor = DummyControl::New();
1647 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1648 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1650 actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
1651 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1652 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1654 application.GetScene().Add( actor );
1655 application.SendNotification();
1656 application.Render();
1658 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
1660 application.SendNotification();
1661 application.Render();
1664 visual.GetNaturalSize(size);
1666 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1667 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1668 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1669 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1674 int UtcDaliImageVisualReleasePolicy01(void)
1676 ToolkitTestApplication application;
1677 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1679 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1680 DALI_TEST_CHECK( imageVisual );
1682 // Set up debug trace
1683 TestGlAbstraction& gl = application.GetGlAbstraction();
1684 TraceCallStack& textureTrace = gl.GetTextureTrace();
1685 textureTrace.Enable(true);
1687 tet_infoline( "Register visual with control and ensure it has the only handle" );
1688 DummyControl actor = DummyControl::New(true);
1689 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1690 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1691 imageVisual.Reset();
1693 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1695 application.SendNotification();
1696 application.Render(0);
1697 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1698 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1700 application.GetScene().Add( actor );
1702 // Wait for image to load
1703 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1705 application.SendNotification();
1706 application.Render(0);
1707 // Test renderer and texture created
1708 tet_infoline( "Confirm texture created" );
1709 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1710 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1712 tet_infoline( "Disable visual causing the texture to be deleted" );
1713 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1715 application.SendNotification();
1716 application.Render(0);
1717 // Test renderer and textures removed.
1718 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1719 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1724 int UtcDaliImageVisualReleasePolicy02(void)
1726 ToolkitTestApplication application;
1727 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1729 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1730 DALI_TEST_CHECK( imageVisual );
1732 // Setup debug trace
1733 TestGlAbstraction& gl = application.GetGlAbstraction();
1734 TraceCallStack& textureTrace = gl.GetTextureTrace();
1735 textureTrace.Enable(true);
1737 tet_infoline( "Register visual with control and ensure it has the only handle" );
1738 DummyControl actor = DummyControl::New(true);
1739 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1740 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1741 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1743 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1745 application.SendNotification();
1746 application.Render(0);
1747 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1748 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1750 application.GetScene().Add( actor );
1752 // Wait for image to load
1753 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1755 application.SendNotification();
1756 application.Render(0);
1757 // Test renderer and texture created
1758 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1759 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1762 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1763 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1764 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1765 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1766 application.SendNotification();
1767 application.Render();
1769 // Test texture removed after visual destroyed.
1770 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1771 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1776 int UtcDaliImageVisualReleasePolicy03(void)
1778 ToolkitTestApplication application;
1779 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1781 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1782 DALI_TEST_CHECK( imageVisual );
1784 TestGlAbstraction& gl = application.GetGlAbstraction();
1785 TraceCallStack& textureTrace = gl.GetTextureTrace();
1786 textureTrace.Enable(true);
1788 tet_infoline( "Register visual with control and ensure it has the only handle" );
1789 DummyControl actor = DummyControl::New(true);
1790 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1791 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1792 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1794 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1796 application.SendNotification();
1797 application.Render(0);
1798 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1799 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1801 application.GetScene().Add( actor );
1803 // Wait for image to load
1804 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1806 application.SendNotification();
1807 application.Render(0);
1808 // Test renderer and texture created
1809 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1810 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1812 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1813 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1814 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1815 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1816 application.SendNotification();
1817 application.Render();
1819 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1820 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1825 int UtcDaliImageVisualReleasePolicy04(void)
1827 ToolkitTestApplication application;
1828 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1830 tet_infoline( "Create first visual with Never release policy" );
1831 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1833 tet_infoline( "Create second visual with Destroyed release policy");
1834 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1836 // Set up trace debug
1837 TestGlAbstraction& gl = application.GetGlAbstraction();
1838 TraceCallStack& textureTrace = gl.GetTextureTrace();
1839 textureTrace.Enable(true);
1841 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1842 DummyControl actor = DummyControl::New(true);
1843 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1844 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1845 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1846 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1847 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1849 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1851 // Test initially zero renderers
1852 application.SendNotification();
1853 application.Render(0);
1854 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1855 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1857 application.GetScene().Add( actor );
1859 // Wait for image to load
1860 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1862 application.SendNotification();
1863 application.Render(0);
1864 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1865 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1866 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1868 // Test renderer removed when visual destroyed
1869 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1870 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1871 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1872 application.SendNotification();
1873 application.Render();
1875 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1876 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1878 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1879 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1880 application.SendNotification();
1881 application.Render();
1883 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1884 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1885 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1890 int UtcDaliImageVisualReleasePolicy05(void)
1892 ToolkitTestApplication application;
1893 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1895 VisualFactory factory = VisualFactory::Get();
1897 Property::Map propertyMapNeverReleasePolicy;
1898 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1899 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1900 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1901 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1902 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1904 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1906 Property::Map resultMap;
1907 imageVisualNever.CreatePropertyMap( resultMap );
1908 DALI_TEST_CHECK( ! resultMap.Empty() );
1910 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1915 int UtcDaliImageVisualReleasePolicy06(void)
1917 ToolkitTestApplication application;
1918 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1920 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1921 DALI_TEST_CHECK( imageVisual );
1923 TestGlAbstraction& gl = application.GetGlAbstraction();
1924 TraceCallStack& textureTrace = gl.GetTextureTrace();
1925 textureTrace.Enable(true);
1927 tet_infoline( "Register visual with control and ensure it has the only handle" );
1928 DummyControl actor = DummyControl::New(true);
1929 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1930 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1931 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1933 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
1935 application.SendNotification();
1936 application.Render(0);
1937 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1938 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1940 application.GetScene().Add( actor );
1942 // Wait for image to load
1943 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1945 application.SendNotification();
1946 application.Render(0);
1947 // Test renderer and texture created
1948 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1949 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1950 textureTrace.Reset();
1952 tet_infoline( "Disable Visual and check texture not affected" );
1953 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1954 application.SendNotification();
1955 application.Render(0);
1956 tet_infoline( "Check renderer is destroyed when visual off stage" );
1957 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1958 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1959 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1960 textureTrace.Reset();
1962 tet_infoline( "Re-enable Visual and check texture not affected" );
1963 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1964 application.SendNotification();
1965 application.Render(0);
1966 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1967 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1968 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1969 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1974 int UtcDaliImageVisualReleasePolicy07(void)
1976 ToolkitTestApplication application;
1977 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1979 tet_infoline( "Create first visual with DESTROYED release policy" );
1980 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1983 tet_infoline( "Create second visual with DETACHED release policy");
1984 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1986 // Set up trace debug
1987 TestGlAbstraction& gl = application.GetGlAbstraction();
1988 TraceCallStack& textureTrace = gl.GetTextureTrace();
1989 textureTrace.Enable(true);
1991 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1992 DummyControl actor = DummyControl::New(true);
1993 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1994 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1995 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1996 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1997 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1999 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2001 // Test initially zero renderers
2002 application.SendNotification();
2003 application.Render(0);
2004 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2005 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2007 application.GetScene().Add( actor );
2009 // Wait for image to load
2010 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2012 application.SendNotification();
2013 application.Render(0);
2014 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
2015 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
2016 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2018 // Test renderer removed when visual destroyed
2019 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
2020 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
2021 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2022 application.SendNotification();
2023 application.Render();
2025 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
2026 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
2028 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
2029 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2030 application.SendNotification();
2031 application.Render();
2033 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
2034 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
2039 int UtcDaliImageVisualReleasePolicy08(void)
2041 ToolkitTestApplication application;
2042 tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" );
2044 tet_infoline( "Create first visual with DESTROYED release policy" );
2045 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
2047 // Set up trace debug
2048 TestGlAbstraction& gl = application.GetGlAbstraction();
2049 TraceCallStack& textureTrace = gl.GetTextureTrace();
2050 textureTrace.Enable(true);
2052 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2053 DummyControl actor = DummyControl::New(true);
2054 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2055 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
2056 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
2058 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2060 // Test initially zero renderers
2061 application.SendNotification();
2062 application.Render(0);
2063 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2064 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2065 textureTrace.Reset();
2067 application.GetScene().Add( actor );
2069 // Wait for image to load
2070 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2072 application.SendNotification();
2073 application.Render(0);
2074 tet_infoline( "Ensure a texture is created" );
2075 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2076 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2077 textureTrace.Reset();
2079 // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy
2080 // 1. Get TextureSet
2081 TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures();
2083 // 2.Remove actor from stage. In this case, renderer also is deleted.
2084 tet_infoline( "Remove actor from stage" );
2085 application.GetScene().Remove( actor );
2086 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2087 application.SendNotification();
2088 application.Render();
2090 tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" );
2091 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
2092 textureTrace.Reset();
2094 // 3.Add actor in stage. In this case, renderer is created.
2095 tet_infoline( "Add actor in stage" );
2096 application.GetScene().Add( actor );
2097 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2098 application.SendNotification();
2099 application.Render();
2100 tet_infoline( "Ensure a texture is not created again" );
2101 DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION );
2102 textureTrace.Reset();
2104 // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED.
2105 tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" );
2106 TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures();
2107 DALI_TEST_CHECK( textureSetBefore == textureSetAfter );
2108 textureSetBefore.Reset();
2109 textureSetAfter.Reset();
2111 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2112 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2113 application.SendNotification();
2114 application.Render();
2115 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2120 int UtcDaliImageVisualLoadPolicy01(void)
2122 ToolkitTestApplication application;
2123 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
2125 // Set up trace debug
2126 TestGlAbstraction& gl = application.GetGlAbstraction();
2127 TraceCallStack& textureTrace = gl.GetTextureTrace();
2128 textureTrace.Enable(true);
2130 tet_infoline( "Create visual with IMMEDIATE load policy" );
2131 VisualFactory factory = VisualFactory::Get();
2133 Property::Map propertyMap;
2134 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2135 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2136 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
2137 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
2138 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
2140 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2142 Property::Map resultMap;
2143 imageVisual.CreatePropertyMap( resultMap );
2144 DALI_TEST_CHECK( ! resultMap.Empty() );
2145 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
2147 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2149 // Ensure texture has been uploaded
2150 application.SendNotification();
2151 application.Render();
2153 tet_infoline( "Ensure texture loading starts after visual created" );
2154 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2155 textureTrace.Reset();
2157 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2158 DummyControl actor = DummyControl::New(true);
2159 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2160 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2161 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2163 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2164 application.GetScene().Add( actor );
2165 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
2166 const unsigned int TIME_OUT_3_SECONDS = 3;
2167 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2169 application.SendNotification();
2170 application.Render();
2172 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2173 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2175 // Ensure texture is deleted when no longer needed (ref count was correct )
2176 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2178 application.SendNotification();
2179 application.Render();
2181 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2182 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2187 int UtcDaliImageVisualLoadPolicy02(void)
2189 ToolkitTestApplication application;
2190 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
2192 // Set up trace debug
2193 TestGlAbstraction& gl = application.GetGlAbstraction();
2194 TraceCallStack& textureTrace = gl.GetTextureTrace();
2195 textureTrace.Enable(true);
2197 tet_infoline( "Create visual with IMMEDIATE load policy" );
2198 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2200 const unsigned int TIME_OUT_3_SECONDS = 3;
2201 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
2203 // Act on meeage queue even although nothing expected to load
2204 application.SendNotification();
2205 application.Render();
2207 tet_infoline( "Ensure texture is not generated yet" );
2208 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
2209 textureTrace.Reset();
2211 tet_infoline( "Register visuals with control and ensure it has the only handles" );
2212 DummyControl actor = DummyControl::New(true);
2213 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2214 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2215 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2217 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2218 application.GetScene().Add( actor );
2219 tet_infoline( "Allow image time to load" );
2220 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2222 application.SendNotification();
2223 application.Render();
2225 tet_infoline( "Ensure texture generated and renderer created" );
2226 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
2227 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2229 // Ensure texture is delete when no longer needed
2230 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2232 application.SendNotification();
2233 application.Render();
2235 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
2236 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
2241 int UtcDaliImageVisualLoadPolicy03(void)
2243 ToolkitTestApplication application;
2244 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
2246 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
2248 // Set up trace debug
2249 TestGlAbstraction& gl = application.GetGlAbstraction();
2250 TraceCallStack& textureTrace = gl.GetTextureTrace();
2251 textureTrace.Enable(true);
2253 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
2254 DummyControl actor = DummyControl::New(true);
2255 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2256 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2257 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2259 tet_infoline( "Create visual with IMMEDIATE load policy" );
2260 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2262 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
2263 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2264 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2266 tet_infoline( "Allow image time to load resource" );
2267 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2268 application.SendNotification();
2269 application.Render();
2271 // Ensure texture has been uploaded
2272 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2273 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2278 int UtcDaliImageVisualLoadPolicy04(void)
2280 ToolkitTestApplication application;
2281 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
2282 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2284 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
2286 // Set up trace debug
2287 TestGlAbstraction& gl = application.GetGlAbstraction();
2288 TraceCallStack& textureTrace = gl.GetTextureTrace();
2289 textureTrace.Enable(true);
2291 tet_infoline( "Create a control and connect to resource ready signal" );
2292 DummyControl actor = DummyControl::New(true);
2293 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2294 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2295 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2297 tet_infoline( "Create visual with IMMEDIATE load policy" );
2298 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2300 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2301 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
2302 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2304 tet_infoline( "Allow image time to load" );
2305 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2306 application.SendNotification();
2307 application.Render();
2309 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2310 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2311 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2313 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2315 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2316 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2317 DummyControl actor2 = DummyControl::New(true);
2318 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2319 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2321 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2322 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2323 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2324 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2325 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2326 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2331 int UtcDaliImageVisualLoadPolicy05(void)
2333 ToolkitTestApplication application;
2334 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2335 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2336 // Set up trace debug
2337 TestGlAbstraction& gl = application.GetGlAbstraction();
2338 TraceCallStack& textureTrace = gl.GetTextureTrace();
2339 textureTrace.Enable(true);
2341 tet_infoline( "Create a control and connect to resource ready signal" );
2342 DummyControl actor = DummyControl::New(true);
2343 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2344 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2345 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2346 application.GetScene().Add( actor );
2348 tet_infoline( "Create visual with ATTACHED load policy" );
2349 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2351 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2352 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2353 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2355 tet_infoline( "Allow image time to load" );
2356 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2357 application.SendNotification();
2358 application.Render();
2360 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2361 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2362 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2364 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2366 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2367 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2368 DummyControl actor2 = DummyControl::New(true);
2369 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2370 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2372 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2373 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2374 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2375 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2376 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2377 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2383 int UtcDaliImageVisualOrientationCorrection(void)
2385 ToolkitTestApplication application;
2386 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2388 VisualFactory factory = VisualFactory::Get();
2389 tet_infoline( "Create visual with Orientation correction set OFF" );
2390 Property::Map propertyMap;
2391 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2392 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2393 propertyMap.Insert( "orientationCorrection", false );
2394 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2396 tet_infoline( "Create control for visual, need to loaded it" );
2397 DummyControl actor = DummyControl::New(true);
2398 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2399 application.GetScene().Add( actor );
2401 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2402 // Wait for image to load
2403 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2405 Vector2 originalImageSize;
2406 tet_infoline( "Get size of original visual to compare later with rotated image" );
2407 imageVisual.GetNaturalSize( originalImageSize );
2408 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2409 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2410 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2411 application.SendNotification();
2412 application.Render();
2414 tet_infoline( "Create visual with Orientation correction set ON " );
2415 propertyMap.Clear();
2416 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2417 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2418 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2419 imageVisual = factory.CreateVisual( propertyMap );
2421 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2422 // Wait for image to load
2423 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2425 Vector2 rotatedImageSize;
2426 imageVisual.GetNaturalSize( rotatedImageSize );
2427 tet_infoline( "Confirm that visual has rotated" );
2428 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2429 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2431 Property::Map resultMap;
2432 imageVisual.CreatePropertyMap( resultMap );
2434 // check the Property::ORIENTATION_CORRECTION value from the returned map
2435 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2436 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2441 int UtcDaliImageVisualCustomShader(void)
2443 ToolkitTestApplication application;
2444 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2446 VisualFactory factory = VisualFactory::Get();
2447 Property::Map properties;
2448 Property::Map shader;
2449 const std::string vertexShader = "Foobar";
2450 const std::string fragmentShader = "Foobar";
2451 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2452 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2454 properties[Visual::Property::TYPE] = Visual::IMAGE;
2455 properties[Visual::Property::SHADER] = shader;
2456 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2458 Visual::Base visual = factory.CreateVisual( properties );
2460 // trigger creation through setting on stage
2461 DummyControl dummy = DummyControl::New( true );
2462 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2463 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2465 dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2466 dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2467 application.GetScene().Add( dummy );
2469 application.SendNotification();
2470 application.Render();
2472 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2474 Renderer renderer = dummy.GetRendererAt( 0 );
2475 Shader shader2 = renderer.GetShader();
2476 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2477 Property::Map* map = value.GetMap();
2478 DALI_TEST_CHECK( map );
2480 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2481 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2483 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2484 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2488 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2489 properties[Visual::Property::SHADER] = shader;
2491 Visual::Base visual1 = factory.CreateVisual( properties );
2493 // trigger creation through setting on stage
2494 DummyControl dummy1 = DummyControl::New( true );
2495 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2496 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2497 dummy1.SetProperty( Actor::Property::SIZE, Vector2( 200, 200 ) );
2498 dummy1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
2499 application.GetScene().Add( dummy1 );
2501 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2502 glAbstraction.EnableEnableDisableCallTrace( true );
2504 application.SendNotification();
2505 application.Render();
2507 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2508 std::ostringstream blendStr;
2509 blendStr << std::hex << GL_BLEND;
2510 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
2516 void ResourceReadyLoadNext( Control control )
2518 static int callNumber = 0;
2520 gResourceReadySignalFired = true;
2521 gReadyIds.push_back(control.GetProperty< int >( Actor::Property::ID ));
2523 if( callNumber == 0 )
2525 DALI_TEST_EQUALS( control.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL), Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION );
2527 tet_infoline( "Create visual with loaded image from within the signal handler" );
2528 VisualFactory factory = VisualFactory::Get();
2529 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions{20,30} );
2531 Impl::DummyControl& controlImpl = static_cast<Impl::DummyControl&>(control.GetImplementation());
2532 controlImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual ); // This should trigger another signal.
2537 tet_infoline( "3rd signal called" );
2538 DALI_TEST_CHECK(true);
2542 int UtcDaliImageVisualLoadReady01(void)
2544 ToolkitTestApplication application;
2545 tet_infoline( "UtcDaliImageVisualLoadReady01");
2546 tet_infoline( "First part: Load an image visual for one resource, then another image visual for a second resource.");
2547 tet_infoline( "Second part, In the ready signal for the second image visual, add a 3rd visual with the first URL" );
2548 tet_infoline( "Should get a ready signal for all three visuals");
2552 tet_infoline( "Create a control and connect to resource ready signal" );
2553 DummyControl actor = DummyControl::New(true);
2554 int actor1Id = actor.GetProperty< int >( Actor::Property::ID );
2555 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2556 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2557 actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2558 application.GetScene().Add(actor);
2560 tet_infoline( "Create visual with IMMEDIATE load policy" );
2561 Visual::Base imageVisual1 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2563 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
2564 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual1 );
2567 tet_infoline( "Allow image time to load" );
2568 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2569 application.SendNotification();
2570 application.Render();
2572 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2573 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2574 DALI_TEST_EQUALS( gReadyIds[0], actor1Id, TEST_LOCATION );
2577 tet_infoline( "Original control correctly signalled, now testing failing image" );
2579 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2582 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_BROKEN_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
2584 DummyControl actor2 = DummyControl::New(true);
2585 int actor2Id = actor2.GetProperty< int >( Actor::Property::ID );
2586 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor2.GetImplementation());
2587 actor2.ResourceReadySignal().Connect( &ResourceReadyLoadNext);
2589 tet_infoline( "Registering visual this should trigger the ready signal when the image fails to load" );
2590 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2592 actor2.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
2593 application.GetScene().Add(actor2);
2595 tet_infoline( "Wait for loading thread to finish");
2596 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2597 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2599 DALI_TEST_EQUALS( gReadyIds[0], actor2Id, TEST_LOCATION);
2601 tet_infoline( "Check for 3rd signal");
2602 application.SendNotification();
2603 DALI_TEST_EQUALS( gReadyIds.size(), 2, TEST_LOCATION );
2604 DALI_TEST_EQUALS( gReadyIds[1], actor2Id, TEST_LOCATION);