2 * Copyright (c) 2018 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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-event-thread-callback.h>
22 #include <dali/devel-api/object/handle-devel.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
33 void dali_image_visual_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_image_visual_cleanup(void)
40 test_return_value = TET_PASS;
45 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
46 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
47 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
48 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
49 const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg";
50 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
51 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
52 const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg";
55 bool gResourceReadySignalFired = false;
57 void ResourceReadySignal( Control control )
59 gResourceReadySignalFired = true;
62 Actor CreateActorWithImageVisual(const Property::Map& map)
64 VisualFactory factory = VisualFactory::Get();
65 DummyControl actor = DummyControl::New();
66 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
67 Visual::Base visual = factory.CreateVisual( map );
68 DALI_TEST_CHECK( visual );
69 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
70 actor.SetSize( 200.f, 200.f );
71 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
76 Visual::Base CreateVisualWithPolicy( const char* url, Property::Index key, const Property::Value& value )
78 VisualFactory factory = VisualFactory::Get();
80 Property::Map propertyMap;
81 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
82 propertyMap.Insert( ImageVisual::Property::URL, url );
83 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
84 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
85 propertyMap.Insert( key , value );
87 return factory.CreateVisual( propertyMap );
92 void TestVisualRender( ToolkitTestApplication& application,
95 std::size_t expectedSamplers = 0,
96 ImageDimensions imageDimensions = ImageDimensions(),
97 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
99 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
100 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
104 // set the image size, for test case, this needs to be set before loading started
105 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
108 actor.SetSize( 200.f, 200.f );
109 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
111 Stage::GetCurrent().Add( actor );
113 application.SendNotification(); // Send messages to update
114 application.Render(); // process update and render
115 application.SendNotification(); // process any signals to event
119 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
122 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
125 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
128 visual.CreatePropertyMap(map);
129 Property::Value* value = map.Find( mixColorIndex );
130 DALI_TEST_CHECK( value );
132 DALI_TEST_CHECK( value->Get( mixColor1 ) );
133 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
135 value = map.Find( Visual::Property::MIX_COLOR );
136 DALI_TEST_CHECK( value );
138 DALI_TEST_CHECK( value->Get( mixColor2 ) );
139 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
141 value = map.Find( Visual::Property::OPACITY );
142 DALI_TEST_CHECK( value );
144 DALI_TEST_CHECK( value->Get( opacity ) );
145 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
150 int UtcDaliImageVisualPropertyMap(void)
152 ToolkitTestApplication application;
153 tet_infoline( "Request image visual with a Property::Map" );
155 VisualFactory factory = VisualFactory::Get();
156 DALI_TEST_CHECK( factory );
157 factory.SetPreMultiplyOnLoad( true );
159 Property::Map propertyMap;
160 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
161 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
163 Visual::Base visual = factory.CreateVisual( propertyMap );
164 DALI_TEST_CHECK( visual );
166 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
167 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
169 TestGlAbstraction& gl = application.GetGlAbstraction();
170 TraceCallStack& textureTrace = gl.GetTextureTrace();
171 textureTrace.Enable(true);
173 DummyControl actor = DummyControl::New();
174 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
175 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
177 actor.SetSize( 200.f, 200.f );
178 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
180 Stage::GetCurrent().Add( actor );
181 application.SendNotification();
182 application.Render();
184 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
186 application.SendNotification();
187 application.Render();
189 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
190 auto renderer = actor.GetRendererAt(0);
191 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
192 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
193 auto preMultipliedAlpha = renderer.GetProperty<float>( preMultipliedIndex );
194 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
195 DALI_TEST_EQUALS( preMultipliedAlpha, 1.0f, TEST_LOCATION );
196 DALI_TEST_EQUALS( preMultipliedAlpha2, true, TEST_LOCATION );
197 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
199 Stage::GetCurrent().Remove( actor );
200 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
206 int UtcDaliImageVisualNoPremultipliedAlpha01(void)
208 ToolkitTestApplication application;
209 tet_infoline( "Request image visual without pre-multiplied alpha" );
211 VisualFactory factory = VisualFactory::Get();
212 DALI_TEST_CHECK( factory );
213 factory.SetPreMultiplyOnLoad( false );
215 Property::Map propertyMap;
216 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
217 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
219 Visual::Base visual = factory.CreateVisual( propertyMap );
220 DALI_TEST_CHECK( visual );
222 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
223 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
225 TestGlAbstraction& gl = application.GetGlAbstraction();
226 TraceCallStack& textureTrace = gl.GetTextureTrace();
227 textureTrace.Enable(true);
229 DummyControl actor = DummyControl::New();
230 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
231 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
233 actor.SetSize( 200.f, 200.f );
234 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
236 Stage::GetCurrent().Add( actor );
237 application.SendNotification();
238 application.Render();
240 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
242 application.SendNotification();
243 application.Render();
245 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
246 auto renderer = actor.GetRendererAt(0);
247 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
248 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
249 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
250 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
252 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
253 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
255 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
257 Stage::GetCurrent().Remove( actor );
258 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
264 int UtcDaliImageVisualNoPremultipliedAlpha02(void)
266 ToolkitTestApplication application;
267 tet_infoline( "Request image visual with no alpha channel" );
269 VisualFactory factory = VisualFactory::Get();
270 DALI_TEST_CHECK( factory );
272 Property::Map propertyMap;
273 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
274 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
276 Visual::Base visual = factory.CreateVisual( propertyMap );
277 DALI_TEST_CHECK( visual );
279 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
280 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
282 TestGlAbstraction& gl = application.GetGlAbstraction();
283 TraceCallStack& textureTrace = gl.GetTextureTrace();
284 textureTrace.Enable(true);
286 DummyControl actor = DummyControl::New();
287 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
288 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
290 actor.SetSize( 200.f, 200.f );
291 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
293 Stage::GetCurrent().Add( actor );
294 application.SendNotification();
295 application.Render();
297 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
299 application.SendNotification();
300 application.Render();
302 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
303 auto renderer = actor.GetRendererAt(0);
304 auto preMultipliedIndex = renderer.GetPropertyIndex( "preMultipliedAlpha" );
305 DALI_TEST_CHECK( preMultipliedIndex != Property::INVALID_INDEX );
306 auto preMultipliedAlpha = renderer.GetProperty<bool>( preMultipliedIndex );
307 auto preMultipliedAlpha2 = renderer.GetProperty<bool>( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
309 DALI_TEST_EQUALS( preMultipliedAlpha, false, TEST_LOCATION );
310 DALI_TEST_EQUALS( preMultipliedAlpha2, false, TEST_LOCATION );
312 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
314 Stage::GetCurrent().Remove( actor );
315 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
321 int UtcDaliImageVisualRemoteImageLoad(void)
323 ToolkitTestApplication application;
324 tet_infoline( "Request remote image visual with a Property::Map" );
326 VisualFactory factory = VisualFactory::Get();
327 DALI_TEST_CHECK( factory );
329 Property::Map propertyMap;
330 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
331 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
333 Visual::Base visual = factory.CreateVisual( propertyMap );
334 DALI_TEST_CHECK( visual );
336 TestGlAbstraction& gl = application.GetGlAbstraction();
337 TraceCallStack& textureTrace = gl.GetTextureTrace();
338 textureTrace.Enable(true);
340 DummyControl actor = DummyControl::New();
341 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
342 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
344 actor.SetSize( 200.f, 200.f );
345 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
347 Stage::GetCurrent().Add( actor );
348 application.SendNotification();
350 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
352 application.SendNotification();
353 application.Render();
355 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
356 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
358 Stage::GetCurrent().Remove( actor );
359 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
364 int UtcDaliImageVisualTextureReuse1(void)
366 ToolkitTestApplication application;
367 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
369 Property::Map propertyMap;
370 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
371 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
372 propertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
374 TestGlAbstraction& gl = application.GetGlAbstraction();
375 TraceCallStack& textureTrace = gl.GetTextureTrace();
376 textureTrace.Enable(true);
377 TraceCallStack& drawTrace = gl.GetDrawTrace();
378 drawTrace.Enable(true);
380 Actor actor = CreateActorWithImageVisual( propertyMap );
381 Stage::GetCurrent().Add( actor );
382 application.SendNotification();
384 // Wait for image to load
385 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
387 application.SendNotification();
388 application.Render();
390 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
391 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
392 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
393 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
394 textureTrace.Reset();
397 Actor actor2 = CreateActorWithImageVisual( propertyMap );
398 Stage::GetCurrent().Add(actor2);
400 application.SendNotification(); // Send messages to update
401 application.Render(); // process update and render
402 application.SendNotification(); // process any signals to event
404 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
406 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
407 "draw calls use the same texture as the previous draw call\n" );
409 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
410 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
411 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
413 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
415 Stage::GetCurrent().Remove( actor );
416 application.SendNotification();
417 application.Render();
419 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
420 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
422 tet_infoline("Test that removing last actor does delete the texture\n");
424 Stage::GetCurrent().Remove( actor2 ); // Detaches remaining ImageVisual
425 application.SendNotification();
426 application.Render();
428 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
429 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
435 int UtcDaliImageVisualTextureReuse2(void)
437 ToolkitTestApplication application;
438 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" );
440 Property::Map propertyMap;
441 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
442 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
444 TestGlAbstraction& gl = application.GetGlAbstraction();
445 TraceCallStack& textureTrace = gl.GetTextureTrace();
446 textureTrace.Enable(true);
447 TraceCallStack& drawTrace = gl.GetDrawTrace();
448 drawTrace.Enable(true);
450 Actor actor = CreateActorWithImageVisual( propertyMap );
451 Stage::GetCurrent().Add( actor );
452 application.SendNotification();
454 // Wait for image to load
455 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
457 application.SendNotification();
458 application.Render();
460 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
461 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
462 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
463 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
464 textureTrace.Reset();
467 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
468 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
469 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
470 Actor actor2 = CreateActorWithImageVisual( propertyMap );
471 Stage::GetCurrent().Add(actor2);
473 application.SendNotification();
475 // Wait for image to load
476 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
478 application.SendNotification();
479 application.Render();
481 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
483 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
484 "renderers are using different textures\n" );
486 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
487 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
488 TraceCallStack::NamedParams tex1;
489 tex1["texture"] = "1";
490 TraceCallStack::NamedParams tex2;
491 tex1["texture"] = "2";
492 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
493 DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
495 tet_infoline("Test that removing 1 actor deletes it's texture\n");
497 Stage::GetCurrent().Remove( actor );
498 application.SendNotification();
499 application.Render();
501 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
502 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
504 tet_infoline("Test that removing last actor deletes it's texture\n");
506 Stage::GetCurrent().Remove( actor2 );
507 application.SendNotification();
508 application.Render();
510 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
511 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
517 int UtcDaliImageVisualImageHandle(void)
519 ToolkitTestApplication application;
520 tet_infoline( "Request image visual with an image handle" );
522 VisualFactory factory = VisualFactory::Get();
523 DALI_TEST_CHECK( factory );
525 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
526 Visual::Base visual = factory.CreateVisual( image );
528 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
529 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
532 const int height=513;
534 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
535 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
537 TestGlAbstraction& gl = application.GetGlAbstraction();
538 TraceCallStack& textureTrace = gl.GetTextureTrace();
539 textureTrace.Enable(true);
541 DummyControl actor = DummyControl::New();
542 TestVisualRender( application, actor, visual, 1u,
543 ImageDimensions(width, height),
544 Integration::ResourcePointer(bitmap) );
546 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
550 int UtcDaliImageVisualCustomWrapModePixelArea(void)
552 ToolkitTestApplication application;
553 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
555 VisualFactory factory = VisualFactory::Get();
556 DALI_TEST_CHECK( factory );
558 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
561 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
563 Property::Map propertyMap;
564 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
565 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
566 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
567 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
568 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
569 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
570 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
571 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
572 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
574 Visual::Base visual = factory.CreateVisual( propertyMap );
575 DALI_TEST_CHECK( visual );
577 TestGlAbstraction& gl = application.GetGlAbstraction();
578 TraceCallStack& textureTrace = gl.GetTextureTrace();
579 textureTrace.Enable(true);
580 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
581 texParameterTrace.Enable( true );
583 DummyControl actor = DummyControl::New();
584 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
585 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
586 actor.SetSize(2000, 2000);
587 actor.SetParentOrigin(ParentOrigin::CENTER);
588 Stage::GetCurrent().Add( actor );
591 application.SendNotification();
592 application.Render();
594 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
596 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
598 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
599 std::stringstream out;
600 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
601 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
603 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
604 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
606 // test the uniforms which used to handle the wrap mode
607 Renderer renderer = actor.GetRendererAt( 0u );
608 DALI_TEST_CHECK( renderer );
610 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
611 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
612 Vector4 pixelAreaUniform;
613 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
614 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
616 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
617 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
618 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
619 Vector2 wrapModeUniform;
620 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
621 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
624 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
629 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
631 ToolkitTestApplication application;
632 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
634 VisualFactory factory = VisualFactory::Get();
635 DALI_TEST_CHECK( factory );
637 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
639 const int height=600;
640 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
642 Property::Map propertyMap;
643 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
644 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
645 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
646 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
647 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
648 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
649 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
650 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
652 Visual::Base visual = factory.CreateVisual( propertyMap );
653 DALI_TEST_CHECK( visual );
655 TestGlAbstraction& gl = application.GetGlAbstraction();
656 TraceCallStack& textureTrace = gl.GetTextureTrace();
657 textureTrace.Enable(true);
658 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
659 texParameterTrace.Enable( true );
661 DummyControl actor = DummyControl::New();
662 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
663 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
664 actor.SetSize(2000, 2000);
665 actor.SetParentOrigin(ParentOrigin::CENTER);
666 Stage::GetCurrent().Add( actor );
669 application.SendNotification();
670 application.Render();
672 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
674 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
676 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
677 std::stringstream out;
678 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
679 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
681 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
682 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
684 // test the uniforms which used to handle the wrap mode
685 Renderer renderer = actor.GetRendererAt( 0u );
686 DALI_TEST_CHECK( renderer );
688 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
689 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
690 Vector4 pixelAreaUniform;
691 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
692 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
694 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
695 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
698 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
703 int UtcDaliImageVisualAnimateMixColor(void)
705 ToolkitTestApplication application;
706 tet_infoline( "Animate mix color" );
708 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
710 VisualFactory factory = VisualFactory::Get();
711 Property::Map propertyMap;
712 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
713 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
714 propertyMap.Insert("mixColor", Color::BLUE);
715 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
716 Visual::Base visual = factory.CreateVisual( propertyMap );
718 DummyControl actor = DummyControl::New(true);
719 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
720 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
722 actor.SetSize(2000, 2000);
723 actor.SetParentOrigin(ParentOrigin::CENTER);
724 actor.SetColor(Color::BLACK);
725 Stage::GetCurrent().Add(actor);
727 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
729 Renderer renderer = actor.GetRendererAt(0);
730 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
731 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
732 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
734 tet_infoline("Test that the renderer has the mixColor property");
735 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
737 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
740 map["target"] = "testVisual";
741 map["property"] = "mixColor";
742 map["initialValue"] = Color::MAGENTA;
743 map["targetValue"] = TARGET_MIX_COLOR;
744 map["animator"] = Property::Map()
745 .Add("alphaFunction", "LINEAR")
746 .Add("timePeriod", Property::Map()
748 .Add("duration", 4.0f));
750 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
752 Animation animation = dummyImpl.CreateTransition( transition );
754 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
755 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
757 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
760 application.SendNotification();
761 application.Render(0); // Ensure animation starts
762 application.Render(2000u); // Halfway point
763 Vector3 testColor( 1.0f, 0.0f, 0.5f );
765 // uColor.a should be actor's alpha * mixColor.a.
766 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
767 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
769 application.Render(2000u); // Halfway point between blue and white
771 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
772 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ), true, TEST_LOCATION );
773 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", Vector3( TARGET_MIX_COLOR ) ), true, TEST_LOCATION );
775 TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
777 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
778 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
783 int UtcDaliImageVisualAnimateOpacity(void)
785 ToolkitTestApplication application;
786 tet_infoline( "Animate image visual opacity" );
788 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
790 VisualFactory factory = VisualFactory::Get();
791 Property::Map propertyMap;
792 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
793 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
794 propertyMap.Insert("opacity", 0.5f);
795 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
796 Visual::Base visual = factory.CreateVisual( propertyMap );
798 DummyControl actor = DummyControl::New(true);
799 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
800 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
802 actor.SetSize(2000, 2000);
803 actor.SetParentOrigin(ParentOrigin::CENTER);
804 actor.SetColor(Color::BLACK);
805 Stage::GetCurrent().Add(actor);
807 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
809 Renderer renderer = actor.GetRendererAt(0);
810 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
811 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
814 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." );
817 map["target"] = "testVisual";
818 map["property"] = "opacity";
819 map["targetValue"] = 1.0f;
820 map["animator"] = Property::Map()
821 .Add("alphaFunction", "LINEAR")
822 .Add("timePeriod", Property::Map()
824 .Add("duration", 4.0f));
826 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
827 Animation animation = dummyImpl.CreateTransition( transition );
830 application.SendNotification();
831 application.Render(0); // Ensure animation starts
832 application.Render(2000u); // Halfway point through animation
833 application.SendNotification(); // Handle any signals
836 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
837 DALI_TEST_EQUALS( color.a, 0.75f, TEST_LOCATION );
839 application.Render(2001u); // end
840 application.SendNotification(); // ensure animation finished signal is sent
842 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
843 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
845 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
846 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
851 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." );
854 map["target"] = "testVisual";
855 map["property"] = Visual::Property::OPACITY;
856 map["targetValue"] = 0.1f;
857 map["animator"] = Property::Map()
858 .Add("alphaFunction", "LINEAR")
859 .Add("timePeriod", Property::Map()
861 .Add("duration", 4.0f));
863 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
864 Animation animation = dummyImpl.CreateTransition( transition );
867 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
868 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
870 application.SendNotification();
871 application.Render(0); // Ensure animation starts
872 application.Render(2000u); // Halfway point
873 application.SendNotification();
876 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
877 DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
879 application.Render(2016u); // end
880 application.SendNotification();
882 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
883 DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
885 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
886 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
895 int UtcDaliImageVisualAnimateOpacity02(void)
897 ToolkitTestApplication application;
898 tet_infoline( "Animate image visual opacity" );
900 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
902 VisualFactory factory = VisualFactory::Get();
903 Property::Map propertyMap;
904 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
905 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
906 propertyMap.Insert("opacity", 0.5f);
907 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
908 Visual::Base visual = factory.CreateVisual( propertyMap );
910 DummyControl actor = DummyControl::New(true);
911 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
912 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
914 actor.SetSize(2000, 2000);
915 actor.SetParentOrigin(ParentOrigin::CENTER);
916 actor.SetColor(Color::BLACK);
918 tet_infoline( "Test that the opacity doesn't animate when actor not staged" );
920 Property::Array array;
923 map["target"] = "testVisual";
924 map["property"] = "opacity";
925 map["initialValue"] = 0.0f;
926 map["targetValue"] = 1.0f;
927 map["animator"] = Property::Map()
928 .Add("alphaFunction", "LINEAR")
929 .Add("timePeriod", Property::Map()
931 .Add("duration", 4.0f));
934 map2["target"] = "testVisual";
935 map2["property"] = "size";
936 map2["targetValue"] = Vector2(1.0f, 1.0f);
938 array.Add( map ).Add(map2);
940 Dali::Toolkit::TransitionData transition = TransitionData::New( array );
941 Animation animation = dummyImpl.CreateTransition( transition );
943 Stage::GetCurrent().Add(actor);
944 application.SendNotification();
945 application.Render(0); // Ensure animation starts
947 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
949 Renderer renderer = actor.GetRendererAt(0);
950 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
951 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
953 animation = dummyImpl.CreateTransition( transition );
956 application.SendNotification();
957 application.Render(0); // Ensure animation starts
958 application.Render(2000u); // Halfway point through animation
959 application.SendNotification(); // Handle any signals
961 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
962 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
965 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
966 DALI_TEST_EQUALS( color.a, 0.5f, TEST_LOCATION );
968 application.Render(2001u); // end
969 application.SendNotification(); // ensure animation finished signal is sent
971 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
972 DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
974 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
975 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
982 int UtcDaliImageVisualAnimatePixelArea(void)
984 ToolkitTestApplication application;
985 tet_infoline( "ImageVisual animate pixel area" );
987 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
989 VisualFactory factory = VisualFactory::Get();
990 Property::Map propertyMap;
991 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
992 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
993 propertyMap.Insert("mixColor", Color::BLUE);
994 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
995 Visual::Base visual = factory.CreateVisual( propertyMap );
997 DummyControl actor = DummyControl::New(true);
998 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
999 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1001 actor.SetSize(2000, 2000);
1002 actor.SetParentOrigin(ParentOrigin::CENTER);
1003 actor.SetColor(Color::BLACK);
1004 Stage::GetCurrent().Add(actor);
1006 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
1008 Renderer renderer = actor.GetRendererAt(0);
1009 Property::Index index = DevelHandle::GetPropertyIndex( renderer, Visual::Property::MIX_COLOR );
1011 tet_infoline("Test that the renderer has the mixColor property");
1012 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
1014 // TransitionData only takes string keys
1016 map["target"] = "testVisual";
1017 map["property"] = "pixelArea";
1018 map["initialValue"] = Vector4( 0,0,0,1 );
1019 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
1020 map["animator"] = Property::Map()
1021 .Add("alphaFunction", "LINEAR")
1022 .Add("timePeriod", Property::Map()
1024 .Add("duration", 4.0f));
1026 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
1028 Animation animation = dummyImpl.CreateTransition( transition );
1029 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
1032 application.SendNotification();
1033 application.Render(0); // Ensure animation starts
1034 application.Render(2000u); // Halfway point
1036 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
1038 application.Render(2000u); // End of animation
1040 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
1045 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
1047 ToolkitTestApplication application;
1048 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
1050 Property::Map propertyMap;
1051 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1052 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
1054 TestGlAbstraction& gl = application.GetGlAbstraction();
1055 TraceCallStack& textureTrace = gl.GetTextureTrace();
1056 textureTrace.Enable(true);
1057 TraceCallStack& drawTrace = gl.GetDrawTrace();
1058 drawTrace.Enable(true);
1060 Actor actor = CreateActorWithImageVisual( propertyMap );
1061 Stage::GetCurrent().Add( actor );
1062 application.SendNotification();
1064 Stage::GetCurrent().Remove( actor );
1065 application.SendNotification();
1067 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1068 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1069 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
1070 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
1075 int UtcDaliImageVisualTextureCancelAsyncLoad(void)
1077 ToolkitTestApplication application;
1078 tet_infoline( "Load image asynchronosly, cancel loading, then load again" );
1080 VisualFactory factory = VisualFactory::Get();
1081 DALI_TEST_CHECK( factory );
1083 Property::Map propertyMap;
1084 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1085 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1087 Visual::Base visual = factory.CreateVisual( propertyMap );
1088 DALI_TEST_CHECK( visual );
1090 TestGlAbstraction& gl = application.GetGlAbstraction();
1091 TraceCallStack& textureTrace = gl.GetTextureTrace();
1092 textureTrace.Enable( true );
1093 TraceCallStack& drawTrace = gl.GetDrawTrace();
1094 drawTrace.Enable( true );
1096 DummyControl actor = DummyControl::New();
1097 DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
1098 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1100 Stage::GetCurrent().Add( actor );
1103 Stage::GetCurrent().Remove( actor );
1105 Stage::GetCurrent().Add( actor );
1107 // Create another visual with the same image
1108 visual = factory.CreateVisual( propertyMap );
1109 DALI_TEST_CHECK( visual );
1111 dummyImpl.RegisterVisual( Control::Property::BACKGROUND, visual );
1113 application.SendNotification();
1114 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1116 application.SendNotification();
1117 application.Render();
1119 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1120 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1121 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1122 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
1127 int UtcDaliImageVisualSetInvalidAsyncImage(void)
1129 ToolkitTestApplication application;
1130 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1132 VisualFactory factory = VisualFactory::Get();
1133 DALI_TEST_CHECK( factory );
1135 Property::Map propertyMap;
1136 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1137 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1139 Visual::Base visual = factory.CreateVisual( propertyMap );
1140 DALI_TEST_CHECK( visual );
1142 TestGlAbstraction& gl = application.GetGlAbstraction();
1143 TraceCallStack& textureTrace = gl.GetTextureTrace();
1144 textureTrace.Enable(true);
1146 DummyControl actor = DummyControl::New();
1147 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1148 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1150 actor.SetSize( 200.f, 200.f );
1151 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1153 Stage::GetCurrent().Add( actor );
1155 application.SendNotification();
1156 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1158 application.SendNotification();
1159 application.Render();
1161 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1162 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1164 Stage::GetCurrent().Remove( actor );
1165 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1170 int UtcDaliImageVisualSetInvalidSyncImage(void)
1172 ToolkitTestApplication application;
1173 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1175 VisualFactory factory = VisualFactory::Get();
1176 DALI_TEST_CHECK( factory );
1178 Property::Map propertyMap;
1179 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1180 propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
1181 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
1183 Visual::Base visual = factory.CreateVisual( propertyMap );
1184 DALI_TEST_CHECK( visual );
1186 TestGlAbstraction& gl = application.GetGlAbstraction();
1187 TraceCallStack& textureTrace = gl.GetTextureTrace();
1188 textureTrace.Enable(true);
1190 DummyControl actor = DummyControl::New();
1191 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1192 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1194 actor.SetSize( 200.f, 200.f );
1195 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1197 Stage::GetCurrent().Add( actor );
1199 application.SendNotification();
1200 application.Render();
1202 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1203 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1205 Stage::GetCurrent().Remove( actor );
1206 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1211 int UtcDaliImageVisualSetInvalidRemoteImage(void)
1213 ToolkitTestApplication application;
1214 tet_infoline( "Request image visual with invalid images - should draw broken.png" );
1216 VisualFactory factory = VisualFactory::Get();
1217 DALI_TEST_CHECK( factory );
1219 // Local invalid file, asynchronous loading
1220 Property::Map propertyMap;
1221 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1222 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
1224 Visual::Base visual = factory.CreateVisual( propertyMap );
1225 DALI_TEST_CHECK( visual );
1227 TestGlAbstraction& gl = application.GetGlAbstraction();
1228 TraceCallStack& textureTrace = gl.GetTextureTrace();
1229 textureTrace.Enable(true);
1231 DummyControl actor = DummyControl::New();
1232 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1233 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1235 actor.SetSize( 200.f, 200.f );
1236 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1238 Stage::GetCurrent().Add( actor );
1240 application.SendNotification();
1241 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1243 application.SendNotification();
1244 application.Render();
1246 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1247 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1249 Stage::GetCurrent().Remove( actor );
1250 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1255 int UtcDaliImageVisualAlphaMask(void)
1257 ToolkitTestApplication application;
1258 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1260 VisualFactory factory = VisualFactory::Get();
1261 DALI_TEST_CHECK( factory );
1263 Property::Map propertyMap;
1264 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1265 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
1266 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1268 Visual::Base visual = factory.CreateVisual( propertyMap );
1269 DALI_TEST_CHECK( visual );
1271 Property::Map testMap;
1272 visual.CreatePropertyMap(testMap);
1273 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1275 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1276 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1278 TestGlAbstraction& gl = application.GetGlAbstraction();
1279 TraceCallStack& textureTrace = gl.GetTextureTrace();
1280 textureTrace.Enable(true);
1282 DummyControl actor = DummyControl::New();
1283 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1284 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1286 actor.SetSize( 200.f, 200.f );
1287 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1288 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1290 Stage::GetCurrent().Add( actor );
1291 application.SendNotification();
1292 application.Render();
1294 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1296 application.SendNotification();
1297 application.Render();
1299 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1300 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1301 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1303 dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 );
1304 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1309 int UtcDaliImageVisualRemoteAlphaMask(void)
1311 ToolkitTestApplication application;
1312 tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1314 VisualFactory factory = VisualFactory::Get();
1315 DALI_TEST_CHECK( factory );
1317 const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1319 Property::Map propertyMap;
1320 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
1321 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1322 propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1324 Visual::Base visual = factory.CreateVisual( propertyMap );
1325 DALI_TEST_CHECK( visual );
1327 Property::Map testMap;
1328 visual.CreatePropertyMap(testMap);
1329 DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1331 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1332 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1334 TestGlAbstraction& gl = application.GetGlAbstraction();
1335 TraceCallStack& textureTrace = gl.GetTextureTrace();
1336 textureTrace.Enable(true);
1338 DummyControl actor = DummyControl::New();
1339 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1340 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1341 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1343 actor.SetSize( 200.f, 200.f );
1344 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1346 Stage::GetCurrent().Add( actor );
1347 application.SendNotification();
1348 application.Render();
1350 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1352 application.SendNotification();
1353 application.Render();
1355 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1356 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1357 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1363 int UtcDaliImageVisualAlphaMaskCrop(void)
1365 ToolkitTestApplication application;
1366 tet_infoline( "Request image visual with an Alpha mask and scale/cropping" );
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_LARGE_IMAGE_FILE_NAME );
1374 propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
1375 propertyMap.Insert( ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f );
1376 propertyMap.Insert( ImageVisual::Property::CROP_TO_MASK, true );
1378 Visual::Base visual = factory.CreateVisual( propertyMap );
1379 DALI_TEST_CHECK( visual );
1381 Property::Map testMap;
1382 visual.CreatePropertyMap(testMap);
1383 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1384 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::MASK_CONTENT_SCALE), Property::Value(1.6f), TEST_LOCATION );
1385 DALI_TEST_EQUALS( *testMap.Find(ImageVisual::Property::CROP_TO_MASK),Property::Value(true), TEST_LOCATION );
1387 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1388 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1390 TestGlAbstraction& gl = application.GetGlAbstraction();
1391 TraceCallStack& textureTrace = gl.GetTextureTrace();
1392 textureTrace.Enable(true);
1394 DummyControl actor = DummyControl::New();
1395 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1396 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1398 actor.SetSize( 200.f, 200.f );
1399 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1400 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
1402 Stage::GetCurrent().Add( actor );
1403 application.SendNotification();
1404 application.Render();
1406 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1408 application.SendNotification();
1409 application.Render();
1412 visual.GetNaturalSize(size);
1414 DALI_TEST_EQUALS( size, Vector2( 100.0f, 100.0f ), 0.001f, TEST_LOCATION );
1415 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1416 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1417 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
1422 int UtcDaliImageVisualReleasePolicy01(void)
1424 ToolkitTestApplication application;
1425 tet_infoline( "UtcDaliImageVisualReleasePolicy01 Detached Policy, disabling visual with this policy deletes texture" );
1427 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1428 DALI_TEST_CHECK( imageVisual );
1430 // Set up debug trace
1431 TestGlAbstraction& gl = application.GetGlAbstraction();
1432 TraceCallStack& textureTrace = gl.GetTextureTrace();
1433 textureTrace.Enable(true);
1435 tet_infoline( "Register visual with control and ensure it has the only handle" );
1436 DummyControl actor = DummyControl::New(true);
1437 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1438 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1439 imageVisual.Reset();
1441 actor.SetSize(200.f, 200.f);
1443 application.SendNotification();
1444 application.Render(0);
1445 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1446 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1448 Stage::GetCurrent().Add( actor );
1450 // Wait for image to load
1451 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1453 application.SendNotification();
1454 application.Render(0);
1455 // Test renderer and texture created
1456 tet_infoline( "Confirm texture created" );
1457 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1458 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1460 tet_infoline( "Disable visual causing the texture to be deleted" );
1461 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1463 application.SendNotification();
1464 application.Render(0);
1465 // Test renderer and textures removed.
1466 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1467 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1472 int UtcDaliImageVisualReleasePolicy02(void)
1474 ToolkitTestApplication application;
1475 tet_infoline( "UtcDaliImageVisualReleasePolicy02 Destroyed Policy, Texture should be deleted when visual destroyed" );
1477 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1478 DALI_TEST_CHECK( imageVisual );
1480 // Setup debug trace
1481 TestGlAbstraction& gl = application.GetGlAbstraction();
1482 TraceCallStack& textureTrace = gl.GetTextureTrace();
1483 textureTrace.Enable(true);
1485 tet_infoline( "Register visual with control and ensure it has the only handle" );
1486 DummyControl actor = DummyControl::New(true);
1487 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1488 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1489 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1491 actor.SetSize(200.f, 200.f);
1493 application.SendNotification();
1494 application.Render(0);
1495 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1496 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1498 Stage::GetCurrent().Add( actor );
1500 // Wait for image to load
1501 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1503 application.SendNotification();
1504 application.Render(0);
1505 // Test renderer and texture created
1506 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1507 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1510 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1511 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1512 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1513 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1514 application.SendNotification();
1515 application.Render();
1517 // Test texture removed after visual destroyed.
1518 tet_infoline( "Ensure texture is deleted after visual destroyed" );
1519 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1524 int UtcDaliImageVisualReleasePolicy03(void)
1526 ToolkitTestApplication application;
1527 tet_infoline( "UtcDaliImageVisualReleasePolicy03 Never Policy, texture should not be deleted after visual destroyed" );
1529 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1530 DALI_TEST_CHECK( imageVisual );
1532 TestGlAbstraction& gl = application.GetGlAbstraction();
1533 TraceCallStack& textureTrace = gl.GetTextureTrace();
1534 textureTrace.Enable(true);
1536 tet_infoline( "Register visual with control and ensure it has the only handle" );
1537 DummyControl actor = DummyControl::New(true);
1538 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1539 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1540 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1542 actor.SetSize(200.f, 200.f);
1544 application.SendNotification();
1545 application.Render(0);
1546 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1547 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1549 Stage::GetCurrent().Add( actor );
1551 // Wait for image to load
1552 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1554 application.SendNotification();
1555 application.Render(0);
1556 // Test renderer and texture created
1557 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1558 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1560 tet_infoline( "Destroy visual by UnRegistering visual with control, check renderer is destroyed" );
1561 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1562 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1563 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1564 application.SendNotification();
1565 application.Render();
1567 tet_infoline( "Ensure texture is not deleted as policy is set to NEVER" );
1568 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1573 int UtcDaliImageVisualReleasePolicy04(void)
1575 ToolkitTestApplication application;
1576 tet_infoline( "UtcDaliImageVisualReleasePolicy04 Two visuals with different policies sharing a texture" );
1578 tet_infoline( "Create first visual with Never release policy" );
1579 Visual::Base imageVisualNever = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1581 tet_infoline( "Create second visual with Destroyed release policy");
1582 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1584 // Set up trace debug
1585 TestGlAbstraction& gl = application.GetGlAbstraction();
1586 TraceCallStack& textureTrace = gl.GetTextureTrace();
1587 textureTrace.Enable(true);
1589 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1590 DummyControl actor = DummyControl::New(true);
1591 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1592 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualNever );
1593 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDestroyed );
1594 imageVisualNever.Reset(); // reduce ref count so only the control keeps the visual alive.
1595 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1597 actor.SetSize(200.f, 200.f);
1599 // Test initially zero renderers
1600 application.SendNotification();
1601 application.Render(0);
1602 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1603 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1605 Stage::GetCurrent().Add( actor );
1607 // Wait for image to load
1608 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1610 application.SendNotification();
1611 application.Render(0);
1612 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1613 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1614 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1616 // Test renderer removed when visual destroyed
1617 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1618 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL2 ); // TEST_VISUAL2 no longer requires the texture as release policy DESTROYED
1619 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1620 application.SendNotification();
1621 application.Render();
1623 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1624 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1626 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1627 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1628 application.SendNotification();
1629 application.Render();
1631 tet_infoline( "Ensure a texture is not deleted as second visual used the NEVER release policy" );
1632 // Test texture was not deleted as TEST_VISUAL release policy is NEVER so it is still required.
1633 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1638 int UtcDaliImageVisualReleasePolicy05(void)
1640 ToolkitTestApplication application;
1641 tet_infoline( "UtcDaliImageVisualReleasePolicy05 Testing settung by string currents correct enum" );
1643 VisualFactory factory = VisualFactory::Get();
1645 Property::Map propertyMapNeverReleasePolicy;
1646 propertyMapNeverReleasePolicy.Insert( Visual::Property::TYPE, Visual::IMAGE );
1647 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1648 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1649 propertyMapNeverReleasePolicy.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1650 propertyMapNeverReleasePolicy.Insert( "releasePolicy" , "never" );
1652 Visual::Base imageVisualNever = factory.CreateVisual( propertyMapNeverReleasePolicy );
1654 Property::Map resultMap;
1655 imageVisualNever.CreatePropertyMap( resultMap );
1656 DALI_TEST_CHECK( ! resultMap.Empty() );
1658 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::RELEASE_POLICY ) )->Get<int>(), (int)ImageVisual::ReleasePolicy::NEVER, TEST_LOCATION );
1663 int UtcDaliImageVisualReleasePolicy06(void)
1665 ToolkitTestApplication application;
1666 tet_infoline( "UtcDaliImageVisualReleasePolicy06 Never Policy, texture should not be affected by Disabling and Enabling visual" );
1668 Visual::Base imageVisual= CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER );
1669 DALI_TEST_CHECK( imageVisual );
1671 TestGlAbstraction& gl = application.GetGlAbstraction();
1672 TraceCallStack& textureTrace = gl.GetTextureTrace();
1673 textureTrace.Enable(true);
1675 tet_infoline( "Register visual with control and ensure it has the only handle" );
1676 DummyControl actor = DummyControl::New(true);
1677 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1678 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1679 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1681 actor.SetSize(200.f, 200.f);
1683 application.SendNotification();
1684 application.Render(0);
1685 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1686 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1688 Stage::GetCurrent().Add( actor );
1690 // Wait for image to load
1691 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1693 application.SendNotification();
1694 application.Render(0);
1695 // Test renderer and texture created
1696 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1697 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1698 textureTrace.Reset();
1700 tet_infoline( "Disable Visual and check texture not affected" );
1701 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1702 application.SendNotification();
1703 application.Render(0);
1704 tet_infoline( "Check renderer is destroyed when visual off stage" );
1705 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1706 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1707 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1708 textureTrace.Reset();
1710 tet_infoline( "Re-enable Visual and check texture not affected" );
1711 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, true );
1712 application.SendNotification();
1713 application.Render(0);
1714 tet_infoline( "Check texture not affected and renderer is destroyed when visual off stage" );
1715 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1716 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1717 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1722 int UtcDaliImageVisualReleasePolicy07(void)
1724 ToolkitTestApplication application;
1725 tet_infoline( "UtcDaliImageVisualReleasePolicy07 Two visuals with different policies sharing a texture DETACHED and DESTROYED" );
1727 tet_infoline( "Create first visual with DESTROYED release policy" );
1728 Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED );
1731 tet_infoline( "Create second visual with DETACHED release policy");
1732 Visual::Base imageVisualDetached = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED );
1734 // Set up trace debug
1735 TestGlAbstraction& gl = application.GetGlAbstraction();
1736 TraceCallStack& textureTrace = gl.GetTextureTrace();
1737 textureTrace.Enable(true);
1739 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1740 DummyControl actor = DummyControl::New(true);
1741 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1742 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed );
1743 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, imageVisualDetached );
1744 imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive.
1745 imageVisualDetached.Reset(); // reduce ref count so only the control keeps the visual alive.
1747 actor.SetSize(200.f, 200.f);
1749 // Test initially zero renderers
1750 application.SendNotification();
1751 application.Render(0);
1752 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1753 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1755 Stage::GetCurrent().Add( actor );
1757 // Wait for image to load
1758 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1760 application.SendNotification();
1761 application.Render(0);
1762 tet_infoline( "Ensure a texture is created, shared amongst both visuals. Each visual has its own renderer" );
1763 DALI_TEST_EQUALS( actor.GetRendererCount(), 2u, TEST_LOCATION );
1764 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1766 // Test renderer removed when visual destroyed
1767 DALI_TEST_CHECK( actor.GetRendererCount() == 2u );
1768 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, false ); // TEST_VISUAL2 no longer requires the texture as release policy DETACHED
1769 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1770 application.SendNotification();
1771 application.Render();
1773 // Test texture was not deleted as TEST_VISUAL release policy is DESTROYED and is still required.
1774 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1776 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL, false );
1777 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1778 application.SendNotification();
1779 application.Render();
1781 tet_infoline( "Ensure a texture is not deleted as second visual used the DESTROYED release policy" );
1782 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1787 int UtcDaliImageVisualLoadPolicy01(void)
1789 ToolkitTestApplication application;
1790 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image before attaching to stage" );
1792 // Set up trace debug
1793 TestGlAbstraction& gl = application.GetGlAbstraction();
1794 TraceCallStack& textureTrace = gl.GetTextureTrace();
1795 textureTrace.Enable(true);
1797 tet_infoline( "Create visual with IMMEDIATE load policy" );
1798 VisualFactory factory = VisualFactory::Get();
1800 Property::Map propertyMap;
1801 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1802 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1803 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 20 );
1804 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 30 );
1805 propertyMap.Insert( "loadPolicy" , ImageVisual::LoadPolicy::IMMEDIATE );
1807 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
1809 Property::Map resultMap;
1810 imageVisual.CreatePropertyMap( resultMap );
1811 DALI_TEST_CHECK( ! resultMap.Empty() );
1812 DALI_TEST_EQUALS( ( resultMap.Find( ImageVisual::Property::LOAD_POLICY ) )->Get<int>(), (int)ImageVisual::LoadPolicy::IMMEDIATE, TEST_LOCATION );
1814 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1816 // Ensure texture has been uploaded
1817 application.SendNotification();
1818 application.Render();
1820 tet_infoline( "Ensure texture loading starts after visual created" );
1821 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1822 textureTrace.Reset();
1824 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1825 DummyControl actor = DummyControl::New(true);
1826 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1827 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1828 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1830 actor.SetSize(200.f, 200.f);
1831 Stage::GetCurrent().Add( actor );
1832 tet_infoline( "Ensure nothing triggers another load as texure already loaded" );
1833 const unsigned int TIME_OUT_3_SECONDS = 3;
1834 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1836 application.SendNotification();
1837 application.Render();
1839 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1840 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1842 // Ensure texture is deleted when no longer needed (ref count was correct )
1843 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1845 application.SendNotification();
1846 application.Render();
1848 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1849 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1854 int UtcDaliImageVisualLoadPolicy02(void)
1856 ToolkitTestApplication application;
1857 tet_infoline( "UtcDaliImageVisualLoadPolicy01 Load a visual image only after attached to stage" );
1859 // Set up trace debug
1860 TestGlAbstraction& gl = application.GetGlAbstraction();
1861 TraceCallStack& textureTrace = gl.GetTextureTrace();
1862 textureTrace.Enable(true);
1864 tet_infoline( "Create visual with IMMEDIATE load policy" );
1865 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
1867 const unsigned int TIME_OUT_3_SECONDS = 3;
1868 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1, TIME_OUT_3_SECONDS ), false, TEST_LOCATION );
1870 // Act on meeage queue even although nothing expected to load
1871 application.SendNotification();
1872 application.Render();
1874 tet_infoline( "Ensure texture is not generated yet" );
1875 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1876 textureTrace.Reset();
1878 tet_infoline( "Register visuals with control and ensure it has the only handles" );
1879 DummyControl actor = DummyControl::New(true);
1880 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1881 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1882 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1884 actor.SetSize(200.f, 200.f);
1885 Stage::GetCurrent().Add( actor );
1886 tet_infoline( "Allow image time to load" );
1887 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1889 application.SendNotification();
1890 application.Render();
1892 tet_infoline( "Ensure texture generated and renderer created" );
1893 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1894 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1896 // Ensure texture is delete when no longer needed
1897 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
1899 application.SendNotification();
1900 application.Render();
1902 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1903 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1908 int UtcDaliImageVisualLoadPolicy03(void)
1910 ToolkitTestApplication application;
1911 tet_infoline( "UtcDaliImageVisualLoadPolicy03 Load a visual image and receive ResourceReady Signal when loaded" );
1913 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing 'false' into an API.
1915 // Set up trace debug
1916 TestGlAbstraction& gl = application.GetGlAbstraction();
1917 TraceCallStack& textureTrace = gl.GetTextureTrace();
1918 textureTrace.Enable(true);
1920 tet_infoline( "Create a control and connect to resource ready signal without adding to stage" );
1921 DummyControl actor = DummyControl::New(true);
1922 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1923 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1924 actor.SetSize(200.f, 200.f);
1926 tet_infoline( "Create visual with IMMEDIATE load policy" );
1927 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1929 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( not staged )" );
1930 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1931 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1933 tet_infoline( "Allow image time to load resource" );
1934 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1935 application.SendNotification();
1936 application.Render();
1938 // Ensure texture has been uploaded
1939 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1940 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1945 int UtcDaliImageVisualLoadPolicy04(void)
1947 ToolkitTestApplication application;
1948 tet_infoline( "UtcDaliImageVisualLoadPolicy04 First part Load a visual image before attaching to stage");
1949 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
1951 const bool VISUAL_NOT_ENABLED( false ); // Instead of just passing false into an API.
1953 // Set up trace debug
1954 TestGlAbstraction& gl = application.GetGlAbstraction();
1955 TraceCallStack& textureTrace = gl.GetTextureTrace();
1956 textureTrace.Enable(true);
1958 tet_infoline( "Create a control and connect to resource ready signal" );
1959 DummyControl actor = DummyControl::New(true);
1960 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
1961 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1962 actor.SetSize(200.f, 200.f);
1964 tet_infoline( "Create visual with IMMEDIATE load policy" );
1965 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1967 tet_infoline( "Registering visual allows control to get a signal once loaded even if visual not enabled( staged )" );
1968 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual, VISUAL_NOT_ENABLED );
1969 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
1971 tet_infoline( "Allow image time to load" );
1972 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1973 application.SendNotification();
1974 application.Render();
1976 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
1977 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1978 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1980 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
1982 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
1983 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::IMMEDIATE );
1984 DummyControl actor2 = DummyControl::New(true);
1985 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
1986 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
1988 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
1989 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
1990 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
1991 actor2.SetSize(200.f, 200.f);
1992 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
1993 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1998 int UtcDaliImageVisualLoadPolicy05(void)
2000 ToolkitTestApplication application;
2001 tet_infoline( "UtcDaliImageVisualLoadPolicy05 LoadPolicy::ATTACHED (default) First part Load a visual image before attaching to stage");
2002 tet_infoline( "Second part, Reuse the same image in aonther control and check resource ready signal fired" );
2003 // Set up trace debug
2004 TestGlAbstraction& gl = application.GetGlAbstraction();
2005 TraceCallStack& textureTrace = gl.GetTextureTrace();
2006 textureTrace.Enable(true);
2008 tet_infoline( "Create a control and connect to resource ready signal" );
2009 DummyControl actor = DummyControl::New(true);
2010 actor.ResourceReadySignal().Connect( &ResourceReadySignal);
2011 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2012 actor.SetSize(200.f, 200.f);
2013 Stage::GetCurrent().Add( actor );
2015 tet_infoline( "Create visual with ATTACHED load policy" );
2016 Visual::Base imageVisual = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2018 tet_infoline( "Registering visual allows control to get a signal once loaded" );
2019 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2020 imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive.
2022 tet_infoline( "Allow image time to load" );
2023 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2024 application.SendNotification();
2025 application.Render();
2027 tet_infoline( "Testing texture is loaded and resource ready signal fired" );
2028 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
2029 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2031 tet_infoline( "Original control correctly signalled, now testing for signal with new Control reusing the image" );
2033 gResourceReadySignalFired = false; // Reset signal check ready for testing next Control
2034 Visual::Base imageVisual2 = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED );
2035 DummyControl actor2 = DummyControl::New(true);
2036 Impl::DummyControl& dummyImpl2 = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2037 actor2.ResourceReadySignal().Connect( &ResourceReadySignal);
2039 tet_infoline( "Registering visual this should trigger the loading signal as is already image loaded for previous control" );
2040 dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual2 );
2041 imageVisual2.Reset(); // reduce ref count so only the control keeps the visual alive.
2042 actor2.SetSize(200.f, 200.f);
2043 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 0 ), true, TEST_LOCATION ); // Not expecting any further loading as texture is being reused.
2044 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2050 int UtcDaliImageVisualOrientationCorrection(void)
2052 ToolkitTestApplication application;
2053 tet_infoline( "UtcDaliImageVisualOrientationCorrection Enabling OrientationCorrection should rotate an image with exif (90deg) orientation data with requested" );
2055 VisualFactory factory = VisualFactory::Get();
2056 tet_infoline( "Create visual with Orientation correction set OFF" );
2057 Property::Map propertyMap;
2058 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2059 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2060 propertyMap.Insert( "orientationCorrection", false );
2061 Visual::Base imageVisual = factory.CreateVisual( propertyMap );
2063 tet_infoline( "Create control for visual, need to loaded it" );
2064 DummyControl actor = DummyControl::New(true);
2065 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
2066 Stage::GetCurrent().Add( actor );
2068 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2069 // Wait for image to load
2070 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2072 Vector2 originalImageSize;
2073 tet_infoline( "Get size of original visual to compare later with rotated image" );
2074 imageVisual.GetNaturalSize( originalImageSize );
2075 DALI_TEST_GREATER( originalImageSize.width, originalImageSize.height, TEST_LOCATION ); // Width and Height must be different for this test.
2076 imageVisual.Reset(); // remove handle so can unregister it and remove from cache
2077 dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL );
2078 application.SendNotification();
2079 application.Render();
2081 tet_infoline( "Create visual with Orientation correction set ON " );
2082 propertyMap.Clear();
2083 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2084 propertyMap.Insert( ImageVisual::Property::URL, TEST_ROTATED_IMAGE );
2085 propertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, true );
2086 imageVisual = factory.CreateVisual( propertyMap );
2088 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
2089 // Wait for image to load
2090 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2092 Vector2 rotatedImageSize;
2093 imageVisual.GetNaturalSize( rotatedImageSize );
2094 tet_infoline( "Confirm that visual has rotated" );
2095 DALI_TEST_EQUALS( originalImageSize.width, rotatedImageSize.height , TEST_LOCATION );
2096 DALI_TEST_EQUALS( originalImageSize.height, rotatedImageSize.width , TEST_LOCATION );
2098 Property::Map resultMap;
2099 imageVisual.CreatePropertyMap( resultMap );
2101 // check the Property::ORIENTATION_CORRECTION value from the returned map
2102 Property::Value* typeValue = resultMap.Find( ImageVisual::Property::ORIENTATION_CORRECTION, Property::BOOLEAN );
2103 DALI_TEST_EQUALS( typeValue->Get<bool>(), true, TEST_LOCATION );
2108 int UtcDaliImageVisualCustomShader(void)
2110 ToolkitTestApplication application;
2111 tet_infoline( "UtcDaliImageVisualCustomShader Test custom shader" );
2113 VisualFactory factory = VisualFactory::Get();
2114 Property::Map properties;
2115 Property::Map shader;
2116 const std::string vertexShader = "Foobar";
2117 const std::string fragmentShader = "Foobar";
2118 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2119 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2121 properties[Visual::Property::TYPE] = Visual::IMAGE;
2122 properties[Visual::Property::SHADER] = shader;
2123 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2125 Visual::Base visual = factory.CreateVisual( properties );
2127 // trigger creation through setting on stage
2128 DummyControl dummy = DummyControl::New( true );
2129 Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() );
2130 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
2132 dummy.SetSize( 200.f, 200.f );
2133 dummy.SetParentOrigin( ParentOrigin::CENTER );
2134 Stage::GetCurrent().Add( dummy );
2136 application.SendNotification();
2137 application.Render();
2139 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2141 Renderer renderer = dummy.GetRendererAt( 0 );
2142 Shader shader2 = renderer.GetShader();
2143 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2144 Property::Map* map = value.GetMap();
2145 DALI_TEST_CHECK( map );
2147 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2148 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2150 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2151 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2155 shader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
2156 properties[Visual::Property::SHADER] = shader;
2158 Visual::Base visual1 = factory.CreateVisual( properties );
2160 // trigger creation through setting on stage
2161 DummyControl dummy1 = DummyControl::New( true );
2162 Impl::DummyControl& dummyImpl1 = static_cast< Impl::DummyControl& >( dummy1.GetImplementation() );
2163 dummyImpl1.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual1 );
2164 dummy1.SetSize( 200, 200 );
2165 dummy1.SetParentOrigin( ParentOrigin::CENTER );
2166 Stage::GetCurrent().Add( dummy1 );
2168 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2169 glAbstraction.EnableEnableDisableCallTrace( true );
2171 application.SendNotification();
2172 application.Render();
2174 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
2175 std::ostringstream blendStr;
2176 blendStr << GL_BLEND;
2177 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );